<?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.diagbot.mapper.PermissionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.Permission">
        <id column="id" property="id"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="creator" property="creator"/>
        <result column="name" property="name"/>
        <result column="permission_url" property="permissionUrl"/>
        <result column="method" property="method"/>
        <result column="descritpion" property="descritpion"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <select id="getByRole" resultMap="BaseResultMap">
        select a.* from sys_menu a, sys_role_menu b, sys_user_role c
        where a.id = b.menu_id and b.role_id and b.role_id = c.role_id and c.user_id = #{userId}
        and a.is_deleted = 'N' and b.is_deleted = 'N' and c.is_deleted = 'N'
        ORDER BY a.order_no
    </select>


    <select id="getByUserId" parameterType="java.lang.Long" resultType="com.diagbot.entity.Permission">
        select p.*
        from sys_user u, sys_user_role sru, sys_role_permission rp, sys_permission p
        where u.is_deleted = 'N' and sru.is_deleted = 'N' and rp.is_deleted = 'N' and p.is_deleted = 'N'
        and u.id = sru.user_id and sru.role_id = rp.role_id and rp.permission_id = p.id
        and u.id= #{userId}
    </select>
</mapper>
