<?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.paper.library.business.mapper.DocManageMapper">
    <select id="pageData" resultType="com.qmth.paper.library.business.bean.result.DocManageResult">
        SELECT
            pst.id paperScanTaskId,
            bs.name semesterName,
            be.name examName,
            pst.course_code courseCode,
            pst.course_name courseName,
            pst.student_count studentCount,
            pst.scan_student_count scanStudentCount
        FROM
            paper_scan_task pst
                LEFT JOIN
            basic_exam be ON pst.exam_id = be.id
                LEFT JOIN
            basic_semester bs ON be.semester_id = bs.id
        <where>
            be.semester_id = #{semesterId}
            <if test="examId != null ">
                and pst.exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and pst.course_code = #{courseCode}
            </if>
        </where>
    </select>
    <select id="statData" resultType="com.qmth.paper.library.business.bean.result.DocManageStatResult">
        SELECT
            count(distinct pst.course_code) courseCount,
            count(pl.id) pictureCount
        FROM
            paper_scan_task pst
                LEFT JOIN
            paper_library pl ON pst.id = pl.paper_scan_task_id
                LEFT JOIN
            basic_exam be ON pst.exam_id = be.id
        <where>
            be.semester_id = #{semesterId}
            <if test="examId != null ">
                and pst.exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and pst.course_code = #{courseCode}
            </if>
        </where>
    </select>
    <select id="pageDetail" resultType="com.qmth.paper.library.business.bean.result.DocManageDetailResult">
        SELECT
            es.id studentId,
            es.exam_id examId,
            es.student_name studentName,
            es.student_code studentCode,
            es.course_code courseCode,
            es.course_name courseName,
            es.teacher,
            es.teach_class teachClass,
            es.college_name collegeName,
            es.major_name majorName,
            es.class_name className,
            es.exam_room examRoom,
            es.score,
            es.remark,
            es.bind_count bindCount
        FROM
            exam_student es
                LEFT JOIN
            paper_scan_task pst ON es.exam_id = pst.exam_id and es.course_code = pst.course_code
        <where>
            pst.id = #{paperScanTaskId}
            <if test="collegeName != null and collegeName != ''">
                and es.college_name like concat(#{collegeName},'%')
            </if>
            <if test="majorName != null and majorName != ''">
                and es.major_name like concat(#{majorName},'%')
            </if>
            <if test="className != null and className != ''">
                and es.class_name like concat(#{className},'%')
            </if>
            <if test="examRoom != null and examRoom != ''">
                and es.exam_room like concat(#{examRoom}, '%')
            </if>
            <if test="teacher != null and teacher != ''">
                and es.teacher like concat(#{teacher},'%')
            </if>
            <if test="teachClass != null and teachClass != ''">
                and es.teach_class like concat(#{teachClass},'%')
            </if>
            <if test="isBind != null">
                <if test="isBind == true">
                    and es.bind_count > 0
                </if>
                <if test="isBind == false">
                    and es.bind_count = 0
                </if>
            </if>
            <if test="param != null and param != ''">
                and (es.student_name like concat(#{param},'%') or es.student_code like concat(#{param},'%'))
            </if>
            <if test="minScore != null">
                and es.score &gt;= #{minScore}
            </if>
            <if test="maxScore != null">
                and es.score &lt;= #{maxScore}
            </if>
            <if test="minBindCount != null">
                and es.bind_count &gt;= #{minBindCount}
            </if>
            <if test="maxBindCount != null">
                and es.bind_count &lt;= #{maxBindCount}
            </if>
            <if test="pictureSymbol != null and pictureSymbol !='' and pictureCount != null">
                <if test="pictureSymbol == 'GREAT_THEN'">
                    and es.bind_count > #{pictureCount}
                </if>
                <if test="pictureSymbol == 'EQUAL'">
                    and es.bind_count = #{pictureCount}
                </if>
                <if test="pictureSymbol == 'LESS_THEN'">
                    and es.bind_count <![CDATA[< #{pictureCount} ]]>
                </if>
                <if test="pictureSymbol == 'NOT_EQUAL'">
                    and es.bind_count != #{pictureCount}
                </if>
            </if>
        </where>
        order by pst.scan_task_name, es.student_code
    </select>
    <select id="listDetail" resultType="com.qmth.paper.library.business.bean.result.DocManageDetailResult">
        SELECT
            es.id studentId,
            es.exam_id examId,
            es.student_name studentName,
            es.student_code studentCode,
            es.course_code courseCode,
            es.course_name courseName,
            es.teacher,
            es.teach_class teachClass,
            es.college_name collegeName,
            es.major_name majorName,
            es.class_name className,
            es.score,
            es.remark,
            es.bind_count bindCount,
            es.file_path filePath
        FROM
            exam_student es
                LEFT JOIN
            paper_scan_task pst ON es.exam_id = pst.exam_id and es.course_code = pst.course_code
        <where>
            pst.id = #{paperScanTaskId}
            <if test="ids != null and ids.size > 0">
                AND es.id IN
                <foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
</mapper>