<?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.report.business.mapper.TBExamCourseMapper">

    <select id="findCourseList" resultType="com.qmth.teachcloud.report.business.bean.result.TBExamCourseResult">
        select DISTINCT tbs.course_code,tbs.course_name from t_b_exam_student tbs
        join basic_course bc
        on tbs.course_code = bc.code
        join sys_org so on
        <choose>
            <when test="inspect != null and inspect == true">
                so.id = tbs.inspect_college_id and tbs.absent = 0
            </when>
            <otherwise>
                so.id = tbs.teach_college_id
            </otherwise>
        </choose>
        <if test="filter != null and filter == true">
            join t_b_exam_course tbec on
            tbec.course_code = bc.code and tbec.exam_id = tbs.exam_id
        </if>
        <where>
            <if test="examId != null and examId != ''">
                and tbs.exam_id = #{examId}
            </if>
            <if test="schoolId != null and schoolId != ''">
                and bc.school_id = #{schoolId}
            </if>
            <if test="absent != null and absent != ''">
                and tbs.absent = #{absent}
            </if>
            <if test="current != null and current != ''">
                and tbs.student_current = #{current}
            </if>
            <if test="collegeIds != null and collegeIds != '' and collegeIds.size > 0">
                <choose>
                    <when test="inspect != null and inspect == true">
                        and tbs.inspect_college_id in
                    </when>
                    <otherwise>
                        and tbs.teach_college_id in
                    </otherwise>
                </choose>
                <foreach collection="collegeIds" item="collegeId" index="index" open="(" separator="," close=")">
                    #{collegeId}
                </foreach>
            </if>
            <if test="filter != null and filter == true">
                and tbec.publish_status = 'PUBLISH'
            </if>
        </where>
    </select>

    <select id="findCourseListByTeacherId" resultType="com.qmth.teachcloud.report.business.bean.result.TBExamCourseResult">
        select DISTINCT tbs.course_code,tbs.course_name from t_b_exam_student tbs
        join basic_course bc
        on tbs.course_code = bc.code
        join t_b_exam_course tbec on
        tbec.course_code = tbs.course_code
        <where>
            <if test="examId != null and examId != ''">
                and tbs.exam_id = #{examId}
            </if>
            <if test="schoolId != null and schoolId != ''">
                and bc.school_id = #{schoolId}
            </if>
            <if test="teacherId != null and teacherId != ''">
                and tbs.teacher_id = #{teacherId}
            </if>
            <if test="absent != null">
                and tbs.absent = #{absent}
            </if>
            <if test="current != null">
                and tbs.student_current = #{current}
            </if>
            <if test="status != null and status != ''">
                and tbec.publish_status = #{status}
            </if>
        </where>
    </select>
</mapper>
