<?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.banding.mapper.BandingTaskMapper">
    <select id="getPage" parameterType="com.xjrsoft.module.banding.dto.BandingTaskPageDto" resultType="com.xjrsoft.module.banding.vo.BandingTaskPageVo">
        SELECT t.id, t.sort_code, t.grade_id, t.enroll_type, t.name, t.status, t2.name AS enrollTypeCn, t1.name AS gradeName,
        (SELECT COUNT(*) FROM base_new_student a1
        INNER JOIN enrollment_plan a2 ON a1.enrollment_plan_id = a2.id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0
        AND a2.grade_id = t.grade_id AND a2.enroll_type = t.enroll_type
        ) AS admissions_count,
        (SELECT COUNT(*) FROM banding_task_class_student a1
        INNER JOIN banding_task_class a2 ON a1.banding_task_class_id = a2.id
        WHERE a1.delete_mark = 0 AND a2.delete_mark = 0 AND a2.banding_task_id = t.id) AS divided_count
        FROM banding_task t
        LEFT JOIN base_grade t1 ON (t1.id = t.grade_id)
        LEFT JOIN xjr_dictionary_detail t2 ON (t2.code = t.enroll_type)
        WHERE t.delete_mark = 0 AND t2.delete_mark = 0
        <if test="dto.enrollType != null and dto.enrollType != ''">
            and t.enroll_type = #{dto.enrollType}
        </if>
    </select>
</mapper>