Merge remote-tracking branch 'origin/main'

This commit is contained in:
liuzhaotian
2024-06-21 10:12:02 +08:00
@@ -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());
@@ -375,7 +386,7 @@ public class PermissionServiceImpl implements PermissionService {
@Override
@DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换
@CacheEvict(value = RedisKeyConstants.USER_ROLE_ID_LIST, key = "#userId")
@CacheEvict(value = RedisKeyConstants.USER_ROLE_ID_LIST, allEntries = true)
public void assignUserRole(Long userId, Set<Long> roleIds, Long organId) {
if(Objects.equals(userId, SecurityFrameworkUtils.getLoginUserId())) {
throw exception(ROLE_ME_ERROR);
@@ -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;
});
}