<?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.qmth.teachcloud.mark.mapper.MarkQuestionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.common.entity.MarkQuestion">
        <id column="id" property="id" />
        <result column="exam_id" property="examId" />
        <result column="paper_number" property="paperNumber" />
        <result column="objective" property="objective" />
        <result column="group_number" property="groupNumber" />
        <result column="main_number" property="mainNumber" />
        <result column="sub_number" property="subNumber" />
        <result column="main_title" property="mainTitle" />
        <result column="answer" property="answer" />
        <result column="total_score" property="totalScore" />
        <result column="interval_score" property="intervalScore" />
        <result column="objective_policy" property="objectivePolicy" />
        <result column="question_type" property="questionType" />
        <result column="name" property="name" />
    </resultMap>
    <select id="assembleQuestionsByExamIdAndPaperNumberAndNumber" resultType="java.lang.String">
        SELECT
            GROUP_CONCAT(CONCAT(mq.main_number, '-', mq.sub_number))
        FROM
            mark_question mq
        WHERE
            mq.exam_id = #{examId}
          AND mq.paper_number = #{paperNumber}
          AND mq.group_number = #{groupNumber}
          AND mq.objective = false
        ORDER BY mq.main_number , mq.sub_number
    </select>
    <select id="sumTotalScoreByGroupNumber" resultType="java.lang.Double">
        SELECT
            SUM(CAST(q.total_score AS DECIMAL (10 , 3 )))
        FROM
            mark_question q
        WHERE
            q.exam_id = #{examId}
          AND q.paper_number = #{paperNumber}
          AND q.group_number = #{groupNumber}
    </select>

</mapper>
