<?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.reportclass.ERclassRankMapper">
    <!--校级报告-成绩分析-->
    <select id="listByExamId" resultType="java.util.Map">
        select err.ranktype,err.rankname,err.rankrange,err.stunum,err.sturate
        <if test="rank.ranktype!=null and rank.ranktype>=3">
        ,err.stujson
        </if>
        ,err.classid,(case when err.classid=0 then '全部班级' else c.classname end)classname
        from e_rclass_rank err left join t_class c on err.classid = c.classid
        where err.examid=#{rank.examid} and err.subjectid=#{rank.subjectid}
        <if test="rank.classid!=null and rank.classid!=0">
            and err.classid=#{rank.classid}
        </if>
        <foreach collection="rank.classids" item="classid" open="and err.classid in(0," separator="," close=")">
            ${classid}
        </foreach>
        <if test="rank.ranktype!=null and rank.ranktype!=0">
            and err.ranktype=#{rank.ranktype}
        </if>
        order by c.classtype,c.classorder,c.classid,err.rcrid
    </select>
    <!--班级报告-成绩分析-->
    <select id="listByExamAndClassId" resultType="java.util.Map">
        select err.ranktype,err.rankname,err.rankrange,err.stunum,err.stujson,err.sturate
        ,err.classid,(case when err.classid=0 then '全部班级' else ec.classname end)classname
        ,err.subjectid
        from e_rclass_rank err left join e_class ec on err.examid = ec.examid and err.classid = ec.classid
        where err.examid=#{rank.examid} and err.classid=#{rank.classid}
        <if test="rank.ranktype!=null and rank.ranktype!=0">
            and err.ranktype=#{rank.ranktype}
        </if>
        <if test="rank.subjectid!=null and rank.subjectid!=''">
            and err.subjectid=#{rank.subjectid}
        </if>
    </select>
    <!--班级报告-单科概况-等级统计-->
    <select id="listDkGkDjTj" resultType="java.util.Map">
        select err.ranktype,err.rankname,err.stunum,err.stujson,err.sturate,er.minscore,er.maxscore
        ,(case when er.linescore is null then '' else concat(er.linescore,'-',er.floatscore) end)rankrange
        from e_rclass_rank err left join e_rrank er on err.examid = er.examid and err.subjectid = er.subjectid
        and er.ranktype=1 and er.rankname=err.rankname
        where err.examid=#{rank.examid} and err.classid=#{rank.classid}
        and err.subjectid=#{rank.subjectid} and err.ranktype=1
    </select>
    <!--获取等级分类-->
    <select id="getRank" resultType="java.util.Map">
        select rankname,maxscore,minscore,linescore,floatscore
        from e_rrank where examid=#{rank.examid} and subjectid=#{rank.subjectid} and ranktype=#{rank.ranktype}
        <if test="rank.ranktype==1 || rank.ranktype==2">
            order by rankid asc
        </if>
        limit 1
    </select>
    <!--获取科目集合-->
    <select id="listSubjectByIds" resultType="java.util.Map">
        select subjectid,subjectname,subjectorder
        from t_subject where subjectid in
        <foreach collection="subjectids" item="subjectid" open="(" separator="," close=")">
            #{subjectid}
        </foreach>
        order by subjectorder,subjectid
    </select>
</mapper>
