|
@@ -1,74 +0,0 @@
|
|
|
-package com.ym.mec.biz.dal.aspects;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
-import com.ym.mec.auth.api.entity.SysUser;
|
|
|
-import com.ym.mec.common.exception.BizException;
|
|
|
-import org.aspectj.lang.JoinPoint;
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.aspectj.lang.annotation.Before;
|
|
|
-import org.aspectj.lang.annotation.Pointcut;
|
|
|
-import org.aspectj.lang.reflect.MethodSignature;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.ServletRequest;
|
|
|
-import javax.servlet.ServletResponse;
|
|
|
-import java.lang.reflect.Method;
|
|
|
-
|
|
|
-@Aspect
|
|
|
-@Component
|
|
|
-public class UserLog {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SysUserFeignService sysUserFeignService;
|
|
|
-
|
|
|
- @Pointcut("@annotation(com.ym.mec.biz.dal.aspects.UserLogAnnotation)")
|
|
|
- public void userLogPoint(){
|
|
|
- }
|
|
|
-
|
|
|
- @Before("userLogPoint()")
|
|
|
- public void saveUserLog(JoinPoint joinPoint){
|
|
|
- //从切面织入点处通过反射机制获取织入点处的方法
|
|
|
- MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
|
|
- //获取切入点所在的方法
|
|
|
- Method method = signature.getMethod();
|
|
|
- UserLogAnnotation logAnnotation = method.getAnnotation(UserLogAnnotation.class);
|
|
|
- String operationType = "";
|
|
|
- String describe = "";
|
|
|
- if(logAnnotation != null){
|
|
|
- describe = logAnnotation.describe();
|
|
|
- operationType = logAnnotation.operationType();
|
|
|
- }
|
|
|
- //获取请求的类名
|
|
|
- String className = joinPoint.getTarget().getClass().getName();
|
|
|
- //获取请求的方法名
|
|
|
- String methodName = method.getName();
|
|
|
- //请求的参数
|
|
|
- Object[] args = joinPoint.getArgs();
|
|
|
- Object[] arguments = new Object[args.length];
|
|
|
- for (int i = 0; i < args.length; i++) {
|
|
|
- if (args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof MultipartFile) {
|
|
|
- //ServletRequest不能序列化,从入参里排除,否则报异常:java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
|
|
|
- //ServletResponse不能序列化 从入参里排除,否则报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
|
|
|
- continue;
|
|
|
- }
|
|
|
- arguments[i] = args[i];
|
|
|
- }
|
|
|
- //将参数所在的数组转换成json
|
|
|
- String params = "";
|
|
|
- if (arguments != null) {
|
|
|
- try {
|
|
|
- params = JSONObject.toJSONString(arguments);
|
|
|
- } catch (Exception e) {
|
|
|
- params = arguments.toString();
|
|
|
- }
|
|
|
- }
|
|
|
- SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- if(sysUser == null){
|
|
|
- throw new BizException("获取用户信息失败");
|
|
|
- }
|
|
|
- System.out.println("记录用户操作日志: {}" + params);
|
|
|
- }
|
|
|
-}
|