<?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.report.EReportGenerateMapper">
    <!--考试科目-->
    <select id="listSubject" resultType="java.util.Map">
        select s.subjectid,s.subjectname,p.epid,p.ptype,p.pscore from e_subject s left join e_paper p on s.esid=p.esid
        where s.examid=#{examid}
        <if test="exammode==1">
            and s.pstate=2
        </if>
        order by s.esid
    </select>
    <!--删除考试报告-->
    <delete id="deleteExamReport">
        delete from e_rbase where examid=#{examid};
        delete from e_rclass where examid=#{examid};
        delete from e_rclass_action where examid=#{examid};
        delete from e_rclass_complexity where examid=#{examid};
        delete from e_rclass_point where examid=#{examid};
        delete from e_rclass_qtype where examid=#{examid};
        delete from e_rclass_question where examid=#{examid};
        delete from e_rclass_rank where examid=#{examid};
        delete from e_rrank where examid=#{examid};
        delete from e_rstudent where examid=#{examid};
        delete from e_rstudent_action where examid=#{examid};
        delete from e_rstudent_complexity where examid=#{examid};
        delete from e_rstudent_point where examid=#{examid};
        delete from e_rstudent_qtype where examid=#{examid};
        delete from e_rsubject where examid=#{examid};
    </delete>
    <!--学生上次考试排名及目标-->
    <select id="listStuRankAndGoal" resultType="com.xhkjedu.sexam.model.reportstu.ERstudent">
        select er.studentid,er.subjectid,er.schoolrank,er.nextgoal,er.classrank
        from(select max(er.rsid)rsid from e_class_student ecs left join e_rstudent er on ecs.studentid = er.studentid
        where ecs.examid=#{examid} and ecs.examid!=er.examid and er.rsid is not null group by er.studentid,er.subjectid)a
        left join e_rstudent er on a.rsid=er.rsid
    </select>
    <!--学生违纪行为-->
    <select id="listBadActionByExamId" resultType="java.util.Map">
        select studentid,classid,es.subjectid,es.subjectname,count(esb.esbsid)num
        from e_subject_badstudent esb left join e_subject es on esb.esid = es.esid
        where esb.examid=#{examid}
        group by studentid, esb.esid
    </select>
    <!--学生优秀行为-->
    <select id="listGoodActionByExamId" resultType="java.util.Map">
        select studentid,classid,epsq.subjectid,s.subjectname,count(epsq.epsqid)num
        from e_paper_student_question epsq left join t_subject s on epsq.subjectid=s.subjectid
        where examid=#{examid} and good=1
        group by studentid, subjectid, good
    </select>
    <!--获取试卷分数-->
    <select id="getScoreByExamAndSubjectId" resultType="java.lang.Double">
        select sum(ep.pscore) from e_paper ep where ep.examid=#{examid}
        <if test="subjectid!='zf'">
            and ep.subjectid=#{subjectid}
        </if>
    </select>
    <!--获取考试发布学生数量-->
    <select id="getStuNumByExamId" resultType="java.lang.Integer">
        select sum(classnum) from e_class where examid=#{examid}
    </select>
    <!--根据考试id获取考试模式-->
    <select id="getExamModeById" resultType="java.lang.Integer">
        select exammode from e_base where examid=#{examid}
    </select>
</mapper>
