<?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.mark.mapper.MarkUserClassMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.mark.entity.MarkUserClass">
        <id column="Id" property="id" />
        <result column="exam_id" property="examId" />
        <result column="paper_number" property="paperNumber" />
        <result column="user_id" property="userId" />
        <result column="class_name" property="className" />
    </resultMap>
    <select id="listClassMarkerByExamIdAndPaperNumberAndGroupNumberAndClassName"
            resultType="com.qmth.teachcloud.common.bean.dto.mark.MarkUser">
        SELECT
            su.id userId,
            su.login_name loginName,
            su.real_name name,
            so.name orgName
        FROM
            mark_user_class muc
                LEFT JOIN
            mark_user_group mug ON muc.exam_id = mug.exam_id AND muc.paper_number = mug.paper_number AND muc.user_id = mug.user_id
                LEFT JOIN
            sys_user su ON muc.user_id = su.id
                LEFT JOIN
            sys_org so ON su.org_id = so.id
        WHERE
            muc.exam_id = #{examId}
          AND muc.paper_number = #{paperNumber}
          AND mug.group_number = #{groupNumber}
          AND muc.class_name = #{className}
    </select>
    <select id="pageClassByExamIdAndPaperNumber"
            resultType="com.qmth.teachcloud.mark.dto.mark.manage.MarkGroupClassProgressDto">
        SELECT
            distinct mg.number groupNumber, muc.class_name className
        FROM mark_group mg
                LEFT JOIN
            mark_user_class muc ON mg.exam_id = muc.exam_id AND mg.paper_number = muc.paper_number
        WHERE
            mg.exam_id = #{examId}
          AND mg.paper_number = #{paperNumber}
            <if test="className != null and className != ''">
                AND muc.class_name = #{className}
            </if>
        ORDER BY  muc.class_name, mg.number
    </select>
    <select id="listMarkerClassByExamIdAndPaperNumberAndUserId"
            resultType="com.qmth.teachcloud.mark.entity.MarkUserClass">
        SELECT
            muc.*
        FROM
            mark_user_class muc
        WHERE
            muc.exam_id = #{examId}
          AND muc.paper_number = #{paperNumber}
          AND muc.user_id = #{userId}
    </select>

</mapper>
