<?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.xjrsoft.module.classtime.mapper.ClassTimeStatisticsMapper">
    <select id="getTeacherList" resultType="com.xjrsoft.module.classtime.vo.TeacherListVo">
        SELECT t1.id,t1.name,t2.employ_type FROM xjr_user t1
        INNER JOIN base_teacher t2 ON t1.id = t2.user_id
        WHERE t1.delete_mark = 0 AND t2.employ_type IN ('FB1601','FB1605','FB1609')
    </select>

    <select id="getWfTeacherCourseTimeList" parameterType="com.xjrsoft.module.classtime.entity.ClassTimeStatistics" resultType="com.xjrsoft.module.oa.entity.WfTeacherCourseTime">
        SELECT t1.* FROM wf_teacher_course_time t1
        INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value
        WHERE t2.current_state = 'COMPLETED'
        and t1.schedule_date BETWEEN #{dto.startDate} and #{dto.endDate}
    </select>

    <select id="getCourseList" parameterType="com.xjrsoft.module.classtime.entity.ClassTimeStatistics" resultType="com.xjrsoft.module.classtime.vo.CourseListVo">
        SELECT t1.class_id, t1.teacher_id, t2.short_name,t1.adjust_type,t4.reason,t1.schedule_date,t1.class_name,t1.course_name,t1.time_number FROM course_table t1
        LEFT JOIN class_time t2 ON t1.time_period = t2.time_period AND t1.time_number = t2.number
        LEFT JOIN course_table_bak t3 ON t1.id = t3.id
        LEFT JOIN wf_course_adjust t4 ON t4.id = t3.wf_course_adjust_id
        WHERE t1.schedule_date BETWEEN #{dto.startDate} and #{dto.endDate}
        AND t1.schedule_date NOT IN (
            SELECT DATE FROM holiday_date WHERE STATUS = 3
            AND DATE BETWEEN #{dto.startDate} and #{dto.endDate}
        )
    </select>

    <select id="getHolidayReplaceCourseList" parameterType="com.xjrsoft.module.classtime.entity.ClassTimeStatistics" resultType="com.xjrsoft.module.classtime.vo.CourseListVo">
        SELECT t1.class_id, t1.teacher_id, t2.short_name,t1.adjust_type,t4.reason,t1.schedule_date,t1.class_name,t1.course_name,t1.time_number FROM course_table t1
        LEFT JOIN class_time t2 ON t1.time_period = t2.time_period AND t1.time_number = t2.number
        LEFT JOIN course_table_bak t3 ON t1.id = t3.id
        LEFT JOIN wf_course_adjust t4 ON t4.id = t3.wf_course_adjust_id
        WHERE t1.schedule_date BETWEEN #{dto.startDate} and #{dto.endDate}
        AND t1.adjust_type = 'course_replace'
        AND t1.schedule_date IN (
            SELECT DATE FROM holiday_date WHERE STATUS = 3
            AND DATE BETWEEN #{dto.startDate} and #{dto.endDate}
        )
    </select>

    <select id="getReplaceCourseList" parameterType="com.xjrsoft.module.classtime.entity.ClassTimeStatistics" resultType="com.xjrsoft.module.classtime.vo.CourseListVo">
        SELECT t1.class_id, t1.teacher_id, t2.short_name,t1.adjust_type,t4.reason,t1.schedule_date,t1.time_number FROM course_table t1
        LEFT JOIN class_time t2 ON t1.time_period = t2.time_period AND t1.time_number = t2.number
        LEFT JOIN course_table_bak t3 ON t1.id = t3.id
        LEFT JOIN wf_course_adjust t4 ON t4.id = t3.wf_course_adjust_id
        WHERE t1.schedule_date BETWEEN #{dto.startDate} and #{dto.endDate}
        AND t1.schedule_date IN (
        SELECT replace_date FROM class_time_calendar WHERE delete_mark = 0 AND replace_date BETWEEN #{dto.startDate} and #{dto.endDate}
        )
    </select>

    <select id="getSubstituteList" parameterType="com.xjrsoft.module.classtime.entity.ClassTimeStatistics" resultType="com.xjrsoft.module.classtime.vo.CourseListVo">
        SELECT t4.short_name,t3.schedule_date,t3.class_id,t1.user_id as teacher_id,t1.exchange_teacher_id,t1.reason FROM wf_course_adjust t1
        INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value
        INNER JOIN course_table_bak t3 ON t1.id = t3.wf_course_adjust_id
        LEFT JOIN class_time t4 ON t3.time_period = t4.time_period AND t3.time_number = t4.number
        <!-- INNER JOIN course_table t5 ON t5.id = t3.id-->
        WHERE t1.delete_mark = 0 AND t2.current_state = 'COMPLETED'
        <!-- AND t1.reason IN ('sick_leave','leave_absence') -->
        and t1.adjust_type = 'course_substitute' and t1.enabled_mark = 1
        AND t3.schedule_date BETWEEN #{dto.startDate} and #{dto.endDate}
        AND t3.schedule_date NOT IN (
            SELECT DATE FROM holiday_date WHERE STATUS = 3
            AND DATE BETWEEN #{dto.startDate} and #{dto.endDate}
        )
    </select>


    <select id="getRecordList" resultType="com.xjrsoft.module.classtime.vo.ClassTimeStatisticsRecordVo">
        SELECT t1.id,t2.user_name,t2.name,t3.name AS employ_type_cn,t1.week_data,
        t1.class_time1,t1.class_time2,t1.class_time3,t1.class_time4,t1.class_time5,
        t1.class_time6,t1.class_time7,t1.class_time8,t1.class_time9,t1.class_time10,t1.class_time11,
        t1.all_class_time,t1.total_amount,t1.class_time_amount,t1.beyond_class_time_amount FROM class_time_statistics_record t1
        INNER JOIN xjr_user t2 ON t1.user_id = t2.id
        LEFT JOIN xjr_dictionary_detail t3 ON t1.employ_type = t3.code
        WHERE t1.delete_mark = 0 AND t1.class_time_statistics_id = #{id}
    </select>

</mapper>