package com.xzx.gc.util;
|
|
|
import com.xzx.gc.common.HttpRequestLocal;
|
import com.xzx.gc.common.utils.RedisUtil;
|
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.annotation.*;
|
import org.aspectj.lang.reflect.MethodSignature;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.lang.reflect.Method;
|
|
/**
|
* 表单提交时间间隔
|
*/
|
@Aspect
|
@Component
|
public class PreventManyCommitAspect {
|
|
public static final String PREVENT_MANY_COMMIT="FROM_";
|
|
@Autowired
|
HttpServletRequest request;
|
|
@Autowired
|
RedisUtil redisService;
|
|
@Autowired
|
HttpRequestLocal httpRequestLocal;
|
|
|
@Around("@annotation(com.xzx.gc.util.PreventManyCommit)")
|
public Object around(ProceedingJoinPoint point) throws Throwable{
|
MethodSignature signature = (MethodSignature)point.getSignature();
|
Method method = signature.getMethod();
|
|
PreventManyCommit preventManyCommit = method.getAnnotation(PreventManyCommit.class);
|
long time = preventManyCommit.time() > 1 ? preventManyCommit.time() : 1;
|
|
/*if(!redisService.preventManyCommit(PREVENT_MANY_COMMIT+httpRequestLocal.getIpAddr(request)+""+request.getRequestURI(), request.getRequestURI(), time)){
|
throw new PlatformException("速度太快了...");
|
}*/
|
|
return point.proceed();
|
}
|
|
@After("@annotation(com.xzx.gc.util.PreventManyCommit)")
|
public void after(JoinPoint point) {
|
}
|
|
@AfterReturning("@annotation(com.xzx.gc.util.PreventManyCommit)")
|
public void afterReturning(JoinPoint joinPoint) {
|
}
|
|
@AfterThrowing(pointcut = "@annotation(UserLock)",throwing = "ex")
|
public void AfterThrowing(JoinPoint joinPoint,Throwable ex){
|
}
|
|
|
}
|
|
|