<?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.dispose.sys.resource.mapper.ResourceMapper">
    <select id="occupied" resultType="java.lang.String">
        SELECT DISTINCT c.role_name
        FROM sys_resource a
        INNER JOIN sys_role_resource b ON b.res_id = a.id
        INNER JOIN sys_role c ON c.id = b.role_id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="listRoleRes" resultType="com.njzscloud.dispose.sys.resource.pojo.entity.ResourceEntity">
        SELECT a.id,
               a.sn,
               a.table_name,
               a.data_id,
               a.memo
        FROM sys_resource a
                 INNER JOIN sys_role_resource b ON b.res_id = a.id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
    <select id="loadPermission" resultType="com.njzscloud.common.security.permission.RolePermission">
        SELECT b.request_method,
               b.endpoint_path endpoint,
               b.access_model,
               d.role_code     `role`
        FROM sys_resource a
                 INNER JOIN sys_endpoint b ON b.id = a.data_id
                 LEFT JOIN sys_role_resource c ON c.res_id = a.id
                 LEFT JOIN sys_role d ON d.id = c.role_id
        WHERE a.table_name = 'sys_endpoint'
    </select>
</mapper>
