<?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.ERclassMapper">
    <!--校级报告-成绩分析-->
    <select id="listByExamId" resultType="java.util.Map">
        select er.allscore,er.classmaxscore,er.classminscore,er.classavgscore,er.schoolmaxscore,er.schoolavgscore
        ,er.stunum,er.missnum,er.yxrate,er.lhrate,er.jgrate,er.dfrate,er.bzc,er.qkbzc,er.subjectname
        ,er.classid,(case when er.classid=0 then '全部班级' else ec.classname end)classname
        from e_rclass er left join e_class ec on er.examid = ec.examid and er.classid = ec.classid
        where er.examid=#{rank.examid}
        <if test="rank.subjectid!=null and rank.subjectid!=''">
            and er.subjectid=#{rank.subjectid}
        </if>
        <if test="rank.classid!=null and rank.classid!=0">
            and er.classid=#{rank.classid}
        </if>
        <foreach collection="rank.classids" item="classid" open="and er.classid in(0," separator="," close=")">
            ${classid}
        </foreach>
    </select>
    <!--班级报告-学科成绩-->
    <select id="listByExamAndClassId" resultType="java.util.Map">
        select er.allscore,er.classmaxscore,er.classminscore,er.classavgscore,er.schoolmaxscore,er.schoolavgscore
        ,er.stunum,er.missnum,er.yxrate,er.lhrate,er.jgrate,er.dfrate,er.bzc,er.qkbzc
        ,er.classid,(case when er.classid=0 then '全部班级' else ec.classname end)classname
        ,(case when er.subjectid='zf' then '总分' else (select s.subjectname from t_subject s where
                er.subjectid=s.subjectid) end)subjectname
        from e_rclass er left join e_class ec on er.examid = ec.examid and er.classid = ec.classid
        where er.examid=#{examid} and er.classid=#{classid}
    </select>
    <!--班级报告-单科概况-班级概况-->
    <select id="findById" resultType="java.util.Map">
        select er.classmaxscore,er.classavgscore,er.classavgscorerank,er.schoolmaxscore,er.schoolavgscore
        ,er.yxrate,er.jgrate
        from e_rclass er
        where er.examid=#{rank.examid} and er.classid=#{rank.classid} and er.subjectid=#{rank.subjectid}
        limit 1
    </select>
    <!--班级报告-单科概况-平均分-->
    <select id="listPjf" resultType="java.util.Map">
        select er.classavgscore,ec.classname,er.classid
        from e_rclass er left join e_class ec on er.examid = ec.examid and er.classid = ec.classid
        where er.examid=#{rank.examid} and er.subjectid=#{rank.subjectid}
    </select>
    <!--班级报告-单科概况-成绩等级分布-->
    <select id="listCjDj" resultType="java.util.Map">
        select er.rankname,concat(er.floatscore,'-',er.linescore)rankrange,err.stunum,err.stujson
        from e_rrank er left join e_rclass_rank err on er.examid = err.examid and er.subjectid = err.subjectid
        where er.examid=#{rank.examid} and err.classid=#{rank.classid}
        and er.subjectid=#{rank.subjectid} and er.ranktype=1
    </select>
    <!--班级报告-单科概况-需关注学生-->
    <select id="listGzXs" resultType="java.util.Map">
        select u.username,er.score,er.classrank,er.classrankpre,er.goal
        <if test="rank.ranktype==3">,es.score*0.6 hgscore</if>
        from e_rstudent er left join t_user u on er.studentid=u.userid
        <if test="rank.ranktype==3">
            left join e_rsubject es on er.examid = es.examid and es.subjectid=er.subjectid
        </if>
        where er.examid=#{rank.examid} and er.classid=#{rank.classid} and er.subjectid=#{rank.subjectid}
        <if test="rank.ranktype==1">
            and er.classrankpre>=5
        </if>
        <if test="rank.ranktype==2">
            and er.classrankpre&lt;=-5
        </if>
        <if test="rank.ranktype==3">
            and abs(es.score*0.6-er.score) between 0.01 and 5
        </if>
        <if test="rank.ranktype==4">
            and abs(er.classrankpre)>=10
        </if>
    </select>
    <!--班级报告-单科概况-高频错题-->
    <select id="listGpCt" resultType="java.util.Map">
        select erq.eptqid,erq.qn,erq.classsrate,erq.gradesrate,erq.answerjson,erq.erroroption
        ,epq.eptname,epq.ctype,epqq.answer,epa.pointjson
        from e_rclass_question erq left join e_paper_qtype_question epqq on erq.epid = epqq.epid and erq.qorder=epqq.qorder
        left join e_paper_qtype epq on epqq.eptid = epq.eptid
        left join e_paper_analyze epa on erq.epid = epa.epid
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid} and erq.classsrate&lt;40
        group by erq.qorder
    </select>
</mapper>
