Authored by DengXinFei

Merge branch 'master' of git.yoho.cn:yoho30/yohobuy-union

... ... @@ -39,5 +39,5 @@ public interface IUnionLogsDAO {
List<UnionLogs> queryByDeviceId(ActivateDeviceIdReqBO activateDeviceIdReqBO);
List<ActivateDeviceIdRspBO> selectListByHour(ActivateDeviceIdReqBO activateDeviceIdReqBO);
List<UnionLogs> selectListByHour(ActivateDeviceIdReqBO activateDeviceIdReqBO);
}
... ...
... ... @@ -188,9 +188,9 @@
</if>
limit 1
</select>
<select id="selectListByHour" resultMap="ActivateMap"
<select id="selectListByHour" resultMap="BaseResultMap"
parameterType="com.yoho.service.model.union.request.ActivateDeviceIdReqBO">
select union_type,union_name,count(idfa) as idfa_count,count(imei) as imei_count
select <include refid="Base_Column_List"/>
from union_logs
where union_type = #{unionType}
<if test="activateHourBegin != null and activateHourBegin>0">
... ...
... ... @@ -122,15 +122,23 @@ public class PinYouServiceImpl implements IPinYouService {
//客户端ip
String ip = requestBO.getIp();
//debug flag
String df = "0";
//按照品友的格式进行拼接
String df = "0";
StringBuffer stringBuffer = new StringBuffer();
stringBuffer = stringBuffer.append(PINYOU_VIEW_URL).append("a=")
.append(advertiser).append("&os=").append(os)
.append("&ts=").append(ts)
.append("&jp=1").append("&ip=").append(ip)
.append("&event=").append(event)
.append("&event_vaule=").append(event_value).append("&df=0");
.append("&event=").append(event);
//由于搜索行为,event_value会有特殊字符,例如空格,所以需要URLEncode一下
if(event.equals(EnentValueEnum.VIEW_SEARCH.getName())){
try{
event_value = URLEncoder.encode(event_value,"UTF-8");
}catch (Exception e){
log.warn("URLEncode error message is {}",e.getMessage());
}
}
stringBuffer = stringBuffer.append("&event_vaule=").append(event_value).append("&df=0");
String url = null;
if (event.equals(EnentValueEnum.ADD_CART.getName()) || event.equals(EnentValueEnum.VIEW_ITEM.getName())) {
stringBuffer = stringBuffer.append("&p=").append(event_value);
... ... @@ -157,6 +165,7 @@ public class PinYouServiceImpl implements IPinYouService {
String advertiser = "MC.LF";
//操作系统信息
String os = requestBO.getOs();
String encode = null;
//根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
String client_type = ClientTypeEnum.IOS.getName();
os = ClientTypeEnum.IOS.getName();
... ... @@ -204,9 +213,9 @@ public class PinYouServiceImpl implements IPinYouService {
stringBuffer = stringBuffer.append("&uid=").append(user_id);
}
if (orderStatus.equals("1") || orderStatus.equals("2")) {
stringBuffer = stringBuffer.append("&gl=9466");
stringBuffer = stringBuffer.append("&gl=10593");
} else {
stringBuffer = stringBuffer.append("&gl=334");
stringBuffer = stringBuffer.append("&gl=10594");
}
url = stringBuffer.toString();
UnionResponse response = sendUrl(url);
... ... @@ -216,13 +225,12 @@ public class PinYouServiceImpl implements IPinYouService {
public UnionResponse sendUrl(String url) {
log.info("pinyou sendUrl url is {}", url);
try {
url = URLEncoder.encode(url, "UTF-8");
Pair<Integer, String> pair = HttpUtils.httpGet(url);
log.info("pinyou sendUrl union success url={}, and result={}", url, pair);
if (pair.getLeft() != 200) {
log.warn("pinyou callback error with request={}", url);
url = URLDecoder.decode(url,"UTF-8");
redisListCache.rightPushAll(UNION_SENDFAIL_KEY,url,24, TimeUnit.HOURS);
// url = URLDecoder.decode(url,"UTF-8");
// redisListCache.rightPushAll(UNION_SENDFAIL_KEY,url,4, TimeUnit.MINUTES);
return new UnionResponse(204, "callback error");
}
} catch (Exception e) {
... ... @@ -230,4 +238,6 @@ public class PinYouServiceImpl implements IPinYouService {
}
return new UnionResponse();
}
}
... ...
... ... @@ -7,6 +7,7 @@ package com.yoho.unions.server.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.netflix.config.DynamicIntProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.yoho.core.common.utils.MD5;
... ... @@ -48,6 +49,7 @@ import javax.annotation.Resource;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
... ... @@ -205,7 +207,7 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
clickUnion.info("clickUnion set redis with key={}, value={}", key, JSON.toJSONString(request));
yhValueOperations.set(key, JSON.toJSONString(request));
String invalidTime = "activeTime"+"_"+request.getUnion_type();
DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty(invalidTime, 3);
DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty(invalidTime, 48);
yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.HOURS);
... ... @@ -830,29 +832,51 @@ public class UnionServiceImpl implements IUnionService,ApplicationEventPublisher
public PageActivateDeviceIdRspBO queryActivateHour(ActivateDeviceIdReqBO activateDeviceIdReqBO) {
log.info("enter queryActivateHour. param activateDeviceIdReqBO={}", activateDeviceIdReqBO);
//(1).查询出各渠道激活的设备id数
List<ActivateDeviceIdRspBO> activateDeviceIdRspList = Lists.newArrayList();
int beginTime = DateUtils.getTodayZero();
//1.初始化map,用于存放24个小时的激活idfa和imei
Map<Integer,List<Integer>> countMap = Maps.newHashMap();
for(int i=0;i<24;i++){
activateDeviceIdReqBO.setActivateHourBegin(beginTime);
activateDeviceIdReqBO.setActivateHourEnd(beginTime+3600);
activateDeviceIdRspList.addAll(unionLogsDAO.selectListByHour(activateDeviceIdReqBO));
beginTime +=3600;
List<Integer> countList = Lists.newArrayList();
countList.add(0);
countList.add(0);
countMap.put(i,countList);
}
String searchDay = DateUtils.int2DateStr(activateDeviceIdReqBO.getActivateTimeEnd(),"yyyy/MM/dd");
int beginTime = DateUtils.getTimesmorning(searchDay);
int endTime = beginTime+3600*24-1;
activateDeviceIdReqBO.setActivateHourBegin(beginTime);
activateDeviceIdReqBO.setActivateHourEnd(endTime);
//2.查询出一个渠道一天的激活数
List<UnionLogs> unionLogs = unionLogsDAO.selectListByHour(activateDeviceIdReqBO);
for(int i=0;i<unionLogs.size();i++){
UnionLogs unionLog = unionLogs.get(i);
String createTime = DateUtils.int2DateStr(unionLog.getCreateTime(),"yyyy-MM-dd HH:mm:ss");
//3.遍历一天的记录,统计每小时的激活数
int key = Integer.parseInt(createTime.substring(11,13));
List<Integer> countList = countMap.get(key);
//list第一个元素是idfa的激活数
if(StringUtils.isNotEmpty(unionLog.getIdfa())){
countList.set(0,countList.get(0)+1);
}
//list第二个元素是idfa的激活数
if (StringUtils.isNotEmpty(unionLog.getImei())){
countList.set(1,countList.get(1)+1);
}
}
List<ActivateDeviceIdRspBO> activateDeviceIdRspList = Lists.newArrayList();
for(int i=0;i<24;i++){
ActivateDeviceIdRspBO bo = activateDeviceIdRspList.get(i);
ActivateDeviceIdRspBO bo = new ActivateDeviceIdRspBO();
String hour = i<10?"0"+i+":00--"+"0"+i+":59":i+":00--"+i+":59";
bo.setHour(hour);
List<Integer> countList = countMap.get(i);
bo.setIdfaCount(countList.get(0));
bo.setImeiCount(countList.get(1));
activateDeviceIdRspList.add(bo);
}
PageActivateDeviceIdRspBO pageActivateDeviceIdRspBO = new PageActivateDeviceIdRspBO();
pageActivateDeviceIdRspBO.setList(activateDeviceIdRspList);
//不需要分页了
// pageActivateDeviceIdRspBO.setTotal(total);
// pageActivateDeviceIdRspBO.setPage(activateDeviceIdReqBO.getPage());
return pageActivateDeviceIdRspBO;
}
... ...
... ... @@ -59,7 +59,6 @@ public class PinYouTask {
//从redis里面获取大数据的数据
Long viewSize = redisListCache.size(UNION_VIEW_KEY);
Long transSize = redisListCache.size(UNION_TRANS_KEY);
Long failSize = redisListCache.size(UNION_SENDFAIL_KEY);
List<ViewPinYouRequestBO> viewPinYouRequestBOList = new ArrayList<>();
int viewSizeInt = viewSize == null ? 0 : viewSize.intValue();
int transSizeInt = transSize == null ? 0:transSize.intValue();
... ... @@ -68,7 +67,6 @@ public class PinYouTask {
if(transSizeInt>0){
for(int i=0; i < limit; i++){
TransPinYouRequestBO transPinYouRequestBO = redisListCache.rightPop(UNION_TRANS_KEY, TransPinYouRequestBO.class);
log.info("transPinYouRequestBO is {}",transPinYouRequestBO);
transPinYouRequestBOList.add(transPinYouRequestBO);
}
}
... ... @@ -80,13 +78,6 @@ public class PinYouTask {
}
}
if(failSize>0){
for(int i=0;i<failSize;i++){
String failUrl = redisListCache.rightPop(UNION_SENDFAIL_KEY,String.class);
pinYouService.sendUrl(failUrl);
}
}
if(CollectionUtils.isNotEmpty(transPinYouRequestBOList)){
log.info("transPinYouRequestBOList size is {}",transPinYouRequestBOList.size());
for(TransPinYouRequestBO transPinYouRequestBO:transPinYouRequestBOList){
... ...
... ... @@ -47,9 +47,9 @@ web.context=union
draw.writeFile.delay=${draw.writeFile.delay}
#广点通 7*24
activeTime_3=24
activeTime_3=48
#今日头条 24
activeTime_4=24
activeTime_4=48
#付费渠道
activeTime_pay_channel=90
... ...
... ... @@ -39,12 +39,19 @@
});
function getId() {
var params = {};
var params = getParam("searchForm");
params["unionType"] = unionType;
return params;
}
});
function getParam(table) {
var paramsArray = $("#"+table+"").serializeArray();
var params = {};
for (var i = 0; i < paramsArray.length; i++) {
params[paramsArray[i].name] = paramsArray[i].value;
}
return params;
}
</script>
\ No newline at end of file
... ...
... ... @@ -343,14 +343,21 @@
function showActivateHour(id) {
unionType = id;
var div = $("<div>").appendTo($(window.self.document.body));
var params = getParam("searchForm");
params['unionType'] = $(this).attr("dataId");
window.self.$(div).myDialog({
modal : true,
collapsible : true,
cache : false,
title : "每小时点击量",
title : "每小时激活量",
width: 600,
height: 600,
href: contextPath + "/admin/activateHour.html?unionType="+id,
href: contextPath + "/admin/activateHour.html",
queryParams: {
unionType: id,
activateTimeEnd:params['activateTimeEnd']
},
buttons : [{
id : "closeBtn",
text : "关闭",
... ...
package com.test;
import com.yoho.core.common.utils.MD5;
import com.yoho.service.model.union.response.UnionResponse;
import com.yoho.unions.common.enums.ClientTypeEnum;
import com.yoho.unions.common.enums.EnentValueEnum;
import com.yoho.unions.common.utils.DateUtil;
import org.apache.commons.lang.StringUtils;
import java.net.URLEncoder;
/**
* Created by dell on 2017/3/15.
*/
public class PinyouTest {
public static void main (String args[]){
String PINYOU_VIEW_URL = "http://stats.ipinyou.com/madv?";
//广告主信息
String advertiser = "MC.LF";
//操作系统信息
String os = "android";
os = ClientTypeEnum.IOS.getName();
//根据从大数据获取的IDFA,IMEI来判断是安卓还是IOS
String client_type = ClientTypeEnum.IOS.getName();
String idfa = "";
String imei = "87394281384";
if (idfa.equals("") || StringUtils.isEmpty(idfa)) {
client_type = ClientTypeEnum.ANDROID.getName();
os = ClientTypeEnum.ANDROID.getName();
}
//时间戳
String ts = "1489468089724";
if (StringUtils.isEmpty(ts)) {
ts = String.valueOf(DateUtil.getCurrentTimeSecond() * 1000);
}
//启动参数,固定位1
String jp = "1";
//用户id
String user_id = "123";
boolean isNum = user_id.matches("[0-9]+");
//用户行为事件
String event = "addCart";
//用户行为数据
String event_value = "三叶草女 卫衣";
//客户端ip
String ip = "171.88.1.219";
//debug flag
String df = "0";
//按照品友的格式进行拼接
StringBuffer stringBuffer = new StringBuffer();
stringBuffer = stringBuffer.append(PINYOU_VIEW_URL).append("a=")
.append(advertiser).append("&os=").append(os)
.append("&ts=").append(ts)
.append("&jp=1").append("&ip=").append(ip)
.append("&event=").append(event);
//由于搜索行为,event_value会有特殊字符,例如空格,所以需要URLEncode一下
if(event.equals(EnentValueEnum.VIEW_SEARCH.getName())){
try{
event_value = URLEncoder.encode(event_value,"UTF-8");
}catch (Exception e){
// log.warn("URLEncode error message is {}",e.getMessage());
}
}
stringBuffer = stringBuffer.append("&event_vaule=").append(event_value).append("&df=0");
String url = null;
if (event.equals(EnentValueEnum.ADD_CART.getName()) || event.equals(EnentValueEnum.VIEW_ITEM.getName())) {
stringBuffer = stringBuffer.append("&p=").append(event_value);
}
if (StringUtils.isNotEmpty(user_id) && user_id.matches("[0-9]+")) {
stringBuffer = stringBuffer.append("&uid=").append(user_id);
}
if (client_type.equalsIgnoreCase(ClientTypeEnum.ANDROID.getName())) {
//如果是浏览商品和加入购物车则需要传p=商品编号
String dim = MD5.md5(imei);
stringBuffer = stringBuffer.append("&dim=").append(dim);
}
if (client_type.equalsIgnoreCase(ClientTypeEnum.IOS.getName())) {
String iam = MD5.md5(idfa);
stringBuffer = stringBuffer.append("&iam=").append(iam);
}
url = stringBuffer.toString();
System.out.print(url);
}
}
... ...