admin
2019-03-08 f5ad4a8171b20ab75eaac90c9717fe7fd801d6cd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.yeshi.fanli.aspect;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
 
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.RedisManager;
 
/**
 * 活跃用户处理
 * 
 * @author Administrator
 *
 */
//@Component
//@Aspect
//@Order(6)
public class ActiveUserAspect {
    
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private UserSystemCouponService userSystemCouponService;
 
    
    public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*(..))";
 
//    @Around(EDP)
    public Object activeAround(ProceedingJoinPoint joinPoint) throws Throwable {
 
        Long uid = null;
    
        ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        HttpServletRequest request = servletContainer.getRequest();
        
        String str_uid = request.getParameter("uid");
        if (str_uid != null && str_uid.trim().length() > 0) {
            uid = Long.parseLong(str_uid);
        }
        
        
        final Long uuid = uid;
        
        executor.execute(new Runnable() {
            @Override
            public void run() {
                
                if (uuid == null) {
                    return;
                }
                
                // 缓存uid的Key
                String key = "activeUid_" + uuid;
                
                // 缓存中是否存在uid
                String cacheValue = redisManager.getCommonString(key);
                if (cacheValue != null && cacheValue.trim().length() > 0) {
                    return;
                }
 
                // 加入缓存 20分钟
                redisManager.cacheCommonString("activeUid_" + uuid, uuid.toString(), 60 * 20);
                
                
                // 接收券
                try {
                    userSystemCouponService.receivedCoupon(uuid);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        
        Object[] args = joinPoint.getArgs();
        return joinPoint.proceed(args);
    }
 
}