...
|
...
|
@@ -19,6 +19,7 @@ import com.yoho.service.model.union.request.ActivateUnionRequestBO; |
|
|
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.common.redis.RedisListCache;
|
|
|
import com.yoho.unions.common.redis.RedisValueCache;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.common.utils.HttpUtils;
|
...
|
...
|
@@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
import org.springframework.context.ApplicationEventPublisherAware;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.List;
|
...
|
...
|
@@ -70,7 +72,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
|
|
|
@Resource(name="yhValueOperations")
|
|
|
YHValueOperations<String, String> yhValueOperations;
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
IUnionLogsDAO unionLogsDAO;
|
|
|
|
...
|
...
|
@@ -84,6 +86,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
RedisValueCache redisValueCache;
|
|
|
|
|
|
@Resource
|
|
|
RedisListCache redisListCache;
|
|
|
|
|
|
@Resource
|
|
|
IMktMarketingUrlDAO mktMarketingUrlDAO;
|
|
|
|
|
|
@Resource
|
...
|
...
|
@@ -93,6 +98,9 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
IUnionActivityLogsDAO unionActivityLogsDAO;
|
|
|
|
|
|
@Resource
|
|
|
IUnionActivityDAO unionActivityDAO;
|
|
|
|
|
|
@Resource
|
|
|
IUnionTypeMatchDAO unionTypeMatchDAO;
|
|
|
|
|
|
@Resource(name="unionServiceImpl")
|
...
|
...
|
@@ -182,25 +190,18 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
yhValueOperations.set(key, JSON.toJSONString(request));
|
|
|
yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS);
|
|
|
clickUnion.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request));
|
|
|
|
|
|
// log.info("clickUnion set redis success with request={}", request);
|
|
|
|
|
|
// if (union != null) {
|
|
|
// //如果90天以内,已经存在点击记录,则不需要插入或更新数据库
|
|
|
// log.info("clickUnion have click in 90 days with request={}", request);
|
|
|
// return new UnionResponse();
|
|
|
|
|
|
// UnionActivityTrans unionActivityTrans = new UnionActivityTrans();
|
|
|
// List<UnionActivityTrans> list = new ArrayList<>();
|
|
|
// for(int i=0;i<3;i++){
|
|
|
// UnionActivityTrans unionActivityTrans = new UnionActivityTrans();
|
|
|
// unionActivityTrans.setOrdercode("123");
|
|
|
// unionActivityTrans.setUdid("234");
|
|
|
// unionActivityTrans.setOrderAmount(new BigDecimal(12));
|
|
|
// unionActivityTrans.setUid("12");
|
|
|
// list.add(unionActivityTrans);
|
|
|
// }
|
|
|
//保存信息到数据库
|
|
|
// UnionLogs logs = new UnionLogs();
|
|
|
// logs.setTd(request.getTd());
|
|
|
// logs.setAppId(request.getAppid());
|
|
|
// logs.setClientType(request.getClient_type());
|
|
|
// logs.setUnionType(Byte.valueOf(request.getUnion_type()));
|
|
|
// logs.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
// logs.setUpdateTime(logs.getCreateTime());
|
|
|
// logs.setAddParams(JSON.toJSONString(request));
|
|
|
// logs.setIsActivate(Byte.valueOf("0"));
|
|
|
// unionLogsDAO.insert(logs);
|
|
|
// redisListCache.rightPushAll("UNION:KEY:123",list,activeTime.get(),TimeUnit.HOURS);
|
|
|
|
|
|
return new UnionResponse();
|
|
|
} catch (Exception e) {
|
...
|
...
|
@@ -216,25 +217,25 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
// 检查输入参数
|
|
|
if (StringUtils.isEmpty(request.getAppid())) {
|
|
|
log.warn("activateUnion error because appid is empty with param is {}", request);
|
|
|
return new UnionResponse(201, "appid is empty");
|
|
|
return new UnionResponse(200, "appid is empty",new JSONObject());
|
|
|
}
|
|
|
if (StringUtils.isEmpty(request.getTd())) {
|
|
|
log.warn("activateUnion error because td is empty with param is {}", request);
|
|
|
return new UnionResponse(201, "td is empty");
|
|
|
return new UnionResponse(200, "td is empty",new JSONObject());
|
|
|
}
|
|
|
if (StringUtils.isEmpty(request.getUdid())) {
|
|
|
log.warn("activateUnion error because udid is empty with param is {}", request);
|
|
|
return new UnionResponse(201, "udid is empty");
|
|
|
return new UnionResponse(200, "udid is empty",new JSONObject());
|
|
|
}
|
|
|
|
|
|
if (ClientTypeEnum.IOS.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getIdfa())) {
|
|
|
log.warn("activateUnion error because idfa is empty with request is {}", request);
|
|
|
return new UnionResponse(201, "idfa is empty");
|
|
|
return new UnionResponse(200, "idfa is empty",new JSONObject());
|
|
|
}
|
|
|
|
|
|
if (ClientTypeEnum.ANDROID.getName().equals(request.getClient_type()) && StringUtils.isEmpty(request.getImei())) {
|
|
|
log.warn("activateUnion error because imei is empty with request is {}", request);
|
|
|
return new UnionResponse(201, "imei is empty");
|
|
|
return new UnionResponse(200, "imei is empty",new JSONObject());
|
|
|
}
|
|
|
|
|
|
try{
|
...
|
...
|
@@ -315,7 +316,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
value = yhValueOperations.get(key);
|
|
|
if(StringUtils.isNotEmpty(value)){
|
|
|
ipMatch.info("activateUnion with IP params td is {},imei is {},idfa is {},IP is {},---- clickMsg is {}",request.getTd(),request.getImei(),request.getIdfa(),request.getClientIp(),value);
|
|
|
return new UnionResponse(204, "user not click");
|
|
|
return new UnionResponse(200, "user not click",new JSONObject());
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -326,7 +327,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
// 如果redis中不存在存在该用户点击信息,则退出
|
|
|
if (StringUtils.isEmpty(value)) {
|
|
|
log.warn("activateUnion error user not click info. with param is {}", request);
|
|
|
return new UnionResponse(204, "user not click");
|
|
|
return new UnionResponse(200, "user not click",new JSONObject());
|
|
|
}
|
|
|
|
|
|
// 把存储的字符串变为对象
|
...
|
...
|
@@ -348,17 +349,23 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
//强制删除带ip的key
|
|
|
yHRedisTemplate.delete(UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey());
|
|
|
|
|
|
if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
|
|
|
// 如果90天之内有过激活日志,则不允许重复激活
|
|
|
log.warn("activateUnion error because 90 days has activate info with param is {}", request);
|
|
|
return new UnionResponse(203, "have activite in 90 days");
|
|
|
}
|
|
|
String unionTypekey = "yh:union:uniontype:"+click.getUnion_type();
|
|
|
MktMarketingUrl mktMarketingUrl = redisValueCache.get(unionTypekey,MktMarketingUrl.class);
|
|
|
if(mktMarketingUrl==null){
|
|
|
mktMarketingUrl = mktMarketingUrlDAO.selectByPrimaryKey(Long.valueOf(click.getUnion_type()));
|
|
|
redisValueCache.set(unionTypekey, mktMarketingUrl, 1, TimeUnit.HOURS);
|
|
|
}
|
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
result.put("landing_page_url",StringUtils.isEmpty(mktMarketingUrl.getLandingPageUrl()) ? "" : mktMarketingUrl.getLandingPageUrl());
|
|
|
|
|
|
if (union != null && union.getIsActivate() != null && union.getIsActivate().byteValue() == 1) {
|
|
|
// 如果90天之内有过激活日志,则不允许重复激活
|
|
|
log.warn("activateUnion error because 90 days has activate info with param is {}", request);
|
|
|
return new UnionResponse(200, "have activite in 90 days",result);
|
|
|
}
|
|
|
// UnionTypeModel u = UnionConstant.unionTypeMap.get(Integer.parseInt(click.getUnion_type()));
|
|
|
|
|
|
UnionTypeModel u = new UnionTypeModel();
|
|
|
u.setName(mktMarketingUrl.getName());
|
|
|
u.setValue(String.valueOf(mktMarketingUrl.getUnionType()));
|
...
|
...
|
@@ -406,7 +413,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
j.put("tdid", request.getTdid());
|
|
|
activeDingdang.info(j.toString());
|
|
|
}
|
|
|
return new UnionResponse(203, "have activite in 90 days");
|
|
|
return new UnionResponse(200, "have activite in 90 days",result);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -489,7 +496,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
}
|
|
|
if (StringUtils.isEmpty(url)) {
|
|
|
log.info("activateUnion in success request is {}", request);
|
|
|
return new UnionResponse();
|
|
|
return new UnionResponse(200,"success",result);
|
|
|
}
|
|
|
if(!"3".equals(union_type)||!"100000000000453".equals(union_type)){
|
|
|
url = URLDecoder.decode(url, "UTF-8");
|
...
|
...
|
@@ -506,21 +513,26 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
activeUnion.info("activateUnion call union success url={}, and result={}", url, pair);
|
|
|
if (pair.getLeft() != 200) {
|
|
|
log.warn("callback error with request={}", request);
|
|
|
return new UnionResponse(204, "callback error");
|
|
|
return new UnionResponse(200, "callback error",result);
|
|
|
}
|
|
|
//如果来源是广点通,则把广点通的一些信息记入表,给之后做转化上报使用
|
|
|
if(union_type.equals("3")){
|
|
|
saveUnionActivity(click,request);
|
|
|
}
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("callback error with request={}", request, e);
|
|
|
//return new UnionResponse(204, "callback error");
|
|
|
}
|
|
|
|
|
|
|
|
|
activeUnion.info("activateUnion in success request is {}", request);
|
|
|
|
|
|
return new UnionResponse();
|
|
|
|
|
|
return new UnionResponse(200,"success",result);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("activateUnion error with request={}", request, e);
|
|
|
return new UnionResponse(300, e.getMessage());
|
|
|
return new UnionResponse(200, e.getMessage(),new JSONObject());
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -567,6 +579,30 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher |
|
|
});
|
|
|
}
|
|
|
|
|
|
private void saveUnionActivity(ClickUnionRequestBO click,ActivateUnionRequestBO request){
|
|
|
taskExecutor.execute(new Runnable(){
|
|
|
@Override
|
|
|
public void run()
|
|
|
{
|
|
|
UnionActivity unionActivity = new UnionActivity();
|
|
|
unionActivity.setClientType(request.getClient_type());
|
|
|
unionActivity.setUdid(request.getUdid());
|
|
|
if(StringUtils.isNotEmpty(click.getIdfa())){
|
|
|
unionActivity.setUdid(click.getIdfa());
|
|
|
}else {
|
|
|
unionActivity.setUdid(click.getImei());
|
|
|
}
|
|
|
unionActivity.setUnionType(click.getUnion_type());
|
|
|
//广点通的账号id存入的是click的commonUse字段
|
|
|
unionActivity.setAdvertiserId(click.getCommonUse());
|
|
|
//广点通点击id
|
|
|
unionActivity.setClickId(click.getClickId());
|
|
|
unionActivity.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionActivityDAO.insertSelective(unionActivity);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
this.publisher = applicationEventPublisher;
|
...
|
...
|
|