|
@@ -1,10 +1,15 @@
|
|
|
package org.jeecg.modules.system.aspect;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
@@ -130,7 +135,9 @@ public class AutoLogAspect {
|
|
|
}
|
|
|
return CommonConstant.OPERATE_TYPE_1;
|
|
|
}
|
|
|
-
|
|
|
+ public static <T> Stream<T> streamOf(T[] array) {
|
|
|
+ return ArrayUtils.isEmpty(array) ? Stream.empty() : Arrays.asList(array).stream();
|
|
|
+ }
|
|
|
/**
|
|
|
* @Description: 获取请求参数
|
|
|
* @author: scott
|
|
@@ -144,18 +151,24 @@ public class AutoLogAspect {
|
|
|
String params = "";
|
|
|
if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) || "PATCH".equals(httpMethod)) {
|
|
|
Object[] paramsArray = joinPoint.getArgs();
|
|
|
- params = JSONObject.toJSONString(paramsArray);
|
|
|
+ List<Object> logArgs = AutoLogAspect.streamOf(paramsArray)
|
|
|
+ .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ params = JSONObject.toJSONString(logArgs);
|
|
|
} else {
|
|
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
Method method = signature.getMethod();
|
|
|
// 请求的方法参数值
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
+ List<Object> logArgs = AutoLogAspect.streamOf(args)
|
|
|
+ .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
// 请求的方法参数名称
|
|
|
LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer();
|
|
|
String[] paramNames = u.getParameterNames(method);
|
|
|
if (args != null && paramNames != null) {
|
|
|
- for (int i = 0; i < args.length; i++) {
|
|
|
- params += " " + paramNames[i] + ": " + args[i];
|
|
|
+ for (int i = 0; i < logArgs.size(); i++) {
|
|
|
+ params += " " + paramNames[i] + ": " + logArgs.get(i);
|
|
|
}
|
|
|
}
|
|
|
}
|