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

    <select id="scoreList" resultType="com.qmth.distributed.print.business.bean.result.ScoreResult">
        SELECT distinct
                 bs.id as semesterId,
                 tc.exam_id as examId,
                 tc.course_code as courseCode,
                 bc.name as courseName,
                 tc.id AS obeCourseOutlineId,
                 creator.real_name AS userName,
                 creator.login_name AS userLoginName
        FROM
            teach_course tc
            left join basic_exam be on be.id = tc.exam_id
            left join basic_semester bs on bs.id = be.semester_id
            left join basic_course bc on bc.code = tc.course_code and bc.school_id = be.school_id
            left join sys_user su on tc.user_id = su.id
            left join sys_user creator on creator.id = tc.user_id
        <where>
            <if test="examId != null and examId != ''">
                and tc.exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and tc.course_code = #{courseCode}
            </if>
            <if test="dpr != null">
                <if test="dpr.requestUserId != null">
                    AND tc.user_id = #{dpr.requestUserId}
                </if>
                <if test="dpr.courseUserId != null">
                    AND tc.user_id = #{dpr.courseUserId}
                </if>
                <if test="dpr.orgIdSet != null and dpr.orgIdSet != '' and dpr.orgIdSet.size > 0">
                    AND su.org_id IN
                    <foreach collection="dpr.orgIdSet" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        </where>
        ORDER BY tc.course_code
    </select>

    <select id="usualScoreList" resultType="com.qmth.distributed.print.business.entity.TCUsualScore">
        select * from t_c_usual_score t
        <where>
            <if test="examId != null and examId != ''">
                and t.exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and t.course_code = #{courseCode}
            </if>
            <if test="paperNumber != null and paperNumber != ''">
                and t.paper_number = #{paperNumber}
            </if>
            <if test="obeCourseOutlineId != null and obeCourseOutlineId != ''">
                and t.teach_course_id = #{obeCourseOutlineId}
            </if>
        </where>
        order by t.student_code
    </select>
</mapper>
