<?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.HealthPersonInfoMapper">
    <resultMap type="com.bonus.canteen.core.health.domain.HealthPersonInfo" id="HealthPersonInfoResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="registerDate"    column="register_date"    />
        <result property="bloodType"    column="blood_type"    />
        <result property="maritalStatus"    column="marital_status"    />
        <result property="pregnantStatus"    column="pregnant_status"    />
        <result property="pregnancyDate"    column="pregnancy_date"    />
        <result property="doctorAdvice"    column="doctor_advice"    />
        <result property="ifHospitalized"    column="if_hospitalized"    />
        <result property="doctorNum"    column="doctor_num"    />
        <result property="hospitalNum"    column="hospital_num"    />
        <result property="inpatientDate"    column="inpatient_date"    />
        <result property="inpatientResult"    column="inpatient_result"    />
        <result property="weightControl"    column="weight_control"    />
        <result property="allergen"    column="allergen"    />
        <result property="labourIntensity"    column="labour_intensity"    />
        <result property="healthState"    column="health_state"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectHealthPersonInfoVo">
        select id, user_id, register_date, blood_type, marital_status, pregnant_status, pregnancy_date, doctor_advice, if_hospitalized, doctor_num, hospital_num, inpatient_date, inpatient_result, weight_control, allergen, labour_intensity, health_state, create_by, create_time, update_by, update_time from health_person_info
    </sql>

    <select id="selectHealthPersonInfoList" parameterType="com.bonus.canteen.core.health.domain.HealthPersonInfo" resultMap="HealthPersonInfoResult">
        <include refid="selectHealthPersonInfoVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="registerDate != null "> and register_date = #{registerDate}</if>
            <if test="bloodType != null "> and blood_type = #{bloodType}</if>
            <if test="maritalStatus != null "> and marital_status = #{maritalStatus}</if>
            <if test="pregnantStatus != null "> and pregnant_status = #{pregnantStatus}</if>
            <if test="pregnancyDate != null "> and pregnancy_date = #{pregnancyDate}</if>
            <if test="doctorAdvice != null "> and doctor_advice = #{doctorAdvice}</if>
            <if test="ifHospitalized != null "> and if_hospitalized = #{ifHospitalized}</if>
            <if test="doctorNum != null  and doctorNum != ''"> and doctor_num = #{doctorNum}</if>
            <if test="hospitalNum != null  and hospitalNum != ''"> and hospital_num = #{hospitalNum}</if>
            <if test="inpatientDate != null "> and inpatient_date = #{inpatientDate}</if>
            <if test="inpatientResult != null  and inpatientResult != ''"> and inpatient_result = #{inpatientResult}</if>
            <if test="weightControl != null "> and weight_control = #{weightControl}</if>
            <if test="allergen != null  and allergen != ''"> and allergen = #{allergen}</if>
            <if test="labourIntensity != null "> and labour_intensity = #{labourIntensity}</if>
            <if test="healthState != null "> and health_state = #{healthState}</if>
        </where>
    </select>
    
    <select id="selectHealthPersonInfoById" parameterType="Long" resultMap="HealthPersonInfoResult">
        <include refid="selectHealthPersonInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHealthPersonInfo" parameterType="com.bonus.canteen.core.health.domain.HealthPersonInfo">
        insert into health_person_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="registerDate != null">register_date,</if>
            <if test="bloodType != null">blood_type,</if>
            <if test="maritalStatus != null">marital_status,</if>
            <if test="pregnantStatus != null">pregnant_status,</if>
            <if test="pregnancyDate != null">pregnancy_date,</if>
            <if test="doctorAdvice != null">doctor_advice,</if>
            <if test="ifHospitalized != null">if_hospitalized,</if>
            <if test="doctorNum != null">doctor_num,</if>
            <if test="hospitalNum != null">hospital_num,</if>
            <if test="inpatientDate != null">inpatient_date,</if>
            <if test="inpatientResult != null and inpatientResult != ''">inpatient_result,</if>
            <if test="weightControl != null">weight_control,</if>
            <if test="allergen != null and allergen != ''">allergen,</if>
            <if test="labourIntensity != null">labour_intensity,</if>
            <if test="healthState != null">health_state,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="registerDate != null">#{registerDate},</if>
            <if test="bloodType != null">#{bloodType},</if>
            <if test="maritalStatus != null">#{maritalStatus},</if>
            <if test="pregnantStatus != null">#{pregnantStatus},</if>
            <if test="pregnancyDate != null">#{pregnancyDate},</if>
            <if test="doctorAdvice != null">#{doctorAdvice},</if>
            <if test="ifHospitalized != null">#{ifHospitalized},</if>
            <if test="doctorNum != null">#{doctorNum},</if>
            <if test="hospitalNum != null">#{hospitalNum},</if>
            <if test="inpatientDate != null">#{inpatientDate},</if>
            <if test="inpatientResult != null and inpatientResult != ''">#{inpatientResult},</if>
            <if test="weightControl != null">#{weightControl},</if>
            <if test="allergen != null and allergen != ''">#{allergen},</if>
            <if test="labourIntensity != null">#{labourIntensity},</if>
            <if test="healthState != null">#{healthState},</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>
         </trim>
    </insert>

    <update id="updateHealthPersonInfo" parameterType="com.bonus.canteen.core.health.domain.HealthPersonInfo">
        update health_person_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="registerDate != null">register_date = #{registerDate},</if>
            <if test="bloodType != null">blood_type = #{bloodType},</if>
            <if test="maritalStatus != null">marital_status = #{maritalStatus},</if>
            <if test="pregnantStatus != null">pregnant_status = #{pregnantStatus},</if>
            <if test="pregnancyDate != null">pregnancy_date = #{pregnancyDate},</if>
            <if test="doctorAdvice != null">doctor_advice = #{doctorAdvice},</if>
            <if test="ifHospitalized != null">if_hospitalized = #{ifHospitalized},</if>
            <if test="doctorNum != null">doctor_num = #{doctorNum},</if>
            <if test="hospitalNum != null">hospital_num = #{hospitalNum},</if>
            <if test="inpatientDate != null">inpatient_date = #{inpatientDate},</if>
            <if test="inpatientResult != null and inpatientResult != ''">inpatient_result = #{inpatientResult},</if>
            <if test="weightControl != null">weight_control = #{weightControl},</if>
            <if test="allergen != null and allergen != ''">allergen = #{allergen},</if>
            <if test="labourIntensity != null">labour_intensity = #{labourIntensity},</if>
            <if test="healthState != null">health_state = #{healthState},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteHealthPersonInfoById" parameterType="Long">
        delete from health_person_info where id = #{id}
    </delete>

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