Browse Source

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

RuoYi 4 years ago
parent
commit
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
     public boolean isSaveRequestData() default true;
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
             String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
91
             String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
92
             operLog.setOperIp(ip);
92
             operLog.setOperIp(ip);
93
-            // 返回参数
94
-            operLog.setJsonResult(JSON.toJSONString(jsonResult));
95
-
96
             operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
93
             operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
97
             String username = SecurityUtils.getUsername();
94
             String username = SecurityUtils.getUsername();
98
             if (StringUtils.isNotBlank(username))
95
             if (StringUtils.isNotBlank(username))
@@ -112,7 +109,7 @@ public class LogAspect
112
             // 设置请求方式
109
             // 设置请求方式
113
             operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
110
             operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
114
             // 处理设置注解上的参数
111
             // 处理设置注解上的参数
115
-            getControllerMethodDescription(joinPoint, controllerLog, operLog);
112
+            getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
116
             // 保存数据库
113
             // 保存数据库
117
             asyncLogService.saveSysLog(operLog);
114
             asyncLogService.saveSysLog(operLog);
118
         }
115
         }
@@ -132,7 +129,7 @@ public class LogAspect
132
      * @param operLog 操作日志
129
      * @param operLog 操作日志
133
      * @throws Exception
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
         // 设置action动作
134
         // 设置action动作
138
         operLog.setBusinessType(log.businessType().ordinal());
135
         operLog.setBusinessType(log.businessType().ordinal());
@@ -146,6 +143,11 @@ public class LogAspect
146
             // 获取参数的信息,传入到数据库中。
143
             // 获取参数的信息,传入到数据库中。
147
             setRequestValue(joinPoint, operLog);
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
     /**