<?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.reportstu.ERstudentMapper">

    <!--校级报告-成绩单-->
    <!--<resultMap id="stuResult" type="java.util.Map">
        <collection property="subjects" ofType="java.util.Map" javaType="java.util.List"
                    select="listSubject" column="{examid=examid,studentid=studentid}">
        </collection>
    </resultMap>
    <select id="listSubject" resultType="java.util.Map">
        select s.score,s.classrank,s.classrankpre
        ,s.schoolrank,s.goal,s.nextgoal,s.subjectname,s.subjectid,s.bzscore
        ,eps.device,eps.submittype,eps.endtime
        ,(case when s.subjectid='zf' then (select (
        case when count(eps2.epsid)=count(case when eps2.sstate=3 then eps2.epsid else null end) then 3 else 2 end)
        from e_paper_student eps2 where eps2.examid=s.examid and eps2.studentid=s.studentid)
        else eps.sstate end)sstate
        from e_rstudent s left join e_paper_student eps on s.examid=eps.examid
        and s.subjectid=eps.subjectid and s.studentid=eps.studentid
        where s.examid=#{examid} and s.studentid=#{studentid}
    </select>
    <select id="listByExamId" resultMap="stuResult">
        select s.examid,s.classid,s.studentid,c.classname,u.username,u.loginname,u.usersex,u.examno
        from e_class_student s left join t_user u on s.studentid=u.userid
        left join e_class c on s.examid=c.examid and s.classid=c.classid
        where s.examid=#{stu.examid}
        <foreach collection="stu.classids" item="classid" open="and s.classid in(0," separator="," close=")">
            ${classid}
        </foreach>
        <if test="stu.classid!=null and stu.classid!=0">
            and s.classid=#{stu.classid}
        </if>
        <if test="stu.createname!=null and stu.createname!=''">
            and (u.username like '%${stu.createname}%' or u.loginname like '%${stu.createname}%')
        </if>
        group by s.studentid
    </select>-->
    <resultMap id="stuResult" type="java.util.Map">
        <result property="examid" column="examid"></result>
        <result property="classid" column="classid"></result>
        <result property="studentid" column="studentid"></result>
        <result property="classname" column="classname"></result>
        <result property="username" column="username"></result>
        <result property="loginname" column="loginname"></result>
        <result property="usersex" column="usersex"></result>
        <result property="examno" column="examno"></result>
        <collection property="subjects" ofType="java.util.Map" javaType="java.util.List">
            <result property="studentid" column="studentid"></result>
            <result property="score" column="score"></result>
            <result property="classrank" column="classrank"></result>
            <result property="classrankpre" column="classrankpre"></result>
            <result property="schoolrank" column="schoolrank"></result>
            <result property="goal" column="goal"></result>
            <result property="nextgoal" column="nextgoal"></result>
            <result property="subjectname" column="subjectname"></result>
            <result property="subjectid" column="subjectid"></result>
            <result property="bzscore" column="bzscore"></result>
            <result property="device" column="device"></result>
            <result property="submittype" column="submittype"></result>
            <result property="endtime" column="endtime"></result>
            <result property="sstate" column="sstate"></result>
        </collection>
    </resultMap>
    <select id="listByExamId" resultMap="stuResult">
        select s.examid,s.classid,s.studentid,c.classname,u.username,u.loginname,u.usersex,u.examno
        ,s.score,s.classrank,s.classrankpre
        ,s.schoolrank,s.goal,s.nextgoal,s.subjectname,s.subjectid,s.bzscore
        ,eps.device,eps.submittype,eps.endtime
        ,(case when s.subjectid='zf' then (select (
        case when count(eps2.epsid)=count(case when eps2.sstate=3 then eps2.epsid else null end) then 3 else 2 end)
        from e_paper_student eps2 where eps2.examid=s.examid and eps2.studentid=s.studentid)
        else eps.sstate end)sstate
        from e_rstudent s left join t_user u on s.studentid=u.userid
        left join e_class c on s.examid=c.examid and s.classid=c.classid
        left join e_paper_student eps on s.examid=eps.examid
        and s.subjectid=eps.subjectid and s.studentid=eps.studentid
        where s.examid=#{stu.examid}
        <foreach collection="stu.classids" item="classid" open="and s.classid in(0," separator="," close=")">
            ${classid}
        </foreach>
        <if test="stu.classid!=null and stu.classid!=0">
            and s.classid=#{stu.classid}
        </if>
        <if test="stu.createname!=null and stu.createname!=''">
            and (u.username like '%${stu.createname}%' or u.loginname like '%${stu.createname}%')
        </if>
    </select>

    <!--学生报告-报告概况-获取学生单次考试情况-->
    <select id="getStudentScoreByExamid" resultType="java.util.Map">
        select rs.rsid,rs.classid,rs.studentid,rs.examid,rs.subjectid,rs.subjectname
        <if test="showrank==0">
             ,0 score,0 bzscore,0 classrank,0 classrankpre,0 classmaxscore,0 classavgscore,0 schoolrank
             ,0 schoolmaxscore,0 schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==1">
            ,rs.score,rs.bzscore,0 classrank,0 classrankpre,rs.classmaxscore,rs.classavgscore,0 schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==2">
            ,rs.score,rs.bzscore,rs.classrank,rs.classrankpre,rs.classmaxscore,rs.classavgscore,0 schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==3">
            ,rs.score,rs.bzscore,rs.classrank,rs.classrankpre,rs.classmaxscore,rs.classavgscore,rs.schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,rs.goal,rs.nextgoal
        </if>
        ,eps.device,eps.submittype,eps.endtime
        ,(case when rs.subjectid='zf' then (select (
        case when count(eps2.epsid)=count(case when eps2.sstate=3 then eps2.epsid else null end) then 3 else 2 end)
        from e_paper_student eps2 where eps2.examid=rs.examid and eps2.studentid=rs.studentid)
        else eps.sstate end)sstate
        from e_rstudent rs left join e_subject s on rs.examid=s.examid and rs.subjectid=s.subjectid
        left join e_paper_student eps on rs.examid=eps.examid and rs.subjectid=eps.subjectid and rs.studentid=eps.studentid
        where rs.examid=#{examid} and rs.studentid=#{studentid} order by s.begintime,s.esid
    </select>
    <!--学生报告-报告概况-获取学生单次考试情况(学生无报告)-->
    <select id="getStudentScoreByExamidForNo" resultType="java.util.Map">
        select * from e_rstudent where examid=#{examid} and classid=#{classid} and subjectid='zf' limit 1
    </select>
    <!--学生报告-报告概况-获取本次考试的班级人数和年级人数-->
    <select id="getStudentNumByExamid" resultType="java.util.Map">
        select c.classnum,(select count(*) from e_class_student s where s.examid=c.examid) gradenum
        from e_class c where c.examid=#{examid} and c.classid=#{classid}
    </select>
    <!--学生报告-报告概况-学生最近十次考试名次-->
    <select id="listStudentExamHistory" resultType="java.util.Map">
        select e.examid,e.examdate,s.classrank,s.schoolrank
        from e_rstudent s LEFT JOIN e_base e on s.examid=e.examid
        where s.studentid=#{studentid} and s.subjectid=#{subjectid} order by e.examdate desc limit 10
    </select>

    <!--学生报告-学科分析-学科名次-->
    <select id="getSubjectScoreByStudentid" resultType="java.util.Map">
        select rs.rsid,rs.classid,rs.studentid,rs.examid,rs.subjectid,rs.subjectname
        <if test="showrank==0">
            ,0 score,0 bzscore,0 classrank,0 classrankpre,0 classmaxscore,0 classavgscore,0 schoolrank
            ,0 schoolmaxscore,0 schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==1">
            ,rs.score,rs.bzscore,0 classrank,0 classrankpre,rs.classmaxscore,rs.classavgscore,0 schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==2">
            ,rs.score,rs.bzscore,rs.classrank,rs.classrankpre,rs.classmaxscore,rs.classavgscore,0 schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==3">
            ,rs.score,rs.bzscore,rs.classrank,rs.classrankpre,rs.classmaxscore,rs.classavgscore,rs.schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,rs.goal,rs.nextgoal
        </if>
        from e_rstudent rs where rs.examid=#{examid} and rs.studentid=#{studentid} and rs.subjectid=#{subjectid}
    </select>
    <!--学生报告-学科分析-知识点分析-->
    <select id="listSubjectPoints" resultType="java.util.Map">
        select sp.pointid,sp.pointname,cp.qns,cp.score,cp.srate
        <if test="showrank==0">
            ,0 stuscore,0 stusrate,0 gradescore,0 gradesrate,0 gradeavgscore
            ,0 classscore,0 classsrate,0 classavgscore
        </if>
        <if test="showrank!=0">
            ,sp.stuscore,sp.stusrate,cp.gradescore,cp.gradesrate,cp.gradeavgscore
            ,cp.classscore,cp.classsrate,cp.classavgscore
        </if>
        from e_rstudent_point sp left join e_rclass_point cp on sp.examid=cp.examid
            and sp.subjectid=cp.subjectid and sp.pointid=cp.pointid and sp.classid=cp.classid
        where sp.examid=#{examid} and sp.subjectid=#{subjectid} and sp.studentid=#{studentid} order by sp.pointid
    </select>
    <!--学生报告-学科分析-难易度分析-->
    <select id="listSubjectComplexitys" resultType="java.util.Map">
        select sc.complexity,cc.qns,cc.score,cc.srate
        <if test="showrank==0">
            ,0 stuscore,0 stusrate,0 gradescore,0 gradeavgscore,0 gradesrate
            ,0 classscore,0 classavgscore,0 classsrate
        </if>
        <if test="showrank!=0">
            ,sc.stuscore,sc.stusrate,cc.gradescore,cc.gradeavgscore,cc.gradesrate
            ,cc.classscore,cc.classavgscore,cc.classsrate
        </if>
        from e_rstudent_complexity sc left join e_rclass_complexity cc on sc.examid=cc.examid
            and sc.subjectid=cc.subjectid and sc.complexity=cc.complexity and sc.classid=cc.classid
        where sc.examid=#{examid} and sc.subjectid=#{subjectid} and sc.studentid=#{studentid} order by sc.complexity
    </select>
    <!--学生报告-学科分析-题型分析-->
    <select id="listSubjectQtypes" resultType="java.util.Map">
        select st.qtypename,ct.qns,ct.score,ct.srate
        <if test="showrank==0">
            ,0 stuscore,0 stusrate,0 gradescore,0 gradesrate,0 gradeavgscore
            ,0 classscore,0 classsrate,0 classavgscore
        </if>
        <if test="showrank!=0">
            ,st.stuscore,st.stusrate,ct.gradescore,ct.gradesrate,ct.gradeavgscore
            ,ct.classscore,ct.classsrate,ct.classavgscore
        </if>
        from e_rstudent_qtype st left join e_rclass_qtype ct on st.examid=ct.examid
            and st.subjectid=ct.subjectid and st.qtypeid=ct.qtypeid and st.classid=ct.classid
        where st.examid=#{examid} and st.subjectid=#{subjectid} and st.studentid=#{studentid} order by st.erstid
    </select>
    <!--学生报告-学科分析-试题分析（附件）-->
    <select id="listSubjectQuestionsForFj" resultType="java.util.Map">
        select sq.qn,sq.qorder,sq.qscore,cq.qtypename
        <if test="showrank==0">
            ,0 stuscore,0 classscore,0 classsrate,0 gradescore,0 gradesrate
            ,0 gradeavgscore,0 classavgscore
        </if>
        <if test="showrank!=0">
            ,sq.stuscore,cq.classscore,cq.classsrate,cq.gradescore,cq.gradesrate
            ,cq.gradeavgscore,cq.classavgscore
        </if>
        from e_paper_student_question sq left join e_paper_student ps on sq.epsid=ps.epsid
        left join e_rclass_question cq on ps.examid=cq.examid and sq.eptqid=cq.eptqid and sq.classid=cq.classid
        and cq.eptqid=cq.eptqid where ps.examid=#{examid} and ps.subjectid=#{subjectid} and sq.studentid=#{studentid} order by sq.eptqid
    </select>
    <!--学生报告-学科分析-试题分析（题库）-->
    <resultMap id="listSubjectQuesTk" type="java.util.Map">
        <result property="questionid" column="questionid" />
        <result property="qtypename" column="qtypename" />
        <result property="classscore" column="classscore" />
        <result property="classsrate" column="classsrate" />
        <result property="classavgscore" column="classavgscore" />
        <result property="gradescore" column="gradescore" />
        <result property="gradesrate" column="gradesrate" />
        <result property="gradeavgscore" column="gradeavgscore" />
        <result property="qscore" column="score" />
        <result property="epid" column="epid" />
        <result property="qn" column="qn" />
        <result property="studentid" column="studentid" />
        <collection property="ques" ofType="java.util.Map" javaType="java.util.List"
                    column="{studentid=studentid,epid=epid,questionid=questionid}" select="listSubjectQuestionsStuScore">
            <result property="questionid" column="squestionid" />
            <result property="stuscore" column="stuscore" />
            <result property="qscore" column="qscore" />
        </collection>
    </resultMap>
    <select id="listSubjectQuestionsForTk" resultMap="listSubjectQuesTk">
        select cq.questionid,cq.qtypename,cq.score,cq.epid,cq.qn,ps.studentid
        <if test="showrank==0">
            ,0 classscore,0 classsrate,0 gradescore,0 gradesrate,0 classavgscore,0 gradeavgscore
        </if>
        <if test="showrank!=0">
            ,cq.classscore,cq.classsrate,cq.gradescore,cq.gradesrate,cq.classavgscore,cq.gradeavgscore
        </if>
        from e_rclass_question cq
        left join e_paper_student ps on cq.epid=ps.epid and cq.classid=ps.classid
        where  cq.epid=#{epid} and ps.studentid=#{studentid} order by cq.qorder
    </select>
    <select id="listSubjectQuestionsStuScore" resultType="java.util.Map">
        select sq.stuscore,sq.qscore,sq.questionid squestionid
        from e_paper_student_question sq
        left join t_question q on sq.questionid=q.questionid
        where sq.studentid=#{studentid} and sq.epid=#{epid} and (q.questionid=#{questionid} or q.questionpid=#{questionid})
        order by q.sorder
    </select>

    <!--学生报告-试卷分析（题库）-->
    <resultMap id="listStudentQues" type="java.util.Map">
        <result property="epsqid" column="epsqid" />
        <result property="eptqid" column="eptqid" />
        <result property="ctype" column="ctype" />
        <result property="questionid" column="questionid" />
        <result property="qn" column="qn" />
        <result property="qorder" column="qorder" />
        <result property="qscore" column="qscore" />
        <result property="stuscore" column="stuscore" />
        <result property="answered" column="answered" />
        <result property="answertype" column="answertype" />
        <result property="stuanswer" column="stuanswer" />
        <result property="stuanswertxt" column="stuanswertxt" />
        <result property="qstem" column="qstem" />
        <result property="qoption" column="qoption" />
        <result property="answer" column="answer" />
        <result property="qanalyze" column="qanalyze" />
        <result property="hashear" column="hashear" />
        <result property="hearfile" column="hearfile" />
        <result property="qlevel" column="qlevel" />
        <result property="sorder" column="sorder" />
        <result property="complexity" column="complexity" />
        <result property="questionpid" column="questionpid" />
        <result property="qtypename" column="qtypename" />
        <result property="mquestionid" column="mquestionid" />
        <result property="mqstem" column="mqstem" />
        <result property="mqoption" column="mqoption" />
        <result property="mqanswer" column="mqanswer" />
        <result property="mqanalyze" column="mqanalyze" />
        <result property="mhashear" column="mhashear" />
        <result property="mhearfile" column="mhearfile" />
        <result property="mqlevel" column="mqlevel" />
        <result property="mctype" column="mctype" />
        <result property="msnum" column="msnum" />
        <result property="mcomplexity" column="mcomplexity" />
        <result property="mqtypename" column="mqtypename" />
        <result property="classavgscore" column="classavgscore" />
        <result property="gradeavgscore" column="gradeavgscore" />
        <result property="goodstujson" column="goodstujson" />
        <result property="badstujson" column="badstujson" />
        <result property="classid" column="classid" />
        <collection property="points" ofType="java.util.Map" javaType="java.util.List"
                    column="{questionid=questionid,qlevel=qlevel,questionpid=questionpid}" select="listQuesPoints">
            <result column="pointid" property="pointid"></result>
            <result column="pointname" property="pointname"></result>
        </collection>
    </resultMap>
    <select id="listStudentQuestionsTk" resultMap="listStudentQues">
        select sq.epsqid,sq.eptqid,sq.ctype,sq.questionid,sq.qn,sq.qorder,sq.qscore,sq.answered,sq.classid,
        sq.answertype,sq.stuanswer,sq.stuanswertxt,pq.answer,q.qstem,q.qoption,q.qanalyze,q.hashear,q.hearfile,
        q.qlevel,q.sorder,q.complexity,q.questionpid,q.qtypename,mq.questionid mquestionid,mq.qstem mqstem,mq.qoption mqoption,mq.qanswer mqanswer,
        mq.qanalyze mqanalyze,mq.hashear mhashear,mq.hearfile mhearfile,mq.qlevel mqlevel,mq.ctype mctype,mq.snum msnum,
        mq.complexity mcomplexity,mq.qtypename as mqtypename,cq.goodstujson,cq.badstujson
        <if test="showrank==0">
            ,0 stuscore,0 classavgscore,0 gradeavgscore
        </if>
        <if test="showrank!=0">
            ,sq.stuscore,cq.classavgscore,cq.gradeavgscore
        </if>
        from e_paper_student_question sq left join t_question q on sq.questionid=q.questionid
        left join t_question mq on q.questionpid=mq.questionid
        left join e_rclass_question cq on sq.epid=cq.epid and sq.classid=cq.classid and (sq.questionid=cq.questionid or mq.questionid=cq.questionid)
        left join e_paper_qtype_question pq on sq.eptqid=pq.eptqid
        where sq.epid=#{epid} and sq.studentid=#{studentid} GROUP BY sq.epsqid order by sq.qorder,q.sorder
    </select>
    <select id="listQuesPoints" resultType="java.util.Map">
        select p.pointid,p.pointname
        from t_question_point qp left join t_point p on qp.pointid=p.pointid
        where
        <if test="qlevel==1">
            qp.questionid=#{questionid}
        </if>
        <if test="qlevel==3">
            qp.questionid=#{questionpid}
        </if> order by p.pointorder
    </select>

    <!--学生报告-试卷分析（题库）-->
    <select id="listStudentQuestionsFj" resultType="java.util.Map">
        select sq.epsqid,sq.eptqid,sq.ctype,sq.qn,sq.qorder,sq.qscore,sq.answered,sq.classid,
               sq.answertype,sq.stuanswer,sq.stuanswertxt,pq.answer,pq.qtypename
        ,cq.goodstujson,cq.badstujson
        <if test="showrank==0">
            ,0 stuscore,0 classavgscore,0 gradeavgscore
        </if>
        <if test="showrank!=0">
            ,sq.stuscore,cq.classavgscore,cq.gradeavgscore
        </if>
        from e_paper_student_question sq left join e_rclass_question cq on sq.eptqid=cq.eptqid and sq.classid=cq.classid
        left join e_paper_qtype_question pq on sq.eptqid=pq.eptqid
        where sq.epid=#{epid} and sq.studentid=#{studentid} group by sq.epsqid order by sq.qorder
    </select>

    <!--学生报告-错题集-各科目错题-->
    <resultMap id="listStudentSubjectErrorQues" type="java.util.Map">
        <result property="subjectid" column="subjectid" />
        <result property="subjectname" column="subjectname" />
        <result property="ptype" column="ptype" />
        <result property="num" column="num" />
        <collection property="questions" ofType="java.util.Map" javaType="java.util.List">
            <result property="epsqid" column="epsqid" />
            <result property="eptqid" column="eptqid" />
            <result property="questionid" column="questionid" />
            <result property="qlevel" column="qlevel" />
            <result property="questionpid" column="questionpid" />
        </collection>
    </resultMap>
    <select id="listStudentSubjectErrorQues" resultMap="listStudentSubjectErrorQues">
        select sq.subjectid,st.subjectname,p.ptype,sq.epsqid,sq.eptqid,q.questionid,q.qlevel,q.questionpid
        from e_paper_student_question sq
        left join t_question q on q.questionid=sq.questionid
        left join t_question mq on q.questionpid=mq.questionid
        left join e_paper p on sq.epid=p.epid
        left join e_subject st on p.esid=st.esid
        where sq.examid=#{examid} and sq.studentid=#{studentid} and st.pstate=2 and sq.stuscore &lt; sq.qscore group by sq.epsqid
        order by st.begintime,st.esid
    </select>
    <!--学生报告-错题集-学生科目下错题（题库）-->
    <select id="listStudentErrorQuestionsForTk" resultMap="listStudentQues">
        select sq.epsqid,sq.eptqid,sq.ctype,sq.questionid,sq.qn,sq.qorder,sq.qscore,sq.answered,
               sq.answertype,sq.stuanswer,sq.stuanswertxt,pq.answer,q.qstem,q.qoption,q.qanswer,q.qanalyze,q.hashear,q.hearfile,
               q.qlevel,q.sorder,q.complexity,q.qtypename,q.questionpid,mq.questionid mquestionid,mq.qstem mqstem,mq.qoption mqoption,mq.qanswer mqanswer,
               mq.qanalyze mqanalyze,mq.hashear mhashear,mq.hearfile mhearfile,mq.qlevel mqlevel,mq.ctype mctype,mq.snum msnum,
               mq.complexity mcomplexity,mq.qtypename mqtypename
        <if test="showrank==0">
            ,0 stuscore,0 classavgscore,0 gradeavgscore
        </if>
        <if test="showrank!=0">
            ,sq.stuscore,cq.classavgscore,cq.gradeavgscore
        </if>
        from e_paper_student_question sq left join t_question q on sq.questionid=q.questionid
        left join t_question mq on q.questionpid=mq.questionid
        left join e_rclass_question cq on sq.epid=cq.epid and sq.classid=cq.classid and (sq.questionid=cq.questionid or mq.questionid=cq.questionid)
        left join e_paper_qtype_question pq on sq.eptqid=pq.eptqid
        where sq.examid=#{examid} and sq.subjectid=#{subjectid} and sq.studentid=#{studentid} and sq.stuscore &lt; sq.qscore
        GROUP BY sq.epsqid order by sq.qorder,q.sorder
    </select>

    <!--学生报告-错题集-学生科目下错题（附件）-->
    <select id="listStudentErrorQuestionsForFj" resultType="java.util.Map">
        select sq.epsqid,sq.eptqid,sq.ctype,sq.qn,sq.qorder,sq.qscore,sq.answered,
               sq.answertype,sq.stuanswer,sq.stuanswertxt,q.qtypeid,q.qtypename,q.optionnum,q.answer
        <if test="showrank==0">
            ,0 stuscore,0 classavgscore,0 gradeavgscore
        </if>
        <if test="showrank!=0">
            ,sq.stuscore,cq.classavgscore,cq.gradeavgscore
        </if>
        from e_paper_student_question sq left join e_rclass_question cq on sq.eptqid=cq.eptqid and sq.classid=cq.classid
        left join e_paper_qtype_question q on sq.eptqid=q.eptqid
        where sq.examid=#{examid} and sq.subjectid=#{subjectid} and sq.studentid=#{studentid} and sq.stuscore &lt; sq.qscore
        group by sq.epsqid order by sq.qorder
    </select>

    <!--学生报告-监控照片-考试科目下违规图片数量-->
    <select id="listExamSubjectBadNums" resultType="java.util.Map">
        select es.esid,es.subjectname,count(*)num from e_subject_badstudent esb
        left join e_subject es on es.esid=esb.esid
        where esb.examid=#{examid} and esb.studentid=#{studentid} and es.pstate=2  group by es.esid order by es.begintime,es.esid
    </select>

    <!--学生报告-监控照片-学生单科图片-->
    <select id="listExamSubjectBadimgs" resultType="java.util.Map">
        select esbsid,badtype,picpath,createtime from e_subject_badstudent
        where esid=#{esid} and studentid=#{studentid} order by createtime
    </select>
    <!--班级报告教师成绩单-->
    <select id="listTeacherCjd" resultType="java.util.Map">
        select s.examid,s.classid,s.studentid,u.username,u.loginname,u.usersex,u.examno
        ,s.subjectname,s.subjectid
        <if test="stu.showrank==0">
            ,0 score,0 classrank,0 schoolrank
        </if>
        <if test="stu.showrank==1">
            ,s.score,0 classrank,0 schoolrank
        </if>
        <if test="stu.showrank==2">
            ,s.score,s.classrank,0 schoolrank
        </if>
        <if test="stu.showrank==3">
            ,s.score,s.classrank,s.schoolrank
        </if>
        ,eps.device,eps.submittype,eps.endtime
        from e_rstudent s left join t_user u on s.studentid=u.userid
        left join e_paper_student eps on s.examid=eps.examid and s.subjectid=eps.subjectid and s.studentid=eps.studentid
        where s.examid=#{stu.examid} and s.classid=#{stu.classid} and s.subjectid=#{stu.subjectid}
        <if test="stu.createname!=null and stu.createname!=''">
            and (u.username like '%${stu.createname}%' or u.loginname like '%${stu.createname}%')
        </if>
        <choose>
            <when test="stu.fieldname!=null and stu.fieldname=='classrank'">order by s.classrank</when>
            <when test="stu.fieldname!=null and stu.fieldname=='score'">order by s.score</when>
            <otherwise>order by s.schoolrank</otherwise>
        </choose>
        <choose>
            <when test="stu.od!=null and stu.od==2">desc</when>
            <otherwise>asc</otherwise>
        </choose>
    </select>
    <!--pdf报告-考试概况-->
    <select id="getPdfKsGk" resultType="java.util.Map">
        select eb.examname,eb.gradeid,eb.examdate,eb.examtype,ecs.classid,er.stunum examnum,u.username
        ,ec.classname,ec.classnum classstunum
        ,er.classnum,er.subjectnum,erc.allscore,er.missnum,er.stunum-er.missnum stunum,er.maxscore,er.avgscore
        from e_base eb left join e_class_student ecs on eb.examid = ecs.examid
        left join e_class ec on ecs.examid = ec.examid and ecs.classid=ec.classid
        left join t_user u on ecs.studentid = u.userid
        left join e_rbase er on eb.examid = er.examid
        left join e_rclass erc on eb.examid = erc.examid and erc.classid=ecs.classid and erc.subjectid='zf'
        where eb.examid=#{examid} and ecs.studentid=#{studentid}
    </select>
    <!--学科名次-->
    <select id="listSubjectScoreByStudentid" resultType="java.util.Map">
        select rs.rsid,rs.classid,rs.studentid,rs.examid,rs.subjectid,rs.subjectname
        <if test="showrank==0">
            ,0 score,0 bzscore,0 classrank,0 classrankpre,0 classmaxscore,0 classavgscore,0 schoolrank
            ,0 schoolmaxscore,0 schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==1">
            ,rs.score,rs.bzscore,0 classrank,0 classrankpre,rs.classmaxscore,rs.classavgscore,0 schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==2">
            ,rs.score,rs.bzscore,rs.classrank,rs.classrankpre,rs.classmaxscore,rs.classavgscore,0 schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,0 goal,0 nextgoal
        </if>
        <if test="showrank==3">
            ,rs.score,rs.bzscore,rs.classrank,rs.classrankpre,rs.classmaxscore,rs.classavgscore,rs.schoolrank
            ,rs.schoolmaxscore,rs.schoolavgscore,rs.goal,rs.nextgoal
        </if>
        from e_rstudent rs left join e_subject es on rs.examid = es.examid and rs.subjectid=es.subjectid
        where rs.examid=#{examid} and rs.studentid=#{studentid} and rs.subjectid!='zf'
        order by es.begintime,es.esid
    </select>
    <!--考试基础（学生）-->
    <select id="findByExamIdAndStudentId" resultType="java.util.Map">
        select b.examid,b.examname,b.gradeid,b.examdate,b.examtype,b.exammode,b.monitored,b.examstate,b.teashowrank,b.stushowrank
        ,b.reportstate,cs.reportstu
        from e_class_student cs left join e_base b on cs.examid=b.examid
        where cs.examid=#{examid} and cs.studentid=#{studentid}
    </select>

    <!--学生报告-pdf报告状态和学生报告地址-->
    <select id="getReportStuState" resultType="java.util.Map">
        select e.reportstate,s.reportstu from e_base e left join e_class_student s on e.examid=s.examid and s.studentid=#{studentid}
        where e.examid=#{examid} limit 1
    </select>
    <!--获取考试PDF报告基础信息-->
    <select id="getPdfInfo" resultType="java.util.Map">
        select b.examname,b.examdate,s.schoolname,b.gradeid,ec.classname
        ,(select u.username from t_user u where u.userid=#{studentid})studentname
        from e_base b left join t_school s on b.schoolid=s.schoolid
        left join e_class_student es on b.examid=es.examid
        left join e_class ec on es.examid=ec.examid and es.classid=ec.classid
        where b.examid=#{examid} and es.studentid=#{studentid}
    </select>
</mapper>
