|
@@ -1,7 +1,11 @@
|
|
package com.jpsoft.smart.advice;
|
|
package com.jpsoft.smart.advice;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.smart.modules.common.utils.HttpUtil;
|
|
|
|
+import com.jpsoft.smart.modules.sys.entity.SysLog;
|
|
import com.jpsoft.smart.modules.sys.service.PermissionService;
|
|
import com.jpsoft.smart.modules.sys.service.PermissionService;
|
|
|
|
+import com.jpsoft.smart.modules.sys.service.SysLogService;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
@@ -14,15 +18,18 @@ import org.springframework.stereotype.Component;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
-
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
|
|
+import java.util.Date;
|
|
|
|
|
|
@Aspect
|
|
@Aspect
|
|
@Component
|
|
@Component
|
|
public class PermissionAdvice {
|
|
public class PermissionAdvice {
|
|
private Logger logger= LoggerFactory.getLogger("root");
|
|
private Logger logger= LoggerFactory.getLogger("root");
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysLogService sysLogService;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private PermissionService permissionService;
|
|
private PermissionService permissionService;
|
|
|
|
|
|
@@ -72,13 +79,42 @@ public class PermissionAdvice {
|
|
ServletRequestAttributes requestAttrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
ServletRequestAttributes requestAttrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
|
|
|
|
Object obj = null;
|
|
Object obj = null;
|
|
|
|
+ SysLog sysLog = new SysLog();
|
|
|
|
|
|
if(requestAttrs!=null) {
|
|
if(requestAttrs!=null) {
|
|
HttpServletRequest request = requestAttrs.getRequest();
|
|
HttpServletRequest request = requestAttrs.getRequest();
|
|
- logger.warn("访问地址:" + request.getRequestURL().toString());
|
|
|
|
|
|
|
|
|
|
+ sysLog.setRemoteIp(HttpUtil.getIpAddress(request));
|
|
|
|
+ sysLog.setUrl(request.getRequestURI());
|
|
|
|
+
|
|
|
|
+ logger.warn("访问地址:" + request.getRequestURL().toString());
|
|
logger.warn("path=" + pathBuilder.toString());
|
|
logger.warn("path=" + pathBuilder.toString());
|
|
|
|
|
|
|
|
+ //1.这里获取到所有的参数值的数组
|
|
|
|
+ Object[] args = point.getArgs();
|
|
|
|
+ String[] parameterNames = methodSignature.getParameterNames();
|
|
|
|
+
|
|
|
|
+ StringBuilder argBuilder = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ for (int i = 0;i<Math.min(args.length, parameterNames.length);i++) {
|
|
|
|
+ if (argBuilder.length()!=0){
|
|
|
|
+ argBuilder.append("&");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(args[i] != null) {
|
|
|
|
+ String value = args[i].toString();
|
|
|
|
+ value = value.length() > 100 ? value.substring(0, 100) : value;
|
|
|
|
+
|
|
|
|
+ if (parameterNames[i].equals("password")){
|
|
|
|
+ value = "******";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ argBuilder.append(parameterNames[i] + "=" + value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sysLog.setData(argBuilder.toString());
|
|
|
|
+
|
|
String userId = (String)request.getAttribute("subject");
|
|
String userId = (String)request.getAttribute("subject");
|
|
|
|
|
|
boolean existed = permissionService.exist(pathBuilder.toString(), request.getMethod());
|
|
boolean existed = permissionService.exist(pathBuilder.toString(), request.getMethod());
|
|
@@ -116,6 +152,16 @@ public class PermissionAdvice {
|
|
System.out.println(classType);
|
|
System.out.println(classType);
|
|
logger.warn(String.format("调用类%s方法%s耗时%s毫秒",clazzSimpleName,methodName,elapse));
|
|
logger.warn(String.format("调用类%s方法%s耗时%s毫秒",clazzSimpleName,methodName,elapse));
|
|
|
|
|
|
|
|
+ if(elapse>3000) {
|
|
|
|
+ //执行时间超过3秒则记录数据库
|
|
|
|
+ sysLog.setElapse(elapse);
|
|
|
|
+ sysLog.setPointcut(clazzSimpleName + "->" + methodName);
|
|
|
|
+ sysLog.setRemark("方法耗时统计");
|
|
|
|
+ sysLog.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ sysLogService.insert(sysLog);
|
|
|
|
+ }
|
|
|
|
+
|
|
return obj;
|
|
return obj;
|
|
}
|
|
}
|
|
}
|
|
}
|