<?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.njzscloud.supervisory.resource.mapper.SysResourceMapper">

    <resultMap id="listUserMenuMap" autoMapping="true" type="com.njzscloud.common.security.support.MenuResource">
        <result property="breadcrumb" column="breadcrumb" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
    </resultMap>
    <select id="listUserMenu" resultMap="listUserMenuMap">
        SELECT a.id,
        a.sn,
        a.pid,
        a.title,
        a.icon,
        a.tier,
        a.breadcrumb,
        a.sort,
        a.route_name,
        a.menu_category
        FROM sys_menu a
        INNER JOIN sys_role_resource b ON b.data_id = a.id AND b.table_name = 'sys_menu'
        AND b.role_id IN (SELECT a.id
        FROM sys_role a
        INNER JOIN sys_user_role b ON b.role_id = a.id AND b.user_id = #{userId}
        WHERE a.deleted = 0)
        WHERE a.deleted = 0
    </select>

    <select id="listUserEndpoint" resultType="com.njzscloud.common.security.support.EndpointResource">
        SELECT a.id,
        a.request_method,
        a.routing_path,
        a.endpoint_path,
        a.access_model,
        a.memo,
        a.creator_id,
        a.modifier_id,
        a.create_time,
        a.modify_time,
        a.deleted
        FROM sys_endpoint a
        INNER JOIN sys_role_resource b ON b.data_id = a.id AND b.table_name = 'sys_endpoint'
        AND b.role_id IN (SELECT a.id
        FROM sys_role a
        INNER JOIN sys_user_role b ON b.role_id = a.id AND b.user_id = #{userId}
        WHERE a.deleted = 0)
        WHERE a.deleted = 0
    </select>
</mapper>
