ActivateUnionRest.java
3.04 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
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
93
94
95
96
97
98
99
100
101
102
103
/**
*
*/
package com.yoho.unions.server.restapi;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.service.model.union.request.ActivateUnionRequestBO;
import com.yoho.service.model.union.request.ActivateUnionRequestVO;
import com.yoho.service.model.union.response.ActiveUnionResponseBO;
import com.yoho.unions.common.constant.UnionConstant;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.utils.SpringContextUtil;
import com.yoho.unions.server.service.MainUnionService;
/**
* 描述:
* 激活联盟入口
* @author ping.huang
* 2016年3月16日
*/
@Controller
@RequestMapping("/ActivateUnionRest")
public class ActivateUnionRest {
static Logger log = LoggerFactory.getLogger(ActivateUnionRest.class);
static ExecutorService exe = Executors.newFixedThreadPool(20);
/**
* 激活联盟
* @param request
* @return
*/
@RequestMapping("/activateUnion")
@ResponseBody public ActiveUnionResponseBO activateUnion(ActivateUnionRequestVO vo) {
log.info("addUnion with param is {}", vo);
ActivateUnionRequestBO bo = new ActivateUnionRequestBO();
BeanUtils.copyProperties(vo, bo);
String clientType = vo.getClient_type();
if (!ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(clientType) && !ClientTypeEnum.IPHONE.getName().equalsIgnoreCase(clientType)) {
log.warn("activateUnion error with param is {}", vo);
return new ActiveUnionResponseBO(600, "error");
}
//多线程处理
exe.execute(new RunActivate(bo));
return new ActiveUnionResponseBO(200, "success");
}
public static class RunActivate implements Runnable {
public RunActivate(ActivateUnionRequestBO bo) {
this.bo = bo;
}
private ActivateUnionRequestBO bo;
@Override
public void run() {
MainUnionService service = null;
if (ClientTypeEnum.ANDROID.getName().equalsIgnoreCase(bo.getClient_type())) {
//处理安卓的服务
for (String str : UnionConstant.andriodServiceList) {
//捕获异常,不影响后面的联盟
try {
service = SpringContextUtil.getBean(str, MainUnionService.class);
service.activeUnion(bo);
} catch (Exception e) {
log.warn("addUnion error with param is {}", bo);
}
}
} else if (ClientTypeEnum.IPHONE.getName().equalsIgnoreCase(bo.getClient_type())) {
//处理iOS的服务
for (String str : UnionConstant.iOSServiceList) {
//捕获异常,不影响后面的联盟
try {
service = SpringContextUtil.getBean(str, MainUnionService.class);
service.activeUnion(bo);
} catch (Exception e) {
log.warn("addUnion error with param is {}", bo);
}
}
}
}
public ActivateUnionRequestBO getBo() {
return bo;
}
public void setBo(ActivateUnionRequestBO bo) {
this.bo = bo;
}
}
}