<?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.ym.mec.biz.dal.dao.CourseScheduleDao">

    <resultMap type="com.ym.mec.biz.dal.entity.CourseSchedule" id="CourseSchedule">
        <result column="id_" property="id"/>
        <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="music_group_id_" property="musicGroupId"/>
        <result column="class_group_id_" property="classGroupId"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="subsidy_" property="subsidy"/>
        <result column="class_date_" property="classDate"/>
        <result column="start_class_time_" property="startClassTime"/>
        <result column="end_class_time_" property="endClassTime"/>
        <result column="start_class_time_str_" property="startClassTimeStr"/>
        <result column="end_class_time_str_" property="endClassTimeStr"/>
        <result column="teacher_id_" property="teacherId"/>
        <result column="actual_teacher_id_" property="actualTeacherId"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
        <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="name_" property="name"/>
        <result column="student_num_" property="studentNum"/>
        <result column="leave_student_num_" property="leaveStudentNum"/>
        <result column="schoole_id_" property="schoolId"/>
        <result column="schoole_name_" property="schoolName"/>
        <result column="class_group_name_" property="classGroupName"/>
        <result column="class_group_type_" property="classGroupType"/>
        <result column="teaching_content_" property="teachingContent"/>
        <result column="note_" property="note"/>
        <result column="organ_id_" property="organId"/>
    </resultMap>

    <resultMap type="com.ym.mec.biz.dal.dto.Mapper" id="Mapper">
        <result column="key_" property="key"/>
        <result column="value_" property="value"/>
    </resultMap>

    <resultMap type="com.ym.mec.biz.dal.dto.RemainCourseTypeDurationDto" id="RemainCourseTypeDurationDto">
        <result column="course_type_" property="courseType"/>
        <result column="remain_minutes_" property="remainMinutes"/>
    </resultMap>

    <resultMap id="CourseScheduleEndDto" type="com.ym.mec.biz.dal.dto.CourseScheduleEndDto" extends="CourseSchedule">
        <result column="course_start_time_" property="startClassTime"/>
        <result column="course_end_time_" property="endClassTime"/>
        <result column="settlement_time_" property="settlementTime"/>
        <result column="organ_name_" property="organName"/>
        <result column="isCallNames" property="isCallNames" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    </resultMap>

    <resultMap type="com.ym.mec.biz.dal.dto.CourseScheduleDto" id="courseScheduleDto" extends="CourseSchedule">
        <result column="teacher_name_" property="teacherName"/>
        <result column="name_" property="classGroupName"/>
        <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="school_name_" property="schoolName"/>
        <result column="sign_in_status_enum_" property="signInStatusEnum" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="sign_out_status_enum_" property="signOutStatusEnum" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="sign_in_status_" property="signInStatus"/>
        <result column="sign_out_status_" property="signOutStatus"/>
        <result column="sign_in_time_" property="signInTime"/>
        <result column="sign_out_time_" property="signOutTime"/>
        <result column="is_complaints_" property="isComplaints"/>
        <result column="complaints_status_" property="complaintsStatus"/>
        <result column="complaints_content_" property="complaintsContent"/>
        <result column="dispose_content_" property="disposeContent"/>
        <result column="seal_class_id_" property="sealClassId"/>
        <result column="total_student_num_" property="totalStudentNum"/>
        <result column="expect_student_num_" property="expectStudentNum"/>
        <result column="teacher_role_" property="teacherRole"
                typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="attendance_status_" property="attendanceStatus"
                typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="complaint_status_" property="complaintStatus"/>
        <result column="student_id_" property="studentId"/>
    </resultMap>

    <resultMap type="com.ym.mec.biz.dal.entity.StudentCourseScheduleRecordDto" id="studentCourseScheduleRecord">
        <result column="id_" property="id"/>
        <result column="course_schedule_id_" property="courseScheduleId"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="name_" property="courseName"/>
        <result column="class_date_" property="classDate"/>
        <result column="start_class_time_" property="startClassTime"/>
        <result column="end_class_time_" property="endClassTime"/>
        <result column="teacher_id_" property="teacherId"/>
        <result column="teacher_name_" property="teacherName"/>
        <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="rest_of_class_" property="restOfClass"/>
        <result column="class_group_id_" property="classGroupId"/>
    </resultMap>

    <resultMap type="com.ym.mec.biz.dal.dto.StudentCourseInfoDto" id="StudentCourseInfoDto">
        <constructor>
            <arg column="class_date_" javaType="string"/>
            <arg column="start_class_time_" javaType="string"/>
            <arg column="end_class_time_" javaType="string"/>
        </constructor>
        <result column="id_" property="id"/>
        <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="music_group_id_" property="musicGroupId"/>
        <result column="class_group_id_" property="classGroupId"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="actual_teacher_id_" property="actualTeacherId"/>
        <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="expect_price_" property="expectPrice"/>
    </resultMap>

    <resultMap type="com.ym.mec.biz.dal.entity.StudentAttendance" id="StudentAttendance">
        <result column="music_group_id_" property="musicGroupId"/>
        <result column="class_group_id_" property="classGroupId"/>
        <result column="group_type_" property="groupType"/>
        <result column="course_schedule_id_" property="courseScheduleId"/>
        <result column="user_id_" property="userId"/>
        <result column="teacher_id_" property="teacherId"/>
        <result column="current_class_times_" property="currentClassTimes"/>
    </resultMap>
    <sql id="resultSql">
        cs.id_,
        cs.music_group_id_,
        cs.group_type_,
        cs.class_group_id_,
        cs.status_,
        cs.subsidy_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.start_class_time_                              start_class_time_str_,
        cs.end_class_time_                                end_class_time_str_,
        cs.teacher_id_,
        cs.actual_teacher_id_,
        cs.create_time_,
        cs.update_time_,
        cs.teach_mode_,
        cs.type_,
        cs.name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.schoole_id_
    </sql>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="CourseSchedule">
        SELECT <include refid="resultSql"/>
        FROM course_schedule cs
        WHERE cs.id_ = #{id}
    </select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="CourseSchedule">
        SELECT <include refid="resultSql"/>
        FROM course_schedule cs
        ORDER BY cs.id_
    </select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.CourseSchedule" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        INSERT INTO course_schedule
        (id_,group_type_,music_group_id_,class_group_id_,status_,subsidy_,class_date_,start_class_time_,end_class_time_,
        teacher_id_,actual_teacher_id_,create_time_,update_time_,type_,name_,teach_mode_,student_num_,leave_student_num_,
        schoole_id_,is_lock_,note_,teaching_content_,organ_id_)
        VALUES(#{id},#{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{musicGroupId},#{classGroupId},
        #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{subsidy},#{classDate},#{startClassTime},
        #{endClassTime},#{teacherId},#{teacherId},now(),now(),
        #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{name},
        #{teachMode,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{studentNum},#{leaveStudentNum},
        #{schoolId},#{isLock},#{note},#{teachingContent},#{organId})
    </insert>

    <insert id="batchAddCourseSchedules" parameterType="java.util.List" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        INSERT INTO course_schedule
        (group_type_,music_group_id_,class_group_id_,status_,subsidy_,class_date_,start_class_time_,end_class_time_,
        teacher_id_,actual_teacher_id_,create_time_,update_time_,type_,name_,teach_mode_,student_num_,leave_student_num_,
        schoole_id_,is_lock_,note_,teaching_content_,organ_id_)
        VALUE
        <foreach collection="list" item="course" separator=",">
            (#{course.groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{course.musicGroupId},
            #{course.classGroupId},#{course.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            #{course.subsidy},#{course.classDate},#{course.startClassTime},#{course.endClassTime},#{course.teacherId},
            #{course.teacherId},now(),now(),#{course.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            #{course.name},#{course.teachMode,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{course.studentNum},
            #{course.leaveStudentNum},#{course.schoolId},#{course.isLock},#{course.note},#{course.teachingContent},#{course.organId})
        </foreach>
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.CourseSchedule">
        UPDATE course_schedule
        <set>
            <if test="organId != null">
                organ_id_ = #{organId},
            </if>
            <if test="note != null">
                note_ = #{note},
            </if>
            <if test="teachingContent != null">
                teaching_content_ = #{teachingContent},
            </if>
            <if test="classDate != null">
                class_date_ = #{classDate},
            </if>
            <if test="musicGroupId != null">
                music_group_id_ = #{musicGroupId},
            </if>
            <if test="endClassTime != null">
                end_class_time_ = #{endClassTime},
            </if>
            <if test="status != null">
                status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="type != null">
                type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="groupType != null">
                group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="actualTeacherId != null">
                actual_teacher_id_ = #{actualTeacherId},
            </if>
            <if test="subsidy != null">
                subsidy_ = #{subsidy},
            </if>
            <if test="classGroupId != null">
                class_group_id_ = #{classGroupId},
            </if>
            <if test="startClassTime != null">
                start_class_time_ = #{startClassTime},
            </if>
            <if test="teacherId != null">
                teacher_id_ = #{teacherId},
            </if>
            <if test="studentNum != null">
                student_num_ = #{studentNum},
            </if>
            <if test="leaveStudentNum != null">
                leave_student_num_ = #{leaveStudentNum},
            </if>
            <if test="schoolId != null">
                schoole_id_ = #{schoolId},
            </if>
            <if test="schoolId == null">
                schoole_id_ = null,
            </if>
            <if test="teachMode != null">
                teach_mode_ = #{teachMode,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="isLock != null">
                is_lock_ = #{isLock},
            </if>
            update_time_ = NOW()
        </set>
        WHERE id_ = #{id}
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
        DELETE
        FROM course_schedule
        WHERE id_ = #{id}
    </delete>

    <delete id="deleteCourseSchedulesByMusicGroupID" parameterType="map">
        DELETE
        FROM course_schedule
        WHERE music_group_id_ = #{musicGroupId}
          AND group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          and status_ = 'NOT_START'
    </delete>

    <update id="logicDeleteCourseSchedulesByMusicGroupID">
        update course_schedule
        set del_flag_    = '1',
            update_time_ = NOW()
        WHERE music_group_id_ = #{musicGroupID}
          AND group_type_ = 'MUSIC'
          and status_ = 'NOT_START'
    </update>

    <update id="resumeCourseScheduleByMusicGroupId">
        update course_schedule
        set del_flag_    = '0',
            update_time_ = NOW()
        WHERE music_group_id_ = #{musicGroupID}
          AND group_type_ = 'MUSIC'
          and status_ = 'NOT_START'
          and del_flag_ = '1'
    </update>

    <delete id="batchDeleteCourseSchedules">
        DELETE FROM course_schedule
        WHERE
        CONCAT( class_date_, ' ', start_class_time_ ) &gt; NOW()
        AND id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </delete>

    <delete id="batchDeleteCourseSchedulesWithoutCheck">
        DELETE FROM course_schedule
        WHERE id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </delete>

    <update id="batchDeleteCourseSchedulesWithLogic">
        UPDATE course_schedule
            SET del_flag_ = '1',update_time_ = NOW()
        WHERE
            CONCAT( class_date_, ' ', start_class_time_ ) &gt; NOW()
            AND id_ IN
            <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
                #{courseScheduleId}
            </foreach>
    </update>

    <delete id="batchDeleteAllCourseSchedules">
        DELETE FROM course_schedule
        WHERE id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </delete>

    <select id="filterNotStartCourseIdsWithIds" resultType="long">
        SELECT id_ FROM course_schedule
        WHERE
        CONCAT( class_date_, ' ', start_class_time_ ) &gt; NOW()
        AND id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </select>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="CourseSchedule" parameterType="map">
        SELECT * FROM course_schedule ORDER BY id_
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
        SELECT COUNT(*)
        FROM course_schedule
    </select>

    <resultMap type="com.ym.mec.biz.dal.dto.TeacherAttendanceDto" id="TeacherAttendanceViewUtilEntity">
        <result property="courseScheduleId" column="id_"/>
        <result property="courseScheduleName" column="course_schedule_name_"/>
        <result property="classDate" column="class_date_"/>
        <result property="startClassTime" column="start_class_time_"/>
        <result property="endClassTime" column="end_class_time_"/>
        <result property="courseStatus" column="course_status_"
                typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="classId" column="class_id"/>
        <result property="className" column="class_name"/>
        <result property="classType" column="class_type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="musicGroupId" column="music_group_id"/>
        <result property="musicGroupName" column="music_group_name"/>
        <result property="schoolId" column="school_id_"/>
        <result property="address" column="address_"/>
        <result property="longitudeAndLatitude" column="longitude_latitude_"/>
        <result property="teacherName" column="teacher_name_"/>
        <result property="signInTime" column="sign_in_time_"/>
        <result column="total_class_times_" property="totalClassTimes"/>
        <result column="current_class_times_" property="currentClassTimes"/>
        <result column="student_num_" property="studentNum"/>
    </resultMap>

    <select id="getCurrentCourseDetail"
            resultMap="TeacherAttendanceViewUtilEntity">
        SELECT cs.id_,
               cs.name_                                          course_schedule_name_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.status_                                        course_status_,
               cg.id_                                            class_id,
               cg.name_                                          class_name,
               cg.total_class_times_,
               cg.current_class_times_,
               cg.student_num_,
               cs.type_                                          class_type,
               mg.id_                                            music_group_id,
               mg.name_                                          music_group_name,
               s.id_                                             school_id_,
               s.address_,
               s.longitude_latitude_,
               su.real_name_                                     teacher_name_,
               ta.sign_in_time_
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
                 LEFT JOIN music_group mg ON cg.music_group_id_ = mg.id_
                 LEFT JOIN school s ON cs.schoole_id_ = s.id_
                 LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
                 LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_ AND ta.teacher_id_ = #{teacherId}
        WHERE cs.id_ = #{courseID}
        LIMIT 1
    </select>

    <select id="getTeacherCourseByDateSpeed"
            resultMap="TeacherAttendanceViewUtilEntity">
        SELECT cs.id_,
               cs.name_                                          course_schedule_name_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.status_                                        course_status_,
               cg.id_                                            class_id,
               cg.name_                                          class_name,
               cs.type_                                          class_type,
               mg.id_                                            music_group_id,
               mg.name_                                          music_group_name,
               s.id_                                             school_id_,
               s.address_,
               s.longitude_latitude_,
               su.real_name_                                     teacher_name_,
               ta.sign_in_time_,
               cs.schoole_id_
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
                 LEFT JOIN music_group mg ON cg.music_group_id_ = mg.id_
                 LEFT JOIN school s ON mg.school_id_ = s.id_
                 LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
                 LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
        WHERE cs.actual_teacher_id_ = #{teacherId}
          AND (CONCAT(cs.class_date_, ' ', cs.end_class_time_) BETWEEN #{startTime} AND #{endTime})
          AND cs.schoole_id_ = #{schoolId}
          AND ta.sign_in_time_ IS NOT NULL
        ORDER BY cs.id_
    </select>



    <resultMap id="studentAttendanceViewUtilEntity" type="com.ym.mec.biz.dal.dto.StudentAttendanceViewDto">
        <result property="classGroupId" column="class_group_id_"/>
        <result property="studentId" column="student_id_"/>
        <result property="userName" column="username_"/>
        <result property="musicGroupId" column="music_group_id_"/>
        <result property="subjectId" column="subject_id_"/>
        <result property="subjectName" column="subject_name_"/>
        <result property="status" column="status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    </resultMap>

    <select id="getCurrentCourseStudents" resultMap="studentAttendanceViewUtilEntity">
        SELECT cgsm.class_group_id_,
               su.id_  student_id_,
               su.username_,
               mg.id_  music_group_id_,
               s.id_   subject_id_,
               s.name_ subject_name_,
               cgsm.status_
        FROM class_group cg
                 LEFT JOIN class_group_student_mapper cgsm ON cg.id_ = cgsm.class_group_id_
                 LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
                 LEFT JOIN music_group mg ON cg.music_group_id_ = mg.id_
                 LEFT JOIN `subject` s ON cg.subject_id_ = s.id_
        WHERE cgsm.class_group_id_ = #{classID}
          AND cgsm.status_ != 'QUIT'
          AND cg.group_type_ = 'MUSIC'
    </select>

    <select id="countStudentInClass" resultType="java.lang.Integer">
        SELECT
        COUNT(class_group_id_)
        FROM
        class_group_student_mapper cgsm
        WHERE class_group_id_ IN
        <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach>
        AND cgsm.status_ != 'QUIT'
        GROUP BY user_id_
    </select>

    <select id="findByCourseScheduleIds" resultMap="CourseSchedule">
        SELECT
        <include refid="resultSql"/>
        FROM
        course_schedule cs
        WHERE cs.id_ IN
        <foreach collection="courseScheduleIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        ORDER BY cs.create_time_ DESC
    </select>

    <select id="findTeachingTeachers"
            resultMap="com.ym.mec.biz.dal.dao.CourseScheduleTeacherSalaryDao.CourseScheduleTeacherSalary">
        SELECT
        csts.*
        FROM
        course_schedule_teacher_salary csts
        WHERE
        csts.teacher_role_ = 'TEACHING'
        AND csts.course_schedule_id_ IN
        <foreach collection="courseScheduleIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

    <select id="getCourseSchedulesWithDate" resultMap="courseScheduleDto">
        SELECT
            cs.id_ seal_class_id_,
            cg.name_,
            cs.type_,
            cs.id_,
            cs.class_date_,
            CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
            CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
            cs.actual_teacher_id_,
            cs.status_,
            cs.student_num_,
            cs.leave_student_num_,
            cs.teach_mode_,
            cs.music_group_id_,
            cs.group_type_,
            cs.class_group_id_,
            cg.student_num_ total_student_num_,
            su.real_name_ teacher_name_,
            IF(ta.sign_in_status_ IS NULL,3,ta.sign_in_status_) sign_in_status_,
            s.name_ school_name_
        FROM
            course_schedule cs
            LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
            LEFT JOIN sys_user su ON cs.actual_teacher_id_=su.id_
            LEFT JOIN teacher_attendance ta ON cs.id_=ta.course_schedule_id_ AND ta.teacher_id_=cs.actual_teacher_id_
            LEFT JOIN school s ON cs.schoole_id_=s.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        <if test="classGroupIds != null and organIdList!=null">
            AND cs.class_group_id_ IN
            <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
                #{classGroupId}
            </foreach>
        </if>
        AND cs.id_ IS NOT NULL
        <if test="type!=null">
            AND cg.group_type_ = #{type}
        </if>
        <if test="musicGroupId!=null">
            AND cs.music_group_id_=#{musicGroupId} AND cs.group_type_='MUSIC'
        </if>
        AND cs.class_date_ = DATE_FORMAT(#{date},'%Y-%m-%d')
        ORDER BY CONCAT(cs.class_date_,' ',cs.start_class_time_)
        <include refid="global.limit"/>
    </select>

    <select id="countCourseSchedulesWithDate" resultType="int">
        SELECT
        count(*)
        FROM
        course_schedule cs
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND cs.id_ IS NOT NULL
        <if test="type!=null">
            AND cg.group_type_ = #{type}
        </if>
        <if test="classGroupIds != null and organIdList!=null">
            AND cs.class_group_id_ IN
            <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
                #{classGroupId}
            </foreach>
        </if>
        <if test="musicGroupId!=null">
            AND cs.music_group_id_=#{musicGroupId} AND cs.group_type_='MUSIC'
        </if>
        AND cs.class_date_ = DATE_FORMAT(#{date},'%Y-%m-%d')
    </select>

    <select id="getStudentCourseSchedulesWithDate" resultMap="courseScheduleDto">
        SELECT
        cs.id_ seal_class_id_,
        cs.name_,
        cs.type_,
        cs.id_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.status_,
        su.real_name_ teacher_name_,
        IF(sa.status_ IS NULL,'NORMAL',sa.status_) attendance_status_,
        csc.id_ IS NOT NULL complaint_status_,
        cs.teach_mode_
        FROM
        course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
        LEFT JOIN sys_user su ON cs.actual_teacher_id_=su.id_
        LEFT JOIN course_schedule_complaints csc ON csc.course_schedule_id_=cssp.course_schedule_id_ AND
        csc.user_id_=#{studentId}
        LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cs.id_ AND sa.user_id_=#{studentId}
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND (cs.is_lock_=0 OR cs.is_lock_ IS NULL)
        AND cs.class_date_ = DATE_FORMAT(#{classDate},'%Y%m%d')
        AND cssp.user_id_ = #{studentId}
        <if test="quitClassGroupIds != null and quitClassGroupIds.size()>0">
            AND cssp.class_group_id_ NOT IN
            <foreach collection="quitClassGroupIds" item="quitClassGroupId" open="(" close=")" separator=",">
                #{quitClassGroupId}
            </foreach>
        </if>
        ORDER BY start_class_time_
    </select>

    <select id="getTeacherCourseSchedulesWithDate" resultMap="courseScheduleDto">
        SELECT
        cs.id_ seal_class_id_,
        cg.name_,
        su.real_name_ teacher_name_,
        cs.type_,
        cs.id_,
        cs.class_group_id_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.status_,
        csts.user_id_ actual_teacher_id_,
        csts.teacher_role_,
        cg.expect_student_num_,
        cs.schoole_id_,
        s.name_ school_name_,
        IF(ta.sign_in_status_ IS NULL,3,ta.sign_in_status_) sign_in_status_enum_,
        IF(ta.sign_out_status_ IS NULL,3,ta.sign_out_status_) sign_out_status_enum_,
        IF(ta.sign_in_status_ IS NULL,0,1) sign_in_status_,
        IF(ta.sign_out_status_ IS NULL,0,1) sign_out_status_,
        cs.teach_mode_
        FROM
        course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON csts.course_schedule_id_=cs.id_
        LEFT JOIN sys_user su ON csts.user_id_ = su.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        LEFT JOIN school s ON cs.schoole_id_ = s.id_
        LEFT JOIN teacher_attendance ta ON cs.id_=ta.course_schedule_id_ AND ta.teacher_id_=#{teacherId}
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND (cs.is_lock_=0 OR cs.is_lock_ IS NULL)
        AND cs.class_date_ = DATE_FORMAT(#{classDate},'%Y%m%d')
        <if test="type!=null and type!=''">
            AND cs.type_=#{type}
        </if>
        AND csts.user_id_ = #{teacherId}
        ORDER BY start_class_time_
    </select>

    <select id="findCourseSchedulesWithDate" resultMap="courseScheduleDto">
        SELECT
        cs.id_ seal_class_id_,
        cg.name_,
        su.real_name_ teacher_name_,
        cs.type_,
        cs.id_,
        cs.class_group_id_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.status_,
        cs.teacher_id_,
        cs.actual_teacher_id_,
        cg.expect_student_num_,
        cs.schoole_id_,
        s.name_ school_name_,
        if(ta.sign_in_status_ IS NULL,0,1) sign_in_status_,
        if(ta.sign_out_status_ IS NULL,0,1) sign_out_status_,
        cs.teach_mode_
        FROM
        course_schedule cs
        LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        LEFT JOIN school s ON cs.schoole_id_ = s.id_
        LEFT JOIN teacher_attendance ta ON cs.id_=ta.course_schedule_id_ AND ta.teacher_id_=#{teacherId}
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND (cs.is_lock_=0 OR cs.is_lock_ IS NULL)
        <if test="teacherId!=null">
            AND cs.actual_teacher_id_=#{teacherId}
        </if>
        <if test="classDate!=null">
            AND cs.class_date_ = DATE_FORMAT(#{classDate},'%Y-%m-%d')
        </if>
        <if test="groupId!=null">
            AND cs.music_group_id_=#{groupId}
        </if>
        <if test="type!=null and type!=''">
            AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        ORDER BY start_class_time_
    </select>

    <select id="getTeacherHistoryCourseSchedulesWithDate" resultMap="courseScheduleDto">
        SELECT cs.id_                                            seal_class_id_,
               cg.name_,
               su.real_name_                                     teacher_name_,
               cs.type_,
               cs.id_,
               cs.class_group_id_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.status_,
               csts.user_id_                                     actual_teacher_id_,
               csts.teacher_role_,
               cs.schoole_id_,
               s.name_                                           school_name_,
               IF(ta.sign_in_status_ IS NULL,3,ta.sign_in_status_) sign_in_status_enum_,
               IF(ta.sign_out_status_ IS NULL,3,ta.sign_out_status_) sign_out_status_enum_,
               IF(ta.sign_in_status_ IS NULL,0,1) sign_in_status_,
               IF(ta.sign_out_status_ IS NULL,0,1) sign_out_status_,
               ta.is_complaints_,
               ta.sign_out_time_,
               ta.sign_in_time_,
               ta.complaints_status_,
               ta.complaints_content_,
               ta.dispose_content_,
               cs.teach_mode_
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON csts.course_schedule_id_ = cs.id_
                 LEFT JOIN sys_user su ON csts.user_id_ = su.id_
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
                 LEFT JOIN school s ON cs.schoole_id_ = s.id_
                 LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_ AND ta.teacher_id_ = #{teacherId}
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cs.class_date_ = DATE_FORMAT(#{classDate}, '%Y%m%d')
          AND csts.user_id_ = #{teacherId}
          AND CONCAT(cs.class_date_, ' ', cs.end_class_time_) &lt; NOW()
        ORDER BY start_class_time_
    </select>

    <select id="getCourseScheduleDateByMonth" resultType="java.util.Date">
        SELECT cs.class_date_
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE DATE_FORMAT(cs.class_date_, '%Y%m') = DATE_FORMAT(#{month}, '%Y%m')
          AND cg.music_group_id_ = #{musicGroupID}
          AND cg.group_type_ = 'MUSIC'
        GROUP BY cs.class_date_
    </select>

    <select id="countTeacherCourseInOnDayRepeats" parameterType="com.ym.mec.biz.dal.entity.CourseSchedule"
            resultType="int">
        SELECT COUNT(*)
        FROM course_schedule cs
        WHERE cs.teacher_id_ = #{teacherId}
          AND cs.class_date_ = DATE_FORMAT(#{classDate}, '%Y-%m-%d')
          AND (
                    CONCAT(cs.class_date_, ' ', cs.start_class_time_) &lt;
                    DATE_FORMAT('endClassTime', '%Y-%m-%d %H:%i:%s')
                OR CONCAT(cs.class_date_, ' ', cs.end_class_time_) &gt;
                   DATE_FORMAT('startClassTime', '%Y-%m-%d %H:%i:%s')
            )
    </select>
    <select id="findTeacherCoursesInDates" resultMap="CourseSchedule">
        SELECT
        id_,
        class_group_id_,
        status_,
        subsidy_,
        class_date_,
        concat(class_date_,' ',start_class_time_) start_class_time_,
        concat(class_date_,' ',end_class_time_) end_class_time_,
        teacher_id_,
        actual_teacher_id_,
        create_time_,
        update_time_
        FROM
        course_schedule cs
        WHERE
        cs.teacher_id_ = #{teacherId}
        AND cs.class_date_ IN
        <foreach collection="dates" item="date" open="(" close=")" separator=",">
            #{date}
        </foreach>
    </select>
    <select id="findCoursesByDates" resultMap="CourseSchedule">
        SELECT
        *
        FROM
        course_schedule cs
        WHERE
        cs.class_date_ IN
        <foreach collection="dates" item="date" open="(" close=")" separator=",">
            DATE_FORMAT(#{date},'%Y-%m-%d')
        </foreach>
    </select>

    <select id="findOverLapCoursesInDay" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.class_group_id_,
        cs.status_,
        cs.subsidy_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.teacher_id_,
        csts.user_id_ actual_teacher_id_,
        cs.create_time_,
        cs.update_time_,
        cs.teach_mode_,
        cs.type_,
        cs.name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.schoole_id_
        FROM
        course_schedule cs
        LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
        WHERE
        cs.class_date_ IN
        <foreach collection="dates" item="date" open="(" close=")" separator=",">
            DATE_FORMAT(#{date},'%Y-%m-%d')
        </foreach>
        AND (
        DATE_FORMAT(cs.start_class_time_,"%H:%i:%s") &gt; DATE_FORMAT(#{endClassTime}, '%H:%i:%s' )
        OR DATE_FORMAT(cs.end_class_time_,"%H:%i:%s") &lt; DATE_FORMAT( #{startClassTime}, '%H:%i:%s' )
        )=0
    </select>

    <select id="findCourseSchedulesByIds" resultMap="CourseSchedule">
        SELECT
        *
        FROM
        course_schedule cs
        WHERE
        cs.id_ IN
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>

    <!-- 获取班级未开始的课程 -->
    <select id="findClassGroupNoStartCourseSchedules" resultMap="CourseSchedule">
        SELECT * FROM course_schedule
        WHERE status_ = 'NOT_START'
        AND class_group_id_ IN
        <foreach collection="classGroupIds" item="classGroupId" index="index" open="(" close=")" separator=",">
            #{classGroupId}
        </foreach>
        <if test="groupType!= null ">
            AND group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
    </select>

    <select id="getStudentCourseScheduleDate" resultType="java.util.Date">
        SELECT
        cs.class_date_
        FROM
        course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND (cs.is_lock_=0 OR cs.is_lock_ IS NULL)
        AND cssp.user_id_ = #{studentId}
        <if test="month==null">
            AND DATE_FORMAT( NOW(), '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="month!=null">
            AND DATE_FORMAT( #{month}, '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="isAttend!=null">
            AND cs.status_='NOT_START'
        </if>
        GROUP BY
        cs.class_date_
    </select>

    <select id="getTeacherCourseScheduleDate" resultType="java.util.Date">
        SELECT
        cs.class_date_
        FROM
        course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON csts.course_schedule_id_=cs.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND (cs.is_lock_=0 OR cs.is_lock_ IS NULL)
        AND csts.user_id_ = #{teacherId}
        <if test="month==null">
            AND DATE_FORMAT( NOW(), '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="month!=null">
            AND DATE_FORMAT( #{month}, '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="type!=null and type!=''">
            AND cs.type_=#{type}
        </if>
        GROUP BY cs.class_date_
    </select>

    <select id="findHaveClassesDatesWithMonth" resultType="java.util.Date">
        SELECT
        cs.class_date_
        FROM
        course_schedule cs
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND (cs.is_lock_=0 OR cs.is_lock_ IS NULL)
        AND cg.del_flag_ = 0
        <if test="teacherId!=null">
            AND cs.actual_teacher_id_=#{teacherId}
        </if>
        <if test="month==null">
            AND DATE_FORMAT( NOW(), '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="month!=null">
            AND DATE_FORMAT( #{month}, '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="groupId!=null">
            AND cs.music_group_id_=#{groupId}
        </if>
        <if test="type!=null and type!=''">
            AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        GROUP BY cs.class_date_
    </select>

    <select id="getTeacherHistoryCourseScheduleDate" resultType="java.util.Date">
        SELECT
        cs.class_date_
        FROM
        course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON csts.course_schedule_id_=cs.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND CONCAT(cs.class_date_,' ',cs.start_class_time_) &lt; NOW()
        AND csts.user_id_ = #{teacherId}
        AND cg.del_flag_ = 0
        <if test="month==null">
            AND DATE_FORMAT( NOW(), '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        <if test="month!=null">
            AND DATE_FORMAT( #{month}, '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
        </if>
        GROUP BY cs.class_date_
    </select>

    <select id="getCourseScheduleDate" resultType="java.util.Date">
        SELECT
            cs.class_date_
        FROM
            course_schedule cs
            LEFT JOIN teacher t ON cs.actual_teacher_id_=t.id_
        WHERE
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
            AND cs.class_group_id_ IN
            <foreach collection="classGroupIds" item="classGroupId" separator="," open="(" close=")">
                #{classGroupId}
            </foreach>
            <if test="month==null">
                AND DATE_FORMAT( NOW(), '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
            </if>
            <if test="month!=null">
                AND DATE_FORMAT( #{month}, '%Y%m' ) = DATE_FORMAT( cs.class_date_, '%Y%m' )
            </if>
            <if test="type!=null and type!=''">
                AND cs.group_type_=#{type}
            </if>
        GROUP BY
        cs.class_date_
    </select>

    <select id="findClassSubjects" resultType="string">
        SELECT
        CONCAT(cg.id_,'-',IF(GROUP_CONCAT(s.name_) IS NULL,'',GROUP_CONCAT(s.name_)))
        FROM
        class_group cg
        LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,cg.subject_id_list_)
        WHERE cg.id_ IN
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY cg.id_
    </select>

    <sql id="queryStudentCourseScheduleRecordCondition">
        <where>
            cssp.user_id_=#{userId}
            AND cs.status_ != 'NOT_START'
            AND cs.del_flag_ = 0
            <if test="teachMode!=null and teachMode!=''">
                AND cs.teach_mode_=#{teachMode}
            </if>
            <if test="type!=null and type!=''">
                AND cs.group_type_ = #{type}
            </if>
            <if test="status != null and status != 'TRUANT'">
                AND sa.status_ = #{status}
            </if>
            <if test="status != null and status == 'TRUANT'">
                AND (sa.status_ = #{status} OR sa.status_ IS NULL)
            </if>
        </where>
    </sql>

    <select id="findStudentCourseScheduleRecords" resultMap="studentCourseScheduleRecord">
        SELECT
        sa.id_,
        IF(sa.status_ IS NULL,'TRUANT',sa.status_) status_,
        sa.teacher_id_,
        su.username_,
        cs.id_ course_schedule_id_,
        cs.name_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.teacher_id_,
        cs.teach_mode_
        FROM course_schedule_student_payment cssp
        LEFT JOIN student_attendance sa ON cssp.course_schedule_id_ = sa.course_schedule_id_ AND cssp.user_id_ =
        sa.user_id_
        LEFT JOIN course_schedule cs ON sa.course_schedule_id_=cs.id_
        LEFT JOIN sys_user su ON sa.teacher_id_=su.id_
        <include refid="queryStudentCourseScheduleRecordCondition"/>
        ORDER BY cs.class_date_ DESC,cs.start_class_time_ DESC
        <include refid="global.limit"/>
    </select>
    <select id="countStudentCourseScheduleRecords" resultType="int">
        SELECT
        count(cssp.id_)
        FROM course_schedule_student_payment cssp
        LEFT JOIN student_attendance sa ON cssp.course_schedule_id_ = sa.course_schedule_id_ AND cssp.user_id_ =
        sa.user_id_
        LEFT JOIN course_schedule cs ON sa.course_schedule_id_=cs.id_
        LEFT JOIN sys_user su ON sa.teacher_id_=su.id_
        <include refid="queryStudentCourseScheduleRecordCondition"/>
    </select>
    <select id="findStudentCourseScheduleNotStartRecords" resultMap="studentCourseScheduleRecord">
        SELECT cs.teacher_id_,
               su.real_name_                                     teacher_name_,
               cs.id_                                            course_schedule_id_,
               cs.name_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.teach_mode_,
               cs.class_group_id_
        FROM class_group_student_mapper cgsm
                 LEFT JOIN course_schedule cs ON cs.class_group_id_ = cgsm.class_group_id_
                 LEFT JOIN sys_user su ON cs.teacher_id_ = su.id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cs.status_ = 'NOT_START'
          AND cgsm.user_id_ = #{userId}
          AND cs.class_date_ = DATE_FORMAT(#{date}, '%Y%m%d')
          AND cgsm.status_ != 'QUIT'
        ORDER BY cs.class_date_, cs.start_class_time_
    </select>
    <select id="findCourseScheduleByMusicGroup" resultMap="CourseSchedule">
        SELECT cs.*
        FROM class_group cg
                 LEFT JOIN course_schedule cs ON cg.id_ = cs.class_group_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cg.music_group_id_ = #{musicGroupId}
    </select>
    <select id="countClassTimes" resultType="int">
        SELECT COUNT(*)
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
          AND CONCAT(class_date_, ' ', end_class_time_) &lt;= #{startClassTime}
    </select>
    <select id="getCourseSchedules" resultMap="courseScheduleDto">
        SELECT cs.type_,
               cs.id_,
               cs.id_                                            seal_class_id_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.status_,
               sc.paran_value_
        FROM course_schedule cs
                 LEFT JOIN sys_config sc ON sc.param_name_ = "vip_appeal_days_range"
        WHERE cs.id_ = #{courseScheduleId}
    </select>

    <select id="findStudentNamesByCourseSchedule" resultType="string">
        SELECT su.username_
        FROM student_attendance sa
                 LEFT JOIN sys_user su ON sa.user_id_ = su.id_
        WHERE sa.course_schedule_id_ = #{courseScheduleId}
          AND status_ = 'NORMAL'
    </select>
    <select id="findGroupCourseSchedules" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.group_type_,
               cs.music_group_id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_,
               s.name_                                           schoole_name_
        FROM course_schedule cs
                 LEFT JOIN school s ON cs.schoole_id_ = s.id_
        WHERE cs.music_group_id_ = #{groupId}
          AND cs.group_type_ = #{groupType}
        ORDER BY start_class_time_
    </select>
    <select id="findVipGroupNotStartCourseScheduleIds" resultType="long">
        SELECT cs.id_
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{groupId}
          AND cs.group_type_ = #{groupType}
          AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
    </select>
    <select id="findByClassGroupAndDate" resultMap="CourseSchedule">
        SELECT
        id_,
        class_group_id_,
        status_,
        subsidy_,
        class_date_,
        CONCAT(class_date_,' ',start_class_time_) start_class_time_,
        CONCAT(class_date_,' ',end_class_time_) end_class_time_,
        teacher_id_,
        actual_teacher_id_,
        create_time_,
        update_time_,
        type_,name_,
        teach_mode_
        FROM
        course_schedule
        <where>
            <if test="classGroupId!=null">
                AND class_group_id_ = #{classGroupId}
            </if>
            <if test="classDates!=null">
                AND class_date_ IN
                <foreach collection="classDates" item="classDate" open="(" close=")" separator=",">
                    #{classDate}
                </foreach>
            </if>
        </where>
    </select>

    <select id="findClassTypeByCourse" resultType="string">
        SELECT cg.type_
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cs.id_ = #{courseScheduleId}
    </select>

    <select id="queryVipGroupTeachereClassTimesByMonth" resultType="map" parameterType="map">
        SELECT vp.organ_id_          organ_id_,
               cs.actual_teacher_id_ teacher_id_,
               COUNT(cs.id_)         times,
               t.is_support_course_schedule_rewards_rules_
        FROM course_schedule cs
                 LEFT JOIN vip_group vp ON cs.music_group_id_ = vp.id_
                 LEFT JOIN teacher t ON cs.actual_teacher_id_ = t.id_
        WHERE cs.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND date_format(#{monthDate}, '%Y%m') = date_format(cs.class_date_, '%Y%m')
        GROUP BY vp.organ_id_, cs.actual_teacher_id_
    </select>

    <select id="queryFinishedWithNoUpdateStatus" resultMap="CourseSchedule">
        select *
        from course_schedule
        where CONCAT(class_date_, ' ', end_class_time_) &lt;= now()
          and status_ != 'OVER'
    </select>

    <select id="queryUnderwayWithNoUpdateStatus" resultMap="CourseSchedule">
        select *
        from course_schedule
        where CONCAT(class_date_, ' ', start_class_time_) &lt;= now()
          and status_ = 'NOT_START'
    </select>

    <update id="batchUpdate" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            UPDATE course_schedule
            <set>
                <if test="item.classDate != null">
                    class_date_ = #{item.classDate},
                </if>
                <if test="item.endClassTime != null">
                    end_class_time_ = #{item.endClassTime},
                </if>
                <if test="item.status != null">
                    status_ = #{item.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                </if>
                <if test="item.type != null">
                    type_ = #{item.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                </if>
                <if test="item.actualTeacherId != null">
                    actual_teacher_id_ = #{item.actualTeacherId},
                </if>
                <if test="item.subsidy != null">
                    subsidy_ = #{item.subsidy},
                </if>
                <if test="item.classGroupId != null">
                    class_group_id_ = #{item.classGroupId},
                </if>
                <if test="item.startClassTime != null">
                    start_class_time_ = #{item.startClassTime},
                </if>
                <if test="item.teacherId != null">
                    teacher_id_ = #{item.teacherId},
                </if>
                <if test="item.studentNum != null">
                    student_num_ = #{item.studentNum},
                </if>
                <if test="item.leaveStudentNum != null">
                    leave_student_num_ = #{item.leaveStudentNum},
                </if>
                schoole_id_ = #{item.schoolId},
                <if test="item.schoolId == null">
                    schoole_id_ = null,
                </if>
                <if test="item.teachMode != null">
                    teach_mode_ = #{item.teachMode,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
                </if>
                update_time_ = NOW()
            </set>
            WHERE id_ = #{item.id}
        </foreach>
    </update>
    <update id="updateByMusicGroupId">
        UPDATE course_schedule cs
        SET cs.schoole_id_ = #{schoolId},
            update_time_   = NOW()
        WHERE cs.class_group_id_ IN (SELECT cg.id_
                                     FROM class_group cg
                                     WHERE cg.music_group_id_ = #{musicGroupId}
                                       AND cg.group_type_ = 'MUSIC')
    </update>

    <update id="updateCourscheduleStatus">
        UPDATE course_schedule
        SET status_      = #{status},
            update_time_ = NOW()
        WHERE id_ = #{courseScheduleId}
    </update>
    <update id="updateCourseScheduleSchool">
        UPDATE course_schedule cs
        SET cs.schoole_id_ = #{schoolId},
            update_time_   = NOW()
        WHERE cs.music_group_id_ = #{musicGroupId}
          AND cs.group_type_ = 'MUSIC'
          AND NOW() &lt; CONCAT(cs.class_date_, " ", cs.start_class_time_);
    </update>
    <update id="updateCourseSchoolByGroup">
        UPDATE course_schedule cs
        SET cs.schoole_id_ = #{schoolId},
            update_time_   = NOW()
        WHERE cs.music_group_id_ = #{groupId}
          AND cs.group_type_ = #{groupType}
          AND cs.teach_mode_ = "OFFLINE"
          AND NOW() &lt; CONCAT(cs.class_date_, " ", cs.start_class_time_);
    </update>

    <update id="updateGroupCourseLock">
        UPDATE course_schedule
        SET is_lock_     = #{isLock},
            update_time_ = NOW()
        WHERE music_group_id_ = #{groupId}
          AND group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND NOW() &lt; CONCAT(class_date_, " ", start_class_time_);
    </update>

    <select id="queryNoSignInListByBeforeMinutes" resultMap="CourseSchedule">
        SELECT cs.*
        FROM course_schedule cs
                 left join teacher_attendance ta on ta.course_schedule_id_ = cs.id_
        WHERE ta.sign_in_time_ is null
          and SUBTIME(start_class_time_, CONCAT(#{minutes}, '00')) &lt; CURRENT_TIME()
    </select>

    <resultMap id="teacherClassCourseSchedule" type="com.ym.mec.biz.dal.dto.TeacherClassCourseSchudeleDto">
        <result property="classGroupId" column="class_group_id_"/>
        <result property="courseScheduleId" column="course_schedule_id_"/>
        <result property="courseScheduleName" column="course_schedule_name_"/>
        <result property="status" column="status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="classDate" column="class_date_"/>
        <result property="startClassTime" column="start_class_time_"/>
        <result property="endClassTime" column="end_class_time_"/>
        <result property="actualTeacherId" column="actual_teacher_id_"/>
        <result property="actualTeacherName" column="username_"/>
        <result property="type" column="type_"/>
        <result property="studentNum" column="student_num_"/>
        <result property="leaveStudentNum" column="leave_student_num_"/>
        <result property="currentClassTimes" column="current_class_times_"/>
        <result property="totalClassTimes" column="total_class_times_"/>
        <result property="studentNames" column="student_names_"/>
        <result column="teach_mode_" property="teachMode" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="school_id_" property="schoolId"/>
        <result column="school_name_" property="schoolName"/>
    </resultMap>

    <sql id="teacherClassCourseScheduleQueryCondition">
        <where>
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
            AND cs.class_group_id_ = #{classGroupId}
            <if test="userId != null">
                AND csts.user_id_ = #{userId}
            </if>
            <if test="onlyHistory!=null and onlyHistory==1">
                AND CONCAT( cs.class_date_, ' ', cs.end_class_time_ )&lt;now()
            </if>
        </where>
    </sql>

    <select id="queryTeacherClassCourseSchedule" resultMap="teacherClassCourseSchedule">
        SELECT
        cs.class_group_id_,
        cs.id_ course_schedule_id_,
        cs.class_date_,
        CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) start_class_time_,
        CONCAT( cs.class_date_, ' ', cs.end_class_time_ ) end_class_time_,
        cs.name_ course_schedule_name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.type_,
        cs.status_,
        cs.actual_teacher_id_,
        cs.teach_mode_,
        su.real_name_ username_,
        cg.total_class_times_,
        cs.schoole_id_ school_id_,
        s.name_ school_name_
        FROM
        course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
        LEFT JOIN class_group cg ON cs.class_group_id_=cg.id_
        LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
        LEFT JOIN school s ON cs.schoole_id_=s.id_
        <include refid="teacherClassCourseScheduleQueryCondition"/>
        ORDER BY start_class_time_
        <include refid="global.limit"/>
    </select>

    <sql id="teacherGroupCourseQueryCondition">
        <where>
            cs.actual_teacher_id_=#{teacherId}
            AND cs.music_group_id_ = #{groupId}
            AND cs.group_type_ = #{groupType}
        </where>
    </sql>

    <select id="findTeacherGroupCourses" resultMap="teacherClassCourseSchedule">
        SELECT
        cs.class_group_id_,
        cs.id_ course_schedule_id_,
        cs.class_date_,
        CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) start_class_time_,
        CONCAT( cs.class_date_, ' ', cs.end_class_time_ ) end_class_time_,
        cs.name_ course_schedule_name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.type_,
        cs.status_,
        cs.actual_teacher_id_,
        cs.teach_mode_
        FROM course_schedule cs
        <include refid="teacherGroupCourseQueryCondition"/>
        ORDER BY CONCAT( cs.class_date_, ' ', cs.start_class_time_ )
        <include refid="global.limit"/>
    </select>

    <select id="countTeacherGroupCourses" resultType="int">
        SELECT
        COUNT(cs.id_)
        FROM course_schedule cs
        <include refid="teacherGroupCourseQueryCondition"/>
    </select>

    <select id="queryTeacherHistoryClassCourseSchedule" resultMap="teacherClassCourseSchedule">
        SELECT
        cs.class_group_id_,
        cs.id_ course_schedule_id_,
        cs.class_date_,
        CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) start_class_time_,
        CONCAT( cs.class_date_, ' ', cs.end_class_time_ ) end_class_time_,
        cs.name_ course_schedule_name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.type_,
        cs.status_,
        cs.actual_teacher_id_,
        cs.teach_mode_,
        su.username_,
        cg.total_class_times_,
        GROUP_CONCAT(IF(sa.status_='NORMAL',ssu.username_,NULL)) student_names_,
        MAX(sa.current_class_times_) current_class_times_,
        cs.schoole_id_ school_id_,
        s.name_ school_name_
        FROM
        student_attendance sa
        LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
        LEFT JOIN class_group cg ON cs.class_group_id_=cg.id_
        LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
        LEFT JOIN sys_user ssu ON sa.user_id_=ssu.id_
        LEFT JOIN school s ON cs.schoole_id_ = s.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND sa.class_group_id_=#{classGroupId}
        <if test="userId != null">
            AND sa.teacher_id_=#{userId}
        </if>
        GROUP BY sa.course_schedule_id_
        ORDER BY cs.id_
        <include refid="global.limit"/>
    </select>

    <select id="countTeacherClassCourseSchedule" resultType="int">
        SELECT
        COUNT(cs.id_)
        FROM
        course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
        <include refid="teacherClassCourseScheduleQueryCondition"/>
    </select>
    <select id="countTeacherHistoryClassCourseSchedule" resultType="int">
        SELECT
        COUNT(DISTINCT sa.class_group_id_)
        FROM
        student_attendance sa
        LEFT JOIN course_schedule cs ON sa.course_schedule_id_=cs.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND sa.class_group_id_=#{classGroupId}
        <if test="userId != null">
            AND sa.teacher_id_=#{userId}
        </if>
    </select>
    <select id="countClassCourseNumByMusicGroup" resultType="java.util.Map">
        SELECT cg.id_        as 'key',
               COUNT(cs.id_) as 'value'
        FROM class_group cg
                 LEFT JOIN course_schedule cs ON cg.id_ = cs.class_group_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND music_group_id_ = #{musicGroupId}
        GROUP BY cg.id_
    </select>
    <select id="findCourseScheduleCurrentTimes" resultType="java.util.Map">
        SELECT
        course_schedule_id_ AS 'key',
        MAX(current_class_times_) AS 'value'
        FROM
        student_attendance sa
        WHERE sa.course_schedule_id_ IN
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY course_schedule_id_
    </select>

    <!-- 获取班级某时间后对应节数的课程 -->
    <select id="findCourseScheduleByClassGroupIdAndDate" resultMap="CourseSchedule">
        SELECT *
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
          AND class_date_ >= #{startDate}
        ORDER BY class_date_ ASC
        LIMIT #{times}
    </select>

    <select id="queryTeacherCourseScheduleListByTimeRangeAndType" resultMap="CourseSchedule" parameterType="map">
        SELECT
        cs.id_,
        cs.music_group_id_,
        cs.class_group_id_,
        cs.status_,
        cs.subsidy_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.teacher_id_,
        cs.actual_teacher_id_,
        cs.create_time_,
        cs.update_time_,
        cs.teach_mode_,
        cs.type_,
        cg.name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.schoole_id_
        FROM course_schedule cs
        LEFT JOIN class_group cg ON cs.class_group_id_=cg.id_
        LEFT JOIN music_group mg ON cs.music_group_id_=mg.id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND cs.teacher_id_=#{teacherId}
        and CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) between #{startTime} and #{endTime}
        <if test="type != null">
            and cs.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        ORDER BY CONCAT(cs.class_date_,' ',cs.start_class_time_)
    </select>
    <!-- 查找班级未开始的课程 -->
    <select id="findCoursesByClassGroupId" resultMap="CourseSchedule">
        SELECT *
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
        <if test="status != null">
            and status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
    </select>

    <resultMap id="CourseAttendanceDetailHeadInfoDto" type="com.ym.mec.biz.dal.dto.CourseAttendanceDetailHeadInfoDto">
        <result property="courseScheduleId" column="course_schedule_id_"/>
        <result property="classGroupId" column="class_group_id_"/>
        <result property="classGroupName" column="class_group_name_"/>
        <result property="teacherId" column="user_id_"/>
        <result property="teacherName" column="username_"/>
        <result property="classDate" column="class_date_"/>
        <result property="startClassTime" column="start_class_time_"/>
        <result property="endClassTime" column="end_class_time_"/>
        <result property="studentNum" column="student_num_"/>
        <result property="leaveStudentNum" column="leave_student_num_"/>
        <result property="totalStudentNum" column="total_student_num_"/>
    </resultMap>

    <select id="findByCourse" resultMap="CourseAttendanceDetailHeadInfoDto">
        SELECT cs.id_                                            course_schedule_id_,
               cg.id_                                            class_group_id_,
               cg.name_                                          class_group_name_,
               csts.user_id_,
               su.real_name_                                     username_,
               cs.student_num_,
               cg.student_num_                                   total_student_num_,
               cs.leave_student_num_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_
        FROM course_schedule cs
                 LEFT JOIN course_schedule_teacher_salary csts
                           ON cs.id_ = csts.course_schedule_id_ AND csts.teacher_role_ = 'BISHOP'
                 LEFT JOIN sys_user su ON csts.user_id_ = su.id_
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cs.id_ = #{courseScheduleId}
    </select>
    <select id="queryMusicGroupIds" resultMap="com.ym.mec.biz.dal.dao.GroupDao.Group">
        SELECT DISTINCT cgsm.music_group_id_ group_id_,cgsm.group_type_ FROM class_group_student_mapper cgsm
        LEFT JOIN music_group mg ON mg.id_ = cgsm.music_group_id_ AND cgsm.group_type_ = 'MUSIC'
        LEFT JOIN vip_group vg ON vg.id_ = cgsm.music_group_id_ AND cgsm.group_type_ = 'VIP' AND vg.group_status_!=7
        LEFT JOIN practice_group pg ON pg.id_ = cgsm.music_group_id_ AND cgsm.group_type_ = 'PRACTICE'
        WHERE cgsm.user_id_ = #{userId} AND cgsm.status_ != 'QUIT'
        AND (mg.status_ = 'PROGRESS' OR vg.group_status_ = 2 OR vg.group_status_ = 4 OR (pg.id_ IS NOT NULL AND
        pg.group_status_!='LOCK' AND pg.group_status_!='CANCEL'))
        ORDER BY cgsm.music_group_id_
        <include refid="global.limit"/>
    </select>
    <select id="countMusicGroupIds" resultType="int">
        SELECT COUNT(DISTINCT cgsm.music_group_id_)
        FROM class_group_student_mapper cgsm
                 LEFT JOIN music_group mg ON mg.id_ = cgsm.music_group_id_ AND cgsm.group_type_ = 'MUSIC'
                 LEFT JOIN vip_group vg ON vg.id_ = cgsm.music_group_id_ AND cgsm.group_type_ = 'VIP' AND vg.group_status_!=7
                 LEFT JOIN practice_group pg ON pg.id_ = cgsm.music_group_id_ AND cgsm.group_type_ = 'PRACTICE'
        WHERE cgsm.user_id_ = #{userId}
          AND cgsm.status_ != 'QUIT'
          AND (mg.status_ = 'PROGRESS' OR vg.group_status_ = 2 OR vg.group_status_ = 4 OR pg.id_ IS NOT NULL)
    </select>
    <select id="queryMusicGroupIdsWithoutOverGroup" resultMap="com.ym.mec.biz.dal.dao.GroupDao.Group">
        SELECT DISTINCT spo.music_group_id_ group_id_,cgsm.group_type_ FROM student_payment_order spo
        LEFT JOIN class_group_student_mapper cgsm ON spo.music_group_id_ = cgsm.music_group_id_
        LEFT JOIN vip_group vg ON vg.id_=spo.music_group_id_ AND spo.group_type_='VIP' AND vg.group_status_!=7
        LEFT JOIN class_group cg ON cgsm.class_group_id_ = cg.id_
        WHERE spo.type_ != 'OTHER' AND spo.music_group_id_ IS NOT NULL
        AND spo.user_id_ = #{userId} AND spo.status_='SUCCESS' AND cgsm.status_ != 'QUIT'
        AND IF(spo.group_type_ = 'VIP', (vg.group_status_ = 4 OR vg.group_status_ = 3 ),0)=0 AND cg.del_flag_ = 0
        <include refid="global.limit"/>
    </select>

    <select id="countMusicGroupIdsWithoutOverGroup" resultType="int">
        SELECT COUNT(DISTINCT spo.music_group_id_)
        FROM student_payment_order spo
                 LEFT JOIN class_group_student_mapper cgsm ON spo.music_group_id_ = cgsm.music_group_id_
                 LEFT JOIN vip_group vg ON vg.id_ = spo.music_group_id_ AND spo.group_type_ = 'VIP' AND vg.group_status_!=7
                 LEFT JOIN class_group cg ON cgsm.class_group_id_ = cg.id_
        WHERE spo.type_ != 'OTHER'
          AND spo.music_group_id_ IS NOT NULL
          AND spo.user_id_ = #{userId}
          AND spo.status_ = 'SUCCESS'
          AND cgsm.status_ != 'QUIT'
          AND IF(spo.group_type_ = 'VIP', (vg.group_status_ = 4 OR vg.group_status_ = 3), 0) = 0
          AND cg.del_flag_ = 0
    </select>
    <select id="countExistRepeatInDateZone" resultType="int">
        SELECT COUNT(csts.course_schedule_id_)
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON csts.course_schedule_id_ = cs.id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND csts.user_id_ = #{teacherId}
          AND cs.class_date_ = DATE_FORMAT(#{classDate}, '%Y-%m-%d')
          AND DATE_FORMAT(#{startTime}, '%H:%i:%S') &lt;= DATE_FORMAT(cs.end_class_time_, '%H:%i:%S')
          AND DATE_FORMAT(#{endTime}, '%H:%i:%S') &gt;= DATE_FORMAT(cs.start_class_time_, '%H:%i:%S')
    </select>
    <select id="findByDateZone" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule cs
        WHERE (cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, '%Y%m%d') AND DATE_FORMAT(#{endTime}, '%Y%m%d'))
          AND cs.status_ = 'NOT_START'
    </select>
    <select id="findAllCourseByDateZone" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.music_group_id_,
               cs.group_type_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_,
               cg.type_                                          class_group_type_
        FROM course_schedule cs
                 left join class_group cg on cs.class_group_id_ = cg.id_
        WHERE (cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, '%Y%m%d') AND DATE_FORMAT(#{endTime}, '%Y%m%d'))
          AND (cs.del_flag_ IS NULL OR cs.del_flag_ = 0)
          AND (cg.del_flag_ IS NULL OR cg.del_flag_ = 0)
    </select>

    <select id="findByClassDate" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.music_group_id_,
        cs.class_group_id_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.type_,
        cs.name_,
        cs.actual_teacher_id_
        FROM
        course_schedule cs
        WHERE (cs.class_date_ IN
        <foreach collection="classDates" item="classDate" open="(" close=")" separator=",">
            #{classDate}
        </foreach>
        )
        AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
    </select>

    <select id="findByClassDateWithoutMusicGroup" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.music_group_id_,
        cs.class_group_id_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.type_,
        cs.name_,
        cs.actual_teacher_id_
        FROM
        course_schedule cs
        WHERE
        cs.group_type_!='MUSIC'
        AND (cs.class_date_ IN
        <foreach collection="classDates" item="classDate" open="(" close=")" separator=",">
            #{classDate}
        </foreach>
        )
        AND (cs.del_flag_ IS NULL OR cs.del_flag_=0)
    </select>

    <select id="findAllCourseByDateZone2" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_group_id_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.actual_teacher_id_
        FROM course_schedule cs
        WHERE (cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, '%Y%m%d') AND DATE_FORMAT(#{endTime}, '%Y%m%d'))
          AND (cs.del_flag_ IS NULL OR cs.del_flag_ = 0)
    </select>

    <select id="queryStudentCoursesTimesOfTomorrow" resultMap="Mapper">
        select cssp.user_id_ key_, count(1) value_
        from course_schedule cs
                 right join course_schedule_student_payment cssp on cs.id_ = cssp.course_schedule_id_
        where class_date_ = date(DATE_ADD(now(), INTERVAL 1 DAY))
        group by cssp.user_id_
    </select>

    <select id="queryStudentNotStartCourseScheduleIn90Mins" resultMap="Mapper">
        select cssp.user_id_ key_, cs.name_ value_
        from course_schedule cs
                 right join course_schedule_student_payment cssp on cs.id_ = cssp.course_schedule_id_
        where CONCAT(cs.class_date_, ' ', cs.start_class_time_) &lt; DATE_ADD(now(), INTERVAL 90 MINUTE)
          and cs.status_ = 'NOT_START'
    </select>

    <select id="queryTeacherCoursesTimesOfTomorrow" resultMap="Mapper">
        select cssp.user_id_ key_, u.real_name_ value_
        from course_schedule cs
                 right join course_schedule_teacher_salary cssp on cs.id_ = cssp.course_schedule_id_
                 left join sys_user u on u.id_ = cssp.user_id_
        where class_date_ = date(DATE_ADD(now(), INTERVAL 1 DAY))
        group by cssp.user_id_
    </select>

    <select id="queryTeacherNotStartCourseScheduleIn30Mins" resultMap="Mapper">
        select cssp.user_id_ key_, cs.name_ value_
        from course_schedule cs
                 right join course_schedule_teacher_salary cssp on cs.id_ = cssp.course_schedule_id_
        where CONCAT(cs.class_date_, ' ', cs.start_class_time_) &lt; DATE_ADD(now(), INTERVAL 30 MINUTE)
          and cs.status_ = 'NOT_START'
    </select>

    <resultMap id="IntegerAndIntegerListDto" type="com.ym.mec.biz.dal.dto.IntegerAndIntegerListDto">
        <result property="id" column="id_"/>
        <collection property="ids" ofType="int" javaType="list">
            <result column="relate_ids"/>
        </collection>
    </resultMap>

    <select id="findCourseScheduleIdAndUserIdsMap" resultMap="IntegerAndIntegerListDto">
        select
        course_schedule_id_ id_,
        user_id_ relate_ids
        from course_schedule_teacher_salary
        where 1=1
        <if test="teacherRole!=null and teacherRole!=''">
            AND teacher_role_=#{teacherRole}
        </if>
        AND course_schedule_id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </select>
    <select id="findClassGroupAndUserIdsMap" resultMap="IntegerAndIntegerListDto">
        SELECT
        class_group_id_ id_,
        user_id_ relate_ids
        FROM
        class_group_teacher_mapper
        WHERE 1=1
        <if test="teacherRole!=null and teacherRole!=''">
            AND teacher_role_=#{teacherRole}
        </if>
        AND class_group_id_ IN
        <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
            #{classGroupId}
        </foreach>
    </select>
    <select id="findCourseScheduleWithDate" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule cs
        WHERE cs.class_date_ BETWEEN #{startDate} AND #{endDate}
          AND cs.group_type_ = 'MUSIC'
          AND (cs.del_flag_ IS NULL OR cs.del_flag_ = 0)
    </select>
    <select id="findByClassGroup" resultMap="CourseSchedule">
        select cs.id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               csts.user_id_                                     actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        from course_schedule cs
                 LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
        where cs.class_group_id_ = #{classGroupId}
    </select>
    <select id="findByClassGroupAndStatus" resultMap="CourseSchedule">
        select cs.id_,
               cs.group_type_,
               cs.music_group_id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               csts.user_id_                                     actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        from course_schedule cs
                 LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
        where cs.class_group_id_ = #{classGroupId}
          AND cs.status_ = #{status}
    </select>
    <select id="findByClassGroups" resultMap="CourseSchedule">
        select
        cs.id_,
        cs.class_group_id_,
        cs.status_,
        cs.subsidy_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.start_class_time_ start_class_time_str_,
        cs.end_class_time_ end_class_time_str_,
        cs.teacher_id_,
        cs.actual_teacher_id_,
        cs.create_time_,
        cs.update_time_,
        cs.teach_mode_,
        cs.type_,
        cs.name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.schoole_id_,
        cg.name_ class_group_name_
        from course_schedule cs
        LEFT JOIN class_group cg ON cs.class_group_id_=cg.id_
        where cs.class_group_id_ IN
        <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
            #{classGroupId}
        </foreach>
        ORDER BY start_class_time_
    </select>
    <select id="findStudentMap" resultType="java.util.Map">
        SELECT cs.user_id_ 'key', cs.user_id_ 'value'
        FROM course_schedule_student_payment cs
        WHERE cs.course_schedule_id_ = #{courseScheduleId}
        GROUP BY user_id_
    </select>

    <select id="findAllCourseSches" resultMap="CourseSchedule">
        select cs.id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        from course_schedule cs
    </select>

    <select id="findOneCourseScheduleByClassGroupId" resultMap="CourseSchedule">
        SELECT *
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
        LIMIT 1
    </select>
    <select id="countClassGroupCourseTimes" resultType="map">
        SELECT
        class_group_id_ AS 'key',
        COUNT(id_) AS 'value'
        FROM
        course_schedule
        <where>
            <if test="classGroupIds!=null">
                class_group_id_ IN
                <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
                    #{classGroupId}
                </foreach>
                AND del_flag_ = 0
            </if>
        </where>

        GROUP BY class_group_id_
    </select>
    <select id="countClassGroupCourses" resultType="int">
        SELECT COUNT(1)
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
          AND (del_flag_ != 1 OR del_flag_ IS NULL)
    </select>
    <select id="findMusicGroupCourseSchedules" resultMap="CourseSchedule">
        SELECT cs.*
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cg.music_group_id_ = #{musicGroupId}
          AND cs.group_type_ = #{groupType}
          AND status_ = #{status}
    </select>
    <select id="findMusicGroupAllCourseSchedules" resultMap="CourseSchedule">
        SELECT cs.*
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cg.music_group_id_ = #{musicGroupId}
          AND cs.group_type_ = #{groupType}
    </select>
    <select id="findMusicGroupCourseSchedulesWithStudent" resultMap="CourseSchedule">
        SELECT cs.*
        FROM course_schedule_student_payment cssp
                 LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cssp.music_group_id_ = #{musicGroupId}
          AND cssp.group_type_ = #{groupType}
          AND cs.status_ = #{status}
          AND cssp.user_id_ = #{userId}
    </select>

    <delete id="deleteMusicGroupCourseSchedulesWithStudent">
        DELETE
        FROM
        course_schedule_student_payment
        WHERE user_id_ =#{userId} AND course_schedule_id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </delete>

    <delete id="deleteMusicGroupCourseSchedulesWithStudents">
        DELETE
        FROM
        course_schedule_student_payment
        WHERE user_id_ IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
        AND course_schedule_id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </delete>

    <select id="getClassGroupNotStartCourse" resultMap="CourseSchedule">
        SELECT * FROM course_schedule WHERE class_group_id_=#{classGroupId} AND CONCAT(class_date_,' ', start_class_time_) &gt; NOW()
    </select>

    <delete id="deleteCourseSchedulesByClassGroupIds">
        DELETE FROM course_schedule WHERE id_ IN
        <foreach collection="courseScheduleIds" item="courseScheduleId" open="(" close=")" separator=",">
            #{courseScheduleId}
        </foreach>
    </delete>
    <delete id="deleteByGroup">
        DELETE
        FROM course_schedule
        WHERE music_group_id_ = #{groupId}
          AND group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
    </delete>

    <select id="queryUnsignedStudentList" resultMap="StudentAttendance">
        SELECT cssp.user_id_,
               cs.actual_teacher_id_ teacher_id_,
               cs.id_                course_schedule_id_,
               cs.class_group_id_,
               cs.music_group_id_,
               cs.group_type_,
               cg.current_class_times_
        FROM course_schedule_student_payment cssp
                 LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
                 LEFT JOIN class_group cg ON cg.id_ = cs.class_group_id_
                 LEFT JOIN student_attendance sa
                           ON sa.course_schedule_id_ = cssp.course_schedule_id_ AND cssp.user_id_ = sa.user_id_
        WHERE CONCAT(cs.class_date_, ' ', cs.end_class_time_) &lt;= DATE_ADD(NOW(), INTERVAL -1 HOUR)
          AND sa.id_ IS NULL
    </select>
    <select id="getNextCourseSchedule" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule cs
        WHERE cs.class_group_id_ = #{classGroupId}
          AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
        ORDER BY CONCAT(cs.class_date_, ' ', cs.start_class_time_)
        LIMIT 1
    </select>
    <select id="countCurrentTimes" resultType="int">
        SELECT COUNT(*)
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
          AND CONCAT(class_date_, ' ', end_class_time_) &lt; #{currentCourseDate}
          AND del_flag_ = 0
    </select>
    <select id="countCourseScheduleByMusicGroupId" resultType="java.lang.Integer">
        SELECT count(cs.id_)
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{musicGroupId}
          and cs.group_type_ = 'MUSIC'
          and cs.status_ != 'OVER'
          AND cs.del_flag_ = 0
        LIMIT 1
    </select>
    <select id="findClassGroupCourseSchedules" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule cs
        WHERE cs.class_group_id_ = #{classGroupId}
          AND (cs.del_flag_ = 0 OR cs.del_flag_ IS NULL)
    </select>
    <select id="countVipGroupCourses" resultType="int">
        SELECT count(cs.id_)
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{vipGroupId}
          AND cs.group_type_ = #{groupType}
    </select>
    <select id="findCourseNoStartNum" resultType="java.lang.Integer">
        SELECT COUNT(cs.id_)
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{vipGroupId}
          AND cs.group_type_ = 'VIP'
          AND cs.status_ = 'NOT_START'
          AND cs.del_flag_ != '1'
    </select>
    <select id="findCourseEndNum" resultType="java.lang.Integer">
        SELECT COUNT(cs.id_)
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{vipGroupId}
          AND cs.group_type_ = 'VIP'
          AND cs.status_ != 'NOT_START'
          AND cs.del_flag_ != '1'
    </select>
    <select id="countCourseNum" resultType="java.lang.Integer">
        SELECT COUNT(cs.id_) FROM course_schedule cs
        WHERE cs.music_group_id_ = #{vipGroupId} AND cs.group_type_ = 'VIP' AND cs.del_flag_ != '1'
        <if test="teachMode != null">
            AND cs.teach_mode_ = #{teachMode}
        </if>
    </select>
    <select id="getTeachModeById" resultType="map">
        SELECT id_ as 'key',teach_mode_ as 'value' FROM course_schedule WHERE id_ IN
        <foreach collection="courseIds" item="courseId" open="(" close=")" separator=",">
            #{courseId}
        </foreach>
    </select>
    <select id="countTotalCourseScheduleNum" resultType="java.util.Map">
        SELECT cs.music_group_id_ 'key',COUNT(cs.id_) 'value' FROM course_schedule cs WHERE cs.music_group_id_ IN
        <foreach collection="vipGroupIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        AND cs.group_type_ = #{groupType} AND cs.del_flag_ = 0
        GROUP BY cs.music_group_id_
    </select>
    <select id="countTotalCourseScheduleNumWithGroup" resultType="int">
        SELECT COUNT(cs.id_)
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{groupId}
        AND cs.group_type_ = #{groupType} AND cs.del_flag_ = 0
    </select>
    <select id="countCourseScheduleNum" resultType="java.util.Map">
        SELECT cs.music_group_id_ 'key',COUNT(cs.id_) 'value' FROM course_schedule cs WHERE cs.music_group_id_ IN
        <foreach collection="vipGroupIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        AND cs.group_type_ = #{groupType} AND cs.status_ != 'NOT_START' AND cs.del_flag_ = 0
        GROUP BY cs.music_group_id_
    </select>
    <select id="countTotalNumByClassGroupId" resultType="java.util.Map">
        SELECT cs.class_group_id_ 'key',COUNT(cs.id_) 'value' FROM course_schedule cs
        WHERE cs.class_group_id_ IN
        <foreach collection="classGroupIds" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
        <if test="classDate != null">
            AND cs.class_date_ = DATE_FORMAT(#{classDate}, '%Y%m%d')
        </if>
        AND cs.del_flag_ = 0
        GROUP BY cs.class_group_id_
    </select>
    <select id="countCurrentNumByClassGroupId" resultType="java.util.Map">
        SELECT cs.class_group_id_ 'key',COUNT(cs.id_) 'value' FROM course_schedule cs
        WHERE cs.class_group_id_ IN
        <foreach collection="classGroupIds" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
        <if test="teacherId != null">
            AND cs.actual_teacher_id_ = #{teacherId}
        </if>
        AND cs.status_ = 'NOT_START' AND cs.del_flag_ = 0
        GROUP BY cs.class_group_id_
    </select>

    <select id="countExpendNumByClassGroupId" resultType="java.util.Map">
        SELECT cs.class_group_id_ 'key',COUNT(cs.id_) 'value' FROM course_schedule cs
        WHERE cs.class_group_id_ IN
        <foreach collection="classGroupIds" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
        AND cs.status_ != 'NOT_START' AND cs.del_flag_ = 0
        GROUP BY cs.class_group_id_
    </select>

    <select id="findUserSurplusCourseInfoByGroup" resultMap="StudentCourseInfoDto">
        SELECT cs.id_,
               cs.music_group_id_,
               cs.class_group_id_,
               cs.status_,
               cs.class_date_,
               cs.start_class_time_,
               cs.end_class_time_,
               cs.actual_teacher_id_,
               cs.teach_mode_,
               cssp.expect_price_
        FROM course_schedule cs
                 LEFT JOIN course_schedule_student_payment cssp ON cs.id_ = cssp.course_schedule_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          <if test="groupType != null">
          AND cs.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          </if>
          <if test="groupId != null">
          AND cs.music_group_id_ = #{groupId}
          </if>
          AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) > NOW()
          AND cssp.user_id_ = #{userId}
    </select>

    <select id="findUserCourseInfos" resultMap="StudentCourseInfoDto">
        SELECT
        cs.id_,
        cs.music_group_id_,
        cs.class_group_id_,
        cs.status_,
        cs.class_date_,
        cs.start_class_time_,
        cs.end_class_time_,
        cs.actual_teacher_id_,
        cs.teach_mode_,
        cssp.expect_price_
        FROM
        course_schedule cs
        LEFT JOIN course_schedule_student_payment cssp ON cs.id_ = cssp.course_schedule_id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND cs.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        AND cs.music_group_id_ = #{groupId}
        AND cssp.user_id_=#{userId}
        <if test="type=='history'">
            AND CONCAT( cs.class_date_, ' ', cs.end_class_time_ ) &lt;= NOW()
        </if>
        <if test="type=='surplus'">
            AND CONCAT( cs.class_date_, ' ', cs.start_class_time_ ) &gt; NOW()
        </if>
    </select>

    <select id="getMinCourseTime" resultType="java.util.Date">
        SELECT MIN(CONCAT(class_date_, ' ', start_class_time_))
        FROM course_schedule
        WHERE group_type_ = #{groupType}
          AND music_group_id_ = #{groupId}
    </select>
    <select id="getMaxCourseTime" resultType="java.util.Date">
        SELECT MAX(CONCAT(class_date_, ' ', end_class_time_))
        FROM course_schedule
        WHERE group_type_ = #{groupType}
          AND music_group_id_ = #{groupId}
    </select>
    <select id="findSurplusCourseWithGroup" resultMap="CourseSchedule">
        SELECT <include refid="resultSql"/>
        FROM course_schedule cs
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cs.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) > NOW()
          AND cs.music_group_id_ = #{groupId}
    </select>

    <select id="getSurplusCourseWithGroup" resultMap="CourseSchedule">
        SELECT <include refid="resultSql"/>
        FROM course_schedule cs
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) > NOW()
          AND cs.id_ = #{courseScheduleId}
    </select>
    <select id="countClassGroupOverCourseNum" resultType="int">
        SELECT COUNT(*)
        FROM course_schedule
        WHERE class_group_id_ = #{classGroupId}
          AND CONCAT(class_date_, ' ', end_class_time_) &lt; NOW()
    </select>

    <sql id="endFindCourseSchedulesCondition">
        <where>
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
            <include refid="queryVipCourseScheduleIds"/>
        </where>
    </sql>

    <select id="endFindCourseSchedules" resultMap="CourseScheduleEndDto">
        SELECT
            cs.id_,
            cs.group_type_,
            cs.music_group_id_,
            cs.class_group_id_,
            cs.status_,
            cs.name_,
            cs.class_date_,
            CONCAT(cs.class_date_,' ',cs.start_class_time_) course_start_time_,
            CONCAT(cs.class_date_,' ',cs.end_class_time_) course_end_time_,
            cs.actual_teacher_id_,
            cs.teach_mode_,
            cs.type_,
            cs.schoole_id_,
            cs.create_time_,
            s.name_ schoole_name_,
            o.name_ organ_name_,
            CASE WHEN COUNT(sa.id_) > 0 THEN 1 ELSE 0 END isCallNames
        FROM
            course_schedule cs
            LEFT JOIN school s ON cs.schoole_id_=s.id_
            LEFT JOIN organization o ON cs.organ_id_=o.id_
            LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cs.id_ AND sa.remark_ IS NULL
            <include refid="endFindCourseSchedulesCondition"/>
        GROUP BY cs.id_
        ORDER BY course_start_time_,cs.id_
        <include refid="global.limit"/>
    </select>

    <select id="endCountCourseSchedules" resultType="int">
        SELECT
        COUNT(DISTINCT cs.id_)
        FROM
        course_schedule cs
        LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cs.id_ AND sa.remark_ IS NULL
        <include refid="endFindCourseSchedulesCondition"/>
    </select>
    <select id="findCourseIdsByStudent" resultType="int">
        SELECT cssp.course_schedule_id_
        FROM course_schedule_student_payment cssp
        LEFT JOIN sys_user su ON cssp.user_id_ = su.id_
        WHERE su.username_ LIKE CONCAT('%', #{search}, '%')
           OR su.id_ = #{search}
    </select>
    <select id="findCourseIdsByTeacher" resultType="int">
        SELECT csts.course_schedule_id_
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN sys_user su ON csts.user_id_ = su.id_
        WHERE real_name_ LIKE CONCAT('%', #{search}, '%')
           OR su.id_ = #{search}
    </select>
    <select id="findClassGroupCourseSchedulesWithDate" resultMap="CourseSchedule">
        SELECT <include refid="resultSql"/>
        FROM course_schedule cs
        WHERE FIND_IN_SET(cs.class_group_id_, #{classGroupIds})
          AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
          AND cs.class_date_ &gt;= DATE_FORMAT(#{fromDate}, "%Y-%m-%d")
          AND (cs.del_flag_ IS NULL OR cs.del_flag_ = 0)
    </select>

    <select id="findGroupCourseStartTime" resultType="java.util.Date">
        SELECT MIN(CONCAT(class_date_, ' ', start_class_time_))
        FROM course_schedule
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND music_group_id_ = #{groupId}
    </select>

    <select id="findGroupCourseEndTime" resultType="java.util.Date">
        SELECT MAX(CONCAT(class_date_, ' ', end_class_time_))
        FROM course_schedule
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND music_group_id_ = #{groupId}
    </select>
    <select id="countGroupAllCourses" resultType="int">
        SELECT COUNT(*)
        FROM course_schedule
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND music_group_id_ = #{groupId}
    </select>
    <select id="queryMusicCourseScheduleIds" resultType="java.lang.Integer">
        SELECT cs.id_ FROM course_schedule cs
        LEFT JOIN music_group mg ON cs.music_group_id_ = mg.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cs.group_type_ = 'MUSIC' AND cs.del_flag_ = 0 AND cg.del_flag_ = 0
        <if test="search != null and search != ''">
            AND (mg.id_ = #{search} OR mg.name_ LIKE CONCAT('%',#{search},'%')
            OR cs.id_ = #{search} OR cs.name_ LIKE CONCAT('%',#{search},'%')
            OR cg.id_ = #{search} OR cg.name_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="organIdList != null and organIdList != ''">
            AND FIND_IN_SET(mg.organ_id_,#{organIdList})
        </if>
        <include refid="queryVipCourseScheduleIds"/>
    </select>
    <sql id="queryVipCourseScheduleIds">
        <if test="isCallNames != null and isCallNames == 1">
            AND sa.id_ IS NOT NULL
        </if>
        <if test="isCallNames != null and isCallNames == 0">
            AND sa.id_ IS NULL
        </if>
        <if test="startTime!=null">
            AND cs.class_date_ &gt;= DATE_FORMAT(#{startTime},"%Y-%m-%d")
        </if>
        <if test="endTime!=null">
            AND cs.class_date_ &lt;= DATE_FORMAT(#{endTime},"%Y-%m-%d")
        </if>
        <if test="courseStatus!=null">
            AND cs.status_ = #{courseStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="createStartDate!=null">
            AND date(cs.create_time_) &gt;= date(#{createStartDate})
        </if>
        <if test="createEndDate!=null">
            AND date(cs.create_time_) &lt;= date(#{createEndDate})
        </if>
        <if test="courseType!=null">
            AND cs.type_ = #{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="groupType!=null">
            AND cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="schoolId!=null">
            AND cs.schoole_id_ = #{schoolId}
        </if>
        <if test="teachMode!=null">
            AND cs.teach_mode_ = #{teachMode,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        <if test="teacherIdList != null">
            AND cs.actual_teacher_id_=#{teacherIdList}
        </if>
        <if test="organIdList!=null">
            AND FIND_IN_SET(cs.organ_id_,#{organIdList})
        </if>
        <if test="search!=null">
            AND (cs.music_group_id_=#{search} OR cs.id_=#{search} OR cs.name_ LIKE CONCAT( '%', #{search}, '%' ))
        </if>
    </sql>
    <select id="queryPracticeCourseScheduleIds" resultType="java.lang.Integer">
        SELECT cs.id_ FROM course_schedule cs
        LEFT JOIN practice_group pg ON cs.music_group_id_ = pg.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cs.group_type_ = 'PRACTICE' AND cs.del_flag_ = 0 AND cg.del_flag_ = 0
        AND pg.group_status_='NORMAL'
        <if test="search != null and search != ''">
            AND (pg.id_ = #{search} OR pg.name_ LIKE CONCAT('%',#{search},'%')
            OR cs.id_ = #{search} OR cs.name_ LIKE CONCAT('%',#{search},'%')
            OR cg.id_ = #{search} OR cg.name_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="organIdList != null and organIdList != ''">
            AND FIND_IN_SET(pg.organ_id_,#{organIdList})
        </if>
        <include refid="queryVipCourseScheduleIds"/>
    </select>
    <select id="queryVipCourseScheduleIds" resultType="java.lang.Integer">
        SELECT cs.id_ FROM course_schedule cs
        LEFT JOIN vip_group vg ON cs.music_group_id_ = vg.id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        WHERE cs.group_type_ = 'VIP' AND cs.del_flag_ = 0 AND cg.del_flag_ = 0
        <if test="search != null and search != ''">
            AND (vg.id_ = #{search} OR vg.name_ LIKE CONCAT('%',#{search},'%')
            OR cs.id_ = #{search} OR cs.name_ LIKE CONCAT('%',#{search},'%')
            OR cg.id_ = #{search} OR cg.name_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="organIdList != null and organIdList != ''">
            AND FIND_IN_SET(vg.organ_id_,#{organIdList})
        </if>
        <include refid="queryVipCourseScheduleIds"/>
    </select>
    <select id="findTeachersCoursesWithDateRange" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        csts.user_id_ actual_teacher_id_,
        cs.group_type_
        FROM
        course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
        WHERE
        (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
        AND cs.class_date_ BETWEEN DATE_FORMAT(#{startTime},"%Y-%m-%d") AND DATE_FORMAT(#{endTime},"%Y-%m-%d")
        AND csts.user_id_ IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
    </select>
    <select id="countTeacherPracticeCourse" resultType="int">
        SELECT COUNT(1)
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cs.group_type_ = 'PRACTICE'
          AND cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, "%Y-%m-%d") AND DATE_FORMAT(#{endTime}, "%Y-%m-%d")
          AND csts.user_id_ = #{userId}
    </select>
    <select id="findTeacherCoursesWithDateRange" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               csts.user_id_                                     actual_teacher_id_,
               cs.group_type_
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, "%Y-%m-%d") AND DATE_FORMAT(#{endTime}, "%Y-%m-%d")
          AND csts.user_id_ = #{userId}
    </select>

    <select id="findTeacherCoursesWithDateRangeWithoutMusicGroup" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               csts.user_id_                                     actual_teacher_id_,
               cs.group_type_
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cs.class_date_ BETWEEN DATE_FORMAT(#{startTime}, "%Y-%m-%d") AND DATE_FORMAT(#{endTime}, "%Y-%m-%d")
          AND csts.user_id_ = #{userId}
    </select>

    <select id="findStudentPracticeCourses" resultMap="courseScheduleDto">
        SELECT cs.id_                                            seal_class_id_,
               cs.type_,
               cs.id_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.actual_teacher_id_,
               cs.status_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.teach_mode_,
               cs.music_group_id_,
               cs.group_type_,
               su.real_name_                                     teacher_name_,
               pg.create_time_
        FROM course_schedule_student_payment cssp
                 LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
                 LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
                 LEFT JOIN practice_group pg ON pg.id_ = cssp.music_group_id_
        WHERE cs.group_type_ = 'PRACTICE'
          AND cssp.user_id_ = #{userId}
          AND cssp.expect_price_ = 0
          AND pg.type_ = 'FREE'
    </select>
    <select id="findTeacherCoursesWithIncludeDateRange" resultMap="CourseSchedule" useCache="false" flushCache="true">
        SELECT cs.id_,
               cs.class_group_id_,
               cs.group_type_,
               cs.music_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cg.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON csts.course_schedule_id_ = cs.id_
                 LEFT JOIN class_group cg ON cg.id_ = csts.class_group_id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND csts.user_id_ = #{userId}
          AND #{startTime} &lt; CONCAT(cs.class_date_, ' ', cs.end_class_time_)
          AND #{endTime} &gt; CONCAT(cs.class_date_, ' ', cs.start_class_time_)
    </select>
    <select id="findStudentCoursesWithIncludeDateRange" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.class_group_id_,
               cs.group_type_,
               cs.music_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.start_class_time_                              start_class_time_str_,
               cs.end_class_time_                                end_class_time_str_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule_student_payment cssp
                 LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
        WHERE (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL)
          AND cssp.user_id_ = #{userId}
          AND #{startTime} &lt; CONCAT(cs.class_date_, ' ', cs.end_class_time_)
          AND #{endTime} &gt; CONCAT(cs.class_date_, ' ', cs.start_class_time_);
    </select>
    <select id="queryStudentContinueCourse" resultMap="CourseSchedule">
        SELECT cs.*
        FROM course_schedule cs
        LEFT JOIN student_attendance sa ON cs.id_ = sa.course_schedule_id_
        WHERE TIMESTAMPDIFF(MINUTE, #{endDateTime}, CONCAT(cs.class_date_, ' ', cs.start_class_time_)) >= 0
          AND TIMESTAMPDIFF(MINUTE, #{endDateTime}, CONCAT(cs.class_date_, ' ', cs.start_class_time_)) &lt;= #{continueCourseTime}
          AND cs.teacher_id_ = #{courseSchedule.teacherId}
          AND cs.class_group_id_ = #{courseSchedule.classGroupId}
          AND (NOW() > CONCAT(cs.class_date_,' ', cs.start_class_time_) OR sa.sign_in_time_ IS NOT NULL)
        LIMIT 1
    </select>
    <select id="queryTeacherContinueCourse" resultMap="CourseSchedule">
        SELECT cs.*
        FROM course_schedule cs
        LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
        WHERE TIMESTAMPDIFF(MINUTE, #{endDateTime}, CONCAT(cs.class_date_, ' ', cs.start_class_time_)) >= 0
          AND TIMESTAMPDIFF(MINUTE, #{endDateTime}, CONCAT(cs.class_date_, ' ', cs.start_class_time_)) &lt;= #{continueCourseTime}
          AND cs.teacher_id_ = #{courseSchedule.teacherId}
          AND cs.class_group_id_ = #{courseSchedule.classGroupId}
          AND (NOW() > CONCAT(cs.class_date_,' ', cs.start_class_time_) OR ta.sign_in_time_ IS NOT NULL)
        LIMIT 1
    </select>
    <select id="getSingleClassMinutes" resultType="java.lang.Integer">
        SELECT FLOOR((UNIX_TIMESTAMP(CONCAT(cs.class_date_, ' ', cs.end_class_time_)) -
                      UNIX_TIMESTAMP(CONCAT(cs.class_date_, ' ', cs.start_class_time_))) / 60)
        FROM course_schedule cs
        WHERE cs.id_ = #{courseScheduleId}
    </select>
    <select id="countGroupOverCourse" resultType="java.util.Map">
        SELECT
        cs.music_group_id_ AS 'key',
        COUNT(cs.Id_) AS 'value'
        FROM
        course_schedule cs
        WHERE cs.status_='OVER'
        AND DATE_FORMAT(cs.class_date_,'%Y-%m')=DATE_FORMAT(NOW(),'%Y-%m')
        AND cs.group_type_ = #{groupType}
        AND cs.music_group_id_ IN
        <foreach collection="groupIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY cs.music_group_id_
    </select>
    <select id="countGroupFinishCourse" resultType="int">
        SELECT
            COUNT(cs.Id_)
        FROM
            course_schedule cs
        WHERE CONCAT(cs.class_date_, ' ', cs.start_class_time_) &lt; NOW()
            AND cs.group_type_ = #{groupType}
            AND cs.music_group_id_ = #{groupId}
    </select>
    <select id="findUserCourses" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.`type_`,
        cgtm.`user_id_` teacher_id_
        FROM
        `class_group_student_mapper` cgsm
        LEFT JOIN `class_group` cg ON cgsm.`class_group_id_` = cg.`id_`
        LEFT JOIN `class_group_teacher_mapper` cgtm ON cgtm.`class_group_id_` = cg.`id_`
        AND cgtm.`teacher_role_` = 'BISHOP'
        LEFT JOIN `course_schedule` cs ON cs.`class_group_id_` = cg.`id_`
        WHERE
        cgsm.user_id_=#{userId}
        AND cgtm.teacher_role_='BISHOP'
        AND cgsm.status_ = 'NORMAL'
        AND cg.`type_` IN ( 'NORMAL', 'HIGH', 'VIP' )
        AND cs.`id_` IS NOT NULL
        AND cgtm.user_id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
        AND ( cs.del_flag_ != 1 OR cs.del_flag_ IS NULL )
    </select>
    <select id="findUserCourses2" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.`type_`,
        cgtm.`user_id_` teacher_id_
        FROM
        `class_group_student_mapper` cgsm
        LEFT JOIN `class_group` cg ON cgsm.`class_group_id_` = cg.`id_`
        LEFT JOIN `class_group_teacher_mapper` cgtm ON cgtm.`class_group_id_` = cg.`id_`
        AND cgtm.`teacher_role_` = 'BISHOP'
        LEFT JOIN `course_schedule` cs ON cs.`class_group_id_` = cg.`id_`
        WHERE
        cgsm.user_id_=#{userId}
        AND cgtm.teacher_role_='BISHOP'
        AND cgsm.status_ = 'NORMAL'
        AND cg.`type_` IN ( 'PRACTICE', 'NORMAL', 'HIGH', 'VIP' )
        AND cs.`id_` IS NOT NULL
        AND cgtm.user_id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
        AND ( cs.del_flag_ != 1 OR cs.del_flag_ IS NULL )
    </select>
    <select id="findUserCourses3" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.group_type_,
        cgtm.`user_id_` teacher_id_
        FROM
        `class_group_student_mapper` cgsm
        LEFT JOIN `class_group` cg ON cgsm.`class_group_id_` = cg.`id_`
        LEFT JOIN `class_group_teacher_mapper` cgtm ON cgtm.`class_group_id_` = cg.`id_`
        AND cgtm.`teacher_role_` = 'BISHOP'
        LEFT JOIN `course_schedule` cs ON cs.`class_group_id_` = cg.`id_`
        WHERE
        cgtm.teacher_role_='BISHOP'
        AND cgsm.status_ = 'NORMAL'
        AND cg.group_type_ IN ( 'PRACTICE', 'MUSIC', 'VIP' )
        AND cs.`id_` IS NOT NULL
        AND cgtm.user_id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
        AND ( cs.del_flag_ != 1 OR cs.del_flag_ IS NULL )
    </select>
    <select id="findUserCoursesWithPay" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.`type_`,
        cgtm.`user_id_` teacher_id_
        FROM
        `class_group_student_mapper` cgsm
        LEFT JOIN `class_group` cg ON cgsm.`class_group_id_` = cg.`id_`
        LEFT JOIN `class_group_teacher_mapper` cgtm ON cgtm.`class_group_id_` = cg.`id_`
        AND cgtm.`teacher_role_` = 'BISHOP'
        LEFT JOIN `course_schedule` cs ON cs.`class_group_id_` = cg.`id_`
        WHERE
        cgsm.user_id_=#{userId}
        AND cgtm.teacher_role_='BISHOP'
        AND cgsm.status_ = 'NORMAL'
        AND cg.`type_` IN ( 'NORMAL', 'HIGH', 'VIP', 'PRACTICE')
        AND cs.`id_` IS NOT NULL
        AND cgtm.user_id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
        AND ( cs.del_flag_ != 1 OR cs.del_flag_ IS NULL )
    </select>

    <select id="queryTeacherName" resultType="java.util.Map">
        SELECT cs.id_ 'key',su.real_name_ 'value' FROM course_schedule cs
        LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
        WHERE cs.id_ IN
        <foreach collection="courseScheduleIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
    <select id="countCurrentCourseTime" resultType="java.lang.Integer">
        SELECT COUNT(1) + 1
        FROM course_schedule cs,
             (SELECT CONCAT(class_date_, " ", start_class_time_) class_date_, class_group_id_
              FROM course_schedule
              WHERE id_ = #{courseScheduleId}
                AND del_flag_ = 0) c
        WHERE cs.class_group_id_ = c.class_group_id_
          AND CONCAT(cs.class_date_, " ", cs.start_class_time_) &lt;= c.class_date_
          AND cs.del_flag_ = 0
    </select>
    <select id="findCourseSchedulesByClassGroups" resultMap="CourseSchedule">
        SELECT
        cs.id_,
        cs.group_type_,
        cs.music_group_id_,
        cs.class_group_id_,
        cs.status_,
        cs.subsidy_,
        cs.class_date_,
        CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
        CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
        cs.start_class_time_ start_class_time_str_,
        cs.end_class_time_ end_class_time_str_,
        cs.teacher_id_,
        cs.actual_teacher_id_,
        cs.create_time_,
        cs.update_time_,
        cs.teach_mode_,
        cs.type_,
        cs.name_,
        cs.student_num_,
        cs.leave_student_num_,
        cs.schoole_id_
        FROM
        course_schedule cs
        WHERE
        cs.class_group_id_ IN
        <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
            #{classGroupId}
        </foreach>
        AND ( cs.del_flag_ != 1 OR cs.del_flag_ IS NULL )
        ORDER BY start_class_time_
    </select>

    <select id="findFirstCourseWithGroup" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.group_type_,
               cs.music_group_id_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.schoole_id_
        FROM course_schedule cs
        WHERE cs.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND cs.music_group_id_ = #{groupId}
        ORDER BY CONCAT(cs.class_date_, ' ', cs.start_class_time_)
        LIMIT 1
    </select>

    <select id="findClassGroupLastTeacher" resultMap="CourseSchedule">
        SELECT *
        FROM course_schedule
        WHERE id_ IN (
        SELECT MAX(id_)
        FROM course_schedule
        WHERE class_group_id_ IN
        <foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
            #{classGroupId}
        </foreach>
        GROUP BY class_group_id_
        )
    </select>
    <select id="findGroupNotStartCourses" resultMap="CourseSchedule">
        SELECT id_,
               group_type_,
               music_group_id_,
               class_group_id_,
               status_,
               subsidy_,
               class_date_,
               CONCAT(class_date_, ' ', start_class_time_) start_class_time_,
               CONCAT(class_date_, ' ', end_class_time_)   end_class_time_,
               teacher_id_,
               actual_teacher_id_,
               create_time_,
               update_time_,
               teach_mode_,
               type_,
               name_,
               student_num_,
               leave_student_num_,
               schoole_id_
        FROM course_schedule
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND music_group_id_ = #{groupId}
          AND CONCAT(class_date_, ' ', start_class_time_) &gt; NOW()
    </select>

    <select id="findGroupNotFinishCourses" resultMap="CourseSchedule">
        SELECT id_,
               group_type_,
               music_group_id_,
               class_group_id_,
               status_,
               subsidy_,
               class_date_,
               CONCAT(class_date_, ' ', start_class_time_) start_class_time_,
               CONCAT(class_date_, ' ', end_class_time_)   end_class_time_,
               teacher_id_,
               actual_teacher_id_,
               create_time_,
               update_time_,
               teach_mode_,
               type_,
               name_,
               student_num_,
               leave_student_num_,
               schoole_id_
        FROM course_schedule
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND music_group_id_ = #{groupId}
          AND CONCAT(class_date_, ' ', start_class_time_) &gt; NOW()
    </select>
    <select id="getSubjectNameById" resultType="java.lang.String">
        SELECT GROUP_CONCAT(DISTINCT s.name_)
        FROM course_schedule cs
                 LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
                 LEFT JOIN `subject` s ON FIND_IN_SET(s.id_, cg.subject_id_list_)
        WHERE cs.id_ = #{courseScheduleId}
        GROUP BY cg.id_
    </select>
    <resultMap id="CourseScheduleRateDtoMap" type="com.ym.mec.biz.dal.dto.CourseScheduleRateDto">
        <result property="teachingContent" column=""/>
        <result property="classDate" column="class_date_"/>
        <result property="startClassTime" column="start_class_time_"/>
        <result property="comment" column="comment_"/>
        <result property="endClassTime" column="end_class_time_"/>
        <result property="courseStatus" column="status_"/>
        <result property="courseScheduleId" column="id_"/>
    </resultMap>
    <select id="findCourseRate" resultMap="CourseScheduleRateDtoMap">
        SELECT cs.class_date_,
        cs.start_class_time_,
        cs.end_class_time_,
        cs.id_,
        cs.teaching_content_,
        GROUP_CONCAT(cse.comment_ SEPARATOR ";") comment_,
        cs.status_
        FROM course_schedule cs
        LEFT JOIN course_schedule_evaluate cse ON cs.id_ = cse.course_schedule_id_
        WHERE cs.group_type_ = #{groupType}
        <if test="groupId != null">
            AND cs.music_group_id_ = #{groupId}
        </if>
        <if test="classGroupId != null">
            AND cs.class_group_id_ = #{classGroupId}
        </if>
        GROUP BY cs.id_
        ORDER BY cs.class_date_, cs.start_class_time_ ASC
    </select>
    <select id="getLastEndCourse" resultMap="CourseSchedule">
        SELECT cs.id_
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{groupId}
          AND cs.group_type_ = #{groupType}
          AND NOW() > CONCAT(cs.class_date_, ' ', cs.end_class_time_)
        ORDER BY cs.class_date_, cs.end_class_time_ ASC
        LIMIT 1
    </select>

    <resultMap id="GroupCourseTimesDto" type="com.ym.mec.biz.dal.dto.GroupCourseTimesDto">
        <result property="groupId" column="group_id_"/>
        <result property="groupType" column="group_type_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="classGroupId" column="class_group_id_"/>
        <result property="totalCourseTimes" column="total_course_times_"/>
        <result property="surplusClassTimes" column="surplus_class_times_"/>
        <result property="startDate" column="start_date_"/>
        <result property="endDate" column="end_date_"/>
    </resultMap>

    <select id="findGroupsCourseTimesInfo" resultMap="GroupCourseTimesDto">
        SELECT
        cg.music_group_id_ group_id_,
        cg.group_type_,
        cg.id_ class_group_id_,
        cg.total_class_times_ total_course_times_,
        COUNT( cs.id_ ) surplus_class_times_,
        MIN( CONCAT( class_date_, ' ', start_class_time_ ) ) start_date_,
        MAX( CONCAT( class_date_, ' ', end_class_time_ ) ) end_date_
        FROM
        class_group cg
        LEFT JOIN course_schedule cs ON cs.class_group_id_ = cg.id_ AND CONCAT( cs.class_date_, ' ',
        cs.start_class_time_ ) > NOW( )
        WHERE
        cg.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        AND cg.music_group_id_ IN
        <foreach collection="groupIds" item="groupId" separator="," open="(" close=")">
            #{groupId}
        </foreach>
        GROUP BY
        cg.id_
    </select>

    <select id="findGroupsValidate" resultType="com.ym.mec.biz.dal.dto.GroupValidDateDto">
        SELECT
        cs.music_group_id_ groupId,
        MIN( CONCAT( class_date_, ' ', start_class_time_ ) ) startDate,
        MAX( CONCAT( class_date_, ' ', end_class_time_ ) ) endDate
        FROM
        course_schedule cs
        WHERE
        cs.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        AND cs.music_group_id_ IN
        <foreach collection="groupIds" item="groupId" separator="," open="(" close=")">
            #{groupId}
        </foreach>
        GROUP BY
        cs.music_group_id_
    </select>
    <select id="findCourseByGroupId" resultMap="CourseSchedule">
        SELECT *
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{groupId}
          AND cs.group_type_ = #{groupType}
          AND cs.del_flag_ = 0
    </select>
    <select id="queryScheduleByAttendance" resultMap="CourseSchedule">
        SELECT cs.*
        FROM teacher_attendance ta
                 LEFT JOIN course_schedule cs ON ta.course_schedule_id_ = cs.id_
                 LEFT JOIN student_attendance sa ON ta.course_schedule_id_ = sa.course_schedule_id_
        WHERE ta.sign_out_status_ = 1
          AND ta.sign_in_time_ IS NOT NULL
          AND MONTH(ta.sign_in_time_) = #{month}
          AND cs.teach_mode_ = 'ONLINE'
          AND ta.teacher_id_ = cs.actual_teacher_id_
        GROUP BY ta.course_schedule_id_
        HAVING COUNT(sa.id_) > 0
    </select>

    <update id="updateCourseNameByGroup">
        UPDATE course_schedule
        SET name_=#{name}
        WHERE group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
          AND music_group_id_ = #{groupId}
    </update>
    <update id="resetStudentNum">
        UPDATE course_schedule cs SET cs.student_num_ = 0 WHERE cs.id_ IN
        <foreach collection="courseScheduleId" separator="," open="(" close=")" item="id">
            #{id}
        </foreach>
    </update>

    <select id="getStudentCourseScheduleNum" resultMap="com.ym.mec.biz.dal.dao.PracticeGroupDao.courseGroupExport">
        SELECT COUNT(*) total_class_times_,cssp.user_id_ student_id_
        FROM course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs on cs.id_ = cssp.course_schedule_id_
        WHERE cssp.user_id_ IN
        <foreach collection="studentIds" separator="," open="(" close=")" item="studentId">
            #{studentId}
        </foreach>
        AND cssp.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        <if test="status != null">
            AND cs.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        </if>
        AND (cs.is_lock_ IS NULL OR cs.is_lock_ =0)
        AND (cs.del_flag_ IS NULL OR cs.del_flag_ =0)
        GROUP BY cssp.user_id_
    </select>

    <select id="getVipGroupExport" resultMap="com.ym.mec.biz.dal.dao.PracticeGroupDao.courseGroupExport">
        SELECT cssp.user_id_ student_id_,
            su.username_ student_name_,
            o.name_ organ_name_,
            GROUP_CONCAT(DISTINCT edut.`real_name_`) edu_teacher_name_,
            GROUP_CONCAT(DISTINCT edut.`id_`) edu_teacher_ids_
        FROM `course_schedule_student_payment` cssp
            LEFT JOIN `vip_group` vg ON vg.`id_` = cssp.`music_group_id_` AND cssp.`group_type_` = 'VIP'
            LEFT JOIN `organization` o ON o.`id_` = vg.`organ_id_`
            LEFT JOIN `sys_user` su ON su.`id_` = cssp.`user_id_`
            LEFT JOIN `sys_user` edut ON edut.`id_` = vg.`educational_teacher_id_`
        WHERE cssp.`group_type_` = 'VIP'
        AND vg.group_status_!=3
        <if test="organIds != null and organIds != ''">
            AND FIND_IN_SET(vg.organ_id_, #{organIds})
        </if>
        GROUP BY cssp.`user_id_`,o.id_
    </select>

    <select id="getStudentCourseInfo" resultMap="com.ym.mec.biz.dal.dao.PracticeGroupDao.courseGroupExport">
        SELECT MIN(concat(cs.`class_date_`,' ',cs.`start_class_time_` )) class_start_date_,
        MAX(concat(cs.`class_date_`,' ',cs.`start_class_time_` )) class_end_date_,cssp.user_id_ student_id_,
        GROUP_CONCAT(DISTINCT su.`real_name_`) teacher_name_,GROUP_CONCAT(DISTINCT cs.`actual_teacher_id_`) teacher_ids_
        FROM course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs on cs.id_ = cssp.course_schedule_id_
        LEFT JOIN sys_user su on cs.actual_teacher_id_ = su.id_
        WHERE cssp.user_id_ IN
        <foreach collection="studentIds" separator="," open="(" close=")" item="studentId">
            #{studentId}
        </foreach>
        AND cssp.group_type_ = #{groupType}
        AND (cs.is_lock_ IS NULL OR cs.is_lock_ =0)
        AND (cs.del_flag_ IS NULL OR cs.del_flag_ =0)
        GROUP BY cssp.user_id_;
    </select>

    <select id="getStudentVipCourseInfo" resultMap="com.ym.mec.biz.dal.dao.PracticeGroupDao.courseGroupExport">
        SELECT MIN(concat(cs.`class_date_`,' ',cs.`start_class_time_` )) class_start_date_,
        MAX(concat(cs.`class_date_`,' ',cs.`start_class_time_` )) class_end_date_,cssp.user_id_ student_id_,
        GROUP_CONCAT(DISTINCT su.`real_name_`) teacher_name_,GROUP_CONCAT(DISTINCT cs.`actual_teacher_id_`) teacher_ids_
        FROM course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs on cs.id_ = cssp.course_schedule_id_
        LEFT JOIN sys_user su on cs.actual_teacher_id_ = su.id_
        LEFT JOIN vip_group vg ON cssp.music_group_id_=vg.id_
        WHERE cssp.user_id_ IN
        <foreach collection="studentIds" separator="," open="(" close=")" item="studentId">
            #{studentId}
        </foreach>
        AND cssp.group_type_ = 'VIP'
        AND vg.group_status_!=3
        AND (cs.is_lock_ IS NULL OR cs.is_lock_ =0)
        AND (cs.del_flag_ IS NULL OR cs.del_flag_ =0)
        GROUP BY cssp.user_id_;
    </select>

    <select id="getLastCourse" resultMap="CourseSchedule">
        SELECT cs.* FROM course_schedule cs
        WHERE cs.class_group_id_ = #{classGroupId}
        AND TIMESTAMPDIFF(MINUTE, CONCAT(cs.class_date_," ",cs.end_class_time_),#{startTime}) &lt;= #{continueCourseTime}
        AND TIMESTAMPDIFF(MINUTE, CONCAT(cs.class_date_," ",cs.end_class_time_),#{startTime}) >= 0
        AND cs.actual_teacher_id_ = #{teacherId}
        ORDER BY cs.class_date_ DESC,cs.end_class_time_ DESC
        LIMIT 1
    </select>
    <select id="findLastOverTime" resultType="java.util.Map">
        SELECT cs.music_group_id_ 'key',MAX(CONCAT(cs.class_date_,' ',cs.start_class_time_)) 'value'
        FROM course_schedule cs
        WHERE cs.status_ = 'OVER' AND cs.group_type_ = 'VIP' AND cs.music_group_id_ IN
        <foreach collection="vipGroupIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        GROUP BY cs.music_group_id_
    </select>
    <select id="findNotStartCourseByIds" resultType="java.lang.Long">
        SELECT cs.id_ FROM course_schedule cs WHERE cs.id_ IN
        <foreach collection="courseScheduleIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        AND cs.status_ = 'NOT_START'
    </select>
    <select id="getLastTime" resultType="java.util.Date">
        SELECT MAX(CONCAT(cs.class_date_," ",cs.end_class_time_))
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{practiceGroupId} AND cs.del_flag_ = 0 AND cs.group_type_ = #{groupType};
    </select>
    <select id="getFirstTime" resultType="java.util.Date">
        SELECT MIN(CONCAT(cs.class_date_," ",cs.end_class_time_))
        FROM course_schedule cs
        WHERE cs.music_group_id_ = #{practiceGroupId} AND cs.del_flag_ = 0 AND cs.group_type_ = #{groupType};
    </select>
    <select id="countStudentVipCoursesWithDate" resultType="map">
        SELECT
        cssp.user_id_ as 'key',
        COUNT( cs.id_ ) as 'value'
        FROM
        course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
        WHERE
        cssp.user_id_ IN
        <foreach collection="studentIds" item="studentId" separator="," open="(" close=")">
            #{studentId}
        </foreach>
        AND cssp.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
        AND cs.class_date_ BETWEEN #{startTime} AND #{endTime}
        GROUP BY
        cssp.user_id_
    </select>
    <select id="countStudentPayPracticeCoursesWithDate" resultType="map">
        SELECT
        cssp.user_id_ as 'key',
        COUNT( cs.id_ ) as 'value'
        FROM
        course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
        LEFT JOIN practice_group pg ON pg.id_=cssp.music_group_id_
        WHERE
        cssp.user_id_ IN
        <foreach collection="studentIds" item="studentId" separator="," open="(" close=")">
            #{studentId}
        </foreach>
        AND cssp.group_type_ = 'PRACTICE'
        AND pg.type_='CHARGE'
        AND cs.class_date_ BETWEEN #{startTime} AND #{endTime}
        GROUP BY
        cssp.user_id_
    </select>

    <select id="countStudentVipCoursesInFuture" resultType="map">
        SELECT
        cssp.user_id_ as 'key',
        COUNT( cs.id_ ) as 'value'
        FROM
        course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
        WHERE
        cssp.user_id_ IN
        <foreach collection="studentIds" item="studentId" separator="," open="(" close=")">
            #{studentId}
        </foreach>
        AND cssp.group_type_ = 'VIP'
        AND CONCAT(cs.class_date_," ",cs.start_class_time_) &gt; NOW()
        GROUP BY
        cssp.user_id_
    </select>
    <select id="queryNoStartCourseByTeacherId" resultMap="CourseSchedule">
        SELECT cs.id_,
               cs.music_group_id_,
               cs.group_type_,
               cs.class_group_id_,
               cs.status_,
               cs.subsidy_,
               cs.class_date_,
               CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
               CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
               cs.teacher_id_,
               cs.actual_teacher_id_,
               cs.create_time_,
               cs.update_time_,
               cs.teach_mode_,
               cs.type_,
               cs.name_,
               cs.student_num_,
               cs.leave_student_num_,
               cs.teaching_content_,
               cs.note_,
               cs.schoole_id_,
               cs.organ_id_ FROM course_schedule cs
        LEFT JOIN course_schedule_teacher_salary csts ON csts.course_schedule_id_ = cs.id_
        WHERE FIND_IN_SET(cs.class_group_id_,#{classGroupIds}) AND csts.teacher_role_ = #{teacherRole}
        AND csts.user_id_ = #{teacherId} AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW() AND cs.del_flag_ = 0
    </select>
    <select id="queryHasReatClass" resultType="java.util.Map">
        SELECT cgtm.class_group_id_ 'key',CASE WHEN COUNT(cs.id_) > 0 THEN 1 ELSE 0 END 'value'
        FROM class_group_teacher_mapper cgtm
        LEFT JOIN course_schedule cs ON cs.class_group_id_ = cgtm.class_group_id_
        AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW() AND cs.del_flag_ = 0
        WHERE cgtm.user_id_ = #{teacherId} AND cgtm.group_type_ = 'MUSIC' AND cgtm.class_group_id_ IN
        <foreach collection="classGroupIds" item="classGroupId" separator="," open="(" close=")">
            #{classGroupId}
        </foreach>
        GROUP BY cgtm.class_group_id_
    </select>

    <select id="getTeacherPrevCourseWithStartTime" resultMap="CourseSchedule">
        SELECT  cs.id_,
                cs.music_group_id_,
                cs.group_type_,
                cs.class_group_id_,
                cs.status_,
                cs.subsidy_,
                cs.class_date_,
                CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
                CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
                cs.teacher_id_,
                cs.actual_teacher_id_,
                cs.create_time_,
                cs.update_time_,
                cs.teach_mode_,
                cs.type_,
                cs.name_,
                cs.student_num_,
                cs.leave_student_num_,
                cs.teaching_content_,
                cs.note_,
                cs.schoole_id_,
                cs.organ_id_
        FROM course_schedule cs LEFT JOIN course_schedule_teacher_salary csts ON csts.course_schedule_id_=cs.id_
        WHERE csts.user_id_=#{teacherId}
        AND cs.class_date_ = DATE_FORMAT(#{startClassTime},'%Y-%m-%d')
        AND cs.start_class_time_ &lt; DATE_FORMAT(#{startClassTime},'%H:%i:%S')
        ORDER BY start_class_time_ DESC LIMIT 1;
    </select>

    <select id="getTeacherAttendanceCourseBeforeStartTime" resultMap="CourseSchedule">
        SELECT  cs.id_,
                cs.music_group_id_,
                cs.group_type_,
                cs.class_group_id_,
                cs.status_,
                cs.subsidy_,
                cs.class_date_,
                CONCAT(cs.class_date_, ' ', cs.start_class_time_) start_class_time_,
                CONCAT(cs.class_date_, ' ', cs.end_class_time_)   end_class_time_,
                cs.teacher_id_,
                cs.actual_teacher_id_,
                cs.create_time_,
                cs.update_time_,
                cs.teach_mode_,
                cs.type_,
                cs.name_,
                cs.student_num_,
                cs.leave_student_num_,
                cs.teaching_content_,
                cs.note_,
                cs.schoole_id_,
                cs.organ_id_
        FROM course_schedule cs
            LEFT JOIN course_schedule_teacher_salary csts ON csts.course_schedule_id_=cs.id_
            LEFT JOIN teacher_attendance ta ON cs.id_=ta.course_schedule_id_ AND ta.teacher_id_=#{teacherId}
        WHERE csts.user_id_=#{teacherId}
        AND cs.class_date_ = DATE_FORMAT(#{startClassTime},'%Y-%m-%d')
        AND cs.start_class_time_ &lt; DATE_FORMAT(#{startClassTime},'%H:%i:%S')
        AND ta.sign_in_status_ IS NOT NULL
        ORDER BY start_class_time_ DESC LIMIT 1;
    </select>

    <select id="queryRemainCourseTypeDuration" resultMap="RemainCourseTypeDurationDto">
        SELECT cs.type_ course_type_,SUM(TIMESTAMPDIFF(MINUTE,STR_TO_DATE(concat(cs.class_date_,' ',cs.start_class_time_),'%Y-%m-%d %H:%i:%s'),
        STR_TO_DATE(concat(cs.class_date_,' ',cs.end_class_time_),'%Y-%m-%d %H:%i:%s'))) remain_minutes_
		from course_schedule cs where FIND_IN_SET(cs.class_group_id_,#{classgroupId}) and cs.status_ = 'NOT_START' group by cs.type_
    </select>

</mapper>
