<?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.yonge.cooleshow.admin.dao.UmsRoleDao">

    <select id="getMenuList" resultType="com.yonge.cooleshow.mbg.model.UmsMenu">
        SELECT
            m.id id,
            m.parent_id parentId,
            m.create_time createTime,
            m.title title,
            m.level level,
            m.sort sort,
            m.name name,
            m.icon icon,
            m.hidden hidden
        FROM
            ums_admin_role_relation arr
                LEFT JOIN ums_role r ON arr.role_id = r.id
                LEFT JOIN ums_role_menu_relation rmr ON r.id = rmr.role_id
                LEFT JOIN ums_menu m ON rmr.menu_id = m.id
        WHERE
            arr.admin_id = #{adminId}
          AND m.id IS NOT NULL
        GROUP BY
            m.id
    </select>
    <select id="getMenuListByRoleId" resultType="com.yonge.cooleshow.mbg.model.UmsMenu">
        SELECT
            m.id id,
            m.parent_id parentId,
            m.create_time createTime,
            m.title title,
            m.level level,
            m.sort sort,
            m.name name,
            m.icon icon,
            m.hidden hidden
        FROM
             ums_role_menu_relation rmr
                LEFT JOIN ums_menu m ON rmr.menu_id = m.id
        WHERE
            rmr.role_id = #{roleId}
          AND m.id IS NOT NULL
        GROUP BY
            m.id
    </select>
    <select id="getResourceListByRoleId" resultType="com.yonge.cooleshow.mbg.model.UmsResource">
        SELECT
            r.id id,
            r.create_time createTime,
            r.`name` `name`,
            r.url url,
            r.description description,
            r.category_id categoryId
        FROM
            ums_role_resource_relation rrr
                LEFT JOIN ums_resource r ON rrr.resource_id = r.id
        WHERE
            rrr.role_id = #{roleId}
          AND r.id IS NOT NULL
        GROUP BY
            r.id
    </select>
</mapper>