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); } /**