From 1a403361c951b91f6e3a33da1d8c0ee77e07bb86 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期四, 19 十二月 2024 09:19:12 +0800
Subject: [PATCH] update 优化 关闭sse后 使用工具报错
---
ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/aspect/LogAspect.java | 42 ++++++++++++++++++++----------------------
1 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/aspect/LogAspect.java b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/aspect/LogAspect.java
index 5e6af11..71b3790 100644
--- a/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/aspect/LogAspect.java
+++ b/ruoyi-common/ruoyi-common-log/src/main/java/org/dromara/common/log/aspect/LogAspect.java
@@ -4,16 +4,6 @@
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
-import org.dromara.common.core.context.ThreadLocalHolder;
-import org.dromara.common.core.domain.model.LoginUser;
-import org.dromara.common.core.utils.ServletUtils;
-import org.dromara.common.core.utils.SpringUtils;
-import org.dromara.common.core.utils.StringUtils;
-import org.dromara.common.json.utils.JsonUtils;
-import org.dromara.common.log.annotation.Log;
-import org.dromara.common.log.enums.BusinessStatus;
-import org.dromara.common.log.event.OperLogEvent;
-import org.dromara.common.satoken.utils.LoginHelper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
@@ -23,6 +13,15 @@
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
+import org.dromara.common.core.domain.model.LoginUser;
+import org.dromara.common.core.utils.ServletUtils;
+import org.dromara.common.core.utils.SpringUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.json.utils.JsonUtils;
+import org.dromara.common.log.annotation.Log;
+import org.dromara.common.log.enums.BusinessStatus;
+import org.dromara.common.log.event.OperLogEvent;
+import org.dromara.common.satoken.utils.LoginHelper;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.http.HttpMethod;
import org.springframework.validation.BindingResult;
@@ -51,15 +50,15 @@
/**
* 璁℃椂 key
*/
- private static final String LOG_STOP_WATCH_KEY = "logStopwatch";
+ private static final ThreadLocal<StopWatch> KEY_CACHE = new ThreadLocal<>();
/**
* 澶勭悊璇锋眰鍓嶆墽琛�
*/
@Before(value = "@annotation(controllerLog)")
- public void boBefore(JoinPoint joinPoint, Log controllerLog) {
+ public void doBefore(JoinPoint joinPoint, Log controllerLog) {
StopWatch stopWatch = new StopWatch();
- ThreadLocalHolder.set(LOG_STOP_WATCH_KEY, stopWatch);
+ KEY_CACHE.set(stopWatch);
stopWatch.start();
}
@@ -101,7 +100,7 @@
if (e != null) {
operLog.setStatus(BusinessStatus.FAIL.ordinal());
- operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
+ operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 3800));
}
// 璁剧疆鏂规硶鍚嶇О
String className = joinPoint.getTarget().getClass().getName();
@@ -112,7 +111,7 @@
// 澶勭悊璁剧疆娉ㄨВ涓婄殑鍙傛暟
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
// 璁剧疆娑堣�楁椂闂�
- StopWatch stopWatch = ThreadLocalHolder.get(LOG_STOP_WATCH_KEY);
+ StopWatch stopWatch = KEY_CACHE.get();
stopWatch.stop();
operLog.setCostTime(stopWatch.getTime());
// 鍙戝竷浜嬩欢淇濆瓨鏁版嵁搴�
@@ -122,7 +121,7 @@
log.error("寮傚父淇℃伅:{}", exp.getMessage());
exp.printStackTrace();
} finally {
- ThreadLocalHolder.remove(LOG_STOP_WATCH_KEY);
+ KEY_CACHE.remove();
}
}
@@ -147,7 +146,7 @@
}
// 鏄惁闇�瑕佷繚瀛榬esponse锛屽弬鏁板拰鍊�
if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) {
- operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 2000));
+ operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 3800));
}
}
@@ -160,14 +159,13 @@
private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog, String[] excludeParamNames) throws Exception {
Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
String requestMethod = operLog.getRequestMethod();
- if (MapUtil.isEmpty(paramsMap)
- && HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
+ if (MapUtil.isEmpty(paramsMap) && StringUtils.equalsAny(requestMethod, HttpMethod.PUT.name(), HttpMethod.POST.name(), HttpMethod.DELETE.name())) {
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
- operLog.setOperParam(StringUtils.substring(params, 0, 2000));
+ operLog.setOperParam(StringUtils.substring(params, 0, 3800));
} else {
MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
MapUtil.removeAny(paramsMap, excludeParamNames);
- operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000));
+ operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 3800));
}
}
@@ -204,7 +202,7 @@
public boolean isFilterObject(final Object o) {
Class<?> clazz = o.getClass();
if (clazz.isArray()) {
- return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
+ return MultipartFile.class.isAssignableFrom(clazz.getComponentType());
} else if (Collection.class.isAssignableFrom(clazz)) {
Collection collection = (Collection) o;
for (Object value : collection) {
--
Gitblit v1.9.3