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

    <resultMap type="com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation"
               id="StudentExtracurricularExercisesSituation">
        <result column="id_" property="id"/>
        <result column="music_group_id_" property="musicGroupId"/>
        <result column="student_id_" property="studentId"/>
        <result column="week_of_year_" property="weekOfYear"/>
        <result column="monday_" property="monday"/>
        <result column="sunday_" property="sunday"/>
        <result column="teacher_id_" property="teacherId"/>
        <result column="expect_exercises_num_" property="expectExercisesNum"/>
        <result column="actual_exercises_num_" property="actualExercisesNum"/>
        <result column="exercises_reply_num_" property="exercisesReplyNum"/>
        <result column="exercises_message_num_" property="exercisesMessageNum"/>
        <result column="exercises_message_timely_num_" property="exercisesMessageTimelyNum"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time_" property="updateTime"/>
        <result column="last_submit_time_" property="lastSubmitTime"/>
        <result column="serve_type_" property="serveType"/>
        <result column="course_ids_" property="courseIds"/>
        <result column="not_over_course_ids_" property="notOverCourseIds"/>
        <result column="not_over_course_num_" property="notOverCourseNum"/>
        <result column="tenant_id_" property="tenantId"/>
    </resultMap>

    <resultMap id="StudentExercisesSituationDto" type="com.ym.mec.biz.dal.dto.StudentExercisesSituationDto"
               extends="StudentExtracurricularExercisesSituation">
        <result column="student_name_" property="studentName"/>
        <result column="teacher_name_" property="teacherName"/>
        <result column="organ_name_" property="organName"/>
        <result column="exist_vip_course_" property="existVipCourse"/>
        <result column="groupNames" property="groupNames" />
        <result column="educationalTeacherId" property="educationalTeacherId" />
        <result column="educationalTeacherName" property="educationalTeacherName" />
    </resultMap>

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

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

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation"
            useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        <!--
        <selectKey resultClass="int" keyProperty="id" >
        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
        </selectKey>
        -->
        INSERT INTO student_extracurricular_exercises_situation_
        (id_,music_group_id_,student_id_,week_of_year_,monday_,sunday_,teacher_id_,expect_exercises_num_,
        actual_exercises_num_,exercises_reply_num_,exercises_message_num_,
        exercises_message_timely_num_,create_time_,update_time_,last_submit_time_,
        serve_type_,course_ids_,not_over_course_ids_,not_over_course_num_,tenant_id_)
        VALUES(#{id},#{musicGroupId},#{studentId},#{weekOfYear},#{monday},#{sunday},#{teacherId},#{expectExercisesNum},#{actualExercisesNum},#{exercisesReplyNum},
        #{exercisesMessageNum},#{exercisesMessageTimelyNum},NOW(),NOW(),#{lastSubmitTime},#{serveType},#{courseIds},#{notOverCourseIds},#{notOverCourseNum},#{tenantId})
    </insert>

    <insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation"
            useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        INSERT INTO student_extracurricular_exercises_situation_
        (music_group_id_,student_id_,week_of_year_,monday_,sunday_,teacher_id_,expect_exercises_num_,
        actual_exercises_num_,exercises_reply_num_,exercises_message_num_,
        exercises_message_timely_num_,create_time_,update_time_,last_submit_time_,
        serve_type_,course_ids_,not_over_course_ids_,not_over_course_num_,tenant_id_)
        VALUES
        <foreach collection="situations" item="situation" separator=",">
            (#{situation.musicGroupId},#{situation.studentId},#{situation.weekOfYear},#{situation.monday},#{situation.sunday},#{situation.teacherId},#{situation.expectExercisesNum},
            #{situation.actualExercisesNum},#{situation.exercisesReplyNum},#{situation.exercisesMessageNum},#{situation.exercisesMessageTimelyNum},
            NOW(),NOW(),#{situation.lastSubmitTime},#{situation.serveType},#{situation.courseIds},#{situation.notOverCourseIds},#{situation.notOverCourseNum},#{situation.tenantId})
        </foreach>
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation">
        UPDATE student_extracurricular_exercises_situation_
        <set>
            <if test="exercisesReplyNum != null">
                exercises_reply_num_ = #{exercisesReplyNum},
            </if>
            <if test="monday != null">
                monday_ = #{monday},
            </if>
            <if test="id != null">
                id_ = #{id},
            </if>
            <if test="weekOfYear != null">
                week_of_year_ = #{weekOfYear},
            </if>
            <if test="exercisesMessageNum != null">
                exercises_message_num_ = #{exercisesMessageNum},
            </if>
            <if test="createTime != null">
                create_time_ = #{createTime},
            </if>
            <if test="teacherId != null">
                teacher_id_ = #{teacherId},
            </if>
            <if test="actualExercisesNum != null">
                actual_exercises_num_ = #{actualExercisesNum},
            </if>
            <if test="exercisesMessageTimelyNum != null">
                exercises_message_timely_num_ = #{exercisesMessageTimelyNum},
            </if>
            <if test="studentId != null">
                student_id_ = #{studentId},
            </if>
            <if test="musicGroupId != null">
                music_group_id_ = #{musicGroupId},
            </if>
            <if test="expectExercisesNum != null">
                expect_exercises_num_ = #{expectExercisesNum},
            </if>
            <if test="sunday != null">
                sunday_ = #{sunday},
            </if>
            <if test="lastSubmitTime!=null">
                last_submit_time_=#{lastSubmitTime},
            </if>
            <if test="serveType!=null">
                serve_type_=#{serveType},
            </if>
            <if test="courseIds!=null and courseIds!=''">
                course_ids_=#{courseIds},
            </if>
            <if test="notOverCourseIds!=null and notOverCourseIds!=''">
                not_over_course_ids_=#{notOverCourseIds},
            </if>
            <if test="notOverCourseNum!=null">
                not_over_course_num_=#{notOverCourseNum},
            </if>
            update_time_ = #{updateTime}
        </set>
        WHERE id_ = #{id} and tenant_id_ = #{tenantId}
    </update>

    <update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation">
        <foreach collection="situations" item="situation" separator=";">
            UPDATE student_extracurricular_exercises_situation_
            <set>
                <if test="situation.exercisesReplyNum != null">
                    exercises_reply_num_ = #{situation.exercisesReplyNum},
                </if>
                <if test="situation.monday != null">
                    monday_ = #{situation.monday},
                </if>
                <if test="situation.weekOfYear != null">
                    week_of_year_ = #{situation.weekOfYear},
                </if>
                <if test="situation.exercisesMessageNum != null">
                    exercises_message_num_ = #{situation.exercisesMessageNum},
                </if>
                <if test="situation.teacherId != null">
                    teacher_id_ = #{situation.teacherId},
                </if>
                <if test="situation.actualExercisesNum != null">
                    actual_exercises_num_ = #{situation.actualExercisesNum},
                </if>
                <if test="situation.exercisesMessageTimelyNum != null">
                    exercises_message_timely_num_ = #{situation.exercisesMessageTimelyNum},
                </if>
                <if test="situation.studentId != null">
                    student_id_ = #{situation.studentId},
                </if>
	            <if test="situation.musicGroupId != null">
	                music_group_id_ = #{situation.musicGroupId},
	            </if>
                <if test="situation.expectExercisesNum != null">
                    expect_exercises_num_ = #{situation.expectExercisesNum},
                </if>
                <if test="situation.sunday != null">
                    sunday_ = #{situation.sunday},
                </if>
                <if test="situation.lastSubmitTime!=null">
                    last_submit_time_=#{situation.lastSubmitTime},
                </if>
                <if test="situation.serveType!=null">
                    serve_type_=#{situation.serveType},
                </if>
                <if test="situation.courseIds!=null">
                    course_ids_=#{situation.courseIds},
                </if>
                <if test="situation.notOverCourseIds!=null and situation.notOverCourseIds!=''">
                    not_over_course_ids_=#{situation.notOverCourseIds},
                </if>
                <if test="situation.notOverCourseNum!=null">
                    not_over_course_num_=#{situation.notOverCourseNum},
                </if>
                update_time_ = NOW()
            </set>
            WHERE id_ = #{situation.id} and tenant_id_ = #{situation.tenantId}
        </foreach>
    </update>

    <!-- 根据主键删除一条记录 -->
    <delete id="delete">
        DELETE
        FROM student_extracurricular_exercises_situation_
        WHERE id_ = #{id}
    </delete>
    <delete id="deleteByMonday">
        DELETE FROM student_extracurricular_exercises_situation_ WHERE monday_ = #{monday}
        <if test="studentIds!=null and studentIds.size()>0">
            AND student_id_ IN
            <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
                #{studentId}
            </foreach>
        </if>
    </delete>
    <select id="selectByMonday" resultMap="StudentExtracurricularExercisesSituation">
        SELECT id_,course_ids_ FROM student_extracurricular_exercises_situation_ WHERE monday_ = #{monday}
        <if test="studentIds!=null and studentIds.size()>0">
            AND student_id_ IN
            <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
                #{studentId}
            </foreach>
        </if>
    </select>
    <delete id="deleteByStudent">
        DELETE FROM student_extracurricular_exercises_situation_ WHERE student_id_ = #{studentId}
        <if test="monday!=null and monday!=''">
            AND monday_=#{monday}
        </if>
    </delete>
    <delete id="batchDelete">
        DELETE FROM student_extracurricular_exercises_situation_ WHERE id_ IN
        <foreach collection="situationIds" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

    <select id="selectByStudent" resultMap="StudentExtracurricularExercisesSituation">
        SELECT id_,course_ids_ FROM student_extracurricular_exercises_situation_ WHERE student_id_ = #{studentId}
        <if test="monday!=null and monday!=''">
            AND monday_=#{monday}
        </if>
    </select>

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

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

    <select id="findExercisesSituations" resultMap="StudentExercisesSituationDto">
        SELECT
        sees.id_ id_,
        sees.music_group_id_,
        mg.name_ groupNames,
        co.education_user_id_ educationalTeacherId,
        uu.real_name_ educationalTeacherName,
        student_id_,
        stu.username_ student_name_,
        tea.real_name_ teacher_name_,
        o.name_ organ_name_,
        sees.monday_,
        sees.sunday_,
        sees.serve_type_,
        sees.course_ids_,
        expect_exercises_num_ expect_exercises_num_,
        actual_exercises_num_ actual_exercises_num_,
        <if test="submitStartDate==null or submitEndDate==null">
            exercises_reply_num_ exercises_reply_num_,
            exercises_message_num_ exercises_message_num_,
            exercises_message_timely_num_ exercises_message_timely_num_,
            last_submit_time_ last_submit_time_
        </if>
        <if test="submitStartDate!=null and submitEndDate!=null">
            IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
            #{submitEndDate},exercises_reply_num_,0) exercises_reply_num_,
            IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
            #{submitEndDate},exercises_message_num_,0) exercises_message_num_,
            IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
            #{submitEndDate},exercises_message_timely_num_,0) exercises_message_timely_num_,
            IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
            #{submitEndDate},last_submit_time_, NULL) last_submit_time_
        </if>
        FROM
        student_extracurricular_exercises_situation_ sees
        left join music_group mg on mg.id_ = sees.music_group_id_
        left join cooperation_organ co on co.id_ = mg.cooperation_organ_id_
        left join sys_user uu on uu.id_ = co.education_user_id_
        LEFT JOIN sys_user stu ON stu.id_=sees.student_id_
        LEFT JOIN teacher t ON t.id_=sees.teacher_id_
        LEFT JOIN sys_user tea ON tea.id_=sees.teacher_id_
        LEFT JOIN organization o ON stu.organ_id_=o.id_
        WHERE
        sees.monday_ &gt;= #{monday}
        AND sees.sunday_ &lt;= #{sunday} and sees.tenant_id_ = #{tenantId}
        <if test="teacherId!=null">
            AND sees.teacher_id_ = #{teacherId}
        </if>
        <if test="search!=null">
            AND (stu.id_=#{search} OR stu.username_ LIKE CONCAT('%', #{search}, '%'))
        </if>
        <if test="organId != null and organId != ''">
            AND FIND_IN_SET(t.organ_id_,#{organId})
        </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_=sees.student_id_ AND cssp.group_type_='VIP' AND
            class_date_ BETWEEN #{monday} AND #{sunday})
        </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_=sees.student_id_ AND cssp.group_type_='VIP' AND
            class_date_ BETWEEN #{monday} AND #{sunday})
        </if>
        <if test="existPracticeCourse!=null and existPracticeCourse==1">
            AND EXISTS (SELECT cssp.id_ FROM course_schedule_student_payment cssp LEFT JOIN course_schedule cs ON
            cs.id_=cssp.course_schedule_id_ LEFT JOIN practice_group pg ON pg.id_=cssp.music_group_id_ WHERE
            cssp.user_id_=sees.student_id_ AND cssp.group_type_='PRACTICE' AND pg.type_='CHARGE' AND class_date_ BETWEEN
            #{monday} AND #{sunday})
        </if>
        <if test="existPracticeCourse!=null and existPracticeCourse==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_ LEFT JOIN practice_group pg ON pg.id_=cssp.music_group_id_ WHERE
            cssp.user_id_=sees.student_id_ AND cssp.group_type_='PRACTICE' AND pg.type_='CHARGE' AND class_date_ BETWEEN
            #{monday} AND #{sunday})
        </if>

        <if test="expectExercisesNum!=null">
            AND expect_exercises_num_ = #{expectExercisesNum}
        </if>
        <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==0">
            AND actual_exercises_num_ &lt; expect_exercises_num_
        </if>
        <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==1">
            AND actual_exercises_num_ &gt;= expect_exercises_num_
        </if>
        <if test="submitStartDate==null or submitEndDate==null">
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==0">
                AND exercises_reply_num_ &lt; actual_exercises_num_
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==1">
                AND exercises_reply_num_ &gt;= actual_exercises_num_
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==0">
                AND exercises_message_num_ &lt; exercises_reply_num_
            </if>
            <if test="serviceIsError!=null and serviceIsError">
                AND (actual_exercises_num_ &lt; expect_exercises_num_ OR exercises_message_num_ &lt;
                exercises_reply_num_)
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==1">
                AND exercises_message_num_ &gt;= exercises_reply_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==0">
                AND exercises_message_timely_num_ &lt; exercises_message_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==1">
                AND exercises_message_timely_num_ &gt;= exercises_message_num_
            </if>
        </if>
        <if test="submitStartDate!=null and submitEndDate!=null">
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==0">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_reply_num_,0) &lt; actual_exercises_num_
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==1">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_reply_num_,0) &gt;= actual_exercises_num_
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==0">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_num_,0) &lt; exercises_reply_num_
            </if>
            <if test="serviceIsError!=null and serviceIsError">
                AND (actual_exercises_num_ &lt; expect_exercises_num_ OR IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d')
                BETWEEN #{submitStartDate} AND #{submitEndDate},exercises_message_num_,0) &lt; exercises_reply_num_)
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==1">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_num_,0) &gt;= exercises_reply_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==0">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_timely_num_,0) &lt; exercises_message_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==1">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_timely_num_,0) &gt;= exercises_message_num_
            </if>
        </if>
        ORDER BY student_id_
        <include refid="global.limit"/>
    </select>

    <select id="countExercisesSituations" resultType="int">
        SELECT COUNT(1) FROM (
        SELECT
        1
        FROM
        student_extracurricular_exercises_situation_ sees
        LEFT JOIN sys_user stu ON stu.id_=sees.student_id_
        LEFT JOIN teacher t ON t.id_=sees.teacher_id_
        LEFT JOIN sys_user tea ON tea.id_=sees.teacher_id_
        LEFT JOIN organization o ON stu.organ_id_=o.id_
        WHERE
        sees.monday_ &gt;= #{monday}
        AND sees.sunday_ &lt;= #{sunday} and sees.tenant_id_ = #{tenantId}
        <if test="teacherId!=null">
            AND sees.teacher_id_ = #{teacherId}
        </if>
        <if test="search!=null">
            AND (stu.id_=#{search} OR stu.username_ LIKE CONCAT('%', #{search}, '%'))
        </if>
        <if test="organId != null and organId != ''">
            AND FIND_IN_SET(t.organ_id_, #{organId})
        </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_=sees.student_id_ AND cssp.group_type_='VIP' AND
            class_date_ BETWEEN #{monday} AND #{sunday})
        </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_=sees.student_id_ AND cssp.group_type_='VIP' AND
            class_date_ BETWEEN #{monday} AND #{sunday})
        </if>
        <if test="existPracticeCourse!=null and existPracticeCourse==1">
            AND EXISTS (SELECT cssp.id_ FROM course_schedule_student_payment cssp LEFT JOIN course_schedule cs ON
            cs.id_=cssp.course_schedule_id_ LEFT JOIN practice_group pg ON pg.id_=cssp.music_group_id_ WHERE
            cssp.user_id_=sees.student_id_ AND cssp.group_type_='PRACTICE' AND pg.type_='CHARGE' AND class_date_ BETWEEN
            #{monday} AND #{sunday})
        </if>
        <if test="existPracticeCourse!=null and existPracticeCourse==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_ LEFT JOIN practice_group pg ON pg.id_=cssp.music_group_id_ WHERE
            cssp.user_id_=sees.student_id_ AND cssp.group_type_='PRACTICE' AND pg.type_='CHARGE' AND class_date_ BETWEEN
            #{monday} AND #{sunday})
        </if>

        <if test="expectExercisesNum!=null">
            AND expect_exercises_num_ = #{expectExercisesNum}
        </if>
        <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==0">
            AND actual_exercises_num_ &lt; expect_exercises_num_
        </if>
        <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==1">
            AND actual_exercises_num_ &gt;= expect_exercises_num_
        </if>
        <if test="submitStartDate==null or submitEndDate==null">
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==0">
                AND exercises_reply_num_ &lt; actual_exercises_num_
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==1">
                AND exercises_reply_num_ &gt;= actual_exercises_num_
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==0">
                AND exercises_message_num_ &lt; exercises_reply_num_
            </if>
            <if test="serviceIsError!=null and serviceIsError">
                AND (actual_exercises_num_ &lt; expect_exercises_num_ OR exercises_message_num_ &lt;
                exercises_reply_num_)
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==1">
                AND exercises_message_num_ &gt;= exercises_reply_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==0">
                AND exercises_message_timely_num_ &lt; exercises_message_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==1">
                AND exercises_message_timely_num_ &gt;= exercises_message_num_
            </if>
        </if>
        <if test="submitStartDate!=null and submitEndDate!=null">
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==0">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_reply_num_,0) &lt; actual_exercises_num_
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==1">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_reply_num_,0) &gt;= actual_exercises_num_
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==0">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_num_,0) &lt; exercises_reply_num_
            </if>
            <if test="serviceIsError!=null and serviceIsError">
                AND (actual_exercises_num_ &lt; expect_exercises_num_ OR IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d')
                BETWEEN #{submitStartDate} AND #{submitEndDate},exercises_message_num_,0) &lt; exercises_reply_num_)
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==1">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_num_,0) &gt;= exercises_reply_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==0">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_timely_num_,0) &lt; exercises_message_num_
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==1">
                AND IF(DATE_FORMAT(last_submit_time_, '%Y-%m-%d') BETWEEN #{submitStartDate} AND
                #{submitEndDate},exercises_message_timely_num_,0) &gt;= exercises_message_num_
            </if>
        </if>
        ) tmp
    </select>

    <select id="findExercisesSituationsById" resultMap="StudentExtracurricularExercisesSituation">
        SELECT * FROM student_extracurricular_exercises_situation_ WHERE id_ IN
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>

    <select id="findTeacherExercisesServiceSituations" resultType="com.ym.mec.biz.dal.dto.TeacherExercisesServiceDto">
        SELECT
        teacher_id_ teacherId,
        COUNT( exercises_reply_num_ ) expectExercisesNum,
        COUNT( CASE WHEN actual_exercises_num_ = 1 THEN 1 ELSE NULL END ) actualExercisesNum
        FROM
        student_extracurricular_exercises_situation_
        FORCE INDEX(monday_)
        WHERE monday_ = #{monday}
        AND teacher_id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
        GROUP BY
        teacher_id_;
    </select>

    <select id="findLastWeekTodayUpdateNum" resultType="int">
        SELECT COUNT(id_) FROM student_extracurricular_exercises_situation_ WHERE sunday_=#{sunday} AND
        DATE_FORMAT(update_time_,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d')
        <if test="tenantId != null">
            and tenant_id_ = #{tenantId}
        </if>
    </select>

    <select id="findStudentExercisesSituationsWithMonDay" resultMap="StudentExtracurricularExercisesSituation">
        SELECT *
        FROM student_extracurricular_exercises_situation_
        WHERE monday_ = #{monday}
          AND student_id_ = #{studentId}
    </select>

    <select id="getNoFinishedServiceTeacher" resultType="java.util.Map">
        SELECT teacher_id_ AS 'key', COUNT( student_id_ ) AS 'value'
        FROM student_extracurricular_exercises_situation_
        WHERE actual_exercises_num_ = 0
          AND serve_type_ = 'EXERCISE'
          AND monday_ = #{monday}
          AND teacher_id_ IS NOT NULL
        GROUP BY teacher_id_
    </select>

    <select id="countWeekServiceNum" resultType="int">
        SELECT COUNT(id_) FROM student_extracurricular_exercises_situation_ WHERE monday_=#{monday}
        <if test="tenantId != null">
            and tenant_id_ = #{tenantId}
        </if>
    </select>

    <select id="findWeekServiceWithStudents" resultMap="StudentExtracurricularExercisesSituation">
        SELECT * FROM student_extracurricular_exercises_situation_
        <where>
            teacher_id_=#{teacherId}
            <if test="monday != null and monday != ''">
                AND monday_ = #{monday}
            </if>
            <if test="studentIds!=null and studentIds.size()>0">
                AND student_id_ IN
                <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
                    #{studentId}
                </foreach>
            </if>
        </where>
    </select>
    <select id="findTeacherNoStartServices" resultMap="StudentExtracurricularExercisesSituation">
        SELECT *
        FROM student_extracurricular_exercises_situation_
        WHERE teacher_id_ = #{teacherId}
          AND actual_exercises_num_ &lt;= 0
          AND serve_type_ = 'HOMEWORK';
    </select>


    <select id="getTeacherHomeworkCourseIdsWithMonday" resultType="string">
        SELECT course_ids_ FROM student_extracurricular_exercises_situation_
        WHERE teacher_id_=#{teacherId}
        AND serve_type_='HOMEWORK'
        <if test="monday!=null and monday!=''">
            AND monday_=#{monday}
        </if>
    </select>

    <select id="findServiceWithCourse"
            resultMap="StudentExtracurricularExercisesSituation">
        SELECT *
        FROM student_extracurricular_exercises_situation_
        WHERE monday_ = #{monday}
          AND FIND_IN_SET(#{courseId}, course_ids_)
    </select>

    <resultMap id="TeacherServeDto" type="com.ym.mec.biz.dal.dto.TeacherServeDto">
        <result column="organ_name_" property="organName"/>
        <result column="monday_" property="monday"/>
        <result column="sunday_" property="sunday"/>
        <result column="teacher_id_" property="teacherId"/>
        <result column="teacher_name_" property="teacherName"/>
        <result column="homework_num_" property="homeworkNum"/>
        <result column="exercise_num_" property="exerciseNum"/>
        <result column="un_done_" property="unDone"/>
        <result column="remind_time_" property="remindDate"/>
        <result column="operator_name_" property="operatorName"/>
        <result column="job_nature_" property="jobNature" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="expect_exercises_num_" property="expectExercisesNum"/>
        <result column="actual_exercises_num_" property="actualExercisesNum"/>
        <result column="exercises_reply_num_" property="exercisesReplyNum"/>
        <result column="exercises_message_num_" property="exercisesMessageNum"/>
        <result column="exercises_message_timely_num_" property="exercisesMessageTimelyNum"/>
    </resultMap>


    <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="queryTeacherServeInfo" resultMap="TeacherServeDto">
        SELECT
        organ.name_ organ_name_,
        sees.monday_,
        sees.sunday_,
        sees.teacher_id_,
        su.real_name_ teacher_name_,
        tea.job_nature_,
        SUM(expect_exercises_num_) expect_exercises_num_,
        SUM(actual_exercises_num_) actual_exercises_num_,
        SUM(exercises_reply_num_) exercises_reply_num_,
        SUM(exercises_message_num_) exercises_message_num_,
        SUM(exercises_message_timely_num_) exercises_message_timely_num_,
        SUM(CASE sees.serve_type_ WHEN 'HOMEWORK' THEN sees.expect_exercises_num_ ELSE 0 END) homework_num_,
        SUM(CASE sees.serve_type_ WHEN 'EXERCISE' THEN 1 ELSE 0 END) exercise_num_,
        SUM( sees.expect_exercises_num_-sees.not_over_course_num_ )> SUM( sees.actual_exercises_num_ ) un_done_
        FROM
        student_extracurricular_exercises_situation_ sees
        LEFT JOIN teacher tea ON tea.id_=sees.teacher_id_
        LEFT JOIN organization organ ON organ.id_=tea.organ_id_
        LEFT JOIN sys_user su ON tea.id_=su.id_
        <include refid="queryTeacherServeInfoCondition"/>
        GROUP BY sees.monday_,sees.sunday_,sees.teacher_id_
        <trim prefix="HAVING" prefixOverrides="AND">
            <if test="unDone!=null">
                <if test="unDone==1">
                    AND SUM( sees.expect_exercises_num_-sees.not_over_course_num_ ) &gt; SUM( sees.actual_exercises_num_
                    )
                </if>
                <if test="unDone==0">
                    AND SUM( sees.expect_exercises_num_-sees.not_over_course_num_ ) &lt;= SUM(
                    sees.actual_exercises_num_ )
                </if>
            </if>
            <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==0">
                AND SUM(actual_exercises_num_) &lt; SUM(expect_exercises_num_)
            </if>
            <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==1">
                AND SUM(actual_exercises_num_) &gt;= SUM(expect_exercises_num_)
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==0">
                AND SUM(exercises_reply_num_) &lt; SUM(actual_exercises_num_)
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==1">
                AND SUM(exercises_reply_num_) &gt;= SUM(actual_exercises_num_)
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==0">
                AND SUM(exercises_message_num_) &lt; SUM(exercises_reply_num_)
            </if>
            <if test="serviceIsError!=null and serviceIsError">
                AND (SUM(actual_exercises_num_) &lt; SUM(expect_exercises_num_) OR SUM(exercises_message_num_) &lt;
                SUM(exercises_reply_num_))
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==1">
                AND SUM(exercises_message_num_) &gt;= SUM(exercises_reply_num_)
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==0">
                AND SUM(exercises_message_timely_num_) &lt; SUM(exercises_message_num_)
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==1">
                AND SUM(exercises_message_timely_num_) &gt;= SUM(exercises_message_num_)
            </if>
        </trim>
        ORDER BY sees.monday_,sees.sunday_,sees.teacher_id_
        <include refid="global.limit"></include>
    </select>

    <select id="countTeacherServeInfo" resultType="int">
        SELECT COUNT(1) FROM (
        SELECT
        sees.id_
        FROM
        student_extracurricular_exercises_situation_ sees
        LEFT JOIN teacher tea ON tea.id_=sees.teacher_id_
        <include refid="queryTeacherServeInfoCondition"/>
        GROUP BY sees.monday_,sees.sunday_,sees.teacher_id_
        <trim prefix="HAVING" prefixOverrides="AND">
            <if test="unDone!=null">
                <if test="unDone==1">
                    AND SUM( sees.expect_exercises_num_-sees.not_over_course_num_ ) &gt; SUM( sees.actual_exercises_num_
                    )
                </if>
                <if test="unDone==0">
                    AND SUM( sees.expect_exercises_num_-sees.not_over_course_num_ ) &lt;= SUM(
                    sees.actual_exercises_num_ )
                </if>
            </if>
            <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==0">
                AND SUM(actual_exercises_num_) &lt; SUM(expect_exercises_num_)
            </if>
            <if test="actualExercisesNumIsAchieve!=null and actualExercisesNumIsAchieve==1">
                AND SUM(actual_exercises_num_) &gt;= SUM(expect_exercises_num_)
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==0">
                AND SUM(exercises_reply_num_) &lt; SUM(actual_exercises_num_)
            </if>
            <if test="exercisesReplyNumIsAchieve!=null and exercisesReplyNumIsAchieve==1">
                AND SUM(exercises_reply_num_) &gt;= SUM(actual_exercises_num_)
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==0">
                AND SUM(exercises_message_num_) &lt; SUM(exercises_reply_num_)
            </if>
            <if test="serviceIsError!=null and serviceIsError">
                AND (SUM(actual_exercises_num_) &lt; SUM(expect_exercises_num_) OR SUM(exercises_message_num_) &lt;
                SUM(exercises_reply_num_))
            </if>
            <if test="exercisesMessageNumIsAchieve!=null and exercisesMessageNumIsAchieve==1">
                AND SUM(exercises_message_num_) &gt;= SUM(exercises_reply_num_)
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==0">
                AND SUM(exercises_message_timely_num_) &lt; SUM(exercises_message_num_)
            </if>
            <if test="exercisesMessageTimelyNumIsAchieve!=null and exercisesMessageTimelyNumIsAchieve==1">
                AND SUM(exercises_message_timely_num_) &gt;= SUM(exercises_message_num_)
            </if>
        </trim>
        ORDER BY sees.monday_,sees.sunday_,sees.teacher_id_
        ) e
    </select>

    <select id="findTeacherServeWithDate" resultMap="StudentExtracurricularExercisesSituation">
        SELECT * FROM student_extracurricular_exercises_situation_
        WHERE monday_ BETWEEN #{monday} AND #{sunday}
        <if test="serveType!=null and serveType!=''">
            AND serve_type_=#{serveType}
        </if>
        AND teacher_id_ IN
        <foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
            #{teacherId}
        </foreach>
    </select>

    <select id="getHomeworkData" resultMap="com.ym.mec.biz.dal.dao.IndexBaseMonthDataDao.IndexBaseMonthData">
        SELECT
        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 teacher tea ON sees.teacher_id_=tea.id_
        WHERE tea.job_nature_='FULL_TIME'
        AND DATE_FORMAT(sees.monday_, '%Y-%m-%d')&gt;=#{startDay}
        AND DATE_FORMAT(sees.sunday_, '%Y-%m-%d')&lt;=#{endDay}
        AND (sees.serve_type_ = 'EXERCISE' OR EXISTS (SELECT id_ FROM course_schedule WHERE group_type_='MUSIC' AND
        music_group_id_=#{musicGroupId} AND FIND_IN_SET(id_, sees.course_ids_)))
        AND sees.student_id_ IN
        <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
            #{studentId}
        </foreach>
        GROUP BY sees.monday_
    </select>

    <select id="queryCourseIdByClassDate" resultType="java.lang.Long">
        SELECT DISTINCT csts.course_schedule_id_
        FROM course_schedule_teacher_salary csts
                 LEFT JOIN course_schedule cs ON cs.id_ = csts.course_schedule_id_
                 LEFT JOIN student_extracurricular_exercises_situation_ se ON se.teacher_id_ = csts.user_id_
        WHERE csts.user_id_ = #{teacherId}
          AND cs.class_date_ BETWEEN #{firstDayOfMonth} AND #{lastDayOfMonth}
          AND FIND_IN_SET(cs.id_, se.course_ids_)
          AND se.serve_type_ = 'HOMEWORK'
    </select>

    <select id="countWaitCreateHomeworkNum" resultType="java.lang.Integer">
        SELECT COUNT(id_)
        FROM student_extracurricular_exercises_situation_
        WHERE teacher_id_ = #{teacherId}
          AND expect_exercises_num_ > actual_exercises_num_
          AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN monday_ AND sunday_
          AND serve_type_ = 'EXERCISE'
    </select>
    <select id="countWaitCreateHomeworkNum1" resultType="java.lang.Integer">
        SELECT SUM(t.num_)
        FROM (
                 SELECT COUNT(se.id_) num_
                 FROM student_extracurricular_exercises_situation_ se
                          LEFT JOIN course_schedule cs ON FIND_IN_SET(cs.id_, se.course_ids_)
                 WHERE se.teacher_id_ = #{teacherId}
                   AND se.expect_exercises_num_ > se.actual_exercises_num_
                   AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN se.monday_ AND se.sunday_
                   AND se.serve_type_ = 'HOMEWORK'
                   AND cs.group_type_ = 'MUSIC'
                   AND cs.class_date_ = DATE_FORMAT(NOW(), '%Y-%m-%d')
                 UNION ALL
                 SELECT COUNT(se.id_) num_
                 FROM student_extracurricular_exercises_situation_ se
                          LEFT JOIN course_schedule cs ON FIND_IN_SET(cs.id_, se.course_ids_)
                 WHERE se.teacher_id_ = #{teacherId}
                   AND se.expect_exercises_num_ > se.actual_exercises_num_
                   AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN se.monday_ AND se.sunday_
                   AND se.serve_type_ = 'HOMEWORK'
                   AND cs.group_type_ != 'MUSIC' AND cs.class_date_ &lt;= DATE_FORMAT(NOW(), '%Y-%m-%d')) t
    </select>

    <select id="queryTeacherPerformanceIndicator" resultMap="TeacherServeDto">
        SELECT
        organ.name_ organ_name_,
        sees.monday_,
        sees.sunday_,
        sees.teacher_id_,
        su.real_name_ teacher_name_,
        tea.job_nature_,
        SUM(expect_exercises_num_) expect_exercises_num_,
        SUM(actual_exercises_num_) actual_exercises_num_,
        SUM(exercises_reply_num_) exercises_reply_num_,
        SUM(exercises_message_num_) exercises_message_num_,
        SUM(exercises_message_timely_num_) exercises_message_timely_num_,
        SUM(CASE sees.serve_type_ WHEN 'HOMEWORK' THEN sees.expect_exercises_num_ ELSE 0 END) homework_num_,
        SUM(CASE sees.serve_type_ WHEN 'EXERCISE' THEN 1 ELSE 0 END) exercise_num_,
        SUM( sees.expect_exercises_num_-sees.not_over_course_num_ )> SUM( sees.actual_exercises_num_ ) un_done_
        FROM
        student_extracurricular_exercises_situation_ sees
        LEFT JOIN teacher tea ON tea.id_=sees.teacher_id_
        LEFT JOIN organization organ ON organ.id_=tea.organ_id_
        LEFT JOIN sys_user su ON tea.id_=su.id_
        <include refid="queryTeacherServeInfoCondition"/>
        GROUP BY sees.teacher_id_
        ORDER BY sees.teacher_id_
        <include refid="global.limit"></include>
    </select>
    <select id="getHomeworkSituations" resultType="java.util.Date">
        SELECT cs.class_date_
        FROM student_extracurricular_exercises_situation_ sees
                 LEFT JOIN course_schedule cs ON FIND_IN_SET(cs.id_, sees.course_ids_)
        WHERE sees.serve_type_ = #{serveType}
          AND cs.id_ != #{courseScheduleId}
          AND cs.music_group_id_ = #{musicGroupId}
          AND sees.monday_ = #{month}
          AND sees.student_id_ = #{userId}
    </select>

    <resultMap id="StudentServeExportDto" type="com.ym.mec.biz.dal.dto.StudentServeExportDto">
        <result column="student_id_" property="studentId" jdbcType="INTEGER"/>
        <result column="user_name_" property="username" jdbcType="VARCHAR"/>
        <result column="music_group_name_" property="musicGroupName" jdbcType="VARCHAR"/>
        <result column="serve_total_num_" property="serveTotalNum" jdbcType="INTEGER"/>
        <result column="sign_num_" property="signNum" jdbcType="INTEGER"/>
        <result column="course_num_" property="courseNum" jdbcType="INTEGER"/>
        <result column="qualified_num_" property="qualifiedNum" jdbcType="INTEGER"/>
        <result column="single_num_" property="singleNum" jdbcType="INTEGER"/>
        <result column="mix_num_" property="mixNum" jdbcType="INTEGER"/>
        <result column="not_sign_num_" property="notSignNum" jdbcType="INTEGER"/>
        <result column="not_sign_date_" property="notSignDate" jdbcType="VARCHAR"/>
        <result column="not_homework_date_" property="notHomeworkDate" jdbcType="VARCHAR"/>
        <result column="monday_" property="monday"/>
        <result column="sunday_" property="sunday"/>
        <result column="actual_exercises_num_" property="actualExercisesNum" jdbcType="INTEGER"/>
        <result column="exercises_reply_num_" property="exercisesReplyNum" jdbcType="INTEGER"/>
        <result column="exercises_message_num_" property="exercisesMessageNum" jdbcType="INTEGER"/>
    </resultMap>

    <select id="queryStudentServeInfo" resultMap="StudentServeExportDto">
        select sees.student_id_,cs.user_name_,cs.music_group_name_,cs.organ_name_,sees.monday_,sees.sunday_,sees.serve_total_num_,sees.actual_exercises_num_,
        sees.exercises_reply_num_,sees.exercises_message_num_,cs.sign_num_,cs.course_num_,cs.qualified_num_,cs.single_num_,cs.mix_num_,
        cs.not_sign_num_,cs.not_sign_date_,sees.not_homework_date_ from (
        select sees.student_id_,sees.music_group_id_,MIN(sees.monday_) monday_,MAX(sees.sunday_) sunday_,sum(sees.expect_exercises_num_) serve_total_num_,
        sum(sees.actual_exercises_num_) actual_exercises_num_,SUM(sees.exercises_reply_num_) exercises_reply_num_,sum(sees.exercises_message_num_) exercises_message_num_,
        GROUP_CONCAT(DISTINCT CASE WHEN sees.exercises_reply_num_ &lt; sees.actual_exercises_num_ THEN sees.monday_ END) not_homework_date_
        FROM student_extracurricular_exercises_situation_ sees
        WHERE sees.monday_ >= #{monday} AND sees.sunday_ &lt;= #{sunday}
        GROUP BY sees.student_id_,sees.music_group_id_) sees
        LEFT JOIN (
        SELECT sees.student_id_,sbi.organ_id_,sees.music_group_id_,sbi.user_name_,mg.name_ music_group_name_,sbi.organ_name_,
        COUNT(DISTINCT CASE WHEN sa.qualified_flag_ = 1 THEN cs.id_ END) qualified_num_,COUNT(DISTINCT cs.id_) course_num_,
        COUNT(DISTINCT CASE WHEN cs.type_ = 'SINGLE' THEN cs.id_ END) single_num_,
        COUNT(DISTINCT CASE WHEN cs.type_ = 'MIX' THEN cs.id_ END) mix_num_,COUNT(DISTINCT sa.id_) sign_num_,
        COUNT(DISTINCT CASE WHEN sa.id_ IS NULL AND cs.status_ = 'OVER' THEN cs.id_ END) not_sign_num_,
        GROUP_CONCAT(DISTINCT CASE WHEN sa.id_ IS NULL AND cs.status_ = 'OVER' THEN cs.class_date_ END) not_sign_date_
        FROM student_extracurricular_exercises_situation_ sees
        LEFT JOIN student_basic_info sbi ON sbi.user_id_ = sees.student_id_
        LEFT JOIN music_group mg ON mg.id_ = sees.music_group_id_
        LEFT JOIN course_schedule_student_payment cssp ON cssp.music_group_id_ = sees.music_group_id_ AND cssp.user_id_ = sees.student_id_ AND cssp.group_type_ = 'MUSIC'
        LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_ AND cs.del_flag_ = 0 AND cs.pre_course_flag_ = 0
        AND cs.is_lock_ = 0 AND ( cs.new_course_id_ IS NULL OR cs.new_course_id_ = cs.id_ ) AND cs.class_date_ BETWEEN #{monday} AND #{sunday}
        LEFT JOIN student_attendance sa ON sa.course_schedule_id_ = cs.id_ AND sa.user_id_ = cssp.user_id_ AND sa.status_ IN ('NORMAL','LATE')
        WHERE sees.monday_ >= #{monday} AND sees.sunday_ &lt;= #{sunday}
        GROUP BY sees.student_id_,sees.music_group_id_) cs ON cs.student_id_ = sees.student_id_ AND cs.music_group_id_ = sees.music_group_id_
        <where>
            <if test="organId != null and organId != ''">
                AND FIND_IN_SET(cs.organ_id_,#{organId})
            </if>
        </where>
        ORDER BY cs.organ_id_,cs.student_id_,cs.music_group_id_
    </select>
    
    <select id="queryStudentExerciseMusicGroupList" resultType="com.ym.mec.biz.dal.dto.MusicGroupExtracurricularSummaryDto">
    	SELECT sees.music_group_id_ musicGroupId,mg.name_ musicGroupName,count(distinct sees.student_id_) studentNum from student_extracurricular_exercises_situation_ sees 
		LEFT JOIN music_group mg on mg.id_ = sees.music_group_id_
		WHERE sees.teacher_id_ = #{teacherId} and sees.serve_type_ = 'EXERCISE' and sees.actual_exercises_num_ = 0
		<if test="musicGroupName != null and musicGroupName != ''">
			and mg.name_ LIKE CONCAT('%', #{musicGroupName}, '%')
		</if>
		<if test="mondayDate != null and mondayDate != ''">
			and sees.monday_ =  #{mondayDate}
		</if>
		<if test="sundayDate != null and sundayDate != ''">
			and sees.sunday_ = #{sundayDate}
		</if>
		GROUP BY sees.music_group_id_
        <include refid="global.limit" />
    </select>
    
    <select id="queryStudentExerciseMusicGroupListCount" resultType="int">
    	SELECT count(distinct sees.music_group_id_) from student_extracurricular_exercises_situation_ sees 
		LEFT JOIN music_group mg on mg.id_ = sees.music_group_id_
		WHERE sees.teacher_id_ = #{teacherId} and sees.serve_type_ = 'EXERCISE' and sees.actual_exercises_num_ = 0
		<if test="musicGroupName != null and musicGroupName != ''">
			and mg.name_ LIKE CONCAT('%', #{musicGroupName}, '%')
		</if>
		<if test="mondayDate != null and mondayDate != ''">
			and sees.monday_ =  #{mondayDate}
		</if>
		<if test="sundayDate != null and sundayDate != ''">
			and sees.sunday_ = #{sundayDate}
		</if>
    </select>
</mapper>
