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

	<resultMap type="com.ym.mec.biz.dal.entity.IndexBaseMonthData" id="IndexBaseMonthData">
		<result column="id_" property="id" />
		<result column="month_" property="month" />
		<result column="month_" property="monthStr" />
		<result column="organ_id_" property="organId" />
		<result column="organ_name_" property="organName" />
		<result column="total_num_" property="totalNum" />
		<result column="activate_num_" property="activateNum" />
		<result column="percent_" property="percent" />
		<result column="data_type_" property="dataType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result column="extend_info_" property="extendInfo"/>
		<result column="order_type_" property="orderType"/>
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="IndexBaseMonthData" >
		SELECT * FROM index_base_month_data WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="IndexBaseMonthData">
		SELECT * FROM index_base_month_data where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

	<select id="getOrganDataWithDayAndDataType" resultMap="IndexBaseMonthData">
		SELECT * FROM index_base_month_data WHERE organ_id_=#{organId} AND month_ = #{day}
		AND data_type_=#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} ORDER BY month_ DESC LIMIT 1;
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.IndexBaseMonthData" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO index_base_month_data (month_,organ_id_,total_num_,activate_num_,percent_,data_type_,extend_info_,create_time_,update_time_,tenant_id_)
		VALUES(#{month},#{organId},#{totalNum},#{activateNum},#{percent},#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{extendInfo},NOW(),NOW(),#{tenantId})
	</insert>

	<insert id="batchInsertWithDataType" parameterType="com.ym.mec.biz.dal.entity.IndexBaseMonthData" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO index_base_month_data (month_,organ_id_,total_num_,activate_num_,percent_,data_type_,extend_info_,create_time_,update_time_,tenant_id_)
		VALUES
		<foreach collection="datas" item="data" separator=",">
			(#{data.month},#{data.organId},#{data.totalNum},#{data.activateNum},#{data.percent},
			#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{data.extendInfo},NOW(),NOW(),#{data.tenantId})
		</foreach>
	</insert>

	<insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.IndexBaseMonthData" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO index_base_month_data (month_,organ_id_,total_num_,activate_num_,percent_,data_type_,extend_info_,create_time_,update_time_,tenant_id_)
		VALUES
		<foreach collection="datas" item="data" separator=",">
			(#{data.month},#{data.organId},#{data.totalNum},#{data.activateNum},#{data.percent},
			#{data.dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{data.extendInfo},NOW(),NOW(),#{tenantId})
		</foreach>
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.IndexBaseMonthData">
		UPDATE index_base_month_data
		<set>
			<if test="organId != null">
				organ_id_ = #{organId},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="activateNum != null">
				activate_num_ = #{activateNum},
			</if>
			<if test="totalNum != null">
				total_num_ = #{totalNum},
			</if>
			<if test="percent != null">
				percent_ = #{percent},
			</if>
			<if test="month != null">
				month_ = #{month},
			</if>
			<if test="dataType != null">
				data_type_ = #{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="extendInfo != null">
				extend_info_ = #{extendInfo},
			</if>
			update_time_ = NOW()
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

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

	<delete id="deleteWithMonthAndType">
		DELETE FROM index_base_month_data
		WHERE tenant_id_ = #{tenantId} AND month_ IN
		<foreach collection="months" item="month" open="(" close=")" separator=",">
			#{month}
		</foreach>
		<if test="dataType!=null">
			AND data_type_=#{dataType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
		</if>
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="IndexBaseMonthData" parameterType="map">
		SELECT * FROM index_base_month_data where tenant_id_ = #{tenantId} ORDER BY id_ <include refid="global.limit"/>
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM index_base_month_data where tenant_id_ = #{tenantId}
	</select>

    <select id="getIndexBaseData" resultMap="IndexBaseMonthData">
		SELECT
			month_,data_type_,SUM(total_num_) total_num_,SUM(activate_num_) activate_num_,SUM(percent_) percent_
		FROM index_base_month_data
		<where>
			tenant_id_ = #{tenantId}
			<if test="dataTypes!=null and dataTypes.size()>0">
				AND data_type_ IN
				<foreach collection="dataTypes" item="dataType" open="(" close=")" separator=",">
					#{dataType}
				</foreach>
			</if>
			<if test="organIds!=null and organIds.size()>0">
				AND organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
			<if test="startMonth!=null and startMonth!=''">
				AND month_&gt;=#{startMonth}
			</if>
			<if test="endMonth!=null and endMonth!=''">
				AND month_&lt;=#{endMonth}
			</if>
		</where>
		GROUP BY month_,data_type_
	</select>

	<select id="getAllIndexBaseData" resultMap="IndexBaseMonthData">
		SELECT
			*
		FROM index_base_month_data
		<where>
			tenant_id_ = #{tenantId}
			<if test="dataTypes!=null and dataTypes.size()>0">
				AND data_type_ IN
				<foreach collection="dataTypes" item="dataType" open="(" close=")" separator=",">
					#{dataType}
				</foreach>
			</if>
			<if test="organIds!=null and organIds.size()>0">
				AND organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
			<if test="startMonth!=null and startMonth!=''">
				AND month_&gt;=#{startMonth}
			</if>
			<if test="endMonth!=null and endMonth!=''">
				AND month_&lt;=#{endMonth}
			</if>
		</where>
	</select>

	<select id="getVipCourseDataList" resultMap="IndexBaseMonthData">
		SELECT
			month_,
			organ_id_,
			data_type_,
			extend_info_
		FROM index_base_month_data
		FORCE INDEX(data_type_, month_)
			<where>
				tenant_id_ = #{tenantId}
				<if test="dataTypes!=null and dataTypes.size()>0">
					AND data_type_ IN
					<foreach collection="dataTypes" item="dataType" open="(" close=")" separator=",">
						#{dataType}
					</foreach>
				</if>
				<if test="organIds!=null and organIds.size()>0">
					AND organ_id_ IN
					<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
						#{organId}
					</foreach>
				</if>
				<if test="startMonth!=null and startMonth!=''">
					AND month_&gt;=#{startMonth}
				</if>
				<if test="endMonth!=null and endMonth!=''">
					AND month_&lt;=#{endMonth}
				</if>
				AND extend_info_ IS NOT NULL
			</where>
	</select>

	<select id="getWithDayAndDataType" resultMap="IndexBaseMonthData">
		SELECT
			*
		FROM index_base_month_data
		WHERE tenant_id_ = #{tenantId}
			AND data_type_ = #{dataType}
			AND month_&gt;=#{day}
	</select>

	<select id="getStudentSignUpData" resultMap="IndexBaseMonthData">
		SELECT
			organ_id_,su.tenant_id_,
			#{dayStr} month_,
			COUNT( id_ ) total_num_,
			COUNT(CASE WHEN password_ IS NOT NULL THEN id_ ELSE NULL END) activate_num_,
			TRUNCATE(COUNT(CASE WHEN password_ IS NOT NULL THEN id_ ELSE NULL END)/COUNT( id_ )*100, 2) percent_
		FROM
			((
				 SELECT DISTINCT
					 sr.user_id_
				 FROM
					 student_registration sr
					LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
				 WHERE
					 mg.status_ IN ( 'PREPARE', 'PROGRESS' )
				   AND sr.music_group_status_ = 'NORMAL'
				   AND DATE_FORMAT(sr.create_time_, '%Y-%m-%d')&lt;=#{dayStr}
			 ) UNION ALL
			(
			 SELECT DISTINCT
				 cssp.user_id_
			 FROM
				course_schedule_student_payment cssp
				LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
			 WHERE
				 cs.del_flag_ = 0 AND cs.pre_course_flag_ = 0
			   AND ( cs.is_lock_ = 0 OR cs.is_lock_ IS NULL )
			   AND ( cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_ )
			   AND cssp.group_type_ IN ('VIP', 'PRACTICE')
			   AND cs.organ_id_ IS NOT NULL
			   AND DATE_FORMAT(cssp.create_time_, '%Y-%m-%d')&lt;=#{dayStr}
				AND cs.class_date_ &gt;= #{courseStartDay}
			)) u
			LEFT JOIN sys_user su ON u.user_id_ = su.id_
		WHERE
			del_flag_=0 and su.tenant_id_ = #{tenantId}
		  	AND organ_id_ IS NOT NULL
			AND user_type_ LIKE '%STUDENT%'
		GROUP BY organ_id_
		ORDER BY organ_id_;
	</select>

	<select id="getStudentRegistrationData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,su.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT stu.user_id_ ) total_num_,
			COUNT( DISTINCT stu.user_id_ ) activate_num_,
			COUNT( DISTINCT stu.user_id_ ) percent_
		FROM
			student stu
			LEFT JOIN sys_user su ON stu.user_id_=su.id_
		WHERE
			su.del_flag_=0 and su.tenant_id_ = #{tenantId}
		  AND su.organ_id_ IS NOT NULL
		  AND su.user_type_ LIKE '%STUDENT%'
		  AND DATE_FORMAT(stu.create_time_, '%Y-%m-%d')&lt;=#{dayStr}
		GROUP BY organ_id_
		ORDER BY organ_id_;
	</select>

	<select id="getAddStudentRegistrationData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,stu.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT stu.user_id_ ) total_num_,
			COUNT( DISTINCT stu.user_id_ ) activate_num_,
			COUNT( DISTINCT stu.user_id_ ) percent_
		FROM
			student stu
			LEFT JOIN sys_user su ON stu.user_id_=su.id_
		WHERE
			su.del_flag_=0 and su.tenant_id_ = #{tenantId}
		  AND su.organ_id_ IS NOT NULL
		  AND su.user_type_ LIKE '%STUDENT%'
		  AND DATE_FORMAT(stu.create_time_, '%Y-%m-%d')=#{dayStr}
		GROUP BY organ_id_
		ORDER BY organ_id_;
	</select>

	<select id="getChargeStudentChangeData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,su.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT stu.user_id_ ) total_num_,
			COUNT( DISTINCT (CASE WHEN DATE_FORMAT( spo.create_time_, '%Y-%m-%d' ) &lt;= #{dayStr} THEN spo.user_id_ ELSE NULL END) ) activate_num_,
			TRUNCATE(COUNT(DISTINCT (CASE WHEN DATE_FORMAT( spo.create_time_, '%Y-%m-%d' ) &lt;= #{dayStr} THEN spo.user_id_ ELSE NULL END))/COUNT(DISTINCT stu.user_id_)*100, 2) percent_
		FROM
			student stu
			LEFT JOIN sys_user su ON stu.user_id_=su.id_
			LEFT JOIN student_payment_order spo ON stu.user_id_=spo.user_id_ AND status_='SUCCESS' AND actual_amount_>0
		WHERE
			su.del_flag_=0 and su.tenant_id_ = #{tenantId}
			  AND su.organ_id_ IS NOT NULL
			  AND su.user_type_ LIKE '%STUDENT%'
			  AND DATE_FORMAT(stu.create_time_, '%Y-%m-%d')&lt;=#{dayStr}
		GROUP BY organ_id_
		ORDER BY organ_id_;
	</select>

	<select id="getHomeworkData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,su.tenant_id_,
			sees.monday_ month_,
			<choose>
				<when test="type == 'submit'">
					SUM(sees.actual_exercises_num_) total_num_,
					SUM(sees.exercises_reply_num_) activate_num_,
					TRUNCATE(SUM(sees.exercises_reply_num_)/SUM(sees.actual_exercises_num_)*100, 2) percent_
				</when>
				<when test="type == 'comment'">
					SUM(sees.exercises_reply_num_) total_num_,
					SUM(sees.exercises_message_num_) activate_num_,
					TRUNCATE(SUM(sees.exercises_message_num_)/SUM(sees.exercises_reply_num_)*100, 2) percent_
				</when>
				<otherwise>
					SUM(sees.expect_exercises_num_-sees.not_over_course_num_) total_num_,
					SUM(sees.actual_exercises_num_) activate_num_,
					TRUNCATE(SUM(sees.actual_exercises_num_)/SUM(sees.expect_exercises_num_-sees.not_over_course_num_)*100, 2) percent_
				</otherwise>
			</choose>
		FROM student_extracurricular_exercises_situation_ sees
		LEFT JOIN sys_user su ON sees.student_id_=su.id_
		LEFT JOIN teacher tea ON sees.teacher_id_=tea.id_
		WHERE su.del_flag_=0 and su.tenant_id_ = #{tenantId}
		  	AND tea.job_nature_='FULL_TIME'
			AND su.organ_id_ IS NOT NULL
			AND DATE_FORMAT(sees.monday_, '%Y-%m-%d')&lt;=#{dayStr}
			AND DATE_FORMAT(sees.sunday_, '%Y-%m-%d')&gt;=#{dayStr}
		GROUP BY su.organ_id_
		ORDER BY su.organ_id_
	</select>

	<select id="getSchoolData" resultMap="IndexBaseMonthData">
		SELECT
			mg.organ_id_,mg.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT mg.cooperation_organ_id_ ) total_num_,
			COUNT( DISTINCT mg.cooperation_organ_id_ ) activate_num_,
			COUNT( DISTINCT mg.cooperation_organ_id_ ) percent_
		FROM
			music_group mg
		WHERE
			mg.del_flag_ = 0 and mg.tenant_id_ = #{tenantId}
			AND mg.organ_id_ IS NOT NULL
			AND mg.status_ = 'PROGRESS'
			AND DATE_FORMAT(mg.create_time_, '%Y-%m-%d')&lt;=#{dayStr}
		GROUP BY
			mg.organ_id_
		ORDER BY
			mg.organ_id_;
	</select>
	<select id="getMusicData" resultMap="IndexBaseMonthData">
		SELECT
			organ_id_,tenant_id_,
			#{dayStr} month_,
			COUNT( id_ ) total_num_,
			COUNT( id_ ) activate_num_,
			COUNT( id_ ) percent_
		FROM
			music_group
		WHERE
			del_flag_ = 0 and tenant_id_ = #{tenantId}
			AND status_ = 'PROGRESS'
			AND organ_id_ IS NOT NULL
			<if test="dayStr!=null and dayStr!=''">
				AND DATE_FORMAT(create_time_, '%Y-%m-%d') &lt;= #{dayStr}
			</if>
		GROUP BY
			organ_id_
		ORDER BY
			organ_id_;
	</select>
	<select id="getMusicStudentData" resultMap="IndexBaseMonthData">
		SELECT
			mg.organ_id_,sr.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT sr.user_id_ ) total_num_,
			COUNT( DISTINCT sr.user_id_ ) activate_num_,
			COUNT( DISTINCT sr.user_id_ ) percent_
		FROM student_registration sr
			LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
		WHERE
			mg.del_flag_ = 0 and mg.tenant_id_ = #{tenantId}
		  	AND mg.organ_id_ IS NOT NULL
			AND mg.status_ = 'PROGRESS'
			<if test="type==null">
				AND sr.music_group_status_='NORMAL'
			</if>
			<if test="type!=null and type=='QUIT'">
				AND sr.music_group_status_='QUIT'
				AND DATE_FORMAT(sr.create_time_, '%Y-%m') &gt;= CONCAT(DATE_FORMAT(NOW(), '%Y'), '-01')
			</if>
			<if test="type!=null and type=='ADD'">
				AND sr.music_group_status_='NORMAL'
				AND DATE_FORMAT(sr.create_time_, '%Y-%m') &gt;= CONCAT(DATE_FORMAT(NOW(), '%Y'), '-01')
			</if>
			<if test="dayStr!=null and dayStr!=''">
				AND DATE_FORMAT(sr.create_time_, '%Y-%m-%d') &lt;= #{dayStr}
			</if>
		GROUP BY
			mg.organ_id_
		ORDER BY
			mg.organ_id_;
	</select>

	<select id="getTeacherData" resultMap="IndexBaseMonthData">
		SELECT
			t.organ_id_,t.tenant_id_,
			#{dayStr} month_,
			COUNT( t.id_ ) total_num_,
			COUNT( t.id_ ) activate_num_,
			COUNT( t.id_ ) percent_
		FROM
			teacher t
			LEFT JOIN sys_user su ON su.id_ = t.id_
		WHERE
			su.del_flag_ = 0 and t.tenant_id_ = #{tenantId}
		  	AND (t.demission_date_ IS NULl OR DATE_FORMAT(t.demission_date_, '%Y-%m-%d') &gt; #{dayStr})
		  	<if test="isDemission==null">
				AND su.lock_flag_ = 0
			</if>
		  	<if test="isDemission!=null">
				AND (su.lock_flag_ = 1 OR t.demission_date_&lt;NOW())
			</if>
			AND t.organ_id_ IS NOT NULL
			<if test="jobNature!=null">
				AND t.job_nature_ = #{jobNature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			<if test="dayStr!=null and dayStr!=''">
				AND DATE_FORMAT(t.create_time_, '%Y-%m-%d') &lt;= #{dayStr}
			</if>
		GROUP BY
			t.organ_id_
		ORDER BY
			t.organ_id_;
	</select>

	<select id="getGroupCourseData" resultMap="IndexBaseMonthData">
		SELECT
			m.organ_id_,m.tenant_id_,
			#{dayStr} month_,
			COUNT( m.id_ ) total_num_,
			COUNT( m.id_ ) activate_num_,
			COUNT( m.id_ ) percent_
		FROM
			course_schedule m
		WHERE
			m.del_flag_ = 0
			AND (m.is_lock_ = 0 OR m.is_lock_ IS NULL)
		  	AND m.status_ = #{courseStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			AND (m.new_course_id_ IS NULL OR m.new_course_id_=m.id_)
			AND NOT EXISTS (SELECT id_ FROM practice_group WHERE m.group_type_='PRACTICE' AND m.music_group_id_=id_ AND type_='TRIAL')
			AND m.organ_id_ IS NOT NULL AND m.pre_course_flag_ = 0 and m.tenant_id_ = #{tenantId}
			<if test="groupType!=null">
				AND m.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			<if test="dayStr!=null and dayStr!=''">
				AND m.class_date_ &gt;= #{dayStr}
			</if>
		GROUP BY
			m.organ_id_
		ORDER BY
			m.organ_id_;
	</select>

	<select id="getGroupSurplusCourseData" resultMap="IndexBaseMonthData">
		SELECT
			m.organ_id_,m.tenant_id_,
			#{dayStr} month_,
			COUNT( m.id_ ) total_num_,
			COUNT( m.id_ ) activate_num_,
			COUNT( m.id_ ) percent_
		FROM
			course_schedule m
		WHERE
			m.del_flag_ = 0 and m.tenant_id_ = #{tenantId}
			AND (m.is_lock_ = 0 OR m.is_lock_ IS NULL)
			AND m.status_ = #{courseStatus, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			AND (m.new_course_id_ IS NULL OR m.new_course_id_=m.id_)
			AND NOT EXISTS (SELECT id_ FROM practice_group WHERE m.group_type_='PRACTICE' AND m.music_group_id_=id_ AND type_='TRIAL')
			AND m.organ_id_ IS NOT NULL AND m.pre_course_flag_ = 0
			<if test="groupType!=null">
				AND m.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			<if test="dayStr!=null and dayStr!=''">
				AND m.class_date_ &lt;= #{dayStr}
			</if>
		GROUP BY m.organ_id_
		ORDER BY m.organ_id_;
	</select>

	<select id="getGroupCourseDataWithGroup" resultMap="IndexBaseMonthData">
		SELECT
		m.organ_id_,m.tenant_id_,
		m.class_date_ month_,
		COUNT( m.id_ ) total_num_,
		COUNT( m.id_ ) activate_num_,
		COUNT( m.id_ ) percent_
		FROM
		course_schedule m
		WHERE
		m.del_flag_ = 0 and m.tenant_id_ = #{tenantId}
		AND (m.is_lock_ = 0 OR m.is_lock_ IS NULL)
		AND (m.new_course_id_ IS NULL OR m.new_course_id_=m.id_)
		AND NOT EXISTS (SELECT id_ FROM practice_group WHERE m.group_type_='PRACTICE' AND m.music_group_id_=id_ AND type_='TRIAL')
		AND m.organ_id_ IS NOT NULL AND m.pre_course_flag_ = 0
		<if test="groupType!=null">
			AND m.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
		</if>
		<if test="dayStr!=null and dayStr!=''">
			AND m.class_date_ = #{dayStr}
		</if>
		<if test="startDate!=null and endDate!=''">
			AND m.class_date_ BETWEEN #{startDate} AND #{endDate}
		</if>
		<if test="teachMode!=null">
			AND m.teach_mode_ = #{teachMode, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND m.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		<if test="dayStr!=null and dayStr!=''">
			GROUP BY m.organ_id_
		</if>
		<if test="startDate!=null and endDate!=''">
			GROUP BY m.class_date_
		</if>
		ORDER BY
			m.organ_id_;
	</select>

	<select id="getVipGroupCategoryCourseData" resultType="com.ym.mec.biz.dal.dto.OrganVipGroupCategoryCourseNumDto">
		SELECT
		m.organ_id_ organId,
		vgc.name_ categoryName,
		COUNT( m.id_ ) courseNum
		FROM
		course_schedule m
		LEFT JOIN vip_group vg ON m.music_group_id_=vg.id_
		LEFT JOIN vip_group_category vgc ON vg.vip_group_category_id_=vgc.id_
		WHERE
		m.del_flag_ = 0 and m.tenant_id_ = #{tenantId}
		AND (m.is_lock_ = 0 OR m.is_lock_ IS NULL)
		AND (m.new_course_id_ IS NULL OR m.new_course_id_=m.id_)
		AND m.organ_id_ IS NOT NULL
		<if test="groupType!=null">
			AND m.group_type_ = #{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
		</if>
		<if test="dayStr!=null and dayStr!=''">
			AND m.class_date_ = #{dayStr}
		</if>
		<if test="startDate!=null and endDate!=null">
			AND m.class_date_ BETWEEN #{startDate} AND #{endDate}
		</if>
		<if test="teachMode!=null">
			AND m.teach_mode_ = #{teachMode, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND m.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY
		m.organ_id_,vgc.name_
		ORDER BY
		m.organ_id_;
	</select>

	<select id="getOtherStudentData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,su.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT s.user_id_ ) total_num_,
			COUNT( DISTINCT s.user_id_ ) activate_num_,
			COUNT( DISTINCT s.user_id_ ) percent_
		FROM
		    sys_user su
			LEFT JOIN course_schedule_student_payment s ON su.id_=s.user_id_
			LEFT JOIN course_schedule m ON s.course_schedule_id_=m.id_
		WHERE
			m.del_flag_ = 0 and m.tenant_id_ = #{tenantId}
			AND (m.is_lock_ = 0 OR m.is_lock_ IS NULL)
			AND su.organ_id_ IS NOT NULL
			AND m.group_type_ IN ('VIP', 'PRACTICE')
			AND m.status_ = 'NOT_START'
			<if test="dayStr!=null and dayStr!=''">
				AND (DATE_FORMAT(s.create_time_, '%Y-%m-%d') &lt;= #{dayStr} OR YEAR(m.create_time_)=3000)
			</if>
		GROUP BY
			su.organ_id_
		ORDER BY
			su.organ_id_;
	</select>

	<select id="getVipPracticeAddStudentData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,su.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT s.user_id_ ) total_num_,
			COUNT( DISTINCT s.user_id_ ) activate_num_,
			COUNT( DISTINCT s.user_id_ ) percent_
		FROM
			sys_user su
			LEFT JOIN course_schedule_student_payment s ON su.id_=s.user_id_
			LEFT JOIN course_schedule_student_payment cssp1 ON s.user_id_=cssp1.user_id_ AND cssp1.create_time_&lt;#{dayStr}
			LEFT JOIN course_schedule m ON s.course_schedule_id_=m.id_
		WHERE
			m.del_flag_ = 0 and m.tenant_id_ = #{tenantId}
			AND (m.is_lock_ = 0 OR m.is_lock_ IS NULL)
			AND cssp1.id_ IS NULL
			AND su.organ_id_ IS NOT NULL
			AND m.group_type_ IN ('VIP', 'PRACTICE')
			<if test="dayStr!=null and dayStr!=''">
				AND DATE_FORMAT(s.create_time_, '%Y-%m-%d') = #{dayStr}
			</if>
		GROUP BY su.organ_id_
		ORDER BY su.organ_id_;
	</select>

	<select id="getStudentConversionData" resultMap="IndexBaseMonthData">
		SELECT
			cs.organ_id_,
			#{dayStr} month_,
			COUNT( DISTINCT m.user_id_ ) total_num_,
			COUNT( DISTINCT m.user_id_ ) activate_num_,
			COUNT( DISTINCT m.user_id_ ) percent_
		FROM
			course_schedule_student_payment m
			LEFT JOIN course_schedule cs ON m.course_schedule_id_=cs.id_
			LEFT JOIN practice_group pg ON m.music_group_id_=pg.id_ AND m.group_type_='PRACTICE'
		WHERE
			(cs.del_flag_ IS NULL OR cs.del_flag_=0)
			AND cs.organ_id_ IS NOT NULL and cs.tenant_id_ = #{tenantId}
			AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_)
			AND m.group_type_ IN ('VIP', 'PRACTICE')
			AND (pg.id_ IS NULL OR pg.type_='CHARGE')
			AND m.user_id_ IN
			<foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
				#{studentId}
			</foreach>
			AND DATE_FORMAT(m.create_time_, '%Y-%m-%d')&lt;=#{dayStr}
		GROUP BY
			cs.organ_id_
		ORDER BY
			cs.organ_id_;
	</select>

	<select id="getMusicGroupPreRegistrationStudentData" resultMap="IndexBaseMonthData">
		SELECT
			mg.organ_id_,
			#{dayStr} month_,
			COUNT( DISTINCT spr.user_id_ ) total_num_,
			COUNT( DISTINCT spr.user_id_ ) activate_num_,
			COUNT( DISTINCT spr.user_id_ ) percent_
		FROM
			student_pre_registration spr
			LEFT JOIN music_group mg ON spr.music_group_id_ = mg.id_
		WHERE
			mg.del_flag_ = 0 and mg.tenant_id_ = #{tenantId}
			AND mg.organ_id_ IS NOT NULL
		  	AND mg.status_ = 'PROGRESS'
			AND DATE_FORMAT( spr.create_time_, '%Y-%m-%d' ) &lt;= #{dayStr}
		GROUP BY
			mg.organ_id_
		ORDER BY
			mg.organ_id_;
	</select>

	<select id="getMusicGroupStudentFromPreData" resultMap="IndexBaseMonthData">
		SELECT
			mg.organ_id_,
			#{dayStr} month_,
			COUNT( DISTINCT sr.user_id_ ) total_num_,
			COUNT( DISTINCT sr.user_id_ ) activate_num_,
			COUNT( DISTINCT sr.user_id_ ) percent_
		FROM
			student_registration sr
			LEFT JOIN student_pre_registration spr ON sr.user_id_ = spr.user_id_ AND sr.music_group_id_ = spr.music_group_id_
			LEFT JOIN music_group mg ON spr.music_group_id_ = mg.id_
		WHERE
			mg.del_flag_ = 0 and mg.tenant_id_ = #{tenantId}
			AND mg.organ_id_ IS NOT NULL
			AND mg.status_ = 'PROGRESS'
			<if test="paymentStatus==null">
				AND sr.music_group_status_ IN ('APPLY', 'NORMAL')
			</if>
		  	<if test="paymentStatus!=null">
				AND sr.music_group_status_ IN ('NORMAL')
				AND sr.payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			AND DATE_FORMAT( sr.create_time_, '%Y-%m-%d' ) &lt;= #{dayStr}
		GROUP BY
			mg.organ_id_
		ORDER BY
			mg.organ_id_;
	</select>

	<select id="getMusicGroupStudentIdFromPre" resultType="int">
		SELECT
			sr.user_id_
		FROM
			student_registration sr
			LEFT JOIN student_pre_registration spr ON sr.user_id_ = spr.user_id_ AND sr.music_group_id_ = spr.music_group_id_
			LEFT JOIN music_group mg ON spr.music_group_id_ = mg.id_
		WHERE
			mg.del_flag_ = 0 and mg.tenant_id_ = #{tenantId}
			AND mg.organ_id_ IS NOT NULL
			AND mg.status_ = 'PROGRESS'
			<if test="paymentStatus==null">
				AND sr.music_group_status_ IN ('APPLY', 'NORMAL')
			</if>
			<if test="paymentStatus!=null">
				AND sr.music_group_status_ IN ('NORMAL')
				AND sr.payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
			AND DATE_FORMAT( sr.create_time_, '%Y-%m-%d' ) &lt;= #{dayStr}
	</select>

	<select id="countLessThenThreeClassGroupNum" resultType="int">
		SELECT COUNT(t.id_) FROM (
		SELECT cg.id_ FROM
		class_group cg
		LEFT JOIN class_group_student_mapper cgsm ON cg.id_ = cgsm.class_group_id_
		LEFT JOIN music_group mg ON cg.music_group_id_=mg.id_
		LEFT JOIN course_schedule cs ON cs.class_group_id_=cg.id_
		WHERE
		cg.type_ IN ('HIGH', 'HIGH_ONLINE') and cg.tenant_id_ = #{tenantId}
		AND mg.status_ = 'PROGRESS' AND cg.del_flag_ = 0 AND cs.pre_course_flag_ = 0
		AND cs.del_flag_=0
		AND cs.status_='NOT_START'
		AND ( cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_ )
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cg.id_
		HAVING
		COUNT(DISTINCT CASE WHEN cgsm.status_ = 'NORMAL' THEN cgsm.user_id_ ELSE NULL END) &lt; 3
		) t
	</select>

	<select id="countLessThenThreeClassOrganGroupNum" resultType="map">
		SELECT t.organ_id_ AS 'key',
		       COUNT(t.id_) AS 'value'
		FROM (
		SELECT mg.organ_id_,cg.id_ FROM
		class_group cg
		LEFT JOIN class_group_student_mapper cgsm ON cg.id_ = cgsm.class_group_id_
		LEFT JOIN music_group mg ON cg.music_group_id_=mg.id_
		LEFT JOIN course_schedule cs ON cs.class_group_id_=cg.id_
		WHERE
		cg.type_ IN ('HIGH', 'HIGH_ONLINE') AND cs.pre_course_flag_ = 0 and cg.tenant_id_ = #{tenantId}
		AND mg.status_ = 'PROGRESS' AND cg.del_flag_ = 0
		AND cs.del_flag_=0
		AND cs.status_='NOT_START'
		AND ( cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_ )
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cg.id_
		HAVING
		COUNT(DISTINCT CASE WHEN cgsm.status_ = 'NORMAL' THEN cgsm.user_id_ ELSE NULL END) &lt; 3
		) t GROUP BY t.organ_id_
	</select>

    <select id="getLessThenThreeMusicGroup" resultType="java.lang.String">
		SELECT cg.music_group_id_ FROM
		class_group cg
		LEFT JOIN class_group_student_mapper cgsm ON cg.id_ = cgsm.class_group_id_
		LEFT JOIN music_group mg ON cg.music_group_id_=mg.id_
		WHERE
		cg.type_ IN ('HIGH_ONLINE') and cg.tenant_id_ = #{tenantId}
		AND mg.status_ = 'PROGRESS' AND cg.del_flag_ = 0
		<if test="organIds!=null and organIds.size()>0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cg.id_
		HAVING
		COUNT(CASE WHEN cgsm.status_ = 'NORMAL' THEN 1 ELSE NULL END) &lt; 3
	</select>

	<select id="countNoPaymentStudentNum" resultType="int">
		SELECT
			COUNT(DISTINCT mgpc.music_group_id_,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_
		LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
		LEFT JOIN student_registration sr ON sr.music_group_id_ = mgpc.music_group_id_ AND mgpcd.user_id_ = sr.user_id_
		WHERE
		mg.status_ = 'PROGRESS' and mg.tenant_id_ = #{tenantId}
		AND ((mgpc.member_rank_setting_id_ IS NOT NULL AND (sr.membership_end_time_ &lt; NOW() OR sr.membership_end_time_ IS NULL)) OR mgpc.member_rank_setting_id_ IS NULL)
		<if test="noPaymentType==null or noPaymentType==0">
			AND DATE_FORMAT(NOW(),'%Y-%m-%d') > DATE_FORMAT(mgpc.deadline_payment_date_,'%Y-%m-%d')
		</if>
		<if test="noPaymentType!=null and noPaymentType==1">
			AND DATE_FORMAT(NOW(),'%Y-%m-%d') BETWEEN DATE_FORMAT(mgpc.start_payment_date_,'%Y-%m-%d') AND DATE_FORMAT(mgpc.deadline_payment_date_,'%Y-%m-%d')
		</if>
		AND mgpcd.payment_status_ = 'NON_PAYMENT' AND mgpc.batch_no_ IS NOT NULL AND mgpc.pay_user_type_ = 'STUDENT'
		AND mgpc.current_total_amount_ > 0
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>

	<select id="countOrganNoPaymentStudentNum" resultType="map">
		SELECT
		    mg.organ_id_ AS 'key',
			COUNT(DISTINCT mgpc.music_group_id_,mgpcd.user_id_) AS 'value'
		FROM
		music_group_payment_calender_detail mgpcd
		LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
		LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
		WHERE
		mg.status_ = 'PROGRESS' and mg.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(NOW(),'%Y-%m-%d') > mgpc.deadline_payment_date_
		AND mgpcd.payment_status_ = 'NON_PAYMENT' AND mgpcd.expect_amount_ > 0 AND mgpc.batch_no_ IS NOT NULL AND mgpc.pay_user_type_ = 'STUDENT'
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY mg.organ_id_
	</select>

	<select id="getNoPaymentMusicGroup" resultType="java.lang.String">
		SELECT
			DISTINCT mg.id_
		FROM
			music_group_payment_calender_detail mgpcd
			LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
			LEFT JOIN music_group mg ON mgpc.music_group_id_ = mg.id_
		WHERE
			mg.status_ = 'PROGRESS' and mg.tenant_id_ = #{tenantId}
			AND DATE_FORMAT(NOW(),'%Y-%m-%d') >= DATE_FORMAT(mgpc.payment_valid_start_date_,'%Y-%m-%d')
			AND mgpcd.payment_status_ = 'NON_PAYMENT'
			<if test="educationUserId != null">
				AND mg.educational_teacher_id_ = #{educationUserId}
			</if>
			<if test="organIds!=null and organIds.size()>0">
				AND mg.organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
	</select>

	<select id="queryApplyForQuitGroupNum" resultType="java.lang.Long">
		SELECT mgq.id_ FROM music_group_quit mgq
			LEFT JOIN music_group mg ON mgq.music_group_id_=mg.id_
		WHERE mg.status_='PROGRESS'
		  AND mgq.status_='PROCESSING' and mgq.tenant_id_ = #{tenantId}
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size() > 0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>

	<select id="queryOrganApplyForQuitGroupNum" resultType="map">
		SELECT
			mg.organ_id_ AS 'key',
		    COUNT(mgq.id_) AS 'value'
		FROM music_group_quit mgq
		LEFT JOIN music_group mg ON mgq.music_group_id_=mg.id_
		WHERE mg.status_='PROGRESS'
		AND mgq.status_='PROCESSING' and mgq.tenant_id_ = #{tenantId}
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size() > 0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY mg.organ_id_
	</select>

	<select id="queryStudentAttendanceInfo" resultType="int">
		SELECT
			COUNT(DISTINCT 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_
			LEFT JOIN student_visit sv ON cssp.id_ = sv.object_id_
		WHERE
				cs.status_ = 'OVER' AND sv.id_ IS NULL AND cs.del_flag_ = 0 AND cs.class_date_ >= #{startTime} AND cs.class_date_ &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d')
				AND cssp.group_type_ IN ('MUSIC','PRACTICE','VIP') AND cs.pre_course_flag_ = 0 and cssp.tenant_id_ = #{tenantId}
			<if test="type!=null and type=='LEAVE'">
				AND sa.status_ = 'LEAVE'
			</if>
			<if test="type!=null and type=='TRUANT'">
				AND (sa.status_ = 'TRUANT' OR sa.id_ IS NULL) AND (cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_)
			</if>
			<if test="organIds!=null and organIds.size()>0">
				AND cs.organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
	</select>
    <select id="getCourseTimeError" resultType="int">
		SELECT COUNT(cs.id_) FROM course_schedule cs
		WHERE cs.status_ = 'NOT_START' AND cs.del_flag_ = 0 AND cs.is_lock_ = 0 AND (cs.start_class_time_ &lt; #{courseStartTimeError} OR cs.end_class_time_ > #{courseEndTimeError})
		AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_) AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds != null and organIds.size()>0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>

	<select id="getOrganCourseTimeError" resultType="map">
		SELECT
		       cs.organ_id_ AS 'key',
		       COUNT(cs.id_) AS 'value'
		FROM course_schedule cs
		WHERE cs.status_ = 'NOT_START' AND cs.del_flag_ = 0 AND cs.is_lock_ = 0 AND cs.start_class_time_ &lt; '06:00:00'
		AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_) AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds != null and organIds.size()>0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cs.organ_id_
	</select>

    <select id="getAttendanceError" resultType="int">
		SELECT COUNT(DISTINCT c.id_) FROM (SELECT cs.id_ FROM course_schedule cs
		LEFT JOIN teacher_attendance ta ON ta.course_schedule_id_ = cs.id_
		LEFT JOIN course_schedule_student_payment cssp ON cssp.course_schedule_id_ = cs.id_
		LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cssp.course_schedule_id_ AND cssp.user_id_ = sa.user_id_
		WHERE ta.teacher_id_ = cs.actual_teacher_id_ AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		AND cs.status_ = 'OVER' AND cs.del_flag_ = 0 AND cs.class_date_ >= '2021-02-01'
		AND (((ta.sign_in_status_ = 0 OR ta.sign_in_status_ IS NULL OR ta.sign_out_status_ = 0 OR ta.sign_out_status_ IS NULL) AND ta.dispose_content_ IS NULL) OR (sa.id_ IS NULL OR (sa.status_ = 'TRUANT' AND sa.visit_flag_ = 0)))
		AND ((ta.sign_in_status_ IS NULL AND ta.sign_out_status_ IS NOT NULL) OR (ta.sign_out_status_ IS NULL AND ta.sign_in_status_ IS NOT NULL) OR (ta.sign_out_status_ IS NOT NULL AND ta.sign_in_status_ IS NOT NULL))
		AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_) AND cssp.id_ IS NOT NULL
		AND EXISTS (SELECT id_ FROM course_schedule_teacher_salary WHERE cs.id_=course_schedule_id_ AND settlement_time_ IS NULL)
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds != null and organIds.size()>0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cs.id_) c
	</select>

	<select id="getOrganAttendanceError" resultType="map">
		SELECT
			c.organ_id_ AS 'key',
		    COUNT(DISTINCT c.id_) AS 'value'
		FROM (SELECT cs.organ_id_,cs.id_ FROM course_schedule cs
		LEFT JOIN teacher_attendance ta ON ta.course_schedule_id_ = cs.id_
		LEFT JOIN course_schedule_student_payment cssp ON cssp.course_schedule_id_ = cs.id_
		LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cssp.course_schedule_id_ AND cssp.user_id_ = sa.user_id_
		WHERE ta.teacher_id_ = cs.actual_teacher_id_ and cs.tenant_id_ = #{tenantId}
		AND cs.status_ = 'OVER' AND cs.del_flag_ = 0 AND cs.class_date_ >= '2021-02-01' AND cs.pre_course_flag_ = 0
		AND (((ta.sign_in_status_ = 0 OR ta.sign_in_status_ IS NULL OR ta.sign_out_status_ = 0 OR ta.sign_out_status_ IS NULL) AND ta.dispose_content_ IS NULL) OR (sa.id_ IS NULL OR (sa.status_ = 'TRUANT' AND sa.visit_flag_ = 0)))
		AND ((ta.sign_in_status_ IS NULL AND ta.sign_out_status_ IS NOT NULL) OR (ta.sign_out_status_ IS NULL AND ta.sign_in_status_ IS NOT NULL) OR (ta.sign_out_status_ IS NOT NULL AND ta.sign_in_status_ IS NOT NULL))
		AND (cs.new_course_id_ IS NULL OR cs.new_course_id_=cs.id_) AND cssp.id_ IS NOT NULL
		AND EXISTS (SELECT id_ FROM course_schedule_teacher_salary WHERE cs.id_=course_schedule_id_ AND settlement_time_ IS NULL)
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds != null and organIds.size()>0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cs.id_) c GROUP BY c.organ_id_
	</select>

	<select id="getNoAttendance" resultType="int">
		SELECT COUNT(DISTINCT cs.id_) FROM course_schedule cs
		LEFT JOIN teacher_attendance ta ON ta.course_schedule_id_ = cs.id_
		WHERE ta.teacher_id_ = cs.actual_teacher_id_ and cs.tenant_id_ = #{tenantId}
		AND cs.status_ = 'OVER' AND cs.del_flag_ = 0 AND cs.class_date_>='2021-02-01' AND cs.pre_course_flag_ = 0
		AND ta.sign_in_time_ IS NULL AND ta.sign_out_time_ IS NULL AND ta.dispose_content_ IS NULL
		AND (cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_)
		AND EXISTS (SELECT id_ FROM course_schedule_teacher_salary WHERE cs.id_=course_schedule_id_ AND settlement_time_ IS NULL)
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds!=null and organIds.size() > 0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>

	<select id="getOrganNoAttendance" resultType="map">
		SELECT
		    cs.organ_id_ AS 'key',
		    COUNT(DISTINCT cs.id_) AS 'value'
		FROM course_schedule cs
		LEFT JOIN teacher_attendance ta ON ta.course_schedule_id_ = cs.id_
		WHERE ta.teacher_id_ = cs.actual_teacher_id_ and cs.tenant_id_ = #{tenantId}
		AND cs.status_ = 'OVER' AND cs.del_flag_ = 0 AND cs.class_date_>='2021-02-01' AND cs.pre_course_flag_ = 0
		AND ta.sign_in_time_ IS NULL AND ta.sign_out_time_ IS NULL AND ta.dispose_content_ IS NULL
		AND (cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_)
		AND EXISTS (SELECT id_ FROM course_schedule_teacher_salary WHERE cs.id_=course_schedule_id_ AND settlement_time_ IS NULL)
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds!=null and organIds.size() > 0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY cs.organ_id_
	</select>

	<select id="queryTeacherLeave" resultType="int">
		SELECT COUNT(DISTINCT tlr.id_) FROM teacher_leave_record tlr
		LEFT JOIN teacher t ON t.id_ = tlr.user_id_
		WHERE tlr.status_ = 'ING' AND DATE_FORMAT( tlr.create_time_, '%Y-%m-%d' ) >= #{startTime} and tlr.tenant_id_ = #{tenantId}
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(t.organ_id_,#{organIdsStr})
		</if>
	</select>
	<select id="queryLowTeacherSalary" resultType="int">
		SELECT COUNT(DISTINCT tcs.user_id_) FROM teacher_course_statistics tcs
		LEFT JOIN teacher t ON t.id_ = tcs.user_id_
		LEFT JOIN sys_user su ON su.id_ = tcs.user_id_
		WHERE su.lock_flag_ = 0 AND su.del_flag_ = 0 AND t.job_nature_ = 'FULL_TIME' AND t.demission_date_ IS NULL
		AND t.is_settlement_salary_ = 1 and t.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(tcs.month_,'%Y-%m') = #{monthStr} AND tcs.low_salary = 1
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(tcs.organ_id_,#{organIdsStr})
		</if>
	</select>

	<select id="queryOrganLowTeacherSalary" resultType="map">
		SELECT
			tcs.organ_id_ AS 'key',
			COUNT(DISTINCT tcs.user_id_) AS 'value'
		FROM teacher_course_statistics tcs
		LEFT JOIN teacher t ON t.id_ = tcs.user_id_
		LEFT JOIN sys_user su ON su.id_ = tcs.user_id_
		WHERE su.lock_flag_ = 0 AND su.del_flag_ = 0 AND t.job_nature_ = 'FULL_TIME' AND t.demission_date_ IS NULL
		AND t.is_settlement_salary_ = 1 and t.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(tcs.month_,'%Y-%m') = #{monthStr} AND tcs.low_salary = 1
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(tcs.organ_id_,#{organIdsStr})
		</if>
		GROUP BY tcs.organ_id_
	</select>

	<select id="queryInspectionItem" resultType="int">
		SELECT COUNT(DISTINCT ii.id_) FROM inspection_item ii
		LEFT JOIN inspection i ON ii.inspection_id_ = i.id_
		WHERE ii.times_ > planned_times_ AND ii.item_ = 'INSPECT' AND ii.memo_ ='' and ii.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(i.month_,'%Y-%m-%d') >= #{startTime}
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(ii.organ_id_,#{organIdsStr})
		</if>
		<if test="userId != null">
			AND ii.user_id_ = #{userId}
		</if>
	</select>

	<select id="queryOrganInspectionItem" resultType="map">
		SELECT
		       ii.organ_id_ AS 'key',
		       COUNT(DISTINCT ii.id_) AS 'value'
		FROM inspection_item ii
		LEFT JOIN inspection i ON ii.inspection_id_ = i.id_
		WHERE ii.times_ > planned_times_ AND ii.item_ = 'INSPECT' AND ii.memo_ ='' and ii.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(i.month_,'%Y-%m-%d') >= #{startTime}
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(ii.organ_id_,#{organIdsStr})
		</if>
		<if test="userId != null">
			AND ii.user_id_ = #{userId}
		</if>
		GROUP BY ii.organ_id_
	</select>

	<select id="queryInspectionItemPlan" resultType="int">
		SELECT COUNT(DISTINCT iip.id_) FROM inspection_item_plan iip
		WHERE iip.status_ = 0 AND iip.memo_ = '' AND DATE_FORMAT(iip.plan_start_,'%Y-%m-%d') &lt; DATE_FORMAT(NOW(),'%Y-%m-%d') and iip.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(iip.plan_start_,'%Y-%m-%d') >= #{startTime} AND DATE_FORMAT(iip.plan_start_,'%Y-%m-%d') &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d')
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(iip.organ_id_,#{organIdsStr})
		</if>
	</select>

	<select id="queryOrganInspectionItemPlan" resultType="map">
		SELECT
			iip.organ_id_ AS 'key',
		    COUNT(DISTINCT iip.id_) AS 'value'
		FROM inspection_item_plan iip
		WHERE iip.status_ = 0 AND iip.memo_ = '' AND DATE_FORMAT(iip.plan_start_,'%Y-%m-%d') &lt; DATE_FORMAT(NOW(),'%Y-%m-%d') and iip.tenant_id_ = #{tenantId}
		AND DATE_FORMAT(iip.plan_start_,'%Y-%m-%d') >= #{startTime} AND DATE_FORMAT(iip.plan_start_,'%Y-%m-%d') &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d')
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(iip.organ_id_,#{organIdsStr})
		</if>
		GROUP BY iip.organ_id_
	</select>

	<select id="queryStudentVisit" resultType="int">
		SELECT COUNT(DISTINCT ii.id_) FROM inspection_item ii
		LEFT JOIN inspection i ON ii.inspection_id_ = i.id_
		WHERE ii.item_ = 'VISIT' AND ii.memo_ ='' and ii.tenant_id_ = #{tenantId}
		AND ii.times_ > (SELECT COUNT(DISTINCT sv.id_) FROM student_visit sv
		WHERE sv.teacher_id_ = ii.user_id_ AND DATE_FORMAT(i.month_,'%Y-%m') = DATE_FORMAT(sv.visit_time_,'%Y-%m'))
		AND i.month_ >= #{startTime} AND i.month_ &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d')
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(ii.organ_id_,#{organIdsStr})
		</if>
		<if test="userId != null">
			AND ii.user_id_ = #{userId}
		</if>
	</select>

	<select id="queryOrganStudentVisit" resultType="map">
		SELECT
			ii.organ_id_ AS 'key',
		    COUNT(DISTINCT ii.id_) AS 'value'
		FROM inspection_item ii
		LEFT JOIN inspection i ON ii.inspection_id_ = i.id_
		WHERE ii.item_ = 'VISIT' AND ii.memo_ =''
		AND ii.times_ > (SELECT COUNT(DISTINCT sv.id_) FROM student_visit sv
		WHERE sv.teacher_id_ = ii.user_id_ AND DATE_FORMAT(i.month_,'%Y-%m') = DATE_FORMAT(sv.visit_time_,'%Y-%m')) and ii.tenant_id_ = #{tenantId}
		AND i.month_ >= #{startTime} AND i.month_ &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d')
		<if test="organIdsStr != null and organIdsStr != ''">
			AND FIND_IN_SET(ii.organ_id_,#{organIdsStr})
		</if>
		<if test="userId != null">
			AND ii.user_id_ = #{userId}
		</if>
		GROUP BY ii.organ_id_
	</select>

    <select id="queryErrInspection" resultType="int">
		SELECT
			COUNT(id_)
		FROM
			inspection_item_plan
		WHERE
			conclusion_status_ = 1 AND memo_ = '' AND DATE_FORMAT(plan_start_,'%Y-%m-%d') >= #{startTime} and tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>

	<select id="queryOrganErrInspection" resultType="map">
		SELECT
			organ_id_ AS 'key',
		    COUNT(id_) AS 'value'
		FROM
		inspection_item_plan
		WHERE
		conclusion_status_ = 1 AND memo_ = '' AND DATE_FORMAT(plan_start_,'%Y-%m-%d') >= #{startTime} and tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY organ_id_
	</select>

	<select id="getNoClassMusicGroupStudentInfo" resultType="com.ym.mec.biz.dal.entity.IndexErrInfoDto">
		SELECT
			'NO_CLASS_MUSIC_GROUP_STUDENT_INFO' errorType,
			COUNT( DISTINCT sr.music_group_id_ ) num,
			COUNT( sr.user_id_ ) num2
		FROM
			student_registration sr
			LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
			LEFT JOIN `subject` sub ON sr.actual_subject_id_=sub.id_
			LEFT JOIN class_group_student_mapper cgsm ON cgsm.group_type_='MUSIC' AND cgsm.music_group_id_=sr.music_group_id_ AND cgsm.user_id_=sr.user_id_ AND cgsm.status_='NORMAL'
		WHERE
			sr.music_group_status_ = 'NORMAL' and sr.tenant_id_ = #{tenantId}
			AND mg.status_ = 'PROGRESS'
			AND cgsm.id_ IS NULL
			AND sub.parent_subject_id_!=24
			<if test="educationUserId != null">
				AND mg.educational_teacher_id_ = #{educationUserId}
			</if>
			<if test="organIds!=null and organIds.size()>0">
				AND mg.organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
	</select>

	<select id="getOrganNoClassMusicGroupStudentNum" resultType="map">
		SELECT
		mg.organ_id_ AS 'key',
		COUNT( sr.user_id_ ) AS 'value'
		FROM
		student_registration sr
		LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
		LEFT JOIN `subject` sub ON sr.actual_subject_id_=sub.id_
		LEFT JOIN class_group_student_mapper cgsm ON cgsm.group_type_='MUSIC' AND cgsm.music_group_id_=sr.music_group_id_ AND cgsm.user_id_=sr.user_id_ AND cgsm.status_='NORMAL'
		WHERE
		sr.music_group_status_ = 'NORMAL' and sr.tenant_id_ = #{tenantId}
		AND mg.status_ = 'PROGRESS'
		AND cgsm.id_ IS NULL
		AND sub.parent_subject_id_!=24
		<if test="educationUserId != null">
			AND mg.educational_teacher_id_ = #{educationUserId}
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND mg.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY mg.organ_id_
	</select>

	<select id="getFinancePayData"  resultMap="IndexBaseMonthData">
		SELECT SUM(fe.amount_) total_num_,SUM(fe.amount_) activate_num_,SUM(fe.amount_) percent_,fe.organ_id_,#{dayStr} month_ FROM financial_expenditure fe
		WHERE DATE_FORMAT(fe.create_time_,'%Y-%m-%d') = #{dayStr}  and fe.tenant_id_ = #{tenantId}
		AND del_flag_ = 0 GROUP BY fe.organ_id_
	</select>
	<select id="getFinanceBalanceData" resultMap="IndexBaseMonthData">
		SELECT spo.organ_id_,SUM(spo.balance_payment_amount_) total_num_,
			   SUM(spo.balance_payment_amount_) activate_num_,
			   SUM(spo.balance_payment_amount_) percent_,#{dayStr} month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') = #{dayStr}  and spo.tenant_id_ = #{tenantId}
		GROUP BY spo.organ_id_
	</select>
	<select id="getFinanceActualData" resultMap="IndexBaseMonthData">
		SELECT spo.organ_id_,SUM(spo.actual_amount_) total_num_,
			   SUM(spo.actual_amount_) activate_num_,
			   SUM(spo.actual_amount_) percent_,#{dayStr} month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') = #{dayStr} and spo.tenant_id_ = #{tenantId}
		GROUP BY spo.organ_id_
	</select>

	<select id="getFinancePayDataWithTimely"  resultMap="IndexBaseMonthData">
		SELECT SUM(fe.amount_) total_num_,SUM(fe.amount_) activate_num_,SUM(fe.amount_) percent_,fe.organ_id_,DATE_FORMAT(fe.create_time_,'%Y-%m-%d') month_
		FROM financial_expenditure fe
		WHERE DATE_FORMAT(fe.create_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and fe.tenant_id_ = #{tenantId}
		  AND del_flag_ = 0
			<if test="organIds!=null and organIds.size()>0">
				AND fe.organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
		GROUP BY DATE_FORMAT(fe.create_time_,'%Y-%m-%d')
	</select>

	<select id="getOrganFinancePayDataWithTimely"  resultMap="IndexBaseMonthData">
		SELECT SUM(fe.amount_) percent_,o.id_ organ_id_,o.name_ organ_name_
		FROM organization o
		LEFT JOIN financial_expenditure fe ON o.id_ = fe.organ_id_ AND fe.tenant_id_ = o.tenant_id_
		AND DATE_FORMAT(fe.create_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} AND fe.del_flag_ = 0
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>
	<select id="getFinanceBalanceDataWithTimely" resultMap="IndexBaseMonthData">
		SELECT spo.organ_id_,SUM(CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_,
			   SUM(CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) activate_num_,
			   SUM(CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
	</select>
	<select id="getOrganFinanceBalanceDataWithTimely" resultMap="IndexBaseMonthData">
		SELECT SUM(CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,
		o.id_ organ_id_,o.name_ organ_name_
		FROM organization o
		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size() > 0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>
	<select id="getFinanceActualDataWithTimely" resultMap="IndexBaseMonthData">
		SELECT spo.organ_id_,SUM(spo.actual_amount_) total_num_,
			   SUM(spo.actual_amount_) activate_num_,
			   SUM(spo.actual_amount_) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
	</select>
	<select id="getOrganFinanceActualDataWithTimely" resultMap="IndexBaseMonthData">
		SELECT SUM(spo.actual_amount_) percent_,o.id_ organ_id_,o.name_ organ_name_
		FROM organization o
		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>
	<select id="getTotalAmountDataWithTimely" resultMap="IndexBaseMonthData">
		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		                         CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_,
			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) activate_num_,
			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
	</select>
	<select id="getOrganTotalAmountDataWithTimely" resultMap="IndexBaseMonthData">
		SELECT SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		                         CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,
		    			   o.id_ organ_id_,o.name_ organ_name_
		FROM organization o
		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>
	<select id="getTotalAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		                         CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_,
			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) activate_num_,
			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		<if test="orderType != null">
			AND FIND_IN_SET(spo.type_,#{orderType})
		</if>
		<if test="notOrderType != null">
			AND spo.type_ NOT IN
			<foreach collection="notOrderType" open="(" close=")" item="item" separator=",">
				#{item}
			</foreach>
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
	</select>

	<select id="getOrganTotalAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
		SELECT SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,
		    			   o.id_ organ_id_,o.name_ organ_name_
		FROM organization o
		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		<if test="orderType != null">
			AND FIND_IN_SET(spo.type_,#{orderType})
		</if>
		<if test="notOrderType != null">
			AND spo.type_ NOT IN
			<foreach collection="notOrderType" open="(" close=")" item="item" separator=",">
				#{item}
			</foreach>
		</if>
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>

	<select id="getVipAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
		SELECT organ_id_,SUM(c.total_num_) total_num_,SUM(c.total_num_) activate_num_,SUM(c.total_num_) percent_,month_ FROM (
		SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
		FROM student_payment_order spo
		LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		AND spo.type_ = 'DEGREE' AND spod.type_ IN ('THEORY_COURSE','VIP')
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
		UNION ALL
		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_
		,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		AND spo.type_ = 'SMALL_CLASS_TO_BUY'
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d')
		)c GROUP BY DATE_FORMAT(c.month_,'%Y-%m-%d')
	</select>

	<select id="getOrganVipAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
		SELECT o.id_ organ_id_,o.name_ organ_name_,SUM(c.total_num_) percent_ FROM organization o
		LEFT JOIN (SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_
		FROM student_payment_order spo
		LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		AND spo.type_ = 'DEGREE' AND spod.type_ IN ('THEORY_COURSE','VIP')
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY spo.organ_id_
		UNION ALL
		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		AND spo.type_ = 'SMALL_CLASS_TO_BUY'
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY spo.organ_id_
		)c ON c.organ_id_ = o.id_
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>

	<select id="getOtherAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
		SELECT organ_id_,SUM(c.total_num_) total_num_,SUM(c.total_num_) activate_num_,SUM(c.total_num_) percent_,month_,c.type_ order_type_ FROM (
		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
							   CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_
		   ,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_,spo.type_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		AND spo.type_ NOT IN ('APPLY','RENEW','PRACTICE_GROUP_BUY','PRACTICE_GROUP_RENEW','SMALL_CLASS_TO_BUY','DEGREE')
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d'),spo.type_
		UNION ALL
		SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_,spo.type_
		FROM student_payment_order spo
			   LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		AND spo.type_ = 'DEGREE' AND spod.type_ = 'DEGREE_REGISTRATION'
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY DATE_FORMAT(spo.pay_time_,'%Y-%m-%d'),spo.type_
		)c GROUP BY DATE_FORMAT(c.month_,'%Y-%m-%d'),c.type_
	</select>

	<select id="getOrganOtherAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
		SELECT o.id_ organ_id_,o.name_ organ_name_,SUM(c.total_num_) percent_ FROM organization o
		LEFT JOIN (
		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
							   CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_,spo.type_
		FROM student_payment_order spo
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
		AND spo.type_ NOT IN ('APPLY','RENEW','PRACTICE_GROUP_BUY','PRACTICE_GROUP_RENEW','SMALL_CLASS_TO_BUY','DEGREE')
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY spo.organ_id_,spo.type_
		UNION ALL
		SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_,spo.type_
		FROM student_payment_order spo
			   LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		AND spo.type_ = 'DEGREE' AND spod.type_ = 'DEGREE_REGISTRATION'
		<if test="organIds!=null and organIds.size()>0">
			AND spo.organ_id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY spo.organ_id_,spo.type_
		)c ON c.organ_id_ = o.id_
		WHERE o.tenant_id_ = #{tenantId}
		<if test="organIds!=null and organIds.size()>0">
			AND o.id_ IN
			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
		GROUP BY o.id_ ORDER BY percent_ DESC
	</select>

	<sql id="queryTeacherServeInfoCondition">
		<where>
			 sees.tenant_id_ = #{tenantId}
			<if test="organIds!=null and organIds.size()>0">
				AND tea.organ_id_ IN
				<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
			<if test="monday!=null and monday!='' and sunday!=null and sunday!=''">
				AND sees.monday_ BETWEEN #{monday} AND #{sunday}
			</if>
			<if test="teacherId!=null">
				AND sees.teacher_id_ = #{teacherId}
			</if>
			<if test="reminded!=null and reminded==0">
				AND NOT EXISTS (SELECT id_ FROM teacher_remind WHERE teacher_id_=sees.teacher_id_ AND monday_ = sees.monday_ AND type_='SERVICE')
			</if>
			<if test="reminded!=null and reminded==1">
				AND EXISTS (SELECT id_ FROM teacher_remind WHERE teacher_id_=sees.teacher_id_ AND monday_ = sees.monday_ AND type_='SERVICE')
			</if>
			<if test="operatorId!=null">
				AND EXISTS (SELECT id_ FROM teacher_remind WHERE operator_id_=#{operatorId} AND teacher_id_=sees.teacher_id_ AND monday_ = sees.monday_ AND type_='SERVICE')
			</if>
			<if test="jobNature!=null">
				AND tea.job_nature_=#{jobNature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
		</where>
	</sql>

	<select id="countOrganTeacherServeInfo" resultType="map">
		SELECT
		    e.organ_id_ AS 'key',
		    COUNT(1) AS 'value'
		FROM (
		SELECT
			tea.organ_id_,
			sees.id_
		FROM
		student_extracurricular_exercises_situation_ sees
		LEFT JOIN teacher tea ON tea.id_=sees.teacher_id_
		<if test="unDone!=null and unDone==1">
			LEFT JOIN teacher_remind tm ON sees.monday_=tm.monday_ AND sees.teacher_id_=tm.teacher_id_
		</if>
		<include refid="queryTeacherServeInfoCondition" />
		GROUP BY sees.monday_,sees.sunday_,sees.teacher_id_
		<if test="unDone!=null">
			HAVING
			<if test="unDone==1">
				SUM( sees.expect_exercises_num_-sees.not_over_course_num_ ) &gt; SUM( sees.actual_exercises_num_ )
			</if>
			<if test="unDone==0">
				SUM( sees.expect_exercises_num_-sees.not_over_course_num_ ) &lt;= SUM( sees.actual_exercises_num_ )
			</if>
		</if>
		ORDER BY sees.monday_,sees.sunday_,sees.teacher_id_
		) e GROUP BY e.organ_id_
	</select>
	<select id="countStudentErrorLeave" resultType="java.lang.Integer">
		SELECT COUNT(DISTINCT c.user_id_) FROM (
		SELECT sa.user_id_ FROM student_attendance sa
		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		WHERE DATE_FORMAT(cs.class_date_,'%Y-%m') >= #{format} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="organIdList != null and organIdList.size > 0">
			AND cs.organ_id_ IN
			<foreach collection="organIdList" open="(" close=")" item="item" separator=",">
				#{item}
			</foreach>
		</if>
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		GROUP BY sa.user_id_,DATE_FORMAT(cs.class_date_,'%Y-%m')
		HAVING COUNT(sa.id_) >= #{studentErrorLeaveNum} AND COUNT(sa.id_) > SUM(sa.leave_visit_flag_)) c
	</select>
	<select id="countOrganStudentErrorLeave" resultType="map">
		SELECT c.organ_id_ 'key',COUNT(c.user_id_) 'value' FROM (
		SELECT sa.user_id_,cs.organ_id_ FROM student_attendance sa
		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		WHERE DATE_FORMAT(cs.class_date_,'%Y-%m') >= '2021-11' AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="organIds != null and organIds.size > 0">
			AND cs.organ_id_ IN
			<foreach collection="organIds" open="(" close=")" item="item" separator=",">
				#{item}
			</foreach>
		</if>
		GROUP BY sa.user_id_
		HAVING COUNT(sa.id_) > 1 AND COUNT(sa.id_) > SUM(sa.leave_visit_flag_))c
		GROUP BY c.organ_id_
	</select>
	<select id="countStudentErrorLeave1" resultType="java.lang.Integer">
		SELECT COUNT(DISTINCT c.user_id_) FROM (
		SELECT sa.user_id_ FROM student_attendance sa
		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		LEFT JOIN sys_user su ON su.id_ = sa.user_id_
		WHERE DATE_FORMAT(cs.class_date_,'%Y-%m') >= #{currentMonth} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="organIds != null">
			AND FIND_IN_SET(cs.organ_id_,#{organIds})
		</if>
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="search != null and search != ''">
			AND (sa.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
		</if>
		GROUP BY sa.user_id_,DATE_FORMAT(cs.class_date_,'%Y-%m')
		HAVING COUNT(sa.id_) >= #{studentErrorLeaveNum} AND COUNT(sa.id_) > SUM(sa.leave_visit_flag_)) c
	</select>
	<resultMap id="StudentErrorLeaveDto" type="com.ym.mec.biz.dal.dto.StudentErrorLeaveDto">
		<result property="currentNum" column="current_num_"/>
		<result property="totalNum" column="total_num_"/>
		<result property="userId" column="user_id_"/>
		<result property="studentName" column="username_"/>
		<result property="phone" column="phone_"/>
		<result property="organId" column="organ_id_"/>
		<result property="organName" column="organ_name_"/>
	</resultMap>
	<select id="queryStudentErrorLeave" resultMap="StudentErrorLeaveDto">
		SELECT organ_id_,organ_name_,user_id_,username_,phone_,current_num_,class_date_
		FROM (SELECT cs.organ_id_,o.name_ organ_name_,sa.user_id_,su.username_,su.phone_,
		COUNT(sa.id_) current_num_,cs.class_date_
		FROM student_attendance sa
		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		LEFT JOIN organization o ON o.id_ = cs.organ_id_
		LEFT JOIN sys_user su ON su.id_ = sa.user_id_
		WHERE DATE_FORMAT(cs.class_date_,'%Y-%m') >= #{currentMonth} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="organIds != null">
			AND FIND_IN_SET(cs.organ_id_,#{organIds})
		</if>
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="search != null and search != ''">
			AND (sa.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
		</if>
		GROUP BY sa.user_id_,DATE_FORMAT(cs.class_date_,'%Y-%m') HAVING COUNT(sa.id_) >= #{studentErrorLeaveNum} AND COUNT(sa.id_) > SUM(sa.leave_visit_flag_) ORDER BY cs.class_date_ DESC)c
		GROUP BY c.user_id_
		<include refid="global.limit"/>
	</select>
	<select id="countStudentLeaveCourseList" resultType="java.lang.Integer">
		SELECT COUNT(sa.id_)
		FROM student_attendance sa
		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		LEFT JOIN sys_user su ON su.id_ = cs.actual_teacher_id_
		<include refid="queryStudentLeaveCourseListSql"/>
	</select>
	<sql id="queryStudentLeaveCourseListSql">
		<where>
			sa.user_id_ = #{userId} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
			<if test="search != null and search != ''">
				AND (cs.id_ = #{search} OR cs.actual_teacher_id_ = #{search} OR su.real_name_ LIKE CONCAT('%',#{search},'%'))
			</if>
			<if test="leaveVisitFlag != null">
				AND sa.leave_visit_flag_ = #{leaveVisitFlag}
			</if>
			<if test="courseType != null">
				AND cs.type_ = #{courseType}
			</if>
		</where>
	</sql>
	<resultMap id="StudentLeaveCourseDto" type="com.ym.mec.biz.dal.dto.StudentLeaveCourseDto">
		<result property="leaveVisitFlag" column="leave_visit_flag_"/>
		<result property="classDate" column="class_date_"/>
		<result property="startClassTime" column="start_class_time_"/>
		<result property="endClassTime" column="end_class_time_"/>
		<result property="teacherName" column="teacher_name_"/>
		<result property="actualTeacherId" column="actual_teacher_id_"/>
		<result property="courseScheduleId" column="course_schedule_id_"/>
		<result property="groupType" column="group_type_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result property="courseScheduleType" column="type_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result property="courseName" column="name_"/>
		<result property="groupId" column="music_group_id_"/>
	</resultMap>
	<select id="queryStudentLeaveCourseList" resultMap="StudentLeaveCourseDto">
		SELECT sa.leave_visit_flag_,cs.class_date_,cs.start_class_time_,
		       cs.end_class_time_,su.real_name_ teacher_name_,cs.actual_teacher_id_,
		       sa.course_schedule_id_,cs.group_type_,cs.type_,cs.name_,cs.music_group_id_
		FROM student_attendance sa
		 LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		 LEFT JOIN sys_user su ON su.id_ = cs.actual_teacher_id_
		<include refid="queryStudentLeaveCourseListSql"/>
		ORDER BY cs.class_date_ DESC,cs.start_class_time_ DESC
		<include refid="global.limit"/>
	</select>
	<select id="getStudentErrorLeaveNumMap" resultType="java.util.Map">
		SELECT user_id_ 'key',SUM(total_num_) 'value'
		FROM (SELECT sa.user_id_,COUNT(sa.id_) total_num_
		FROM student_attendance sa
		LEFT JOIN course_schedule cs ON cs.id_ = sa.course_schedule_id_
		LEFT JOIN sys_user su ON su.id_ = sa.user_id_
		WHERE DATE_FORMAT(cs.class_date_,'%Y-%m') >= #{totalMonth} AND sa.status_ = 'LEAVE' AND cs.pre_course_flag_ = 0 and cs.tenant_id_ = #{tenantId}
		<if test="organIds != null">
			AND FIND_IN_SET(cs.organ_id_,#{organIds})
		</if>
		<if test="classGroupIds != null and classGroupIds.size() > 0">
			AND cs.class_group_id_ IN
			<foreach collection="classGroupIds" item="classGroupId" open="(" close=")" separator=",">
				#{classGroupId}
			</foreach>
		</if>
		<if test="search != null and search != ''">
			AND (sa.user_id_ = #{search} OR su.username_ LIKE CONCAT('%',#{search},'%') OR su.phone_ LIKE CONCAT('%',#{search},'%'))
		</if>
		GROUP BY sa.user_id_,DATE_FORMAT(cs.class_date_,'%Y-%m') HAVING COUNT(sa.id_) >= #{studentErrorLeaveNum} AND COUNT(sa.id_) > SUM(sa.leave_visit_flag_) ORDER BY cs.class_date_ DESC)c
		GROUP BY c.user_id_
	</select>

	<select id="getOrgansStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
			t.organ_id_,t.tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT t.user_id_ ) total_num_,
			COUNT( DISTINCT t.user_id_ ) activate_num_,
			COUNT( DISTINCT t.user_id_ ) percent_
		FROM((
			SELECT
				su.organ_id_,sr.tenant_id_,
				sr.user_id_
			FROM
				student_registration sr
				LEFT JOIN music_group mg ON sr.music_group_id_=mg.id_
				LEFT JOIN sys_user su ON sr.user_id_ = su.id_
			WHERE
				su.del_flag_ = 0 and sr.tenant_id_ = #{tenantId}
				AND mg.status_='PROGRESS'
				AND sr.music_group_status_ = 'NORMAL'
				<if test="dayStr!=null and dayStr!=''">
					AND DATE(sr.create_time_)&lt;= #{dayStr}
				</if>)
		UNION ALL
		(
			SELECT
				su.organ_id_,cssp.tenant_id_,
				cssp.user_id_
			FROM
				course_schedule_student_payment cssp
				LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
				LEFT JOIN sys_user su ON cssp.user_id_ = su.id_
			WHERE
				cssp.group_type_ IN ( 'VIP', 'PRACTICE' ) and cssp.tenant_id_ = #{tenantId}
				AND cs.status_ = 'NOT_START'
				AND su.del_flag_ = 0
				<if test="dayStr!=null and dayStr!=''">
					AND DATE(cssp.create_time_)&lt;= #{dayStr}
				</if>)) t
		WHERE t.user_id_ NOT IN (SELECT user_id_ FROM student WHERE subject_id_list_ REGEXP '21|25|26|27|28|29')
		GROUP BY t.organ_id_
	</select>

	<select id="getMemberStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,cto.tenant_id_,
			#{dayStr} month_,
			COUNT(DISTINCT cto.student_id_) total_num_,
			COUNT(DISTINCT cto.student_id_) activate_num_,
			COUNT(DISTINCT cto.student_id_) percent_
		FROM cloud_teacher_order cto
			LEFT JOIN sys_user su ON cto.student_id_=su.id_
		WHERE su.del_flag_=0 AND cto.status_ IN (1,2) and cto.tenant_id_ = #{tenantId}
			<if test="dayStr!=null and dayStr!=''">
				AND DATE(cto.create_time_)&lt;= #{dayStr}
			</if>
		GROUP BY su.organ_id_
	</select>

	<select id="getNewMemberStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
		su.organ_id_,cto.tenant_id_,
		#{dayStr} month_,
		COUNT(DISTINCT cto.student_id_) total_num_,
		COUNT(DISTINCT cto.student_id_) activate_num_,
		COUNT(DISTINCT cto.student_id_) percent_
		FROM cloud_teacher_order cto
		LEFT JOIN sys_user su ON cto.student_id_=su.id_
		WHERE su.del_flag_=0 AND cto.status_ IN (1,2) and cto.tenant_id_ = #{tenantId}
		<if test="dayStr!=null and dayStr!=''">
			AND DATE(cto.create_time_)= #{dayStr}
		</if>
		GROUP BY su.organ_id_
	</select>

	<select id="getExperienceMemberStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
		su.organ_id_,stu.tenant_id_,
		#{dayStr} month_,
		COUNT(DISTINCT stu.user_id_) total_num_,
		COUNT(DISTINCT stu.user_id_) activate_num_,
		COUNT(DISTINCT stu.user_id_) percent_
		FROM student stu
		LEFT JOIN cloud_teacher_order cto ON stu.user_id_=cto.student_id_
		LEFT JOIN sys_user su ON su.id_=stu.user_id_
		WHERE su.del_flag_=0 AND stu.experience_member_rank_setting_id_ IS NOT NULL AND (cto.id_ IS NULL OR cto.status_ NOT IN (1, 2)) and cto.tenant_id_ = #{tenantId}
		<if test="dayStr!=null and dayStr!=''">
			AND DATE(stu.experience_membership_start_time_)&lt;= #{dayStr}
		</if>
		GROUP BY su.organ_id_
	</select>

	<select id="getCloudStudyDayUseStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
			su.organ_id_,smcr.tenant_id_,
			#{dayStr} month_,
			COUNT(DISTINCT smcr.user_id_) total_num_,
			COUNT(DISTINCT smcr.user_id_) activate_num_,
			COUNT(DISTINCT smcr.user_id_) percent_
		FROM sys_music_compare_record smcr
			LEFT JOIN sys_user su ON smcr.user_id_=su.id_
			LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
		WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL and smcr.tenant_id_ = #{tenantId}
			<if test="dayStr!=null and dayStr!=''">
				AND DATE(smcr.create_time_)= #{dayStr}
			</if>
		GROUP BY su.organ_id_
	</select>

	<select id="getCloudStudyLivelyStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
			t.organ_id_,t.tenant_id_,
			#{dayStr} month_,
			COUNT(user_id_) total_num_,
			COUNT(user_id_) activate_num_,
			COUNT(user_id_) percent_
		FROM (SELECT
			su.organ_id_,su.tenant_id_,
			smcr.user_id_,
			COUNT(DISTINCT(CASE WHEN DATEDIFF(NOW(), smcr.create_time_)&lt;=15 THEN DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') ELSE NULL END)) days
			FROM sys_music_compare_record smcr
			LEFT JOIN sys_user su ON smcr.user_id_=su.id_
			LEFT JOIN student stu ON smcr.user_id_=stu.user_id_
			WHERE su.del_flag_=0 AND stu.user_id_ IS NOT NULL and smcr.tenant_id_ = #{tenantId}
			<if test="dayStr!=null and dayStr!=''">
				AND DATE(smcr.create_time_) &lt;= #{dayStr}
			</if>
			GROUP BY smcr.user_id_) t WHERE t.days>=5
		GROUP BY t.organ_id_
	</select>

	<select id="getCloudStudyNewStudentNumData" resultMap="IndexBaseMonthData">
		SELECT
			organ_id_,tenant_id_,
			#{dayStr} month_,
			COUNT( DISTINCT user_id_ ) total_num_,
			COUNT( DISTINCT user_id_ ) activate_num_,
			COUNT( DISTINCT user_id_ ) percent_
		FROM
		(
		SELECT
			su.organ_id_,smcr.tenant_id_,
			smcr.user_id_
		FROM
			sys_music_compare_record smcr
			LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
		WHERE su.del_flag_ = 0 and smcr.tenant_id_ = #{tenantId}
		GROUP BY user_id_
		HAVING MIN(DATE( smcr.create_time_ ))= #{dayStr}) t
		GROUP BY t.organ_id_
	</select>
	<resultMap id="CloudTeacherActiveTargetDto" type="com.ym.mec.biz.dal.dto.CloudTeacherActiveTargetDto">
		<result property="organId" column="organ_id_"/>
		<result property="organName" column="organ_name_"/>
		<result property="totalNum" column="total_num_"/>
		<result property="buyAmount" column="buy_amount_"/>
		<result property="buyNum" column="buy_num_"/>
		<result property="targetAmount" column="target_amount_"/>
		<result property="targetNum" column="target_num_"/>
	</resultMap>
    <select id="countCloudTeacherActive" resultMap="CloudTeacherActiveTargetDto">
		SELECT o.name_ organ_name_,o.id_ organ_id_,CASE WHEN SUM(cto.amount_) IS NULL THEN 0 ELSE SUM(cto.amount_) END buy_amount_,
		COUNT(DISTINCT cto.student_id_) buy_num_
		FROM student s
		LEFT JOIN cloud_teacher_order cto ON cto.student_id_ = s.user_id_ AND cto.status_ != 0 AND cto.active_remark_ = '202109'
		LEFT JOIN sys_user su ON su.id_ = s.user_id_
		LEFT JOIN organization o ON o.id_ = su.organ_id_
		WHERE  s.tenant_id_ = #{tenantId}
		<if test="organIdList != null and organIdList.size > 0">
			AND su.organ_id_ IN
			<foreach collection="organIdList" open="(" close=")" item="item" separator=",">
				#{item}
			</foreach>
		</if>
		GROUP BY su.organ_id_
	</select>
	<select id="getStudentVipOrderNum"  resultMap="IndexBaseMonthData">
		SELECT spo.create_time_ month_,spo.organ_id_,
		       COUNT(DISTINCT spo.id_) total_num_,
		       'STUDENT_VIP_ORDER_NUM' data_type_,spo.user_id_ extend_info_,spo.tenant_id_
		FROM (SELECT id_,user_id_,organ_id_,activity_id_,music_group_id_,calender_id_,type_,group_type_,
		             DATE_FORMAT(create_time_,'%Y-%m-%d') create_time_,tenant_id_ FROM student_payment_order
		WHERE status_ = 'SUCCESS' AND DATE_FORMAT(create_time_,'%Y-%m-%d') = #{dayStr} AND tenant_id_ = #{tenantId}) spo
		LEFT JOIN student_payment_order_detail spod ON spod.payment_order_id_ = spo.id_
		LEFT JOIN vip_group_activity vga ON FIND_IN_SET(vga.id_,spo.activity_id_)
		LEFT JOIN vip_group_category vgc ON vgc.id_ = vga.vip_group_category_id_list_
		LEFT JOIN vip_group vg ON vg.id_ = spo.music_group_id_
		LEFT JOIN vip_group_category vgc1 ON vgc1.id_ = vg.vip_group_category_id_
		LEFT JOIN music_group_payment_calender_activity mgpca ON mgpca.calender_id_ = spo.calender_id_
		LEFT JOIN vip_group_activity vga1 ON vga1.id_ = mgpca.activity_id_
		LEFT JOIN vip_group_category vgc2 ON vgc2.id_ = vga1.vip_group_category_id_list_
		WHERE (spo.group_type_ = 'SPORADIC' AND spo.type_ = 'DEGREE_REGISTRATION' AND spod.type_ = 'DEGREE_REGISTRATION')
		OR (spo.group_type_ = 'SPORADIC' AND spo.type_ = 'DOUBLE_ELEVEN2020') OR (spo.group_type_ = 'DEGREE' AND spod.type_ = 'VIP')
		OR (spo.type_ = 'SMALL_CLASS_TO_BUY' AND vgc1.name_ != '乐理课') OR (spo.group_type_ = 'MUSIC' AND spod.type_ = 'VIP' AND vgc2.name_ != '乐理课')
		OR (spo.type_ = 'DOUBLE_ELEVEN2021' AND vgc.name_ != '乐理课')
		GROUP BY spo.user_id_,spo.create_time_,spo.organ_id_;
	</select>
	<select id="getStudentTheoryOrderNum" resultMap="IndexBaseMonthData">
		SELECT spo.create_time_ month_,spo.organ_id_,
			   COUNT(DISTINCT spo.id_) total_num_,
			   'STUDENT_THEORY_ORDER_NUM' data_type_,spo.user_id_ extend_info_,spo.tenant_id_
		FROM (SELECT id_,user_id_,organ_id_,activity_id_,music_group_id_,calender_id_,type_,group_type_,
					 DATE_FORMAT(create_time_,'%Y-%m-%d') create_time_,tenant_id_ FROM student_payment_order
			  WHERE status_ = 'SUCCESS' AND DATE_FORMAT(create_time_,'%Y-%m-%d') = #{dayStr} AND tenant_id_ = #{tenantId}) spo
				 LEFT JOIN student_payment_order_detail spod ON spod.payment_order_id_ = spo.id_
				 LEFT JOIN vip_group_activity vga ON FIND_IN_SET(vga.id_,spo.activity_id_)
				 LEFT JOIN vip_group_category vgc ON vgc.id_ = vga.vip_group_category_id_list_
				 LEFT JOIN vip_group vg ON vg.id_ = spo.music_group_id_
				 LEFT JOIN vip_group_category vgc1 ON vgc1.id_ = vg.vip_group_category_id_
				 LEFT JOIN music_group_payment_calender_activity mgpca ON mgpca.calender_id_ = spo.calender_id_
				 LEFT JOIN vip_group_activity vga1 ON vga1.id_ = mgpca.activity_id_
				 LEFT JOIN vip_group_category vgc2 ON vgc2.id_ = vga1.vip_group_category_id_list_
		WHERE (spo.group_type_ = 'DEGREE' AND spod.type_ = 'THEORY_COURSE')
		   OR (spo.type_ = 'SMALL_CLASS_TO_BUY' AND vgc1.name_ = '乐理课') OR (spo.group_type_ = 'MUSIC' AND spod.type_ = 'VIP' AND vgc2.name_ = '乐理课')
		   OR (spo.type_ = 'DOUBLE_ELEVEN2021' AND vgc.name_ = '乐理课')
		GROUP BY spo.user_id_,spo.create_time_,spo.organ_id_;
	</select>
	<select id="getStudentPracticeOrderNum" resultMap="IndexBaseMonthData">
		SELECT spo.create_time_ month_,spo.organ_id_,
			   COUNT(DISTINCT spo.id_) total_num_,
			   'STUDENT_PRACTICE_ORDER_NUM' data_type_,spo.user_id_ extend_info_,spo.tenant_id_
		FROM (SELECT id_,user_id_,organ_id_,activity_id_,music_group_id_,calender_id_,type_,group_type_,
					 DATE_FORMAT(create_time_,'%Y-%m-%d') create_time_,tenant_id_ FROM student_payment_order
			  WHERE status_ = 'SUCCESS' AND DATE_FORMAT(create_time_,'%Y-%m-%d') = #{dayStr} AND tenant_id_ = #{tenantId}) spo
				 LEFT JOIN student_payment_order_detail spod ON spod.payment_order_id_ = spo.id_
		WHERE spo.type_ = 'PRACTICE_GROUP_BUY' OR spo.type_ = 'PRACTICE_GROUP_RENEW' OR (spo.group_type_ = 'MUSIC' AND spod.type_ = 'PRACTICE')
		GROUP BY spo.user_id_,spo.create_time_,spo.organ_id_;
	</select>
</mapper>
