<?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.TBDimensionMapper">

    <select id="findDimensionInfo" resultType="com.qmth.teachcloud.report.business.bean.result.CourseDimensionResult">
        SELECT
            tmp.exam_id AS examId,
            (select tbe.exam_code from t_b_exam tbe where tbe.id = tmp.exam_id) as examCode,
            tmp.course_code AS courseCode,
            tmp.dimension_type AS module,
            code_primary AS dimensionCode,
            name_primary AS dimensionName,
            interpretation,
            total_count AS totalCount,
            round(CONVERT( papDio.score_rate * 100 , DECIMAL (10 , 4 )),2) AS schScoreRate,
            round(CONVERT( colDio.score_rate * 100 , DECIMAL (10 , 4 )),2) AS colScoreRate,
            colDio.inspect_college_name AS collegeName,
            round(colDio.score_rate, 1) as degree
        FROM
            (SELECT
                 exam_id,
                 course_code,
                 dimension_type,
                 code_primary,
                 name_primary,
                 interpretation
             FROM
                 t_b_dimension
             GROUP BY exam_id, course_code , dimension_type , code_primary , name_primary , interpretation) tmp
                INNER JOIN
            (SELECT
                 exam_id,
                 course_code,
                 dimension_type,
                 dimension_code,
                 AVG(score_rate) AS score_rate,
                 AVG(total_count) AS total_count
             FROM
                  t_a_exam_course_dio
             GROUP BY exam_id , course_code , dimension_type , dimension_code) papDio ON tmp.code_primary = papDio.dimension_code
                AND tmp.dimension_type = papDio.dimension_type
                AND tmp.exam_id = papDio.exam_id
                AND tmp.course_code = papDio.course_code
                INNER JOIN
            t_a_exam_course_college_inspect_dio colDio ON tmp.code_primary = colDio.dimension_code
                AND tmp.dimension_type = colDio.dimension_type
                AND papDio.exam_id = colDio.exam_id
                AND papDio.course_code = colDio.course_code
                <where>
                    <if test="examId != null and examId != ''">
                        and papDio.exam_id = #{examId}
                    </if>
                    <if test="courseCode != null and courseCode != ''">
                        and papDio.course_code = #{courseCode}
                    </if>
                    <if test="collegeId != null and collegeId != ''">
                        and colDio.inspect_college_id = #{collegeId}
                    </if>
                </where>
    </select>

    <select id="findDimensionByTeacherInfo" resultType="com.qmth.teachcloud.report.business.bean.result.CourseDimensionResult">
        SELECT
        tmp.exam_id AS examId,
        (select tbe.exam_code from t_b_exam tbe where tbe.id = tmp.exam_id) as examCode,
        tmp.course_code AS courseCode,
        tmp.dimension_type AS module,
        code_primary AS dimensionCode,
        name_primary AS dimensionName,
        interpretation,
        total_count AS totalCount,
        round(CONVERT( papDio.score_rate * 100 , DECIMAL (10 , 4 )),2) AS schScoreRate,
        round(CONVERT( colDio.score_rate * 100 , DECIMAL (10 , 4 )),2) AS colScoreRate,
        colDio.teacher_name AS teacherName,
        round(colDio.score_rate, 1) as degree
        FROM
        (SELECT
        exam_id,
        course_code,
        dimension_type,
        code_primary,
        name_primary,
        interpretation
        FROM
        t_b_dimension
        GROUP BY exam_id, course_code , dimension_type , code_primary , name_primary , interpretation) tmp
        INNER JOIN
        (SELECT
        exam_id,
        course_code,
        dimension_type,
        dimension_code,
        AVG(score_rate) AS score_rate,
        AVG(total_count) AS total_count
        FROM
        t_a_exam_course_dio
        GROUP BY exam_id , course_code , dimension_type , dimension_code) papDio ON tmp.code_primary = papDio.dimension_code
        AND tmp.dimension_type = papDio.dimension_type
        AND tmp.exam_id = papDio.exam_id
        AND tmp.course_code = papDio.course_code
        INNER JOIN
        t_a_exam_course_teacher_dio colDio ON tmp.code_primary = colDio.dimension_code
        AND tmp.dimension_type = colDio.dimension_type
        AND papDio.exam_id = colDio.exam_id
        AND papDio.course_code = colDio.course_code
        <where>
            <if test="examId != null and examId != ''">
                and papDio.exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and papDio.course_code = #{courseCode}
            </if>
            <if test="teacherId != null and teacherId != ''">
                and colDio.teacher_id = #{teacherId}
            </if>
        </where>
    </select>
</mapper>
