<?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.EnrollmentPlanMajorSetMapper">
    <select id="baseMajorSetOfEnrollmentPlan" parameterType="com.xjrsoft.module.student.dto.BaseMajorSetOfEnrollmentPlanPageDto"
            resultType="com.xjrsoft.module.student.vo.BaseMajorSetOfEnrollmentPlanPageVo">
        select
        t.id,
        t.name as baseMajorSetCn,
        t.department_id as departmentId,
        t3.name as majorGradationIdCn,
        t4.name as departmentIdCn,
        (SELECT
             COUNT(*)
         FROM enrollment_plan_major_set a
         WHERE  a.base_major_set_id = t.id
           and a.delete_mark = 0
        <if test="dto.enrollmentPlanId != null">
            and a.enrollment_plan_id = #{dto.enrollmentPlanId}
        </if>
         ) as isSelect
        from base_major_set t
        left join base_major_gradation t3 on t3.id = t.major_gradation_id
        left join xjr_department t4 on t4.id = t.department_id
        where t.delete_mark = 0
        <if test="dto.name != null and dto.name != ''">
            and t.name like concat('%', #{dto.name}, '%')
        </if>
        <if test="dto.departmentId != null and dto.departmentId > 0">
            and t.department_id = #{dto.departmentId}
        </if>
        <if test="dto.majorCategorId != null and dto.majorCategorId > 0">
            and t.major_categor_id = #{dto.majorCategorId}
        </if>
    </select>

    <select id="baseGraduateSchoolOfEnrollmentPlan" parameterType="com.xjrsoft.module.student.dto.BaseGraduateSchoolOfEnrollmentPlanListDto"
            resultType="com.xjrsoft.module.student.vo.BaseGraduateSchoolOfEnrollmentPlanListVo">
        select
        t.id,
        t.name,
        (SELECT
        COUNT(*)
        FROM enrollment_plan_graduate_school a
        left join enrollment_plan_major_set b on b.id = a.enrollment_plan_major_set_id
        WHERE  a.base_graduate_school_id = t.id
        and a.delete_mark = 0
        <if test="dto.enrollmentPlanId != null">
            and b.enrollment_plan_id = #{dto.enrollmentPlanId}
        </if>
        <if test="dto.baseMajorSetId != null">
            and b.base_major_set_id = #{dto.baseMajorSetId}
        </if>
        ) as isSelect
        from base_graduate_school t
        where t.delete_mark = 0
    </select>
</mapper>