<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dgtly.system.mapper.UserTemperatureMapper">
    
    <resultMap type="UserTemperature" id="UserTemperatureResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="temperature"    column="temperature"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectUserTemperatureVo">
        select id, user_id, temperature, create_by, create_time, update_by, update_time, remark from user_temperature
    </sql>

    <select id="selectUserTemperatureList" parameterType="UserTemperature" resultMap="UserTemperatureResult">
        <include refid="selectUserTemperatureVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="temperature != null  and temperature != ''"> and temperature = #{temperature}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectUserTemperatureById" parameterType="Long" resultMap="UserTemperatureResult">
        <include refid="selectUserTemperatureVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertUserTemperature" parameterType="UserTemperature">
        insert into user_temperature
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="userId != null ">user_id,</if>
            <if test="temperature != null  and temperature != ''">temperature,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="temperature != null  and temperature != ''">#{temperature},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updateUserTemperature" parameterType="UserTemperature">
        update user_temperature
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="temperature != null  and temperature != ''">temperature = #{temperature},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserTemperatureById" parameterType="Long">
        delete from user_temperature where id = #{id}
    </delete>

    <delete id="deleteUserTemperatureByIds" parameterType="String">
        delete from user_temperature where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>