<?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.StudentStatisticsDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.StudentStatistics" id="StudentStatistics">
		<result column="id_" property="id" />
		<result column="user_id_" property="userId" />
		<result column="teacher_id_" property="teacherId" />
		<result column="teacher_name_" property="teacherName" />
		<result column="music_director_id_" property="musicDirectorId" />
		<result column="music_director_name_" property="musicDirectorName" />
		<result column="total_course_num_" property="totalCourseNum" />
		<result column="over_course_num_" property="overCourseNum" />
		<result column="sub_course_num_" property="subCourseNum" />
		<result column="no_schedule_num_" property="noScheduleNum" />
		<result column="first_course_time_" property="firstCourseTime" />
		<result column="last_course_time_" property="lastCourseTime" />
		<result column="lately_course_consumer_" property="latelyCourseConsumer" />
		<result column="lately_year_course_consumer_" property="latelyYearCourseConsumer" />
		<result column="visit_num_" property="visitNum" />
		<result column="last_visit_status_" property="lastVisitStatus" />
		<result column="visit_reason_" property="visitReason" />
		<result column="last_visit_time_" property="lastVisitTime" />
		<result column="not_start_course_fee_" property="notStartCourseFee" />
		<result column="no_course_fee_" property="noCourseFee" />
		<result column="preCourseFee" property="preCourseFee" />
		<result column="first_order_time_" property="firstOrderTime" />
		<result column="last_order_time_" property="lastOrderTime" />
		<result column="order_num_" property="orderNum" />
		<result column="group_type_" property="groupType" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="StudentStatistics" >
		SELECT * FROM student_statistics WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="StudentStatistics">
		SELECT * FROM student_statistics ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentStatistics" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO student_statistics (id_,user_id_,teacher_id_,teacher_name_,music_director_id_,
		music_director_name_,total_course_num_,over_course_num_,sub_course_num_,
		no_schedule_num_,first_course_time_,last_course_time_,lately_course_consumer_,
		visit_num_,last_visit_status_,visit_reason_,last_visit_time_,not_start_course_fee_,no_course_fee_,first_order_time_,
		last_order_time_,order_num_,group_type_)
		VALUES(#{id},#{userId},#{teacherId},#{teacherName},#{musicDirectorId},#{musicDirectorName},
		       #{totalCourseNum},#{overCourseNum},#{subCourseNum},#{noScheduleNum},#{firstCourseTime},#{lastCourseTime},
		       #{latelyCourseConsumer},#{visitNum},#{lastVisitStatus},#{visitReason},#{lastVisitTime},#{notStartCourseFee},#{noCourseFee},#{firstOrderTime},
		       #{lastOrderTime},#{orderNum},#{groupType})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentStatistics">
		UPDATE student_statistics <set>
		<if test="overCourseNum != null">
		over_course_num_ = #{overCourseNum},
		</if>
		<if test="latelyCourseConsumer != null">
		lately_course_consumer_ = #{latelyCourseConsumer},
		</if>
		<if test="lastCourseTime != null">
		last_course_time_ = #{lastCourseTime},
		</if>
		<if test="totalCourseNum != null">
		total_course_num_ = #{totalCourseNum},
		</if>
		<if test="musicDirectorName != null">
		music_director_name_ = #{musicDirectorName},
		</if>
		<if test="visitNum != null">
		visit_num_ = #{visitNum},
		</if>
		<if test="teacherName != null">
		teacher_name_ = #{teacherName},
		</if>
		<if test="subCourseNum != null">
		sub_course_num_ = #{subCourseNum},
		</if>
		<if test="lastVisitStatus != null">
		last_visit_status_ = #{lastVisitStatus},
		</if>
		<if test="lastVisitTime != null">
		last_visit_time_ = #{lastVisitTime},
		</if>
		<if test="teacherId != null">
		teacher_id_ = #{teacherId},
		</if>
		<if test="musicDirectorId != null">
		music_director_id_ = #{musicDirectorId},
		</if>
		<if test="lastOrderTime != null">
		last_order_time_ = #{lastOrderTime},
		</if>
		<if test="firstOrderTime != null">
		first_order_time_ = #{firstOrderTime},
		</if>
		<if test="orderNum != null">
		order_num_ = #{orderNum},
		</if>
		<if test="groupType != null">
		group_type_ = #{groupType},
		</if>
		<if test="visitReason != null">
		visit_reason_ = #{visitReason},
		</if>
		<if test="notStartCourseFee != null">
			not_start_course_fee_ = #{notStartCourseFee},
		</if>
		<if test="noCourseFee != null">
			no_course_fee_ = #{noCourseFee},
		</if>
		<if test="noScheduleNum != null">
		no_schedule_num_ = #{noScheduleNum},
		</if>
		<if test="firstCourseTime != null">
		first_course_time_ = #{firstCourseTime},
		</if>
		</set> WHERE id_ = #{id}
	</update>
	<update id="clean">
		UPDATE student_statistics ss SET ss.total_course_num_ = 0,ss.sub_course_num_ = 0,
		ss.over_course_num_ = 0,ss.lately_course_consumer_ = 0,ss.lately_year_course_consumer_ = 0,
		ss.no_course_fee_ = 0,ss.no_schedule_num_ = 0,ss.normal_group_num_ = 0,ss.not_start_course_fee_ = 0,
		ss.teacher_id_ = NULL,ss.teacher_name_ = NULL,ss.music_director_id_ = NULL,ss.music_director_name_ = NULL
	</update>
	<update id="batchUpdate">
		<foreach collection="statisticsList" item="bean" index="index" open="" close="" separator=";">
			UPDATE student_statistics
			<set>
				<if test="bean.overCourseNum != null">
					over_course_num_ = #{bean.overCourseNum},
				</if>
				<if test="bean.latelyCourseConsumer != null">
					lately_course_consumer_ = #{bean.latelyCourseConsumer},
				</if>
				<if test="bean.lastCourseTime != null">
					last_course_time_ = #{bean.lastCourseTime},
				</if>
				<if test="bean.totalCourseNum != null">
					total_course_num_ = #{bean.totalCourseNum},
				</if>
				<if test="bean.musicDirectorName != null and bean.musicDirectorName != ''">
					music_director_name_ = #{bean.musicDirectorName},
				</if>
				<if test="bean.teacherName != null and bean.teacherName != ''">
					teacher_name_ = #{bean.teacherName},
				</if>
				<if test="bean.subCourseNum != null">
					sub_course_num_ = #{bean.subCourseNum},
				</if>
				<if test="bean.teacherId != null">
					teacher_id_ = #{bean.teacherId},
				</if>
				<if test="bean.musicDirectorId != null">
					music_director_id_ = #{bean.musicDirectorId},
				</if>
				<if test="bean.notStartCourseFee != null">
					not_start_course_fee_ = #{bean.notStartCourseFee},
				</if>
				<if test="bean.noCourseFee != null">
					no_course_fee_ = #{bean.noCourseFee},
				</if>
				<if test="bean.noScheduleNum != null">
					no_schedule_num_ = #{bean.noScheduleNum},
				</if>
				<if test="bean.firstCourseTime != null">
					first_course_time_ = #{bean.firstCourseTime},
				</if>
				id_ = id_
			</set> WHERE user_id_ = #{bean.userId} AND group_type_ = #{bean.groupType}
		</foreach>
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM student_statistics WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="StudentStatistics" parameterType="map">
		SELECT * FROM student_statistics ORDER BY id_ <include refid="global.limit"/>
	</select>
	<update id="updateTeacherAndEdu">
		SELECT updateTeacherAndEdu()
	</update>
	<update id="updateCourseNum">
		SELECT updateCourseNum()
	</update>
	<update id="updateNoCourseNum">
		SELECT updateNoCourseNum()
	</update>
	<update id="updateNotStartCourseFee">
		SELECT updateNotStartCourseFee()
	</update>
	<update id="updateNoCourseFee">
		SELECT updateNoCourseFee()
	</update>
	<update id="updateFirstAndLastCourseTime">
		SELECT updateFirstAndLastCourseTime()
	</update>
	<update id="updateNormalGroupNum">
		SELECT updateNormalGroupNum()
	</update>
	<update id="updateFirstOrderTime">
		SELECT updateFirstOrderTime()
	</update>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM student_statistics
	</select>
	<resultMap id="StudentStatisticsDto" type="com.ym.mec.biz.dal.dto.StudentStatisticsDto" extends="StudentStatistics">
		<association property="studentBasicInfo" javaType="com.ym.mec.biz.dal.entity.StudentBasicInfo">
			<result column="user_id_" property="userId" />
			<result column="user_name_" property="userName" />
			<result column="phone_" property="phone" />
			<result column="subject_id_" property="subjectId" />
			<result column="subject_name_" property="subjectName" />
			<result column="grade_" property="grade" />
			<result column="organ_id_" property="organId" />
			<result column="organ_name_" property="organName" />
			<result column="cooperation_organ_id_" property="cooperationOrganId" />
			<result column="cooperation_organ_name_" property="cooperationOrganName" />
			<result column="subject_teacher_id_" property="subjectTeacherId" />
			<result column="subject_teacher_name_" property="subjectTeacherName" />
			<result column="course_balance_" property="courseBalance" />
			<result column="student_status_" property="studentStatus" />
		</association>
	</resultMap>
	<sql id="queryStatisticsSql">
		<where>
			<if test="search != null and search != ''">
				AND (sbi.user_id_ = #{search} OR sbi.user_name_ LIKE CONCAT('%',#{search},'%'))
			</if>
			<if test="subjectId != null">
				AND sbi.subject_id_ = #{subjectId}
			</if>
			<if test="studentStatus != null and studentStatus != ''">
				<if test="studentStatus == 'NORMAL'">
					AND (ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0)
				</if>
				<if test="studentStatus == 'SLEEPY'">
					AND ss.over_course_num_ > 0 AND (ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0) AND ss.lately_year_course_consumer_ &lt;= 0
				</if>
				<if test="studentStatus == 'LOST'">
					AND ss.over_course_num_ > 0 AND ss.sub_course_num_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0 AND suca.course_balance_ &lt;= 0
				</if>
				<if test="studentStatus == 'PAUSE'">
					AND suca.course_balance_ > 0 AND ss.sub_course_num_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0
				</if>
			</if>
			<if test="studentStatus == null or studentStatus == ''">
				AND (ss.over_course_num_ > 0 OR ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0 OR suca.course_balance_ > 0)
			</if>
			<if test="feedbackType != null and feedbackType != ''">
				AND ss.last_visit_status_ = #{feedbackType}
			</if>
			<if test="latelyCourseConsumer != null">
				AND ss.lately_course_consumer_ = #{latelyCourseConsumer}
			</if>
			<if test="latelyYearCourseConsumer != null">
				AND ss.lately_year_course_consumer_ = #{latelyYearCourseConsumer}
			</if>
			<if test="visitNum != null">
				AND ss.visit_num_ = #{visitNum}
			</if>
			<if test="teacherId != null">
				AND ss.teacher_id_ = #{teacherId}
			</if>
			<if test="subjectTeacherId != null">
				AND sbi.subject_teacher_id_ = #{subjectTeacherId}
			</if>
			<if test="musicDirectorId != null">
				AND ss.music_director_id_ = #{musicDirectorId}
			</if>
			<if test="courseConsumerError != null and courseConsumerError == true">
				AND ss.lately_course_consumer_ &lt; 4
			</if>
			<if test="courseConsumerError != null and courseConsumerError == false">
				AND ss.lately_course_consumer_ >= 4
			</if>
			<if test="wornFlag != null and wornFlag == true">
				AND (ss.no_schedule_num_ + ss.sub_course_num_) &lt; 4
			</if>
			<if test="wornFlag != null and wornFlag == false">
				AND (ss.no_schedule_num_ + ss.sub_course_num_) > 3
			</if>
			<if test="firstCourseStartTime != null">
				AND ss.first_course_time_ >= #{firstCourseStartTime}
			</if>
			<if test="firstCourseEndTime != null">
				AND ss.first_course_time_ &lt;= #{firstCourseEndTime}
			</if>
			<if test="lastVisitStartTime != null and lastVisitStartTime != '' ">
				AND ss.last_visit_time_ >= #{lastVisitStartTime}
			</if>
			<if test="lastVisitEndTime != null and lastVisitEndTime != '' ">
				AND ss.last_visit_time_ &lt;= #{lastVisitEndTime}
			</if>
			<if test="subCourseMinNum != null">
				AND (ss.no_schedule_num_ + ss.sub_course_num_) >= #{subCourseMinNum}
			</if>
			<if test="subCourseMaxNum != null">
				AND (ss.no_schedule_num_ + ss.sub_course_num_) &lt;= #{subCourseMaxNum}
			</if>
			<if test="groupType != null and groupType != ''">
				AND ss.group_type_ = #{groupType}
			</if>
			<if test="organIdList != null and organIdList.size > 0">
				AND sbi.organ_id_ IN
				<foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
					#{organId}
				</foreach>
			</if>
		</where>
	</sql>
	<select id="countStatistics" resultType="java.lang.Integer">
		SELECT COUNT(sbi.id_) FROM student_basic_info sbi
		LEFT JOIN student_statistics ss ON ss.user_id_ = sbi.user_id_
		LEFT JOIN sys_user_cash_account suca ON sbi.user_id_ = suca.user_id_
		<include refid="queryStatisticsSql"/>
	</select>
	<select id="queryStatistics" resultMap="StudentStatisticsDto">
		SELECT sbi.*,ss.not_start_course_fee_ + ss.no_course_fee_ preCourseFee,
			CASE WHEN (ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0) THEN '在读'
			WHEN ss.over_course_num_ > 0 AND (ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0) AND ss.lately_year_course_consumer_ &lt;= 0 THEN '沉睡'
			WHEN ss.over_course_num_ > 0 AND ss.sub_course_num_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0 AND suca.course_balance_ &lt;= 0 THEN '流失'
			WHEN suca.course_balance_ > 0 AND ss.sub_course_num_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0 THEN '暂停' ELSE '其他' END student_status_
			,suca.course_balance_,
			ss.last_visit_time_
		FROM student_basic_info sbi
		LEFT JOIN student_statistics ss ON ss.user_id_ = sbi.user_id_
		LEFT JOIN sys_user_cash_account suca ON sbi.user_id_ = suca.user_id_
		<include refid="queryStatisticsSql"/>
		<include refid="global.limit"/>
	</select>
	<resultMap id="StudentStatisticsSumDto" type="com.ym.mec.biz.dal.dto.StudentStatisticsSumDto">
		<result property="sleepStudentNum" column="sleepStudentNum"/>
		<result property="sleepStudentHasNotSchedule" column="sleepStudentHasNotSchedule"/>
		<result property="sleepStudentNoNotSchedule" column="sleepStudentNoNotSchedule"/>
		<result property="normalStudentNum" column="normalStudentNum"/>
		<result property="normalStudentHasNormalGroupNum" column="normalStudentHasNormalGroupNum"/>
		<result property="hasCourseBalanceAndNotSubCourseNum" column="hasCourseBalanceAndNotSubCourseNum"/>
		<result property="normalStudentHasNoScheduleNum" column="normalStudentHasNoScheduleNum"/>
		<result property="waitRenewNum" column="waitRenewNum"/>
		<result property="subCourseNum" column="subCourseNum"/>
		<result property="noScheduleNum" column="noScheduleNum"/>
	</resultMap>
	<select id="studentSmallClassStatisticsSum" resultMap="StudentStatisticsSumDto">
		SELECT
		COUNT(CASE WHEN ss.over_course_num_ > 0 AND (ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0) AND ss.lately_year_course_consumer_ &lt;= 0 THEN 1 ELSE NULL END) 'sleepStudentNum',
		COUNT(CASE WHEN ss.over_course_num_ > 0 AND (ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0) AND ss.lately_year_course_consumer_ &lt;= 0 AND ss.no_schedule_num_ > 0 THEN 1 ELSE NULL END) 'sleepStudentHasNotSchedule',
		COUNT(CASE WHEN ss.over_course_num_ > 0 AND (ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0) AND ss.lately_year_course_consumer_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0 THEN 1 ELSE NULL END) 'sleepStudentNoNotSchedule',
		COUNT(CASE WHEN (ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0) THEN 1 ELSE NULL END) 'normalStudentNum',
		COUNT(CASE WHEN ((ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0)) AND ss.normal_group_num_ > 0 THEN 1 ELSE NULL END) 'normalStudentHasNormalGroupNum',
		COUNT(CASE WHEN suca.course_balance_ > 0 AND ss.sub_course_num_ &lt;= 0 AND ss.no_schedule_num_ &lt;= 0 THEN 1 ELSE NULL END) 'hasCourseBalanceAndNotSubCourseNum',
		COUNT(CASE WHEN ((ss.no_schedule_num_ > 0 OR ss.sub_course_num_ > 0) AND (ss.lately_year_course_consumer_ > 0 OR ss.over_course_num_ &lt;= 0)) AND ss.no_schedule_num_ > 0 THEN 1 ELSE NULL END) 'normalStudentHasNoScheduleNum',
		COUNT(CASE WHEN (ss.no_schedule_num_ + ss.sub_course_num_) &lt; 4 THEN 1 ELSE NULL END) 'waitRenewNum',
		SUM(ss.sub_course_num_) 'subCourseNum',
		SUM(ss.no_schedule_num_) 'noScheduleNum'
		FROM student_statistics ss
		LEFT JOIN sys_user_cash_account suca ON ss.user_id_ = suca.user_id_
		LEFT JOIN student_basic_info sbi ON ss.user_id_ = sbi.user_id_
		WHERE ss.group_type_ = #{groupType}
		AND (ss.over_course_num_ > 0 OR ss.sub_course_num_ > 0 OR ss.no_schedule_num_ > 0 OR suca.course_balance_ > 0)
		<if test="organIdList != null and organIdList.size > 0">
			AND sbi.organ_id_ IN
			<foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>
    <select id="countAddStudentNum" resultType="java.lang.Integer">
		SELECT COUNT(DISTINCT ss.user_id_) FROM student_statistics ss
		LEFT JOIN student_basic_info sbi ON sbi.user_id_ = ss.user_id_
		WHERE ss.group_type_ = #{groupType} AND DATE_FORMAT(ss.first_order_time_, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
		<if test="organIdList != null and organIdList.size > 0">
			AND sbi.organ_id_ IN
			<foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>
	<select id="countRenewStudentNum" resultType="java.lang.Integer">
		SELECT COUNT(cssp.user_id_) FROM (
		<if test="groupType == 'VIP'">
			SELECT cssp.user_id_,MIN(vg.create_time_) first_order_time_,MAX(vg.create_time_) last_order_time_ FROM course_schedule_student_payment cssp
			LEFT JOIN vip_group vg ON CONVERT(vg.id_ , CHAR) = cssp.music_group_id_
			LEFT JOIN vip_group_category vgc ON vgc.id_ = vg.vip_group_category_id_
			WHERE cssp.actual_price_ > 0 AND cssp.group_type_ = 'VIP' AND vgc.music_theory_ = 0 AND DATE_FORMAT(vg.create_time_, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
			GROUP BY cssp.user_id_
		</if>
		<if test="groupType == 'THEORY'">
			SELECT cssp.user_id_,MIN(vg.create_time_) first_order_time_,MAX(vg.create_time_) last_order_time_ FROM course_schedule_student_payment cssp
			LEFT JOIN vip_group vg ON CONVERT(vg.id_ , CHAR) = cssp.music_group_id_
			LEFT JOIN vip_group_category vgc ON vgc.id_ = vg.vip_group_category_id_
			WHERE cssp.actual_price_ > 0 AND cssp.group_type_ = 'VIP' AND vgc.music_theory_ AND DATE_FORMAT(vg.create_time_, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
			GROUP BY cssp.user_id_
		</if>
		<if test="groupType == 'PRACTICE'">
			SELECT cssp.user_id_,MIN(pg.create_time_) first_order_time_,MAX(pg.create_time_) last_order_time_ FROM course_schedule_student_payment cssp
			LEFT JOIN practice_group pg ON CONVERT(pg.id_ , CHAR) = cssp.music_group_id_
			WHERE cssp.actual_price_ > 0 AND cssp.group_type_ = 'PRACTICE' AND DATE_FORMAT(pg.create_time_, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
			GROUP BY cssp.user_id_
		</if> ) cssp
		LEFT JOIN student_statistics ss ON cssp.user_id_ = ss.user_id_
		WHERE ss.group_type_ = #{groupType} AND (cssp.first_order_time_ != ss.first_order_time_ OR cssp.last_order_time_ != ss.first_order_time_)
		AND ss.first_order_time_ IS NOT NULL;
	</select>
	<select id="countVisitNum" resultType="java.lang.Integer">
		SELECT COUNT(DISTINCT student_id_) FROM student_visit
		WHERE type_ = '小课回访' AND purpose_ =
		<if test="groupType == 'VIP'">
			'VIP课回访'
		</if>
		<if test="groupType == 'THEORY'">
			'乐理课回访'
		</if>
		<if test="groupType == 'PRACTICE'">
			'网管课回访'
		</if>
		<if test="startDate != null and startDate != ''">
			AND visit_time_ >= #{startDate}
		</if>
		<if test="endDate != null and endDate != ''">
			AND visit_time_ &lt;= #{endDate}
		</if>
		<if test="organIdList != null and organIdList.size > 0">
			AND organ_id_ IN
			<foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>
	<select id="countLostStudentNum" resultType="java.lang.Integer">
		SELECT COUNT(ss.id_) FROM student_statistics ss
		LEFT JOIN student_basic_info sbi ON ss.user_id_ = sbi.user_id_
		WHERE ss.group_type_ = #{groupType} AND ss.last_visit_status_ = 'LOST'
		<if test="startDate != null and startDate != ''">
			AND ss.last_visit_time_ >= #{startDate}
		</if>
		<if test="endDate != null and endDate != ''">
			AND ss.last_visit_time_ &lt;= #{endDate}
		</if>
		<if test="organIdList != null and organIdList.size > 0">
			AND sbi.organ_id_ IN
			<foreach collection="organIdList" item="organId" open="(" close=")" separator=",">
				#{organId}
			</foreach>
		</if>
	</select>
	<select id="queryTeacherIds" resultType="java.lang.Integer">
		SELECT DISTINCT teacher_id_ FROM student_statistics WHERE group_type_ = #{groupType} AND teacher_id_ IS NOT NULL
	</select>
	<select id="queryDirectorList" resultType="java.lang.Integer">
		SELECT DISTINCT music_director_id_ FROM student_statistics WHERE group_type_ = #{groupType} AND music_director_id_ IS NOT NULL
	</select>
	<sql id="dateTypeSql">
		WHERE data_type_ =
		<if test="groupType == 'VIP'">
			'STUDENT_VIP_ORDER_NUM'
		</if>
		<if test="groupType == 'THEORY'">
			'STUDENT_THEORY_ORDER_NUM'
		</if>
		<if test="groupType == 'PRACTICE'">
			'STUDENT_PRACTICE_ORDER_NUM'
		</if>
	</sql>
	
	<select id="queryNoScheduleNumStudent" resultType="com.ym.mec.biz.dal.dto.StudentOrganDto">
		SELECT ss.`user_id_` userId,u.organ_id_ organId FROM `student_statistics` ss 
		LEFT JOIN `sys_user` u on u.`id_` = ss.`user_id_`
		WHERE ss.`no_schedule_num_` > 0
		AND u.organ_id_ IN
        <foreach collection="organIds" item="organId" open="(" close=")" separator=",">
            #{organId}
        </foreach>
        group by ss.user_id_ , u.organ_id_
	</select>
</mapper>
