Переглянути джерело

日志注解新增是否保存响应参数

RuoYi 4 роки тому
батько
коміт
ab8215d1ce

+ 5 - 0
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/annotation/Log.java

@@ -38,4 +38,9 @@ public @interface Log
38 38
      * 是否保存请求的参数
39 39
      */
40 40
     public boolean isSaveRequestData() default true;
41
+
42
+    /**
43
+     * 是否保存响应的参数
44
+     */
45
+    public boolean isSaveResponseData() default true;
41 46
 }

+ 7 - 5
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java

@@ -90,9 +90,6 @@ public class LogAspect
90 90
             // 请求的地址
91 91
             String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
92 92
             operLog.setOperIp(ip);
93
-            // 返回参数
94
-            operLog.setJsonResult(JSON.toJSONString(jsonResult));
95
-
96 93
             operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
97 94
             String username = SecurityUtils.getUsername();
98 95
             if (StringUtils.isNotBlank(username))
@@ -112,7 +109,7 @@ public class LogAspect
112 109
             // 设置请求方式
113 110
             operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
114 111
             // 处理设置注解上的参数
115
-            getControllerMethodDescription(joinPoint, controllerLog, operLog);
112
+            getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
116 113
             // 保存数据库
117 114
             asyncLogService.saveSysLog(operLog);
118 115
         }
@@ -132,7 +129,7 @@ public class LogAspect
132 129
      * @param operLog 操作日志
133 130
      * @throws Exception
134 131
      */
135
-    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog) throws Exception
132
+    public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception
136 133
     {
137 134
         // 设置action动作
138 135
         operLog.setBusinessType(log.businessType().ordinal());
@@ -146,6 +143,11 @@ public class LogAspect
146 143
             // 获取参数的信息,传入到数据库中。
147 144
             setRequestValue(joinPoint, operLog);
148 145
         }
146
+        // 是否需要保存response,参数和值
147
+        if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
148
+        {
149
+            operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
150
+        }
149 151
     }
150 152
 
151 153
     /**