<?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.fs.his.mapper.FsHealthDataMapper">
    
    <resultMap type="FsHealthData" id="FsHealthDataResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="weight"    column="weight"    />
        <result property="heartRate"    column="heart_rate"    />
        <result property="temperature"    column="temperature"    />
        <result property="bloodPressure"    column="blood_pressure"    />
        <result property="bloodSugar"    column="blood_sugar"    />
        <result property="uric"    column="uric"    />
        <result property="sleep"    column="sleep"    />
        <result property="step"    column="step"    />
        <result property="shit"    column="shit"    />
        <result property="mood"    column="mood"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFsHealthDataVo">
        select id, user_id, weight, heart_rate, temperature, blood_pressure, blood_sugar, uric, sleep, step, shit, mood, create_time from fs_health_data
    </sql>

    <select id="selectFsHealthDataList" parameterType="FsHealthData" resultMap="FsHealthDataResult">
        <include refid="selectFsHealthDataVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="weight != null "> and weight = #{weight}</if>
            <if test="heartRate != null  and heartRate != ''"> and heart_rate = #{heartRate}</if>
            <if test="temperature != null  and temperature != ''"> and temperature = #{temperature}</if>
            <if test="bloodPressure != null  and bloodPressure != ''"> and blood_pressure = #{bloodPressure}</if>
            <if test="bloodSugar != null  and bloodSugar != ''"> and blood_sugar = #{bloodSugar}</if>
            <if test="uric != null  and uric != ''"> and uric = #{uric}</if>
            <if test="sleep != null  and sleep != ''"> and sleep = #{sleep}</if>
            <if test="step != null  and step != ''"> and step = #{step}</if>
            <if test="shit != null  and shit != ''"> and shit = #{shit}</if>
            <if test="mood != null  and mood != ''"> and mood = #{mood}</if>
        </where>
    </select>
    
    <select id="selectFsHealthDataById" parameterType="Long" resultMap="FsHealthDataResult">
        <include refid="selectFsHealthDataVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsHealthData" parameterType="FsHealthData" useGeneratedKeys="true" keyProperty="id">
        insert into fs_health_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="weight != null">weight,</if>
            <if test="heartRate != null">heart_rate,</if>
            <if test="temperature != null">temperature,</if>
            <if test="bloodPressure != null">blood_pressure,</if>
            <if test="bloodSugar != null">blood_sugar,</if>
            <if test="uric != null">uric,</if>
            <if test="sleep != null">sleep,</if>
            <if test="step != null">step,</if>
            <if test="shit != null">shit,</if>
            <if test="mood != null">mood,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="weight != null">#{weight},</if>
            <if test="heartRate != null">#{heartRate},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="bloodPressure != null">#{bloodPressure},</if>
            <if test="bloodSugar != null">#{bloodSugar},</if>
            <if test="uric != null">#{uric},</if>
            <if test="sleep != null">#{sleep},</if>
            <if test="step != null">#{step},</if>
            <if test="shit != null">#{shit},</if>
            <if test="mood != null">#{mood},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateFsHealthData" parameterType="FsHealthData">
        update fs_health_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="heartRate != null">heart_rate = #{heartRate},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="bloodPressure != null">blood_pressure = #{bloodPressure},</if>
            <if test="bloodSugar != null">blood_sugar = #{bloodSugar},</if>
            <if test="uric != null">uric = #{uric},</if>
            <if test="sleep != null">sleep = #{sleep},</if>
            <if test="step != null">step = #{step},</if>
            <if test="shit != null">shit = #{shit},</if>
            <if test="mood != null">mood = #{mood},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsHealthDataById" parameterType="Long">
        delete from fs_health_data where id = #{id}
    </delete>

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