<?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.MsTemplateBlockMapper">
    
    <!--删除模板中指定类型题块信息-->
    <delete id="deleteByMtidAndMtype">
        delete from ms_template_block where mtid = #{mtid}
        <if test="mttype!=null and mttype > 0">
            and mttype = #{mttype}
        </if>
    </delete>

    <resultMap id="templateBlockResultMap" type="com.xhkjedu.smarking.model.paper.MsTemplateBlock">
        <result column="mtbid" property="mtbid" />
        <result column="mblockid" property="mblockid" />
        <result column="blockname" property="blockname" />
        <result column="mttype" property="mttype" />
        <result column="direct" property="direct" />
        <result column="localcoor" property="localcoor" />
        <result column="extendcoor" property="extendcoor" />
        <result column="scorecoor" property="scorecoor" />
        <result column="mtborder" property="mtborder" />
        <collection property="tbquestions" ofType="com.xhkjedu.smarking.model.paper.MsTemplateBlockQuestion" javaType="java.util.ArrayList">
            <result column="mtbqid" property="mtbqid" />
            <result column="qn" property="qn" />
            <result column="mptqid" property="mptqid" />
            <result column="qlocalcoor" property="qlocalcoor" />
            <result column="mtbqorder" property="mtbqorder" />
        </collection>
    </resultMap>
    <!--模板信息详情-->
    <select id="listTemplateBlockQuestions" resultMap="templateBlockResultMap">
        select b.mtbid,b.mblockid,b.blockname,b.mttype,b.direct,b.localcoor,b.extendcoor,b.scorecoor,
        b.mtborder,q.mtbqid,q.qn,q.qlocalcoor,q.mtbqorder
        from ms_template_block b left join ms_template_block_question q on b.mtbid=q.mtbid
        where b.mtid=#{mtid}
        <if test="mttype!=null and mttype > 0">
            and b.mttype = #{mttype}
        </if>
        order by b.mtborder,q.mtbqorder
    </select>

    <!--获取模板主观题题块信息-->
    <select id="listSubjectiveBlockQuestions" resultType="java.util.Map">
        select b.mtbid,b.mblockid,b.blockname,b.mttype,b.direct,b.localcoor,b.extendcoor,b.scorecoor,
        b.mtborder from ms_template_block b where b.mtid=#{mtid} and b.mttype=2 order by b.mtborder
    </select>

    <resultMap id="blockTemplate" type="java.util.Map">
        <result column="mblockid" property="mblockid" />
        <result column="blockname" property="blockname" />
        <result column="blockorder" property="blockorder" />
        <result column="bqnum" property="bqnum" />
        <result column="bqscore" property="bqscore" />
        <result column="localcoor" property="localcoor" />
        <result column="extendcoor" property="extendcoor" />
        <result column="scorecoor" property="scorecoor" />
        <collection property="questions" ofType="java.util.Map" javaType="java.util.ArrayList">
            <result column="mbqid" property="mbqid" />
            <result column="bqn" property="bqn" />
        </collection>
    </resultMap>
    <!--主观题框选题块获取-->
    <select id="listBlockTemplates" resultMap="blockTemplate">
        select DISTINCT b.mblockid,b.blockname,b.blockorder,b.bqnum,b.bqscore,
                        tb.localcoor,tb.extendcoor,tb.scorecoor,bq.mbqid,bq.bqn
        from ms_paper_block b left join ms_template_block tb on b.mblockid=tb.mblockid
        left join ms_template t on b.mpid=t.mpid
        left join ms_paper_block_question bq on b.mblockid=bq.mblockid
        where b.mpid=#{mpid} and b.blocktype=2 and t.mtid=#{mtid} order by b.blockorder,bq.bqorder
    </select>
</mapper>
