提交 960ffcd9 authored 作者: 马晨俊's avatar 马晨俊

mcj:aop记录方法时间

上级 d4904820
......@@ -24,7 +24,7 @@ import java.util.List;
@Aspect
@Slf4j
@Component
public class AuthIntercept {
public class AopIntercept {
private User user;
......@@ -32,27 +32,18 @@ public class AuthIntercept {
this.user = user;
}
@Pointcut("@annotation(com.zjty.inspect.aop.AuthAnnotation)")
@Pointcut("execution(* com.zjty.inspect.inspect.Inspector.inspect(..))")
public void doPointCut() {
}
@Around("doPointCut()")
public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
AuthAnnotation annotation = ((MethodSignature)joinPoint.getSignature()).getMethod().getAnnotation(AuthAnnotation.class);
//注解配置权限code
String[] methodAuthCodes = annotation.code();
//用户拥有权限code
List<String> authorityCode = user.getAuthorityCode();
int i =0;
for (String methodAuthCode : methodAuthCodes) {
if(authorityCode.contains(methodAuthCode)){
i++;
}
}
if(i==0){
return ResponseEntity.status(403).build();
}
long startMillis = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long endMillis = System.currentTimeMillis();
long time = (endMillis - startMillis);
log.info("评估总耗时{}毫秒",time);
log.info("PersonAspect2 ==> before method : {}", joinPoint.getSignature().getName());
log.info("注解的类型名称为{}",joinPoint.getSignature().getDeclaringTypeName());
log.info("方法修饰符个数为{}",joinPoint.getSignature().getModifiers());
......
package com.zjty.inspect.config;
import com.zjty.inspect.aop.AuthIntercept;
import com.zjty.inspect.aop.AopIntercept;
import com.zjty.inspect.entity.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
......@@ -22,7 +22,7 @@ public class LoginInterceptor implements HandlerInterceptor {
private RestTemplate restTemplate;
@Autowired
private AuthIntercept authIntercept;
private AopIntercept aopIntercept;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) {
String sessionId = request.getHeader("sessionId");
......@@ -34,7 +34,7 @@ public class LoginInterceptor implements HandlerInterceptor {
response.setStatus(403);
return false;
}
authIntercept.setUser(user.getData());
aopIntercept.setUser(user.getData());
return true;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论