<?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.reportclass.MsrClassQuestionMapper">

    <!-- 清除单次考试报告 -->
    <delete id="deleteReportByExamid">
        delete from msr_class_qobjsub where examid = #{examid};
        delete from msr_class_qtype where examid = #{examid};
        delete from msr_class_question where examid = #{examid};
        delete from msr_class_question_obj where examid = #{examid};
        delete from msr_student_point where examid = #{examid};
        delete from msr_subject_point where examid = #{examid};
        delete from msr_subject_point_section where examid = #{examid};
        delete from msr_subject_question_rankgroup where examid = #{examid};
        delete from msr_subject_question_section where examid = #{examid};
    </delete>

    <!--获取考试难度和区别度数据-->
    <select id="listQuestionClassForNdByExamid" resultType="com.xhkjedu.smarking.model.report.reportclass.MsrClassQuestion">
        select cqid,examid,subjectid,nd,ndms,ndfw,qfd,qfdms,qfdfw from msr_class_question where examid = #{examid}
    </select>
    <!--修改难度-->
    <update id="updateBatchNdById">
        <foreach collection="list" item="item" separator=";">
            update msr_class_question set ndms = #{item.ndms},ndfw = #{item.ndfw} where cqid = #{item.cqid}
        </foreach>
    </update>

    <!--修改区分度-->
    <update id="updateBatchQfdById">
        <foreach collection="list" item="item" separator=";">
            update msr_class_question set qfdms = #{item.ndms},qfdfw = #{item.ndfw} where cqid = #{item.cqid}
        </foreach>
    </update>
    
    <resultMap id="zhQuestionSummary" type="java.util.Map">
        <result property="cqid" column="cqid"/>
        <result property="classid" column="classid"/>
        <result property="mptqid" column="mptqid"/>
        <result property="qn" column="qn"/>
        <result property="qtype" column="qtype"/>
        <result property="fullscore" column="fullscore"/>
        <result property="schoolavgscore" column="schoolavgscore"/>
        <result property="nd" column="nd"/>
        <result property="ndms" column="ndms"/>
        <result property="qfd" column="qfd"/>
        <result property="qfdms" column="qfdms"/>
        <result property="zqda" column="zqda"/>
        <result property="zqrate" column="zqrate"/>
        <result property="lfnum" column="lfnum"/>
        <result property="lfrate" column="lfrate"/>
        <result property="mfnum" column="mfnum"/>
        <result property="mfrate" column="mfrate"/>
        <collection property="objs" ofType="java.util.Map" javaType="java.util.ArrayList">
            <result property="cqoid" column="cqoid"/>
            <result property="xxda" column="xxda"/>
            <result property="xxnum" column="xxnum"/>
            <result property="xxnum" column="xxnum"/>
            <result property="xxrate" column="xxrate"/>
        </collection>
    </resultMap>
    <!--综合报告-试题汇总表-全部分类-按小题分析-->
    <select id="listQuestionSummaryForSmall" resultMap="zhQuestionSummary">
        select q.cqid,q.classid,q.mptqid,q.qn,q.qtype,q.fullscore,q.schoolavgscore,q.bzc,q.nd,q.ndms,q.qfd,q.qfdms,q.zqda,q.zqrate,q.lfnum,q.lfrate,q.mfnum,q.mfrate,qo.cqoid,qo.xxda,xxnum,qo.xxrate
        from msr_class_question q
        left join msr_class_question_obj qo on q.mptqid=qo.mptqid
        where q.examid=#{param.examid} and q.subjectid=#{param.subjectid}
        <if test="param.selclass == 1">and q.classid=0</if>
        <if test="param.selclass == 4">and q.classid=#{param.classid}</if>
        order by q.qorder
    </select>
    <!--综合报告-试题汇总表-全部分类-按大题分析-->
    <select id="listQuestionSummaryForQtype" resultType="java.util.Map">
        select t.cqtid,t.classid,t.mptid,t.mptqn,t.avgscore,t.bzc,t.nd,t.ndms,t.qfd,t.qfdms,t.fullscore,
            t.mfnum,t.mfrate,t.lfnum,t.lfrate,c.classname from msr_class_qtype t
            left join ms_class c on t.examid=c.examid and t.subjectid=c.subjectid and t.classid=c.classid
        where t.examid=#{param.examid} and t.subjectid=#{param.subjectid}
        <if test="param.selclass == 1">and t.classid=0</if>
        <if test="param.selclass == 4">and t.classid=#{param.classid}</if>
        order by t.cqtid,t.mptorder
    </select>
    <!--综合报告-试题汇总表-全部分类-按主(客)题分析-->
    <select id="listQuestionSummaryForObjsub" resultType="java.util.Map">
        select q.coid,q.classid,q.qtype,q.stunum,q.fullscore,q.avgscore,q.avgrate,nd,q.mfnum,q.mfrate,
        q.lfnum,q.lfrate,c.classname from msr_class_qobjsub q
        left join ms_class c on q.examid=c.examid and q.subjectid=c.subjectid and q.classid=c.classid
        where q.examid=#{param.examid} and q.subjectid=#{param.subjectid}
        <if test="param.selclass == 1">and q.classid=0</if>
        <if test="param.selclass == 4">and q.classid=#{param.classid}</if>
        order by q.coid
    </select>

    <!--学科报告-各班学科试题分析-->
    <select id="listQuestionForXh" resultType="com.xhkjedu.smarking.model.report.reportclass.MsrClassQuestion">
        select distinct q.cqid,q.mptqid,q.classid,q.qn,q.qtype,q.qorder,q.fullscore,
        q.classavgrate,q.schoolavgrate,q.scorerate,q.scoreratec,q.nd,q.ndms,q.ndfw,q.qfd,q.qfdms,c.classname
        from msr_class_question q left join ms_class c on q.examid=c.examid
        and q.subjectid=c.subjectid and q.classid=c.classid
        where q.examid=#{param.examid} and q.subjectid=#{param.subjectid}
        <if test="param.selclass == 3">
            and q.classid in (${param.classids})
        </if>
        <if test="param.selclass == 4"> and q.classid = #{param.classid}</if>
        order by q.mptqid
    </select>

    <!--命题质量-命题分析-试题分析指标明细表-->
    <select id="listMtzlMtfxQuestions" resultType="java.util.Map">
        select cq.cqid,cq.mptqid,cq.qn,cq.qorder,cq.qtype,cq.fullscore,cq.stunum,cq.schoolmaxscore,
        cq.schoolminscore,cq.schoolavgscore,cq.nd,cq.bzc,cq.cyxs,cq.qfd,cq.jbzs,cq.lfnum,
        cq.lfrate,cq.mfnum,cq.mfrate from msr_class_question cq where cq.examid=#{param.examid}
        and cq.subjectid=#{param.subjectid} and cq.classid=0
        order by cq.cqid
    </select>

    <!--命题质量-试题分析-试卷试题-->
    <select id="listQuestionsFroMtzlSt" resultType="java.util.Map">
        select distinct q.cqid,q.mptqid,q.qn,q.qtype,q.nd,q.ndms,q.ndfw,tq.pagenum,tq.stemcoor,tq.quecoor
        from msr_class_question q left join ms_paper_qtype_question tq on q.mptqid=tq.mptqid
        where q.examid=#{param.examid} and q.subjectid=#{param.subjectid} and q.classid=0
        order by q.cqid
    </select>

    <!--命题质量-试题分析-单试题常用分析指标-->
    <select id="listQuestionByMptqidForMtzlSt" resultType="java.util.Map">
        select cq.cqid,cq.mptqid,cq.qn,cq.fullscore,cq.stunum,cq.schoolmaxscore,
        cq.schoolminscore,cq.schoolavgscore,cq.nd,cq.bzc,cq.cyxs,cq.qfd,cq.jbzs,cq.lfnum,
        cq.lfrate,cq.mfnum,cq.mfrate from msr_class_question cq where cq.examid=#{param.examid}
        and cq.subjectid=#{param.subjectid} and cq.classid=0 and cq.mptqid=#{param.mptqid}
    </select>

    <!--学科素养-单个知识点分析-知识点下试题-->
    <select id="listQuestionsForXksyOnePoint" resultType="java.util.Map">
        select distinct cq.cqid,cq.mptqid,cq.qn,cq.fullscore,cq.schoolavgscore,cq.schoolavgrate,cq.mfnum,
                        cq.lfnum,cq.qtype,q.stemcoor,q.quecoor
        from msr_class_question cq left join ms_paper_qtype_question q on cq.mptqid=q.mptqid
        where cq.examid=#{param.examid} and cq.subjectid=#{param.subjectid} and cq.classid=0
        and cq.mptqid in (${param.mptqids}) order by cq.cqid
    </select>



</mapper>
