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 {
log.warn("activateUnion error with param is {}", vo);
return new ActiveUnionResponseBO(600, "error");
}
bo.setClientIp(RemoteIPInterceptor.getRemoteIP());
//IP取出来的有可能是42.239.40.36,123.151.42.50,只取第一个
String IP = RemoteIPInterceptor.getRemoteIP();
String clientIp = null;
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
bo.setClientIp(clientIp);
//多线程处理
exe.execute(new RunActivate(bo));
return new ActiveUnionResponseBO(200, "success");
... ...
... ... @@ -66,7 +66,14 @@ public class ClickUnionRest {
if ("iphone".equals(request.getClient_type())) {
request.setClient_type(ClientTypeEnum.IOS.getName());
}
request.setClientIp(RemoteIPInterceptor.getRemoteIP());
String IP = RemoteIPInterceptor.getRemoteIP();
// String IP = "42.236.215.29, 123.151.42.48";
String clientIp = null;
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
request.setClientIp(clientIp);
clickUnion.info("addUnion with param is {}", request);
UnionResponse response = unionService.clickUnion(request);
log.info("addUnion with result is {}, and request is {}", response, request);
... ... @@ -91,8 +98,13 @@ public class ClickUnionRest {
}else {
request = unionService.clickHttpRequestTOBO(httpServletRequest,request);
}
request.setClientIp(RemoteIPInterceptor.getRemoteIP());
String IP = RemoteIPInterceptor.getRemoteIP();
String clientIp = null;
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
request.setClientIp(clientIp);
// IUnionService service = SpringContextUtil.getBean(bean, IUnionService.class);
clickUnion.info("addCommonUnion request is {}",request);
UnionResponse response = unionService.clickUnion(request);
... ... @@ -111,7 +123,13 @@ public class ClickUnionRest {
public void addUnion4Special(ClickUnionRequestBO bo, HttpServletRequest request, HttpServletResponse response) {
log.info("addUnion4Special with param is {}", bo);
try {
bo.setClientIp(RemoteIPInterceptor.getRemoteIP());
String clientIp = null;
String IP = RemoteIPInterceptor.getRemoteIP();
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
bo.setClientIp(clientIp);
String agent = request.getHeader("user-agent");
log.info("user-agent={}", agent);
if (StringUtils.isEmpty(agent)) {
... ... @@ -162,7 +180,13 @@ public class ClickUnionRest {
if (StringUtils.isEmpty(bo.getUnion_type())) {
return;
}
bo.setClientIp(RemoteIPInterceptor.getRemoteIP());
String clientIp = null;
String IP = RemoteIPInterceptor.getRemoteIP();
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
bo.setClientIp(clientIp);
bo.setClient_type("android");
bo.setAppid("com.yoho");
String agent = request.getHeader("user-agent");
... ... @@ -222,8 +246,14 @@ public class ClickUnionRest {
String key = e.nextElement();
log.info("addMonitor with key={}, value={}", key, request.getParameter(key));
}
String IP = RemoteIPInterceptor.getRemoteIP();
String clientIp = null;
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
bo.setClientIp(RemoteIPInterceptor.getRemoteIP());
bo.setClientIp(clientIp);
String agent = request.getHeader("user-agent");
log.info("addMonitor user-agent={}", agent);
try{
... ...
... ... @@ -65,7 +65,13 @@ public class MobvistaUnionRest {
req.setAppid("android");
downloadURL = "http://cdn.yoho.cn/app-downfiles/yohoBuy_YOHO_2953.apk";
}
req.setIp(RemoteIPInterceptor.getRemoteIP());
String clientIp = null;
String IP = RemoteIPInterceptor.getRemoteIP();
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
req.setIp(clientIp);
String url = "http://stat.mobvista.com/install?mobvista_pl="+req.getDevice_type()+"&mobvista_campuuid="+req.getUuid()+""
+ "&mobvista_ip="+req.getIp()+"&mobvista_clickid="+req.getClickid()+"&mobvista_gaid=&mobvista_devid=";
req.setCallbackurl(url);
... ...
... ... @@ -9,6 +9,7 @@ import com.yoho.service.model.union.request.ClickUnionRequestBO;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.interceptor.RemoteIPInterceptor;
import org.apache.commons.lang.StringUtils;
import javax.servlet.http.HttpServletRequest;
... ... @@ -37,7 +38,14 @@ public interface IUnionService {
clickUnionRequestBO.setUnion_type(request.getParameter("union_type"));
clickUnionRequestBO.setImei(request.getParameter("imei"));
clickUnionRequestBO.setTd(request.getParameter("td"));
clickUnionRequestBO.setClientIp(RemoteIPInterceptor.getRemoteIP());
String clientIp = null;
String IP = RemoteIPInterceptor.getRemoteIP();
if(StringUtils.isNotEmpty(IP)){
String[] IPS = IP.split(",");
clientIp = IPS[0];
}
clickUnionRequestBO.setClientIp(clientIp);
return clickUnionRequestBO;
}
... ...
... ... @@ -3,6 +3,7 @@
*/
package com.yoho.unions.server.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.netflix.config.DynamicIntProperty;
... ... @@ -30,7 +31,6 @@ import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.net.URLDecoder;
import java.util.List;
... ... @@ -127,12 +127,14 @@ public class UnionServiceImpl implements IUnionService {
log.warn("clickUnion error because union_type is error with param is {}", request);
return new UnionResponse(201, "union_type is error");
}
//异步记录日志表,以后查询日志方便
try {
saveLog(request);
} catch (Exception e) {
log.error("", e);
}
//组装redis保存的key
String key;
if (StringUtils.isNotEmpty(request.getIdfa())) {
... ... @@ -207,27 +209,7 @@ public class UnionServiceImpl implements IUnionService {
return new UnionResponse(300, e.getMessage());
}
}
//异步记录点击日志表
private void saveLog(ClickUnionRequestBO request){
taskExecutor.execute(new Runnable() {
@Override
public void run()
{
UnionClickLogs unionClickLogs = new UnionClickLogs();
unionClickLogs.setUnionType(request.getUnion_type());
unionClickLogs.setTd(request.getTd());
unionClickLogs.setIdfa(request.getIdfa());
unionClickLogs.setImei(request.getImei());
unionClickLogs.setClientIp(request.getClientIp());
unionClickLogs.setAppKey(request.getAppkey());
unionClickLogs.setAppId(request.getAppid());
unionClickLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
unionClickLogsDAO.insertSelective(unionClickLogs);
}
});
}
@Override
public UnionResponse activateUnion(ActivateUnionRequestBO request) throws ServiceException {
try {
... ... @@ -257,6 +239,11 @@ public class UnionServiceImpl implements IUnionService {
}
saveActivityLog(request);
try{
saveActivityLog(request);
}catch (Exception e){
log.error("activity save log error is {}",e.getMessage());
}
// 组装redis保存的key
String key = "";
... ... @@ -332,8 +319,13 @@ public class UnionServiceImpl implements IUnionService {
}
if (StringUtils.isEmpty(value)) {
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
value = yhValueOperations.get(key);
if(StringUtils.isEmpty(request.getClientIp())){
value = null;
}else{
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
value = yhValueOperations.get(key);
}
log.info("activateUnion with get redis forth with key={}, value={}", key, value);
clickUnion.info("activateUnion with get redis forth with key={}, value={}", key, value);
}
... ... @@ -532,6 +524,27 @@ public class UnionServiceImpl implements IUnionService {
}
//异步记录点击日志表
private void saveLog(ClickUnionRequestBO request){
taskExecutor.execute(new Runnable() {
@Override
public void run()
{
UnionClickLogs unionClickLogs = new UnionClickLogs();
unionClickLogs.setUnionType(request.getUnion_type());
unionClickLogs.setTd(request.getTd());
unionClickLogs.setIdfa(request.getIdfa());
unionClickLogs.setImei(request.getImei());
unionClickLogs.setClientIp(request.getClientIp());
unionClickLogs.setAppKey(request.getAppkey());
unionClickLogs.setAppId(request.getAppid());
unionClickLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
unionClickLogsDAO.insertSelective(unionClickLogs);
}
});
}
private void saveActivityLog(ActivateUnionRequestBO request){
taskExecutor.execute(new Runnable() {
@Override
... ...