122 lines
3.6 KiB
XML
122 lines
3.6 KiB
XML
<?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="cc.iteachyou.cms.dao.RoleMapper">
|
|
<resultMap id="BaseResultMap" type="cc.iteachyou.cms.entity.Role">
|
|
<!--
|
|
WARNING - @mbg.generated
|
|
-->
|
|
<id column="id" jdbcType="VARCHAR" property="id" />
|
|
<result column="role_name" jdbcType="VARCHAR" property="roleName" />
|
|
<result column="role_code" jdbcType="VARCHAR" property="roleCode" />
|
|
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
|
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
|
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
|
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
|
</resultMap>
|
|
<sql id="Base_Column_List">
|
|
<!--
|
|
WARNING - @mbg.generated
|
|
-->
|
|
id, role_name, role_code, create_by, create_time, update_by, update_time
|
|
</sql>
|
|
|
|
<select id="queryListByPage" parameterType="java.util.Map" resultMap="BaseResultMap">
|
|
select
|
|
*
|
|
from system_role
|
|
where 1 = 1
|
|
<if test="roleName != null and roleName != ''">
|
|
and role_name like concat('%', #{roleName,jdbcType=VARCHAR},'%')
|
|
</if>
|
|
<if test="roleCode != null and roleCode != ''">
|
|
and role_code = #{roleCode,jdbcType=VARCHAR}
|
|
</if>
|
|
order by create_time desc
|
|
</select>
|
|
|
|
<select id="selectPermissionsByRoleId" parameterType="java.lang.String" resultType="cc.iteachyou.cms.entity.vo.PermissionVO">
|
|
SELECT
|
|
m.id,
|
|
m.menu_name AS permissionName,
|
|
m.parent_id AS parentId,
|
|
'menu' AS TYPE,
|
|
CASE
|
|
WHEN p.id IS NULL THEN FALSE
|
|
ELSE TRUE
|
|
END AS checked
|
|
FROM system_menu m
|
|
LEFT JOIN system_role_permission p ON p.permission_id = m.id AND p.type = '1' AND p.role_id = #{roleId,jdbcType=VARCHAR}
|
|
UNION ALL
|
|
SELECT
|
|
m.id,
|
|
m.permission_name AS permissionName,
|
|
m.menu_id AS parentId,
|
|
'perm' AS TYPE,
|
|
CASE
|
|
WHEN p.id IS NULL THEN FALSE
|
|
ELSE TRUE
|
|
END AS checked
|
|
FROM system_permission m
|
|
LEFT JOIN system_role_permission p ON p.permission_id = m.id AND p.type = '2' AND p.role_id = #{roleId,jdbcType=VARCHAR}
|
|
</select>
|
|
|
|
<!-- 根据用户ID查询所拥有的角色 -->
|
|
<select id="selectRoleCodesByUserId" parameterType="java.lang.String" resultType="java.lang.String">
|
|
SELECT
|
|
r.role_code
|
|
FROM system_role r
|
|
WHERE
|
|
r.id IN(
|
|
SELECT ur.role_id FROM system_user_role ur WHERE ur.user_id = #{userId,jdbcType=VARCHAR}
|
|
)
|
|
</select>
|
|
|
|
<!-- 根据用户ID查询所拥有的权限 -->
|
|
<select id="selectPermissionCodesByUserId" parameterType="java.lang.String" resultType="java.lang.String">
|
|
SELECT
|
|
m.menu_code as permissionCode
|
|
FROM system_menu m
|
|
WHERE
|
|
m.id IN(
|
|
SELECT
|
|
rp.permission_id
|
|
FROM system_role_permission rp
|
|
WHERE
|
|
rp.type = '1'
|
|
AND rp.role_id IN (
|
|
SELECT r.id
|
|
FROM system_role r
|
|
WHERE
|
|
r.id IN(
|
|
SELECT role_id FROM system_user_role ur WHERE ur.user_id = #{userId,jdbcType=VARCHAR}
|
|
)
|
|
)
|
|
)
|
|
UNION ALL
|
|
SELECT
|
|
p.permission_code as permissionCode
|
|
FROM system_permission p
|
|
WHERE
|
|
p.id IN(
|
|
SELECT
|
|
rp.permission_id
|
|
FROM system_role_permission rp
|
|
WHERE
|
|
rp.type = '2'
|
|
AND rp.role_id IN (
|
|
SELECT r.id
|
|
FROM system_role r
|
|
WHERE
|
|
r.id IN(
|
|
SELECT role_id FROM system_user_role ur WHERE ur.user_id = #{userId,jdbcType=VARCHAR}
|
|
)
|
|
)
|
|
)
|
|
</select>
|
|
|
|
<select id="selectAllPermissionCodes" resultType="java.lang.String">
|
|
SELECT m.menu_code as permissionCode FROM system_menu m
|
|
UNION ALL
|
|
SELECT p.permission_code as permissionCode FROM system_permission p
|
|
</select>
|
|
</mapper> |