refactor(tenant): 优化及修复租户相关部分代码

- 移动 TenantExtensionProperties 到 common 模块
- 修复 MenuController#tree 接口 setExcludeMenuIdList 方法判断非默认租户条件缺失
- 修复更新租户套餐菜单,没有及时更新在线用户数据权限(后面考虑重构 satoken 权限数据读取部分)
- TenantService 接口 getByDomain => getIdByDomain、getByCode => getIdByCode
- 移除 MenuService 中已废弃的方法
- LogDaoLocalImpl 还原(未测出租户用户操作,无租户 ID 问题)
- 优化 pg 数据库脚本,移除菜单表的租户相关字段
- 其他代码优化
This commit is contained in:
2025-07-20 23:13:07 +08:00
parent ada6f3ef5c
commit 84b2c39a30
24 changed files with 164 additions and 233 deletions

View File

@@ -20,7 +20,6 @@ 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;
@@ -39,10 +38,7 @@ public class LogConfiguration {
* 日志持久层接口本地实现类
*/
@Bean
public LogDao logDao(UserService userService,
LogMapper logMapper,
TraceProperties traceProperties,
TenantProperties tenantProperties) {
return new LogDaoLocalImpl(userService, logMapper, traceProperties, tenantProperties);
public LogDao logDao(UserService userService, LogMapper logMapper, TraceProperties traceProperties) {
return new LogDaoLocalImpl(userService, logMapper, traceProperties);
}
}

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

View File

@@ -215,6 +215,7 @@ continew-starter.tenant:
- tenant_package_menu # 租户套餐与菜单关联表
- gen_config # 代码生成配置表
- gen_field_config # 代码生成字段配置表
- sys_menu # 菜单表
- sys_dict # 字典表
- sys_dict_item # 字典项表
- sys_option # 参数表
@@ -223,9 +224,9 @@ continew-starter.tenant:
- sys_sms_log # 短信日志表
- sys_client # 客户端表
- sys_app # 应用表
- sys_menu # 菜单表
# 忽略菜单 ID租户不能使用的菜单
ignore-menus:
- 1050 # 菜单管理
- 1130 # 字典管理
- 1140 # 字典项管理
- 1150 # 系统配置
@@ -234,7 +235,6 @@ continew-starter.tenant:
- 7000 # 能力开放
- 8000 # 任务调度
- 9000 # 开发工具
- 1050 # 菜单管理
--- ### 限流器配置
continew-starter:

View File

@@ -76,10 +76,6 @@ COMMENT ON COLUMN "tenant_package_menu"."menu_id" IS '菜单ID';
COMMENT ON TABLE "tenant_package_menu" IS '租户套餐和菜单关联表';
-- 为已有表增加租户字段
ALTER TABLE "sys_menu" ADD COLUMN "tenant_id" int8 NOT NULL DEFAULT 0;
COMMENT ON COLUMN "sys_menu"."tenant_id" IS '租户ID';
CREATE INDEX "idx_menu_tenant_id" ON "sys_menu" ("tenant_id");
ALTER TABLE "sys_dept" ADD COLUMN "tenant_id" int8 NOT NULL DEFAULT 0;
COMMENT ON COLUMN "sys_dept"."tenant_id" IS '租户ID';
CREATE INDEX "idx_dept_tenant_id" ON "sys_dept" ("tenant_id");
@@ -141,9 +137,6 @@ COMMENT ON COLUMN "sys_app"."tenant_id" IS '租户ID';
CREATE INDEX "idx_app_tenant_id" ON "sys_app" ("tenant_id");
-- 调整唯一索引
ALTER TABLE "sys_menu" DROP INDEX "uk_menu_title_parent_id";
CREATE UNIQUE INDEX "uk_menu_title_parent_id" ON "sys_menu" ("title", "parent_id", "tenant_id");
ALTER TABLE "sys_dept" DROP INDEX "uk_dept_name_parent_id";
CREATE UNIQUE INDEX "uk_dept_name_parent_id" ON "sys_dept" ("name", "parent_id", "tenant_id");