Helius
2021-08-05 fdb91cc72f7cbe8c095a1ce6442c9259ff01ff06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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){
    }
 
 
}