From e6edb57a8cf991be9408df2dfaf50271d3e0b638 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 22 Jul 2025 23:42:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=A2=9E=E5=8A=A0=E5=AF=B9=E5=A4=9A=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../continew/admin/config/log/LogDaoLocalImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/continew-server/src/main/java/top/continew/admin/config/log/LogDaoLocalImpl.java b/continew-server/src/main/java/top/continew/admin/config/log/LogDaoLocalImpl.java index 46e05140..ed2112e7 100644 --- a/continew-server/src/main/java/top/continew/admin/config/log/LogDaoLocalImpl.java +++ b/continew-server/src/main/java/top/continew/admin/config/log/LogDaoLocalImpl.java @@ -23,6 +23,7 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.hutool.http.HttpStatus; import cn.hutool.json.JSONUtil; import lombok.RequiredArgsConstructor; @@ -41,6 +42,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; @@ -88,7 +90,15 @@ public class LogDaoLocalImpl implements LogDao { // 设置操作人 this.setCreateUser(logDO, logRequest, logResponse); // 保存记录 - TenantUtils.execute(TenantContextHolder.getTenantId(), () -> logMapper.insert(logDO)); + if (TenantContextHolder.isTenantEnabled()) { + // 异步无法获取租户 ID + String tenantId = logRequest.getHeaders().get(SpringUtil.getBean(TenantProperties.class).getTenantIdHeader()); + if (StrUtil.isNotBlank(tenantId)) { + TenantUtils.execute(Long.parseLong(tenantId), () -> logMapper.insert(logDO)); + return; + } + } + logMapper.insert(logDO); } /**