From a874b928e16320839315b9abcdf2cece1229a424 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 07 十一月 2024 09:20:38 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-infra/iailab-module-infra-biz/src/main/java/com/iailab/module/infra/service/logger/ApiAccessLogServiceImpl.java |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/iailab-module-infra/iailab-module-infra-biz/src/main/java/com/iailab/module/infra/service/logger/ApiAccessLogServiceImpl.java b/iailab-module-infra/iailab-module-infra-biz/src/main/java/com/iailab/module/infra/service/logger/ApiAccessLogServiceImpl.java
index 513c84d..6fd58ff 100644
--- a/iailab-module-infra/iailab-module-infra-biz/src/main/java/com/iailab/module/infra/service/logger/ApiAccessLogServiceImpl.java
+++ b/iailab-module-infra/iailab-module-infra-biz/src/main/java/com/iailab/module/infra/service/logger/ApiAccessLogServiceImpl.java
@@ -3,6 +3,8 @@
 import cn.hutool.core.util.StrUtil;
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.util.object.BeanUtils;
+import com.iailab.framework.tenant.core.context.TenantContextHolder;
+import com.iailab.framework.tenant.core.util.TenantUtils;
 import com.iailab.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
 import com.iailab.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
 import com.iailab.module.infra.dal.dataobject.logger.ApiAccessLogDO;
@@ -35,7 +37,12 @@
         ApiAccessLogDO apiAccessLog = BeanUtils.toBean(createDTO, ApiAccessLogDO.class);
         apiAccessLog.setRequestParams(StrUtil.maxLength(apiAccessLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
         apiAccessLog.setResultMsg(StrUtil.maxLength(apiAccessLog.getResultMsg(), RESULT_MSG_MAX_LENGTH));
-        apiAccessLogMapper.insert(apiAccessLog);
+        if (TenantContextHolder.getTenantId() != null) {
+            apiAccessLogMapper.insert(apiAccessLog);
+        } else {
+            // 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败!
+            TenantUtils.executeIgnore(() -> apiAccessLogMapper.insert(apiAccessLog));
+        }
     }
 
     @Override

--
Gitblit v1.9.3