1、还原超管myabtis-plus自动塞入organId;

2、修复修改菜单权限,角色权限,用户权限没有立刻生效的问题;
This commit is contained in:
gaoqr
2024-06-20 19:41:55 +08:00
parent 6e686816b4
commit 9053616222
2 changed files with 18 additions and 6 deletions
@@ -48,9 +48,8 @@ public class OrganDatabaseInterceptor implements TenantLineHandler {
@Override
public boolean ignoreTable(String tableName) {
return OrganContextHolder.isIgnore() // 情况一,全局忽略多组织
|| CollUtil.contains(ignoreTables, tableName); // 情况二,忽略多组织的表
//忽略超管跳过orm层面自动塞入organid,超管分库分表相关的操作只看本机构下的
// || isAdmin(); //情况三,忽略超级管理员
|| CollUtil.contains(ignoreTables, tableName) // 情况二,忽略多组织的表
|| isAdmin(); //情况三,忽略超级管理员
}
private boolean isAdmin() {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
@@ -192,6 +192,12 @@ public class PermissionServiceImpl implements PermissionService {
// 角色菜单权限发生修改,通知刷新本地缓存
if (CollectionUtil.isNotEmpty(createMenuIds) || CollectionUtil.isNotEmpty(deleteMenuIds)) {
CompletableFuture.runAsync(() -> {
// 获取新增和删除菜单id的并集
Collection<Long> 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));
});
redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, "");
}).exceptionally(e -> {
log.error("redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage());
@@ -288,7 +294,7 @@ public class PermissionServiceImpl implements PermissionService {
throw new ServiceException(ErrorCodeConstants.ROLE_NOT_SUPERADMIN_NO_ORGAN_ID_OPER_ERROR);
}
}
final Long finalOrganId = organId;
Long roleId = reqVO.getRoleId();
// 当前用户不能操作含有自己的角色
if (CollectionUtil.isNotEmpty(userIds)) {
@@ -307,7 +313,6 @@ public class PermissionServiceImpl implements PermissionService {
// 筛选要新增的userRole:前端有,数据库没有
Collection<Long> createRoleUserIds = CollUtil.subtract(userIds, roleUserIds);
if (!CollectionUtil.isEmpty(createRoleUserIds)) {
Long finalOrganId = organId;
userRoleMapper.insertBatch(CollectionUtils.convertList(createRoleUserIds, userId -> {
UserRoleDO entity = new UserRoleDO();
entity.setUserId(userId).setRoleId(roleId).setOrganId(finalOrganId);
@@ -324,6 +329,12 @@ public class PermissionServiceImpl implements PermissionService {
// 角色菜单权限发生修改,通知刷新本地缓存
if (CollectionUtil.isNotEmpty(createRoleUserIds) || CollectionUtil.isNotEmpty(deleteRoleUserIds)) {
CompletableFuture.runAsync(() -> {
// 获取新增和删除用户id的并集
Collection<Long> 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));
});
redisTemplate.convertAndSend(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, "");
}).exceptionally(e -> {
log.error("redis message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage());
@@ -404,9 +415,11 @@ public class PermissionServiceImpl implements PermissionService {
// 角色菜单权限发生修改,通知刷新本地缓存
if (CollectionUtil.isNotEmpty(createRoleIds) || CollectionUtil.isNotEmpty(deleteMenuIds)) {
CompletableFuture.runAsync(() -> {
// 移除redis中的缓存
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 message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage());
log.error("redis 清空user_role_ids或message发送失败, topic:{}, 异常:{}", RedisRefreshChannelTopicConstants.PERMISSION_REFRESH, e.getMessage());
return null;
});
}