refactor(pigx-upms-biz): 重构租户菜单缓存清理逻辑

- 将缩进从4个空格统一替换为Tab,并调整链式调用换行格式
- 重构 updateTenant 方法中菜单缓存清理逻辑,移除 RedisUtils 依赖,改用 Spring Cache 的 Cache.evict 按角色ID清除缓存
- 移除未使用的 RedisUtils 导入,增加 Cache 导入
- 微调日志格式和数组字面量格式

(cherry picked from commit b368a80a83a7d7efb34a63cda26e4ad64e99dfd0)
This commit is contained in:
PIGCLOUD committed 2026-09-22 21:52:17 +08:00
1 parent 1dc58c60cf
commit 545b0a4642
1 file changed
+7 -6
@@ -35,7 +35,6 @@ import com.pig4cloud.pigx.common.core.constant.CacheConstants;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
import com.pig4cloud.pigx.common.data.cache.RedisUtils;
import com.pig4cloud.pigx.common.data.datascope.DataScopeTypeEnum;
import com.pig4cloud.pigx.common.data.resolver.ParamResolver;
import com.pig4cloud.pigx.common.data.tenant.TenantBroker;
@@ -46,6 +45,7 @@ import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
@@ -307,11 +307,12 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
});
}
// 清空指定租户的菜单权限缓存
Set<String> keys = RedisUtils.keys(String.format("%s:%s::*", tenantDTO.getId(), CacheConstants.MENU_DETAILS));
if (CollUtil.isNotEmpty(keys)) {
RedisUtils.delete(keys.toArray(new String[0]));
}
// 菜单缓存按角色 ID 全局存储,仅清除目标租户的角色菜单缓存
TenantBroker.runAs(tenantDTO.getId(), tenantId -> {
List<SysRole> roles = roleService.list(Wrappers.<SysRole>lambdaQuery().select(SysRole::getRoleId));
Cache menuCache = Objects.requireNonNull(cacheManager.getCache(CacheConstants.MENU_DETAILS));
roles.forEach(role -> menuCache.evict(role.getRoleId()));
});
return Boolean.TRUE;
}