fix: 修复租户套餐更新时租户权限未更新问题、租户操作日志未记录问题、租户角色管理模块菜单过滤、删除租户时菜单被删除问题

This commit is contained in:
小熊
2025-07-20 19:21:07 +08:00
parent 382c87f8bd
commit ada6f3ef5c
8 changed files with 59 additions and 10 deletions

View File

@@ -126,8 +126,6 @@ public class TenantDataHandlerForSystem implements TenantDataHandler {
}
// 日志清除
logMapper.delete(dw);
// 菜单清除
menuMapper.delete(dw);
// 消息清除
messageMapper.delete(dw);
messageUserMapper.delete(dw);

View File

@@ -49,6 +49,7 @@ import top.continew.starter.extension.tenant.util.TenantUtils;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
@@ -160,8 +161,15 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, TenantDO, T
RoleDO roleDO = roleService.getByCode(SysConstants.TENANT_ADMIN_ROLE_CODE);
List<Long> oldMenuIds = roleMenuService.list(Wrappers.lambdaQuery(RoleMenuDO.class)
.eq(RoleMenuDO::getRoleId, roleDO.getId())).stream().map(RoleMenuDO::getMenuId).toList();
newMenuIds.removeAll(oldMenuIds);
roleMenuService.add(newMenuIds, roleDO.getId());
List<Long> addMenuIds = CollUtil.disjunction(newMenuIds, oldMenuIds).stream().toList();
if (CollUtil.isNotEmpty(addMenuIds)) {
List<RoleMenuDO> roleMenuDOList = new ArrayList<>();
for (Long addMenuId : addMenuIds) {
RoleMenuDO roleMenuDO = new RoleMenuDO(roleDO.getId(), addMenuId);
roleMenuDOList.add(roleMenuDO);
}
roleMenuService.saveBatch(roleMenuDOList, roleMenuDOList.size());
}
}));
//清理角色菜单缓存
RedisUtils.deleteByPattern(CacheConstants.ROLE_MENU_KEY_PREFIX + StringConstants.ASTERISK);

View File

@@ -20,6 +20,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.continew.admin.system.mapper.LogMapper;
import top.continew.admin.system.service.UserService;
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
import top.continew.starter.log.annotation.ConditionalOnEnabledLog;
import top.continew.starter.log.dao.LogDao;
import top.continew.starter.trace.autoconfigure.TraceProperties;
@@ -38,7 +39,10 @@ public class LogConfiguration {
* 日志持久层接口本地实现类
*/
@Bean
public LogDao logDao(UserService userService, LogMapper logMapper, TraceProperties traceProperties) {
return new LogDaoLocalImpl(userService, logMapper, traceProperties);
public LogDao logDao(UserService userService,
LogMapper logMapper,
TraceProperties traceProperties,
TenantProperties tenantProperties) {
return new LogDaoLocalImpl(userService, logMapper, traceProperties, tenantProperties);
}
}

View File

@@ -41,7 +41,7 @@ import top.continew.admin.system.service.UserService;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.ExceptionUtils;
import top.continew.starter.core.util.StrUtils;
import top.continew.starter.extension.tenant.context.TenantContextHolder;
import top.continew.starter.extension.tenant.autoconfigure.TenantProperties;
import top.continew.starter.extension.tenant.util.TenantUtils;
import top.continew.starter.log.dao.LogDao;
import top.continew.starter.log.model.LogRecord;
@@ -67,6 +67,7 @@ public class LogDaoLocalImpl implements LogDao {
private final UserService userService;
private final LogMapper logMapper;
private final TraceProperties traceProperties;
private final TenantProperties tenantProperties;
@Async
@Override
@@ -87,8 +88,12 @@ public class LogDaoLocalImpl implements LogDao {
logDO.setCreateTime(LocalDateTime.ofInstant(logRecord.getTimestamp(), ZoneId.systemDefault()));
// 设置操作人
this.setCreateUser(logDO, logRequest, logResponse);
Long tenantId = TenantContextHolder.getTenantId();
TenantUtils.execute(tenantId, () -> logMapper.insert(logDO));
String strTenantId = logRequest.getHeaders().get(tenantProperties.getTenantIdHeader());
if (StrUtil.isNotBlank(strTenantId)) {
TenantUtils.execute(Long.parseLong(strTenantId), () -> logMapper.insert(logDO));
} else {
logMapper.insert(logDO);
}
}
/**

View File

@@ -223,7 +223,7 @@ continew-starter.tenant:
- sys_sms_log # 短信日志表
- sys_client # 客户端表
- sys_app # 应用表
- sys_menu
- sys_menu # 菜单表
# 忽略菜单 ID租户不能使用的菜单
ignore-menus:
- 1130 # 字典管理
@@ -234,6 +234,7 @@ continew-starter.tenant:
- 7000 # 能力开放
- 8000 # 任务调度
- 9000 # 开发工具
- 1050 # 菜单管理
--- ### 限流器配置
continew-starter:

View File

@@ -17,10 +17,13 @@
package top.continew.admin.system.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RestController;
import top.continew.admin.common.constant.CacheConstants;
@@ -36,8 +39,10 @@ import top.continew.starter.core.util.validation.ValidationUtils;
import top.continew.starter.extension.crud.annotation.CrudApi;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.enums.Api;
import top.continew.starter.extension.crud.model.query.SortQuery;
import java.lang.reflect.Method;
import java.util.List;
/**
* 菜单管理 API
@@ -47,9 +52,12 @@ import java.lang.reflect.Method;
*/
@Tag(name = "菜单管理 API")
@RestController
@AllArgsConstructor
@CrudRequestMapping(value = "/system/menu", api = {Api.TREE, Api.GET, Api.CREATE, Api.UPDATE, Api.BATCH_DELETE})
public class MenuController extends BaseController<MenuService, MenuResp, MenuResp, MenuQuery, MenuReq> {
private final MenuService menuService;
@Operation(summary = "清除缓存", description = "清除缓存")
@SaCheckPermission("system:menu:clearCache")
@DeleteMapping("/cache")
@@ -77,4 +85,11 @@ public class MenuController extends BaseController<MenuService, MenuResp, MenuRe
req.setComponent(StrUtil.removePrefix(req.getComponent(), StringConstants.SLASH));
}
}
@Override
public List<Tree<Long>> tree(@Valid MenuQuery query, @Valid SortQuery sortQuery) {
query.setExcludeMenuIdList(menuService.listExcludeTenantMenu());
return super.tree(query, sortQuery);
}
}

View File

@@ -64,4 +64,9 @@ public interface MenuService extends BaseService<MenuResp, MenuResp, MenuQuery,
* @param parentMenu 父菜单
*/
void addTenantMenu(MenuDO menu, MenuDO parentMenu);
/**
* 查询租户排除的菜单
*/
List<Long> listExcludeTenantMenu();
}

View File

@@ -18,6 +18,7 @@ package top.continew.admin.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -163,6 +164,18 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuRes
RedisUtils.deleteByPattern(CacheConstants.ROLE_MENU_KEY_PREFIX + StringConstants.ASTERISK);
}
@Override
public List<Long> listExcludeTenantMenu() {
RoleDO role = roleMapper.selectOne(Wrappers.lambdaQuery(RoleDO.class)
.eq(RoleDO::getCode, SysConstants.TENANT_ADMIN_ROLE_CODE));
if (role == null) {
return ListUtil.of();
}
List<Long> allMenuList = list().stream().map(MenuDO::getId).toList();
List<Long> menuList = baseMapper.selectListByRoleId(role.getId()).stream().map(MenuDO::getId).toList();
return CollUtil.disjunction(allMenuList, menuList).stream().toList();
}
/**
* 检查标题是否重复
*