<?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.system.mapper.XjrMenuGroupMapper">
    <select id="getMenuList" parameterType="com.xjrsoft.module.system.dto.XjrMenuGroupMenuListDto" resultType="com.xjrsoft.module.system.vo.XjrMenuGroupMenuListVo">
        SELECT t1.id, t1.name,(
        SELECT COUNT(*) FROM xjr_menu_group WHERE delete_mark = 0 AND xjr_menu_group_set_id =  #{dto.xjrMenuGroupSetId}
        AND xjr_menu_id = t1.id
        ) AS is_selected,
        (SELECT COUNT(*) FROM xjr_menu_group a1
        INNER JOIN xjr_menu_group_set a2 ON a1.xjr_menu_group_set_id = a2.id
        WHERE a1.delete_mark = 0 AND a2.id !=  #{dto.xjrMenuGroupSetId} AND a2.role_id = #{dto.roleId}
        AND a2.delete_mark = 0
        AND a1.xjr_menu_id = t1.id) AS is_used FROM xjr_menu t1
        LEFT JOIN xjr_subsystem t2 ON t1.system_id = t2.id
        WHERE 1 = 1
        AND t1.delete_mark = 0 AND t1.enabled_mark = 1
        AND t1.system_type = 'system_app'
        <if test="dto.roleId != null and dto.roleId == 3">
            and t2.code = 'student_app'
        </if>
        <if test="dto.roleId != null and dto.roleId == 4">
            and t2.code = 'parents_app'
        </if>
    </select>
</mapper>