<?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.distributed.print.business.mapper.TSyncExamLogMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.distributed.print.business.entity.TSyncExamLog">
        <result column="id" property="id"/>
        <result column="school_id" property="schoolId"/>
        <result column="semester_id" property="semesterId"/>
        <result column="exam_id" property="examId"/>
        <result column="exam_name" property="examName"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="status" property="status"/>
        <result column="result" property="result"/>
        <result column="total_courses" property="totalCourses"/>
        <result column="total_exam_tasks" property="totalExamTasks"/>
        <result column="total_students" property="totalStudents"/>
        <result column="success_students" property="successStudents"/>
        <result column="fail_students" property="failStudents"/>
        <result column="error_file_path" property="errorFilePath"/>
        <result column="create_id" property="createId"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, school_id, exam_id, exam_name, start_time, end_time, status, `result`, total_courses, total_exam_tasks, total_students,success_students,fail_students, error_file_path, create_id, create_time
    </sql>

    <select id="list" resultType="com.qmth.distributed.print.business.entity.TSyncExamLog">
        SELECT DISTINCT
            ets.third_relate_id thirdRelateId,
            tsse.exam_name examName
        FROM
            exam_task_sync ets
                LEFT JOIN
            t_sync_stmms_exam tsse ON ets.third_relate_id = tsse.exam_id
        WHERE
            ets.sync_status = 'FINISH'
          AND ets.third_relate_id IS NOT NULL
          AND EXISTS( SELECT
                          1
                      FROM
                          exam_task et
                              JOIN
                          basic_exam be ON et.school_id = be.school_id
                              AND et.exam_id = be.id
                      WHERE
                          ets.school_id = et.school_id
                        AND ets.exam_id = et.exam_id
                        AND ets.paper_number = et.paper_number
                        AND be.semester_id = #{semesterId}
                        AND be.id = #{examId})
    </select>
</mapper>