<?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.smarking.mapper.report.reportstu.MsrStudentMapper">
    <!--获取学生考试得分和排名-->
    <select id="listStuScoreAndRankByExamid" resultType="com.xhkjedu.smarking.model.report.reportstu.MsrStudent">
        select rsid,examid,subjectid,classid,studentid,stuscore,classrank,schoolrank from msr_student where examid = #{examid}
        <if test="subjectid!= null and subjectid!= ''"> and subjectid = #{subjectid}</if>
    </select>

    <!--批量修改学生主观题、客观题分值-->
    <update id="updateBatchObjSubScore">
        <foreach collection="list" item="item" separator=";">
            update msr_student set objscore = #{item.objscore},subscore = #{item.subscore} where rsid = #{item.rsid}
        </foreach>
    </update>

    <!--综合报告-小分表-学生分数排名-->
    <resultMap id="studentChengji" type="java.util.Map">
        <id property="rsid" column="rsid"/>
        <result property="examid" column="examid"/>
        <result property="subjectid" column="subjectid"/>
        <result property="studentid" column="studentid"/>
        <result property="username" column="username"/>
        <result property="examno" column="examno"/>
        <result property="classid" column="classid"/>
        <result property="classname" column="classname"/>
        <result property="stuscore" column="stuscore"/>
        <result property="classrank" column="classrank"/>
        <result property="schoolrank" column="schoolrank"/>
        <result property="objscore" column="objscore"/>
        <result property="subscore" column="subscore"/>
        <result property="totalscore" column="totalscore"/>
        <collection property="questions" ofType="java.util.Map" javaType="java.util.ArrayList">
            <result property="mpsqid" column="mpsqid"/>
            <result property="stuscore" column="xtscore"/>
            <result property="answertype" column="answertype"/>
            <result property="stuanswer" column="stuanswer"/>
            <result property="qanswer" column="qanswer"/>
            <result property="qscore" column="qscore"/>
            <result property="qtype" column="qtype"/>
            <result property="qnstr" column="qnstr"/>
        </collection>
    </resultMap>
    <select id="listStuScoreAndRankByExamidAndSubjectid" resultMap="studentChengji">
        select distinct s.rsid,s.examid,s.subjectid,s.studentid,s.classid,c.classname,s.stuscore,s.classrank,
        s.schoolrank,s.objscore,s.subscore,sq.mpsqid,sq.qn,sq.stuscore as xtscore,sq.answertype,sq.stuanswer,
        q.qanswer,q.qscore,q.qtype,q.qnstr
        from msr_student s left join ms_class c on s.classid=c.classid
        left join ms_paper_student_question sq on s.examid=sq.examid
        and s.subjectid=sq.subjectid and s.studentid=sq.studentid
        left join ms_paper_qtype_question q on sq.mptqid=q.mptqid
        where s.examid=#{examid} and s.subjectid=#{subjectid}
        order by s.schoolrank,s.rsid,q.qorder
    </select>

    <!--学生报告-学生学科试题分析-->
    <select id="listStuSubjectQuestions" resultType="java.util.Map">
        select distinct q.mpsqid,q.mptqid,q.qscore,q.stuscore,q.ctype,q.stuanswer,
        cq.schoolavgscore,cq.scorerate,cq.qn
        from ms_paper_student_question q
        left join msr_class_question cq on q.examid=cq.examid and q.subjectid=cq.subjectid
            and q.mptqid=cq.mptqid and cq.classid=0
        where q.examid=#{params.examid} and q.subjectid=#{params.subjectid} and q.studentid=#{params.studentid}
        order by cq.qorder
    </select>
    <!--综合报告-总概览-整体分数分布分析-->
    <select id="listScoreForZgl" resultType="java.util.Map">
        select stuscore,count(*) as num
        from msr_student
        where examid=#{examid} and subjectid=#{subjectid}
        group by stuscore
    </select>
    <!--综合报告-排行榜-->
    <select id="listStudentForPhb" resultType="java.util.Map">
        select ${sql}
        where s.examid=#{params.examid}
        <if test="params.subjectid!='zf'">
            and s.subjectid=#{params.subjectid}
        </if>
        <foreach collection="params.classids" item="classid" open="and classid in (" close=")" separator=",">
            #{classid}
        </foreach>
    </select>
    <!--学生成绩分析-->
    <select id="listStudentBySql" resultType="com.xhkjedu.smarking.model.report.reportstu.MsrStudent">
        select ${sql}
    </select>
    <!--学生成绩分析2-->
    <select id="listStudentBySql2" resultType="java.util.Map">
        select ${sql}
    </select>
</mapper>
