<?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.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate,erq.classratetype
        ,erq.answerjson,erq.goodstujson,erq.badstujson,erq.questionid,erq.eptqid,erq.complexity,erq.score
        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.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        ,erq.answerjson,erq.goodstujson,erq.badstujson,erq.eptqid,erq.classratetype
        ,epqq.ctype,epqq.score,epqq.answer,epqq.qtypename,epqq.optionnum
        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,erq.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        from e_rclass_qtype erq
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid}
    </select>
    <!--试卷分析-小题分析-->
    <select id="listQuestion" resultType="java.util.Map">
        select erq.eptqid,erq.qn,erq.qorder,erq.score,erq.qtypename,erq.complexity
        ,erq.classavgscore,erq.classsrate,erq.gradeavgscore,erq.gradesrate
        from e_rclass_question erq
        where erq.examid=#{rank.examid} and erq.classid=#{rank.classid}
        and erq.subjectid=#{rank.subjectid}
    </select>
    <!--试卷分析-知识点分析-->
    <select id="listPoint" resultType="java.util.Map">
        select erp.pointname,erp.qns,erp.score,erp.srate,erp.classavgscore,erp.classsrate,erp.gradeavgscore,erp.gradesrate
        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} 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.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,er.score,er.classrank,er.schoolrank,eps.epsid
        from e_rstudent er left join e_paper ep on er.examid = ep.examid and er.subjectid=ep.subjectid
        left join e_paper_student eps on ep.epid = eps.epid and eps.studentid=er.studentid
        where er.examid=#{rank.examid} and er.subjectid=#{rank.subjectid} and er.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>
        <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="listEndExamsForClassTeacher" 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 left join e_class c on e.examid=c.examid
        left join t_class_teacher ct on c.classid=ct.classid
        where e.examstate=2 and e.deleted=1 and s.pstate=2
          and ct.teacherid=#{paramsVo.userid}
        <if test="paramsVo.begindate!=null and paramsVo.begindate!=''">
            and e.examdate between #{paramsVo.begindate} and #{paramsVo.enddate}
        </if>
        group by s.esid order by e.examdate desc, s.esid asc
    </select>

    <!--考试教师权限下班级-->
    <select id="listExamQxClassTeacher" resultType="java.util.Map">
        select c.classid,c.classname from e_class c
        left join t_class_teacher ct on c.classid=ct.classid
        left join t_class tc on c.classid=tc.classid
        where c.examid=#{params.examid} and ct.teacherid=#{params.userid} group by c.classid
        order by tc.classorder,ecid
    </select>
</mapper>
