<?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.education.business.mapper.system.SystemMenuMapper">

    <select id="getTreeMenuList" resultType="com.education.model.dto.MenuTree">
       select
         a.name,
         a.name as label,
         a.id, a.url,
         a.type,
         a.create_type,
         a.sort, a.parent_id, a.permission, a.icon, b.name as parent_name from system_menu a left join (select id, name from system_menu) b
       on a.parent_id = b.id order by a.sort asc
    </select>

    <select id="selectMenuTreeById" resultType="com.education.model.dto.MenuTree">
         select
           a.name,
           a.name as label,
           a.id, a.url,
           a.type,
           a.create_type,
           a.sort, a.parent_id, a.permission, a.icon, b.name as parent_name
         from system_menu a left join (select id, name from system_menu) b
         on a.parent_id = b.id
         where a.id = #{id} order by a.sort asc
    </select>

    <select id="getMenuListByRoles" resultType="com.education.model.entity.SystemMenu">
        select * from system_menu where id in (
           select menu_id from system_role_menu where role_id in
           <foreach collection="roleIds" separator="," open="(" close=")" item="roleId">
               #{roleId}
           </foreach>
        ) order by sort asc
    </select>


    <select id="selectTreeMenuListByRoleId" resultType="com.education.model.dto.MenuTree">
        select * from system_menu where id in (select menu_id from system_role_menu where role_id = #{roleId})
        order by sort asc
    </select>
</mapper>