| | |
| | | @Around("@within(org.springframework.web.bind.annotation.RestController)" + |
| | | "||@within(org.springframework.stereotype.Controller)") |
| | | public Object after(ProceedingJoinPoint joinPoint) throws Throwable { |
| | | ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
| | | ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder |
| | | .getRequestAttributes(); |
| | | HttpServletRequest request = requestAttributes != null ? requestAttributes.getRequest() : null; |
| | | long start = System.currentTimeMillis(); |
| | | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | OpenApiLog annotation = method.isAnnotationPresent(OpenApiLog.class) ? method.getAnnotation(OpenApiLog.class) : null; |
| | | OpenApiLog annotation = method.isAnnotationPresent(OpenApiLog.class) ? method.getAnnotation(OpenApiLog.class) |
| | | : null; |
| | | Object result = null; |
| | | Object errorResponse = null; |
| | | try { |
| | | if (licenseTimer != null && !licenseTimer.getSystemSupport()) { |
| | | Object fail = R.error("许可证失效"); |
| | | if (annotation != null && !Cools.isEmpty(annotation.memo())) { |
| | | saveErrLog(joinPoint, request, fail, new CoolException("许可证失效"), annotation.memo()); |
| | | } |
| | | return fail; |
| | | } |
| | | result = joinPoint.proceed(joinPoint.getArgs()); |
| | | if (annotation != null && !Cools.isEmpty(annotation.memo())) { |
| | | if (licenseTimer != null && !licenseTimer.getSystemSupport()) { |
| | | Object fail = R.error("许可证失效"); |
| | | if (annotation != null && !Cools.isEmpty(annotation.memo())) { |
| | | saveErrLog(joinPoint, request, fail, new CoolException("许可证失效"), annotation.memo()); |
| | | } |
| | | return fail; |
| | | } |
| | | saveLog(joinPoint, request, result, annotation.memo()); |
| | | } |
| | | return result; |
| | |
| | | if (annotation != null && !Cools.isEmpty(annotation.memo())) { |
| | | saveErrLog(joinPoint, request, errorResponse, ex, annotation.memo()); |
| | | } |
| | | return errorResponse; |
| | | if (ex instanceof Exception) { |
| | | throw (Exception) ex; |
| | | } |
| | | throw new RuntimeException(ex); |
| | | } finally { |
| | | long end = System.currentTimeMillis(); |
| | | // log.info("请求日志的打印"); |
| | | // log.info("请求地址:{}", request != null ? Optional.ofNullable(request.getRequestURI()).orElse(null) : null); |
| | | // log.info("请求方式:{}", request != null ? request.getMethod() : null); |
| | | // log.info("请求类方法:{}", joinPoint.getSignature()); |
| | | // log.info("请求类方法参数:{}", JSONObject.toJSONString(filterArgs(joinPoint.getArgs()))); |
| | | // log.info("请求响应参数{}", JSONObject.toJSONString(result != null ? result : errorResponse)); |
| | | // log.info("执行耗时:{}", end - start); |
| | | // log.info("请求日志的打印"); |
| | | // log.info("请求地址:{}", request != null ? |
| | | // Optional.ofNullable(request.getRequestURI()).orElse(null) : null); |
| | | // log.info("请求方式:{}", request != null ? request.getMethod() : null); |
| | | // log.info("请求类方法:{}", joinPoint.getSignature()); |
| | | // log.info("请求类方法参数:{}", |
| | | // JSONObject.toJSONString(filterArgs(joinPoint.getArgs()))); |
| | | // log.info("请求响应参数{}", JSONObject.toJSONString(result != null ? result : |
| | | // errorResponse)); |
| | | // log.info("执行耗时:{}", end - start); |
| | | } |
| | | } |
| | | |
| | |
| | | 1, |
| | | new Date(), |
| | | null, |
| | | null |
| | | )); |
| | | null)); |
| | | } |
| | | |
| | | private void saveErrLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object response, Throwable ex, String memo) { |
| | | private void saveErrLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object response, Throwable ex, |
| | | String memo) { |
| | | apiLogService.insert(new ApiLog( |
| | | null, |
| | | memo, |
| | |
| | | 1, |
| | | new Date(), |
| | | null, |
| | | null |
| | | )); |
| | | null)); |
| | | } |
| | | |
| | | private Object buildErrorResponse(Throwable ex) { |