<?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.sexam.mapper.report.EReportSchoolMapper">
    <!--删除考试等级报告-->
    <delete id="delByExamAndSubjectId">
        delete from e_rclass_rank where examid=#{examid} and subjectid=#{subjectid} and ranktype=#{ranktype};
        delete from e_rrank where examid=#{examid} and subjectid=#{subjectid} and ranktype=#{ranktype};
    </delete>
    <!--行为分析-班级-->
    <select id="listXwBj" resultType="java.util.Map">
        select ec.classname,ca.classid,ca.subjectjson
        from e_rclass_action ca left join e_class ec on ca.examid = ec.examid and ca.classid = ec.classid
        where ca.examid=#{rank.examid} and ca.actiontype=#{rank.actiontype}
        <if test="rank.classid!=null and rank.classid!=0">
            and ca.classid=#{rank.classid}
        </if>
        <foreach collection="rank.classids" item="classid" open="and ca.classid in(0," separator="," close=")">
            ${classid}
        </foreach>
    </select>
    <!--行为分析-学生-->
    <select id="listXwXs" resultType="java.util.Map">
        select ec.classname,sa.classid,sa.studentid,sa.subjectjson,u.username,u.loginname
        from e_rstudent_action sa left join e_class ec on sa.examid = ec.examid and sa.classid = ec.classid
        left join t_user u on sa.studentid=u.userid
        where sa.examid=#{rank.examid} and sa.actiontype=#{rank.actiontype}
        <if test="rank.classid!=null and rank.classid!=0">
            and sa.classid=#{rank.classid}
        </if>
        <foreach collection="rank.classids" item="classid" open="and sa.classid in(0," separator="," close=")">
            ${classid}
        </foreach>
        <if test="rank.createname!=null and rank.createname!=''">
            and (u.username like '%${rank.createname}%' or u.loginname like '%${rank.createname}%')
        </if>
    </select>
    <!--违纪行为分析-详情-->
    <select id="listWjXq" resultType="java.util.Map">
        select s.subjectname,sb.badtype,sb.picpath,sb.createtime
        from e_subject_badstudent sb left join e_subject s on sb.esid=s.esid
        where sb.examid=#{rank.examid}
        <if test="rank.studentid!=null and rank.studentid!=0">
            and sb.studentid=#{rank.studentid}
        </if>
        <if test="rank.classid!=null and rank.classid!=0">
            and sb.classid=#{rank.classid}
        </if>
        <if test="rank.subjectid!=null and rank.subjectid!=''">
            and s.subjectid=#{rank.subjectid}
        </if>
        order by sb.esbsid
    </select>
    <!--等级分类列表-->
    <select id="listDjFl" resultType="java.util.Map">
        select ranktype,rankname,maxscore,minscore,linescore,floatscore
        from e_rrank where examid=#{rank.examid} and ranktype=#{rank.ranktype} and subjectid=#{rank.subjectid}
    </select>

    <!--校级报告列表-->
    <resultMap id="listExamEndResult" type="java.util.Map">
        <result property="examid" column="examid"></result>
        <result property="examname" column="examname"></result>
        <result property="examdate" column="examdate"></result>
        <result property="gradeid" column="gradeid"></result>
        <result property="examtype" column="examtype"></result>
        <result property="exammode" column="exammode"></result>
        <collection property="subjects" ofType="java.util.Map" javaType="java.util.List">
            <result property="esid" column="esid"></result>
            <result property="subjectid" column="subjectid"></result>
            <result property="subjectname" column="subjectname"></result>
        </collection>
    </resultMap>
    <select id="listEndExams" resultMap="listExamEndResult">
        select e.examid,e.examname,e.examdate,e.gradeid,e.examtype,e.exammode,e.monitored
             ,s.esid,s.subjectid,s.subjectname
        from e_base e left join e_subject s on e.examid=s.examid
        where e.schoolid=#{ebase.schoolid} and e.examstate=2 and e.deleted=1 and s.pstate=2
        <if test="ebase.gradeid!=null and ebase.gradeid!=0">
            and e.gradeid=#{ebase.gradeid}
        </if>
        <if test="ebase.begindate!=null and ebase.begindate!=''">
            and e.examdate between #{ebase.begindate} and #{ebase.enddate}
        </if>
        order by e.examdate desc, s.esid asc
    </select>
    <!--行为分析-班级-->
    <select id="listXwBjByExamId" resultType="java.util.Map">
        select ec.classname,ca.classid,ca.subjectjson,ca.actiontype
        from e_rclass_action ca left join e_class ec on ca.examid = ec.examid and ca.classid = ec.classid
        where ca.examid=#{examid}
    </select>
    <!--考试班级等级分布-->
    <select id="listCjFxByExamId" resultType="java.util.Map">
        select err.ranktype,err.rankname,err.rankrange,err.stunum,err.sturate,err.subjectid
        ,(case when err.ranktype>=3 then err.stujson else '' end)stujson
        ,err.classid,(case when err.classid=0 then '全部班级' else ec.classname end)classname
        from e_rclass_rank err left join e_class ec on err.examid = ec.examid and err.classid = ec.classid
        where err.examid=#{examid}
    </select>
    <!--考试等级分类-->
    <select id="listRankByExamId" resultType="java.util.Map">
        select rankname,maxscore,minscore,linescore,floatscore,subjectid,ranktype
        from e_rrank where examid=#{examid}
        group by subjectid,ranktype order by rankid
    </select>
</mapper>
