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

    <select id="getOverview" resultType="com.qmth.teachcloud.report.business.entity.TAExamTotal">
        SELECT
            a.exam_time examTime,
            a.college_count collegeCount,
            a.college_names collegeNames,
            a.course_count courseCount,
            a.public_course_count publicCourseCount,
            a.major_course_count majorCourseCount,
            a.total_course_times totalCourseTimes,
            a.total_count totalCount,
            a.reality_course_times realityCourseTimes,
            a.reality_count realityCount,
            a.absent_course_times absentCourseTimes,
            a.absent_count absentCount
        FROM
            t_a_exam_total a
                LEFT JOIN
            t_b_exam b ON a.exam_id = b.id
        <where>
            and b.school_id = #{schoolId}
            <if test="semesterId != null and semesterId != ''">
                and b.semester_id = #{semesterId}
            </if>
            <if test="examId != null">
                and a.exam_id = #{examId}
            </if>
        </where>
    </select>
    <select id="getCourseSummary" resultType="com.qmth.teachcloud.report.business.entity.TAExamCourse">
        select * from(SELECT
        a.course_code courseCode,
        a.course_name courseName,
        a.teach_college_name teachCollegeName,
        a.inspect_college_count inspectCollegeCount,
        a.reality_count realityCount,
        a.current_reality_count currentRealityCount,
        a.absent_count absentCount,
        round(a.avg_score, 1) avgScore,
        a.pass_count passCount,
        round(a.pass_rate * 100,1) passRate,
        round(a.current_avg_score, 1) currentAvgScore,
        a.current_pass_count currentPassCount,
        round(a.current_pass_rate * 100, 1) currentPassRate,
        round(a.current_reality_rate * 100, 1) currentRealityRate,
        round(a.past_reality_rate * 100, 1) pastRealityRate,
        round((1 - a.pass_rate) * 100,1) as notPassRate,
        round(a.paper_current_avg_score,1) as paperCurrentAvgScore,
        round((1 - a.current_pass_rate) * 100,1) as currentNotPassRate,
        (a.reality_count - a.pass_count) as notPassCount,
        (a.current_reality_count - a.current_pass_count) as currentNotPassCount,
        a.past_reality_count as pastRealityCount
        FROM
        t_a_exam_course a
        LEFT JOIN
        t_b_exam b ON a.exam_id = b.id
        join t_b_exam_course tbec on
        tbec.exam_id = a.exam_id and
        tbec.course_code = a.course_code
        <where>
            and b.school_id = #{schoolId}
            <if test="semesterId != null and semesterId != ''">
                and b.semester_id = #{semesterId}
            </if>
            <if test="examId != null">
                and a.exam_id = #{examId}
            </if>
            <if test="collegeIds != null and collegeIds != '' and collegeIds.size > 0">
                and a.teach_college_id in
                <foreach collection="collegeIds" item="collegeId" index="index" open="(" separator="," close=")">
                    #{collegeId}
                </foreach>
            </if>
                and tbec.publish_status = 'PUBLISH'
        </where>
        ) t
        <if test="column != null and column != '' and order != null and order != ''">
            order by t.${column} ${order}
        </if>
    </select>
</mapper>
