Authored by zhengwen.ge

Merge branch 'master' into union_type整改

# Conflicts:
#	server/src/main/java/com/yoho/unions/server/service/impl/UnionServiceImpl.java
@@ -99,7 +99,14 @@ public class ActivateUnionRest { @@ -99,7 +99,14 @@ public class ActivateUnionRest {
99 log.warn("activateUnion error with param is {}", vo); 99 log.warn("activateUnion error with param is {}", vo);
100 return new ActiveUnionResponseBO(600, "error"); 100 return new ActiveUnionResponseBO(600, "error");
101 } 101 }
102 - bo.setClientIp(RemoteIPInterceptor.getRemoteIP()); 102 + //IP取出来的有可能是42.239.40.36,123.151.42.50,只取第一个
  103 + String IP = RemoteIPInterceptor.getRemoteIP();
  104 + String clientIp = null;
  105 + if(StringUtils.isNotEmpty(IP)){
  106 + String[] IPS = IP.split(",");
  107 + clientIp = IPS[0];
  108 + }
  109 + bo.setClientIp(clientIp);
103 //多线程处理 110 //多线程处理
104 exe.execute(new RunActivate(bo)); 111 exe.execute(new RunActivate(bo));
105 return new ActiveUnionResponseBO(200, "success"); 112 return new ActiveUnionResponseBO(200, "success");
@@ -66,7 +66,14 @@ public class ClickUnionRest { @@ -66,7 +66,14 @@ public class ClickUnionRest {
66 if ("iphone".equals(request.getClient_type())) { 66 if ("iphone".equals(request.getClient_type())) {
67 request.setClient_type(ClientTypeEnum.IOS.getName()); 67 request.setClient_type(ClientTypeEnum.IOS.getName());
68 } 68 }
69 - request.setClientIp(RemoteIPInterceptor.getRemoteIP()); 69 + String IP = RemoteIPInterceptor.getRemoteIP();
  70 +// String IP = "42.236.215.29, 123.151.42.48";
  71 + String clientIp = null;
  72 + if(StringUtils.isNotEmpty(IP)){
  73 + String[] IPS = IP.split(",");
  74 + clientIp = IPS[0];
  75 + }
  76 + request.setClientIp(clientIp);
70 clickUnion.info("addUnion with param is {}", request); 77 clickUnion.info("addUnion with param is {}", request);
71 UnionResponse response = unionService.clickUnion(request); 78 UnionResponse response = unionService.clickUnion(request);
72 log.info("addUnion with result is {}, and request is {}", response, request); 79 log.info("addUnion with result is {}, and request is {}", response, request);
@@ -91,8 +98,13 @@ public class ClickUnionRest { @@ -91,8 +98,13 @@ public class ClickUnionRest {
91 }else { 98 }else {
92 request = unionService.clickHttpRequestTOBO(httpServletRequest,request); 99 request = unionService.clickHttpRequestTOBO(httpServletRequest,request);
93 } 100 }
94 -  
95 - request.setClientIp(RemoteIPInterceptor.getRemoteIP()); 101 + String IP = RemoteIPInterceptor.getRemoteIP();
  102 + String clientIp = null;
  103 + if(StringUtils.isNotEmpty(IP)){
  104 + String[] IPS = IP.split(",");
  105 + clientIp = IPS[0];
  106 + }
  107 + request.setClientIp(clientIp);
96 // IUnionService service = SpringContextUtil.getBean(bean, IUnionService.class); 108 // IUnionService service = SpringContextUtil.getBean(bean, IUnionService.class);
97 clickUnion.info("addCommonUnion request is {}",request); 109 clickUnion.info("addCommonUnion request is {}",request);
98 UnionResponse response = unionService.clickUnion(request); 110 UnionResponse response = unionService.clickUnion(request);
@@ -111,7 +123,13 @@ public class ClickUnionRest { @@ -111,7 +123,13 @@ public class ClickUnionRest {
111 public void addUnion4Special(ClickUnionRequestBO bo, HttpServletRequest request, HttpServletResponse response) { 123 public void addUnion4Special(ClickUnionRequestBO bo, HttpServletRequest request, HttpServletResponse response) {
112 log.info("addUnion4Special with param is {}", bo); 124 log.info("addUnion4Special with param is {}", bo);
113 try { 125 try {
114 - bo.setClientIp(RemoteIPInterceptor.getRemoteIP()); 126 + String clientIp = null;
  127 + String IP = RemoteIPInterceptor.getRemoteIP();
  128 + if(StringUtils.isNotEmpty(IP)){
  129 + String[] IPS = IP.split(",");
  130 + clientIp = IPS[0];
  131 + }
  132 + bo.setClientIp(clientIp);
115 String agent = request.getHeader("user-agent"); 133 String agent = request.getHeader("user-agent");
116 log.info("user-agent={}", agent); 134 log.info("user-agent={}", agent);
117 if (StringUtils.isEmpty(agent)) { 135 if (StringUtils.isEmpty(agent)) {
@@ -162,7 +180,13 @@ public class ClickUnionRest { @@ -162,7 +180,13 @@ public class ClickUnionRest {
162 if (StringUtils.isEmpty(bo.getUnion_type())) { 180 if (StringUtils.isEmpty(bo.getUnion_type())) {
163 return; 181 return;
164 } 182 }
165 - bo.setClientIp(RemoteIPInterceptor.getRemoteIP()); 183 + String clientIp = null;
  184 + String IP = RemoteIPInterceptor.getRemoteIP();
  185 + if(StringUtils.isNotEmpty(IP)){
  186 + String[] IPS = IP.split(",");
  187 + clientIp = IPS[0];
  188 + }
  189 + bo.setClientIp(clientIp);
166 bo.setClient_type("android"); 190 bo.setClient_type("android");
167 bo.setAppid("com.yoho"); 191 bo.setAppid("com.yoho");
168 String agent = request.getHeader("user-agent"); 192 String agent = request.getHeader("user-agent");
@@ -222,8 +246,14 @@ public class ClickUnionRest { @@ -222,8 +246,14 @@ public class ClickUnionRest {
222 String key = e.nextElement(); 246 String key = e.nextElement();
223 log.info("addMonitor with key={}, value={}", key, request.getParameter(key)); 247 log.info("addMonitor with key={}, value={}", key, request.getParameter(key));
224 } 248 }
  249 + String IP = RemoteIPInterceptor.getRemoteIP();
  250 + String clientIp = null;
  251 + if(StringUtils.isNotEmpty(IP)){
  252 + String[] IPS = IP.split(",");
  253 + clientIp = IPS[0];
  254 + }
225 255
226 - bo.setClientIp(RemoteIPInterceptor.getRemoteIP()); 256 + bo.setClientIp(clientIp);
227 String agent = request.getHeader("user-agent"); 257 String agent = request.getHeader("user-agent");
228 log.info("addMonitor user-agent={}", agent); 258 log.info("addMonitor user-agent={}", agent);
229 try{ 259 try{
@@ -65,7 +65,13 @@ public class MobvistaUnionRest { @@ -65,7 +65,13 @@ public class MobvistaUnionRest {
65 req.setAppid("android"); 65 req.setAppid("android");
66 downloadURL = "http://cdn.yoho.cn/app-downfiles/yohoBuy_YOHO_2953.apk"; 66 downloadURL = "http://cdn.yoho.cn/app-downfiles/yohoBuy_YOHO_2953.apk";
67 } 67 }
68 - req.setIp(RemoteIPInterceptor.getRemoteIP()); 68 + String clientIp = null;
  69 + String IP = RemoteIPInterceptor.getRemoteIP();
  70 + if(StringUtils.isNotEmpty(IP)){
  71 + String[] IPS = IP.split(",");
  72 + clientIp = IPS[0];
  73 + }
  74 + req.setIp(clientIp);
69 String url = "http://stat.mobvista.com/install?mobvista_pl="+req.getDevice_type()+"&mobvista_campuuid="+req.getUuid()+"" 75 String url = "http://stat.mobvista.com/install?mobvista_pl="+req.getDevice_type()+"&mobvista_campuuid="+req.getUuid()+""
70 + "&mobvista_ip="+req.getIp()+"&mobvista_clickid="+req.getClickid()+"&mobvista_gaid=&mobvista_devid="; 76 + "&mobvista_ip="+req.getIp()+"&mobvista_clickid="+req.getClickid()+"&mobvista_gaid=&mobvista_devid=";
71 req.setCallbackurl(url); 77 req.setCallbackurl(url);
@@ -9,6 +9,7 @@ import com.yoho.service.model.union.request.ClickUnionRequestBO; @@ -9,6 +9,7 @@ import com.yoho.service.model.union.request.ClickUnionRequestBO;
9 import com.yoho.service.model.union.response.UnionResponse; 9 import com.yoho.service.model.union.response.UnionResponse;
10 import com.yoho.unions.common.enums.ClientTypeEnum; 10 import com.yoho.unions.common.enums.ClientTypeEnum;
11 import com.yoho.unions.interceptor.RemoteIPInterceptor; 11 import com.yoho.unions.interceptor.RemoteIPInterceptor;
  12 +import org.apache.commons.lang.StringUtils;
12 13
13 import javax.servlet.http.HttpServletRequest; 14 import javax.servlet.http.HttpServletRequest;
14 15
@@ -37,7 +38,14 @@ public interface IUnionService { @@ -37,7 +38,14 @@ public interface IUnionService {
37 clickUnionRequestBO.setUnion_type(request.getParameter("union_type")); 38 clickUnionRequestBO.setUnion_type(request.getParameter("union_type"));
38 clickUnionRequestBO.setImei(request.getParameter("imei")); 39 clickUnionRequestBO.setImei(request.getParameter("imei"));
39 clickUnionRequestBO.setTd(request.getParameter("td")); 40 clickUnionRequestBO.setTd(request.getParameter("td"));
40 - clickUnionRequestBO.setClientIp(RemoteIPInterceptor.getRemoteIP()); 41 +
  42 + String clientIp = null;
  43 + String IP = RemoteIPInterceptor.getRemoteIP();
  44 + if(StringUtils.isNotEmpty(IP)){
  45 + String[] IPS = IP.split(",");
  46 + clientIp = IPS[0];
  47 + }
  48 + clickUnionRequestBO.setClientIp(clientIp);
41 49
42 return clickUnionRequestBO; 50 return clickUnionRequestBO;
43 } 51 }
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 */ 3 */
4 package com.yoho.unions.server.service.impl; 4 package com.yoho.unions.server.service.impl;
5 5
  6 +
6 import com.alibaba.fastjson.JSON; 7 import com.alibaba.fastjson.JSON;
7 import com.alibaba.fastjson.JSONObject; 8 import com.alibaba.fastjson.JSONObject;
8 import com.netflix.config.DynamicIntProperty; 9 import com.netflix.config.DynamicIntProperty;
@@ -30,7 +31,6 @@ import org.apache.commons.lang3.tuple.Pair; @@ -30,7 +31,6 @@ import org.apache.commons.lang3.tuple.Pair;
30 import org.slf4j.Logger; 31 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory; 32 import org.slf4j.LoggerFactory;
32 import org.springframework.stereotype.Service; 33 import org.springframework.stereotype.Service;
33 -  
34 import javax.annotation.Resource; 34 import javax.annotation.Resource;
35 import java.net.URLDecoder; 35 import java.net.URLDecoder;
36 import java.util.List; 36 import java.util.List;
@@ -127,12 +127,14 @@ public class UnionServiceImpl implements IUnionService { @@ -127,12 +127,14 @@ public class UnionServiceImpl implements IUnionService {
127 log.warn("clickUnion error because union_type is error with param is {}", request); 127 log.warn("clickUnion error because union_type is error with param is {}", request);
128 return new UnionResponse(201, "union_type is error"); 128 return new UnionResponse(201, "union_type is error");
129 } 129 }
  130 +
130 //异步记录日志表,以后查询日志方便 131 //异步记录日志表,以后查询日志方便
131 try { 132 try {
132 saveLog(request); 133 saveLog(request);
133 } catch (Exception e) { 134 } catch (Exception e) {
134 log.error("", e); 135 log.error("", e);
135 } 136 }
  137 +
136 //组装redis保存的key 138 //组装redis保存的key
137 String key; 139 String key;
138 if (StringUtils.isNotEmpty(request.getIdfa())) { 140 if (StringUtils.isNotEmpty(request.getIdfa())) {
@@ -207,27 +209,7 @@ public class UnionServiceImpl implements IUnionService { @@ -207,27 +209,7 @@ public class UnionServiceImpl implements IUnionService {
207 return new UnionResponse(300, e.getMessage()); 209 return new UnionResponse(300, e.getMessage());
208 } 210 }
209 } 211 }
210 -  
211 - //异步记录点击日志表  
212 - private void saveLog(ClickUnionRequestBO request){  
213 - taskExecutor.execute(new Runnable() {  
214 - @Override  
215 - public void run()  
216 - {  
217 - UnionClickLogs unionClickLogs = new UnionClickLogs();  
218 - unionClickLogs.setUnionType(request.getUnion_type());  
219 - unionClickLogs.setTd(request.getTd());  
220 - unionClickLogs.setIdfa(request.getIdfa());  
221 - unionClickLogs.setImei(request.getImei());  
222 - unionClickLogs.setClientIp(request.getClientIp());  
223 - unionClickLogs.setAppKey(request.getAppkey());  
224 - unionClickLogs.setAppId(request.getAppid());  
225 - unionClickLogs.setCreateTime(DateUtil.getCurrentTimeSecond());  
226 - unionClickLogsDAO.insertSelective(unionClickLogs);  
227 - }  
228 - });  
229 - }  
230 - 212 +
231 @Override 213 @Override
232 public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException { 214 public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException {
233 try { 215 try {
@@ -257,6 +239,11 @@ public class UnionServiceImpl implements IUnionService { @@ -257,6 +239,11 @@ public class UnionServiceImpl implements IUnionService {
257 } 239 }
258 240
259 saveActivityLog(request); 241 saveActivityLog(request);
  242 + try{
  243 + saveActivityLog(request);
  244 + }catch (Exception e){
  245 + log.error("activity save log error is {}",e.getMessage());
  246 + }
260 247
261 // 组装redis保存的key 248 // 组装redis保存的key
262 String key = ""; 249 String key = "";
@@ -332,8 +319,13 @@ public class UnionServiceImpl implements IUnionService { @@ -332,8 +319,13 @@ public class UnionServiceImpl implements IUnionService {
332 } 319 }
333 320
334 if (StringUtils.isEmpty(value)) { 321 if (StringUtils.isEmpty(value)) {
335 - key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();  
336 - value = yhValueOperations.get(key); 322 + if(StringUtils.isEmpty(request.getClientIp())){
  323 + value = null;
  324 + }else{
  325 + key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
  326 + value = yhValueOperations.get(key);
  327 + }
  328 +
337 log.info("activateUnion with get redis forth with key={}, value={}", key, value); 329 log.info("activateUnion with get redis forth with key={}, value={}", key, value);
338 clickUnion.info("activateUnion with get redis forth with key={}, value={}", key, value); 330 clickUnion.info("activateUnion with get redis forth with key={}, value={}", key, value);
339 } 331 }
@@ -532,6 +524,27 @@ public class UnionServiceImpl implements IUnionService { @@ -532,6 +524,27 @@ public class UnionServiceImpl implements IUnionService {
532 524
533 } 525 }
534 526
  527 +
  528 + //异步记录点击日志表
  529 + private void saveLog(ClickUnionRequestBO request){
  530 + taskExecutor.execute(new Runnable() {
  531 + @Override
  532 + public void run()
  533 + {
  534 + UnionClickLogs unionClickLogs = new UnionClickLogs();
  535 + unionClickLogs.setUnionType(request.getUnion_type());
  536 + unionClickLogs.setTd(request.getTd());
  537 + unionClickLogs.setIdfa(request.getIdfa());
  538 + unionClickLogs.setImei(request.getImei());
  539 + unionClickLogs.setClientIp(request.getClientIp());
  540 + unionClickLogs.setAppKey(request.getAppkey());
  541 + unionClickLogs.setAppId(request.getAppid());
  542 + unionClickLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
  543 + unionClickLogsDAO.insertSelective(unionClickLogs);
  544 + }
  545 + });
  546 + }
  547 +
535 private void saveActivityLog(ActivateUnionRequestBO request){ 548 private void saveActivityLog(ActivateUnionRequestBO request){
536 taskExecutor.execute(new Runnable() { 549 taskExecutor.execute(new Runnable() {
537 @Override 550 @Override