<?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.qmth.teachcloud.mark.mapper.ScanPaperMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.mark.entity.ScanPaper">
        <id column="id" property="id"/>
        <result column="exam_id" property="examId"/>
        <result column="card_number" property="cardNumber"/>
        <result column="number" property="number"/>
        <result column="page_count" property="pageCount"/>
        <result column="mismatch" property="mismatch"/>
        <result column="assigned" property="assigned"/>
        <result column="question_filled" property="questionFilled"/>
        <result column="creator_id" property="creatorId"/>
        <result column="updater_id" property="updaterId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>
    <select id="listStudentPaperDetail" resultType="com.qmth.teachcloud.mark.dto.mark.score.StudentPaperDetailDto">
        SELECT ssp.student_id  studentId,
               ssp.paper_index paperIndex,
               ssp.paper_id    paperId,
               sp.card_number  cardNumber,
               spp.page_index  pageIndex,
               spp.sheet_path  sheetPath,
               spp.recog_data  recogData
        FROM (SELECT student_id,
                     paper_index,
                     paper_id
              FROM scan_student_paper
              WHERE student_id = #{studentId}) ssp
                 JOIN
             scan_paper sp ON ssp.paper_id = sp.id
                 AND ssp.paper_index = sp.number
                 JOIN
             scan_paper_page spp ON sp.id = spp.paper_id
        ORDER BY ssp.paper_index, spp.page_index
    </select>
    <select id="findStudentPaper"
            resultType="com.qmth.teachcloud.mark.bean.scanpaper.PaperVo">
        SELECT p.id,
               t.paper_index number,
               b.id          batchId,
               u.login_name  userName,
               p.create_time createTime,
               p.mismatch
        FROM scan_student_paper t
                 inner join scan_paper p on t.paper_id = p.id
                 left join scan_batch_paper bp on bp.paper_id = p.id
                 left join scan_batch b on bp.batch_id = b.id
                 left join sys_user u on b.user_id = u.id
        WHERE t.student_id = #{studentId}
        ORDER BY t.paper_index
    </select>
    <select id="listByStudentIds"
            resultType="com.qmth.teachcloud.mark.bean.scananswer.StudentPaperVo">
        SELECT
        t.paper_id,
        t.student_id,
        t.paper_index number,
        p.assigned,
        p.invalid
        FROM
        scan_student_paper t
        inner join scan_paper p on t.paper_id=p.id
        WHERE 1=2
        <foreach collection="studentIds" index="index" item="studentId">
            or t.student_id=#{studentId}
        </foreach>
        order by t.paper_index
    </select>
</mapper>
