From ac9e3f2ca4d2255739f8b60165f5b51b31ccd3e6 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期五, 13 一月 2023 23:04:08 +0800
Subject: [PATCH] update 适配 springdoc 新版本配置方式

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java |   42 +++++++++++++++++++++++++++---------------
 1 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
index 49828ef..64ab736 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
@@ -1,8 +1,10 @@
 package com.ruoyi.framework.aspectj;
 
+import cn.hutool.core.lang.Dict;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.ruoyi.common.annotation.Log;
-import com.ruoyi.common.core.domain.dto.OperLogDTO;
-import com.ruoyi.common.core.service.OperLogService;
+import com.ruoyi.common.core.domain.event.OperLogEvent;
 import com.ruoyi.common.enums.BusinessStatus;
 import com.ruoyi.common.enums.HttpMethod;
 import com.ruoyi.common.helper.LoginHelper;
@@ -18,7 +20,6 @@
 import org.springframework.stereotype.Component;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.servlet.HandlerMapping;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -34,6 +35,11 @@
 @Aspect
 @Component
 public class LogAspect {
+
+    /**
+     * 鎺掗櫎鏁忔劅灞炴�у瓧娈�
+     */
+    public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
 
     /**
      * 澶勭悊瀹岃姹傚悗鎵ц
@@ -60,12 +66,12 @@
         try {
 
             // *========鏁版嵁搴撴棩蹇�=========*//
-            OperLogDTO operLog = new OperLogDTO();
+            OperLogEvent operLog = new OperLogEvent();
             operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
             // 璇锋眰鐨勫湴鍧�
             String ip = ServletUtils.getClientIP();
             operLog.setOperIp(ip);
-            operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
+            operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
             operLog.setOperName(LoginHelper.getUsername());
 
             if (e != null) {
@@ -80,11 +86,10 @@
             operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
             // 澶勭悊璁剧疆娉ㄨВ涓婄殑鍙傛暟
             getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
-            // 淇濆瓨鏁版嵁搴�
-            SpringUtils.getBean(OperLogService.class).recordOper(operLog);
+            // 鍙戝竷浜嬩欢淇濆瓨鏁版嵁搴�
+            SpringUtils.context().publishEvent(operLog);
         } catch (Exception exp) {
             // 璁板綍鏈湴寮傚父鏃ュ織
-            log.error("==鍓嶇疆閫氱煡寮傚父==");
             log.error("寮傚父淇℃伅:{}", exp.getMessage());
             exp.printStackTrace();
         }
@@ -97,7 +102,7 @@
      * @param operLog 鎿嶄綔鏃ュ織
      * @throws Exception
      */
-    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLogDTO operLog, Object jsonResult) throws Exception {
+    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLogEvent operLog, Object jsonResult) throws Exception {
         // 璁剧疆action鍔ㄤ綔
         operLog.setBusinessType(log.businessType().ordinal());
         // 璁剧疆鏍囬
@@ -110,7 +115,7 @@
             setRequestValue(joinPoint, operLog);
         }
         // 鏄惁闇�瑕佷繚瀛榬esponse锛屽弬鏁板拰鍊�
-        if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) {
+        if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) {
             operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 2000));
         }
     }
@@ -121,14 +126,15 @@
      * @param operLog 鎿嶄綔鏃ュ織
      * @throws Exception 寮傚父
      */
-    private void setRequestValue(JoinPoint joinPoint, OperLogDTO operLog) throws Exception {
+    private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog) throws Exception {
         String requestMethod = operLog.getRequestMethod();
         if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
             String params = argsArrayToString(joinPoint.getArgs());
             operLog.setOperParam(StringUtils.substring(params, 0, 2000));
         } else {
-            Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
-            operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000));
+            Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
+            MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
+            operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000));
         }
     }
 
@@ -139,9 +145,15 @@
         StringBuilder params = new StringBuilder();
         if (paramsArray != null && paramsArray.length > 0) {
             for (Object o : paramsArray) {
-                if (StringUtils.isNotNull(o) && !isFilterObject(o)) {
+                if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
                     try {
-                        params.append(JsonUtils.toJsonString(o)).append(" ");
+                        String str = JsonUtils.toJsonString(o);
+                        Dict dict = JsonUtils.parseMap(str);
+                        if (MapUtil.isNotEmpty(dict)) {
+                            MapUtil.removeAny(dict, EXCLUDE_PROPERTIES);
+                            str = JsonUtils.toJsonString(dict);
+                        }
+                        params.append(str).append(" ");
                     } catch (Exception e) {
                         e.printStackTrace();
                     }

--
Gitblit v1.9.3