<?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.report.business.mapper.TAExamCourseRecordDioMapper">

    <select id="listDiosBySchoolIdAndExamIdAndCourseCodeAndModuleName"
            resultType="com.qmth.teachcloud.report.business.bean.result.ModuleDetailResult">
        SELECT
            ROUND(a.score_rate * 100, 1) rate,
            ROUND(c.score_rate * 100, 1) collegeRate,
            b.code_primary code,
            b.name_primary name,
            b.interpretation
        FROM
            t_a_exam_course_record_dio a
                JOIN
            (SELECT DISTINCT
                exam_id,
                    code_primary,
                    name_primary,
                    course_code,
                    dimension_type,
                    interpretation
            FROM
                t_b_dimension
            WHERE
                exam_id = #{examId} AND course_code = #{courseCode}
                    AND dimension_type = #{moduleName}) b ON a.exam_id = b.exam_id
                AND a.course_code = b.course_code
                AND a.dimension_type = b.dimension_type
                AND a.dimension_code = b.code_primary
                LEFT JOIN
            t_a_exam_course_college_inspect_dio c ON a.school_id = c.school_id
                AND a.exam_id = c.exam_id
                AND a.course_code = c.course_code
                AND a.dimension_type = c.dimension_type
                AND a.dimension_code = c.dimension_code
                AND a.inspect_college_id = c.inspect_college_id
        <where>
            and a.school_id = #{schoolId}
            and a.exam_id = #{examId}
            and a.course_code = #{courseCode}
            and a.dimension_type = #{moduleName}
            and a.student_code = #{studentCode}
        </where>
    </select>
    <select id="listSubDiosBySchoolIdAndExamIdAndStudentCodeAndCourseCodeAndModuleName"
            resultType="com.qmth.teachcloud.report.business.bean.result.DimensionDetailResult">
        SELECT
            ROUND(a.score_rate * 100, 1) scoreRate,
            ROUND(c.score_rate * 100, 1) collegeAvgScore,
            b.code_second code,
            b.name_second name,
            a.proficiency
        FROM
            t_a_exam_course_record_dio a
                JOIN
            (SELECT DISTINCT
                exam_id,
                    code_second,
                    name_second,
                    course_code,
                    dimension_type,
                    interpretation
            FROM
                t_b_dimension
            WHERE
                exam_id = #{examId} AND course_code = #{courseCode}
                    AND dimension_type = #{moduleName}) b ON a.exam_id = b.exam_id
                AND a.course_code = b.course_code
                AND a.dimension_type = b.dimension_type
                AND a.dimension_code = b.code_second
                LEFT JOIN
            t_a_exam_course_college_inspect_dio c ON a.school_id = c.school_id
                AND a.exam_id = c.exam_id
                AND a.course_code = c.course_code
                AND a.dimension_type = c.dimension_type
                AND a.dimension_code = c.dimension_code
                AND a.inspect_college_id = c.inspect_college_id
        <where>
            and a.school_id = #{schoolId}
            and a.exam_id = #{examId}
            and a.course_code = #{courseCode}
            and a.dimension_type = #{moduleName}
            and a.student_code = #{studentCode}
        </where>
    </select>
    <select id="findDimensionTypesByCourseCode"
            resultType="java.lang.String">
        SELECT
            distinct (dimension_type)
        FROM
            t_a_exam_course_record_dio
        <where>
            <if test="schoolId != null and schoolId != ''">
                AND school_id = #{schoolId}
            </if>
            <if test="examId != null and examId != ''">
                AND exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                AND course_code = #{courseCode}
            </if>
        </where>
    </select>
</mapper>
