拦截类UserLogAopAspect
@Slf4j
@Aspect
@Component
@Order(AopOrderConst.LOG_AOP_ORDER)
public class UserLogAopAspect {
@Autowired
private IUserOperateLogService userOperateLogService;
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Around("@annotation(annotation)")
public Object logSave(ProceedingJoinPoint joinPoint, UserOperateLogAnnotation annotation) throws Throwable {
long start = System.currentTimeMillis();
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
//调用原来的方法
Object result = joinPoint.proceed();
UserOperateLogAnnotation operateLogAnnotation = methodSignature.getMethod().getDeclaredAnnotation(UserOperateLogAnnotation.class);
//如果需要记录数据库开启异步操作
if (Objects.nonNull(operateLogAnnotation) && operateLogAnnotation.saveDb()) {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();
// 请求流水号
String traceId = StringUtils.defaultString(TraceUtils.getTrace(), MDC.get(TraceConstant.LOG_TRACE_ID));
String httpMethod = request.getMethod();
List<Object> httpReqArgs = new ArrayList<Object>();
UserOperateLogEntity operateLogEnt