<?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.HealthMedicalReportDetailMapper">
    <resultMap type="com.bonus.canteen.core.health.domain.HealthMedicalReportDetail" id="HealthMedicalReportDetailResult">
        <result property="id"    column="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="medicalProjectDetailUnit"    column="medical_project_detail_unit"    />
        <result property="medicalProjectDetailReference"    column="medical_project_detail_reference"    />
        <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="selectHealthMedicalReportDetailVo">
        select id, medical_project_id, medical_project_detail_id, medical_project_detail_name, medical_project_detail_unit, medical_project_detail_reference, create_by, create_time, update_by, update_time from health_medical_report_detail
    </sql>

    <select id="selectHealthMedicalReportDetailList" parameterType="com.bonus.canteen.core.health.domain.HealthMedicalReportDetail" resultMap="HealthMedicalReportDetailResult">
        <include refid="selectHealthMedicalReportDetailVo"/>
        <where>  
            <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="medicalProjectDetailUnit != null  and medicalProjectDetailUnit != ''"> and medical_project_detail_unit = #{medicalProjectDetailUnit}</if>
            <if test="medicalProjectDetailReference != null  and medicalProjectDetailReference != ''"> and medical_project_detail_reference = #{medicalProjectDetailReference}</if>
        </where>
    </select>
    
    <select id="selectHealthMedicalReportDetailById" parameterType="Long" resultMap="HealthMedicalReportDetailResult">
        <include refid="selectHealthMedicalReportDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHealthMedicalReportDetail" parameterType="com.bonus.canteen.core.health.domain.HealthMedicalReportDetail" useGeneratedKeys="true" keyProperty="id">
        insert into health_medical_report_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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="medicalProjectDetailUnit != null">medical_project_detail_unit,</if>
            <if test="medicalProjectDetailReference != null">medical_project_detail_reference,</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="medicalProjectId != null">#{medicalProjectId},</if>
            <if test="medicalProjectDetailId != null">#{medicalProjectDetailId},</if>
            <if test="medicalProjectDetailName != null and medicalProjectDetailName != ''">#{medicalProjectDetailName},</if>
            <if test="medicalProjectDetailUnit != null">#{medicalProjectDetailUnit},</if>
            <if test="medicalProjectDetailReference != null">#{medicalProjectDetailReference},</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="updateHealthMedicalReportDetail" parameterType="com.bonus.canteen.core.health.domain.HealthMedicalReportDetail">
        update health_medical_report_detail
        <trim prefix="SET" suffixOverrides=",">
            <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="medicalProjectDetailUnit != null">medical_project_detail_unit = #{medicalProjectDetailUnit},</if>
            <if test="medicalProjectDetailReference != null">medical_project_detail_reference = #{medicalProjectDetailReference},</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="deleteHealthMedicalReportDetailById" parameterType="Long">
        delete from health_medical_report_detail where id = #{id}
    </delete>

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