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

    <resultMap type="com.ym.mec.biz.dal.entity.Teacher" id="Teacher">
        <result column="id_" property="id"/>
        <result column="organ_id_" property="organId"/>
        <result column="teacher_organ_id_" property="teacherOrganId"/>
        <result column="organ_name_" property="organName"/>
        <result column="job_type_" property="jobType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="job_nature_" property="jobNature" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="is_probation_period_" property="isProbationPeriod"
                typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="education_background_" property="educationBackground"/>
        <result column="graduate_school_" property="graduateSchool"/>
        <result column="technical_titles_" property="technicalTitles"/>
        <result column="work_unit_" property="workUnit"/>
        <result column="subject_id_" property="subjectId"/>
        <result column="entry_date_" property="entryDate"/>
        <result column="demission_date_" property="demissionDate"/>
        <result column="formal_staff_date_" property="formalStaffDate"/>
        <result column="certificate_type_" property="certificateType"/>
        <result column="certificate_num_" property="certificateNum"/>
        <result column="flow_organ_range_" property="flowOrganRange"/>
        <result column="introduction_" property="introduction"/>
        <result column="is_support_extra_practice_lesson_" property="isSupportExtraPracticeLesson"/>
        <result column="is_support_course_schedule_rewards_rules_" property="isSupportCourseScheduleRewardsRules"/>
        <result column="idcard_front_img_" property="idcardFrontImg"/>
        <result column="idcard_back_img_" property="idcardBackImg"/>
        <result column="idcard_hand_img_" property="idcardHandImg"/>
        <result column="update_time_" property="updateTime"/>
        <result column="create_time_" property="createTime"/>
        <result column="memo_" property="memo"/>
        <result column="lecture_num_" property="lectureNum"/>

        <result column="username_" property="username"/>
        <result column="password_" property="password"/>
        <result column="real_name_" property="realName"/>
        <result column="salt_" property="salt"/>
        <result column="phone_" property="phone"/>
        <result column="avatar_" property="avatar"/>
        <result column="lock_flag_" property="lockFlag"/>
        <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="wx_openid_" property="wxOpenid"/>
        <result column="qq_openid_" property="qqOpenid"/>
        <result column="user_type_" property="userType"/>
        <result column="gender_" property="gender"/>
        <result column="nation_" property="nation"/>
        <result column="birthdate_" property="birthdate"/>
        <result column="email_" property="email"/>
        <result column="im_token_" property="imToken"/>
        <result column="subject_name_" property="splitSubjectName"/>
        <result column="id_card_no_" property="idCardNo"/>
        <result column="is_settlement_salary_" property="isSettlementSalary"/>
    </resultMap>
    
    <resultMap type="com.ym.mec.biz.dal.dto.TeacherDefaultSalaryDto" id="TeacherDefaultSalaryDto">
        <result column="id_" property="userId"/>
        <result column="real_name_" property="realName"/>
        <result column="name_" property="organName"/>
        <result column="job_nature" property="jobNature"/>
        <result column="demisson_status" property="demissionStatus" />
        <result column="status_" property="status"/>
        <result column="vip1" property="vip1"/>
        <result column="vip2" property="vip2"/>
        <result column="vip3" property="vip3"/>
        <result column="vip4" property="vip4"/>
        <result column="vip5" property="vip5"/>
        <result column="vip6" property="vip6"/>
        <result column="vip7" property="vip7"/>
        <result column="practice" property="practiceSalary"/>

        <result column="main_single2" property="mainSingleSalary2"/>
        <result column="main_mix2" property="mainMixSalary2"/>
        <result column="main_comprehensive2" property="mainComprehensiveSalary2"/>
        <result column="main_training_single2" property="mainTraningSigleSalary2"/>
        <result column="main_training_mix2" property="mainTraningMixSalary2"/>
        <result column="main_high2" property="mainHighSalary2"/>
        <result column="main_classroom2" property="mainClassroomSalary2"/>
        <result column="main_single" property="mainSingleSalary"/>
        <result column="main_mix" property="mainMixSalary"/>
        <result column="main_comprehensive" property="mainComprehensiveSalary"/>
        <result column="main_training_single" property="mainTraningSigleSalary"/>
        <result column="main_training_mix" property="mainTraningMixSalary"/>
        <result column="main_high" property="mainHighSalary"/>
        <result column="main_classroom" property="mainClassroomSalary"/>

        <result column="high_online3" property="highOnline3Salary"/>
        <result column="high_online4" property="highOnline4Salary"/>
        <result column="high_online5" property="highOnline5Salary"/>
        <result column="music_network1" property="musicNetwork1Salary"/>

        <result column="assistant_single2" property="assistantSingleSalary2"/>
        <result column="assistant_mix2" property="assistantMixSalary2"/>
        <result column="assistant_comprehensive2" property="assistantComprehensiveSalary2"/>
        <result column="assistant_training_single2" property="assistantTraningSigleSalary2"/>
        <result column="assistant_training_mix2" property="assistantTraningMixSalary2"/>
        <result column="assistant_high2" property="assistantHighSalary2"/>
        <result column="assistant_classroom2" property="assistantClassroomSalary2"/>
        <result column="assistant_single" property="assistantSingleSalary"/>
        <result column="assistant_mix" property="assistantMixSalary"/>
        <result column="assistant_comprehensive" property="assistantComprehensiveSalary"/>
        <result column="assistant_training_single" property="assistantTraningSigleSalary"/>
        <result column="assistant_training_mix" property="assistantTraningMixSalary"/>
        <result column="assistant_high" property="assistantHighSalary"/>
        <result column="assistant_classroom" property="assistantClassroomSalary"/>
    </resultMap>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="Teacher">
        SELECT t.id_,t.organ_id_ teacher_organ_id_,t.job_type_,t.job_nature_,t.is_probation_period_,t.education_background_,t.graduate_school_,t.graduate_school_,
        t.technical_titles_,t.work_unit_,t.subject_id_,t.entry_date_,t.certificate_type_,t.certificate_num_,t.flow_organ_range_,t.update_time_,
        t.create_time_,t.introduction_,t.demission_date_,t.formal_staff_date_,t.is_support_course_schedule_rewards_rules_,t.is_support_extra_practice_lesson_,
        t.lecture_num_,t.idcard_front_img_,t.idcard_back_img_,t.idcard_hand_img_,t.memo_,
        su.real_name_,su.id_card_no_,su.password_,su.salt_,su.phone_,su.avatar_,
        su.lock_flag_,su.del_flag_,su.wx_openid_,su.qq_openid_,su.user_type_,
        su.gender_,su.nation_,su.birthdate_,su.email_,su.im_token_,su.username_,su.organ_id_,
        t.is_settlement_salary_
        FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE t.id_ = #{id} AND su.del_flag_ = 0
    </select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="Teacher">
        SELECT *
        FROM teacher
        ORDER BY id_
    </select>
    
    <select id="getLocked" resultMap="Teacher">
        SELECT * FROM teacher where id_ = #{id} for update
    </select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Teacher" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        INSERT INTO teacher
        (id_,organ_id_,job_type_,job_nature_,is_probation_period_,education_background_,graduate_school_,technical_titles_,work_unit_,subject_id_,entry_date_,demission_date_,formal_staff_date_,certificate_type_,certificate_num_,flow_organ_range_,introduction_,update_time_,create_time_,is_support_course_schedule_rewards_rules_,idcard_front_img_,idcard_back_img_,idcard_hand_img_,memo_,is_settlement_salary_)
        VALUES(#{id},#{organId},#{jobType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{jobNature},#{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{educationBackground},#{graduateSchool},#{technicalTitles},#{workUnit},#{subjectId},#{entryDate},#{demissionDate},#{formalStaffDate},#{certificateType},#{certificateNum},#{flowOrganRange},#{introduction},now(),now(),#{isSupportCourseScheduleRewardsRules},#{idcardFrontImg},#{idcardBackImg},#{idcardHandImg},#{memo},#{isSettlementSalary})
    </insert>

    <insert id="addSysUser" parameterType="com.ym.mec.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        INSERT INTO sys_user
        (im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,password_)
        VALUES(#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
        #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{password})
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.Teacher">
        UPDATE teacher
        <set>
            <if test="lectureNum != null">
                lecture_num_ = #{lectureNum},
            </if>
            <if test="graduateSchool != null">
                graduate_school_ = #{graduateSchool},
            </if>
            <if test="subjectId != null">
                subject_id_ = #{subjectId},
            </if>
            <if test="organId != null">
                organ_id_ = #{organId},
            </if>
            <if test="technicalTitles != null">
                technical_titles_ = #{technicalTitles},
            </if>
            <if test="entryDate != null">
                entry_date_ = #{entryDate},
            </if>
            <if test="jobType != null">
                job_type_ = #{jobType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="flowOrganRange != null">
                flow_organ_range_ = #{flowOrganRange},
            </if>
            <if test="certificateType != null">
                certificate_type_ = #{certificateType},
            </if>
            <if test="jobNature != null">
                job_nature_ = #{jobNature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="isProbationPeriod != null">
                is_probation_period_ = #{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="updateTime != null">
                update_time_ = NOW(),
            </if>
            <if test="educationBackground != null">
                education_background_ = #{educationBackground},
            </if>
            <if test="certificateNum != null">
                certificate_num_ = #{certificateNum},
            </if>
            <if test="workUnit != null">
                work_unit_ = #{workUnit},
            </if>
            <if test="introduction != null">
                introduction_ = #{introduction},
            </if>
            <if test="isSupportCourseScheduleRewardsRules != null">
                is_support_course_schedule_rewards_rules_ = #{isSupportCourseScheduleRewardsRules},
            </if>
            <if test="isSupportExtraPracticeLesson != null">
                is_support_extra_practice_lesson_ = #{isSupportExtraPracticeLesson},
            </if>
            <if test="idcardFrontImg != null">
                idcard_front_img_ = #{idcardFrontImg},
            </if>
            <if test="idcardBackImg != null">
                idcard_back_img_ = #{idcardBackImg},
            </if>
            <if test="idcardHandImg != null">
                idcard_hand_img_ = #{idcardHandImg},
            </if>
            <if test="isSettlementSalary != null">
                is_settlement_salary_ = #{isSettlementSalary},
            </if>
        </set>
        WHERE id_ = #{id}
    </update>

    <!-- 根据主键查询一条记录 -->
    <update id="eduUpdateTeacher" parameterType="com.ym.mec.biz.dal.entity.Teacher">
        UPDATE teacher
        <set>
            <if test="lectureNum != null">
                lecture_num_ = #{lectureNum},
            </if>
                memo_ = #{memo},
            <if test="graduateSchool != null">
                graduate_school_ = #{graduateSchool},
            </if>
            <if test="subjectId != null">
                subject_id_ = #{subjectId},
            </if>
            <if test="organId != null">
                organ_id_ = #{organId},
            </if>
            <if test="technicalTitles != null">
                technical_titles_ = #{technicalTitles},
            </if>
            <if test="entryDate != null">
                entry_date_ = #{entryDate},
            </if>
                demission_date_ = #{demissionDate},
                formal_staff_date_ = #{formalStaffDate},
            <if test="jobType != null">
                job_type_ = #{jobType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="flowOrganRange != null">
                flow_organ_range_ = #{flowOrganRange},
            </if>
            <if test="certificateType != null">
                certificate_type_ = #{certificateType},
            </if>
            <if test="jobNature != null">
                job_nature_ = #{jobNature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="isProbationPeriod != null">
                is_probation_period_ = #{isProbationPeriod,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="updateTime != null">
                update_time_ = NOW(),
            </if>
            <if test="educationBackground != null">
                education_background_ = #{educationBackground},
            </if>
            <if test="certificateNum != null">
                certificate_num_ = #{certificateNum},
            </if>
            <if test="workUnit != null">
                work_unit_ = #{workUnit},
            </if>
            <if test="introduction != null">
                introduction_ = #{introduction},
            </if>
            <if test="isSupportCourseScheduleRewardsRules != null">
                is_support_course_schedule_rewards_rules_ = #{isSupportCourseScheduleRewardsRules},
            </if>
            <if test="isSupportExtraPracticeLesson != null">
                is_support_extra_practice_lesson_ = #{isSupportExtraPracticeLesson},
            </if>
            <if test="idcardFrontImg != null">
                idcard_front_img_ = #{idcardFrontImg},
            </if>
            <if test="idcardBackImg != null">
                idcard_back_img_ = #{idcardBackImg},
            </if>
            <if test="idcardHandImg != null">
                idcard_hand_img_ = #{idcardHandImg},
            </if>
            <if test="isSettlementSalary != null">
                is_settlement_salary_ = #{isSettlementSalary},
            </if>
        </set>
        WHERE id_ = #{id}
    </update>

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

    <update id="updateUser" parameterType="com.ym.mec.auth.api.entity.SysUser">
        UPDATE sys_user
        <set>
            <if test="delFlag != null">
                del_flag_ = #{delFlag, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="wxOpenid != null">
                wx_openid_ = #{wxOpenid},
            </if>
            <if test="password != null">
                password_ = #{password},
            </if>
            <if test="avatar != null">
                avatar_ = #{avatar},
            </if>
            <if test="email != null">
                email_ = #{email},
            </if>
            <if test="gender != null">
                gender_ = #{gender},
            </if>
            <if test="salt != null">
                salt_ = #{salt},
            </if>
            <if test="username != null">
                username_ = #{username},
            </if>
            <if test="realName != null">
                real_name_ = #{realName},
            </if>
            <if test="userType != null">
                user_type_ = #{userType},
            </if>
            <if test="updateTime != null">
                update_time_ = NOW(),
            </if>
            <if test="lockFlag != null">
                lock_flag_ = #{lockFlag},
            </if>
            <if test="birthdate != null">
                birthdate_ = #{birthdate},
            </if>
            <if test="phone != null">
                phone_ = #{phone},
            </if>
            <if test="qqOpenid != null">
                qq_openid_ = #{qqOpenid},
            </if>
            <if test="nation != null">
                nation_ = #{nation},
            </if>
            <if test="organId != null">
                organ_id_ = #{organId},
            </if>
            <if test="imToken != null">
                im_token_ = #{imToken},
            </if>
        </set>
        WHERE id_ = #{id}
    </update>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="Teacher" parameterType="map">
        SELECT t.id_,su.real_name_,su.lock_flag_,t.subject_id_,su.phone_,t.organ_id_ teacher_organ_id_,t.organ_id_,t.is_support_extra_practice_lesson_,
        t.job_nature_,t.demission_date_,t.formal_staff_date_,t.is_probation_period_,t.memo_,GROUP_CONCAT(s.name_) subject_name_,su.del_flag_,t.is_settlement_salary_
        FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,t.subject_id_)
        <include refid="queryPageMap"/>
        GROUP BY t.id_
        ORDER BY t.id_ DESC
        <include refid="global.limit"/>
    </select>
    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
        SELECT COUNT(DISTINCT t.id_)
        FROM teacher t LEFT JOIN sys_user su ON t.id_ = su.id_
        <include refid="queryPageMap"/>
    </select>

    <sql id="queryPageMap">
        <where>
            su.del_flag_ = 0
            <if test="organId != null and organId != ''">
               AND (CONCAT(',',t.organ_id_,',',IFNULL(t.flow_organ_range_,''),',') REGEXP CONCAT(',(',replace(#{organId},',','|'),'),'))
            </if>
            <if test="subjectId != null">
                AND FIND_IN_SET(#{subjectId},t.subject_id_)
            </if>
            <if test="jobNature != null">
                AND t.job_nature_ = #{jobNature}
            </if>
            <if test="isProbationPeriod != null">
                AND t.is_probation_period_ = #{isProbationPeriod}
            </if>
            <if test="isSupportExtraPracticeLesson != null">
                AND t.is_support_extra_practice_lesson_ = #{isSupportExtraPracticeLesson}
            </if>
            <if test="lockFlag != null">
                AND su.lock_flag_ = #{lockFlag}
            </if>
            <if test="teacherId != null">
                AND t.id_ IN
                <foreach collection="teacherId" separator="," open="(" close=")" item="item">
                    #{item}
                </foreach>
            </if>
            <if test="isSettlementSalary!=null">
                AND t.is_settlement_salary_ = #{isSettlementSalary}
            </if>
            <if test="search != null">
                AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%') OR t.id_ = #{search})
            </if>
        </where>
    </sql>

    <!-- 根据证件号查询老师 -->
    <select id="findByCertificateNum" resultMap="Teacher">
        SELECT * FROM teacher WHERE certificate_num_ = #{certificateNum} LIMIT 1
    </select>
    <select id="queryGroupStudents" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,s.name_ subject_name_,sr.music_group_id_,su.user_type_
        FROM class_group_teacher_mapper cgtm
        LEFT JOIN class_group_student_mapper cgsm ON cgtm.class_group_id_ = cgsm.class_group_id_
        LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
        LEFT JOIN student_registration sr ON sr.user_id_ = cgsm.user_id_ AND cgsm.music_group_id_ = sr.music_group_id_
        LEFT JOIN `subject` s ON s.id_ = sr.actual_subject_id_
        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'
        WHERE (cgtm.user_id_ = #{teacherId} OR mg.team_teacher_id_ = #{teacherId} OR mg.educational_teacher_id_ = #{teacherId}
        OR director_user_id_ = #{teacherId}) AND su.id_ IS NOT NULL AND (sr.music_group_status_ != 'QUIT' OR sr.id_ IS NULL)
        AND (mg.status_ = 'PROGRESS' OR vg.group_status_ IN (2,4) OR cgsm.group_type_ = 'PRACTICE')
        <if test="search != null">
            AND su.username_ LIKE CONCAT('%',#{search},'%')
        </if>
        GROUP BY su.id_,s.id_,sr.id_
    </select>
    <select id="queryNameByIds" resultType="java.util.Map" parameterType="list">
        select id_ `key`,IF(real_name_ IS NUll,'',real_name_) `value` FROM sys_user s WHERE FIND_IN_SET(id_,#{userIds})
    </select>
    <select id="queryNameByIdList" resultType="java.util.Map">
        select id_ `key`,IF(real_name_ IS NUll,username_,real_name_) `value` FROM sys_user s WHERE id_ IN
        <foreach collection="userIds" item="userId" separator="," open="(" close=")">
            #{userId}
        </foreach>
    </select>
    <select id="queryUserNameByIdList" resultType="java.util.Map">
        select id_ `key`,IF(username_ IS NUll,real_name_,username_) `value` FROM sys_user s WHERE id_ IN
        <foreach collection="userIds" item="userId" separator="," open="(" close=")">
            #{userId}
        </foreach>
    </select>

    <select id="queryNickNameByRole" resultType="java.util.Map">
        select id_ `key`,IF(username_ IS NUll,real_name_,username_) `value` FROM sys_user s WHERE id_ IN
        <foreach collection="userIds" item="userId" separator="," open="(" close=")">
            #{userId}
        </foreach>
    </select>

    <select id="querySubjectNameByIdList" resultType="java.util.Map">
        select t.id_ `key`,GROUP_CONCAT(s.name_) `value`
        FROM teacher t
        LEFT JOIN subject s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE t.id_ IN
        <foreach collection="userIds" item="userId" separator="," open="(" close=")">
            #{userId}
        </foreach>
        GROUP BY t.id_
    </select>

    <select id="queryPhoneByIds" resultType="java.util.Map" parameterType="list">
        select id_ `key`,phone_ `value` FROM sys_user s WHERE FIND_IN_SET(id_,#{userIds}) AND s.phone_ IS NOT NULL
    </select>

    <resultMap id="TeacherBasicDto" type="com.ym.mec.biz.dal.dto.TeacherBasicDto">
        <result property="id" column="id_"/>
        <result property="username" column="username_"/>
        <result property="realName" column="real_name_"/>
        <result property="organId" column="organ_id_"/>
    </resultMap>

    <resultMap id="ExtendTeacherBasicDto" type="com.ym.mec.biz.dal.dto.ExtendTeacherBasicDto" extends="TeacherBasicDto">
        <result property="isSupportExtraPracticeLesson" column="is_support_extra_practice_lesson_"/>
        <result property="avatar" column="avatar_"/>
        <result property="subjectNames" column="subject_names_"/>
        <result property="introduction" column="introduction_"/>
    </resultMap>

    <select id="findSimpleTeachers" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
        SELECT su.id_ userId,su.real_name_ userName FROM sys_user su
        LEFT JOIN teacher t ON su.id_=t.id_
        <where>
            <if test="userIds != null">
                su.id_ IN
                <foreach collection="userIds" separator="," open="(" close=")" item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="getUsersSimpleInfo" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
        SELECT
            su.id_ userId,
            su.username_ nickName,
            su.real_name_ userName,
            su.gender_ gender,
            su.phone_ phone
        FROM sys_user su
        <where>
            <if test="userIds != null">
                su.id_ IN
                <foreach collection="userIds" separator="," open="(" close=")" item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="findTeaTeachersByOrganAndSubject" resultMap="TeacherBasicDto">
        SELECT
            su.id_,
            su.username_,
            su.real_name_,
            t.organ_id_
        FROM
            teacher t
            LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE
            FIND_IN_SET(#{subjectId},t.subject_id_)
            AND (t.organ_id_=#{organId} OR FIND_IN_SET(#{organId},t.flow_organ_range_))
            AND su.del_flag_=0 AND su.lock_flag_=0
            AND t.is_support_extra_practice_lesson_=1
            AND t.organ_id_!=36
    </select>
    <select id="findTeaTeachersByOrganAndSubject1" resultMap="ExtendTeacherBasicDto">
        SELECT
            su.id_,
            su.username_,
            su.real_name_,
            t.organ_id_,
            t.is_support_extra_practice_lesson_
        FROM
            teacher t
            LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE
            FIND_IN_SET(#{subjectId},t.subject_id_)
            AND (t.organ_id_=#{organId} OR FIND_IN_SET(#{organId},t.flow_organ_range_))
            AND su.del_flag_=0 AND su.lock_flag_=0
            AND t.is_support_extra_practice_lesson_=1
            AND t.organ_id_!=36
    </select>

    <select id="findTeaTeachersByOrganAndSubject2" resultMap="ExtendTeacherBasicDto">
        SELECT
            su.id_,
            su.username_,
            su.real_name_,
            su.avatar_,
            t.introduction_,
            t.organ_id_,
            t.is_support_extra_practice_lesson_,
            GROUP_CONCAT(s.name_) subject_names_
        FROM
            teacher t
            LEFT JOIN sys_user su ON t.id_ = su.id_
            LEFT JOIN subject s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE
            FIND_IN_SET(#{subjectId},t.subject_id_)
            AND (t.organ_id_=#{organId} OR FIND_IN_SET(#{organId},t.flow_organ_range_))
            AND su.del_flag_=0 AND su.lock_flag_=0
            AND t.is_support_extra_practice_lesson_=1
            AND t.organ_id_!=36
        GROUP BY su.id_
    </select>

    <select id="findTeaTeachersByOrganAndSubject3" resultMap="ExtendTeacherBasicDto">
        SELECT
            su.id_,
            su.username_,
            su.real_name_,
            su.avatar_,
            t.introduction_,
            t.organ_id_,
            t.is_support_extra_practice_lesson_,
            GROUP_CONCAT(s.name_) subject_names_
        FROM
            teacher t
            LEFT JOIN sys_user su ON t.id_ = su.id_
            LEFT JOIN subject s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE
            FIND_IN_SET(#{subjectId},t.subject_id_)
            AND (t.organ_id_=#{organId} OR FIND_IN_SET(#{organId},t.flow_organ_range_))
            AND su.del_flag_=0 AND su.lock_flag_=0
            AND t.organ_id_!=36
            GROUP BY su.id_
    </select>

    <select id="findTeacherByOrganAndSubject" resultMap="TeacherBasicDto">
        SELECT
            su.id_,
            su.username_,
            su.real_name_,
            t.organ_id_
        FROM
            teacher t
            LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE
            FIND_IN_SET(#{subjectIds},t.subject_id_)
            AND (FIND_IN_SET(t.organ_id_, #{organIds}) OR INTE_ARRAY(t.flow_organ_range_, #{organIds}))
    </select>
    <select id="findByTeacherId" resultMap="TeacherBasicDto">
        SELECT
            su.id_,
            su.username_,
            su.real_name_,
            t.organ_id_
        FROM
            teacher t
            LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE
            t.id_=#{teacherId}
    </select>
    <select id="countCloses" resultType="java.lang.Integer">
        SELECT COUNT(cs.id_)
        FROM course_schedule cs
        LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
        LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_ AND ta.teacher_id_ = csts.user_id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        <include refid="queryCloses"/>
    </select>
    <resultMap id="TeacherCloseDto" type="com.ym.mec.biz.dal.dto.TeacherCloseDto">
        <result property="classDate" column="class_date_"/>
        <result property="classTime" column="start_class_time_"/>
        <result property="className" column="class_name_"/>
        <result property="courseScheduleType" column="class_type_"/>
        <result property="teacherRole" column="teacher_role_"/>
        <result property="currentClassTimes" column="current_class_times_"/>
        <result property="totalClassTimes" column="total_class_times_"/>
        <result property="signInStatus" column="sign_in_status_"/>
        <result property="signOutStatus" column="sign_out_status_"/>
        <result property="actualSalary" column="actual_salary_"/>
        <result property="expectSalary" column="expect_salary_"/>
        <result property="subsidy" column="subsidy_"/>
        <result property="settlementTime" column="settlement_time_"/>
        <result property="courseScheduleId" column="course_schedule_id_"/>
    </resultMap>
    <select id="queryCloses" resultMap="TeacherCloseDto">
        SELECT cs.id_ course_schedule_id_,cs.class_date_,cs.start_class_time_,cg.name_ class_name_,cs.type_ class_type_,
        csts.teacher_role_,ta.current_class_times_,cg.total_class_times_,
        IF(ta.sign_in_status_ IS NULL,3,ta.sign_in_status_) sign_in_status_,
        IF(ta.sign_out_status_ IS NULL,3,ta.sign_out_status_) sign_out_status_,
        csts.actual_salary_,csts.settlement_time_,csts.subsidy_,csts.expect_salary_
        FROM course_schedule cs
        LEFT JOIN course_schedule_teacher_salary csts ON cs.id_ = csts.course_schedule_id_
        LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_ AND ta.teacher_id_ = csts.user_id_
        LEFT JOIN class_group cg ON cs.class_group_id_ = cg.id_
        <include refid="queryCloses"/>
        ORDER BY cs.class_date_,cs.start_class_time_ DESC
        <include refid="global.limit"/>
    </select>

    <select id="findTeacherNoPay" resultType="decimal">
        SELECT SUM(expect_salary_) FROM course_schedule_teacher_salary csts WHERE settlement_time_ IS NULL AND user_id_
        = #{teacherId}
    </select>

    <select id="findTeacherByMusicGroup" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT
            su.id_ user_id_,
            su.real_name_ username_
        FROM
          class_group_teacher_mapper cgtm
            LEFT JOIN class_group cg ON cg.id_=cgtm.class_group_id_
            LEFT JOIN sys_user su ON cgtm.user_id_=su.id_
        WHERE cg.music_group_id_=#{musicGroupId} AND cg.group_type_='MUSIC'
        GROUP BY su.id_
    </select>
    <resultMap id="MusicGroupTeachersDto" type="com.ym.mec.biz.dal.dto.MusicGroupTeachersDto">
        <result property="teacherName" column="real_name_"/>
        <result property="teacherPhone" column="phone_"/>
        <result property="jobNature" column="job_nature_"/>
        <result property="classGroupName" column="class_group_name_"/>
        <result property="classGroupId" column="class_group_id_"/>
        <result property="teacherId" column="teacher_id_"/>
    </resultMap>
    <select id="queryMusicGroupTeachers" resultMap="MusicGroupTeachersDto">
        SELECT su.real_name_,su.phone_,t.job_nature_,GROUP_CONCAT(cg.name_) class_group_name_,t.id_ teacher_id_
        FROM teacher t
        LEFT JOIN class_group_teacher_mapper cgtm ON t.id_ = cgtm.user_id_
        LEFT JOIN class_group cg ON cg.id_ = cgtm.class_group_id_
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE cg.del_flag_ != '1' AND cgtm.group_type_ = 'MUSIC'
        <include refid="queryMusicGroupTeachersSql"/>
        GROUP BY t.id_
        <include refid="global.limit"/>
    </select>
    <select id="countMusicGroupTeachers" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT t.id_)
        FROM teacher t
        LEFT JOIN class_group_teacher_mapper cgtm ON t.id_ = cgtm.user_id_
        LEFT JOIN class_group cg ON cg.id_ = cgtm.class_group_id_
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE cg.del_flag_ != '1' AND cgtm.group_type_ = 'MUSIC'
        <include refid="queryMusicGroupTeachersSql"/>
    </select>
    <sql id="queryMusicGroupTeachersSql">
        <if test="search != null and search != ''">
            AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%') OR
            su.id_=#{search})
        </if>
        <if test="musicGroupId != null and musicGroupId != ''">
            AND cgtm.music_group_id_ = #{musicGroupId}
        </if>
        <if test="classGroupId != null">
            AND cg.id_ = #{classGroupId}
        </if>
    </sql>

    <select id="findSignNum" resultType="java.util.Map">
        SELECT ta.teacher_id_ 'key',COUNT(ta.id_) 'value' FROM teacher_attendance ta
        WHERE FIND_IN_SET(ta.teacher_id_,#{teacherIdStr}) AND ta.music_group_id_ = #{musicGroupId}
        GROUP BY ta.teacher_id_
    </select>

    <sql id="queryTeacherAttendanceSql">
        <where>
            CONCAT(cs.class_date_,' ',cs.start_class_time_) &lt; NOW() AND cgtm.teacher_role_ = 'BISHOP'
            <if test="startTime != null and startTime != ''">
                AND cs.class_date_ &gt;= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND cs.class_date_ &lt;= #{endTime}
            </if>
            <if test="musicGroupId != null and musicGroupId != ''">
                AND ta.music_group_id_ = #{musicGroupId}
            </if>
            <if test="teacherName != null and teacherName != ''">
                AND su.real_name_ LIKE CONCAT('%',#{teacherName},'%')
            </if>
        </where>
    </sql>
    <resultMap id="MusicGroupTeacherAttendanceDto" type="com.ym.mec.biz.dal.dto.MusicGroupTeacherAttendanceDto">
        <result property="classDate" column="class_date_"/>
        <result property="startClassTime" column="start_class_time_"/>
        <result property="courseScheduleName" column="name_"/>
        <result property="realName" column="real_name_"/>
        <result property="signInStatus" column="sign_in_status_"/>
        <result property="signOutStatus" column="sign_out_status_"/>
    </resultMap>
    <select id="queryTeacherAttendance" resultMap="MusicGroupTeacherAttendanceDto">
        SELECT cs.class_date_,cs.start_class_time_,cs.name_,su.real_name_,
        IF(ta.sign_in_status_ IS NULL,3,ta.sign_in_status_) sign_in_status_,
        IF(ta.sign_out_status_ IS NULL,3,ta.sign_out_status_) sign_out_status_
        FROM course_schedule cs
        LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
        LEFT JOIN sys_user su ON su.id_ = ta.teacher_id_
        LEFT JOIN class_group_teacher_mapper cgtm ON cgtm.class_group_id_ = cs.class_group_id_ AND ta.teacher_id_ = cgtm.user_id_
        <include refid="queryTeacherAttendanceSql"/>
        ORDER BY cs.class_date_ DESC,cs.start_class_time_ DESC
        <include refid="global.limit"/>
    </select>
    <select id="countTeacherAttendance" resultType="java.lang.Integer">
        SELECT COUNT(cs.id_)
        FROM course_schedule cs
        LEFT JOIN teacher_attendance ta ON cs.id_ = ta.course_schedule_id_
        LEFT JOIN sys_user su ON su.id_ = ta.teacher_id_
        LEFT JOIN class_group_teacher_mapper cgtm ON cgtm.class_group_id_ = cs.class_group_id_ AND ta.teacher_id_ = cgtm.user_id_
        <include refid="queryTeacherAttendanceSql"/>
    </select>
    <select id="queryNameById" resultType="java.lang.String">
        select real_name_ FROM sys_user s WHERE id_ = #{userId} LIMIT 1
    </select>
    <resultMap id="musicGroupStudentApplyDto" type="com.ym.mec.biz.dal.dto.MusicGroupStudentApplyDto">
        <result property="userId" column="user_id_"/>
        <result property="userName" column="username_"/>
        <result property="currentClass" column="current_class_"/>
        <result property="currentGrade" column="current_grade_"/>
        <result property="subjectName" column="subject_name_"/>
        <result property="subjectId" column="actual_subject_id_"/>
        <result property="paymentAmount" column="actual_amount_"/>
        <result property="payTime" column="pay_time_"/>
        <result property="paymentStatus" column="payment_status_"/>
        <result property="remark" column="remark_"/>
    </resultMap>
    <select id="queryMusicGroupStudentApply" resultMap="musicGroupStudentApplyDto">
        SELECT sr.user_id_,su.username_,sr.current_class_,sr.current_grade_,s.name_ subject_name_,sr.remark_,
        sr.payment_status_,sr.actual_subject_id_
        FROM student_registration sr
        LEFT JOIN sys_user su ON sr.user_id_ = su.id_
        LEFT JOIN `subject` s ON sr.actual_subject_id_ = s.id_
        <include refid="queryMusicGroupStudentApplySql"/>
        <include refid="global.limit"/>
    </select>
    <sql id="queryMusicGroupStudentApplySql">
        <where>
            sr.music_group_id_ = #{musicGroupId} AND sr.music_group_status_ != 'QUIT'
            <if test="subjectId != null">
                AND sr.actual_subject_id_ = #{subjectId}
            </if>
            <if test="paymentStatus != null">
                AND sr.payment_status_ = #{paymentStatus}
            </if>
        </where>
    </sql>
    <select id="countMusicGroupStudentApply" resultType="java.lang.Integer">
        SELECT COUNT(sr.user_id_)
        FROM student_registration sr
        LEFT JOIN sys_user su ON sr.user_id_ = su.id_
        LEFT JOIN `subject` s ON sr.actual_subject_id_ = s.id_
        <include refid="queryMusicGroupStudentApplySql"/>
    </select>

    <select id="queryMusicGroupStudents" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.real_name_ username_,su.id_ user_id_,su.avatar_ head_url_,
        su.gender_,GROUP_CONCAT(s.name_) subject_name_,su.user_type_
        FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE FIND_IN_SET(t.id_,#{teacherIds})
        <if test="search != null">
            AND su.real_name_ LIKE CONCAT('%',#{search},'%')
        </if>
        GROUP BY t.id_
    </select>
    <select id="findOrganTeacherBySubject" resultMap="Teacher">
        SELECT su.* FROM teacher t
        LEFT JOIN sys_user su on t.id_ = su.id_ WHERE 1=1
        <if test="subjectId != null">
            AND FIND_IN_SET(#{subjectId},t.subject_id_)
        </if>
    </select>

    <sql id="queryCloses">
        <where>
            CONCAT(cs.class_date_,' ',cs.start_class_time_) &lt; NOW()
            <if test="teacherId != null">
                AND csts.user_id_ = #{teacherId}
            </if>
            <if test="courseStartDate != null and courseStartDate != ''">
                AND cs.class_date_ &gt;= #{courseStartDate}
            </if>
            <if test="courseEndDate != null and courseEndDate != ''">
                AND cs.class_date_ &lt;= #{courseEndDate}
            </if>
            <if test="courseScheduleType != null and courseScheduleType != ''">
                AND cs.type_ = #{courseScheduleType}
            </if>
            <if test="teacherRole != null and teacherRole != ''">
                AND csts.teacher_role_ = #{teacherRole}
            </if>
            <if test="signInStatus != null and signInStatus != 3">
                AND ta.sign_in_status_ = #{signInStatus}
            </if>
            <if test="signOutStatus != null and signOutStatus != 3">
                AND ta.sign_out_status_ = #{signOutStatus}
            </if>
            <if test="signOutStatus != null and signOutStatus == 3">
                AND ta.sign_out_status_ IS NULL
            </if>
            <if test="signInStatus != null and signInStatus == 3">
                AND ta.sign_in_status_ IS NULL
            </if>
        </where>
    </sql>

    <select id="queryOrganTeacherNum" resultType="map">
        select count(*) total,sum(case when job_nature_ = 'PART_TIME' then 1 else 0 end) part_time_num_,sum(case when
        job_nature_ = 'FULL_TIME' then 1 else 0 end) full_time_num_ from teacher
        where demission_date_ is null and organ_id_ not in (36,38)
            <if test="organId != null">
                and FIND_IN_SET(organ_id_,#{organId})
            </if>
    </select>
    <select id="findByFlowOrganRangeTeachers" resultMap="TeacherBasicDto">
        SELECT su.id_,su.username_,su.real_name_,t.organ_id_ FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE su.del_flag_ = 0 AND su.lock_flag_=0
        <if test="organId != null and organId != ''">
            AND (INTE_ARRAY(#{organId},t.flow_organ_range_) OR FIND_IN_SET(t.organ_id_,#{organId}))
        </if>
    </select>

    <select id="findByTeacherIds" resultMap="Teacher">
        SELECT t.*,su.real_name_ FROM teacher t
        LEFT JOIN sys_user su ON su.id_ = t.id_
        WHERE t.id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
    </select>
    <select id="findTeacherByOrganId" resultMap="TeacherBasicDto">
        SELECT su.id_,su.username_,su.real_name_ FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE su.del_flag_ != 1 AND su.lock_flag_!=1
        <if test="organId != null">
            AND (FIND_IN_SET(t.organ_id_,#{organId}) OR INTE_ARRAY(t.flow_organ_range_,#{organId}))
        </if>
        <if test="subjectIds != null">
            AND INTE_ARRAY(t.subject_id_,#{subjectIds})
        </if>
        <if test="jobNature != null">
            AND t.job_nature_ = #{jobNature}
        </if>
    </select>
    <select id="queryUsernameByIds" resultType="java.util.Map" parameterType="list">
        select id_ `key`,username_ `value` FROM sys_user s
        WHERE s.id_ IN
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <select id="searchTeachers" resultMap="TeacherBasicDto">
        SELECT su.id_,su.username_,su.real_name_ FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE su.del_flag_ != 1 AND su.lock_flag_!=1
        <if test="organId != null">
            AND FIND_IN_SET(t.organ_id_,#{organId})
        </if>
        <if test="teacherName != null">
            AND su.real_name_ LIKE CONCAT('%',#{teacherName},'%')
        </if>
    </select>
    <select id="countTeacherName" resultType="java.lang.Integer">
        SELECT COUNT(su.id_) FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        WHERE su.del_flag_ != 1 AND su.lock_flag_!=1
        <include refid="queryPageNameSql"/>
    </select>
    <sql id="queryPageNameSql">
        <if test="organId != null and includeFlowOrgan==null">
            AND FIND_IN_SET(t.organ_id_,#{organId})
        </if>
        <if test="organId != null and includeFlowOrgan!=null and includeFlowOrgan">
            AND (CONCAT(',',t.organ_id_,',',IFNULL(t.flow_organ_range_,''),',') REGEXP CONCAT(',(',replace(#{organId},',','|'),'),'))
        </if>
        <if test="subjectIds != null">
            AND INTE_ARRAY(t.subject_id_,#{subjectIds})
        </if>
        <if test="jobNature != null">
            AND t.job_nature_ = #{jobNature}
        </if>
        <if test="teacherId != null">
            AND t.id_ = #{teacherId}
        </if>
        <if test="search != null">
            AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
        </if>
    </sql>
    <select id="queryPageName" resultMap="Teacher">
        SELECT su.id_,su.real_name_,su.avatar_,t.subject_id_,t.organ_id_,GROUP_CONCAT(s.name_) subject_name_ FROM teacher t
        LEFT JOIN sys_user su ON t.id_ = su.id_
        LEFT JOIN subject s ON FIND_IN_SET(s.id_, t.subject_id_)
        WHERE su.del_flag_ != 1 AND su.lock_flag_!=1
        <include refid="queryPageNameSql"/>
        GROUP BY su.id_
        <include refid="global.limit"/>
    </select>
    <select id="getCourseScheduleHomework" resultMap="com.ym.mec.biz.dal.dao.CourseHomeworkDao.CourseHomework">
        SELECT * FROM course_homework WHERE course_schedule_id_ = #{courseScheduleId} LIMIT 1
    </select>
    <select id="lockTeachers" resultType="int">
        SELECT id_ FROM teacher WHERE id_ IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
        FOR UPDATE
    </select>
    <resultMap type="com.ym.mec.auth.api.entity.SysUser" id="SysUser">
        <result column="id_" property="id"/>
        <result column="username_" property="username"/>
        <result column="real_name_" property="realName"/>
        <result column="password_" property="password"/>
        <result column="salt_" property="salt"/>
        <result column="phone_" property="phone"/>
        <result column="avatar_" property="avatar"/>
        <result column="organ_id_" property="organId"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
        <result column="lock_flag_" property="lockFlag"/>
        <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="wx_openid_" property="wxOpenid"/>
        <result column="qq_openid_" property="qqOpenid"/>
        <result column="user_type_" property="userType"/>
        <result column="gender_" property="gender"/>
        <result column="nation_" property="nation"/>
        <result column="birthdate_" property="birthdate"/>
        <result column="email_" property="email"/>
        <result column="im_token_" property="imToken"/>
        <result column="id_card_no_" property="idCardNo"/>
        <result column="wechat_id_" property="wechatId"/>
        <result column="is_super_admin_" property="isSuperAdmin"/>
        <result column="current_grade_" property="currentGrade"/>
        <result column="current_class_" property="currentClass"/>
        <result column="certificate_type_" property="certificateType"/>
    </resultMap>

    <select id="getUser" resultMap="SysUser">
        SELECT su.*
        FROM sys_user su
        WHERE su.id_ = #{id} LIMIT 1
    </select>

    <select id="getUserWithPhone" resultMap="SysUser">
        SELECT su.*
        FROM sys_user su
        WHERE su.phone_ = #{phone} LIMIT 1
    </select>

    <select id="queryTeacherBaseInfo"  resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT
        CASE WHEN su.user_type_ LIKE '%TEACHER%' OR su.user_type_ LIKE '%SYSTEM%' THEN su.real_name_ ELSE su.username_ END username_,
        su.id_ user_id_,
        su.avatar_ head_url_,
        gender_,
        GROUP_CONCAT(s.name_) subject_name_
        FROM sys_user su
        LEFT JOIN teacher t ON su.id_ = t.id_
        LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE su.id_ IN
        <foreach collection="teacherId" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
        <if test="search != null and search != ''">
            AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
        </if>
        AND su.del_flag_ = 0 AND su.lock_flag_=0
        GROUP BY su.id_
    </select>
    <select id="queryTeacherImModel" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.ImUserModel">
        SELECT su.id_,su.avatar_,su.real_name_ username_
        FROM sys_user su
        WHERE su.id_ IN
        <foreach collection="teacherIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
        <if test="search != null and search != ''">
            AND su.real_name_ LIKE CONCAT('%',#{search},'%')
        </if>
    </select>
    <select id="findMusicTeacherIds" resultType="java.lang.Integer">
        SELECT DISTINCT cgtm.user_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN music_group mg ON cgsm.music_group_id_ = mg.id_
        WHERE mg.status_ IN ('PROGRESS','PAUSE') AND cgsm.user_id_ = #{studentId}
    </select>
    <select id="findVipTeacherIds" resultType="java.lang.Integer">
        SELECT DISTINCT cgtm.user_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN vip_group vg ON vg.id_ = cgsm.music_group_id_
        WHERE vg.group_status_ IN (2,3,4,6) AND cgsm.user_id_ = #{studentId}
    </select>
    <select id="findPracticeTeacherIds" resultType="java.lang.Integer">
        SELECT DISTINCT cgtm.user_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN practice_group pg ON pg.id_ = cgsm.music_group_id_
        WHERE cgsm.group_type_ = 'PRACTICE' AND cgsm.user_id_ = #{studentId}
    </select>
    <select id="findCloseCourseTeacherIds" resultType="java.lang.Integer">
        SELECT DISTINCT cgtm.user_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN courses_group cg ON cg.id_ = cgsm.music_group_id_
        WHERE cgsm.group_type_ = 'COMM' AND cgsm.user_id_ = #{studentId}
    </select>

    <select id="findTeacherInfo"  resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT
        su.real_name_ username_,
        su.id_ user_id_,
        su.avatar_ head_url_,
        gender_,
        GROUP_CONCAT(s.name_) subject_name_
        FROM sys_user su
        LEFT JOIN teacher t ON su.id_ = t.id_
        LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE su.id_ = #{id}
    </select>
    <select id="queryEducationIpa" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.real_name_ username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,GROUP_CONCAT(s.name_) subject_name_,su.user_type_
        FROM employee e
        LEFT JOIN teacher t ON INTE_ARRAY(e.organ_id_list_,t.flow_organ_range_) OR FIND_IN_SET(t.organ_id_,e.organ_id_list_)
        LEFT JOIN sys_user su ON t.id_ = su.id_
        LEFT JOIN `subject` s ON FIND_IN_SET(s.id_,t.subject_id_)
        WHERE e.user_id_ = #{userId}
        <if test="search != null and search != ''">
            AND su.real_name_ LIKE CONCAT('%',#{search},'%')
        </if>
        GROUP BY t.id_
        UNION ALL
        SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,NULL subject_name_,su.user_type_
        FROM employee e
        LEFT JOIN sys_user su ON FIND_IN_SET(su.organ_id_,e.organ_id_list_)
        LEFT JOIN student_registration sr ON su.id_ = sr.user_id_
        LEFT JOIN music_group mg ON mg.id_ = sr.music_group_id_
        WHERE e.user_id_ = #{userId} AND (sr.id_ IS NULL OR sr.music_group_status_ = 'QUIT' OR mg.status_ != 'PROGRESS')
        <if test="search != null and search != ''">
            AND su.username_ LIKE CONCAT('%',#{search},'%')
        </if>
        GROUP BY su.id_
    </select>
    <select id="findCloseCourseStudentIds" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,NULL subject_name_,su.user_type_
        FROM course_schedule_teacher_salary csts
        LEFT JOIN course_schedule cs ON csts.course_schedule_id_ = cs.id_
        LEFT JOIN course_schedule_student_payment cssp ON cs.id_ = cssp.course_schedule_id_
        LEFT JOIN sys_user su ON su.id_ = cssp.user_id_
        WHERE csts.group_type_ IN ('VIP','PRACTICE') AND cs.status_ = 'OVER' AND csts.user_id_ = #{teacherId} AND su.id_ IS NOT NULL
        <if test="search != null and search != ''">
            AND su.username_ LIKE CONCAT('%',#{search},'%')
        </if>
        GROUP BY su.id_
    </select>

    <select id="findVipEducationalStudentId" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,NULL subject_name_,su.user_type_
        FROM vip_group vg
        LEFT JOIN course_schedule_student_payment cssp ON cssp.music_group_id_ = vg.id_
        LEFT JOIN sys_user su ON su.id_ = cssp.user_id_
        WHERE cssp.group_type_ = 'VIP' AND vg.educational_teacher_id_ = #{teacherId}
        GROUP BY su.id_
    </select>
    <select id="findCommEducationalStudentId" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,NULL subject_name_,su.user_type_
        FROM courses_group vg
        LEFT JOIN course_schedule_student_payment cssp ON cssp.music_group_id_ = vg.id_
        LEFT JOIN sys_user su ON su.id_ = cssp.user_id_
        WHERE cssp.group_type_ = 'COMM' AND vg.educational_teacher_id_ = #{teacherId}
        GROUP BY su.id_
    </select>
    <select id="findPracticeEducationalStudentId" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.username_,su.id_ user_id_,su.avatar_ head_url_,su.gender_,NULL subject_name_,su.user_type_
        FROM practice_group pg
        LEFT JOIN course_schedule_student_payment cssp ON cssp.music_group_id_ = pg.id_
        LEFT JOIN sys_user su ON su.id_ = cssp.user_id_
        WHERE cssp.group_type_ = 'PRACTICE' AND pg.educational_teacher_id_ = #{teacherId}
        GROUP BY su.id_
    </select>
    <select id="findPracticeEducationalTeacherId" resultType="java.lang.Integer">
        SELECT DISTINCT pg.educational_teacher_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN practice_group pg ON pg.id_ = cgsm.music_group_id_
        WHERE cgsm.group_type_ = 'PRACTICE' AND cgsm.user_id_ = #{userId}
    </select>
    <select id="findVipEducationalTeacherId" resultType="java.lang.Integer">
        SELECT DISTINCT vg.educational_teacher_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN vip_group vg ON vg.id_ = cgsm.music_group_id_
        WHERE cgsm.group_type_ = 'VIP' AND cgsm.user_id_ = #{userId}
    </select>
    <select id="findCommEducationalTeacherId" resultType="java.lang.Integer">
        SELECT DISTINCT vg.educational_teacher_id_ FROM class_group_student_mapper cgsm
        LEFT JOIN class_group_teacher_mapper cgtm ON cgsm.class_group_id_ = cgtm.class_group_id_
        LEFT JOIN courses_group vg ON vg.id_ = cgsm.music_group_id_
        WHERE cgsm.group_type_ = 'COMM' AND cgsm.user_id_ = #{userId}
    </select>
    <select id="queryCourseClassStudentIds" resultType="java.lang.Integer">
        SELECT cgsm.user_id_ FROM course_schedule_teacher_salary csts
        LEFT JOIN class_group_student_mapper cgsm ON csts.class_group_id_ = cgsm.class_group_id_
        WHERE csts.user_id_ = #{teacherId}
        GROUP BY cgsm.user_id_
        UNION ALL
        SELECT cgsm.user_id_ FROM class_group_teacher_mapper cgtm
        LEFT JOIN class_group_student_mapper cgsm ON cgtm.class_group_id_ = cgsm.class_group_id_
        WHERE cgtm.user_id_ = #{teacherId}
        GROUP BY cgsm.user_id_
        UNION ALL
        SELECT cssp.user_id_ FROM music_group mg
        LEFT JOIN course_schedule_student_payment cssp ON mg.id_ = cssp.music_group_id_
        WHERE (mg.educational_teacher_id_ = #{teacherId} OR mg.director_user_id_ = #{teacherId} OR mg.team_teacher_id_ = #{teacherId})
        AND cssp.group_type_ = 'MUSIC' AND mg.status_ IN ('PROGRESS','PAUSE')
        UNION ALL
        SELECT cgsm.user_id_ FROM vip_group vg
        LEFT JOIN class_group_student_mapper cgsm ON vg.id_ = cgsm.music_group_id_
        WHERE vg.educational_teacher_id_ = #{teacherId} AND cgsm.group_type_ = 'VIP' AND vg.group_status_ IN (2,3,4,6)
        UNION ALL
        SELECT cssp.user_id_ FROM courses_group cg
        LEFT JOIN course_schedule_student_payment cssp ON cg.id_ = cssp.music_group_id_
        WHERE cg.educational_teacher_id_ = #{teacherId} AND cssp.group_type_ = 'COMM'
        UNION ALL
        SELECT cssp.user_id_ FROM practice_group pg
        LEFT JOIN course_schedule_student_payment cssp ON pg.id_ = cssp.music_group_id_
        WHERE pg.educational_teacher_id_ = #{teacherId} AND cssp.group_type_ = 'PRACTICE'
        UNION ALL
        SELECT s.user_id_ FROM student s WHERE s.teacher_id_ = #{teacherId}
    </select>
    <select id="queryCourseClassTeacherIds" resultType="java.lang.Integer">
        SELECT csts.user_id_ FROM music_group mg
        LEFT JOIN course_schedule_teacher_salary csts ON mg.id_ = csts.music_group_id_
        WHERE csts.group_type_ = 'MUSIC' AND (mg.educational_teacher_id_ = #{teacherId} OR mg.director_user_id_ = #{teacherId} OR mg.team_teacher_id_ = #{teacherId})
        GROUP BY csts.user_id_
        UNION ALL
        SELECT csts.user_id_ FROM vip_group vg 
        LEFT JOIN course_schedule_teacher_salary csts ON vg.id_ = csts.music_group_id_
        WHERE vg.educational_teacher_id_ = #{teacherId} AND csts.group_type_ = 'VIP' AND vg.group_status_ IN (2,3,4,6)
        GROUP BY csts.user_id_
        UNION ALL
        SELECT csts.user_id_ FROM courses_group cg 
        LEFT JOIN course_schedule_teacher_salary csts ON cg.id_ = csts.music_group_id_
        WHERE cg.educational_teacher_id_ = #{teacherId} AND csts.group_type_ = 'COMM'
        GROUP BY csts.user_id_
        UNION ALL
        SELECT csts.user_id_ FROM practice_group pg 
        LEFT JOIN course_schedule_teacher_salary csts ON pg.id_ = csts.music_group_id_
        WHERE pg.educational_teacher_id_ = #{teacherId} AND csts.group_type_ = 'PRACTICE'
        GROUP BY csts.user_id_
        UNION ALL
        SELECT cgtm.user_id_ FROM music_group mg
        LEFT JOIN class_group_teacher_mapper cgtm ON mg.id_ = cgtm.music_group_id_
        WHERE cgtm.group_type_ = 'MUSIC' AND mg.status_ IN ('PROGRESS','PAUSE')
        AND (mg.educational_teacher_id_ = #{teacherId} OR mg.director_user_id_ = #{teacherId} OR mg.team_teacher_id_ = #{teacherId})
        GROUP BY cgtm.user_id_
        UNION ALL
        SELECT cgtm.user_id_ FROM vip_group vg 
        LEFT JOIN class_group_teacher_mapper cgtm ON vg.id_ = cgtm.music_group_id_
        WHERE vg.educational_teacher_id_ = #{teacherId} AND cgtm.group_type_ = 'VIP' AND vg.group_status_ IN (2,3,4,6)
        GROUP BY cgtm.user_id_
        UNION ALL
        SELECT cgtm.user_id_ FROM courses_group cg 
        LEFT JOIN class_group_teacher_mapper cgtm ON cg.id_ = cgtm.music_group_id_
        WHERE cg.educational_teacher_id_ = #{teacherId} AND cgtm.group_type_ = 'COMM'
        GROUP BY cgtm.user_id_
        UNION ALL
        SELECT cgtm.user_id_ FROM practice_group pg 
        LEFT JOIN class_group_teacher_mapper cgtm ON pg.id_ = cgtm.music_group_id_
        WHERE pg.educational_teacher_id_ = #{teacherId} AND cgtm.group_type_ = 'PRACTICE'
        GROUP BY cgtm.user_id_
        UNION ALL
        SELECT vg.educational_teacher_id_ FROM class_group_teacher_mapper cgtm
        LEFT JOIN vip_group vg ON vg.id_ = cgtm.music_group_id_
        WHERE cgtm.user_id_ = #{teacherId} AND cgtm.group_type_ = 'VIP' AND vg.group_status_ IN (2,3,4,6)
        GROUP BY vg.educational_teacher_id_
        UNION ALL
        SELECT cg.educational_teacher_id_ FROM class_group_teacher_mapper cgtm
        LEFT JOIN courses_group cg ON cg.id_ = cgtm.music_group_id_
        WHERE cgtm.user_id_ = #{teacherId} AND cgtm.group_type_ = 'COMM'
        GROUP BY cg.educational_teacher_id_
        UNION ALL
        SELECT pg.educational_teacher_id_ FROM class_group_teacher_mapper cgtm
        LEFT JOIN practice_group pg ON pg.id_ = cgtm.music_group_id_
        WHERE cgtm.user_id_ = #{teacherId} AND cgtm.group_type_ = 'PRACTICE'
        GROUP BY pg.educational_teacher_id_
        UNION ALL
        SELECT vg.educational_teacher_id_ FROM course_schedule_teacher_salary csts
        LEFT JOIN vip_group vg ON vg.id_ = csts.music_group_id_
        WHERE csts.user_id_ = #{teacherId} AND csts.group_type_ = 'VIP' AND vg.group_status_ IN (2,3,4,6)
        GROUP BY vg.educational_teacher_id_
        UNION ALL
        SELECT cg.educational_teacher_id_ FROM course_schedule_teacher_salary csts
        LEFT JOIN courses_group cg ON cg.id_ = csts.music_group_id_
        WHERE csts.user_id_ = #{teacherId} AND csts.group_type_ = 'COMM'
        GROUP BY cg.educational_teacher_id_
        UNION ALL
        SELECT pg.educational_teacher_id_ FROM course_schedule_teacher_salary csts
        LEFT JOIN practice_group pg ON pg.id_ = csts.music_group_id_
        WHERE csts.user_id_ = #{teacherId} AND csts.group_type_ = 'PRACTICE'
        GROUP BY pg.educational_teacher_id_
    </select>
    <select id="queryMusicLeaderIds" resultType="java.lang.String">
        SELECT DISTINCT CONCAT(mg.educational_teacher_id_,',',mg.director_user_id_,',',mg.team_teacher_id_) FROM course_schedule_teacher_salary csts
        LEFT JOIN music_group mg ON mg.id_ = csts.music_group_id_
        WHERE csts.user_id_ = #{teacherId} AND csts.group_type_ = 'MUSIC' AND mg.status_ IN ('PROGRESS','PAUSE')
        GROUP BY mg.id_
        UNION ALL
        SELECT DISTINCT CONCAT(mg.educational_teacher_id_,',',mg.director_user_id_,',',mg.team_teacher_id_) FROM class_group_teacher_mapper cgtm
        LEFT JOIN music_group mg ON mg.id_ = cgtm.music_group_id_
        WHERE cgtm.user_id_ = #{teacherId} AND cgtm.group_type_ = 'MUSIC' AND mg.status_ IN ('PROGRESS','PAUSE')
        GROUP BY mg.id_
    </select>
    <select id="queryStudent" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.username_,s.user_id_,su.phone_ FROM student s
        LEFT JOIN sys_user su ON s.user_id_ = su.id_
        WHERE s.teacher_id_ = #{search}
        <include refid="global.limit"/>
    </select>
    <select id="countStudent" resultType="java.lang.Integer">
        SELECT COUNT(s.user_id_) FROM student s
        WHERE s.teacher_id_ = #{search}
    </select>
    
    <select id="queryTeacherDefaultSalary" resultMap="TeacherDefaultSalaryDto">
    	SELECT t.`id_` ,su.`real_name_` ,o.`name_` ,
		case when t.`job_nature_` = 'PART_TIME' then '兼职' when  t.`job_nature_` = 'FULL_TIME' then '全职' else '临时工' end job_nature,
		case when t.`demission_date_` IS NULL then '在职' else '离职' end demisson_status,
		case when su.`lock_flag_` = 1 then '冻结' WHEN su.`lock_flag_` = 9 then '锁定' else '正常' end status_,
		max(case when gc.`name_` = '1V1' then gs.`offline_classes_salary_` else 0 end) vip1,
		max(case when gc.`name_` = '1V2' then gs.`offline_classes_salary_` else 0 end) vip2,
		max(case when gc.`name_` = '1V3' then gs.`offline_classes_salary_` else 0 end) vip3,
		max(case when gc.`name_` = '1V4' then gs.`offline_classes_salary_` else 0 end) vip4,
		max(case when gc.`name_` = '1V5' then gs.`offline_classes_salary_` else 0 end) vip5,
		max(case when gc.`name_` = '1V6' then gs.`offline_classes_salary_` else 0 end) vip6,
		max(case when gc.`name_` = '1V7' then gs.`offline_classes_salary_` else 0 end) vip7,
		max(pgs.main_teacher_salary_) practice,
        MAX(case when mgs.course_schedule_type_ = 'SINGLE' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_single2,
        MAX(case when mgs.course_schedule_type_ = 'MIX' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_mix2,
        MAX(case when mgs.course_schedule_type_ = 'COMPREHENSIVE' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_comprehensive2,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_SINGLE' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_training_single2,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_MIX' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_training_mix2,
        MAX(case when mgs.course_schedule_type_ = 'HIGH' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_high2,
        MAX(case when mgs.course_schedule_type_ = 'CLASSROOM' then mgs.main_teacher_30min_salary_ ELSE 0 END) main_classroom2,
        MAX(case when mgs.course_schedule_type_ = 'SINGLE' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_single,
        MAX(case when mgs.course_schedule_type_ = 'MIX' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_mix,
        MAX(case when mgs.course_schedule_type_ = 'COMPREHENSIVE' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_comprehensive,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_SINGLE' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_training_single,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_MIX' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_training_mix,
        MAX(case when mgs.course_schedule_type_ = 'HIGH' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_high,
        MAX(case when mgs.course_schedule_type_ = 'CLASSROOM' then mgs.main_teacher_90min_salary_ ELSE 0 END) main_classroom,

        MAX(case when mgs.course_schedule_type_ = 'SINGLE' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_single2,
        MAX(case when mgs.course_schedule_type_ = 'MIX' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_mix2,
        MAX(case when mgs.course_schedule_type_ = 'COMPREHENSIVE' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_comprehensive2,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_SINGLE' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_training_single2,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_MIX' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_training_mix2,
        MAX(case when mgs.course_schedule_type_ = 'HIGH' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_high2,
        MAX(case when mgs.course_schedule_type_ = 'CLASSROOM' then mgs.assistant_teacher_30min_salary_ ELSE 0 END) assistant_classroom2,
        MAX(case when mgs.course_schedule_type_ = 'SINGLE' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_single,
        MAX(case when mgs.course_schedule_type_ = 'MIX' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_mix,
        MAX(case when mgs.course_schedule_type_ = 'COMPREHENSIVE' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_comprehensive,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_SINGLE' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_training_single,
        MAX(case when mgs.course_schedule_type_ = 'TRAINING_MIX' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_training_mix,
        MAX(case when mgs.course_schedule_type_ = 'HIGH' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_high,
        MAX(case when mgs.course_schedule_type_ = 'CLASSROOM' then mgs.assistant_teacher_90min_salary_ ELSE 0 END) assistant_classroom,

		MAX(case when mgs.course_schedule_type_ = 'HIGH_ONLINE' then CONVERT(JSON_EXTRACT(mgs.salary_rule_json_,'$."3"'),DECIMAL) END) high_online3,
		MAX(case when mgs.course_schedule_type_ = 'HIGH_ONLINE' then CONVERT(JSON_EXTRACT(mgs.salary_rule_json_,'$."4"'),DECIMAL) END) high_online4,
		MAX(case when mgs.course_schedule_type_ = 'HIGH_ONLINE' then CONVERT(JSON_EXTRACT(mgs.salary_rule_json_,'$."5"'),DECIMAL) END) high_online5,
		MAX(case when mgs.course_schedule_type_ = 'MUSIC_NETWORK' then CONVERT(JSON_EXTRACT(mgs.salary_rule_json_,'$."1"'),DECIMAL) END) music_network1
		FROM `teacher` t LEFT JOIN `sys_user` su on t.`id_` = su.`id_` 
		LEFT JOIN `organization` o on o.`id_` = t.`organ_id_` 
		LEFT JOIN `teacher_default_vip_group_salary` gs on gs.`user_id_` = t.`id_`
		LEFT JOIN `vip_group_category` gc on gc.`id_` = gs.`vip_group_category_id_`
		LEFT JOIN teacher_default_practice_group_salary pgs ON pgs.user_id_ = t.id_
		LEFT JOIN teacher_default_music_group_salary mgs ON mgs.user_id_ = t.id_
		<where>
			<if test="organIdList != null">
                AND find_in_set(t.organ_id_,#{organIdList})
            </if>
		</where>
		GROUP BY t.`id_` 
    </select>
    <select id="findUserByPhone" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT username_,id_ user_id_,avatar_ head_url_,
        gender_,user_type_
        FROM sys_user WHERE phone_ = #{phone}
    </select>
    <select id="existUser" resultType="java.lang.Boolean">
        SELECT COUNT(0) FROM student WHERE user_id_ = #{userId} LIMIT 1
    </select>
    <select id="queryTeacherNameByTeacherIds" resultType="String">
        SELECT GROUP_CONCAT(real_name_) FROM sys_user su
        WHERE FIND_IN_SET(su.id_,#{teachingTeacherIds})
    </select>
    <select id="queryAllIds" resultType="java.lang.Integer">
        SELECT id_ FROM sys_user
    </select>
</mapper>
