<?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.HealthMedicalReportProjectMapper">
    <resultMap type="com.bonus.canteen.core.health.domain.HealthMedicalReportProject" id="HealthMedicalReportProjectResult">
        <result property="id"    column="id"    />
        <result property="medicalProjectId"    column="medical_project_id"    />
        <result property="medicalTemplateId"    column="medical_template_id"    />
        <result property="medicalProjectName"    column="medical_project_name"    />
        <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="selectHealthMedicalReportProjectVo">
        select id, medical_project_id, medical_template_id, medical_project_name, create_by, create_time, update_by, update_time from health_medical_report_project
    </sql>

    <select id="selectHealthMedicalReportProjectList" parameterType="com.bonus.canteen.core.health.domain.HealthMedicalReportProject" resultMap="HealthMedicalReportProjectResult">
        <include refid="selectHealthMedicalReportProjectVo"/>
        <where>  
            <if test="medicalProjectId != null "> and medical_project_id = #{medicalProjectId}</if>
            <if test="medicalTemplateId != null "> and medical_template_id = #{medicalTemplateId}</if>
            <if test="medicalProjectName != null  and medicalProjectName != ''"> and medical_project_name like concat('%', #{medicalProjectName}, '%')</if>
        </where>
    </select>
    
    <select id="selectHealthMedicalReportProjectById" parameterType="Long" resultMap="HealthMedicalReportProjectResult">
        <include refid="selectHealthMedicalReportProjectVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertHealthMedicalReportProject" parameterType="com.bonus.canteen.core.health.domain.HealthMedicalReportProject" useGeneratedKeys="true" keyProperty="id">
        insert into health_medical_report_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="medicalProjectId != null">medical_project_id,</if>
            <if test="medicalTemplateId != null">medical_template_id,</if>
            <if test="medicalProjectName != null and medicalProjectName != ''">medical_project_name,</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="medicalTemplateId != null">#{medicalTemplateId},</if>
            <if test="medicalProjectName != null and medicalProjectName != ''">#{medicalProjectName},</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="updateHealthMedicalReportProject" parameterType="com.bonus.canteen.core.health.domain.HealthMedicalReportProject">
        update health_medical_report_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="medicalProjectId != null">medical_project_id = #{medicalProjectId},</if>
            <if test="medicalTemplateId != null">medical_template_id = #{medicalTemplateId},</if>
            <if test="medicalProjectName != null and medicalProjectName != ''">medical_project_name = #{medicalProjectName},</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="deleteHealthMedicalReportProjectById" parameterType="Long">
        delete from health_medical_report_project where id = #{id}
    </delete>

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