From 666cdb08c2710abe714ac1e6126c279770868d82 Mon Sep 17 00:00:00 2001 From: gaoqr <13665037151@163.com> Date: Fri, 21 Jun 2024 10:51:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=92=E8=89=B2=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E3=80=81=E8=A7=92=E8=89=B2=E7=94=A8=E6=88=B7=E3=80=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2=E6=8E=88=E6=9D=83=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E7=AB=8B=E5=8D=B3=E7=94=9F=E6=95=88=EF=BC=9A=201?= =?UTF-8?q?=E3=80=81=E9=80=90=E4=B8=AA=E5=88=A0=E9=99=A4key=20->=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=EF=BC=9B=202=E3=80=81?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BA=BA=E6=93=8D=E4=BD=9C=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=9C=BA=E6=9E=84=E6=97=B6=E6=89=8D=E6=98=BE=E7=A4=BA=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=9B=203=E3=80=81=E6=97=A5=E5=BF=97=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E4=BC=98=E5=8C=96=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permission/PermissionServiceImpl.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/permission/PermissionServiceImpl.java b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/permission/PermissionServiceImpl.java index e1cb70387..2b8a97ddf 100644 --- a/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/permission/PermissionServiceImpl.java +++ b/cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/permission/PermissionServiceImpl.java @@ -3,6 +3,7 @@ package com.cf.imes.module.system.service.permission; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import com.cf.imes.framework.common.enums.CommonStatusEnum; import com.cf.imes.framework.common.exception.ServiceException; @@ -189,18 +190,22 @@ public class PermissionServiceImpl implements PermissionService { roleMenuMapper.deleteListByRoleIdAndMenuIds(roleId, deleteMenuIds); } + Long currentOrganId = SecurityFrameworkUtils.getUserOrganId(); // 角色菜单权限发生修改,通知刷新本地缓存 if (CollectionUtil.isNotEmpty(createMenuIds) || CollectionUtil.isNotEmpty(deleteMenuIds)) { CompletableFuture.runAsync(() -> { - // 获取新增和删除菜单id的并集 - Collection delKeys = CollUtil.union(createMenuIds, deleteMenuIds); - delKeys.forEach(menuId -> { - // 移除redis中的缓存 - redisTemplate.delete(String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), organId, menuId)); - }); + // 当前操作人和所操作的目标菜单机构不同时,清空MENU_ROLE_ID_LIST:目标机构id:菜单id的缓存 + if (ObjectUtil.notEqual(organId, currentOrganId)) { + // 获取新增和删除菜单id的并集 + Collection delMenuIds = CollUtil.union(createMenuIds, deleteMenuIds); + // 构建批量删除的key集合 + Set delKeys = delMenuIds.stream().map(menuId -> String.format(String.valueOf(new StringBuffer(RedisKeyConstants.MENU_ROLE_ID_LIST).append(":%s:%s")), organId, menuId)).collect(Collectors.toSet()); + Long batchDelNum = redisTemplate.delete(delKeys); + log.info("[assignRoleMenu] 批量删除redis[MENU_ROLE_ID_LIST]数量:{}", batchDelNum); + } redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, ""); }).exceptionally(e -> { - log.error("redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage()); + log.error("[assignRoleMenu] redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e); return null; }); } @@ -326,18 +331,22 @@ public class PermissionServiceImpl implements PermissionService { userRoleMapper.deleteListByRoleIdAndUserIds(roleId, deleteRoleUserIds); } + Long currentOrganId = SecurityFrameworkUtils.getUserOrganId(); // 角色菜单权限发生修改,通知刷新本地缓存 if (CollectionUtil.isNotEmpty(createRoleUserIds) || CollectionUtil.isNotEmpty(deleteRoleUserIds)) { CompletableFuture.runAsync(() -> { - // 获取新增和删除用户id的并集 - Collection delKeys = CollUtil.union(createRoleUserIds, deleteRoleUserIds); - delKeys.forEach(userId -> { - // 移除redis中的缓存 - redisTemplate.delete(String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), finalOrganId, userId)); - }); + // 当前操作人和所操作的目标菜单机构不同时,清空USER_ROLE_ID_LIST:目标机构id:用户id的缓存 + if (ObjectUtil.notEqual(finalOrganId, currentOrganId)) { + // 获取新增和删除用户id的并集 + Collection delRoleUserIds = CollUtil.union(createRoleUserIds, deleteRoleUserIds); + // 构建批量删除的key集合 + Set delKeys = delRoleUserIds.stream().map(userId -> String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), finalOrganId, userId)).collect(Collectors.toSet()); + Long batchDelNum = redisTemplate.delete(delKeys); + log.info("[batchAssignRoleUsers] 批量删除redis[USER_ROLE_ID_LIST]数量:{}", batchDelNum); + } redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, ""); }).exceptionally(e -> { - log.error("redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage()); + log.error("[batchAssignRoleUsers] redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e); return null; }); } @@ -419,7 +428,7 @@ public class PermissionServiceImpl implements PermissionService { redisTemplate.delete(String.format(String.valueOf(new StringBuffer(RedisKeyConstants.USER_ROLE_ID_LIST).append(":%s:%s")), organId, userId)); redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, ""); }).exceptionally(e -> { - log.error("redis 清空user_role_ids或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage()); + log.error("[assignUserRole] redis 清空USER_ROLE_ID_LIST或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e); return null; }); }