<?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.HealthPersonMedicalReportMapper">
    <resultMap type="com.bonus.canteen.core.health.domain.HealthPersonMedicalReport" id="HealthPersonMedicalReportResult">
        <result property="id"    column="id"    />
        <result property="medicalId"    column="medical_id"    />
        <result property="userId"    column="user_id"    />
        <result property="medicalDate"    column="medical_date"    />
        <result property="medicalMechanism"    column="medical_mechanism"    />
        <result property="medicalTemplateId"    column="medical_template_id"    />
        <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="selectHealthPersonMedicalReportVo">
        select id, medical_id, user_id, medical_date, medical_mechanism, medical_template_id, create_by, create_time, update_by, update_time from health_person_medical_report
    </sql>

    <select id="selectHealthPersonMedicalReportList" parameterType="com.bonus.canteen.core.health.domain.HealthPersonMedicalReport" resultMap="HealthPersonMedicalReportResult">
        <include refid="selectHealthPersonMedicalReportVo"/>
        <where>  
            <if test="medicalId != null "> and medical_id = #{medicalId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="medicalDate != null "> and medical_date = #{medicalDate}</if>
            <if test="medicalMechanism != null  and medicalMechanism != ''"> and medical_mechanism = #{medicalMechanism}</if>
            <if test="medicalTemplateId != null "> and medical_template_id = #{medicalTemplateId}</if>
        </where>
    </select>
    
    <select id="selectHealthPersonMedicalReportById" parameterType="Long" resultMap="HealthPersonMedicalReportResult">
        <include refid="selectHealthPersonMedicalReportVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHealthPersonMedicalReport" parameterType="com.bonus.canteen.core.health.domain.HealthPersonMedicalReport" useGeneratedKeys="true" keyProperty="id">
        insert into health_person_medical_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="medicalId != null">medical_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="medicalDate != null">medical_date,</if>
            <if test="medicalMechanism != null and medicalMechanism != ''">medical_mechanism,</if>
            <if test="medicalTemplateId != null">medical_template_id,</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="medicalId != null">#{medicalId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="medicalDate != null">#{medicalDate},</if>
            <if test="medicalMechanism != null and medicalMechanism != ''">#{medicalMechanism},</if>
            <if test="medicalTemplateId != null">#{medicalTemplateId},</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="updateHealthPersonMedicalReport" parameterType="com.bonus.canteen.core.health.domain.HealthPersonMedicalReport">
        update health_person_medical_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="medicalId != null">medical_id = #{medicalId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="medicalDate != null">medical_date = #{medicalDate},</if>
            <if test="medicalMechanism != null and medicalMechanism != ''">medical_mechanism = #{medicalMechanism},</if>
            <if test="medicalTemplateId != null">medical_template_id = #{medicalTemplateId},</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="deleteHealthPersonMedicalReportById" parameterType="Long">
        delete from health_person_medical_report where id = #{id}
    </delete>

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