refactor permission system
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?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.imyeyu.api.modules.user.mapper.PermissionMapper">
|
||||
<select id="selectByIdList" resultType="com.imyeyu.api.modules.user.entity.Permission">
|
||||
SELECT
|
||||
*
|
||||
FROM `permission`
|
||||
WHERE
|
||||
TRUE
|
||||
<if test="idList != null and !idList.isEmpty()">
|
||||
AND `id` IN
|
||||
<foreach collection="idList" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="idList == null or idList.isEmpty()">
|
||||
AND FALSE
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectByModuleCode" resultType="com.imyeyu.api.modules.user.entity.Permission">
|
||||
SELECT
|
||||
*
|
||||
FROM `permission`
|
||||
WHERE
|
||||
`module_code` = #{moduleCode}
|
||||
AND `deleted_at` IS NULL
|
||||
ORDER BY `code`
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,6 +1,15 @@
|
||||
<?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.imyeyu.api.modules.user.mapper.RoleMapper">
|
||||
<select id="selectById" resultType="com.imyeyu.api.modules.user.entity.Role">
|
||||
SELECT
|
||||
*
|
||||
FROM `role`
|
||||
WHERE
|
||||
`id` = #{id}
|
||||
AND `deleted_at` IS NULL
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="selectByIdList" resultType="com.imyeyu.api.modules.user.entity.Role">
|
||||
SELECT
|
||||
*
|
||||
@@ -27,4 +36,26 @@
|
||||
AND `deleted_at` IS NULL
|
||||
ORDER BY `created_at`
|
||||
</select>
|
||||
<select id="selectByParentRoleId" resultType="com.imyeyu.api.modules.user.entity.Role">
|
||||
SELECT
|
||||
*
|
||||
FROM `role`
|
||||
WHERE
|
||||
<if test="parentRoleId != null">
|
||||
`parent_role_id` = #{parentRoleId}
|
||||
</if>
|
||||
<if test="parentRoleId == null">
|
||||
`parent_role_id` IS NULL
|
||||
</if>
|
||||
AND `deleted_at` IS NULL
|
||||
ORDER BY `module_code`, `created_at`
|
||||
</select>
|
||||
<select id="selectAll" resultType="com.imyeyu.api.modules.user.entity.Role">
|
||||
SELECT
|
||||
*
|
||||
FROM `role`
|
||||
WHERE
|
||||
`deleted_at` IS NULL
|
||||
ORDER BY `module_code`, `created_at`
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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.imyeyu.api.modules.user.mapper.RolePermissionDelegationMapper">
|
||||
<select id="selectByRoleIdList" resultType="com.imyeyu.api.modules.user.entity.RolePermissionDelegation">
|
||||
SELECT
|
||||
*
|
||||
FROM `role_permission_delegation`
|
||||
WHERE
|
||||
`role_id` IN
|
||||
<foreach collection="roleIdList" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectPermissionByRoleIdList" resultType="com.imyeyu.api.modules.user.entity.Permission">
|
||||
SELECT DISTINCT
|
||||
permission.*
|
||||
FROM `role_permission_delegation`
|
||||
LEFT JOIN `permission` ON permission.id = role_permission_delegation.permission_id
|
||||
WHERE
|
||||
`role_permission_delegation`.`role_id` IN
|
||||
<foreach collection="roleIdList" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND `role_permission_delegation`.`deleted_at` IS NULL
|
||||
AND `permission`.`deleted_at` IS NULL
|
||||
ORDER BY
|
||||
`permission`.code ASC
|
||||
</select>
|
||||
<insert id="createBatch">
|
||||
INSERT INTO `role_permission_delegation` (
|
||||
id,
|
||||
role_id,
|
||||
permission_id,
|
||||
created_by,
|
||||
created_at
|
||||
) VALUES
|
||||
<foreach collection="rolePermissionDelegationList" item="item" separator=",">
|
||||
(#{item.id}, #{item.roleId}, #{item.permissionId}, #{item.createdBy}, #{item.createdAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
<update id="deleteByPermissionIdList">
|
||||
UPDATE `role_permission_delegation`
|
||||
SET `deleted_at` = UNIX_TIMESTAMP()
|
||||
WHERE
|
||||
`role_id` = #{roleId}
|
||||
AND `permission_id` IN
|
||||
<foreach collection="permissionIdList" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND `deleted_at` IS NULL
|
||||
</update>
|
||||
</mapper>
|
||||
+31
-10
@@ -1,10 +1,10 @@
|
||||
<?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.imyeyu.api.modules.user.mapper.RoleRelationMapper">
|
||||
<select id="selectByParentRoleId" resultType="com.imyeyu.api.modules.user.entity.RoleRelation">
|
||||
<mapper namespace="com.imyeyu.api.modules.user.mapper.RolePermissionInheritMapper">
|
||||
<select id="selectByParentRoleId" resultType="com.imyeyu.api.modules.user.entity.RolePermissionInherit">
|
||||
SELECT
|
||||
*
|
||||
FROM `role_relation`
|
||||
FROM `role_permission_inherit`
|
||||
WHERE
|
||||
`parent_role_id` = #{parentRoleId}
|
||||
AND `deleted_at` IS NULL
|
||||
@@ -12,15 +12,26 @@
|
||||
<select id="selectChildRoleIdListByParentRoleId" resultType="java.lang.String">
|
||||
SELECT
|
||||
`child_role_id`
|
||||
FROM `role_relation`
|
||||
FROM `role_permission_inherit`
|
||||
WHERE
|
||||
`parent_role_id` = #{parentRoleId}
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectByParentRoleIdList" resultType="com.imyeyu.api.modules.user.entity.RolePermissionInherit">
|
||||
SELECT
|
||||
*
|
||||
FROM `role_permission_inherit`
|
||||
WHERE
|
||||
`parent_role_id` IN
|
||||
<foreach collection="parentRoleIdList" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectChildRoleIdListByParentRoleIdList" resultType="java.lang.String">
|
||||
SELECT
|
||||
`child_role_id`
|
||||
FROM `role_relation`
|
||||
FROM `role_permission_inherit`
|
||||
WHERE
|
||||
`parent_role_id` IN
|
||||
<foreach collection="parentRoleIdList" item="item" separator="," open="(" close=")">
|
||||
@@ -29,24 +40,34 @@
|
||||
AND `deleted_at` IS NULL
|
||||
</select>
|
||||
<insert id="createBatch">
|
||||
INSERT INTO `role_relation` (
|
||||
INSERT INTO `role_permission_inherit` (
|
||||
id,
|
||||
parent_role_id,
|
||||
child_role_id,
|
||||
owner_type,
|
||||
owner_id,
|
||||
created_by,
|
||||
created_at
|
||||
) VALUES
|
||||
<foreach collection="roleRelationList" item="item" separator=",">
|
||||
(#{item.id}, #{item.parentRoleId}, #{item.childRoleId}, #{item.createdAt})
|
||||
<foreach collection="rolePermissionInheritList" item="item" separator=",">
|
||||
(#{item.id}, #{item.parentRoleId}, #{item.childRoleId}, #{item.ownerType}, #{item.ownerId}, #{item.createdBy}, #{item.createdAt})
|
||||
</foreach>
|
||||
</insert>
|
||||
<update id="deleteByChildRoleIdList">
|
||||
UPDATE `role_relation`
|
||||
SET `deleted_at` = UNIX_TIMESTAMP()
|
||||
UPDATE `role_permission_inherit`
|
||||
SET `deleted_at` = UNIX_TIMESTAMP() * 1000
|
||||
WHERE
|
||||
`parent_role_id` = #{parentRoleId}
|
||||
AND `child_role_id` IN
|
||||
<foreach collection="childRoleIdList" item="item" separator="," open="(" close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
AND `owner_type` = #{ownerType}
|
||||
<if test="ownerId != null">
|
||||
AND `owner_id` = #{ownerId}
|
||||
</if>
|
||||
<if test="ownerId == null">
|
||||
AND `owner_id` IS NULL
|
||||
</if>
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -13,7 +13,7 @@
|
||||
AND `role_permission`.`deleted_at` IS NULL
|
||||
</select>
|
||||
<select id="selectPermissionByRoleIdList" resultType="com.imyeyu.api.modules.user.entity.Permission">
|
||||
SELECT
|
||||
SELECT DISTINCT
|
||||
permission.*
|
||||
FROM `role_permission`
|
||||
LEFT JOIN `permission` ON permission.id = role_permission.permission_id
|
||||
|
||||
Reference in New Issue
Block a user