<?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.papercheck.MsPaperCheckTeacherTaskMapper">
    <!--批量保存或更新-->
    <insert id="batchSave">
        <foreach collection ="tasks" item="s" index= "index" separator =";">
            insert into ms_paper_check_teacher_task (mpid, mblockid, teacherid, taskorder, mpsbid, checktype, createtime)
            values (#{s.mpid},#{s.mblockid},#{s.teacherid},#{s.taskorder},#{s.mpsbid},#{s.checktype},#{s.createtime})
            on duplicate key update taskorder=#{s.taskorder},teacherid=#{s.teacherid}
        </foreach>
    </insert>
    <!--保存或更新单个任务-->
    <insert id="save">
        insert into ms_paper_check_teacher_task (mpid, mblockid, mptqid, teacherid, taskorder, mpsbid, checktype, createtime)
        values (#{s.mpid},#{s.mblockid},#{s.mptqid},#{s.teacherid},#{s.taskorder},#{s.mpsbid},#{s.checktype},#{s.createtime})
        on duplicate key update taskorder=#{s.taskorder},teacherid=#{s.teacherid},mblockid=#{s.mblockid}
    </insert>
    <!--批量更新任务信息-->
    <update id="batchUpdate">
        update ms_paper_check_teacher_task
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="teacherid = case mpcttid" suffix="end,">
                <foreach collection="tasks" item="item" separator=" ">
                    when #{item.mpcttid} then #{item.teacherid}
                </foreach>
            </trim>
            <trim prefix="taskorder = case mpcttid" suffix="end,">
                <foreach collection="tasks" item="item" separator=" ">
                    when #{item.mpcttid} then #{item.taskorder}
                </foreach>
            </trim>
        </trim>
        where mpcttid in
        <foreach collection="tasks" item="item" open="(" separator="," close=")">
            #{item.mpcttid}
        </foreach>
    </update>
    <!--更新教师阅卷任务状态-->
    <update id="updateCheckStatus">
        update ms_paper_check_teacher_task
        set checkstate = #{checkstate}
        where mpid=#{mpid} and mpsbid=#{mpsbid} and teacherid=#{teacherid}
    </update>
    <!--教师批阅-批阅试题-->
    <update id="correct">
        update ms_paper_check_teacher_task
        set checkstate = 3,checkscore = #{param.checkscore}
        <if test="param.hasgood!=null and param.hasgood!=0">
            ,hasgood=#{param.hasgood}
        </if>
        <if test="param.hasbad!=null and param.hasbad!=0">
            ,hasbad=#{param.hasbad},problemtype=#{param.problemtype}
        </if>
        <if test="param.problemcomm!=null and param.problemcomm!=''">
            ,problemcomm=#{param.problemcomm}
        </if>
        where mpid=#{param.mpid} and mpsbid=#{param.mpsbid} and teacherid=#{param.handleid}
    </update>
    <!--删除教师阅卷任务-->
    <delete id="deleteByMpsbids">
        delete from ms_paper_check_teacher_task where mpsbid in (${mpsbids})
    </delete>
    <!--根据题块ID和教师ID获取指定数量的任务ID列表-->
    <select id="getTaskIdsByMBlockIdAndTeacherId" resultType="java.lang.Integer">
        select mpcttid
        from ms_paper_check_teacher_task
        where mblockid = #{mblockid} and teacherid = #{teacherid} and checkstate != 3
        order by taskorder desc limit #{tasknum}
    </select>
    <!--阅卷进度-按题块-->
    <resultMap id="blockResultMap" type="java.util.Map">
        <id property="mblockid" column="mblockid"/>
        <result property="blockname" column="blockname"/>
        <result property="bqscore" column="bqscore"/>
        <result property="blockorder" column="blockorder"/>
        <result property="bqnum" column="bqnum"/>
        <result property="checktype" column="checktype"/>
        <result property="checkstate" column="checkstate"/>
        <result property="totalNum" column="totalNum"/>
        <result property="checkedNum" column="checkedNum"/>
        <result property="uncheckedNum" column="uncheckedNum"/>
        <collection property="teachers" select="listCheckTeacher" column="mblockid"/>
    </resultMap>
    <!--题块阅卷教师列表-->
    <select id="listCheckTeacher" resultType="java.util.Map">
        select mct.teacherid,u.username as teachername
        from t_user u,ms_paper_check_teacher mct
        where u.userid = mct.teacherid and mct.mblockid = #{mblockid}
    </select>
    <select id="listByBlock" resultMap="blockResultMap">
        select pb.mblockid,pb.blockname,pb.bqscore,pb.blockorder,pb.bqnum
        ,pc.checktype,pc.checkstate,count(distinct psb.mpsbid) as totalNum,count(distinct if(psb.checked=3,psb.mpsbid,null)) as checkedNum
        ,count(distinct if(psb.checked!=3,psb.mpsbid,null))as uncheckedNum
        ,(select group_concat(pbbq.bqn separator '、') from ms_paper_block_question pbbq where pbbq.mblockid = pb.mblockid) as bqn
        from ms_paper_check pc right join ms_paper_block pb on pc.mpid=pb.mpid and pc.mblockid = pb.mblockid
        left join ms_paper_student_block psb on psb.mpid=pc.mpid and psb.mblockid=pc.mblockid
        where pb.mpid=#{mpid} and pb.blocktype= 2
        group by pb.mblockid
        order by pb.blockorder
    </select>
    <!--阅卷进度-按题块-查看详情-->
    <select id="detailByBlock" resultType="java.util.Map">
        <if test="dispenseway!=null and dispenseway!=2">
            select pctt.teacherid,u.username as teachername
            ,count(pctt.mpcttid) as totalNum,count(if(pctt.checkstate=3,1,null)) as checkedNum
            ,count(if(pctt.checkstate!=3,1,null))as uncheckedNum
            from ms_paper_check_teacher_task pctt left join t_user u on u.userid = pctt.teacherid
            where pctt.mpid=#{mpid} and pctt.mblockid=#{mblockid}
            group by pctt.teacherid
        </if>
        <if test="dispenseway!=null and dispenseway==2">
            select t.*,u.username as teachername
            from(select pct.teacherid,count(distinct psb.mpsbid) as totalNum
            ,count(distinct if(((psb.firstcid=pct.teacherid and psb.firstcime is not null)
            <if test="checktype==2">
                or (psb.secondcid=pct.teacherid and psb.secondctime is not null)
            </if>
            )
            ,psb.mpsbid,null)) as checkedNum
            ,count(distinct if(psb.checked=1 or (psb.checked=2 and ((psb.firstcid=pct.teacherid and psb.firstcime is null)
            <if test="checktype==2">
                or (psb.secondcid=pct.teacherid and psb.secondctime is null)
                or (psb.firstcid!=pct.teacherid and psb.secondcid is null)
                or (psb.secondcid!=pct.teacherid and psb.firstcid is null)
            </if>
            )),psb.mpsbid,null)) as uncheckedNum
            from ms_paper_check_teacher pct left join ms_paper_student_block psb on pct.mpid = psb.mpid and pct.mblockid = psb.mblockid
            where pct.mpid=#{mpid} and pct.mblockid=#{mblockid}
            group by pct.teacherid
            )t left join t_user u on t.teacherid=u.userid
        </if>
    </select>
    <!--阅卷进度-按教师-->
    <resultMap id="teacherResultMap" type="java.util.Map">
        <id property="teacherid" column="teacherid"/>
        <result property="teachername" column="teachername"/>
        <collection property="blocks" ofType="java.util.Map" javaType="java.util.List">
            <id property="mblockid" column="mblockid"/>
            <result property="qorder" column="qorder"/>
            <result property="qn" column="qn"/>
            <result property="blockname" column="blockname"/>
            <result property="totalNum" column="totalNum"/>
            <result property="checkedNum" column="checkedNum"/>
            <result property="uncheckedNum" column="uncheckedNum"/>
        </collection>
    </resultMap>
    <select id="listByTeacher" resultMap="teacherResultMap">
        <if test="correcttype==1">
            select pct.teacherid,u.username as teachername
            ,count(distinct psb.mpsqid) as totalNum
            ,count(distinct if(psb.firstcid=pct.teacherid and psb.checked=3,psb.mpsqid,null)) as checkedNum
            ,count(distinct if((psb.firstcid=pct.teacherid and psb.checked=2) or psb.checked=1,psb.mpsqid,null)) as uncheckedNum
            ,psb.mptqid as mblockid,psb.qorder,psb.qn
            from ms_paper_check_teacher pct left join t_user u on u.userid = pct.teacherid
            left join ms_paper_check pc on pct.mblockid = pc.mblockid and pct.mpid = pc.mpid
            left join ms_paper_student_question psb on pct.mpid = psb.mpid
            inner join ms_class c on c.examid=psb.examid and c.subjectid=psb.subjectid and c.classid=pct.mblockid
            where pct.mpid=#{mpid} and psb.ctype in (3, 13, 14, 15) and psb.answered=1
            group by pct.teacherid,psb.mptqid
            order by teachername,psb.qorder,psb.qn
        </if>
        <if test="correcttype==2">
            select pct.teacherid,u.username as teachername
            ,if(pc.dispenseway=2,count(distinct psb.mpsqid),count(distinct pctt.mpcttid)) as totalNum
            ,count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)) as checkedNum
            ,if(pc.dispenseway=2,count(distinct if(psb.checked=1 or pctt.checkstate!=3
            or (pc.checktype=2 and (psb.firstcid is null or psb.secondcid is null)),psb.mpsqid,null))
            ,count(distinct if(pctt.checkstate!=3,pctt.mpcttid,null))) as uncheckedNum
            ,pct.mblockid,psb.qorder,psb.qn
            from ms_paper_check_teacher pct left join t_user u on u.userid = pct.teacherid
            left join ms_paper_check pc on pct.mblockid = pc.mblockid and pct.mpid = pc.mpid
            left join ms_paper_student_question psb on pct.mblockid = psb.mptqid and pct.mpid = psb.mpid and psb.answered=1
            left join ms_paper_check_teacher_task pctt on pctt.mpid = pct.mpid and pctt.mpsbid=psb.mpsqid and pctt.teacherid = pct.teacherid
            where pct.mpid=#{mpid}
            group by pct.teacherid,pct.mblockid
            order by teachername,psb.qorder,psb.qn
        </if>
        <if test="correcttype==3">
            select pct.teacherid,u.username as teachername
            ,if(pc.dispenseway=2,count(psb.mpsbid),count(distinct pctt.mpcttid)) as totalNum
            ,count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)) as checkedNum
            ,if(pc.dispenseway=2,count(distinct if(psb.checked=1 or pctt.checkstate!=3
            or (pc.checktype=2 and (psb.firstcid is null or psb.secondcid is null)),psb.mpsbid,null))
            ,count(distinct if(pctt.checkstate!=3,pctt.mpcttid,null))) as uncheckedNum
            ,pct.mblockid,pb.blockname
            from ms_paper_check_teacher pct left join t_user u on u.userid = pct.teacherid
            left join ms_paper_block pb on pct.mblockid = pb.mblockid and pct.mpid = pb.mpid
            left join ms_paper_check pc on pct.mblockid = pc.mblockid and pct.mpid = pc.mpid
            left join ms_paper_student_block psb on psb.mblockid = pct.mblockid and pct.mpid = psb.mpid
            left join ms_paper_check_teacher_task pctt on pctt.mpid = pct.mpid and pctt.mpsbid=psb.mpsbid and pctt.teacherid = pct.teacherid
            where pct.mpid=#{mpid}
            group by pct.teacherid,pct.mblockid
            order by teachername,pb.blockorder
        </if>
    </select>
    <!--教师阅卷-待/已阅卷列表-->
    <select id="listCorrect" resultType="java.util.Map">
        select t.msid,t.subjectname,t.sdate,t.begintime,t.endtime,t.examname,t.gradeid,t.examtype,t.exammode
        ,t.mpid,t.checktype,t.dispenseway,t.numtype,t.correcttype
        ,truncate(t.checkedNum*100/t.totalNum,2) as checkrate
        from(select s.msid,s.subjectname,s.sdate,s.begintime,s.endtime,e.examname,e.gradeid,e.examtype,e.exammode
        ,pc.mpid,pc.checktype,pc.dispenseway,pc.numtype,pc.correcttype
        ,truncate((count(distinct if(psb.firstcime>0 or psb.secondctime>0,psb.mpsbid,null))
        )*100/count(distinct psb.mpsbid),2) as checkrate
        ,count(distinct if(psb.firstcime>0 or psb.secondctime>0,psb.mpsbid,null)) as checkedNum
        ,count(distinct psb.mpsbid) as totalNum
        from ms_subject s inner join ms_exam e on s.examid = e.examid
        inner join ms_paper_check pc on pc.msid = s.msid
        inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid=pc.mpid
        inner join ms_paper_student_block psb on psb.mblockid = pc.mblockid and psb.mpid = pc.mpid
        where e.schoolid=#{param.schoolid} and s.checkstate=1 and e.deleted=1 and pc.dispenseway=2 and pc.correcttype=3
        and (psb.checked=1 or (psb.checked in(2,3) and (psb.firstcid=#{param.handleid} or psb.secondcid=#{param.handleid})))
        group by s.msid
        <if test="param.checktype==0">having 100>checkrate</if>
        <if test="param.checktype==1">having 100=checkrate</if>
        union
        select s.msid,s.subjectname,s.sdate,s.begintime,s.endtime,e.examname,e.gradeid,e.examtype,e.exammode
        ,pc.mpid,pc.checktype,pc.dispenseway,pc.numtype,pc.correcttype
        ,truncate((count(distinct if(psb.firstcime>0 or psb.secondctime>0,psb.mpsqid,null))
        )*100/count(distinct psb.mpsqid),2) as checkrate
        ,count(distinct if(psb.firstcime>0 or psb.secondctime>0,psb.mpsqid,null)) as checkedNum
        ,count(distinct psb.mpsqid) as totalNum
        from ms_subject s inner join ms_exam e on s.examid = e.examid
        inner join ms_paper_check pc on pc.msid = s.msid
        inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid=pc.mpid
        inner join ms_paper_student_question psb on psb.mptqid = pc.mblockid and psb.mpid = pc.mpid
        where e.schoolid=#{param.schoolid} and s.checkstate=1 and e.deleted=1 and pc.dispenseway=2 and pc.correcttype=2
        and (psb.checked=1 or (psb.checked in(2,3) and (psb.firstcid=#{param.handleid} or psb.secondcid=#{param.handleid})))
        group by s.msid
        <if test="param.checktype==0">having 100>checkrate</if>
        <if test="param.checktype==1">having 100=checkrate</if>
        union
        select s.msid,s.subjectname,s.sdate,s.begintime,s.endtime,e.examname,e.gradeid,e.examtype,e.exammode
        ,pc.mpid,pc.checktype,pc.dispenseway,pc.numtype,pc.correcttype
        ,truncate((count(distinct if(psb.firstcime>0 or psb.secondctime>0,psb.mpsqid,null))
        )*100/count(distinct psb.mpsqid),2) as checkrate
        ,count(distinct if(psb.firstcime>0 or psb.secondctime>0,psb.mpsqid,null)) as checkedNum
        ,count(distinct psb.mpsqid) as totalNum
        from ms_subject s inner join ms_exam e on s.examid = e.examid
        inner join ms_paper_check pc on pc.msid = s.msid
        inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid=pc.mpid
        inner join ms_class_student cs on cs.examid = e.examid and cs.subjectid = s.subjectid and cs.classid = pct.mblockid
        inner join ms_paper_student_question psb on psb.studentid = cs.studentid and psb.mpid = pc.mpid
        where e.schoolid=#{param.schoolid} and s.checkstate=1 and e.deleted=1 and pc.dispenseway=2 and pc.correcttype=1
        and (psb.checked=1 or (psb.checked in(2,3) and (psb.firstcid=#{param.handleid} or psb.secondcid=#{param.handleid})))
        group by s.msid
        <if test="param.checktype==0">having 100>checkrate</if>
        <if test="param.checktype==1">having 100=checkrate</if>
        union
        select s.msid,s.subjectname,s.sdate,s.begintime,s.endtime,e.examname,e.gradeid,e.examtype,e.exammode
        ,pc.mpid,pc.checktype,pc.dispenseway,pc.numtype,pc.correcttype
        ,truncate((count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)))*100/count(distinct pctt.mpcttid),2) as checkrate
        ,count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)) as checkedNum
        ,count(distinct pctt.mpcttid) as totalNum
        from ms_subject s inner join ms_exam e on s.examid = e.examid
        inner join ms_paper_check pc on pc.msid = s.msid
        inner join ms_paper_check_teacher_task pctt on pc.mblockid = pctt.mblockid and pctt.mpid=pc.mpid
        where e.schoolid=#{param.schoolid} and s.checkstate=1 and e.deleted=1 and pc.dispenseway in(1,3)
        and pctt.teacherid = #{param.handleid}
        group by s.msid
        <if test="param.checktype==0">having 100>checkrate</if>
        <if test="param.checktype==1">having 100=checkrate</if>
        )t
        group by t.msid
        <if test="param.checktype==0">having 100>checkrate</if>
        <if test="param.checktype==1">having 100=checkrate</if>
        order by msid desc
    </select>
    <!--教师阅卷-待阅卷详情-->
    <select id="listPendingBlock" resultType="java.util.Map">
        <if test="param.correcttype==3">
            select pb.blockname,pb.blockorder,pb.bqnum
            ,pc.mblockid,pc.checktype,pc.dispenseway,pc.numtype
            ,count(psb.mpsbid) as totalNum
            ,count(distinct if(psb.checked=3,psb.mpsbid,null)) as totalCheckedNum
            ,count(distinct if(psb.checked in(1,2),psb.mpsbid,null)) as totalUncheckedNum
            ,count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)) as myCheckedNum
            ,if(pc.dispenseway=2,count(distinct if(psb.checked=1 or pctt.checkstate!=3
            or (pc.checktype=2 and (psb.firstcid is null or psb.secondcid is null)),psb.mpsbid,null))
            ,count(distinct if(pctt.checkstate!=3,pctt.mpcttid,null))) as myUncheckedNum
            ,(select group_concat(pbbq.bqn separator '、') from ms_paper_block_question pbbq where pbbq.mblockid = pb.mblockid) as bqn
            from ms_paper_check pc left join ms_paper_student_block psb on psb.mblockid = pc.mblockid and psb.mpid = pc.mpid
            and psb.checked!=0
            inner join ms_paper_block pb on pc.mblockid = pb.mblockid and pb.mpid = pc.mpid
            inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid=pc.mpid and pct.teacherid = #{param.handleid}
            left join ms_paper_check_teacher_task pctt on pctt.mpid = pct.mpid and pctt.mpsbid=psb.mpsbid and pctt.teacherid = pct.teacherid
            where pc.mpid=#{param.mpid}
            group by pb.mblockid
            order by pb.blockorder
        </if>
        <if test="param.correcttype==2">
            select pb.qorder,pb.qn
            ,pc.mblockid,pc.checktype,pc.dispenseway,pc.numtype
            ,count(distinct psb.mpsqid) as totalNum
            ,count(distinct if(psb.checked=3,psb.mpsqid,null)) as totalCheckedNum
            ,count(distinct if(psb.checked in(1,2),psb.mpsqid,null)) as totalUncheckedNum
            ,count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)) as myCheckedNum
            ,if(pc.dispenseway=2,count(distinct if(psb.checked=1 or pctt.checkstate!=3
            or (pc.checktype=2 and (psb.firstcid is null or psb.secondcid IS NULL)),psb.mpsqid,null))
            ,count(distinct if(pctt.checkstate!=3,pctt.mpcttid,null))) as myUncheckedNum
            from ms_paper_check pc left join ms_paper_student_question psb on psb.mptqid = pc.mblockid and psb.mpid = pc.mpid
            and psb.checked!=0 and psb.answered=1
            inner join ms_paper_qtype_question pb on pc.mblockid = pb.mptqid and pb.mpid = pc.mpid
            inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid=pc.mpid and pct.teacherid = #{param.handleid}
            left join ms_paper_check_teacher_task pctt on pctt.mpid = pct.mpid and pctt.mpsbid=psb.mpsqid and pctt.teacherid = pct.teacherid
            where pc.mpid=#{param.mpid}
            group by pb.mptqid
            order by pb.mptqid
        </if>
        <if test="param.correcttype==1">
            select c.classname,c.classtype
            ,pc.mblockid,pc.checktype,pc.dispenseway,pc.numtype
            ,count(distinct psb.mpsqid) as totalNum
            ,count(distinct if(psb.checked=3,psb.mpsqid,null)) as totalCheckedNum
            ,count(distinct if(psb.checked in(1,2),psb.mpsqid,null)) as totalUncheckedNum
            ,count(distinct if(pctt.checkstate=3,pctt.mpcttid,null)) as myCheckedNum
            ,if(pc.dispenseway=2,count(distinct if(psb.checked=1 or pctt.checkstate!=3
            or (pc.checktype=2 and (psb.firstcid is null or psb.secondcid IS NULL)),psb.mpsqid,null))
            ,count(distinct if(pctt.checkstate!=3,pctt.mpcttid,null))) as myUncheckedNum
            from ms_paper_check pc inner join ms_class c on pc.mblockid = c.classid
            inner join ms_class_student cs on c.examid=cs.examid and c.subjectid=cs.subjectid and pc.mblockid=cs.classid
            inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid=pc.mpid and pct.teacherid = #{param.handleid}
            left join ms_paper_student_question psb on psb.mpid = pc.mpid and psb.studentid=cs.studentid and psb.checked!=0 and psb.answered=1
            left join ms_paper_check_teacher_task pctt on pctt.mpid = pct.mpid and pctt.mpsbid=psb.mpsqid and pctt.teacherid = pct.teacherid
            where pc.mpid=#{param.mpid} and c.subjectid=#{param.subjectid}
            group by c.classid
            order by c.mcid
        </if>
    </select>
    <!--教师阅卷-题块列表-->
    <resultMap id="teacherBlockResultMap" type="java.util.Map">
        <result property="mblockid" column="mblockid"/>
        <result property="blockname" column="blockname"/>
        <result property="blockorder" column="blockorder"/>
        <result property="bqnum" column="bqnum"/>
        <collection property="questions" select="listQuestion" column="mblockid"/>
    </resultMap>
    <select id="listQuestion" resultType="java.util.Map">
        select pbq.mbqid,pbq.mptqid,pbq.mbqtype,pbq.bqscore,pbq.bqorder,pbq.bqn
        ,pbq.mergeqid,pbq.mergeqn,pbq.mergescore,pbq.scorestepway,pbq.scorestep
        from ms_paper_block_question pbq where pbq.mblockid=#{mblockid}
        order by pbq.bqn
    </select>
    <select id="listTeacherBlock" resultMap="teacherBlockResultMap">
        select pct.mblockid,pb.blockname,pb.blockorder,pb.bqnum
        from ms_paper_block pb inner join ms_paper_check_teacher pct on pb.mblockid = pct.mblockid
        and pct.teacherid = #{param.handleid}
        where pct.mpid=#{param.mpid}
        group by pb.mblockid
        order by pb.blockorder
    </select>
    <!--教师阅卷-试题列表-->
    <select id="listTeacherQuestion" resultType="java.util.Map">
        <if test="param.correcttype==1">
            select pb.mptqid as mblockid,pb.qorder,pb.qn,pb.qscore
            from ms_paper_qtype_question pb
            where pb.mpid=#{param.mpid} and pb.qtype=2
            group by pb.mptqid
            order by pb.qorder,pb.qn
        </if>
        <if test="param.correcttype==2">
            select pct.mblockid,pb.qorder,pb.qn,pb.qscore
            from ms_paper_qtype_question pb inner join ms_paper_check_teacher pct on pb.mptqid = pct.mblockid
            and pct.teacherid = #{param.handleid}
            where pb.mpid=#{param.mpid}
            group by pb.mptqid
            order by pb.qorder,pb.qn
        </if>
    </select>
    <!--教师阅卷-班级列表-->
    <select id="listTeacherClass" resultType="java.util.Map">
        select pct.mblockid,c.classname,c.classtype
        from ms_paper_check_teacher pct inner join ms_paper p on pct.mpid = p.mpid
        inner join ms_class c on pct.mblockid = c.classid and c.examid = p.examid and c.subjectid = p.subjectid
        where pct.mpid=#{param.mpid} and pct.teacherid = #{param.handleid}
        order by c.mcid
    </select>
    <!--教师阅卷-待批题块列表-->
    <select id="listBlockCheck" resultType="com.xhkjedu.smarking.model.papercheck.MsPaperCheck">
        select pc.mblockid,pc.checktype,pc.hidefirstscore,pc.scoreway,pc.finalscore,pc.roundvalue,pc.dispenseway,pc.numtype
        ,pc.checkstate,pc.correcttype,pc.mpid
        from ms_paper_check pc inner join ms_paper_student_block psb on psb.mblockid = pc.mblockid and psb.mpid = pc.mpid
        inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid = pc.mpid and pct.teacherid = #{param.handleid}
        where pc.checkstate=1 and psb.checked in(1,2) and pc.mpid=#{param.mpid}
        <if test="param.mblockid!=null and param.mblockid!=0">
            and pc.mblockid=#{param.mblockid}
        </if>
        group by pc.mblockid
        order by pc.mpcid
    </select>
    <!--教师阅卷-按题块-获取待批试题-->
    <select id="getCorrectBlock" resultType="com.xhkjedu.smarking.vo.papercheck.MsPaperCheckVo">
        <if test="param.dispenseway!=null and param.dispenseway!=2">
            select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
            ,2 as answertype
            ,pctt.mpid,pctt.mblockid,pctt.mpsbid,pctt.mptqid,pctt.checktype
            from ms_paper_student_block psq inner join ms_paper_check_teacher_task pctt on psq.mpsbid = pctt.mpsbid and psq.mpid=pctt.mpid
            where pctt.mpid=#{param.mpid} and pctt.mblockid = #{param.mblockid} and pctt.teacherid = #{param.teacherid}
            and pctt.checkstate!=3 and psq.hasproblem=0
            order by psq.mpsbid,field(pctt.checkstate,2,1,3),pctt.taskorder
            limit 1
        </if>
        <if test="param.dispenseway!=null and param.dispenseway==2">
            select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
            ,2 as answertype
            ,psq.mblockid,psq.mpsbid,psq.firstcid
            from ms_paper_student_block psq
            where psq.mpid=#{param.mpid} and psq.mblockid = #{param.mblockid}
            and (psq.checked=1 or (psq.checked=2 and ((psq.firstcid=#{param.teacherid} and psq.firstcime is null)
            <if test="param.checktype==2">
                or (psq.secondcid=#{param.teacherid} and psq.secondctime is null)
                or (psq.firstcid!=#{param.teacherid} and psq.secondcid is null)
                or (psq.secondcid!=#{param.teacherid} and psq.firstcid is null)
            </if>
            )))
            and psq.hasproblem=0
            order by psq.mpsbid,field(psq.checked,2,1,3)
            limit 1
        </if>
    </select>
    <!--阅卷进度-按试题-->
    <resultMap id="questionResultMap" type="java.util.Map">
        <result property="qorder" column="qorder"/>
        <result property="qn" column="qn"/>
        <result property="qscore" column="qscore"/>
        <result property="mblockid" column="mblockid"/>
        <result property="mpid" column="mpid"/>
        <result property="checktype" column="checktype"/>
        <result property="checkstate" column="checkstate"/>
        <result property="totalNum" column="totalNum"/>
        <result property="checkedNum" column="checkedNum"/>
        <result property="uncheckedNum" column="uncheckedNum"/>
        <collection property="teachers" select="listCheckTeacher" column="mblockid"/>
    </resultMap>
    <select id="listByQuestion" resultMap="questionResultMap">
        select q.qorder,q.qn,q.qscore,q.mptqid as mblockid,q.mpid,pc.checktype,pc.checkstate
        ,count(distinct psq.mpsqid) as totalNum
        ,count(distinct if(psq.checked=3,psq.mpsqid,null)) as checkedNum
        ,count(distinct if(psq.checked!=3,psq.mpsqid,null)) as uncheckedNum
        from ms_paper_qtype_question q left join ms_paper_check pc on q.mpid=pc.mpid and pc.mblockid=q.mptqid
        left join ms_paper_student_question psq on q.mptqid=psq.mptqid and psq.answered=1
        where q.mpid=#{mpid} and q.qtype=2
        group by q.mptqid
        order by q.qorder,q.qn
    </select>
    <!--阅卷进度-按试题-查看详情-->
    <select id="detailByQuestion" resultType="java.util.Map">
        <if test="dispenseway!=null and dispenseway!=2">
            select pctt.teacherid,u.username as teachername
            ,count(pctt.mpcttid) as totalNum,count(if(pctt.checkstate=3,1,null)) as checkedNum
            ,count(if(pctt.checkstate!=3,1,null))as uncheckedNum
            from ms_paper_check_teacher_task pctt left join t_user u on u.userid = pctt.teacherid
            where pctt.mpid=#{mpid} and pctt.mblockid=#{mblockid}
            group by pctt.teacherid
        </if>
        <if test="dispenseway!=null and dispenseway==2">
            select t.*,u.username as teachername
            from(select pct.teacherid,count(distinct psb.mpsqid) as totalNum
            ,count(distinct if(((psb.firstcid=pct.teacherid and psb.firstcime is not null)
            <if test="checktype==2">
                or (psb.secondcid=pct.teacherid and psb.secondctime is not null)
            </if>
            )
            ,psb.mpsqid,null)) as checkedNum
            ,count(distinct if(psb.checked=1 or (psb.checked=2 and ((psb.firstcid=pct.teacherid and psb.firstcime is null)
            <if test="checktype==2">
                or (psb.secondcid=pct.teacherid and psb.secondctime is null)
                or (psb.firstcid!=pct.teacherid and psb.secondcid is null)
                or (psb.secondcid!=pct.teacherid and psb.firstcid is null)
            </if>
            )),psb.mpsqid,null)) as uncheckedNum
            from ms_paper_check_teacher pct left join ms_paper_student_question psb on pct.mpid=psb.mpid and pct.mblockid=psb.mptqid and psb.answered=1
            where pct.mpid=#{mpid} and pct.mblockid=#{mblockid}
            group by pct.teacherid
            )t left join t_user u on t.teacherid=u.userid
        </if>
    </select>
    <!--阅卷进度-按班级-->
    <resultMap id="classResultMap" type="java.util.Map">
        <result property="classname" column="classname"/>
        <result property="mblockid" column="mblockid"/>
        <result property="mpid" column="mpid"/>
        <result property="checktype" column="checktype"/>
        <result property="checkstate" column="checkstate"/>
        <result property="totalNum" column="totalNum"/>
        <result property="checkedNum" column="checkedNum"/>
        <result property="uncheckedNum" column="uncheckedNum"/>
        <collection property="teachers" select="listCheckTeacher" column="mblockid"/>
    </resultMap>
    <select id="listByClass" resultMap="classResultMap">
        select c.classname,c.classid as mblockid,pc.mpid,pc.checktype,pc.checkstate
        ,count(distinct psq.mpsqid) as totalNum
        ,count(distinct if(psq.checked=3,psq.mpsqid,null)) as checkedNum
        ,count(distinct if(psq.checked!=3,psq.mpsqid,null)) as uncheckedNum
        from ms_class c inner join ms_paper_check pc on pc.mblockid=c.classid
        inner join ms_class_student cs on c.examid=cs.examid and c.subjectid=cs.subjectid and pc.mblockid=cs.classid
        left join ms_paper_student_question psq on pc.mpid=psq.mpid and psq.studentid=cs.studentid and psq.answered=1 and psq.ctype in(3,13,14,15)
        where pc.mpid=#{mpid} and c.subjectid=#{subjectid}
        group by c.classid
        order by c.mcid
    </select>
    <!--阅卷进度-按班级-查看详情-->
    <select id="detailByClass" resultType="java.util.Map">
        select t.*,u.username as teachername
        from(select pct.teacherid,count(distinct if(psb.answered=1,psb.mpsqid,null)) as totalNum
        ,count(distinct if(psb.checked=3 and psb.firstcid=pct.teacherid,psb.mpsqid,null)) as checkedNum
        from ms_paper_check_teacher pct left join ms_paper_student_question psb on psb.mpid=pct.mpid and psb.ctype in(3,13,14,15)
        inner join ms_class_student cs on psb.examid=cs.examid and psb.subjectid=cs.subjectid and psb.studentid=cs.studentid
        and cs.classid=pct.mblockid
        where pct.mpid=#{mpid} and pct.mblockid=#{mblockid}
        group by pct.teacherid
        )t left join t_user u on t.teacherid=u.userid
    </select>
    <!--教师阅卷-待批试题列表-->
    <select id="listQuestionCheck" resultType="com.xhkjedu.smarking.model.papercheck.MsPaperCheck">
        select pc.mblockid,pc.checktype,pc.hidefirstscore,pc.scoreway,pc.finalscore,pc.roundvalue,pc.dispenseway,pc.numtype
        ,pc.checkstate,pc.correcttype,pc.mpid
        from ms_paper_check pc inner join ms_paper_student_question psb on psb.mptqid = pc.mblockid and psb.mpid = pc.mpid
        inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid = pc.mpid and pct.teacherid = #{param.handleid}
        where pc.checkstate=1 and psb.checked in(1,2) and pc.mpid=#{param.mpid}
        <if test="param.mblockid!=null and param.mblockid!=0">
            and pc.mblockid=#{param.mblockid}
        </if>
        group by pc.mblockid
        order by pc.mpcid
    </select>
    <!--教师阅卷-按试题-获取待批试题-->
    <select id="getCorrectQuestion" resultType="com.xhkjedu.smarking.vo.papercheck.MsPaperCheckVo">
        <if test="param.dispenseway!=null and param.dispenseway!=2">
            select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
            ,psq.answertype
            ,pctt.mpid,pctt.mblockid,pctt.mpsbid,pctt.mptqid,pctt.checktype
            from ms_paper_student_question psq inner join ms_paper_check_teacher_task pctt on psq.mpsqid = pctt.mpsbid and psq.mpid=pctt.mpid
            where pctt.mpid=#{param.mpid} and pctt.mblockid = #{param.mblockid} and pctt.teacherid = #{param.teacherid}
            and pctt.checkstate!=3 and psq.hasproblem=0
            order by psq.mptqid,field(pctt.checkstate,2,1,3),pctt.taskorder
            limit 1
        </if>
        <if test="param.dispenseway!=null and param.dispenseway==2">
            select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
            ,psq.answertype
            ,psq.mptqid as mblockid,psq.mpsqid as mpsbid,psq.mptqid,psq.firstcid
            from ms_paper_student_question psq
            where psq.mpid=#{param.mpid} and psq.mptqid = #{param.mblockid}
            and (psq.checked=1 or (psq.checked=2 and ((psq.firstcid=#{param.teacherid} and psq.firstcime is null)
            <if test="param.checktype==2">
                or (psq.secondcid=#{param.teacherid} and psq.secondctime is null)
                or (psq.firstcid!=#{param.teacherid} and psq.secondcid is null)
                or (psq.secondcid!=#{param.teacherid} and psq.firstcid is null)
            </if>
            )))
            and psq.hasproblem=0
            order by psq.mptqid,field(psq.checked,2,1,3)
            limit 1
        </if>
    </select>
    <!--教师阅卷-待批班级列表-->
    <select id="listClassCheck" resultType="com.xhkjedu.smarking.model.papercheck.MsPaperCheck">
        select pc.mblockid,pc.checktype,pc.hidefirstscore,pc.scoreway,pc.finalscore,pc.roundvalue,pc.dispenseway,pc.numtype
        ,pc.checkstate,pc.correcttype,pc.mpid
        from ms_paper_check pc inner join ms_paper_student_question psb on psb.mpid = pc.mpid
        inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid = pc.mpid and pct.teacherid = #{param.handleid}
        where pc.checkstate=1 and psb.checked in(1,2) and pc.mpid=#{param.mpid}
        <if test="param.mblockid!=null and param.mblockid!=0">
            and pc.mblockid=#{param.mblockid}
        </if>
        <if test="param.mptqid!=null and param.mptqid!=0">
            and psb.mptqid=#{param.mptqid}
        </if>
        group by pc.mblockid
        order by pc.mpcid
    </select>
    <!--教师阅卷-按班级-获取待批试题-->
    <select id="getCorrectClassQuestion" resultType="com.xhkjedu.smarking.vo.papercheck.MsPaperCheckVo">
        <if test="param.dispenseway!=null and param.dispenseway!=2">
            select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
            ,psq.answertype
            ,pctt.mpid,pctt.mblockid,pctt.mpsbid,pctt.mptqid,pctt.checktype
            from ms_paper_student_question psq inner join ms_paper_check_teacher_task pctt on psq.mpsqid = pctt.mpsbid and psq.mpid=pctt.mpid
            where pctt.mpid=#{param.mpid} and pctt.mblockid = #{param.mblockid} and pctt.teacherid = #{param.teacherid}
            and pctt.checkstate!=3 and psq.hasproblem=0
            <if test="param.mptqid!=null and param.mptqid!=0">
                and psq.mptqid=#{param.mptqid}
            </if>
            order by psq.mptqid,field(pctt.checkstate,2,1,3),pctt.taskorder
            limit 1
        </if>
        <if test="param.dispenseway!=null and param.dispenseway==2">
            select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
            ,psq.answertype
            ,c.classid as mblockid,psq.mpsqid as mpsbid,psq.mptqid,psq.firstcid
            from ms_paper_student_question psq inner join ms_class c on c.examid=psq.examid and c.subjectid=psq.subjectid
            inner join ms_class_student cs on cs.examid=psq.examid and cs.subjectid=psq.subjectid and cs.studentid=psq.studentid
            where psq.mpid=#{param.mpid} and c.classid = #{param.mblockid}
            and (psq.checked=1 or (psq.checked=2 and ((psq.firstcid=#{param.teacherid} and psq.firstcime is null)
            <if test="param.checktype==2">
                or (psq.secondcid=#{param.teacherid} and psq.secondctime is null)
                or (psq.firstcid!=#{param.teacherid} and psq.secondcid is null)
                or (psq.secondcid!=#{param.teacherid} and psq.firstcid is null)
            </if>
            )))
            and psq.hasproblem=0
            <if test="param.mptqid!=null and param.mptqid!=0">
                and psq.mptqid=#{param.mptqid}
            </if>
            order by psq.mptqid,field(psq.checked,2,1,3),psq.mptqid
            limit 1
        </if>
    </select>
    <!--获取教师批阅数量-->
    <select id="getCheckNum" resultType="com.xhkjedu.smarking.model.papercheck.MsPaperCheckTeacher">
        <if test="param.dispenseway!=null and param.dispenseway!=2">
            select count(pctt.mpcttid) as tasknum,count(if(pctt.checkstate=3,1,null)) as checkednum
            from ms_paper_check_teacher pct left join ms_paper_check_teacher_task pctt on pct.mpid=pctt.mpid and pct.teacherid=pctt.teacherid and pct.mblockid=pctt.mblockid
            where pct.mpid=#{param.mpid} and pct.teacherid=#{param.teacherid} and pct.mblockid=#{param.mblockid}
        </if>
        <if test="param.dispenseway!=null and param.dispenseway==2">
            <if test="param.correcttype==3">
                select count(psb.mpsbid) as tasknum
                ,count(if(pctt.checkstate=3,1,null)) as checkednum
                from ms_paper_student_block psb left join ms_paper_check_teacher_task pctt on psb.mpid=pctt.mpid and pctt.teacherid=#{param.teacherid} and psb.mpsbid=pctt.mpsbid
                where psb.mpid=#{param.mpid} and psb.mblockid=#{param.mblockid} and psb.checked!=0
            </if>
            <if test="param.correcttype==2">
                select count(psb.mpsqid) as tasknum
                ,count(if(pctt.checkstate=3,1,null)) as checkednum
                from ms_paper_student_question psb left join ms_paper_check_teacher_task pctt on psb.mpid=pctt.mpid and pctt.teacherid=#{param.teacherid} and psb.mpsqid=pctt.mpsbid
                where psb.mpid=#{param.mpid} and psb.mptqid=#{param.mblockid} and psb.checked!=0
            </if>
            <if test="param.correcttype==1">
                select count(psb.mpsqid) as tasknum
                ,count(if(pctt.checkstate=3,1,null)) as checkednum
                from ms_paper_student_question psb left join ms_paper_check_teacher_task pctt on psb.mpid=pctt.mpid and pctt.teacherid=#{param.teacherid} and psb.mpsqid=pctt.mpsbid
                inner join ms_class_student cs on psb.examid=cs.examid and psb.subjectid=cs.subjectid and psb.studentid=cs.studentid
                where psb.mpid=#{param.mpid} and psb.mptqid=#{param.mptqid} and cs.classid=#{param.mblockid} and psb.checked!=0
            </if>
        </if>
    </select>
    <!--教师阅卷-上一份-->
    <select id="getPreCorrect" resultType="java.util.Map">
        select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
        <if test="param.correcttype==3">
            ,2 as answertype
        </if>
        <if test="param.correcttype!=3">
            ,psq.answertype
        </if>
        ,pctt.mpid,pctt.mblockid,pctt.mpsbid,pctt.mptqid,pctt.taskorder,pctt.checkscore,pctt.checktype
        from ms_paper_check_teacher_task pctt
        <if test="param.correcttype==3">
            inner join ms_paper_student_block psq on pctt.mpsbid=psq.mpsbid
        </if>
        <if test="param.correcttype!=3">
            inner join ms_paper_student_question psq on pctt.mpsbid=psq.mpsqid
        </if>
        where pctt.mpid=#{param.mpid} and pctt.mblockid=#{param.mblockid} and pctt.teacherid=#{param.handleid}
        and pctt.checkstate=3 and #{param.taskorder}>pctt.taskorder
        <if test="param.mptqid!=null and param.mptqid!=0">
            and pctt.mptqid=#{param.mptqid}
        </if>
        order by pctt.taskorder desc limit 1
    </select>
    <!--教师阅卷-阅卷历史-->
    <select id="listCorrectHistory" resultType="java.util.Map">
        select pctt.mpcttid,pctt.taskorder,pctt.checkscore
        ,(case when pctt.hasgood=1 then '优' when pctt.hasbad=1 then '违' when pctt.hasproblem=1 then '疑' else '' end) as comm
        from ms_paper_check_teacher_task pctt
        where pctt.mpid=#{param.mpid} and pctt.mblockid = #{param.mblockid} and pctt.teacherid = #{param.handleid}
        and pctt.checkstate=3
        <if test="param.mptqid!=null and param.mptqid!=0">
            and pctt.mptqid=#{param.mptqid}
        </if>
        <if test="param.taskorder!=null and param.taskorder!=0">
            and pctt.taskorder=#{param.taskorder}
        </if>
        order by pctt.taskorder desc
    </select>
    <!--教师阅卷-历史详情-->
    <select id="detailHistory" resultType="java.util.Map">
        select psq.stuanswer,psq.stumerge,psq.hasgood,psq.hasbad,psq.hasproblem,psq.problemtype,psq.problemcomm
        <if test="param.correcttype==3">
             ,2 as answertype
        </if>
        <if test="param.correcttype!=3">
            ,psq.answertype
        </if>
        ,pctt.mpid,pctt.mblockid,pctt.mpsbid,pctt.mptqid,pctt.taskorder,pctt.checkscore,pctt.checktype
        ,psq.hasfinal
        from ms_paper_check_teacher_task pctt
        <if test="param.correcttype==3">
            inner join ms_paper_student_block psq on pctt.mpsbid=psq.mpsbid
        </if>
        <if test="param.correcttype!=3">
            inner join ms_paper_student_question psq on pctt.mpsbid=psq.mpsqid
        </if>
        where pctt.mpcttid=#{param.mpcttid}
    </select>
    <!--教师阅卷-平均分-->
    <select id="avgScore" resultType="java.util.Map">
        select if(count(pctt.mpcttid)=0,0,truncate(avg(pctt.checkscore),2)) as avgscore
        ,if(count(pctt2.mpcttid)=0,0,truncate(avg(pctt2.checkscore),2)) as myavgscore
        from ms_paper_check_teacher_task pctt left join ms_paper_check_teacher_task pctt2 on pctt.mpcttid=pctt2.mpcttid and pctt2.teacherid = #{param.handleid}
        where pctt.mpid=#{param.mpid} and pctt.mblockid = #{param.mblockid}
        and pctt.checkstate=3
        <if test="param.mptqid!=null and param.mptqid!=0">
            and pctt.mptqid=#{param.mptqid}
        </if>
    </select>
    <!--教师阅卷-待批阅数量-->
    <select id="getPendingCorrectNum" resultType="java.lang.Integer">
        select sum(a.num) from(select if(pc.correcttype=3,if(pc.dispenseway=2
        ,(select count(psb.mpsbid) from ms_paper_student_block psb
        where psb.mpid=pct.mpid and psb.mblockid=pct.mblockid and psb.hasproblem=0
        and (psb.checked=1 or (psb.checked=2 and ((psb.firstcid=pct.teacherid and psb.firstcime is null)
            or (psb.secondcid=pct.teacherid and psb.secondctime is null)))))
        ,(select count(pctt.mpcttid) from ms_paper_check_teacher_task pctt where pctt.mpid = pc.mpid and pctt.teacherid = #{param.handleid} and pctt.checkstate!=3)
        ),if(pc.dispenseway=2
        ,if(pc.correcttype=2,(select count(psb.mpsqid) from ms_paper_student_question psb
        where psb.mpid=pct.mpid and psb.mptqid=pct.mblockid and psb.hasproblem=0
        and (psb.checked=1 or (psb.checked=2 and ((psb.firstcid=pct.teacherid and psb.firstcime is null)
        or (psb.secondcid=pct.teacherid and psb.secondctime is null)))))
        ,(select count(psb.mpsqid) from ms_paper_student_question psb
        inner join ms_class c on c.examid=psb.examid and c.subjectid=psb.subjectid and c.classid=pct.mblockid
        inner join ms_class_student cs on c.examid=cs.examid and c.subjectid=cs.subjectid and pc.mblockid=cs.classid
        where psb.mpid=pct.mpid and psb.mptqid=pct.mblockid and psb.hasproblem=0 and psb.studentid=cs.studentid
        and (psb.checked=1 or (psb.checked=2 and ((psb.firstcid=pct.teacherid and psb.firstcime is null)
        or (psb.secondcid=pct.teacherid and psb.secondctime is null))))))
        ,(select count(pctt.mpcttid) from ms_paper_check_teacher_task pctt where  pctt.mpid = pc.mpid and pctt.teacherid = #{param.handleid} and pctt.checkstate!=3)
        )) as num
        from ms_paper_check pc inner join ms_paper_check_teacher pct on pc.mblockid = pct.mblockid and pct.mpid = pc.mpid
        where pc.checkstate=1 and pct.teacherid = #{param.handleid}) as a
    </select>
    <!--教师阅卷-待仲裁数量-->
    <select id="getPendingArbitrateNum" resultType="java.lang.Integer">
        select sum(a.num) from(select if(pc.correcttype=3,(select count(psb.mpsbid) from ms_paper_student_block psb
        where psb.mpid=pc.mpid and psb.mblockid=pc.mblockid and psb.arbitratestate=1)
        ,(select count(psb.mpsqid) from ms_paper_student_question psb
        where psb.mpid=pc.mpid and psb.mptqid=pc.mblockid and psb.arbitratestate=1)) as num
        from ms_paper_check pc
        where pc.checkstate=1 and pc.arbitrateid = #{param.handleid}) as a
    </select>
    <!--获取批阅结果-->
    <select id="getCheckResult" resultType="com.xhkjedu.smarking.vo.papercheck.MsCheckVo">
        select psq.firstcid,psq.firstcime,psq.firstccore,psq.secondcid,psq.secondctime,psq.secondcscore
        ,psq.mpsid
        <if test="param.correcttype==3">
            ,psq.firstccores,psq.secondcscores
            from ms_paper_student_block psq
            where psq.mpsbid=#{param.mpsbid}
        </if>
        <if test="param.correcttype!=3">
            from ms_paper_student_question psq
            where psq.mpsqid=#{param.mpsbid}
        </if>
    </select>
</mapper>
