<?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.jkserver.dao.ExamStudentAnswerDao">

    <delete id="deleteById">
        delete t from jk_exam_student_answer t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
        </where>
    </delete>

    <select id="findByExamCode" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select * from jk_exam_student_answer t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndIsAbort" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select * from jk_exam_student_answer t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
            <if test="isAbort != null and isAbort != '' or isAbort == 0">
                and t.is_abort = #{isAbort}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndIsAbsent" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select * from jk_exam_student_answer t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
            <if test="isAbsent != null and isAbsent != '' or isAbsent == 0">
                and t.is_absent = #{isAbsent}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndIsCheat" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select * from jk_exam_student_answer t
        <where>
            <if test="examCode != null and examCode != ''">
                and t.exam_code = #{examCode}
            </if>
            <if test="isCheat != null and isCheat != '' or isCheat == 0">
                and t.is_cheat = #{isCheat}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndPlaceCodeAndRoomCodeCount" resultType="java.lang.Long">
        select
            count(1)
        from
            jk_exam_student_answer jesa
        join jk_exam_student jes on
            jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="placeCode != null and placeCode != ''">
                and jes.place_code = #{placeCode}
            </if>
            <if test="roomCode != null and roomCode != ''">
                and jes.room_code = #{roomCode}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndStageIdAndBatchIdAndPlaceCodeAndRoomCodeAndAbsentAndCheatAndAbortCount" resultType="java.lang.Long">
        select
        count(1)
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="stageId != null and stageId != ''">
                and jes.stage_id = #{stageId}
            </if>
            <if test="batchId != null and batchId != ''">
                and jes.batch_id = #{batchId}
            </if>
            <if test="placeCodeSet != null and placeCodeSet != '' and placeCodeSet.size > 0">
                and jes.place_code in
                <foreach collection="placeCodeSet" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="roomCode != null and roomCode != ''">
                and jes.room_code = #{roomCode}
            </if>
            <if test="absent != null and absent != '' or absent == 0">
                and jesa.is_absent = #{absent}
            </if>
            <if test="cheat != null and cheat != '' or cheat == 0">
                and jesa.is_cheat = #{cheat}
            </if>
            <if test="abort != null and abort != '' or abort == 0">
                and jesa.is_abort = #{abort}
            </if>
        </where>
    </select>

    <select id="findByExamCodeAndStageIdAndBatchIdAndPlaceCodeAndRoomCodeAndAbsentAndCheatAndAbortByIpage" resultType="java.util.Map">
        select
            jesa.id as id,
            jesa.exam_code as examCode,
            jesa.student_id as studentId,
            jesa.is_abort as isAbort,
            jesa.is_absent as isAbsent,
            jesa.is_cheat as isCheat,
            jesa.objective_answer as objectiveAnswer,
            jesa.paper_id as paperId,
            jesa.paper_name as paperName,
            jesa.answer_time as answerTime,
            jesa.answer_path as answerPath,
            jesa.decode_file_id as decodeFileId,
            jesa.progress_type as progressType,
            jesa.login_time as loginTime,
            jesa.`time`,
            jesa.student_id as studentId,
            jesa.original_answer_id as originalAnswerId,
            jesa.exam_task_id as examTaskId,
            jesa.task_sync_result as taskSyncResult,
            jes.batch_id as batchId,
            jes.batch_Name as batchName,
            jes.stage_id as stageId,
            jes.name as name,
            jes.place_code as placeCode,
            jes.room_code as roomCode,
            jes.course_name as courseName,
            jes.course_code as courseCode,
            jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="stageId != null and stageId != ''">
                and jes.stage_id = #{stageId}
            </if>
            <if test="batchId != null and batchId != ''">
                and jes.batch_id = #{batchId}
            </if>
            <if test="placeCodeSet != null and placeCodeSet != '' and placeCodeSet.size > 0">
                and jes.place_code in
                <foreach collection="placeCodeSet" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="roomCode != null and roomCode != ''">
                and jes.room_code = #{roomCode}
            </if>
            <if test="absent != null and absent != '' or absent == 0">
                and jesa.is_absent = #{absent}
            </if>
            <if test="cheat != null and cheat != '' or cheat == 0">
                and jesa.is_cheat = #{cheat}
            </if>
            <if test="abort != null and abort != '' or abort == 0">
                and jesa.is_abort = #{abort}
            </if>
        </where>
        order by jes.ticket_no,jes.course_code
    </select>

    <select id="findByExamCodeByTicketNo" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
                and jesa.objective_answer is not null and jesa.paper_id is not null and jesa.is_absent <![CDATA[ <> ]]> true
        </where>
    </select>

    <select id="findByExamCodeByPage" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            and jesa.objective_answer is not null and jesa.paper_id is not null and jesa.is_absent <![CDATA[ <> ]]> true
        </where>
        order by paper_id,jes.ticket_no
    </select>

    <select id="findByExamCodeByPaperNamePage" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            and jesa.paper_name is not null and jesa.is_absent <![CDATA[ <> ]]> true
        </where>
        order by jes.ticket_no
    </select>

    <select id="findByExamCodeByCourseCode" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and jes.course_code = #{courseCode}
            </if>
        </where>
        order by jes.course_code
    </select>

    <select id="findByExamCodeByPlaceCodeAndRoomCode" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="placeCode != null and placeCode != ''">
                and jes.place_code = #{placeCode}
            </if>
            <if test="roomCode != null and roomCode != ''">
                and jes.room_code = #{roomCode}
            </if>
        </where>
    </select>

    <select id="findByExamCodeByTicketNoDel" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="ticketNo != null and ticketNo != ''">
                and jes.ticket_no = #{ticketNo}
            </if>
        </where>
    </select>

    <select id="findByExamCodeByTicketNoAndCourseCode" resultType="com.qmth.jkserver.model.ExamStudentAnswer">
        select
        jesa.id as id,
        jesa.exam_code as examCode,
        jesa.student_id as studentId,
        jesa.is_abort as isAbort,
        jesa.is_absent as isAbsent,
        jesa.is_cheat as isCheat,
        jesa.objective_answer as objectiveAnswer,
        jesa.paper_id as paperId,
        jesa.paper_name as paperName,
        jesa.answer_time as answerTime,
        jesa.answer_path as answerPath,
        jesa.decode_file_id as decodeFileId,
        jesa.progress_type as progressType,
        jesa.login_time as loginTime,
        jesa.`time`,
        jesa.student_id as studentId,
        jesa.original_answer_id as originalAnswerId,
        jesa.exam_task_id as examTaskId,
        jesa.task_sync_result as taskSyncResult,
        jes.batch_id as batchId,
        jes.batch_Name as batchName,
        jes.stage_id as stageId,
        jes.name as name,
        jes.place_code as placeCode,
        jes.room_code as roomCode,
        jes.course_name as courseName,
        jes.course_code as courseCode,
        jes.ticket_no as ticketNo
        from
        jk_exam_student_answer jesa
        join jk_exam_student jes on
        jes.id = jesa.student_id
        <where>
            <if test="examCode != null and examCode != ''">
                and jesa.exam_code = #{examCode}
            </if>
            <if test="ticketNo != null and ticketNo != ''">
                and jes.ticket_no = #{ticketNo}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and jes.course_code = #{courseCode}
            </if>
        </where>
    </select>

</mapper>
