<?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.ruoyi.project.business.mapper.TtAssessResultMapper">
    
    <resultMap type="TtAssessResult" id="TtAssessResultResult">
        <result property="id"    column="id"    />
        <result property="testPaperDetailId"    column="test_paper_detail_id"    />
        <result property="trainTargetId"    column="train_target_id"    />
        <result property="answerContent"    column="answer_content"    />
        <result property="score"    column="score"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTtAssessResultVo">
        select id, test_paper_detail_id, train_target_id, answer_content, score, del_flag, create_time, create_by, update_time, update_by, remark from tt_assess_result
    </sql>

    <select id="selectTtAssessResultList" parameterType="TtAssessResult" resultMap="TtAssessResultResult">
        <include refid="selectTtAssessResultVo"/>
        <where>  
            <if test="testPaperDetailId != null "> and test_paper_detail_id = #{testPaperDetailId}</if>
            <if test="trainTargetId != null "> and train_target_id = #{trainTargetId}</if>
            <if test="answerContent != null  and answerContent != ''"> and answer_content = #{answerContent}</if>
            <if test="score != null "> and score = #{score}</if>
        </where>
    </select>
    
    <select id="selectTtAssessResultById" parameterType="Long" resultMap="TtAssessResultResult">
        <include refid="selectTtAssessResultVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTtAssessResult" parameterType="TtAssessResult" useGeneratedKeys="true" keyProperty="id">
        insert into tt_assess_result
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="testPaperDetailId != null">test_paper_detail_id,</if>
            <if test="trainTargetId != null">train_target_id,</if>
            <if test="answerContent != null">answer_content,</if>
            <if test="score != null">score,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="testPaperDetailId != null">#{testPaperDetailId},</if>
            <if test="trainTargetId != null">#{trainTargetId},</if>
            <if test="answerContent != null">#{answerContent},</if>
            <if test="score != null">#{score},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <insert id="insertTtAssessResultBatch">
        insert into tt_assess_result
            (test_paper_detail_id, train_target_id, answer_content, score, del_flag, create_time, create_by, update_time, update_by, remark)
        values
            <foreach item="item" collection="list" separator=",">
                (#{item.testPaperDetailId}, #{item.trainTargetId},
                 #{item.answerContent}, #{item.score}, #{item.delFlag},
                 #{item.createTime}, #{item.createBy}, #{item.updateTime},
                 #{item.updateBy}, #{item.remark})
            </foreach>
    </insert>

    <update id="updateTtAssessResult" parameterType="TtAssessResult">
        update tt_assess_result
        <trim prefix="SET" suffixOverrides=",">
            <if test="testPaperDetailId != null">test_paper_detail_id = #{testPaperDetailId},</if>
            <if test="trainTargetId != null">train_target_id = #{trainTargetId},</if>
            <if test="answerContent != null">answer_content = #{answerContent},</if>
            <if test="score != null">score = #{score},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTtAssessResultById" parameterType="Long">
        delete from tt_assess_result where id = #{id}
    </delete>

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