<?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.sexam.mapper.paper.EPaperQtypeQuestionMapper">

    <!--保存试题正确答案-->
    <update id="updateBatchQuestionAnswer">
        update e_paper_qtype_question set
        <trim prefix="answer=case" suffix="end">
            <foreach collection="list" item="q">
                when eptqid=#{q.eptqid} then #{q.answer}
            </foreach>
        </trim>
        <where>
            <foreach collection="list" item="q" separator="or">
                eptqid=#{q.eptqid}
            </foreach>
        </where>
    </update>

    <!--保存试卷答题卡坐标-->
    <update id="updateBatchQuestionForScan">
        update e_paper_qtype_question
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="coord = case" suffix="end,">
                <foreach collection="list" item="q">
                    when eptqid=#{q.eptqid} then #{q.coord}
                </foreach>
            </trim>
            <trim prefix="gnum = case" suffix="end,">
                <foreach collection="list" item="q">
                    when eptqid=#{q.eptqid} then #{q.gnum}
                </foreach>
            </trim>
            <trim prefix="height = case" suffix="end,">
                <foreach collection="list" item="q">
                    when eptqid=#{q.eptqid} then #{q.height}
                </foreach>
            </trim>
            <trim prefix="queshtml = case" suffix="end,">
                <foreach collection="list" item="q">
                    when eptqid=#{q.eptqid} then #{q.queshtml}
                </foreach>
            </trim>
        </trim>
        <where>
            <foreach collection="list" item="q" separator="or">
                eptqid=#{q.eptqid}
            </foreach>
        </where>
    </update>

    <!--保存主观题选项数量-->
    <update id="updateBatchQuestionOptionnum">
        update e_paper_qtype_question
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="optionnum = case" suffix="end,">
                <foreach collection="list" item="q">
                    when eptqid=#{q.eptqid} then #{q.optionnum}
                </foreach>
            </trim>
        </trim>
        <where>
            <foreach collection="list" item="q" separator="or">
                eptqid=#{q.eptqid}
            </foreach>
        </where>
    </update>

    <!--试卷中所有试题基础信息-->
    <select id="listQuestionsByEpid" resultType="com.xhkjedu.sexam.model.paper.EPaperQtypeQuestion">
        select * from e_paper_qtype_question where epid=#{epid} order by qorder
    </select>
    <!--试卷中所有试题题号信息-->
    <select id="listQnByEpid" resultType="java.util.Map">
        select eptqid,score,concat('第',qn,'题')qn
        from e_paper_qtype_question where epid=#{epid} order by qorder
    </select>

</mapper>
