<?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.EReportClassMapper">
    <!--试卷基本信息-->
    <select id="getPaperByExamSubjectId" resultType="java.util.Map">
        select ep.epid,ep.ptype,eb.examname,epa.pointjson
        from e_paper ep left join e_base eb on ep.examid = eb.examid
        left join e_paper_analyze epa on ep.epid = epa.epid
        where ep.examid=#{rank.examid} and ep.subjectid=#{rank.subjectid} limit 1
    </select>
    <!--试卷概况-题库-->
    <select id="listTkSjGk" resultType="java.util.Map">
        select erq.qn,erq.qorder,erq.classratetype
        ,erq.answerjson,erq.fullscorenum,erq.goodstujson,erq.badstujson,erq.questionid,erq.eptqid,erq.complexity,erq.score
        <if test="rank.showrank==0">
            ,0 classavgscore,0 classsrate,0 gradeavgscore,0 gradesrate
        </if>
        <if test="rank.showrank!=0">
            ,erq.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        </if>
        from e_rclass_question erq
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid}
        <if test="rank.ranktype==1">order by erq.qorder</if>
        <if test="rank.ranktype==2">order by erq.classsrate</if>
    </select>
    <select id="listTkQuestion" resultType="java.util.Map">
        select epqq.eptqid,epqq.ctype,epqq.score,epqq.answer,epqq.qtypename,epqq.questionid,epqq.qn,epqq.qorder
        ,q.questionpid,q.qstem,q.qoption,q.qanalyze,q.hashear,q.hearfile
        ,mq.questionid mquestionid,mq.qstem mqstem,mq.qanalyze mqanalyze,mq.ctype mctype
        ,mq.qtypename mqtypename,mq.hashear mhashear,mq.hearfile mhearfile
        from e_paper_qtype_question epqq left join t_question q on epqq.questionid = q.questionid
        left join t_question mq on q.questionpid=mq.questionid
        where epqq.epid=#{epid}
    </select>
    <!--试卷概况-附件-->
    <select id="listFjSjGk" resultType="java.util.Map">
        select erq.qn,erq.qorder
        ,erq.answerjson,erq.fullscorenum,erq.goodstujson,erq.badstujson,erq.eptqid,erq.classratetype
        ,epqq.ctype,epqq.score,epqq.answer,epqq.qtypename,epqq.optionnum
        <if test="rank.showrank==0">
            ,0 classavgscore,0 classsrate,0 gradeavgscore,0 gradesrate
        </if>
        <if test="rank.showrank!=0">
            ,erq.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        </if>
        from e_rclass_question erq left join e_paper_qtype_question epqq on erq.eptqid = epqq.eptqid
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid}
        <if test="rank.ranktype==1">order by erq.qorder</if>
        <if test="rank.ranktype==2">order by erq.classsrate</if>
    </select>
    <!--试卷分析-大题分析-->
    <select id="listType" resultType="java.util.Map">
        select erq.qtypename,erq.qns,erq.score,erq.srate
        <if test="rank.showrank==0">
            ,0 classavgscore,0 classsrate,0 gradeavgscore,0 gradesrate
        </if>
        <if test="rank.showrank!=0">
            ,erq.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        </if>
        from e_rclass_qtype erq
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid} order by erq.rctid
    </select>
    <!--试卷分析-小题分析-->
    <select id="listQuestion" resultType="java.util.Map">
        select erq.eptqid,erq.qn,erq.qorder,erq.score,erq.qtypename,erq.complexity,erq.ctype
        <if test="rank.showrank==0">
            ,0 classavgscore,0 classsrate,0 gradeavgscore,0 gradesrate
        </if>
        <if test="rank.showrank!=0">
            ,erq.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        </if>
        ,erq.answerjson,erq.fullscorenum
        from e_rclass_question erq
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid} order by erq.qorder
    </select>
    <!--试卷分析-知识点分析-->
    <select id="listPoint" resultType="java.util.Map">
        select erp.pointname,erp.qns,erp.score,erp.srate
        <if test="rank.showrank==0">
            ,0 classavgscore,0 classsrate,0 gradeavgscore,0 gradesrate
        </if>
        <if test="rank.showrank!=0">
            ,erp.classavgscore,erp.classsrate,erp.gradeavgscore,erp.gradesrate
        </if>
        from e_rclass_point erp
        where erp.examid=#{rank.examid} and erp.classid=#{rank.classid}
        and erp.subjectid=#{rank.subjectid}
    </select>
    <!--行为分析-科目-->
    <select id="getSubjectJson" resultType="java.lang.String">
        select ca.subjectjson from e_rclass_action ca
        where ca.examid=#{rank.examid} and ca.actiontype=#{rank.actiontype} and ca.classid=#{rank.classid}
        <if test="rank.subjectid!=null and rank.subjectid!=''">
            and json_contains(ca.subjectjson, json_object('subjectid', #{rank.subjectid}))
        </if>
        limit 1
    </select>
    <!--行为分析-学生-->
    <select id="listXwXs" resultType="java.util.Map">
        select sa.classid,sa.studentid,sa.subjectjson,u.username,u.loginname
        from e_rstudent_action sa left join t_user u on sa.studentid=u.userid
        where sa.examid=#{rank.examid} and sa.actiontype=#{rank.actiontype}
        <if test="rank.subjectid!=null and rank.subjectid!=''">
            and json_contains(sa.subjectjson, json_object('subjectid', #{rank.subjectid}))
        </if>
        <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="getStuPaperInfo" resultType="java.util.Map">
        select ep.pnum,ep.pscore,ep.ptype,eps.stuscore score,er.classrank,er.schoolrank,eps.epsid
        from e_paper ep left join e_paper_student eps on ep.epid = eps.epid
        LEFT JOIN e_rstudent er on er.examid = ep.examid and er.subjectid=ep.subjectid  and  er.studentid=eps.studentid
        where ep.examid=#{rank.examid} and ep.subjectid=#{rank.subjectid} and eps.studentid=#{rank.createid}
    </select>
    <!--试卷概况-优秀卷-->
    <select id="listSjGkYxj" resultType="java.util.Map">
        SELECT u.username,psq.stuscore,psq.qscore,psq.qn,psq.answertype,psq.stuanswer,psq.stuanswertxt
        FROM e_paper_student_question psq LEFT JOIN t_user u ON psq.studentid=u.userid
        WHERE epid=#{rank.epid} AND classid=#{rank.classid} AND good=1 and psq.qorder=#{rank.qorder}
    </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>
        <result property="esid" column="esid"></result>
        <result property="subjectid" column="subjectid"></result>
        <result property="subjectname" column="subjectname"></result>
        <result property="classid" column="classid"></result>
        <result property="classname" column="classname"></result>
    </resultMap>
    <select id="listEndExamsForClassTeacher" resultMap="listExamEndResult">
        select e.examid,e.examname,e.examdate,e.gradeid,e.examtype,e.exammode,e.monitored
        ,s.esid,s.subjectid,s.subjectname,c.classid,c.classname from e_base e
        left join e_subject s on e.examid=s.examid
        left join t_teacher_powersb tp on tp.teacherid=#{paramsVo.userid} and tp.subjectid=s.subjectid
        left join e_class c on e.examid=c.examid
        left join t_class_teacher ct on c.classid=ct.classid
        where e.examstate=3 and e.deleted=1 and tp.teacherid=#{paramsVo.userid} and ct.teacherid=#{paramsVo.userid}
          and c.schoolid=#{paramsVo.schoolid}
        <if test="paramsVo.begindate!=null and paramsVo.begindate!=''">
            and e.examdate between #{paramsVo.begindate} and #{paramsVo.enddate}
        </if>
        group by e.examid order by e.examdate desc,e.examid desc
    </select>

    <!--教师考试权限科目-->
    <select id="listExamSubject" resultType="java.util.Map">
        select es.subjectid,es.subjectname,p.pnum,p.ptype,p.pscore
        from e_subject es left join t_teacher_powersb ttp on es.subjectid = ttp.subjectid
        left join e_paper p on es.esid=p.esid
        where es.examid=#{examid} and ttp.teacherid=#{teacherid}
        group by es.subjectid order by es.begintime,es.esid
    </select>
    <!--教师考试权限班级-->
    <select id="listExamClass" resultType="java.util.Map">
        select ec.classid,ec.classname,ec.classnum
        from e_class ec left join t_class_teacher ct on ec.classid = ct.classid
        left join t_class c on ec.classid=c.classid
        where ec.examid=#{examid} and ct.teacherid=#{teacherid} and ec.schoolid=#{schoolid}
        group by ec.classid order by c.classtype,c.classorder,ec.ecid
    </select>
    <!--根据考试id班级id获取班级名称-->
    <select id="getClassNameByExamIdCid" resultType="java.lang.String">
        select ec.classname from e_class ec where ec.examid=#{examid} and ec.classid=#{classid}
    </select>
    <!--班级报告列表-->
    <resultMap id="listEndExamsForClass" 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"
                    select="listExamSubjects2" column="examid">
        </collection>
    </resultMap>
    <select id="listEndExamsForClass" resultMap="listEndExamsForClass">
        select e.examid,e.examname,e.examdate,e.gradeid,e.examtype,e.exammode,e.monitored
        from e_base e left join e_class c on e.examid=c.examid
        left join t_class_teacher ct on c.classid=ct.classid
        where e.examstate=3 and e.deleted=1 and ct.teacherid=#{paramsVo.userid} and c.schoolid=#{paramsVo.schoolid}
        <if test="paramsVo.begindate!=null and paramsVo.begindate!=''">
            and e.examdate between #{paramsVo.begindate} and #{paramsVo.enddate}
        </if>
        group by e.examid order by e.examdate desc
    </select>
    <select id="listExamSubjects2" resultType="java.util.Map">
        select esid,subjectid,subjectname from e_subject where examid=#{examid} and pstate=2 order by begintime,esid
    </select>
    <!--获取考试班级名称-->
    <select id="getClassName" resultType="java.lang.String">
        select c.classname from e_class c where c.examid=#{examid} and c.classid=#{classid}
    </select>
    <!--获取考试PDF报告基础信息-->
    <select id="getPdfInfo" resultType="java.util.Map">
        select b.examname,b.examdate,s.schoolname,b.gradeid,ec.classname
        from e_base b left join t_school s on b.schoolid=s.schoolid
        left join e_class ec on b.examid = ec.examid
        where b.examid=#{examid} and ec.classid=#{classid}
    </select>
    <!--单科考试概况-->
    <select id="getDkKsGk" resultType="java.util.Map">
        select er.allscore,er.yxrate,er.jgrate,er.missnum,er.stunum
        ,ec.classnum classstunum,ec.classname
        ,e.classnum,e.stunum examnum
        ,(select s.subjectname from t_subject s where s.subjectid=#{rank.subjectid})subjectname
        <if test="rank.showrank==0">
            ,0 classmaxscore,0 classavgscore,0 classavgscorerank,0 schoolmaxscore,0 schoolavgscore
        </if>
        <if test="rank.showrank==1">
            ,er.classmaxscore,er.classavgscore,0 classavgscorerank,er.schoolmaxscore,er.schoolavgscore
        </if>
        <if test="rank.showrank==2 or rank.showrank==3">
            ,er.classmaxscore,er.classavgscore,er.classavgscorerank,er.schoolmaxscore,er.schoolavgscore
        </if>
        from e_rclass er left join e_class ec on er.examid = ec.examid and er.classid=ec.classid
        left join e_rbase e on er.examid = e.examid
        where er.examid=#{rank.examid} and er.classid=#{rank.classid} and er.subjectid=#{rank.subjectid}
        limit 1
    </select>
    <!--获取单科考试PDF报告基础信息-->
    <select id="getPdfDkInfo" resultType="java.util.Map">
        select b.examname,b.examdate,s.schoolname,b.gradeid,ec.classname
        ,(select es.subjectname from e_subject es where es.examid=#{examid} and es.subjectid=#{subjectid})subjectname
        from e_base b left join t_school s on b.schoolid=s.schoolid
        left join e_class ec on b.examid = ec.examid
        where b.examid=#{examid} and ec.classid=#{classid}
    </select>
    <!--单科报告-获取pdf报告状态和地址-->
    <select id="getReportDkClass" resultType="java.util.Map">
        select e.reportstate,c.reporturl
        from e_base e left join e_class_subject c on e.examid=c.examid and c.classid=#{classid} and c.subjectid=#{subjectid}
        where e.examid=#{examid} limit 1
    </select>
</mapper>
