<?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.student.mapper.StudentReportRecordMapper">
    <select id="getClassStatistics" parameterType="com.xjrsoft.module.student.dto.StudentReportRecordStatisticsDto"
            resultType="com.xjrsoft.module.student.vo.StudentReportRecordStatisticsVo">
        SELECT t1.name AS class_name,t2.name AS teacher_name,
        (
        SELECT COUNT(*) FROM xjr_user a1
        INNER 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
        ) AS all_count,
        (
        SELECT COUNT(*) FROM xjr_user a1
        INNER 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
        ) AS male_count,
        (
        SELECT COUNT(*) FROM xjr_user a1
        INNER 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
        ) AS female_count,
        (
        SELECT COUNT(distinct(a1.id)) FROM xjr_user a1
        INNER JOIN base_student_school_roll a2 ON a1.id = a2.user_id
        INNER JOIN student_report_record a3 ON a1.id = a3.user_id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0 and a3.delete_mark = 0
        AND a2.class_id = t1.id AND a3.base_semester_id = #{dto.baseSemesterId} AND a3.report_time IS NOT NULL
        ) AS arrived_count
        FROM base_class t1
        INNER JOIN xjr_user t2 ON t1.teacher_id = t2.id
        WHERE t1.delete_mark = 0 and t1.grade_id = #{dto.gradeId}
        AND t1.teacher_id = #{dto.teacherId}
    </select>
    <select id="getMobilePage" parameterType="com.xjrsoft.module.student.dto.StudentReportRecordPageDto"
            resultType="com.xjrsoft.module.student.vo.StudentReportRecordPageVo">
        SELECT t1.id as user_id,t1.name,t1.credential_number,t1.mobile,t4.name AS stduy_status_cn,t5.telephone AS parent_mobile,t2.graduated_university,
        (select count(*) from student_report_record where user_id = t1.id and base_semester_id = #{dto.baseSemesterId} and delete_mark = 0) as is_report FROM xjr_user t1
        INNER JOIN base_student_school_roll t2 ON t1.id = t2.user_id
        INNER JOIN base_class t3 ON t2.class_id = t3.id
        LEFT JOIN xjr_dictionary_detail t4 ON t2.stduy_status = t4.code
        LEFT JOIN base_student_family t5 ON t5.user_id = t1.id
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        AND t3.teacher_id = #{dto.teacherId} and t2.grade_id = #{dto.gradeId}
        <if test="dto.keyword != null and dto.keyword != ''">
            and t1.name like concat('%', #{dto.keyword},'%')
        </if>
        <if test="dto.classId != null">
            and t3.id = #{dto.classId}
        </if>
        ORDER BY t1.create_date DESC, t2.create_date DESC,t3.create_date DESC,t1.id
    </select>
    <select id="getStatisticsDataList" parameterType="com.xjrsoft.module.student.dto.StudentReportRecordStatisticsDto"
            resultType="com.xjrsoft.module.student.vo.StudentReportRecordStatisticsListVo">
        SELECT t1.name,t1.credential_number,t2.gender,t4.graduated_university,t4.stduy_status,t5.report_time ,
        t6.name AS class_name,t8.name as class_type,t7.name AS major_name FROM base_new_student t1
        INNER JOIN xjr_user t2 ON t1.credential_number = t2.credential_number
        INNER JOIN enrollment_plan t3 ON t3.id = t1.enrollment_plan_id
        INNER JOIN base_student_school_roll t4 ON t4.user_id = t2.id
        LEFT JOIN student_report_record t5 ON t2.id = t5.user_id AND t5.delete_mark = 0
        INNER JOIN base_class t6 ON t6.id = t4.class_id
        INNER JOIN base_major_set t7 ON t7.id = t6.major_set_id
        left join xjr_dictionary_detail t8 on t6.class_type = t8.code and t8.item_id = 2023000000000000039
        WHERE t1.delete_mark = 0 AND t2.delete_mark = 0
        AND t3.grade_id = #{dto.gradeId} AND t3.enroll_type = #{dto.enrollType}
        AND (t1.delete_reason IS NULL OR t1.delete_reason = '')
        AND t2.delete_mark = 0
    </select>
</mapper>