<?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.paper.MsPaperBlockMapper">

    <resultMap id="paperBlockResultMap" type="com.xhkjedu.smarking.model.paper.MsPaperBlock">
        <result property="mblockid" column="mblockid"/>
        <result property="mpid" column="mpid"/>
        <result property="blockname" column="blockname"/>
        <result property="blocktype" column="blocktype"/>
        <result property="blockorder" column="blockorder"/>
        <result property="bqnum" column="bqnum"/>
        <result property="bqscore" column="bqscore"/>
        <collection property="questions" ofType="com.xhkjedu.smarking.model.paper.MsPaperBlockQuestion" javaType="java.util.List">
            <result property="mbqid" column="mbqid"/>
            <result property="mbqtype" column="mbqtype"/>
            <result property="mptqid" column="mptqid"/>
            <result property="bqn" column="bqn"/>
            <result property="bqscore" column="qscore"/>
            <result property="bqorder" column="bqorder"/>
            <result property="mergeqid" column="mergeqid"/>
            <result property="mergeqn" column="mergeqn"/>
            <result property="mergescore" column="mergescore"/>
            <result property="scorestepway" column="scorestepway"/>
            <result property="scorestep" column="scorestep"/>
        </collection>
    </resultMap>

    <!--获取题块及题块下试题-->
    <select id="listPaperBlockQuestions" resultMap="paperBlockResultMap">
        select b.mblockid,b.mpid,b.blockname,b.blocktype,b.blockorder,b.bqnum,b.bqscore,
        q.mbqid,q.mbqtype,q.mptqid,q.bqn,q.bqscore as qscore,q.bqorder,q.mergeqid,q.mergeqn,q.mergescore,q.scorestepway,q.scorestep
        from ms_paper_block b
        left join ms_paper_block_question q on b.mblockid=q.mblockid
        left join ms_paper p on b.mpid=p.mpid
        where p.mpid = #{mpid}
        <if test="blocktype!=null and blocktype > 0"> and b.blocktype=#{blocktype} </if>
        order by b.blockorder,q.bqorder
    </select>

    <!--根据试卷ID删除题块-->
    <delete id="deleteObjByMpidAndBlocktype">
        delete from ms_paper_block where mpid = #{mpid}
        <if test="blocktype!=null and blocktype > 0">
            and blocktype = #{blocktype}
        </if>
    </delete>

    <!--获取试卷中所有主观题题块ID-->
    <select id="listSubjectiveBlockidsByMpid" resultType="java.lang.Integer">
        select mblockid from ms_paper_block where mpid = #{mpid} and blocktype = 2 order by mblockid
    </select>

    <!--试卷所有题块-->
    <select id="listPaperBlocksByMpid" resultType="com.xhkjedu.smarking.model.paper.MsPaperBlock">
        select * from ms_paper_block where mpid = #{mpid} order by blockorder
    </select>

</mapper>
