|
|
@@ -1,18 +1,13 @@
|
|
1
|
1
|
package com.ruoyi.common.log.aspect;
|
|
2
|
2
|
|
|
3
|
|
-import java.lang.reflect.Method;
|
|
4
|
3
|
import java.util.Collection;
|
|
5
|
|
-import java.util.Iterator;
|
|
6
|
4
|
import java.util.Map;
|
|
7
|
5
|
import javax.servlet.http.HttpServletRequest;
|
|
8
|
6
|
import javax.servlet.http.HttpServletResponse;
|
|
9
|
7
|
import org.aspectj.lang.JoinPoint;
|
|
10
|
|
-import org.aspectj.lang.Signature;
|
|
11
|
8
|
import org.aspectj.lang.annotation.AfterReturning;
|
|
12
|
9
|
import org.aspectj.lang.annotation.AfterThrowing;
|
|
13
|
10
|
import org.aspectj.lang.annotation.Aspect;
|
|
14
|
|
-import org.aspectj.lang.annotation.Pointcut;
|
|
15
|
|
-import org.aspectj.lang.reflect.MethodSignature;
|
|
16
|
11
|
import org.slf4j.Logger;
|
|
17
|
12
|
import org.slf4j.LoggerFactory;
|
|
18
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -44,21 +39,15 @@ public class LogAspect
|
|
44
|
39
|
@Autowired
|
|
45
|
40
|
private AsyncLogService asyncLogService;
|
|
46
|
41
|
|
|
47
|
|
- // 配置织入点
|
|
48
|
|
- @Pointcut("@annotation(com.ruoyi.common.log.annotation.Log)")
|
|
49
|
|
- public void logPointCut()
|
|
50
|
|
- {
|
|
51
|
|
- }
|
|
52
|
|
-
|
|
53
|
42
|
/**
|
|
54
|
43
|
* 处理完请求后执行
|
|
55
|
44
|
*
|
|
56
|
45
|
* @param joinPoint 切点
|
|
57
|
46
|
*/
|
|
58
|
|
- @AfterReturning(pointcut = "logPointCut()", returning = "jsonResult")
|
|
59
|
|
- public void doAfterReturning(JoinPoint joinPoint, Object jsonResult)
|
|
|
47
|
+ @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult")
|
|
|
48
|
+ public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult)
|
|
60
|
49
|
{
|
|
61
|
|
- handleLog(joinPoint, null, jsonResult);
|
|
|
50
|
+ handleLog(joinPoint, controllerLog, null, jsonResult);
|
|
62
|
51
|
}
|
|
63
|
52
|
|
|
64
|
53
|
/**
|
|
|
@@ -67,23 +56,16 @@ public class LogAspect
|
|
67
|
56
|
* @param joinPoint 切点
|
|
68
|
57
|
* @param e 异常
|
|
69
|
58
|
*/
|
|
70
|
|
- @AfterThrowing(value = "logPointCut()", throwing = "e")
|
|
71
|
|
- public void doAfterThrowing(JoinPoint joinPoint, Exception e)
|
|
|
59
|
+ @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e")
|
|
|
60
|
+ public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e)
|
|
72
|
61
|
{
|
|
73
|
|
- handleLog(joinPoint, e, null);
|
|
|
62
|
+ handleLog(joinPoint, controllerLog, e, null);
|
|
74
|
63
|
}
|
|
75
|
64
|
|
|
76
|
|
- protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult)
|
|
|
65
|
+ protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult)
|
|
77
|
66
|
{
|
|
78
|
67
|
try
|
|
79
|
68
|
{
|
|
80
|
|
- // 获得注解
|
|
81
|
|
- Log controllerLog = getAnnotationLog(joinPoint);
|
|
82
|
|
- if (controllerLog == null)
|
|
83
|
|
- {
|
|
84
|
|
- return;
|
|
85
|
|
- }
|
|
86
|
|
-
|
|
87
|
69
|
// *========数据库日志=========*//
|
|
88
|
70
|
SysOperLog operLog = new SysOperLog();
|
|
89
|
71
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
|
@@ -164,22 +146,11 @@ public class LogAspect
|
|
164
|
146
|
String params = argsArrayToString(joinPoint.getArgs());
|
|
165
|
147
|
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
|
166
|
148
|
}
|
|
167
|
|
- }
|
|
168
|
|
-
|
|
169
|
|
- /**
|
|
170
|
|
- * 是否存在注解,如果存在就获取
|
|
171
|
|
- */
|
|
172
|
|
- private Log getAnnotationLog(JoinPoint joinPoint) throws Exception
|
|
173
|
|
- {
|
|
174
|
|
- Signature signature = joinPoint.getSignature();
|
|
175
|
|
- MethodSignature methodSignature = (MethodSignature) signature;
|
|
176
|
|
- Method method = methodSignature.getMethod();
|
|
177
|
|
-
|
|
178
|
|
- if (method != null)
|
|
|
149
|
+ else
|
|
179
|
150
|
{
|
|
180
|
|
- return method.getAnnotation(Log.class);
|
|
|
151
|
+ Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
|
|
152
|
+ operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000));
|
|
181
|
153
|
}
|
|
182
|
|
- return null;
|
|
183
|
154
|
}
|
|
184
|
155
|
|
|
185
|
156
|
/**
|
|
|
@@ -190,13 +161,13 @@ public class LogAspect
|
|
190
|
161
|
String params = "";
|
|
191
|
162
|
if (paramsArray != null && paramsArray.length > 0)
|
|
192
|
163
|
{
|
|
193
|
|
- for (int i = 0; i < paramsArray.length; i++)
|
|
|
164
|
+ for (Object o : paramsArray)
|
|
194
|
165
|
{
|
|
195
|
|
- if (StringUtils.isNotNull(paramsArray[i]) && !isFilterObject(paramsArray[i]))
|
|
|
166
|
+ if (StringUtils.isNotNull(o) && !isFilterObject(o))
|
|
196
|
167
|
{
|
|
197
|
168
|
try
|
|
198
|
169
|
{
|
|
199
|
|
- Object jsonObj = JSON.toJSON(paramsArray[i]);
|
|
|
170
|
+ Object jsonObj = JSON.toJSON(o);
|
|
200
|
171
|
params += jsonObj.toString() + " ";
|
|
201
|
172
|
}
|
|
202
|
173
|
catch (Exception e)
|
|
|
@@ -225,17 +196,17 @@ public class LogAspect
|
|
225
|
196
|
else if (Collection.class.isAssignableFrom(clazz))
|
|
226
|
197
|
{
|
|
227
|
198
|
Collection collection = (Collection) o;
|
|
228
|
|
- for (Iterator iter = collection.iterator(); iter.hasNext();)
|
|
|
199
|
+ for (Object value : collection)
|
|
229
|
200
|
{
|
|
230
|
|
- return iter.next() instanceof MultipartFile;
|
|
|
201
|
+ return value instanceof MultipartFile;
|
|
231
|
202
|
}
|
|
232
|
203
|
}
|
|
233
|
204
|
else if (Map.class.isAssignableFrom(clazz))
|
|
234
|
205
|
{
|
|
235
|
206
|
Map map = (Map) o;
|
|
236
|
|
- for (Iterator iter = map.entrySet().iterator(); iter.hasNext();)
|
|
|
207
|
+ for (Object value : map.entrySet())
|
|
237
|
208
|
{
|
|
238
|
|
- Map.Entry entry = (Map.Entry) iter.next();
|
|
|
209
|
+ Map.Entry entry = (Map.Entry) value;
|
|
239
|
210
|
return entry.getValue() instanceof MultipartFile;
|
|
240
|
211
|
}
|
|
241
|
212
|
}
|