From d24e551894e04a557adbcfffddd5cf0966f38e2f Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期六, 18 九月 2021 18:49:41 +0800
Subject: [PATCH] 修复 全局限流key会多出一个"-" 将其移动到IP后面 去除多余的空格

---
 src/main/java/com/ruoyi/framework/aspectj/LogAspect.java |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
index 873004b..cc66490 100644
--- a/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
+++ b/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
@@ -21,16 +21,15 @@
 import org.springframework.web.servlet.HandlerMapping;
 import com.alibaba.fastjson.JSON;
 import com.ruoyi.common.enums.HttpMethod;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.ip.IpUtils;
-import com.ruoyi.common.utils.spring.SpringUtils;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessStatus;
 import com.ruoyi.framework.manager.AsyncManager;
 import com.ruoyi.framework.manager.factory.AsyncFactory;
 import com.ruoyi.framework.security.LoginUser;
-import com.ruoyi.framework.security.service.TokenService;
 import com.ruoyi.project.monitor.domain.SysOperLog;
 
 /**
@@ -85,7 +84,7 @@
             }
 
             // 鑾峰彇褰撳墠鐨勭敤鎴�
-            LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
+            LoginUser loginUser = SecurityUtils.getLoginUser();
 
             // *========鏁版嵁搴撴棩蹇�=========*//
             SysOperLog operLog = new SysOperLog();
@@ -93,9 +92,6 @@
             // 璇锋眰鐨勫湴鍧�
             String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
             operLog.setOperIp(ip);
-            // 杩斿洖鍙傛暟
-            operLog.setJsonResult(JSON.toJSONString(jsonResult));
-
             operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
             if (loginUser != null)
             {
@@ -114,7 +110,7 @@
             // 璁剧疆璇锋眰鏂瑰紡
             operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
             // 澶勭悊璁剧疆娉ㄨВ涓婄殑鍙傛暟
-            getControllerMethodDescription(joinPoint, controllerLog, operLog);
+            getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
             // 淇濆瓨鏁版嵁搴�
             AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
         }
@@ -134,7 +130,7 @@
      * @param operLog 鎿嶄綔鏃ュ織
      * @throws Exception
      */
-    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog) throws Exception
+    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception
     {
         // 璁剧疆action鍔ㄤ綔
         operLog.setBusinessType(log.businessType().ordinal());
@@ -147,6 +143,11 @@
         {
             // 鑾峰彇鍙傛暟鐨勪俊鎭紝浼犲叆鍒版暟鎹簱涓��
             setRequestValue(joinPoint, operLog);
+        }
+        // 鏄惁闇�瑕佷繚瀛榬esponse锛屽弬鏁板拰鍊�
+        if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
+        {
+            operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
         }
     }
 
@@ -197,7 +198,7 @@
         {
             for (int i = 0; i < paramsArray.length; i++)
             {
-                if (!isFilterObject(paramsArray[i]))
+                if (StringUtils.isNotNull(paramsArray[i]) && !isFilterObject(paramsArray[i]))
                 {
                     Object jsonObj = JSON.toJSON(paramsArray[i]);
                     params += jsonObj.toString() + " ";

--
Gitblit v1.9.3