<?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.ExtracurricularExercisesReplyDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply" id="ExtracurricularExercisesReply">
		<result column="id_" property="id" />
		<result column="extracurricular_exercises_id_" property="extracurricularExercisesId" />
		<result column="title_" property="extracurricularExercises.title" />
		<result column="user_id_" property="userId" />
		<result column="username_" property="user.username" />
		<result column="attachments_" property="attachments" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="remark_" property="remark" />
		<result column="status_" property="status" />
		<result column="is_replied_" property="isReplied" />
		<result column="is_replied_timely_" property="isRepliedTimely" />
		<result column="is_view_" property="isView" />
		<result column="organ_name_" property="organName" />
		<result column="submit_time_" property="submitTime" />
		<result column="music_score_id_" property="musicScoreId" />
		<result column="music_score_content_" property="musicScoreContent" />
		<result column="tenant_id_" property="tenantId" />
		<result column="standard_flag_" property="standardFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<association property="extracurricularExercises" columnPrefix="ee_" resultMap="com.ym.mec.biz.dal.dao.ExtracurricularExercisesDao.ExtracurricularExercises"/>
	</resultMap>

	<resultMap id="ExtraExerciseStudentsDto" type="com.ym.mec.biz.dal.dto.ExtraExerciseStudentsDto" extends="ExtracurricularExercisesReply">
		<result column="student_name_" property="studentName"/>
		<result column="teacher_id_" property="teacherId"/>
		<result column="teacher_name_" property="teacherName"/>
		<result column="avatar_" property="headUrl"/>
		<result column="phone_" property="phone"/>
		<result column="title_" property="title"/>
		<result column="content_" property="content"/>
		<result column="expire_date_" property="expireDate"/>
		<result column="music_score_id_" property="musicScoreId" />
		<result column="music_score_content_" property="musicScoreContent" />
		<result column="homework_create_time_" property="homeworkCreateTime" />
	</resultMap>

	<sql id="queryPageCondition">
		<where>
			eer.tenant_id_ = #{tenantId}
			<if test="extracurricularExercisesId != null">
				AND extracurricular_exercises_id_ = #{extracurricularExercisesId}
			</if>
			<if test="teacherId != null">
				AND teacher_id_ = #{teacherId}
			</if>
			<if test="organIdList != null">
				AND FIND_IN_SET(o.id_, #{organIdList})
			</if>
			<if test="studentId != null">
				AND user_id_ = #{studentId}
			</if>
			<if test="title != null">
				AND title_ like '%' #{title} '%'
			</if>
			<if test="status != null">
				AND eer.status_ = #{status}
			</if>
			<if test="isReplied != null">
				AND is_replied_ = #{isReplied}
			</if>
			<if test="isView != null">
				AND is_view_ = #{isView}
			</if>
			<if test="search != null">
				AND (title_ like concat('%',#{search},'%') or u.username_ like concat('%',#{search},'%'))
			</if>
			<if test="submitStartTime != null">
				AND date(eer.create_time_) &gt;= #{submitStartTime}
			</if>
			<if test="submitEndTime != null">
				AND date(eer.create_time_) &lt;= #{submitEndTime}
			</if>
		</where>
	</sql>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="ExtracurricularExercisesReply" >
		SELECT * FROM extracurricular_exercises_reply WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="ExtracurricularExercisesReply">
		SELECT * FROM extracurricular_exercises_reply where tenant_id_ = #{tenantId} ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO extracurricular_exercises_reply (extracurricular_exercises_id_,user_id_,attachments_,create_time_,
		                                             update_time_,remark_,status_,is_replied_,is_view_,is_replied_timely_,
		                                             music_score_id_,music_score_content_,tenant_id_,standard_flag_)
		VALUES(#{extracurricularExercisesId},#{userId},#{attachments},NOW(),NOW(),#{remark},#{status},#{isReplied},#{isView},
		       #{isRepliedTimely},#{musicScoreId},#{musicScoreContent},#{tenantId},#{standardFlag})
	</insert>

	<insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO extracurricular_exercises_reply (extracurricular_exercises_id_,user_id_,attachments_,
		                                             create_time_,update_time_,remark_,status_,is_replied_,is_view_,
		                                             is_replied_timely_,music_score_id_,music_score_content_,tenant_id_,standard_flag_)
		VALUES
		<foreach collection="replies" item="reply" separator=",">
			(#{reply.extracurricularExercisesId},#{reply.userId},#{reply.attachments},NOW(),NOW(),
			 #{reply.remark},#{reply.status},#{reply.isReplied},#{reply.isView},#{reply.isRepliedTimely},
			 #{reply.musicScoreId},#{reply.musicScoreContent},#{replay.tenantId},#{replay.standardFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
		</foreach>
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply">
		UPDATE extracurricular_exercises_reply
		<set>
			<if test="standardFlag != null">
				standard_flag_ = #{standardFlag,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="musicScoreId != null">
				music_score_id_ = #{musicScoreId},
			</if>
			<if test="musicScoreContent != null and musicScoreContent != ''">
				music_score_content_ = #{musicScoreContent},
			</if>
			<if test="status != null">
			status_ = #{status},
			</if>
			<if test="isView != null">
			is_view_ = #{isView},
			</if>
			<if test="userId != null">
			user_id_ = #{userId},
			</if>
			<if test="remark != null">
			remark_ = #{remark},
			</if>
			<if test="id != null">
			id_ = #{id},
			</if>
			<if test="isReplied != null">
			is_replied_ = #{isReplied},
			</if>
			<if test="isRepliedTimely != null">
				is_replied_timely_ = #{isRepliedTimely},
			</if>
			<if test="extracurricularExercisesId != null">
			extracurricular_exercises_id_ = #{extracurricularExercisesId},
			</if>
			<if test="attachments != null">
			attachments_ = #{attachments},
			</if>
			<if test="submitTime != null">
				submit_time_ = #{submitTime},
			</if>
			update_time_ = NOW()
		</set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM extracurricular_exercises_reply WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="ExtraExerciseStudentsDto" parameterType="map">
		SELECT eer.*,u.username_,ee.title_,o.name_ organ_name_,ee.teacher_id_,ee.expire_date_
		FROM extracurricular_exercises_reply eer
		left join extracurricular_exercises ee on eer.extracurricular_exercises_id_ = ee.id_
		left join sys_user u on eer.user_id_ = u.id_
		left join teacher t on t.id_ = ee.teacher_id_
		left join organization o on o.id_ = t.organ_id_
		<include refid="queryPageCondition"/>
		 ORDER BY eer.id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(eer.id_) FROM extracurricular_exercises_reply eer
		left join extracurricular_exercises ee on eer.extracurricular_exercises_id_ = ee.id_
		left join sys_user u on eer.user_id_ = u.id_
		left join teacher t on t.id_ = ee.teacher_id_
		left join organization o on o.id_ = t.organ_id_
		<include refid="queryPageCondition"/>
	</select>
	
	<select id="findExtraExerciseStudents" resultMap="ExtraExerciseStudentsDto">
		SELECT
			eer.*,
			su.username_ student_name_,
		    su.avatar_,
		    su.phone_
		FROM
			extracurricular_exercises_reply eer
			LEFT JOIN sys_user su ON su.id_ = eer.user_id_
		WHERE eer.extracurricular_exercises_id_= #{extraExerciseId}
		<if test="studentName != null">
			AND su.username_ LIKE CONCAT('%',#{studentName},'%')
		</if>
	</select>

	<select id="findExtraExerciseStudentsByExtraExercises" resultMap="ExtracurricularExercisesReply">
		SELECT * FROM extracurricular_exercises_reply WHERE extracurricular_exercises_id_ IN
		<foreach collection="extraExerciseIds" item="extraExerciseId" open="(" close=")" separator=",">
			#{extraExerciseId}
		</foreach>
	</select>

	<select id="findExtraExerciseReply" resultMap="ExtraExerciseStudentsDto">
		SELECT
			eer.*,
			ee.title_,
			ee.content_,
			ee.expire_date_,
			ee.teacher_id_,
			eer.music_score_id_,
			eer.music_score_content_,
			eer.standard_flag_,
			su.username_ student_name_,
			ee.create_time_ homework_create_time_
		FROM
			extracurricular_exercises_reply eer
			LEFT JOIN extracurricular_exercises ee ON ee.id_=eer.extracurricular_exercises_id_
			LEFT JOIN sys_user su ON su.id_ = eer.user_id_
		WHERE
			eer.id_ = #{extraExerciseReplyId}
	</select>

	<sql id="queryStudentExtraExercisesCondition">
		<where>
			eer.tenant_id_ = #{tenantId}
			<if test="studentId!=null">
				AND eer.user_id_=#{studentId}
			</if>
			<if test="createTime!=null">
				AND DATE_FORMAT(eer.create_time_, '%Y-%m') = DATE_FORMAT(#{createTime}, '%Y-%m')
			</if>
		</where>
	</sql>
	<select id="countStudentExtraExercises" resultType="int">
		SELECT COUNT(id_) FROM extracurricular_exercises_reply eer
		<include refid="queryStudentExtraExercisesCondition"/>
	</select>
	<select id="findStudentExtraExercises" resultMap="ExtraExerciseStudentsDto">
		SELECT
			eer.*,
			ee.title_,
			ee.expire_date_,
			ee.teacher_id_,
			tea.real_name_ teacher_name_,
			tea.avatar_,
			su.username_ student_name_
		FROM
			extracurricular_exercises_reply eer
			LEFT JOIN extracurricular_exercises ee ON ee.id_=eer.extracurricular_exercises_id_
			LEFT JOIN sys_user su ON su.id_ = eer.user_id_
			LEFT JOIN sys_user tea ON tea.id_ = ee.teacher_id_
			<include refid="queryStudentExtraExercisesCondition"/>
			ORDER BY eer.create_time_ DESC
		<include refid="global.limit"/>
	</select>
	<select id="countIsSubmitStudents" resultType="int">
		SELECT COUNT(id_) FROM extracurricular_exercises_reply WHERE extracurricular_exercises_id_=#{extraExerciseId} AND attachments_ IS NOT NULL
	</select>

	<sql id="queryExtraExercisesCondition">
		<where>
			eer.tenant_id_ = #{tenantId}
			<if test="cloudHomeworkFlag != null and cloudHomeworkFlag == true">
				AND eer.music_score_id_ IS NOT NULL AND eer.music_score_id_ != ''
			</if>
			<if test="cloudHomeworkFlag != null and cloudHomeworkFlag == false">
				AND (eer.music_score_id_ IS NULL OR eer.music_score_id_ = '')
			</if>
			<if test="extracurricularExercisesId != null">
				AND extracurricular_exercises_id_ = #{extracurricularExercisesId}
			</if>
			<if test="teacherId != null">
				AND teacher_id_ = #{teacherId}
			</if>
			<if test="organIdList != null">
				AND FIND_IN_SET(o.id_, #{organIdList})
			</if>
			<if test="studentId != null">
				AND user_id_ = #{studentId}
			</if>
			<if test="title != null">
				AND title_ like '%' #{title} '%'
			</if>
			<if test="status != null">
				AND eer.status_ = #{status}
			</if>
			<if test="isReplied != null">
				AND is_replied_ = #{isReplied}
			</if>
			<if test="isView != null">
				AND is_view_ = #{isView}
			</if>
			<if test="search != null">
				AND (title_ like concat('%',#{search},'%') or u.id_=#{search} or u.username_ like concat('%',#{search},'%'))
			</if>
			<if test="submitStartTime != null">
				AND date(eer.create_time_) &gt;= #{submitStartTime}
			</if>
			<if test="submitEndTime != null">
				AND date(eer.create_time_) &lt;= #{submitEndTime}
			</if>
			<if test="expireStartDate != null and expireEndDate != null">
				AND DATE_FORMAT(ee.expire_date_,"%Y%m%d") BETWEEN DATE_FORMAT(#{expireStartDate},"%Y%m%d") AND DATE_FORMAT(#{expireEndDate},"%Y%m%d")
			</if>
			<if test="isRepliedTimely!=null">
				AND eer.is_replied_timely_=#{isRepliedTimely}
			</if>
			<if test="existVipCourse!=null and existVipCourse==1">
				AND EXISTS (SELECT cssp.id_ FROM course_schedule_student_payment cssp LEFT JOIN course_schedule cs ON cs.id_=cssp.course_schedule_id_ WHERE cssp.user_id_=eer.user_id_ AND cssp.group_type_='VIP' AND CONCAT(cs.class_date_," ",cs.start_class_time_) &gt; NOW())
			</if>
			<if test="existVipCourse!=null and existVipCourse==0">
				AND NOT EXISTS (SELECT cssp.id_ FROM course_schedule_student_payment cssp LEFT JOIN course_schedule cs ON cs.id_=cssp.course_schedule_id_ WHERE cssp.user_id_=eer.user_id_ AND cssp.group_type_='VIP' AND CONCAT(cs.class_date_," ",cs.start_class_time_) &gt; NOW())
			</if>
		</where>
	</sql>

	<select id="findExtraExercises" resultMap="ExtraExerciseStudentsDto">
		SELECT eer.*,u.username_,ee.title_,ee.content_,o.name_ organ_name_,ee.teacher_id_,ee.expire_date_
		FROM extracurricular_exercises_reply eer
		left join extracurricular_exercises ee on eer.extracurricular_exercises_id_ = ee.id_
		left join sys_user u on eer.user_id_ = u.id_
		left join teacher t on t.id_ = ee.teacher_id_
		left join organization o on o.id_ = u.organ_id_
		<include refid="queryExtraExercisesCondition"/>
		ORDER BY eer.id_ <include refid="global.limit"/>
	</select>
	<select id="countExtraExercises" resultType="int">
		SELECT COUNT(eer.id_) FROM extracurricular_exercises_reply eer
		left join extracurricular_exercises ee on eer.extracurricular_exercises_id_ = ee.id_
		left join sys_user u on eer.user_id_ = u.id_
		left join teacher t on t.id_ = ee.teacher_id_
		left join organization o on o.id_ = u.organ_id_
		<include refid="queryExtraExercisesCondition"/>
	</select>

	<resultMap id="StudentServiceHomeworkDto" type="com.ym.mec.biz.dal.dto.StudentServiceHomeworkDto">
		<result column="id_" property="id" />
		<result column="user_id_" property="userId" />
		<result column="status_" property="status" />
		<result column="is_replied_" property="isReplied" />
		<result column="is_replied_timely_" property="isRepliedTimely" />
		<result column="is_view_" property="isView" />
		<result column="submit_time_" property="submitTime" />
		<result column="type_" property="type" />
	</resultMap>

	<select id="findStudentHomewarksInWeek" resultMap="StudentServiceHomeworkDto">
		SELECT
			eer.id_,
			eer.user_id_,
			eer.status_,
			eer.submit_time_,
			eer.is_replied_,
			eer.is_replied_timely_,
			'EXTRA' type_
		FROM
			extracurricular_exercises_reply eer
		WHERE
			DATE_FORMAT( eer.create_time_, '%Y-%m-%d' ) BETWEEN #{monday} AND #{sunday} and eer.tenant_id_ = #{tenantId}
		UNION ALL
		SELECT
			sch.id_,
			sch.user_id_,
			sch.status_,
			sch.submit_time_,
			sch.is_replied_,
			sch.is_replied_timely_,
			'HOMEWORK' type_
		FROM
			student_course_homework sch
			LEFT JOIN course_schedule cs ON cs.id_ = sch.course_schedule_id_
		WHERE
			cs.group_type_='PRACTICE' AND DATE_FORMAT( sch.create_time_, '%Y-%m-%d' ) BETWEEN #{monday} AND #{sunday} and sch.tenant_id_ = #{tenantId}
	</select>

	<resultMap id="StudentServiceDetailDto" type="com.ym.mec.biz.dal.dto.StudentServiceDetailDto">
		<result property="homeworkId" column="homework_id_"/>
		<result property="studentHomeworkId" column="student_homework_id_"/>
		<result property="homeworkType" column="homework_type_"/>
		<result property="title" column="title_"/>
		<result property="content" column="content_"/>
		<result property="courseScheduleId" column="course_schedule_id_"/>
		<result property="groupId" column="group_id_"/>
		<result property="groupType" column="group_type_" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result property="groupName" column="group_name_"/>
		<result property="courseStartTime" column="course_start_time_"/>
		<result property="courseEndTime" column="course_end_time_"/>
		<result property="teacherId" column="teacher_id_"/>
		<result property="teacherName" column="teacher_name_"/>
		<result property="homeworkCreateTime" column="homework_create_time_"/>
		<result property="submitTime" column="submit_time_"/>
		<result property="isSubmit" column="is_submit_"/>
		<result property="isReplied" column="is_replied_"/>
		<result property="attachments" column="attachments_"/>
		<result property="musicScoreId" column="music_score_id_"/>
	</resultMap>

	<select id="findStudentHomeworkDetailsInTimeZone" resultMap="StudentServiceDetailDto">
		(SELECT
			ee.id_ homework_id_,
			eer.id_ student_homework_id_,
			eer.music_score_id_,
			ee.title_,
		 	NULL course_schedule_id_,
			ee.teacher_id_,
			tea.real_name_ teacher_name_,
			NULL group_id_,
			NULL group_type_,
			NULL group_name_,
			ee.create_time_ course_start_time_,
			NULL course_end_time_,
			ee.content_,
			ee.create_time_ homework_create_time_,
			eer.user_id_,
			eer.attachments_,
			eer.submit_time_,
			eer.is_replied_,
			'EXTRA' homework_type_
		FROM
			extracurricular_exercises_reply eer
		LEFT JOIN extracurricular_exercises ee ON ee.id_=eer.extracurricular_exercises_id_
		LEFT JOIN sys_user tea ON ee.teacher_id_=tea.id_
		WHERE
			eer.user_id_=#{studentId} AND DATE_FORMAT( eer.create_time_, '%Y-%m-%d' ) BETWEEN #{monday} AND #{sunday})
		UNION ALL
		(SELECT
			ch.id_ homework_id_,
			sch.id_ student_homework_id_,
			sch.music_score_id_,
			NULL title_,
		    cs.id_ course_schedule_id_,
			cs.actual_teacher_id_,
			tea.real_name_ teacher_name_,
			cs.music_group_id_ group_id_,
			cs.group_type_,
			cs.name_ group_name_,
			CONCAT(cs.class_date_, ' ', cs.start_class_time_) course_start_time_,
			CONCAT(cs.class_date_, ' ', cs.end_class_time_) course_end_time_,
			ch.content_,
			ch.create_time_ homework_create_time_,
			sch.user_id_,
			sch.attachments_,
			sch.submit_time_,
			sch.is_replied_,
			'HOMEWORK' homework_type_
		FROM
			student_course_homework sch
		LEFT JOIN course_homework ch ON ch.id_=sch.course_homework_id_
		LEFT JOIN course_schedule cs ON cs.id_=ch.course_schedule_id_
		LEFT JOIN sys_user tea ON cs.actual_teacher_id_=tea.id_
		WHERE
			sch.user_id_=#{studentId} AND cs.class_date_ BETWEEN #{monday} AND #{sunday})
		ORDER BY homework_create_time_ DESC
		<include refid="global.limit"/>
	</select>

	<select id="countStudentHomeworkDetailsInTimeZone" resultType="int">
		SELECT COUNT(t.id_) FROM (
			(SELECT
				eer.id_
			FROM
				extracurricular_exercises_reply eer
			WHERE
				eer.user_id_=#{studentId} AND DATE_FORMAT( eer.create_time_, '%Y-%m-%d' ) BETWEEN #{monday} AND #{sunday})
			UNION ALL
			(SELECT
				sch.id_
			FROM
				student_course_homework sch
				LEFT JOIN course_schedule cs ON cs.id_=sch.course_schedule_id_
			WHERE
				sch.user_id_=#{studentId} AND cs.class_date_ BETWEEN #{monday} AND #{sunday})
		) t
	</select>
	<select id="getStudentExercisesWithTimeZone" resultMap="ExtracurricularExercisesReply">
		SELECT
			eer.id_,
			eer.user_id_,
			eer.status_,
			eer.submit_time_,
			eer.is_replied_,
			eer.is_replied_timely_,
			ee.teacher_id_ ee_teacher_id_,
			eer.music_score_id_,
			ee.music_group_id_ ee_music_group_id_
		FROM
			extracurricular_exercises_reply eer
			LEFT JOIN extracurricular_exercises ee ON eer.extracurricular_exercises_id_=ee.id_
		WHERE
			DATE_FORMAT( eer.create_time_, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate} and eer.tenant_id_ = #{tenantId}
	</select>

	<select id="checkStudentHaveExercisesInDateRange" resultType="java.lang.Integer">
		SELECT
			DISTINCT user_id_
		FROM
			extracurricular_exercises_reply
		WHERE
			DATE_FORMAT( create_time_, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate}
			AND user_id_ IN
			<foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
				#{studentId}
			</foreach>
	</select>

	<sql id="getEduHomeworkListCondition">
		<where>
			EXISTS (SELECT user_id_ FROM student_registration sr
			LEFT JOIN music_group mg ON mg.id_=sr.music_group_id_
			WHERE sr.user_id_ = eer.user_id_ AND sr.music_group_status_='NORMAL'
			AND mg.status_ = 'PROGRESS' AND mg.transaction_teacher_id_=#{transactionTeacherId})
			<if test="search != null and search != ''">
				AND (su.real_name_ LIKE CONCAT('%',#{search},'%') OR su.id_ = #{search})
			</if>
			<if test="startTime!=null">
				AND DATE_FORMAT(ee.create_time_, "%Y-%m-%d") &gt;= DATE_FORMAT(#{startTime}, "%Y-%m-%d")
			</if>
			<if test="endTime!=null">
				AND DATE_FORMAT(ee.create_time_, "%Y-%m-%d") &lt;= DATE_FORMAT(#{endTime}, "%Y-%m-%d")
			</if>
		</where>
	</sql>

    <select id="getEduHomeworkList" resultType="com.ym.mec.biz.dal.dto.EduHomeworkCardDto">
		SELECT
			ee.id_ homeworkId,
			su.real_name_ teacherName,
		    su.avatar_ teacherAvatar,
			ee.create_time_ createTime,
			COUNT( eer.user_id_ ) exceptStudentNum,
			SUM( eer.status_ ) submitStudentNum,
			SUM( eer.is_replied_ ) repliedStudentNum,
			eer.music_score_id_ musicScoreId
		FROM
			extracurricular_exercises ee
			LEFT JOIN sys_user su ON ee.teacher_id_ = su.id_
			LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
		<include refid="getEduHomeworkListCondition" />
		GROUP BY ee.id_
		ORDER BY ee.create_time_ DESC
		<include refid="global.limit"></include>
	</select>

	<select id="countEduHomeworkList" resultType="int">
		SELECT
			COUNT(DISTINCT ee.id_)
		FROM
		extracurricular_exercises ee
		LEFT JOIN sys_user su ON ee.teacher_id_ = su.id_
		LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
		<include refid="getEduHomeworkListCondition" />
	</select>
	<select id="countEduHomeworkStudentNumWithMusicGroup"
			resultType="com.ym.mec.biz.dal.dto.EduHomeworkCardDto">
		SELECT
			sr.music_group_id_ groupId,
			COUNT( eer.user_id_ ) exceptStudentNum,
			SUM( eer.status_ ) submitStudentNum,
			SUM( eer.is_replied_ ) repliedStudentNum
		FROM
			extracurricular_exercises ee
			LEFT JOIN sys_user su ON ee.teacher_id_ = su.id_
			LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
			LEFT JOIN student_registration sr ON eer.user_id_ = sr.user_id_
		WHERE sr.music_group_status_='NORMAL' and ee.tenant_id_ = #{tenantId}
			<if test="groupIds!=null and groupIds.size()>0">
				AND sr.music_group_id_ IN
				<foreach collection="groupIds" item="groupId" open="(" close=")" separator=",">
					#{groupId}
				</foreach>
			</if>
			<if test="startTime!=null">
				AND DATE_FORMAT(ee.create_time_, "%Y-%m-%d") &gt;= DATE_FORMAT(#{startTime}, "%Y-%m-%d")
			</if>
			<if test="endTime!=null">
				AND DATE_FORMAT(ee.create_time_, "%Y-%m-%d") &lt;= DATE_FORMAT(#{endTime}, "%Y-%m-%d")
			</if>
		GROUP BY sr.music_group_id_
	</select>

	<select id="countEduHomeworkSubjectStudentNumWithMusicGroup"
			resultType="com.ym.mec.biz.dal.dto.EduHomeworkCardDto">
		SELECT
		sr.actual_subject_id_ subjectId,
		COUNT( eer.user_id_ ) exceptStudentNum,
		SUM( eer.status_ ) submitStudentNum,
		SUM( eer.is_replied_ ) repliedStudentNum
		FROM
		extracurricular_exercises ee
		LEFT JOIN sys_user su ON ee.teacher_id_ = su.id_
		LEFT JOIN extracurricular_exercises_reply eer ON ee.id_ = eer.extracurricular_exercises_id_
		LEFT JOIN student_registration sr ON eer.user_id_ = sr.user_id_
		WHERE sr.music_group_status_='NORMAL'
			AND sr.music_group_id_ = #{groupId}
			<if test="startTime!=null">
				AND DATE_FORMAT(ee.create_time_, "%Y-%m-%d") &gt;= DATE_FORMAT(#{startTime}, "%Y-%m-%d")
			</if>
			<if test="endTime!=null">
				AND DATE_FORMAT(ee.create_time_, "%Y-%m-%d") &lt;= DATE_FORMAT(#{endTime}, "%Y-%m-%d")
			</if>
		GROUP BY sr.actual_subject_id_
	</select>

</mapper>
