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


    <resultMap id="studentManageCourseListDto" type="com.ym.mec.biz.dal.dto.StudentManageCourseListDto">
        <result property="classGroupId" column="class_group_id_" />
        <result property="classGroupName" column="class_group_name_" />
        <result property="classGroupType" column="class_group_type_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="courseScheduleType" column="course_schedule_type_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="courseDate" column="course_date_" />
        <result property="courseEndDate" column="course_end_date_" />
        <result property="courseScheduleId" column="course_schedule_id_" />
        <result property="courseStatus" column="course_status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="teacherName" column="teacher_name_" />
        <result property="currentCLassTimes" column="current_class_times_" />
        <result property="totalClassTimes" column="total_class_times_" />
        <result property="attendanceStatus" column="status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="courseStatus" column="courseStatus" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="teachMode" column="teach_mode_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    </resultMap>

    <resultMap id="studentManageAccountBaseInfo" type="com.ym.mec.biz.dal.dto.StudentManageAccountBaseInfoDto">
        <result property="balance" column="balance_"/>
        <result property="courseBalance" column="course_balance_"/>
        <result property="bankName" column="bank_name_"/>
        <result property="cardNo" column="card_no_"/>
        <result property="courseBalance" column="course_balance_"/>
    </resultMap>

    <resultMap id="StudentListCourseDto" type="com.ym.mec.biz.dal.dto.StudentListCourseDto">
        <result property="userId" column="userId"/>
        <result property="remainCourseNum" column="remainCourseNum"/>
        <result property="remainPracticeNum" column="remainPracticeNum"/>
        <result property="remainVipNum" column="remainVipNum"/>
    </resultMap>
    
    <resultMap id="studentManageListDto" type="com.ym.mec.biz.dal.dto.StudentManageListDto">
        <result property="userId" column="user_id_"/>
        <result property="realName" column="real_name_"/>
        <result property="nation" column="nation_"/>
        <result property="parentsPhone" column="parents_phone_"/>
        <result property="parentsName" column="real_name_"/>
        <result property="gender" column="gender_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="username" column="username_"/>
        <result property="birthdate" column="birthdate_"/>
        <result property="currentGrade" column="current_grade_"/>
        <result property="currentGradeNum" column="current_grade_num_"/>
        <result property="currentClass" column="current_class_"/>
        <result property="isActive" column="isActive_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="hasCourse" column="hasCourse_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="hasPracticeCourse" column="hasPracticeCourse_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="musicGroupName" column="music_group_name_"/>
        <result property="musicGroupStatus" column="music_group_status_"/>
        <result property="vipGroupName" column="vip_group_name_"/>
        <result property="vipGroupStatus" column="vip_group_status_"/>
        <result property="organName" column="organ_name_"/>
        <result property="organId" column="organ_id_"/>
        <result property="subjectName" column="music_group_subject_"/>
        <result property="courseBalance" column="course_balance_"/>
        <result property="balance" column="balance_"/>
        <result property="serviceTag" column="service_tag_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="operatingTag" column="operating_tag_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="teacherName" column="teacher_name_"/>
        <result property="teacherId" column="teacher_id_"/>
        <result property="subjectIdList" column="subject_id_list_"/>
        <result property="isNewUser" column="is_new_user_"/>
        <result property="isSignedContract" column="is_signed_contract_"/>
        <result property="memberRankSettingId" column="member_rank_setting_id_"/>
        <result column="care_package_" property="carePackage"/>
        <result column="come_on_package_" property="comeOnPackage"/>
        <result column="grade_type_" property="gradeType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="cooperation_organ_id_" property="cooperationOrganId"/>
        <result column="cooperation_organ_name_" property="cooperationOrganName"/>
        <result column="membership_end_time_" property="membershipEndTime"/>
    </resultMap>

    <sql id="queryCondition">
        <where>
            cgsm.user_id_ IS NOT NULL
            <if test="organID != null">
              AND s.organ_id_=#{organID}
            </if>
            <if test="musicGroupId != null">
                and mg.id_ = #{musicGroupId}
            </if>
            <if test="studentStatus != null">
                and cgsm.status_ = #{studentStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            </if>
            <if test="queryString != null">
                and (su.username_ like CONCAT("%",#{queryString},"%")
                    or su.phone_ like CONCAT("%",#{queryString},"%")
                  )
            </if>
        </where>
    </sql>
    <update id="updateUser" parameterType="com.ym.mec.auth.api.entity.SysUser">
        UPDATE sys_user
        <set>
            <if test="delFlag != null">
                del_flag_ = #{delFlag},
            </if>
            <if test="wxOpenid != null">
                wx_openid_ = #{wxOpenid},
            </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="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>
            <if test="idCardNo != null">
                id_card_no_ = #{idCardNo},
            </if>
            <if test="wechatId != null">
                wechat_id_ = #{wechatId},
            </if>
            <if test="realName != null">
                real_name_ = #{realName},
            </if>
        </set>
        WHERE id_ = #{id}
    </update>

    <select id="findStudentsByOrganId" resultMap="studentManageListDto">
        SELECT o.`name_` organ_name_,o.grade_type_,s.`user_id_` ,su.`username_` ,su.`phone_` parents_phone_,
        sut.name_ real_name_,su.`gender_` , su.organ_id_,
		tu.`real_name_` teacher_name_,CASE s.service_tag_ WHEN 2 THEN 0 ELSE s.service_tag_ END service_tag_ ,s.`operating_tag_` ,
        s.care_package_, s.come_on_package_, suca.`course_balance_` ,suca.balance_,
		sub.`name_` music_group_subject_ ,su.birthdate_,s.subject_id_list_,s.teacher_id_,s.current_grade_num_,s.current_class_,s.member_rank_setting_id_,
        CASE WHEN su.password_ IS NULL THEN FALSE ELSE TRUE END isActive_,s.is_new_user_,s.membership_end_time_,CASE WHEN sut.user_id_ IS NULL THEN 0 ELSE 1 END is_signed_contract_,
        s.cooperation_organ_id_,co.name_ cooperation_organ_name_
		FROM `student` s LEFT JOIN `sys_user` su ON s.`user_id_` = su.`id_`
		LEFT JOIN `organization` o ON o.`id_` = su.`organ_id_`
		LEFT JOIN `sys_user` tu ON tu.`id_` = s.`teacher_id_`
		LEFT JOIN `sys_user_cash_account` suca ON suca.`user_id_` = s.`user_id_`
		LEFT JOIN `subject` sub ON sub.id_ = s.`subject_id_list_`
		LEFT JOIN sys_user_tsign sut ON sut.user_id_ = s.user_id_
        LEFT JOIN cooperation_organ co ON s.cooperation_organ_id_=co.id_
        <include refid="findStudentsByOrganIdSql"/>
        ORDER BY su.create_time_ DESC
        <include refid="global.limit"/>
    </select>
    <sql id="findStudentsByOrganIdSql">
        <where>
                su.del_flag_ = 0
            <if test="organIds != null and organIds.length>0">
                AND su.organ_id_ IN
                <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
                    #{organId}
                </foreach>
            </if>
            <if test="search != null and search != ''">
                AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
            </if>
            <if test="isActive != null and isActive == true">
                AND su.password_ is not null
            </if>
            <if test="isActive != null and isActive == false">
                AND su.password_ is null
            </if>
            <if test="operatingTag != null">
                AND s.operating_tag_ = #{operatingTag}
            </if>
            <if test="serviceTag != null">
                <if test="serviceTag == 0">
                    AND s.service_tag_ IN (0, 2)
                </if>
                <if test="serviceTag == 1">
                    AND s.service_tag_ = 1
                </if>
            </if>
            <if test="hasMember != null">
                <if test="hasMember == 0">
                    AND s.member_rank_setting_id_ IS NULL
                </if>
                <if test="hasMember == 1">
                    AND s.member_rank_setting_id_ IS NOT NULL
                </if>
            </if>
            <if test="teacherId != null">
                AND s.teacher_id_ = #{teacherId}
            </if>
            <if test="isNewUser != null">
                AND s.is_new_user_ = #{isNewUser}
            </if>
            <if test="carePackage != null">
                AND s.care_package_ = #{carePackage}
            </if>
            <if test="comeOnPackage != null">
                AND s.come_on_package_ = #{comeOnPackage}
            </if>
            <if test="subjectId!=null">
                AND FIND_IN_SET( #{subjectId}, s.subject_id_list_ )
            </if>
            <if test="activityCourseType!=null and activityCourseType!=''">
                AND JSON_EXTRACT(activity_course_detail_, CONCAT('$.', #{activityCourseType}))>0
            </if>
        </where>
    </sql>

    <select id="countStudentByOrganId" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT su.id_)
        FROM `student` s LEFT JOIN `sys_user` su on s.`user_id_` = su.`id_`
       <include refid="findStudentsByOrganIdSql"/>
    </select>
    <select id="findStudentBaseInfoByUserID" resultMap="studentManageListDto">
        SELECT su.username_,su.gender_,su.birthdate_,su.real_name_,su.id_ user_id_,
        su.phone_ parents_phone_,sr.current_class_,sr.current_grade_,su.nation_
        FROM sys_user su
        LEFT JOIN student_registration sr ON su.id_ = sr.user_id_
        WHERE su.id_ =#{userId} AND su.user_type_ LIKE '%STUDENT%' LIMIT 1
    </select>

    <select id="findGoodsNamesByIds" resultType="string">
      SELECT name_ FROM goods WHERE id_ IN
      <foreach collection="ids" item="id" open="(" close=")" separator=",">
          #{id}
      </foreach>
    </select>

    <resultMap id="musicGroup" type="com.ym.mec.biz.dal.dto.StudentManageBaseInfoOfMusicGroupDto">
        <result property="musicGroupId" column="music_group_id_"/>
        <result property="musicGroupName" column="music_group_name_"/>
        <result property="musicGroupStatus" column="music_group_status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="joinMusicGroupDate" column="join_date_"/>
        <result property="subjectId" column="subject_id_"/>
        <result property="subjectName" column="subject_name_"/>
        <result property="kitPurchaseMethod" column="kit_purchase_method_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="depositFee" column="deposit_fee_"/>
        <result property="userId" column="user_id_"/>
        <result property="userMusicGroupStatus" column="user_music_group_status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    </resultMap>
    <select id="findStudentMusicGroupsByUserId" resultMap="musicGroup">
        SELECT mg.id_ music_group_id_,sr.create_time_ join_date_,mg.name_ music_group_name_,mg.status_ music_group_status_,
        s.id_ subject_id_,s.name_ subject_name_,sr.kit_purchase_method_,mgsp.deposit_fee_,sr.user_id_,sr.music_group_status_ user_music_group_status_
        FROM student_registration sr
        LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
        LEFT JOIN `subject` s ON s.id_ = sr.actual_subject_id_
        LEFT JOIN music_group_subject_plan mgsp ON mg.id_ = mgsp.music_group_id_ AND s.id_ = mgsp.subject_id_
        WHERE sr.user_id_=#{userId} AND (sr.music_group_status_ != 'QUIT' OR (sr.music_group_status_ = 'QUIT' AND mgsp.id_ IS NOT NULL))
        ORDER BY mg.create_time_ DESC
    </select>

    <sql id="studentManageCourseQueryCondition">
        <where>
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL) AND cs.pre_course_flag_ = 0
            AND cgsm.status_ != 'QUIT'
            <if test="studentId!=null">
                and cgsm.user_id_ = #{studentId}
            </if>
            <if test="musicGroupId!=null">
                and cg.music_group_id_ = #{musicGroupId} AND cg.group_type_='MUSIC'
            </if>
            <if test="classGroupType!=null">
                and cg.type_ = #{classGroupType}
            </if>
            <if test="courseStatus!=null">
                and cs.status_=#{courseStatus}
            </if>
            <if test="classGroupName!=null">
                and cg.name_ like CONCAT("%",#{classGroupName},"%")
            </if>
            <if test="teacherName!=null">
                and su.username_ like CONCAT("%",#{teacherName},"%")
            </if>
            <if test="vipGroupId!=null">
                and cg.music_group_id_ = #{vipGroupId} AND cg.group_type_='VIP'
            </if>
        </where>
    </sql>

    <select id="findStudentCourseList" resultMap="studentManageCourseListDto">
        SELECT
            cg.id_ class_group_id_,
            cg.name_ class_group_name_,
            cg.type_ class_group_type_,
            CONCAT(cs.class_date_," ",cs.start_class_time_) course_date_,
            cs.status_ course_status_,
            su.real_name_ teacher_name_,
            cs.teach_mode_
        FROM class_group cg
            LEFT JOIN class_group_student_mapper cgsm ON cg.id_=cgsm.class_group_id_
            LEFT JOIN course_schedule cs ON cg.id_=cs.class_group_id_
            LEFT JOIN sys_user su ON cs.teacher_id_=su.id_
        <include refid="studentManageCourseQueryCondition"/>
        ORDER BY course_date_
        <include refid="global.limit"/>
    </select>

    <select id="countStudentCourses" resultType="int">
        SELECT count(*) FROM class_group cg
        LEFT JOIN class_group_student_mapper cgsm ON cg.id_=cgsm.class_group_id_
        LEFT JOIN course_schedule cs ON cg.id_ = cs.class_group_id_
        LEFT JOIN sys_user su ON cs.teacher_id_=su.id_
        <include refid="studentManageCourseQueryCondition"/>
    </select>

    <sql id="studentManageAttendanceQueryCondition">
        <where>
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL) AND cs.pre_course_flag_ = 0
            <if test="studentId!=null">
                AND cssp.user_id_ = #{studentId}
            </if>
            <if test="courseStatus != null and courseStatus != ''">
                AND cs.status_ = #{courseStatus}
            </if>
            <if test="courseScheduleType!=null">
                AND cs.type_ = #{courseScheduleType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            </if>
            <if test="attendanceStatus != null and attendanceStatus != @com.ym.mec.biz.dal.enums.StudentAttendanceStatusEnum@TRUANT">
                AND sa.status_ = #{attendanceStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
            </if>
            <if test="attendanceStatus != null and attendanceStatus == @com.ym.mec.biz.dal.enums.StudentAttendanceStatusEnum@TRUANT">
                AND (sa.status_ = #{attendanceStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
                OR (sa.status_ IS NULL AND cs.status_!='NOT_START'))
            </if>
            <if test="classGroupName!=null">
                AND (cg.name_ LIKE CONCAT("%",#{classGroupName},"%") OR cs.name_ LIKE CONCAT("%",#{classGroupName},"%"))
            </if>
            <if test="teacherName!=null">
                AND su.real_name_ LIKE CONCAT("%",#{teacherName},"%")
            </if>
        </where>
    </sql>

    <select id="findStudentAttendances" resultMap="studentManageCourseListDto">
        SELECT
            cg.id_ class_group_id_,
            cg.name_ class_group_name_,
            cg.type_ class_group_type_,
            cs.type_ course_schedule_type_,
            CONCAT(cs.class_date_," ",cs.start_class_time_) course_date_,
            CONCAT(cs.class_date_," ",cs.end_class_time_) course_end_date_,
            cssp.course_schedule_id_,
            su.real_name_ teacher_name_,
            IF(sa.status_ IS NULL AND cs.status_!='NOT_START','TRUANT',sa.status_) status_,
            sa.current_class_times_,
            cg.total_class_times_,
            cs.status_ courseStatus,
            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 class_group cg ON cssp.class_group_id_ = cg.id_
            LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
            LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
        <include refid="studentManageAttendanceQueryCondition"/>
        ORDER BY course_date_ DESC
        <include refid="global.limit"/>
    </select>

    <select id="countStudentAttendances" 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 class_group cg ON cssp.class_group_id_ = cg.id_
        LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
        LEFT JOIN sys_user su ON cs.actual_teacher_id_ = su.id_
        <include refid="studentManageAttendanceQueryCondition"/>
    </select>

    <select id="getStudentAccountBaseInfo" resultMap="studentManageAccountBaseInfo">
        SELECT
            suca.balance_,
            suca.course_balance_,
            subc.bank_name_,
            subc.card_no_,
            suca.course_balance_
        FROM
            sys_user_cash_account suca
            LEFT JOIN sys_user_bank_card subc ON suca.user_id_ = subc.user_id_
            AND subc.is_default_ = 1
        WHERE
            suca.user_id_ =#{userId}
    </select>

    <resultMap id="StudentPaymentDto" type="com.ym.mec.biz.dal.dto.StudentPaymentDto">
        <result property="classDate" column="class_date_"/>
        <result property="startClassTime" column="start_class_time_"/>
        <result property="classGroupType" column="class_group_type_"/>
        <result property="classGroupName" column="class_group_name_"/>
        <result property="currentClassTimes" column="current_class_times_"/>
        <result property="totalClassTimes" column="total_class_times_"/>
        <result property="status" column="status_"/>
        <result property="expectPrice" column="expect_price_"/>
        <result property="actualPrice" column="actual_price_"/>
    </resultMap>
    <select id="queryStudentPayment" resultMap="StudentPaymentDto">
        SELECT cs.class_date_,cs.start_class_time_,cs.type_ class_group_type_ ,cg.name_ class_group_name_,
        cg.total_class_times_,sa.current_class_times_,IF(sa.status_ IS NULL,'TRUANT',sa.status_) status_,cssp.expect_price_,cssp.actual_price_
        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 sa.user_id_ = cssp.user_id_
        <include refid="studentPaymentSql"/>
        ORDER BY cs.class_date_ DESC,cs.start_class_time_ DESC
        <include refid="global.limit"/>
    </select>
    <sql id="studentPaymentSql">
        <where>
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL) AND cs.pre_course_flag_ = 0
            AND cs.id_ IS NOT NULL AND CONCAT(cs.class_date_,' ',cs.start_class_time_) &lt; NOW()
            <if test="classGroupType != null">
                AND cs.type_ = #{classGroupType}
            </if>
            <if test="classGroupName != null">
                AND cs.name_ = #{classGroupName}
            </if>
            <if test="attendanceStatus != null">
                AND sa.status_ = #{attendanceStatus}
            </if>
            <if test="studentId != null">
                AND cssp.user_id_ = #{studentId}
            </if>
        </where>
    </sql>
    <select id="countStudentPayment" resultType="java.lang.Integer">
        SELECT COUNT(cssp.id_)
        FROM course_schedule_student_payment cssp
        LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
        LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cssp.course_schedule_id_ AND sa.user_id_ = cssp.user_id_
        <include refid="studentPaymentSql"/>
    </select>

    <sql id="queryMusicGroupStudentSql">
        <where>
            <if test="search != null and search != ''">
                AND (su.id_ = #{search} OR su.username_ LIKE CONCAT("%",#{search},"%") OR su.phone_ LIKE CONCAT("%",#{search},"%"))
            </if>
            <if test="subjectId != null">
                AND sr.actual_subject_id_ = #{subjectId}
            </if>
            <if test="classGroupId != null">
                AND cgsm.class_group_id_ = #{classGroupId} AND sr.user_id_ = cgsm.user_id_ AND cgsm.status_ != 'QUIT'
            </if>
            <if test="studentStatus != null and studentStatus != ''">
                AND sr.music_group_status_ = #{studentStatus}
            </if>
            <if test="paymentStatus != null">
                AND sr.payment_status_ = #{paymentStatus}
            </if>
            <if test="musicGroupId != null and musicGroupId != ''">
                AND sr.music_group_id_ = #{musicGroupId}
            </if>
            <if test="isActive != null and isActive == true">
                and su.password_ is not null
            </if>
            <if test="isActive != null and isActive == false">
                and su.password_ is null
            </if>
            <if test="carePackage != null">
                AND stu.care_package_ = #{carePackage}
            </if>
            <if test="comeOnPackage != null">
                AND stu.come_on_package_ = #{comeOnPackage}
            </if>
            <if test="userIds != null">
                AND sr.user_id_ IN
                <foreach collection="userIds" open="(" close=")" item="item" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="currentGrade != null">
                AND sr.current_grade_ LIKE CONCAT('%',#{currentGrade},'%')
            </if>
            <if test="createYear != null">
                AND DATE_FORMAT(sr.create_time_,'%Y') =  #{createYear}
            </if>
        </where>
    </sql>
    <resultMap id="MusicGroupStudentsDto" type="com.ym.mec.biz.dal.dto.MusicGroupStudentsDto">
        <result property="studentRegistrationId" column="student_registration_id_"/>
        <result property="userId" column="user_id_"/>
        <result property="realName" column="real_name_"/>
        <result property="phone" column="parents_phone_"/>
        <result property="gender" column="gender_"/>
        <result property="currentGrade" column="current_grade_"/>
        <result property="currentGradeDate" column="current_grade_date_"/>
        <result property="currentClass" column="current_class_"/>
        <result property="subjectId" column="subject_id_"/>
        <result property="subjectName" column="subject_name_"/>
        <result property="regSubjectId" column="reg_subject_id_"/>
        <result property="regSubjectName" column="regSubjectName"/>
        <result property="studentStatus" column="student_status_"/>
        <result property="paymentStatus" column="payment_status_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="musicGroupId" column="music_group_id_"/>
        <result property="isNewStudent" column="is_new_student_"/>
        <result property="courseFee" column="course_fee_"/>
        <result property="nextPaymentDate" column="next_payment_date_"/>
        <result property="isActive" column="isActive_"/>
        <result property="isLock" column="is_lock_"/>
        <result property="paymentPeriodList" column="payment_period_list_"/>
        <result column="care_package_" property="carePackage"/>
        <result column="come_on_package_" property="comeOnPackage"/>
        <result column="registerTime" property="registerTime"/>
        <result column="remark_" property="remark"/>
    </resultMap>
    <select id="queryMusicGroupStudent" resultMap="MusicGroupStudentsDto">
        SELECT sr.id_ student_registration_id_,sr.user_id_,su.username_ real_name_,su.gender_,su.phone_ parents_phone_,sr.current_grade_,sr.current_grade_date_,
        sr.current_class_,sr.music_group_status_ student_status_,sr.payment_status_,sr.subject_id_ reg_subject_id_,rs.name_ regSubjectName,sr.remark_,
        sr.actual_subject_id_ subject_id_,s.name_ subject_name_,sr.music_group_id_,CASE WHEN su.password_ IS NULL THEN 0 ELSE 1 END isActive_,
        IF(DATE_FORMAT(sr.create_time_,'%Y-%m-%d') > DATE_FORMAT(mg.payment_expire_date_,'%Y-%m-%d'),1,0) is_new_student_,
        stu.care_package_,stu.come_on_package_,sr.create_time_ registerTime
        FROM student_registration sr
        LEFT JOIN sys_user su ON sr.user_id_ = su.id_
        LEFT JOIN subject s ON s.id_ = sr.actual_subject_id_
        LEFT JOIN subject rs ON rs.id_ = sr.subject_id_
        LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
        LEFT JOIN student stu ON sr.user_id_ = stu.user_id_
        <if test="classGroupId != null">
            LEFT JOIN class_group_student_mapper cgsm ON cgsm.music_group_id_ = sr.music_group_id_
        </if>
        <include refid="queryMusicGroupStudentSql"/>
        ORDER BY sr.id_ DESC
        <include refid="global.limit"/>
    </select>

    <select id="countMusicGroupStudent" 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 s.id_ = sr.actual_subject_id_
        LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
        <if test="classGroupId != null">
            LEFT JOIN class_group_student_mapper cgsm ON cgsm.music_group_id_ = sr.music_group_id_
        </if>
        <if test="carePackage != null or comeOnPackage != null">
            LEFT JOIN student stu ON sr.user_id_ = stu.user_id_
        </if>
        <include refid="queryMusicGroupStudentSql"/>
    </select>

    <select id="countStudyNum" resultType="java.lang.Integer">
        SELECT COUNT(sr.user_id_) FROM student_registration sr
        WHERE sr.music_group_id_ = #{musicGroupId}
        AND sr.payment_status_ = 2
        AND sr.music_group_status_ != 'QUIT'
    </select>

    <select id="countQuitNum" resultType="java.lang.Integer">
        SELECT COUNT(sr.user_id_) FROM student_registration sr
        WHERE sr.music_group_id_ = #{musicGroupId}
        AND sr.music_group_status_ = 'QUIT'
    </select>
    <select id="countAddNum" resultType="java.lang.Integer">
        SELECT COUNT(sr.user_id_) FROM student_registration sr
        LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
        WHERE sr.music_group_id_ = #{musicGroupId} AND sr.music_group_status_ != 'QUIT'
        AND DATE_FORMAT(sr.create_time_,'%Y-%m-%d') > DATE_FORMAT(mg.payment_expire_date_,'%Y-%m-%d')
    </select>

    <resultMap id="MusicGroupStudentSignDto" type="com.ym.mec.biz.dal.dto.MusicGroupStudentSignDto">
        <result property="signTime" column="create_time_"/>
        <result property="name" column="real_name_"/>
        <result property="signStatus" column="status_"/>
        <result property="courseScheduleName" column="name_"/>
        <result property="classGroupName" column="class_group_name_"/>
    </resultMap>
    <select id="queryMusicGroupStudentsSign" resultMap="MusicGroupStudentSignDto">
        SELECT sa.create_time_,su.username_ real_name_,sa.status_,cs.name_,cg.name_ class_group_name_
        FROM student_attendance sa
        LEFT JOIN sys_user su ON sa.user_id_ = su.id_
        LEFT JOIN course_schedule cs ON sa.course_schedule_id_ = cs.id_
        LEFT JOIN class_group cg ON sa.class_group_id_=cg.id_
        <include refid="queryMusicGroupStudentsSignSql"/>
        <include refid="global.limit"/>
    </select>

    <sql id="queryMusicGroupStudentsSignSql">
        <where>
            (cs.del_flag_ != 1 OR cs.del_flag_ IS NULL) AND cs.pre_course_flag_ = 0
            <if test="musicGroupId != null">
                AND sa.music_group_id_ = #{musicGroupId}
            </if>
            <if test="courseScheduleName != null">
                AND cs.name_ LIKE CONCAT('%',#{courseScheduleName},'%')
            </if>
            <if test="startTime != null">
                AND sa.create_time_ &gt;= #{startTime}
            </if>
            <if test="endTime != null">
                AND sa.create_time_ &lt;= #{endTime}
            </if>
            <if test="signStatus != null">
                AND sa.status_ = #{signStatus}
            </if>
            <if test="userName != null">
                AND su.username_ LIKE CONCAT('%',#{userName},'%')
            </if>
            <if test="classGroupId != null">
                AND sa.class_group_id_ = #{classGroupId}
            </if>
        </where>
    </sql>

    <select id="countMusicGroupStudentsSign" resultType="java.lang.Integer">
        SELECT COUNT(sa.id_)
        FROM student_attendance sa
        LEFT JOIN sys_user su ON sa.user_id_ = su.id_
        LEFT JOIN course_schedule cs ON sa.course_schedule_id_ = cs.id_
        <include refid="queryMusicGroupStudentsSignSql"/>
    </select>
    <resultMap id="StudentManageVipGroupClassDto" type="com.ym.mec.biz.dal.dto.StudentManageVipGroupClassDto">
        <result property="vipGroupId" column="id_"/>
        <result property="vipGroupName" column="vip_group_name_"/>
        <result property="vipGroupStatus" column="status_"/>
        <result property="teacherId" column="user_id_"/>
        <result property="eduTeacherId" column="educational_teacher_id_"/>
        <result property="studentNum" column="student_num_"/>
        <result property="activeName" column="name_"/>
        <result property="courseStartDate" column="courses_start_date"/>
        <result property="currentClassTimes" column="current_class_times_"/>
        <result property="totalClassTimes" column="total_class_times_"/>
    </resultMap>
    <select id="findStudentVipGroupClass" resultMap="StudentManageVipGroupClassDto">
        SELECT vg.id_,vg.name_ vip_group_name_,vg.group_status_ status_,vg.user_id_,vg.educational_teacher_id_,cg.student_num_,
        vgc.name_,vg.courses_start_date,cg.current_class_times_,cg.total_class_times_
        FROM class_group_student_mapper cgsm
        LEFT JOIN class_group cg ON cgsm.class_group_id_ = cg.id_
        LEFT JOIN vip_group vg ON cg.music_group_id_ = vg.id_
        LEFT JOIN vip_group_activity vgc ON vgc.id_ = vg.vip_group_activity_id_
        WHERE cg.group_type_ = 'VIP' AND cgsm.user_id_ = #{studentId} AND vg.group_status_ != 3
        <if test="vipGroupName != null">
            AND vg.name_ LIKE CONCAT('%',#{vipGroupName},'%')
        </if>
        <if test="vipGroupStatus != null">
            AND vg.group_status_ = #{vipGroupStatus}
        </if>
        ORDER BY vg.create_time_ DESC
        <include refid="global.limit"/>
    </select>
    <select id="countStudentVipGroupClass" resultType="java.lang.Integer">
        SELECT COUNT(vg.id_)
        FROM class_group_student_mapper cgsm
        LEFT JOIN class_group cg ON cgsm.class_group_id_ = cg.id_
        LEFT JOIN vip_group vg ON cg.music_group_id_ = vg.id_
        WHERE cg.group_type_ = 'VIP' AND cgsm.user_id_ = #{studentId} AND vg.group_status_ != 3
        <if test="vipGroupName != null">
            AND vg.name_ LIKE CONCAT('%',#{vipGroupName},'%')
        </if>
        <if test="vipGroupStatus != null">
            AND vg.group_status_ = #{vipGroupStatus}
        </if>
    </select>
    <sql id="queryHasCourseSql">
        <if test="userIds != null">
            AND su.id_ IN
            <foreach collection="userIds" open="(" close=")" separator="," item="item">
                #{item}
            </foreach>
        </if>
        <if test="organId != null and organId != ''">
            AND FIND_IN_SET(su.organ_id_,#{organId})
        </if>
        <if test="search != null and search != ''">
            AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="isActive != null and isActive == true">
            AND su.password_ IS NOT NULL
        </if>
        <if test="isActive != null and isActive == false">
            AND su.password_ IS NULL
        </if>
        <if test="isMake != null and isMake == true">
            AND pla.id_ IS NOT NULL
        </if>
        <if test="isMake != null and isMake == false">
            AND pla.id_ IS NULL
        </if>
        <if test="operatingTag != null">
            AND st.operating_tag_ = #{operatingTag}
        </if>
        <if test="serviceTag != null">
            AND st.service_tag_ = #{serviceTag}
        </if>
        <if test="teacherId != null">
            AND st.teacher_id_ = #{teacherId}
        </if>
    </sql>
    <resultMap id="StudentHasCourseDtoMap" type="com.ym.mec.biz.dal.dto.StudentHasCourseDto">
        <result property="userName" column="username_"/>
        <result property="musicGroupName" column="music_group_name_"/>
        <result property="vipGroupName" column="vip_group_name_"/>
        <result property="organName" column="organ_name_"/>
        <result property="subjectName" column="music_group_subject_"/>
        <result property="userId" column="id_"/>
        <result property="isActive" column="is_active_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result property="isMake" column="is_make_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
    </resultMap>
    
    <select id="queryHasCourseStudent" resultMap="studentManageListDto">
        SELECT su.id_ user_id_,su.username_,su.gender_,GROUP_CONCAT(DISTINCT sr.parents_name_)parents_name_,
        GROUP_CONCAT(DISTINCT sr.parents_phone_)parents_phone_,
        GROUP_CONCAT(DISTINCT mg.name_) music_group_name_,
        GROUP_CONCAT(DISTINCT CASE WHEN sr.music_group_status_ = 'NORMAL' THEN '在读'
        WHEN sr.music_group_status_ = 'LEAVE' THEN '请假'
        WHEN sr.music_group_status_ = 'QUIT' THEN '退班'
        WHEN sr.music_group_status_ = 'QUIT_SCHOOL' THEN '休学' ELSE NULL END) music_group_status_,
        GROUP_CONCAT(DISTINCT vg.name_) vip_group_name_,
        GROUP_CONCAT(DISTINCT CASE WHEN cgsm.status_ = 'NORMAL' THEN '在读'
        WHEN cgsm.status_ = 'LEAVE' THEN '请假'
        WHEN cgsm.status_ = 'QUIT' THEN '退班'
        WHEN cgsm.status_ = 'QUIT_SCHOOL' THEN '休学' ELSE NULL END) vip_group_status_,
        GROUP_CONCAT(DISTINCT o.name_) organ_name_,
        GROUP_CONCAT(DISTINCT s.name_) music_group_subject_,
        CASE WHEN GROUP_CONCAT(DISTINCT cs.id_) IS NULL THEN 0 ELSE 1 END hasCourse_,
        CASE WHEN GROUP_CONCAT(DISTINCT pla.id_) IS NULL THEN 0 ELSE 1 END isMake_,
        CASE WHEN su.password_ IS NULL THEN 0 ELSE 1 END isActive_,
        CASE WHEN GROUP_CONCAT(DISTINCT cssp1.id_) IS NULL THEN 0 ELSE 1 END hasPracticeCourse_,
        suca.course_balance_
        FROM sys_user su
        LEFT JOIN course_schedule_student_payment cssp ON su.id_ = cssp.user_id_
        LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_ AND cs.status_ != 'OVER'
        LEFT JOIN music_group mg ON cssp.music_group_id_ = mg.id_ AND cssp.group_type_ = 'MUSIC'
        LEFT JOIN vip_group vg ON cssp.music_group_id_ = vg.id_ AND cssp.group_type_ = 'VIP'
        LEFT JOIN organization o ON su.organ_id_ = o.id_
        LEFT JOIN student_registration sr ON su.id_ = sr.user_id_ AND cssp.music_group_id_ = sr.music_group_id_
        LEFT JOIN `subject` s ON s.id_ = sr.actual_subject_id_
        LEFT JOIN practice_lesson_apply pla on pla.user_id_ = su.id_
        LEFT JOIN course_schedule_student_payment cssp1 ON su.id_ = cssp1.user_id_ AND cssp1.group_type_ = 'PRACTICE'
        LEFT JOIN class_group_student_mapper cgsm ON su.id_ = cgsm.user_id_ AND cgsm.group_type_ = 'VIP'
        LEFT JOIN sys_user_cash_account suca ON su.id_ = suca.user_id_
        WHERE su.user_type_ LIKE '%STUDENT%' AND cs.pre_course_flag_ = 0
        <if test="hasPracticeCourse != null and hasPracticeCourse == true">
            AND cssp1.id_ IS NOT NULL
        </if>
        <if test="hasPracticeCourse != null and hasPracticeCourse == false">
            AND cssp1.id_ IS NULL
        </if>
        <if test="hasCourse != null and hasCourse == true">
            AND cs.id_ IS NOT NULL
        </if>
        <if test="hasCourse != null and hasCourse == false">
            AND cs.id_ IS NULL
        </if>
        <if test="isActive != null and isActive == true">
            AND su.password_ IS NOT NULL
        </if>
        <if test="isActive != null and isActive == false">
            AND su.password_ IS NULL
        </if>
        <if test="organId != null and organId != ''">
            AND FIND_IN_SET(su.organ_id_,#{organId})
        </if>
        <if test="search != null and search != ''">
            AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="isMake != null and isMake == true">
            AND pla.id_ IS NOT NULL
        </if>
        <if test="isMake != null and isMake == false">
            AND pla.id_ IS NULL
        </if>
        GROUP BY su.id_
    </select>
    <select id="countStudentSignInNum" resultType="java.lang.Integer">
        SELECT COUNT(id_) FROM student_attendance WHERE course_schedule_id_ = #{courseScheduleId} AND status_ = #{status}
    </select>
    <select id="countHomeworkNum" resultType="java.lang.Integer">
        SELECT COUNT(id_) FROM student_course_homework WHERE course_schedule_id_ = #{courseScheduleId} AND status_ = 1
    </select>
    <select id="countRepliedNum" resultType="java.lang.Integer">
        SELECT COUNT(id_) FROM student_course_homework WHERE course_schedule_id_ = #{courseScheduleId} AND is_replied_ = 1 AND status_ = 1
    </select>

    <sql id="queryHasPracticeCourseSql">
        <if test="organId != null">
            AND FIND_IN_SET(su.organ_id_,#{organId})
        </if>
        <if test="search != null and search != ''">
            AND (su.phone_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.id_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="isActive != null and isActive == true">
            AND su.password_ IS NOT NULL
        </if>
        <if test="isActive != null and isActive == false">
            AND su.password_ IS NULL
        </if>
    </sql>
    <select id="getHasPracticeCourse" resultType="java.util.Map">
        SELECT cssp.user_id_ 'key',COUNT(DISTINCT cssp.user_id_) 'value' FROM course_schedule_student_payment cssp
        WHERE cssp.group_type_ = 'PRACTICE' AND cssp.user_id_ IN
        <foreach collection="userIds" separator="," open="(" close=")" item="item">
            #{item}
        </foreach>
        GROUP BY cssp.user_id_
    </select>
    <select id="getIsActive" resultType="java.util.Map">
        SELECT su.id_ 'key',COUNT(su.id_) 'value' FROM sys_user su
        WHERE su.user_type_ LIKE '%STUDENT%' AND su.del_flag_ = 0 AND su.password_ IS NULL AND su.id_ IN
        <foreach collection="userIds" separator="," open="(" close=")" item="item">
            #{item}
        </foreach>
        GROUP BY su.id_
    </select>
    <select id="getIsMake" resultType="java.util.Map">
        SELECT pla.user_id_ 'key',pla.user_id_ 'value' FROM practice_lesson_apply pla
        WHERE pla.user_id_ IN
        <foreach collection="userIds" separator="," open="(" close=")" item="item">
            #{item}
        </foreach>
    </select>
    <select id="querySubjectNames" resultType="java.util.Map">
        SELECT sr.user_id_ 'key',GROUP_CONCAT(s.name_) 'value' FROM student_registration sr
		LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
		LEFT JOIN `subject` s ON sr.actual_subject_id_ = s.id_
		WHERE mg.status_ = 'PROGRESS' AND sr.user_id_ IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
		GROUP BY sr.user_id_
    </select>
    
    <select id="queryCanAddStudent" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        select su.id_ user_id_,su.username_,su.phone_,s.name_ subject_name_ from student_registration sr 
        LEFT JOIN sys_user su ON su.id_ = sr.user_id_
        LEFT JOIN `subject` s ON s.id_ = sr.actual_subject_id_
        WHERE sr.music_group_id_ = #{musicGroupId} AND sr.music_group_status_ = 'NORMAL' AND sr.user_id_ NOT IN (
        SELECT DISTINCT mgpcd.user_id_ FROM music_group_payment_calender_detail mgpcd
        LEFT JOIN music_group_payment_calender mgpc on mgpcd.music_group_payment_calender_id_ = mgpc.id_
        WHERE mgpc.batch_no_ = #{batchNo} and mgpc.music_group_id_ = #{musicGroupId}
        )
        <if test="search != null and search != ''">
            AND (sr.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%'))
        </if>
        <if test="subjectId != null">
            AND sr.actual_subject_id_ = #{subjectId}
        </if>
    </select>
    
    <select id="queryHasCourseMap" resultType="java.util.Map">
        SELECT su.id_ 'key',COUNT(DISTINCT su.id_) 'value' FROM sys_user su
        LEFT JOIN course_schedule_student_payment cssp ON cssp.user_id_ = su.id_
        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
        WHERE cs.status_ != 'OVER' AND cs.pre_course_flag_ = 0 AND su.id_ IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
        GROUP BY su.id_
    </select>
    
    <select id="queryStudentRemianCourse" resultMap="StudentListCourseDto">
    	SELECT cssp.`user_id_` userId,count(cssp.`id_`) remainCourseNum,sum(case when cs.`group_type_` = 'PRACTICE' then 1 else 0 end) remainPracticeNum,
        sum(case when cs.`group_type_` = 'VIP' then 1 else 0 end) remainVipNum
        FROM `course_schedule_student_payment` cssp LEFT JOIN `course_schedule` cs on cssp.`course_schedule_id_` = cs.`id_`
		WHERE cs.`status_` = 'NOT_START' AND cssp.`user_id_` IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
		GROUP BY cssp.`user_id_`
    </select>

    <select id="queryVipGroupStudents" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.id_ user_id_,su.username_,su.phone_,su.avatar_ head_url_,su.gender_ FROM
        vip_group vg
        LEFT JOIN class_group_student_mapper cgsm ON vg.id_ = cgsm.music_group_id_
        LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
        WHERE cgsm.group_type_ = 'VIP' AND cgsm.status_ != 'QUIT'
        AND vg.educational_teacher_id_ = #{teacherId}
        AND vg.group_status_ IN (0,1,2,5)
        <if test="search != null and search != ''">
            AND (su.id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
        </if>
        GROUP BY cgsm.user_id_
        <include refid="global.limit"/>
    </select>

    <select id="queryPracticeGroupStudents" resultMap="com.ym.mec.biz.dal.dao.MusicGroupDao.BasicUserDto">
        SELECT su.id_ user_id_,su.username_,su.phone_,su.avatar_ head_url_,su.gender_ FROM
        practice_group pg
        LEFT JOIN class_group_student_mapper cgsm ON pg.id_ = cgsm.music_group_id_
        LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
        WHERE cgsm.group_type_ = 'PRACTICE' AND cgsm.status_ != 'QUIT'
        AND pg.educational_teacher_id_ = #{teacherId}
        AND pg.group_status_ NOT IN ('FINISH','CANCEL')
        <if test="search != null and search != ''">
            AND (su.id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
        </if>
        GROUP BY cgsm.user_id_
        <include refid="global.limit"/>
    </select>

    <select id="countVipGroupStudents" resultType="int">
        SELECT COUNT(DISTINCT cgsm.user_id_) FROM
        vip_group vg
        LEFT JOIN class_group_student_mapper cgsm ON vg.id_ = cgsm.music_group_id_
        LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
        WHERE cgsm.group_type_ = 'VIP' AND cgsm.status_ != 'QUIT'
        AND vg.educational_teacher_id_ = #{teacherId}
        AND vg.group_status_ IN (0,1,2,5)
        <if test="search != null and search != ''">
            AND (su.id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
        </if>
    </select>

    <select id="countPracticeGroupStudents" resultType="int">
        SELECT COUNT(DISTINCT cgsm.user_id_) FROM
        practice_group pg
        LEFT JOIN class_group_student_mapper cgsm ON pg.id_ = cgsm.music_group_id_
        LEFT JOIN sys_user su ON cgsm.user_id_ = su.id_
        WHERE cgsm.group_type_ = 'PRACTICE' AND cgsm.status_ != 'QUIT'
        AND pg.educational_teacher_id_ = #{teacherId}
        AND pg.group_status_ NOT IN ('FINISH','CANCEL')
        <if test="search != null and search != ''">
            AND (su.id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
        </if>
    </select>

    <select id="getStudentSubject" resultMap="com.ym.mec.biz.dal.dao.SubjectDao.Subject">
        SELECT s.user_id_ id_ ,GROUP_CONCAT(sj.name_) name_ FROM student s
        LEFT JOIN subject sj ON FIND_IN_SET(sj.id_,s.subject_id_list_)
        WHERE s.user_id_ IN
        <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
        GROUP BY s.user_id_
    </select>
</mapper>
