<?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.TtTestPaperDetailMapper">

    <resultMap id="BaseResultMap" type="com.ruoyi.project.business.domain.train.TtTestPaperDetail">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="testPaperId" column="test_paper_id" jdbcType="BIGINT"/>
        <result property="questionId" column="question_id" jdbcType="BIGINT"/>
        <result property="questionScore" column="question_score" jdbcType="DECIMAL"/>
        <result property="sortIndex" column="sort_index" jdbcType="BIGINT"/>
        <result property="delFlag" column="del_flag" jdbcType="CHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="createBy" column="create_by" jdbcType="BIGINT"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="BIGINT"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,test_paper_id,question_id,
        question_score,sort_index,del_flag,
        create_time,create_by,update_time,
        update_by,remark
    </sql>

    <insert id="batchInsert" parameterType="ttTestPaperDetail" useGeneratedKeys="true" keyProperty="id">
        insert into tt_test_paper_detail
        (test_paper_id,question_id,question_score,sort_index,del_flag,create_time, create_by,update_time,update_by,remark) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.testPaperId},#{item.questionId},#{item.questionScore},#{item.sortIndex},#{item.delFlag},#{item.createTime},#{item.createBy},#{item.updateTime},#{item.updateBy},#{item.remark})
        </foreach>
    </insert>

    <select id="selectTestPaperDetailList"
            resultType="com.ruoyi.project.business.domain.vo.train.TtTestPaperDetailVo">
        select pd.*,qd.correct_answer,qd.question_context,qd.question_type,qd.option1,qd.option2,qd.option3,
               qd.option4,qd.option5,qd.option6,qd.option7,qd.option8,qd.option9,qd.option10,qd.status,ar.answer_content,ar.score getScore
        from tt_test_paper_detail pd
        inner join tt_question_database qd on pd.question_id = qd.id and qd.del_flag = '0'
        left join tt_assess_result ar on ar.test_paper_detail_id = pd.id and ar.del_flag != '1' and ar.train_target_id = #{loginUserId}
        <where>
            pd.del_flag != '1'
            <if test="testPaperId != null and testPaperId != ''"> and pd.test_paper_id = #{testPaperId}</if>
        </where>
    </select>

</mapper>
