<?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.srs.diagnostic.mapper.DiaReportStudentCompletionMapper">

    <resultMap type="DiaReportStudentCompletion" id="DiaReportStudentCompletionResult">
        <result property="completionId"    column="completionId"    />
        <result property="relId"    column="relId"    />
        <result property="itemId"    column="itemId"    />
        <result property="stuNo"    column="stu_no"    />
        <result property="completed"    column="completed"    />
        <result property="reason"    column="reason"    />
        <result property="improvementMeasures"    column="improvement_measures"    />
        <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="selectDiaReportStudentCompletionVo">
        select completionId, relId, itemId, stu_no, completed, reason, improvement_measures, create_by, create_time, update_by, update_time from dia_report_student_completion
    </sql>

    <select id="selectDiaReportStudentCompletionList" parameterType="DiaReportStudentCompletion" resultMap="DiaReportStudentCompletionResult">
        <include refid="selectDiaReportStudentCompletionVo"/>
        <where>
            <if test="relId != null "> and relId = #{relId}</if>
            <if test="itemId != null "> and itemId = #{itemId}</if>
            <if test="stuNo != null "> and stu_no = #{stuNo}</if>
            <if test="completed != null "> and completed = #{completed}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="improvementMeasures != null  and improvementMeasures != ''"> and improvement_measures = #{improvementMeasures}</if>
        </where>
    </select>

    <select id="selectDiaReportStudentCompletionByCompletionId" parameterType="Long" resultMap="DiaReportStudentCompletionResult">
        <include refid="selectDiaReportStudentCompletionVo"/>
        where completionId = #{completionId}
    </select>

    <insert id="insertDiaReportStudentCompletion" parameterType="DiaReportStudentCompletion" useGeneratedKeys="true" keyProperty="completionId">
        insert into dia_report_student_completion
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="relId != null">relId,</if>
            <if test="itemId != null">itemId,</if>
            <if test="stuNo != null">stu_no,</if>
            <if test="completed != null">completed,</if>
            <if test="reason != null">reason,</if>
            <if test="improvementMeasures != null">improvement_measures,</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="relId != null">#{relId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="stuNo != null">#{stuNo},</if>
            <if test="completed != null">#{completed},</if>
            <if test="reason != null">#{reason},</if>
            <if test="improvementMeasures != null">#{improvementMeasures},</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="updateDiaReportStudentCompletion" parameterType="DiaReportStudentCompletion">
        update dia_report_student_completion
        <trim prefix="SET" suffixOverrides=",">
            <if test="relId != null">relId = #{relId},</if>
            <if test="itemId != null">itemId = #{itemId},</if>
            <if test="stuNo != null">stu_no = #{stuNo},</if>
            <if test="completed != null">completed = #{completed},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="improvementMeasures != null">improvement_measures = #{improvementMeasures},</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 completionId = #{completionId}
    </update>

    <delete id="deleteDiaReportStudentCompletionByCompletionId" parameterType="Long">
        delete from dia_report_student_completion where completionId = #{completionId}
    </delete>

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