|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.teachcloud.report.aspect;
|
|
|
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
@@ -19,6 +20,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
/**
|
|
|
* @Description: api aspect
|
|
@@ -48,43 +50,39 @@ public class ApiControllerAspect {
|
|
|
*/
|
|
|
@Around(value = "apiAspect()")
|
|
|
public Object aroundApiPoint(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
try {
|
|
|
- long start = System.currentTimeMillis();
|
|
|
MethodSignature msig = (MethodSignature) joinPoint.getSignature();
|
|
|
String className = msig.getDeclaringTypeName();
|
|
|
String methodName = msig.getName();
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
String[] paramsName = msig.getParameterNames();
|
|
|
HttpServletRequest request = ServletUtil.getRequest();
|
|
|
- if (Objects.nonNull(request)) {
|
|
|
- log.info("============请求地址========:{}", request.getServletPath());
|
|
|
- log.info("============类=============:{}", className);
|
|
|
- log.info("============方法===========:{}", methodName);
|
|
|
- if (Objects.nonNull(args) && args.length > 0) {
|
|
|
- for (int i = 0; i < args.length; i++) {
|
|
|
- if (Objects.nonNull(args[i]) && (args[i] instanceof HttpServletRequest || args[i] instanceof HttpServletResponse || args[i] instanceof CommonsMultipartFile || args[i] instanceof MultipartFile || args[i] instanceof BeanPropertyBindingResult)) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- log.info("============参数key:{},参数value===========:{}", JacksonUtil.parseJson(paramsName[i]), JacksonUtil.parseJson(args[i]));
|
|
|
- }
|
|
|
+ stringJoiner.add("============请求地址============:").add(request.getServletPath()).add("\r\n");
|
|
|
+ stringJoiner.add("============类============:").add(className).add("\r\n");
|
|
|
+ stringJoiner.add("============方法============:").add(methodName).add("\r\n");
|
|
|
+ if (Objects.nonNull(args) && args.length > 0) {
|
|
|
+ for (int i = 0; i < args.length; i++) {
|
|
|
+ if (Objects.nonNull(args[i]) && (args[i] instanceof HttpServletRequest || args[i] instanceof HttpServletResponse || args[i] instanceof CommonsMultipartFile || args[i] instanceof MultipartFile || args[i] instanceof BeanPropertyBindingResult)) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ stringJoiner.add("参数key:").add(JacksonUtil.parseJson(paramsName[i])).add(",参数value:").add(JacksonUtil.parseJson(args[i])).add("\r\n");
|
|
|
}
|
|
|
}
|
|
|
-// log.info("============platform===========:{}", ServletUtil.getRequestPlatform());
|
|
|
-// log.info("============deviceId===========:{}", ServletUtil.getRequestDeviceId());
|
|
|
-// log.info("============Authorization===========:{}", ServletUtil.getRequestAuthorizationForAspect());
|
|
|
-// log.info("============time===========:{}", ServletUtil.getRequestTimeForTime());
|
|
|
}
|
|
|
- Object proceed = joinPoint.proceed();
|
|
|
- long end = System.currentTimeMillis();
|
|
|
- log.info("============耗时============:{}秒", (end - start) / 1000);
|
|
|
- return proceed;
|
|
|
+ return joinPoint.proceed();
|
|
|
} catch (Exception e) {
|
|
|
- log.error("请求出错", e);
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
if (e instanceof ApiException) {
|
|
|
return ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
} else {
|
|
|
return ResultUtil.error(e.getMessage());
|
|
|
}
|
|
|
+ } finally {
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ stringJoiner.add("============耗时============:").add((end - start) / 1000 + "").add("秒");
|
|
|
+ log.info("{}", stringJoiner.toString());
|
|
|
}
|
|
|
}
|
|
|
}
|