<?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.bonus.canteen.core.health.mapper.HealthPersonBodyRecordMapper">
    <resultMap type="com.bonus.canteen.core.health.domain.HealthPersonBodyRecord" id="HealthPersonBodyRecordResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="registerDate"    column="register_date"    />
        <result property="height"    column="height"    />
        <result property="weight"    column="weight"    />
        <result property="bmi"    column="bmi"    />
        <result property="shape"    column="shape"    />
        <result property="bust"    column="bust"    />
        <result property="waistline"    column="waistline"    />
        <result property="bloodSugar"    column="blood_sugar"    />
        <result property="bloodFat"    column="blood_fat"    />
        <result property="bloodPressureHigh"    column="blood_pressure_high"    />
        <result property="bloodPressureLow"    column="blood_pressure_low"    />
        <result property="heartRate"    column="heart_rate"    />
        <result property="bloodOxygen"    column="blood_oxygen"    />
        <result property="uricAcid"    column="uric_acid"    />
        <result property="bloodPressure"    column="blood_pressure"    />
        <result property="ifLatest"    column="if_latest"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="healthInfoSource"    column="health_info_source"    />
        <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="selectHealthPersonBodyRecordVo">
        select id, user_id, register_date, height, weight, bmi, shape, bust, waistline, blood_sugar, blood_fat, blood_pressure_high, blood_pressure_low, heart_rate, blood_oxygen, uric_acid, blood_pressure, if_latest, del_flag, health_info_source, create_by, create_time, update_by, update_time, remark from health_person_body_record
    </sql>

    <select id="selectHealthPersonBodyRecordList" parameterType="com.bonus.canteen.core.health.domain.HealthPersonBodyRecord" resultMap="HealthPersonBodyRecordResult">
        <include refid="selectHealthPersonBodyRecordVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="registerDate != null "> and register_date = #{registerDate}</if>
            <if test="height != null "> and height = #{height}</if>
            <if test="weight != null "> and weight = #{weight}</if>
            <if test="bmi != null "> and bmi = #{bmi}</if>
            <if test="shape != null  and shape != ''"> and shape = #{shape}</if>
            <if test="bust != null "> and bust = #{bust}</if>
            <if test="waistline != null "> and waistline = #{waistline}</if>
            <if test="bloodSugar != null "> and blood_sugar = #{bloodSugar}</if>
            <if test="bloodFat != null "> and blood_fat = #{bloodFat}</if>
            <if test="bloodPressureHigh != null "> and blood_pressure_high = #{bloodPressureHigh}</if>
            <if test="bloodPressureLow != null "> and blood_pressure_low = #{bloodPressureLow}</if>
            <if test="heartRate != null "> and heart_rate = #{heartRate}</if>
            <if test="bloodOxygen != null "> and blood_oxygen = #{bloodOxygen}</if>
            <if test="uricAcid != null "> and uric_acid = #{uricAcid}</if>
            <if test="bloodPressure != null "> and blood_pressure = #{bloodPressure}</if>
            <if test="ifLatest != null "> and if_latest = #{ifLatest}</if>
            <if test="healthInfoSource != null "> and health_info_source = #{healthInfoSource}</if>
        </where>
    </select>
    
    <select id="selectHealthPersonBodyRecordById" parameterType="Long" resultMap="HealthPersonBodyRecordResult">
        <include refid="selectHealthPersonBodyRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHealthPersonBodyRecord" parameterType="com.bonus.canteen.core.health.domain.HealthPersonBodyRecord" useGeneratedKeys="true" keyProperty="id">
        insert into health_person_body_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="registerDate != null">register_date,</if>
            <if test="height != null">height,</if>
            <if test="weight != null">weight,</if>
            <if test="bmi != null">bmi,</if>
            <if test="shape != null and shape != ''">shape,</if>
            <if test="bust != null">bust,</if>
            <if test="waistline != null">waistline,</if>
            <if test="bloodSugar != null">blood_sugar,</if>
            <if test="bloodFat != null">blood_fat,</if>
            <if test="bloodPressureHigh != null">blood_pressure_high,</if>
            <if test="bloodPressureLow != null">blood_pressure_low,</if>
            <if test="heartRate != null">heart_rate,</if>
            <if test="bloodOxygen != null">blood_oxygen,</if>
            <if test="uricAcid != null">uric_acid,</if>
            <if test="bloodPressure != null">blood_pressure,</if>
            <if test="ifLatest != null">if_latest,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="healthInfoSource != null">health_info_source,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="registerDate != null">#{registerDate},</if>
            <if test="height != null">#{height},</if>
            <if test="weight != null">#{weight},</if>
            <if test="bmi != null">#{bmi},</if>
            <if test="shape != null and shape != ''">#{shape},</if>
            <if test="bust != null">#{bust},</if>
            <if test="waistline != null">#{waistline},</if>
            <if test="bloodSugar != null">#{bloodSugar},</if>
            <if test="bloodFat != null">#{bloodFat},</if>
            <if test="bloodPressureHigh != null">#{bloodPressureHigh},</if>
            <if test="bloodPressureLow != null">#{bloodPressureLow},</if>
            <if test="heartRate != null">#{heartRate},</if>
            <if test="bloodOxygen != null">#{bloodOxygen},</if>
            <if test="uricAcid != null">#{uricAcid},</if>
            <if test="bloodPressure != null">#{bloodPressure},</if>
            <if test="ifLatest != null">#{ifLatest},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="healthInfoSource != null">#{healthInfoSource},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateHealthPersonBodyRecord" parameterType="com.bonus.canteen.core.health.domain.HealthPersonBodyRecord">
        update health_person_body_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="registerDate != null">register_date = #{registerDate},</if>
            <if test="height != null">height = #{height},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="bmi != null">bmi = #{bmi},</if>
            <if test="shape != null and shape != ''">shape = #{shape},</if>
            <if test="bust != null">bust = #{bust},</if>
            <if test="waistline != null">waistline = #{waistline},</if>
            <if test="bloodSugar != null">blood_sugar = #{bloodSugar},</if>
            <if test="bloodFat != null">blood_fat = #{bloodFat},</if>
            <if test="bloodPressureHigh != null">blood_pressure_high = #{bloodPressureHigh},</if>
            <if test="bloodPressureLow != null">blood_pressure_low = #{bloodPressureLow},</if>
            <if test="heartRate != null">heart_rate = #{heartRate},</if>
            <if test="bloodOxygen != null">blood_oxygen = #{bloodOxygen},</if>
            <if test="uricAcid != null">uric_acid = #{uricAcid},</if>
            <if test="bloodPressure != null">blood_pressure = #{bloodPressure},</if>
            <if test="ifLatest != null">if_latest = #{ifLatest},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="healthInfoSource != null">health_info_source = #{healthInfoSource},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteHealthPersonBodyRecordById" parameterType="Long">
        delete from health_person_body_record where id = #{id}
    </delete>

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