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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.distributed.print.business.entity.TBTaskPdf">
        <id column="id" property="id" />
        <result column="school_id" property="schoolId" />
        <result column="semester_id" property="semesterId" />
        <result column="exam_id" property="examId" />
        <result column="print_plan_id" property="printPlanId" />
        <result column="course_name_code" property="courseNameCode" />
        <result column="paper_number" property="paperNumber" />
        <result column="create_type" property="createType" />
        <result column="status" property="status" />
        <result column="summary" property="summary" />
        <result column="result" property="result" />
        <result column="create_id" property="createId" />
        <result column="create_time" property="createTime" />
        <result column="update_id" property="updateId" />
        <result column="update_time" property="updateTime" />
        <result column="remark" property="remark" />
    </resultMap>
    <select id="pageData" resultType="com.qmth.teachcloud.common.bean.result.TaskPdfResult">
        SELECT
            tp.id,
            tp.exam_id,
            epp.name print_plan_name,
            tp.course_name_code,
            tp.paper_number,
            tp.create_type,
            tp.status,
            tp.result,
            tp.summary,
            ed.exam_place,
            ed.exam_room,
            ed.exam_start_time,
            ed.exam_end_time
        FROM
            t_b_task_pdf tp
                LEFT JOIN
            exam_detail ed ON tp.id = ed.id
                LEFT JOIN
            exam_print_plan epp ON tp.print_plan_id = epp.id
        <where>
            tp.exam_id = #{examId}
            <if test="printPlanId != null">
                and tp.print_plan_id = #{printPlanId}
            </if>
            <if test="courseCode != null">
                and exists (select 1 from exam_detail_course edc where ed.id = edc.exam_detail_id and edc.course_code = #{courseCode})
            </if>
            <if test="paperNumber != null">
                and exists (select 1 from exam_detail_course edc where ed.id = edc.exam_detail_id and edc.paper_number = #{paperNumber})
            </if>
            <if test="status != null">
                and tp.status = #{status}
            </if>
            <if test="result != null">
                and tp.result = #{result}
            </if>
            <if test="examPlace != null">
                and ed.exam_place = #{examPlace}
            </if>
            <if test="examRoom != null">
                and ed.exam_room = #{examRoom}
            </if>
            <if test="examStartTime != null">
                and ed.exam_start_time &gt;= #{examStartTime}
            </if>
            <if test="examEndTime != null">
                and ed.exam_end_time &lt;= #{examEndTime}
            </if>
        </where>
        order by tp.id desc
    </select>

</mapper>
