<?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.qmth.paper.library.common.mapper.SysPrivilegeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.paper.library.common.entity.SysPrivilege">
    <result column="id" property="id" />
        <result column="name" property="name" />
        <result column="url" property="url" />
        <result column="type" property="type" />
        <result column="parent_id" property="parentId" />
        <result column="sequence" property="sequence" />
        <result column="property" property="property" />
        <result column="related" property="related" />
        <result column="enable" property="enable" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        school_id, name, url, type, parent_id, sequence, property, related
    </sql>

    <select id="getClientUrlByUserId" resultMap="BaseResultMap">
        SELECT
            *
        FROM
            sys_privilege sp
                JOIN
            sys_role_privilege srp ON sp.id = srp.privilege_id
                JOIN
            sys_user_role sur ON srp.role_id = sur.role_id
        WHERE
            sur.user_id = #{userId}
    </select>

    <select id="findByConnectByParentId" resultType="com.qmth.paper.library.common.entity.SysPrivilege">
        SELECT su.* FROM (SELECT @a AS _id, (SELECT @a := sp.parent_id FROM sys_privilege sp WHERE sp.id = _id) AS parent_id FROM (SELECT @a := #{privilegeId}) vars, sys_privilege h) temp JOIN sys_privilege su ON temp._id = su.id
    </select>

<!--    <select id="getRolePrivilegeList" resultType="SysRolePrivilegeDto">-->
<!--        select-->
<!--        bs.name as schoolName,-->
<!--        bs.code as schoolCode,-->
<!--        sr.id as roleId,-->
<!--        sr.name as roleName,-->
<!--        sp.id as privilegeId,-->
<!--        sp.name as privilegeName,-->
<!--        sp.url as privilegeUrl,-->
<!--        sp.`type` as privilegeType,-->
<!--        srp.id as rolePrivilegeId-->
<!--        from-->
<!--        sys_role_privilege srp-->
<!--        join sys_privilege sp on-->
<!--        sp.id = srp.privilege_id-->
<!--        join sys_role sr on-->
<!--        sr.id = srp.role_id-->
<!--        join basic_school bs on-->
<!--        bs.id = sr.school_id-->
<!--        where-->
<!--        srp.enable = true-->
<!--        and sp.enable = true-->
<!--        and sr.enable = true-->
<!--        and srp.role_id <![CDATA[ <> ]]> 1-->
<!--        and srp.privilege_id <![CDATA[ > ]]> 100000-->
<!--    </select>-->

<!--    <select id="getRolePrivilegeCount" resultType="java.lang.Integer">-->
<!--        select count(1) from-->
<!--        sys_role_privilege srp-->
<!--        join sys_privilege sp on-->
<!--        sp.id = srp.privilege_id-->
<!--        join sys_role sr on-->
<!--        sr.id = srp.role_id-->
<!--        join basic_school bs on-->
<!--        bs.id = sr.school_id-->
<!--        where-->
<!--        srp.enable = true-->
<!--        and sp.enable = true-->
<!--        and sr.enable = true-->
<!--        and srp.role_id <![CDATA[ <> ]]> 1-->
<!--        and srp.privilege_id <![CDATA[ > ]]> 100000-->
<!--    </select>-->

<!--    <select id="findByDefault" resultType="SysPrivilege">-->
<!--        select * from sys_privilege sp where sp.id <![CDATA[ < ]]> 100000-->
<!--    </select>-->
</mapper>
