<?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.courseTable.mapper.CourseTableMapper">
    <select id="getList" parameterType="com.xjrsoft.module.schedule.dto.CourseTableDto" resultType="com.xjrsoft.module.schedule.vo.CourseDetailVo">
        SELECT t1.course_name, t2.name AS teacher_name,CONCAT(t4.name,t3.name) AS classroom_name,t1.weeks,t1.time_period,t1.time_number,t5.name as class_name,t1.schedule_date FROM course_table t1
        LEFT JOIN xjr_user t2 ON t1.teacher_id = t2.id
        LEFT JOIN base_classroom t3 ON t1.site_id = t3.id
        LEFT JOIN base_office_build t4 ON t3.office_build_id = t4.id
        LEFT JOIN base_class t5 ON t1.class_id = t5.id
        LEFT JOIN base_class_major_set t7 ON t7.class_id = t5.id
        LEFT JOIN base_grade t6 ON t5.grade_id = t6.id
        where t1.status = 1
        <if test="dto.semesterId != null">
            and t1.base_semester_id = #{dto.semesterId}
        </if>
        <if test="dto.weekDay != null">
            and t1.weeks = #{dto.weekDay}
        </if>
        <if test="dto.courseType != null and dto.courseType != '' and dto.courseType == 'teacher'">
            <if test="dto.teacherId != null ">
                and t1.teacher_id = #{dto.teacherId}
            </if>
        </if>

        <if test="dto.courseType != null and dto.courseType != '' and dto.courseType == 'class'">
            <if test="dto.gradeId != null">
                and t6.id = #{dto.gradeId}
            </if>
            <if test="dto.classId != null">
                and t5.id = #{dto.classId}
            </if>
            <if test="dto.majorSetId != null">
                and t7.major_set_id = #{dto.majorSetId}
            </if>
        </if>
        <if test="dto.startDate != null and dto.endDate != null">
            and t1.schedule_date between #{dto.startDate} and #{dto.endDate}
        </if>
        <if test="dto.toDay != null">
            and t1.schedule_date = #{dto.toDay}
        </if>
        <if test="dto.teacherId != null">
            and t1.teacher_id = #{dto.teacherId}
        </if>
        <if test="dto.classId != null">
            and t5.id = #{dto.classId}
        </if>
    </select>
    <select id="getAdjustList" parameterType="com.xjrsoft.module.schedule.dto.CourseTableAdjustDto" resultType="com.xjrsoft.module.schedule.vo.CourseListVo">
        SELECT t1.time_period,t1.time_number,t1.course_name,t2.name AS class_name,t3.name AS classroom_name,t1.id,t2.id as class_id FROM course_table t1
        LEFT JOIN base_class t2 ON t1.class_id = t2.id
        LEFT JOIN base_classroom t3 ON t1.site_id = t3.id
        WHERE t1.status = 1 AND t1.teacher_id = #{dto.teacherId}
        AND t1.weeks = #{dto.week} AND t1.schedule_date = #{dto.adjustDate}
        <if test="dto.classId != null and dto.classId != ''">
            and t1.class_id = #{dto.classId}
        </if>
    </select>
</mapper>