Commit d3329768 authored by 赵啸非's avatar 赵啸非

修改部分pom

parent 6e9bce59
...@@ -76,6 +76,11 @@ ...@@ -76,6 +76,11 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
......
...@@ -139,6 +139,7 @@ ...@@ -139,6 +139,7 @@
<dependency> <dependency>
<groupId>org.flowable</groupId> <groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-basic</artifactId> <artifactId>flowable-spring-boot-starter-basic</artifactId>
<version>6.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -71,6 +71,10 @@ ...@@ -71,6 +71,10 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
</dependencies> </dependencies>
......
package com.mortals.xhx.base.framework.aspect; //package com.mortals.xhx.base.framework.aspect;
//
import com.alibaba.fastjson.JSONObject; //import com.alibaba.fastjson.JSONObject;
import com.mortals.xhx.base.framework.annotation.LogPrint; //import com.mortals.xhx.base.framework.annotation.LogPrint;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint; //import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; //import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*; //import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.Profile; //import org.springframework.aop.Pointcut;
import org.springframework.stereotype.Component; //import org.springframework.context.annotation.Profile;
import org.springframework.web.context.request.RequestContextHolder; //import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletRequestAttributes; //import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.multipart.MultipartFile; //import org.springframework.web.context.request.ServletRequestAttributes;
//import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; //
import javax.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method; //import javax.servlet.http.HttpServletResponse;
//import java.lang.reflect.Method;
//@Aspect //
//@Component ////@Aspect
//@Profile({"dev"}) //一般生产环境不允许日志打印参数 ////@Component
@Slf4j ////@Profile({"dev"}) //一般生产环境不允许日志打印参数
public class LogPrintAspect { //@Slf4j
/** //public class LogPrintAspect {
* 换行符 // /**
*/ // * 换行符
private static final String LINE_SEPARATOR = System.lineSeparator(); // */
// private static final String LINE_SEPARATOR = System.lineSeparator();
/** //
* 以自定义 @LogPrint 注解为切点 // /**
*/ // * 以自定义 @LogPrint 注解为切点
//@Pointcut("@annotation(com.*.*.config.annotation.LogPrint)") // */
@Pointcut("execution(public * com.mortals.xhx..*Controller.*(..))") // //@Pointcut("@annotation(com.*.*.config.annotation.LogPrint)")
public void logPrint() { // @Pointcut("execution(public * com.mortals.xhx..*Controller.*(..))")
} // public void logPrint() {
// }
/** //
* 在切点之前织入 // /**
* // * 在切点之前织入
* @param joinPoint // *
* @throws Throwable // * @param joinPoint
*/ // * @throws Throwable
@Before("logPrint()") // */
public void doBefore(JoinPoint joinPoint) throws Throwable { // @Before("logPrint()")
// 开始打印请求日志 // public void doBefore(JoinPoint joinPoint) throws Throwable {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); // // 开始打印请求日志
HttpServletRequest request = attributes.getRequest(); // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// HttpServletRequest request = attributes.getRequest();
// 获取 @WebLog 注解的描述信息 //
String methodDescription = getAspectLogDescription(joinPoint); // // 获取 @WebLog 注解的描述信息
// String methodDescription = getAspectLogDescription(joinPoint);
// 打印请求相关参数 //
log.info("========================================== Start =========================================="); // // 打印请求相关参数
// 打印请求 url // log.info("========================================== Start ==========================================");
log.info("URL : {}", request.getRequestURL().toString()); // // 打印请求 url
// 打印描述信息 // log.info("URL : {}", request.getRequestURL().toString());
log.info("Description : {}", methodDescription); // // 打印描述信息
// 打印 Http method // log.info("Description : {}", methodDescription);
log.info("HTTP Method : {}", request.getMethod()); // // 打印 Http method
// 打印调用 controller 的全路径以及执行方法 // log.info("HTTP Method : {}", request.getMethod());
log.info("Class Method : {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName()); // // 打印调用 controller 的全路径以及执行方法
// 打印请求的 IP // log.info("Class Method : {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
log.info("IP : {}", request.getRemoteAddr()); // // 打印请求的 IP
// 打印请求入参 // log.info("IP : {}", request.getRemoteAddr());
log.info("Request Args : {}", getParams(joinPoint)); // // 打印请求入参
} // log.info("Request Args : {}", getParams(joinPoint));
// }
/** //
* 在切点之后织入 // /**
* // * 在切点之后织入
* @throws Throwable // *
*/ // * @throws Throwable
@After("logPrint()") // */
public void doAfter() throws Throwable { // @After("logPrint()")
// 接口结束后换行,方便分割查看 // public void doAfter() throws Throwable {
log.info("=========================================== End ===========================================" + LINE_SEPARATOR); // // 接口结束后换行,方便分割查看
} // log.info("=========================================== End ===========================================" + LINE_SEPARATOR);
// }
/** //
* 环绕 // /**
* // * 环绕
* @param proceedingJoinPoint // *
* @return // * @param proceedingJoinPoint
* @throws Throwable // * @return
*/ // * @throws Throwable
@Around("logPrint()") // */
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { // @Around("logPrint()")
long startTime = System.currentTimeMillis(); // public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
Object result = proceedingJoinPoint.proceed(); // long startTime = System.currentTimeMillis();
// 打印出参 // Object result = proceedingJoinPoint.proceed();
log.info("Response Args : {}", JSONObject.toJSONString(result)); // // 打印出参
// 执行耗时 // log.info("Response Args : {}", JSONObject.toJSONString(result));
log.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime); // // 执行耗时
return result; // log.info("Time-Consuming : {} ms", System.currentTimeMillis() - startTime);
} // return result;
// }
//
/** //
* 获取切面注解的描述 // /**
* // * 获取切面注解的描述
* @param joinPoint 切点 // *
* @return 描述信息 // * @param joinPoint 切点
* @throws Exception // * @return 描述信息
*/ // * @throws Exception
public String getAspectLogDescription(JoinPoint joinPoint) // */
throws Exception { // public String getAspectLogDescription(JoinPoint joinPoint)
String targetName = joinPoint.getTarget().getClass().getName(); // throws Exception {
String methodName = joinPoint.getSignature().getName(); // String targetName = joinPoint.getTarget().getClass().getName();
Object[] arguments = joinPoint.getArgs(); // String methodName = joinPoint.getSignature().getName();
Class targetClass = Class.forName(targetName); // Object[] arguments = joinPoint.getArgs();
Method[] methods = targetClass.getMethods(); // Class targetClass = Class.forName(targetName);
StringBuilder description = new StringBuilder(""); // Method[] methods = targetClass.getMethods();
for (Method method : methods) { // StringBuilder description = new StringBuilder("");
if (method.getName().equals(methodName)) { // for (Method method : methods) {
Class[] clazzs = method.getParameterTypes(); // if (method.getName().equals(methodName)) {
if (clazzs.length == arguments.length) { // Class[] clazzs = method.getParameterTypes();
description.append(method.getAnnotation(LogPrint.class).description()); // if (clazzs.length == arguments.length) {
break; // description.append(method.getAnnotation(LogPrint.class).description());
} // break;
} // }
} // }
return description.toString(); // }
} // return description.toString();
// }
private String getParams(JoinPoint joinPoint) { //
String params = ""; // private String getParams(JoinPoint joinPoint) {
if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) { // String params = "";
for (int i = 0; i < joinPoint.getArgs().length; i++) { // if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) {
Object arg = joinPoint.getArgs()[i]; // for (int i = 0; i < joinPoint.getArgs().length; i++) {
if ((arg instanceof HttpServletResponse) || (arg instanceof HttpServletRequest) // Object arg = joinPoint.getArgs()[i];
|| (arg instanceof MultipartFile) || (arg instanceof MultipartFile[])) { // if ((arg instanceof HttpServletResponse) || (arg instanceof HttpServletRequest)
continue; // || (arg instanceof MultipartFile) || (arg instanceof MultipartFile[])) {
} // continue;
try { // }
params += JSONObject.toJSONString(joinPoint.getArgs()[i]); // try {
} catch (Exception e1) { // params += JSONObject.toJSONString(joinPoint.getArgs()[i]);
log.error(e1.getMessage()); // } catch (Exception e1) {
} // log.error(e1.getMessage());
} // }
} // }
return params; // }
} // return params;
// }
} //
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment