<?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.hw.qms.mapper.QmsCheckResultDetailProjectMapper">

    <resultMap type="QmsCheckResultDetailProject" id="QmsCheckResultDetailProjectResult">
        <result property="resultDetailProjectId"    column="result_detail_project_id"    />
        <result property="checkResultDetailId"    column="check_result_detail_id"    />
        <result property="checkProjectId"    column="check_project_id"    />
        <result property="checkProjectStatus"    column="check_project_status"    />
        <result property="checkProjectResult"    column="check_project_result"    />
        <result property="projectStepOrder"    column="project_step_order"    />
        <result property="standardValue"    column="standard_value"    />
        <result property="checkProjectName"    column="check_project_name"    />
        <result property="checkProjectProperty"    column="check_project_property"    />
        <result property="upperDiff"    column="upper_diff"    />
        <result property="downDiff"    column="down_diff"    />
        <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="selectQmsCheckResultDetailProjectVo">
        select result_detail_project_id, check_result_detail_id, check_project_id, check_project_status, check_project_result, project_step_order, standard_value, check_project_name, check_project_property, upper_diff, down_diff, create_by, create_time, update_by, update_time from qms_check_result_detail_project
    </sql>

    <select id="selectQmsCheckResultDetailProjectList" parameterType="QmsCheckResultDetailProject" resultMap="QmsCheckResultDetailProjectResult">
        <include refid="selectQmsCheckResultDetailProjectVo"/>
        <where>
            <if test="checkResultDetailId != null "> and check_result_detail_id = #{checkResultDetailId}</if>
            <if test="checkProjectId != null "> and check_project_id = #{checkProjectId}</if>
            <if test="checkProjectStatus != null  and checkProjectStatus != ''"> and check_project_status = #{checkProjectStatus}</if>
            <if test="checkProjectResult != null "> and check_project_result = #{checkProjectResult}</if>
            <if test="projectStepOrder != null "> and project_step_order = #{projectStepOrder}</if>
            <if test="standardValue != null "> and standard_value = #{standardValue}</if>
            <if test="checkProjectName != null  and checkProjectName != ''"> and check_project_name like concat('%', #{checkProjectName}, '%')</if>
            <if test="checkProjectProperty != null  and checkProjectProperty != ''"> and check_project_property = #{checkProjectProperty}</if>
            <if test="upperDiff != null "> and upper_diff = #{upperDiff}</if>
            <if test="downDiff != null "> and down_diff = #{downDiff}</if>
        </where>
    </select>

    <select id="selectQmsCheckResultDetailProjectByResultDetailProjectId" parameterType="Long" resultMap="QmsCheckResultDetailProjectResult">
        <include refid="selectQmsCheckResultDetailProjectVo"/>
        where result_detail_project_id = #{resultDetailProjectId}
    </select>

    <insert id="insertQmsCheckResultDetailProject" parameterType="QmsCheckResultDetailProject" useGeneratedKeys="true" keyProperty="resultDetailProjectId">
        insert into qms_check_result_detail_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="checkResultDetailId != null">check_result_detail_id,</if>
            <if test="checkProjectId != null">check_project_id,</if>
            <if test="checkProjectStatus != null">check_project_status,</if>
            <if test="checkProjectResult != null">check_project_result,</if>
            <if test="projectStepOrder != null">project_step_order,</if>
            <if test="standardValue != null">standard_value,</if>
            <if test="checkProjectName != null">check_project_name,</if>
            <if test="checkProjectProperty != null">check_project_property,</if>
            <if test="upperDiff != null">upper_diff,</if>
            <if test="downDiff != null">down_diff,</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="checkResultDetailId != null">#{checkResultDetailId},</if>
            <if test="checkProjectId != null">#{checkProjectId},</if>
            <if test="checkProjectStatus != null">#{checkProjectStatus},</if>
            <if test="checkProjectResult != null">#{checkProjectResult},</if>
            <if test="projectStepOrder != null">#{projectStepOrder},</if>
            <if test="standardValue != null">#{standardValue},</if>
            <if test="checkProjectName != null">#{checkProjectName},</if>
            <if test="checkProjectProperty != null">#{checkProjectProperty},</if>
            <if test="upperDiff != null">#{upperDiff},</if>
            <if test="downDiff != null">#{downDiff},</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="updateQmsCheckResultDetailProject" parameterType="QmsCheckResultDetailProject">
        update qms_check_result_detail_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="checkResultDetailId != null">check_result_detail_id = #{checkResultDetailId},</if>
            <if test="checkProjectId != null">check_project_id = #{checkProjectId},</if>
            <if test="checkProjectStatus != null">check_project_status = #{checkProjectStatus},</if>
            <if test="checkProjectResult != null">check_project_result = #{checkProjectResult},</if>
            <if test="projectStepOrder != null">project_step_order = #{projectStepOrder},</if>
            <if test="standardValue != null">standard_value = #{standardValue},</if>
            <if test="checkProjectName != null">check_project_name = #{checkProjectName},</if>
            <if test="checkProjectProperty != null">check_project_property = #{checkProjectProperty},</if>
            <if test="upperDiff != null">upper_diff = #{upperDiff},</if>
            <if test="downDiff != null">down_diff = #{downDiff},</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 result_detail_project_id = #{resultDetailProjectId}
    </update>

    <delete id="deleteQmsCheckResultDetailProjectByResultDetailProjectId" parameterType="Long">
        delete from qms_check_result_detail_project where result_detail_project_id = #{resultDetailProjectId}
    </delete>

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