<?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.HealthPersonMedicalReportDetailMapper">
    <resultMap type="com.bonus.canteen.core.health.domain.HealthPersonMedicalReportDetail" id="HealthPersonMedicalReportDetailResult">
        <result property="id"    column="id"    />
        <result property="medicalId"    column="medical_id"    />
        <result property="medicalProjectId"    column="medical_project_id"    />
        <result property="medicalProjectDetailId"    column="medical_project_detail_id"    />
        <result property="medicalProjectDetailName"    column="medical_project_detail_name"    />
        <result property="result"    column="result"    />
        <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="selectHealthPersonMedicalReportDetailVo">
        select id, medical_id, medical_project_id, medical_project_detail_id, medical_project_detail_name, result, create_by, create_time, update_by, update_time from health_person_medical_report_detail
    </sql>

    <select id="selectHealthPersonMedicalReportDetailList" parameterType="com.bonus.canteen.core.health.domain.HealthPersonMedicalReportDetail" resultMap="HealthPersonMedicalReportDetailResult">
        <include refid="selectHealthPersonMedicalReportDetailVo"/>
        <where>  
            <if test="medicalId != null "> and medical_id = #{medicalId}</if>
            <if test="medicalProjectId != null "> and medical_project_id = #{medicalProjectId}</if>
            <if test="medicalProjectDetailId != null "> and medical_project_detail_id = #{medicalProjectDetailId}</if>
            <if test="medicalProjectDetailName != null  and medicalProjectDetailName != ''"> and medical_project_detail_name like concat('%', #{medicalProjectDetailName}, '%')</if>
            <if test="result != null  and result != ''"> and result = #{result}</if>
        </where>
    </select>
    
    <select id="selectHealthPersonMedicalReportDetailById" parameterType="Long" resultMap="HealthPersonMedicalReportDetailResult">
        <include refid="selectHealthPersonMedicalReportDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHealthPersonMedicalReportDetail" parameterType="com.bonus.canteen.core.health.domain.HealthPersonMedicalReportDetail" useGeneratedKeys="true" keyProperty="id">
        insert into health_person_medical_report_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="medicalId != null">medical_id,</if>
            <if test="medicalProjectId != null">medical_project_id,</if>
            <if test="medicalProjectDetailId != null">medical_project_detail_id,</if>
            <if test="medicalProjectDetailName != null and medicalProjectDetailName != ''">medical_project_detail_name,</if>
            <if test="result != null">result,</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="medicalProjectId != null">#{medicalProjectId},</if>
            <if test="medicalProjectDetailId != null">#{medicalProjectDetailId},</if>
            <if test="medicalProjectDetailName != null and medicalProjectDetailName != ''">#{medicalProjectDetailName},</if>
            <if test="result != null">#{result},</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="updateHealthPersonMedicalReportDetail" parameterType="com.bonus.canteen.core.health.domain.HealthPersonMedicalReportDetail">
        update health_person_medical_report_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="medicalId != null">medical_id = #{medicalId},</if>
            <if test="medicalProjectId != null">medical_project_id = #{medicalProjectId},</if>
            <if test="medicalProjectDetailId != null">medical_project_detail_id = #{medicalProjectDetailId},</if>
            <if test="medicalProjectDetailName != null and medicalProjectDetailName != ''">medical_project_detail_name = #{medicalProjectDetailName},</if>
            <if test="result != null">result = #{result},</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="deleteHealthPersonMedicalReportDetailById" parameterType="Long">
        delete from health_person_medical_report_detail where id = #{id}
    </delete>

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