<?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.distributed.print.business.mapper.GradePaperStructMapper">

    <select id="findBySchoolIdAndPaperNumberAndPaperType"
            resultType="com.qmth.distributed.print.business.bean.dto.open.PaperStructure">
        SELECT id,
               question_name         questionName,
               number_type           numberType,
               big_question_number   bigQuestionNumber,
               small_question_number smallQuestionNumber,
               big_topic_name        bigTopicName,
               full_score            fullScore,
               score_rules           scoreRules,
               knowledge_dimension   knowledgeDimension,
               ability_dimension     abilityDimension
        FROM grade_paper_struct
        where school_id = #{schoolId}
          and exam_id = #{examId}
          and paper_number = #{paperNumber}
          and paper_type = #{paperType}

    </select>

    <select id="findStructByGradePaper"
            resultType="com.qmth.distributed.print.business.bean.result.analyze.GradePaperStructResult">
        SELECT
            et.course_code AS courseCode,
            et.course_name AS courseName,
            gps.paper_number AS paperNumber,
            gps.paper_type AS paperType,
            gps.number_type AS numberType,
            gps.big_topic_name AS bigTopicName,
            gps.big_question_number AS bigQuestionNumber,
            gps.small_question_number AS smallQuestionNumber,
            gps.full_score AS fullScore,
            gps.score_rules AS scoreRules,
            gps.knowledge_dimension AS knowledgeDimension,
            gps.ability_dimension AS abilityDimension
        FROM
            grade_paper_struct gps
                LEFT JOIN
            (SELECT
                 school_id,
                 exam_id,
                 paper_number,
                 MAX(course_code) AS course_code,
                 MAX(course_name) AS course_name
             FROM
                 exam_task
             GROUP BY school_id ,exam_id, paper_number) et ON gps.school_id = et.school_id
                AND gps.exam_Id = et.exam_id
                AND gps.paper_number = et.paper_number
        <where>
            <if test="schoolId != null and schoolId != ''">
                AND gps.school_id = #{schoolId}
            </if>
            <if test="examId != null">
                AND gps.exam_id = #{examId}
            </if>
            <if test="paperNumber != null and paperNumber != ''">
                AND gps.paper_number = #{paperNumber}
            </if>
            <if test="paperType != null and paperType != ''">
                AND gps.paper_type = #{paperType}
            </if>
        </where>
        ORDER BY gps.exam_id,gps.paper_number,gps.paper_type,gps.number_type,gps.big_question_number,gps.small_question_number
    </select>
</mapper>
