<?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.xjrsoft.module.base.mapper.BaseClassMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.base.dto.BaseClassPageDto" resultType="com.xjrsoft.module.base.vo.BaseClassPageVo">
        SELECT t1.id,t1.name,t1.code,t4.name AS grade_name,t2.name AS teacher_name,t3.name AS enroll_type_cn,
        t5.name AS class_type_cn,t6.name AS classroomName,
        (SELECT COUNT(DISTINCT(a1.id)) FROM xjr_user a1
        LEFT JOIN base_student_school_roll a2 ON a1.id = a2.user_id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
        AND a1.gender = 'SB10001' AND a2.class_id = t1.id
        AND a2.archives_status = 'FB2901') AS male_cout,
        (SELECT COUNT(DISTINCT(a1.id)) FROM xjr_user a1
        LEFT JOIN base_student_school_roll a2 ON a1.id = a2.user_id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
        AND a1.gender = 'SB10002' AND a2.class_id = t1.id
        AND a2.archives_status = 'FB2901') AS female_count,
        (SELECT COUNT(DISTINCT(a1.id)) FROM xjr_user a1
        LEFT JOIN base_student_school_roll a2 ON a1.id = a2.user_id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
        AND a2.class_id = t1.id AND a2.stduy_status = 'FB3002'
        AND a2.archives_status = 'FB2901') AS stay_count,
        (SELECT COUNT(DISTINCT(a1.id)) FROM xjr_user a1
        LEFT JOIN base_student_school_roll a2 ON a1.id = a2.user_id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
        AND a2.class_id = t1.id AND a2.stduy_status = 'FB3001'
        AND a2.archives_status = 'FB2901') AS not_stay_count,t7.name AS org_name,
        t8.name as major_set_name,t1.major_set_id FROM base_class t1
        LEFT JOIN xjr_user t2 ON t1.teacher_id = t2.id
        LEFT JOIN xjr_dictionary_detail t3 ON t3.code = t1.enroll_type AND t3.item_id = 2023000000000000027
        LEFT JOIN xjr_dictionary_detail t5 ON t5.code = t1.class_type AND t5.item_id = 1784405535724978177
        LEFT JOIN base_grade t4 ON t1.grade_id = t4.id
        LEFT JOIN base_classroom t6 ON t1.classroom_id = t6.id
        LEFT JOIN xjr_department t7 ON t1.org_id = t7.id
        left join base_major_set t8 on t1.major_set_id = t8.id
        WHERE t1.delete_mark = 0
        <if test="dto.name != null and dto.name != ''">
            and t1.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.teacherName != null and dto.teacherName != ''">
            and t2.name like concat('%', #{dto.teacherName}, '%')
        </if>
        <if test="dto.gradeId != null">
            and t4.id = #{dto.gradeId}
        </if>
        <if test="dto.classroomName != null and dto.classroomName != ''">
            and t6.name like concat('%', #{dto.classroomName}, '%')
        </if>
        <if test="dto.classType != null and dto.classType != ''">
            and t1.class_type = #{dto.classType}
        </if>
        <if test="dto.isOrderClass != null">
            and t1.is_order_class = #{dto.isOrderClass}
        </if>
        <if test="dto.isGraduate != null">
            and t1.is_graduate = #{dto.isGraduate}
        </if>
        <if test="dto.teacherId != null">
            and t1.teacher_id = #{dto.teacherId}
        </if>
        <if test="dto.orgId != null">
            and t1.org_id = #{dto.orgId}
        </if>
        <if test="dto.classroomId != null">
            and t1.classroom_id = #{dto.classroomId}
        </if>
        <if test="dto.code != null and dto.code != ''">
            and t1.code like concat('%', #{dto.code}, '%')
        </if>
        <if test="dto.enrollType != null and dto.enrollType != ''">
            and t1.enroll_type = #{dto.enrollType}
        </if>
    </select>

    <select id="getStudentClass" resultType="com.xjrsoft.module.base.vo.StudentClassVo">
        SELECT t2.user_id, t1.id, t1.name, t1.teacher_id FROM base_class t1
        INNER JOIN base_student_school_roll t2 ON t1.id = t2.class_id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
    </select>
    <select id="getAttendanceClass" resultType="com.xjrsoft.module.attendance.vo.ClassStatisticsVo">
        SELECT t1.id,t1.name,t2.name AS teacher_name,
        (SELECT COUNT(*) FROM base_student_school_roll c1
        INNER JOIN xjr_user c2 ON c1.user_id = c2.id
        WHERE c1.delete_mark = 0 AND c1.delete_mark = 0
        AND c1.class_id = t1.id AND c1.archives_status = 'FB2901') AS student_count,
        (SELECT COUNT(*) FROM base_student_school_roll c1
        INNER JOIN xjr_user c2 ON c1.user_id = c2.id
        WHERE c1.delete_mark = 0 AND c1.delete_mark = 0
        AND c1.class_id = t1.id AND c1.archives_status = 'FB2901' AND c1.stduy_status = 'FB3002') AS stay_count,
        (SELECT COUNT(*) FROM base_student_school_roll c1
        INNER JOIN xjr_user c2 ON c1.user_id = c2.id
        WHERE c1.delete_mark = 0 AND c1.delete_mark = 0
        AND c1.class_id = t1.id AND c1.archives_status = 'FB2901' AND c1.stduy_status = 'FB3001') AS not_stay_count FROM base_class t1
        LEFT JOIN xjr_user t2 ON t1.teacher_id = t2.id
        WHERE t1.delete_mark = 0
        <if test="dto.classId != null">
            and t1.id = #{dto.classId}
        </if>
        <if test="dto.gradeId != null">
            and t1.grade_id = #{dto.gradeId}
        </if>
    </select>
</mapper>