PreActivityHandler.java
1.71 KB
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
package com.zhaoonline.coupen.handler;
import com.zhaoonline.coupen.bean.Activity;
import com.zhaoonline.coupen.bean.CommonCoupenEntity;
import com.zhaoonline.coupen.dispatcher.UserCoupenMappingHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import java.util.List;
/**
* Created by ZhaoOnline<br/>
* User: yangyoupeng<br/>
* Date: 2016/12/17<br/>
* Time: 10:22<br/>
* Description:在处理红包之前。
*/
public class PreActivityHandler {
private UserCoupenMappingHandler userCoupenMappingHandler= null;
@Autowired
public PreActivityHandler(UserCoupenMappingHandler userCoupenMappingHandler){
this.userCoupenMappingHandler = userCoupenMappingHandler;
}
/**
* 这是是要对根据用户和Activity来判断
* @param activity
* @param context
* @return
*/
public boolean preProcessRequest(Activity activity,DrawContext context){
List<CommonCoupenEntity> coupnesOfUserInOneActivity=this.userCoupenMappingHandler.getMappingOfUser(activity,context.getDrawOwner());
if(ObjectUtils.isEmpty(coupnesOfUserInOneActivity) || checkBeyondDrawLimit(context, coupnesOfUserInOneActivity)){
return true;
}
return false;
}
/**判断是否用户领取已经超出了限制次数。正常逻辑,每个用户在一个活动中只允许领取一个红包
* @param context
* @param coupnesOfUserInOneActivity
* @return
*/
private boolean checkBeyondDrawLimit(DrawContext context, List<CommonCoupenEntity> coupnesOfUserInOneActivity) {
return coupnesOfUserInOneActivity.size() <context.getConfig().getRepeatDrawCount();
}
}