<?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.classmaxscore,s.classavgscore
        ,s.schoolrank,s.schoolmaxscore,s.schoolavgscore,s.goal,s.nextgoal,s.subjectname,s.subjectid,s.bzscore
        from e_rstudent s 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
        from e_class_student s left join t_user u on s.studentid=u.userid
        left join e_class c on 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>

    <!--学生报告-报告概况-获取学生单次考试情况-->
    <select id="getStudentScoreByExamid" resultType="java.util.Map">
        select rs.* from e_rstudent rs
                             left join t_subject s on rs.subjectid=s.subjectid
        where rs.examid=#{examid} and rs.studentid=#{studentid} order by s.subjectorder
    </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 limit 10
    </select>

    <!--学生报告-学科分析-学科名次-->
    <select id="getSubjectScoreByStudentid" resultType="java.util.Map">
        select rs.* 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,sp.stuscore,sp.stusrate,cp.score,cp.srate,cp.gradescore,cp.gradesrate,cp.gradeavgscore,
               cp.classscore,cp.classsrate,cp.classavgscore,cp.qns
        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,sc.stuscore,sc.stusrate,cc.score,cc.srate,cc.gradescore,cc.gradeavgscore,cc.gradesrate,
               cc.classscore,cc.classavgscore,cc.classsrate,cc.qns
        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,st.stuscore,st.stusrate,ct.score,ct.srate,ct.gradescore,ct.gradesrate,ct.gradeavgscore
               ,ct.classscore,ct.classsrate,ct.classavgscore,ct.qns
        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.stuscore,sq.qscore,cq.qtypename,cq.classscore,cq.classsrate,cq.gradescore,cq.gradesrate
               ,cq.gradeavgscore,cq.classavgscore
        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.classscore,cq.classsrate,cq.gradescore,cq.gradesrate,cq.qtypename,cq.score,
        cq.epid,cq.qn,ps.studentid,cq.classavgscore,cq.gradeavgscore 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="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="classavgscore" column="classavgscore" />
        <result property="gradeavgscore" column="gradeavgscore" />
        <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.stuscore,sq.answered,
        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,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,cq.classavgscore,cq.gradeavgscore
        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.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.stuscore,sq.answered,
               sq.answertype,sq.stuanswer,sq.stuanswertxt,pq.answer,pq.qtypename,cq.classavgscore,cq.gradeavgscore
        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" />
        <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,s.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_subject s on sq.subjectid=s.subjectid
        left join t_question mq on q.questionpid=mq.questionid
        left join e_paper p on sq.epid=p.epid
        where sq.examid=#{examid} and sq.studentid=#{studentid} and sq.stuscore &lt; sq.qscore group by sq.epsqid order by s.subjectorder
    </select>
    <!--学生报告-错题集-学生科目下错题（题库）-->
    <select id="listStudentErrorQuestionsForTk" resultMap="listStudentQues">
        select sq.epsqid,sq.eptqid,sq.ctype,sq.questionid,sq.qn,sq.qorder,sq.qscore,sq.stuscore,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.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,cq.classavgscore,cq.gradeavgscore
        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.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.stuscore,sq.answered,
               sq.answertype,sq.stuanswer,sq.stuanswertxt,q.qtypeid,q.qtypename,q.optionnum,q.answer,
               cq.classavgscore,cq.gradeavgscore
        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>

</mapper>
