|
@@ -0,0 +1,72 @@
|
|
|
+package com.qmth.themis.exam.aspect;
|
|
|
+
|
|
|
+import com.qmth.themis.common.util.ResultUtil;
|
|
|
+import com.qmth.themis.exam.util.ServletUtil;
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
+import org.aspectj.lang.reflect.MethodSignature;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: api aspect
|
|
|
+ * @Param:
|
|
|
+ * @return:
|
|
|
+ * @Author: wangliang
|
|
|
+ * @Date: 2020/5/12
|
|
|
+ */
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class ApiControllerAspect {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(ApiControllerAspect.class);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * api切入点
|
|
|
+ */
|
|
|
+ @Pointcut("execution(public * com.qmth.themis.exam.api.*.*(..))")
|
|
|
+ public void apiAspect() {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 考试环绕切入
|
|
|
+ *
|
|
|
+ * @param joinPoint
|
|
|
+ * @return
|
|
|
+ * @throws Throwable
|
|
|
+ */
|
|
|
+ @Around(value = "apiAspect()")
|
|
|
+ public Object aroundApiPoint(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
+ 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();
|
|
|
+ log.info("============请求地址========:{}", request.getRequestURL());
|
|
|
+ log.info("============类=============:{}", className);
|
|
|
+ log.info("============方法===========:{}", methodName);
|
|
|
+ for (int i = 0; i < args.length; i++) {
|
|
|
+ log.info("============参数key:{},参数value===========:{}", paramsName[i], args[i]);
|
|
|
+ }
|
|
|
+// log.info("============参数key:{},参数value===========:{}", JSONObject.toJSONString(paramsName), JSONObject.toJSONString(args));
|
|
|
+ log.info("============platform===========:{}", ServletUtil.getRequestPlatform());
|
|
|
+ log.info("============deviceId===========:{}", ServletUtil.getRequestDeviceId());
|
|
|
+ log.info("============Authorization===========:{}", ServletUtil.getRequestAuthorization());
|
|
|
+ log.info("============time===========:{}", ServletUtil.getRequestTime());
|
|
|
+ Object proceed = joinPoint.proceed();
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("============耗时============:{}秒", (end - start) / 1000);
|
|
|
+ return proceed;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|