<?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.xhkjedu.smarking.mapper.exam.MsSubjectBadstudentMapper">

    <!--实时监控-班级下学生-->
    <select id="listClassStus" resultType="java.util.Map">
        select ms.studentid,ms.sstate,u.username as studentname
        from ms_paper_student ms
        left join ms_class_student cs on ms.examid=cs.examid and ms.subjectid=cs.subjectid and ms.studentid=cs.studentid
        left join t_user u on ms.studentid = u.userid
        where ms.msid=#{mi.msid} and cs.classid=#{mi.classid}
        <if test="mi.sstate!=null and mi.sstate!=-1">
            and ms.sstate=#{mi.sstate}
        </if>
        <if test="mi.createname!=null and mi.createname!=''">
            and u.username like '%${ei.createname}%'
        </if>
        order by convert(u.username using gbk),u.userid
    </select>

    <!--实时监控-学生进场、提交情况-->
    <select id="getSubjectStuInRate" resultType="java.util.Map">
        select count(ps.mpsid)stunum
        ,count(case when ps.sstate!=0 then ps.mpsid else null end)jcnum
        ,count(case when ps.sstate=0 then ps.mpsid else null end)wjcnum
        ,count(case when ps.sstate=2 then ps.mpsid else null end)tjcnum
        ,truncate(count(case when ps.sstate!=0 then ps.mpsid else null end)*100/count(*),2)jcrate
        from ms_paper_student ps
        left join ms_class_student cs on ps.examid=cs.examid and ps.subjectid=cs.subjectid and ps.studentid=cs.studentid
        where ps.msid=#{mi.msid}
        <if test="mi.classid!=null and mi.classid!=0">
            and cs.classid=#{mi.classid}
        </if>
        <if test="mi.classids!=null and mi.classids!=''">
            and cs.classid in(${mi.classids})
        </if>
    </select>

    <!--实时监控-学生违规照片-->
    <select id="listSubjectStuBadPics" resultType="java.util.Map">
        select ms.studentid,u.username,ms.badtype,ms.picpath,ms.createtime,c.classname
        from ms_subject_badstudent ms left join t_user u on ms.studentid = u.userid
        left join ms_subject s on ms.msid=s.msid
        left join ms_class_student cs on s.examid=cs.examid and s.subjectid=cs.subjectid and ms.studentid=cs.studentid
        left join ms_class c on cs.examid = c.examid and cs.subjectid=c.subjectid and cs.classid=c.classid
        where ms.msid=#{mi.msid}
        <if test="mi.classid!=null and mi.classid!=0">
            and cs.classid=#{mi.classid}
        </if>
        <if test="mi.classids!=null and mi.classids!=''">
            and cs.classid in(${mi.classids})
        </if>
        order by ms.msbsid desc, c.classtype
    </select>
</mapper>
