Commit 5d65517d authored by 宋新宇's avatar 宋新宇

抖小更改及监测

parent ccfedbac
...@@ -78,7 +78,9 @@ public class UniversalProcess { ...@@ -78,7 +78,9 @@ public class UniversalProcess {
public long incrby(String key, int increment) { public long incrby(String key, int increment) {
return redisTemplate.opsForValue().increment(key,increment); return redisTemplate.opsForValue().increment(key,increment);
} }
public void del(String key) {
redisTemplate.delete(key);
}
/******************************************** INNER CLASS ******************************************************/ /******************************************** INNER CLASS ******************************************************/
......
package com.lwby.marketing.att.dyvideo; package com.lwby.marketing.att.dyvideo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alicp.jetcache.anno.CacheRefresh; import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.CacheType; import com.alicp.jetcache.anno.CacheType;
...@@ -10,7 +11,9 @@ import com.lwby.marketing.att.UniversalProcess; ...@@ -10,7 +11,9 @@ import com.lwby.marketing.att.UniversalProcess;
import com.lwby.marketing.att.CallBackType; import com.lwby.marketing.att.CallBackType;
import com.lwby.marketing.att.novel.AttributionType; import com.lwby.marketing.att.novel.AttributionType;
import com.lwby.marketing.po.ThirdAccountDy; import com.lwby.marketing.po.ThirdAccountDy;
import com.lwby.marketing.po.VideoUpload;
import com.lwby.marketing.util.CacheKeyUtils; import com.lwby.marketing.util.CacheKeyUtils;
import com.lwby.marketing.util.DateTimUtils;
import com.lwby.marketing.util.HttpUtil; import com.lwby.marketing.util.HttpUtil;
import com.lwby.marketing.vo.AppChannelVO; import com.lwby.marketing.vo.AppChannelVO;
import com.lwby.marketing.vo.DeliveryDeviceInfo; import com.lwby.marketing.vo.DeliveryDeviceInfo;
...@@ -18,6 +21,7 @@ import com.lwby.marketing.vo.StoryNovelAction; ...@@ -18,6 +21,7 @@ import com.lwby.marketing.vo.StoryNovelAction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -51,6 +55,13 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -51,6 +55,13 @@ public class DyVideoUniversalProcess extends UniversalProcess {
private static final String tokenDyProdUrl = "https://open.douyin.com/oauth/client_token/"; private static final String tokenDyProdUrl = "https://open.douyin.com/oauth/client_token/";
private static final String lottoDevUrl = "http://47.98.241.45:19005/xs/";
private static final String lottoProdUrl = "https://alb.xiaoshidata.com/xs/";
@Autowired
private Environment env;
/** /**
* 通知处理结果 * 通知处理结果
*/ */
...@@ -83,6 +94,24 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -83,6 +94,24 @@ public class DyVideoUniversalProcess extends UniversalProcess {
); );
} }
public void notifyResult(String openId,VideoUpload videoUpload) {
DeliveryDeviceInfo ddi = new DeliveryDeviceInfo();
ddi.setIs_call(8);
ddi.setUserId(videoUpload.getUserId());
ddi.setDevice_id(String.valueOf(videoUpload.getUserId()));
ddi.setActive_time(System.currentTimeMillis());
ddi.setChannel(videoUpload.getChannel());
ddi.setOpenId(openId);
String jsonString = JSONObject.toJSONString(ddi);
ListenableFuture<SendResult<String, String>> active_result = storyKafkaTemplate.send("ocpc_behavior", jsonString);
active_result.addCallback(
result -> DYVIDEO_SYS_LOG.info("归因成功[{}],归因类型[{}]", jsonString, "关键行为"),
ex -> DYVIDEO_ERROR_LOG.error("归因失败[{}],归因类型[{}]", jsonString, "关键行为", ex)
);
}
public <T> T getOld(Class<T> clazz, String key) { public <T> T getOld(Class<T> clazz, String key) {
String value = oldMarketRedisTemplate.opsForValue().get(key); String value = oldMarketRedisTemplate.opsForValue().get(key);
if(!Objects.isNull(value)){ if(!Objects.isNull(value)){
...@@ -120,7 +149,7 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -120,7 +149,7 @@ public class DyVideoUniversalProcess extends UniversalProcess {
public String getFirstCheckerKey(StoryNovelAction action) { public String getFirstCheckerKey(StoryNovelAction action) {
return Objects.equals(action.getType(), CallBackType.active.getType()) return Objects.equals(action.getType(), CallBackType.active.getType())
? String.format("fc_%d_%d_%s_%s", action.getUserId(), action.getPlatformId(),action.getMediaName(),action.getCurrentDateStr()) ? String.format("fc_%d_%d_%s_%s", action.getUserId(), action.getPlatformId(),action.getMediaName(),action.getCurrentDateStr())
: String.format("fc_%d_%d_%s", action.getUserId(), action.getPlatformId(),action.getMediaName()); : String.format("fc_%s_%d_%s", action.getOpenId(), action.getPlatformId(),action.getMediaName());
} }
public int getExpire(StoryNovelAction action) { public int getExpire(StoryNovelAction action) {
...@@ -151,7 +180,7 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -151,7 +180,7 @@ public class DyVideoUniversalProcess extends UniversalProcess {
thirdAccountDy.setClientId(client_id); thirdAccountDy.setClientId(client_id);
String tokenDy = "token_dy_" + client_id; String tokenDy = "token_dy_" + client_id;
//往老的market缓存写,防止token一直失效 //往老的market缓存写,防止token一直失效
setToken(tokenDy, Integer.parseInt(String.valueOf(expiresIn)),JSON.toJSONString(thirdAccountDy)); set(tokenDy, Integer.parseInt(String.valueOf(expiresIn)),JSON.toJSONString(thirdAccountDy));
} else { } else {
log.warn("dy_access_token_error,code={},resultdy={}", resultCode, JSONObject.toJSONString(result)); log.warn("dy_access_token_error,code={},resultdy={}", resultCode, JSONObject.toJSONString(result));
} }
...@@ -243,7 +272,7 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -243,7 +272,7 @@ public class DyVideoUniversalProcess extends UniversalProcess {
DYVIDEO_SYS_LOG.info("DouyinBehaviorKafkaConsumer.douyin code error,userId={},result={}",userId,JSON.toJSONString(result)); DYVIDEO_SYS_LOG.info("DouyinBehaviorKafkaConsumer.douyin code error,userId={},result={}",userId,JSON.toJSONString(result));
if (resultCode == 28001008) { if (resultCode == 28001008) {
//删除授权过期token //删除授权过期token
delToken(tokenDy); del(tokenDy);
getDyAccessToken(dyMarketPlatformAppIdList.get(0), dyMarketPlatformAppIdList.get(1), Objects.equals(env.getActiveProfiles()[0],"prod") ? tokenDyProdUrl : tokenDyDevUrl); getDyAccessToken(dyMarketPlatformAppIdList.get(0), dyMarketPlatformAppIdList.get(1), Objects.equals(env.getActiveProfiles()[0],"prod") ? tokenDyProdUrl : tokenDyDevUrl);
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.douyin code auth token expired,userId={},result={}",userId,JSON.toJSONString(result)); DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.douyin code auth token expired,userId={},result={}",userId,JSON.toJSONString(result));
} }
...@@ -259,4 +288,108 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -259,4 +288,108 @@ public class DyVideoUniversalProcess extends UniversalProcess {
return resultCountMap; return resultCountMap;
} }
public void uploadCallbackUserInfo(StoryNovelAction action) {
VideoUpload videoUpload = action.getVideoUpload();
String url = Objects.equals(env.getActiveProfiles()[0],"prod") ? lottoProdUrl : lottoDevUrl;
String result = "";
Integer resultCode = -1;
try {
url += "microapp/gy/info/apxsbkjc";
Map<String, Object> map = new HashMap<>();
map.put("adId",videoUpload.getAdid());
map.put("creativeId",videoUpload.getCreativeId());
map.put("event_time", DateTimUtils.getCurrentTimeString());
map.put("openId",action.getOpenId());
map.put("channel",action.getChannelId());
result = HttpUtil.post(url, JSONObject.toJSONString(map));
resultCode = (Integer) JSON.parseObject(result).get("code");
if (resultCode == 0) {
DYVIDEO_SYS_LOG.info("dyvideo upload user success,result={},videoUpload={}",JSONObject.toJSONString(result),JSONObject.toJSONString(videoUpload));
} else {
DYVIDEO_ERROR_LOG.error("dyvideo upload user fail,result={},videoUpload={}",JSONObject.toJSONString(result),JSONObject.toJSONString(videoUpload));
}
} catch (Throwable e) {
DYVIDEO_ERROR_LOG.error("dyvideo upload user error,videoUpload={}",JSONObject.toJSONString(videoUpload));
}
}
public void uploadCallbackAdsInfo(StoryNovelAction action, String jsonBody) {
VideoUpload videoUpload = action.getVideoUpload();
String url = Objects.equals(env.getActiveProfiles()[0],"prod") ? lottoProdUrl : lottoDevUrl;
String result = "";
Integer resultCode = -1;
try {
url += "microapp/record/info/apxsbkjc";
result = HttpUtil.post(url, jsonBody);
resultCode = (Integer) JSON.parseObject(result).get("code");
if (resultCode == 0) {
DYVIDEO_SYS_LOG.info("dyvideo upload user success,result={},videoUpload={}",JSONObject.toJSONString(result),JSONObject.toJSONString(videoUpload));
} else {
DYVIDEO_ERROR_LOG.error("dyvideo upload user fail,result={},videoUpload={}",JSONObject.toJSONString(result),JSONObject.toJSONString(videoUpload));
}
} catch (Throwable e) {
DYVIDEO_ERROR_LOG.error("dyvideo upload user error,videoUpload={}",JSONObject.toJSONString(videoUpload));
}
}
public JSONArray getUploadAdsInfo(JSONArray jsonArray,Date day, StoryNovelAction action, String accessToken, String tokenDy,
List<String> dyMarketPlatformAppIdList, Environment env) {
int pageNumer = 1;
long userId = action.getUserId();
String openId = action.getOpenId();
String cursor = null;
for (int i=1 ; i<= pageNumer ; i++) {
Map<String,Object> mp = new HashMap<>();
mp.put("open_id",openId);
mp.put("date_hour",dfh.format(day));
if (cursor != null) {
mp.put("cursor",cursor);
}
String mapAction = JSONObject.toJSONString(mp);
try {
String result = HttpUtil.postDy(url, mapAction,accessToken);
Integer resultCode = (Integer) JSON.parseObject(result).get("err_no");
if (resultCode == 0) {
Map dataMap = (Map) JSON.parseObject(result).get("data");
List<JSONObject> records = (List<JSONObject>)dataMap.get("records");
String next_cursor = (String)dataMap.get("next_cursor");
if (records != null && records.size()>0) {
for(JSONObject jsonObject : records) {
JSONObject obj = new JSONObject();
obj.put("cost",jsonObject.getString("cost"));
obj.put("open_id",jsonObject.getString("open_id"));
obj.put("id",jsonObject.getString("id"));
obj.put("event_time",DateTimUtils.getCurrentTimeString(
new Date(Long.parseLong(jsonObject.getString("event_time")))));
obj.put("event_name",jsonObject.getString("ad_type"));
jsonArray.add(obj);
}
}
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.douyin code succ,userId={},result={}",userId,JSON.toJSONString(result));
if (records != null && records.size() == 500) {
pageNumer ++;
cursor = next_cursor;
}
} else {
DYVIDEO_SYS_LOG.info("getUploadAdsInfo.douyin code error,userId={},result={}",userId,JSON.toJSONString(result));
if (resultCode == 28001008) {
//删除授权过期token
delToken(tokenDy);
getDyAccessToken(dyMarketPlatformAppIdList.get(0), dyMarketPlatformAppIdList.get(1), Objects.equals(env.getActiveProfiles()[0],"prod") ? tokenDyProdUrl : tokenDyDevUrl);
DYVIDEO_SYS_LOG.info("getUploadAdsInfo.douyin code auth token expired,userId={},result={}",userId,JSON.toJSONString(result));
}
return jsonArray;
}
} catch (Throwable e) {
DYVIDEO_ERROR_LOG.error("getUploadAdsInfo error,userId={}",userId,e);
}
}
return jsonArray;
}
} }
...@@ -14,7 +14,7 @@ public class CheckerDyVideoFirstFlow extends NodeFlow<StoryNovelAction> { ...@@ -14,7 +14,7 @@ public class CheckerDyVideoFirstFlow extends NodeFlow<StoryNovelAction> {
@Override @Override
public void process(StoryNovelAction action) { public void process(StoryNovelAction action) {
if(up.exists(up.getFirstCheckerKey(action))){ if(up.exists(up.getFirstCheckerKey(action)) && !"lotto".equals(action.getVideoUpload().getSource())){
action.stop(true); action.stop(true);
} }
} }
......
package com.lwby.marketing.att.dyvideo.handle; package com.lwby.marketing.att.dyvideo.handle;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.lwby.marketing.att.AttributionStatus; import com.lwby.marketing.att.AttributionStatus;
import com.lwby.marketing.att.BehavoirType; import com.lwby.marketing.att.BehavoirType;
...@@ -63,23 +64,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -63,23 +64,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
public void process(StoryNovelAction action) { public void process(StoryNovelAction action) {
VideoUpload videoUpload = action.getVideoUpload(); VideoUpload videoUpload = action.getVideoUpload();
long userId = action.getUserId(); long userId = action.getUserId();
int platformId = action.getPlatformId();
Long channelId = action.getChannelId();
long activeTime = videoUpload.getActiveTime(); long activeTime = videoUpload.getActiveTime();
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
DeliveryDeviceInfo deliveryDeviceInfo = action.getDeliveryDeviceInfo(); DeliveryDeviceInfo deliveryDeviceInfo = action.getDeliveryDeviceInfo();
long hour = TimeUnit.MILLISECONDS.toHours(currentTime - activeTime);
if (hour > 6) {
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow expeed six hour ,videoUpload={},userId={}",JSON.toJSONString(videoUpload),userId);
return;
}
int platformId = action.getPlatformId();
Long channelId = action.getChannelId();
AppChannelVO appChannel = up.getAppChannelByPlatformAndChannel(platformId,channelId);
//处理关键行为上报
String openId = action.getOpenId();
JSONObject dyMarketPlatformAppIdJson = JSON.parseObject( JSONObject dyMarketPlatformAppIdJson = JSON.parseObject(
"{\n" "{\n"
+ " \"400\": \"ttf2f6844b6dc9702901_d4ac08a22f80f73256836fdd9655dbb0b6e6de7c\",\n" + " \"400\": \"ttf2f6844b6dc9702901_d4ac08a22f80f73256836fdd9655dbb0b6e6de7c\",\n"
...@@ -89,58 +78,89 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -89,58 +78,89 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
//走平台 //走平台
String dyMarketPlatformAppId = dyMarketPlatformAppIdJson.getString(platformKey); String dyMarketPlatformAppId = dyMarketPlatformAppIdJson.getString(platformKey);
List<String> dyMarketPlatformAppIdList = new ArrayList<>(); List<String> dyMarketPlatformAppIdList = new ArrayList<>();
String tokenDy = "";
ThirdAccountDy thirdAccountDy = null;
if (dyMarketPlatformAppId != null) { if (dyMarketPlatformAppId != null) {
dyMarketPlatformAppIdList = Arrays.asList(dyMarketPlatformAppId.split("_")); dyMarketPlatformAppIdList = Arrays.asList(dyMarketPlatformAppId.split("_"));
String tokenDy = "token_dy_" + dyMarketPlatformAppIdList.get(0); tokenDy = "token_dy_" + dyMarketPlatformAppIdList.get(0);
ThirdAccountDy thirdAccountDy = null; DYVIDEO_SYS_LOG.info("thirdAccountDy url={}",
DYVIDEO_SYS_LOG.info("thirdAccountDy url={}",Objects.equals(env.getActiveProfiles()[0],"prod") ? tokenDyProdUrl : tokenDyDevUrl); Objects.equals(env.getActiveProfiles()[0], "prod") ? tokenDyProdUrl : tokenDyDevUrl);
if (up.existsOld(tokenDy)) { if (up.exists(tokenDy)) {
thirdAccountDy = up.getOld(ThirdAccountDy.class, tokenDy); thirdAccountDy = up.get(ThirdAccountDy.class, tokenDy);
} else { } else {
thirdAccountDy = up.getDyAccessToken(dyMarketPlatformAppIdList.get(0), dyMarketPlatformAppIdList.get(1), thirdAccountDy = up.getDyAccessToken(dyMarketPlatformAppIdList.get(0), dyMarketPlatformAppIdList.get(1),
Objects.equals(env.getActiveProfiles()[0],"prod") ? tokenDyProdUrl : tokenDyDevUrl); Objects.equals(env.getActiveProfiles()[0], "prod") ? tokenDyProdUrl : tokenDyDevUrl);
} }
}
//这里通过source字段 给乐途上报广告信息
if (Objects.equals(action.getVideoUpload().getSource(),"lotto")) {
if (thirdAccountDy != null) { if (thirdAccountDy != null) {
//平均ecpm次数
Integer ecpmAvgCount = 0;
//每次ecpm次数
Integer pecpmCount = 0;
//激励视频次数
Integer motivateCount = 0;
//激励视频总ecpm次数
Integer tvcCount = 0;
LocalDateTime now = LocalDateTime.now(); // 获取当前日期时间 LocalDateTime now = LocalDateTime.now(); // 获取当前日期时间
LocalTime six = LocalTime.of(6, 0, 0); // 获取当天6点的时间 LocalTime two = LocalTime.of(2, 0, 0); // 获取当天6点的时间
String accessToken = thirdAccountDy.getAccessToken();
Date date = new Date(); Date date = new Date();
Map<String, Integer> resultCountMap = null; JSONArray jsonArray = new JSONArray();
Number behavoirType = BehavoirType.PECPMMODELCOUNT.getBehavoirType(appChannel); if (now.toLocalTime().isBefore(two)) {
Integer pecpmModel = null; //当天2点之前,查两天,先查昨天的ecpm指标
if (behavoirType != null) {
pecpmModel = behavoirType.intValue();
}
if (now.toLocalTime().isBefore(six)) {
//当天6点之前,查两天,先查昨天的ecpm指标
Calendar calendar = Calendar.getInstance(); // 获取日历对象 Calendar calendar = Calendar.getInstance(); // 获取日历对象
calendar.setTime(date); // 设置时间 calendar.setTime(date); // 设置时间
calendar.add(Calendar.DAY_OF_MONTH, -1); // 将时间减去一天 calendar.add(Calendar.DAY_OF_MONTH, -1); // 将时间减去一天
Date day = calendar.getTime(); Date day = calendar.getTime();
resultCountMap = up.getResultCountList(day, openId, accessToken, tvcCount, motivateCount, pecpmCount, jsonArray = up.getUploadAdsInfo(jsonArray,day,action, thirdAccountDy.getAccessToken(),tokenDy, dyMarketPlatformAppIdList,env);
pecpmModel, userId, tokenDy, dyMarketPlatformAppIdList,env); }
if (resultCountMap != null && resultCountMap.size() != 0) { jsonArray = up.getUploadAdsInfo(jsonArray,date,action, thirdAccountDy.getAccessToken(),tokenDy, dyMarketPlatformAppIdList,env);
tvcCount = resultCountMap.get("tvc");
if (tvcCount != null) { if (jsonArray.size()>0) {
tvcCount = tvcCount / 100; up.uploadCallbackAdsInfo(action,jsonArray.toJSONString());
}
motivateCount = resultCountMap.get("motivate");
pecpmCount = resultCountMap.get("pecpm");
}
} }
//查询今天的ecpm指标 }
resultCountMap = up.getResultCountList(date, openId, accessToken, tvcCount, motivateCount, pecpmCount, return;
}
long hour = TimeUnit.MILLISECONDS.toHours(currentTime - activeTime);
if (hour > 6) {
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow expeed six hour ,videoUpload={},userId={}",JSON.toJSONString(videoUpload),userId);
return;
}
AppChannelVO appChannel = up.getAppChannelByPlatformAndChannel(platformId,channelId);
//处理关键行为上报
String openId = action.getOpenId();
if (thirdAccountDy != null) {
//平均ecpm次数
Integer ecpmAvgCount = 0;
//每次ecpm次数
Integer pecpmCount = 0;
//激励视频次数
Integer motivateCount = 0;
//激励视频总ecpm次数
Integer tvcCount = 0;
LocalDateTime now = LocalDateTime.now(); // 获取当前日期时间
LocalTime six = LocalTime.of(6, 0, 0); // 获取当天6点的时间
String accessToken = thirdAccountDy.getAccessToken();
Date date = new Date();
Map<String, Integer> resultCountMap = null;
Number behavoirType = BehavoirType.PECPMMODELCOUNT.getBehavoirType(appChannel);
Integer pecpmModel = null;
if (behavoirType != null) {
pecpmModel = behavoirType.intValue();
}
if (now.toLocalTime().isBefore(six)) {
//当天6点之前,查两天,先查昨天的ecpm指标
Calendar calendar = Calendar.getInstance(); // 获取日历对象
calendar.setTime(date); // 设置时间
calendar.add(Calendar.DAY_OF_MONTH, -1); // 将时间减去一天
Date day = calendar.getTime();
resultCountMap = up.getResultCountList(day, openId, accessToken, tvcCount, motivateCount, pecpmCount,
pecpmModel, userId, tokenDy, dyMarketPlatformAppIdList,env); pecpmModel, userId, tokenDy, dyMarketPlatformAppIdList,env);
if (resultCountMap != null && resultCountMap.size() != 0) { if (resultCountMap != null && resultCountMap.size() != 0) {
tvcCount = resultCountMap.get("tvc"); tvcCount = resultCountMap.get("tvc");
...@@ -150,90 +170,101 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -150,90 +170,101 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
motivateCount = resultCountMap.get("motivate"); motivateCount = resultCountMap.get("motivate");
pecpmCount = resultCountMap.get("pecpm"); pecpmCount = resultCountMap.get("pecpm");
} }
}
if ((tvcCount != 0 && motivateCount != 0)) { //查询今天的ecpm指标
Double ecpmAvgCountD = (double)tvcCount / motivateCount; resultCountMap = up.getResultCountList(date, openId, accessToken, tvcCount, motivateCount, pecpmCount,
ecpmAvgCount = ecpmAvgCountD.intValue(); pecpmModel, userId, tokenDy, dyMarketPlatformAppIdList,env);
DYVIDEO_SYS_LOG.info("ecpmAvgCount success,ecpmAvgCount={},tvcCount={},motivateCount={},djChanel={},userId={}",ecpmAvgCount,tvcCount,motivateCount,channelId,userId); if (resultCountMap != null && resultCountMap.size() != 0) {
} else { tvcCount = resultCountMap.get("tvc");
DYVIDEO_SYS_LOG.info("behavoir not receive data,tvcCount={},motivateCount={},djChanel={},userId={}",tvcCount,motivateCount,channelId,userId); if (tvcCount != null) {
action.stop(true); tvcCount = tvcCount / 100;
return;
} }
motivateCount = resultCountMap.get("motivate");
pecpmCount = resultCountMap.get("pecpm");
}
for (BehavoirType type : BehavoirType.values()) { if ((tvcCount != 0 && motivateCount != 0)) {
Number behavoirVal = type.getBehavoirType(appChannel); Double ecpmAvgCountD = (double)tvcCount / motivateCount;
if (null != behavoirVal && behavoirVal instanceof Integer) { ecpmAvgCount = ecpmAvgCountD.intValue();
if (type.getValue().startsWith(BehavoirType.MOTIVATEMODELCOUNT.getValue()) && null != motivateCount) { DYVIDEO_SYS_LOG.info("ecpmAvgCount success,ecpmAvgCount={},tvcCount={},motivateCount={},djChanel={},userId={}",ecpmAvgCount,tvcCount,motivateCount,channelId,userId);
if (motivateCount < behavoirVal.intValue()) { } else {
DYVIDEO_SYS_LOG.info("motivate not up to the standard,motivateCount={},motivateModelCount={},djChanel={},userId={}",motivateCount,behavoirVal,channelId,userId); DYVIDEO_SYS_LOG.info("behavoir not receive data,tvcCount={},motivateCount={},djChanel={},userId={}",tvcCount,motivateCount,channelId,userId);
action.stop(true); action.stop(true);
break; return;
} }
deliveryDeviceInfo.setMotivateCount(String.valueOf(motivateCount));
continue; for (BehavoirType type : BehavoirType.values()) {
Number behavoirVal = type.getBehavoirType(appChannel);
if (null != behavoirVal && behavoirVal instanceof Integer) {
if (type.getValue().startsWith(BehavoirType.MOTIVATEMODELCOUNT.getValue()) && null != motivateCount) {
if (motivateCount < behavoirVal.intValue()) {
DYVIDEO_SYS_LOG.info("motivate not up to the standard,motivateCount={},motivateModelCount={},djChanel={},userId={}",motivateCount,behavoirVal,channelId,userId);
action.stop(true);
break;
} }
if (type.getValue().startsWith(BehavoirType.ECPMAVGMODELCOUNT.getValue()) && null != ecpmAvgCount) { deliveryDeviceInfo.setMotivateCount(String.valueOf(motivateCount));
if (ecpmAvgCount < behavoirVal.intValue()) { continue;
DYVIDEO_SYS_LOG.info("ecpm not up to the standard,ecpmAvgCount={},ecpmAvgModelCount={},djChanel={},userId={}",ecpmAvgCount,behavoirVal,channelId,userId); }
action.stop(true); if (type.getValue().startsWith(BehavoirType.ECPMAVGMODELCOUNT.getValue()) && null != ecpmAvgCount) {
break; if (ecpmAvgCount < behavoirVal.intValue()) {
} DYVIDEO_SYS_LOG.info("ecpm not up to the standard,ecpmAvgCount={},ecpmAvgModelCount={},djChanel={},userId={}",ecpmAvgCount,behavoirVal,channelId,userId);
deliveryDeviceInfo.setEcpmAvgCount(String.valueOf(ecpmAvgCount)); action.stop(true);
continue; break;
} }
if (type.getValue().startsWith(BehavoirType.PECPMMODELCOUNT.getValue()) && null != pecpmCount) { deliveryDeviceInfo.setEcpmAvgCount(String.valueOf(ecpmAvgCount));
if (pecpmCount < BehavoirType.MOTIVATEMODELCOUNT.getBehavoirType(appChannel).intValue()) { continue;
DYVIDEO_SYS_LOG.info("pecpmCount not up to the standard,pecpmModelCount={},pecpmCount={},motivateModelCount={},motivateCount={},djChanel={},userId={}",behavoirVal,pecpmCount,BehavoirType.MOTIVATEMODELCOUNT.getBehavoirType(appChannel),motivateCount,channelId,userId); }
action.stop(true); if (type.getValue().startsWith(BehavoirType.PECPMMODELCOUNT.getValue()) && null != pecpmCount) {
break; if (pecpmCount < BehavoirType.MOTIVATEMODELCOUNT.getBehavoirType(appChannel).intValue()) {
} DYVIDEO_SYS_LOG.info("pecpmCount not up to the standard,pecpmModelCount={},pecpmCount={},motivateModelCount={},motivateCount={},djChanel={},userId={}",behavoirVal,pecpmCount,BehavoirType.MOTIVATEMODELCOUNT.getBehavoirType(appChannel),motivateCount,channelId,userId);
action.stop(true);
deliveryDeviceInfo.setPecpmCount(String.valueOf(behavoirVal));
deliveryDeviceInfo.setPerecpmSize(String.valueOf(pecpmCount));
break; break;
} }
deliveryDeviceInfo.setPecpmCount(String.valueOf(behavoirVal));
deliveryDeviceInfo.setPerecpmSize(String.valueOf(pecpmCount));
break;
} }
} }
}
//满足之后扣量 //满足之后扣量
Integer sprDedu = appChannel.getSprDedu(); Integer sprDedu = appChannel.getSprDedu();
CallBackType type = CallBackType.getCallBackTypeByType(action.getType()); CallBackType type = CallBackType.getCallBackTypeByType(action.getType());
//等于空 或 100直接回传 //等于空 或 100直接回传
if (sprDedu == null || sprDedu == 100) { if (sprDedu == null || sprDedu == 100) {
action.getMedia().notify(action); action.getMedia().notify(action);
up.notifyResult(action, type.getTopic()+"_test",type.getStatus()); up.notifyResult(action, type.getTopic(),type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1"); up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
return; return;
} }
//总数 //总数
String channelTotal = up.getTotalCountKey(AttributionType.CHANNEL, action.getPlatformId(), action.getChannelId(), sprDedu, action.getCurrentDateStr()); String channelTotal = up.getTotalCountKey(AttributionType.CHANNEL, action.getPlatformId(), action.getChannelId(), sprDedu, action.getCurrentDateStr());
//回传 //回传
String channelCallback = up.getCallbackCountKey(AttributionType.CHANNEL, action.getPlatformId(), action.getChannelId(), sprDedu, action.getCurrentDateStr()); String channelCallback = up.getCallbackCountKey(AttributionType.CHANNEL, action.getPlatformId(), action.getChannelId(), sprDedu, action.getCurrentDateStr());
long channelTotalCount = up.incrby(channelTotal, 0, 60 * 60 * 24); long channelTotalCount = up.incrby(channelTotal, 0, 60 * 60 * 24);
long channelCallbackCount = up.incrby(channelCallback, 0, 60 * 60 * 24); long channelCallbackCount = up.incrby(channelCallback, 0, 60 * 60 * 24);
up.incrby(channelTotal, 1); up.incrby(channelTotal, 1);
if (isCallback(channelTotalCount, channelCallbackCount, sprDedu)) { if (isCallback(channelTotalCount, channelCallbackCount, sprDedu)) {
//回传,回传个数 + 1 //回传,回传个数 + 1
up.incrby(channelCallback, 1); up.incrby(channelCallback, 1);
action.getMedia().notify(action); action.getMedia().notify(action);
up.notifyResult(action, type.getTopic()+"_test",type.getStatus()); up.notifyResult(action, type.getTopic(),type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1"); up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
DYVIDEO_SYS_LOG.info( DYVIDEO_SYS_LOG.info(
"ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}", "ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}",
action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 1); action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 1);
} else { } else {
up.notifyResult(action,"ocpc_behavior_test", AttributionStatus.NORMAL_DEDUCTION_CALLBACK); up.notifyResult(action,type.getTopic(), AttributionStatus.NORMAL_DEDUCTION_CALLBACK);
up.set(up.getFirstCheckerKey(action), up.getExpire(action), "1"); up.set(up.getFirstCheckerKey(action), up.getExpire(action), "1");
DYVIDEO_SYS_LOG.info( DYVIDEO_SYS_LOG.info(
"ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}", "ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}",
action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 0); action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 0);
}
} }
} }
} }
......
...@@ -20,7 +20,7 @@ public class StoreDyVideoAttributionFlow extends NodeFlow<StoryNovelAction> { ...@@ -20,7 +20,7 @@ public class StoreDyVideoAttributionFlow extends NodeFlow<StoryNovelAction> {
//商店归因通知 //商店归因通知
if(Objects.isNull(action.getDeliveryDeviceInfo())){ if(Objects.isNull(action.getDeliveryDeviceInfo())){
if (action.getType().equals(CallBackType.active.getType())) { if (action.getType().equals(CallBackType.active.getType())) {
up.notifyResult(action,"ocpc_result_test", AttributionStatus.STORE_CALLBACK); up.notifyResult(action,"ocpc_result", AttributionStatus.STORE_CALLBACK);
} }
action.stop(true); //结束后面所有执行流程 action.stop(true); //结束后面所有执行流程
} }
......
...@@ -7,6 +7,7 @@ import com.lwby.marketing.vo.StoryNovelAction; ...@@ -7,6 +7,7 @@ import com.lwby.marketing.vo.StoryNovelAction;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Objects;
/** /**
* @author songxinyu * @author songxinyu
...@@ -24,8 +25,12 @@ public class UploadDyVideoCallFlow extends NodeFlow<StoryNovelAction> { ...@@ -24,8 +25,12 @@ public class UploadDyVideoCallFlow extends NodeFlow<StoryNovelAction> {
boolean success = action.getMedia().notify(action); boolean success = action.getMedia().notify(action);
if (success) { if (success) {
//根据source判断是否给指定外包上报
if (Objects.equals(action.getVideoUpload().getSource(),"lotto")) {
up.uploadCallbackUserInfo(action);
}
action.getVideoUpload().setActiveTime(System.currentTimeMillis()); action.getVideoUpload().setActiveTime(System.currentTimeMillis());
up.notifyResult(action, type.getTopic()+"_test",type.getStatus()); up.notifyResult(action, type.getTopic(),type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1"); up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
} }
} }
......
...@@ -25,19 +25,19 @@ import java.util.Map; ...@@ -25,19 +25,19 @@ import java.util.Map;
@EnableKafka @EnableKafka
public class DyVideoActiveKafkaConsumerConfig { public class DyVideoActiveKafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}") @Value("${spring.kafka.bootstrap-servers}")
private String servers; private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}") @Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit; private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}") @Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset; private String autoOffsetReset;
@Value("${system.consumer.dyvideo.active.group_id}") @Value("${system.consumer.dyvideo.active.group_id}")
private String groupId; private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}") @Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig; private int maxPollRecordsConfig;
......
...@@ -24,19 +24,19 @@ import java.util.Map; ...@@ -24,19 +24,19 @@ import java.util.Map;
@EnableKafka @EnableKafka
public class DyVideoBehavoirKafkaConsumerConfig { public class DyVideoBehavoirKafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}") @Value("${spring.kafka.bootstrap-servers}")
private String servers; private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}") @Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit; private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}") @Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset; private String autoOffsetReset;
@Value("${system.consumer.dyvideo.behavoir.group_id}") @Value("${system.consumer.dyvideo.behavoir.group_id}")
private String groupId; private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}") @Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig; private int maxPollRecordsConfig;
......
package com.lwby.marketing.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lwby.marketing.att.dyvideo.DyVideoUniversalProcess;
import com.lwby.marketing.notify.media.jrtt.dto.JrttAttributeRequest;
import com.lwby.marketing.po.DyVideoUpload;
import com.lwby.marketing.po.VideoUpload;
import com.lwby.marketing.util.HttpUtil;
import com.lwby.marketing.util.ResultConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* @author songxinyu
* @version DyVideoController.java, v 0.1 2024年04月10日 11:27 songxinyu Exp $
*/
@RestController
@Slf4j
@RequestMapping(value = "/market_attr")
public class DyVideoController {
public static final String ATTRIBUTE_URL = "https://analytics.oceanengine.com/api/v2/conversion";
@Resource
DyVideoUniversalProcess up;
@RequestMapping("uploadBehavoir")
public String uploadBehavoirByDyVideo(@RequestParam("openId") String openId) {
Map map = new HashMap();
String result = "";
VideoUpload videoUpload = up.get(VideoUpload.class,assembleKey(openId));
Integer platformId = videoUpload.getPlatformId();
String uploadKey = String.format("dv_%s_%d_%s", openId, platformId,videoUpload.getMedia());
if (up.exists(uploadKey)) {
map.put("code", ResultConstant.CALL_BACK_UPED_FAIL);
map.put("message",ResultConstant.CALL_BACK_UPED_MESSAGE);
result = JSONObject.toJSONString(map);
return result;
}
JrttAttributeRequest.Ad ad = new JrttAttributeRequest.Ad();
ad.setCallback(videoUpload.getClickId());
JrttAttributeRequest.Context context = new JrttAttributeRequest.Context();
context.setAd(ad);
JrttAttributeRequest request = JrttAttributeRequest.builder().context(context).event_type("game_addiction").timestamp(
System.currentTimeMillis()).build();
String userJson = JSONObject.toJSONString(request);
try {
String ret = HttpUtil.post(ATTRIBUTE_URL, userJson);
Integer resultCode = (Integer) JSON.parseObject(ret).get("code");
if (resultCode == 0) {
map.put("code", ResultConstant.CALL_BACK_SUCCESS);
map.put("message",ResultConstant.CALL_BACK_SUCCESS_MESSAGE);
result = JSONObject.toJSONString(map) ;
//给bi发消息
up.notifyResult(openId,videoUpload);
up.set(uploadKey,60 * 60 * 24 * 7,"1");
} else {
map.put("code", ResultConstant.CALL_BACK_FAIL);
map.put("message",ResultConstant.CALL_BACK_FAIL_MESSAGE);
result = JSONObject.toJSONString(map) ;
}
return result;
} catch (Exception e) {
map.put("code", ResultConstant.CALL_BACK_FAIL);
map.put("message",ResultConstant.CALL_BACK_FAIL_MESSAGE);
result = JSONObject.toJSONString(map) ;
return result;
}
}
public String assembleKey(String openId) {
return String.format("video:upload:%s", openId);
}
}
package com.lwby.marketing.controller;
import com.alibaba.fastjson.JSON;
import com.lwby.marketing.factory.MediaClickFactory;
import com.lwby.marketing.notify.Media;
import com.lwby.marketing.service.MediaClick;
import com.lwby.marketing.util.Stats;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/**
* @author songxinyu
* @version MediaClickController.java, v 0.1 2024年04月10日 13:48 songxinyu Exp $
*/
@RestController
@Slf4j
@RequestMapping(value = "/market_growth")
public class MediaClickController {
@Resource
MediaClickFactory mediaClickFactory;
@RequestMapping("/jrtt")
public Object jrttClick(HttpServletRequest request, HttpServletResponse res){
Map<String, String> params = new HashMap<String, String>();
Enumeration<String> en = request.getParameterNames();
while(en.hasMoreElements()){
String key = en.nextElement();
params.put(key, request.getParameter(key));
}
log.info("JrttClick params:{}", JSON.toJSONString(params));
MediaClick mediaClickFacade = mediaClickFactory.getMediaClickFacade(Media.NOVEL_JRTT);
String result = mediaClickFacade.click("", params);
log.info("JrttClick , {}",result);
Stats.HTTP_MG_JRTT.add();
return result;
}
}
package com.lwby.marketing.factory;
import com.google.common.collect.ArrayListMultimap;
import com.lwby.marketing.notify.Media;
import com.lwby.marketing.service.MediaClick;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class MediaClickFactory {
@Autowired
ApplicationContext applicationContext;
ArrayListMultimap<Media, MediaClick> multimap = ArrayListMultimap.create();
/**
* @return
*/
/**
*
* @return
*/
public MediaClick getMediaClickFacade(Media mediaEnum) {
List<MediaClick> mediaClickFacade = multimap.get(mediaEnum);
return mediaClickFacade.get(0);
}
/**
*
*/
@PostConstruct
public void init() {
Map<String, MediaClick> type = applicationContext.getBeansOfType(MediaClick.class);
for (Map.Entry<String, MediaClick> item : type.entrySet()) {
multimap.put(item.getValue().getMedia(), item.getValue());
}
}
}
...@@ -21,7 +21,7 @@ public enum Media { ...@@ -21,7 +21,7 @@ public enum Media {
DY_VIDEO_JRTT("jrtt", Platform.DY_VIDEO, "今日头条",new DyVideoJRTTNotify()), DY_VIDEO_JRTT("jrtt", Platform.DY_VIDEO, "今日头条",new DyVideoJRTTNotify()),
VIDEOAPP_JRTT("jrtt_freevideo", Platform.VIDEO, "今日头条",new VideoAppJRTTNotify()); VIDEOAPP_JRTT("jrtt_freevideo", Platform.VIDEO, "今日头条",new VideoAppJRTTNotify());
final String name; public final String name;
final Platform platform; final Platform platform;
final String desc; final String desc;
final BaseNotiry baseNotify; final BaseNotiry baseNotify;
......
...@@ -46,12 +46,10 @@ public class DyVideoJRTTNotify extends DYNotify { ...@@ -46,12 +46,10 @@ public class DyVideoJRTTNotify extends DYNotify {
String userJson = JSONObject.toJSONString(request); String userJson = JSONObject.toJSONString(request);
try { try {
//TODO;测试不执行 String result = HttpUtil.post(ATTRIBUTE_URL, userJson);
//String result = HttpUtil.post(ATTRIBUTE_URL, userJson); Integer resultCode = (Integer) JSON.parseObject(result).get("code");
//Integer resultCode = (Integer) JSON.parseObject(result).get("code");
//return resultCode == 0;
DYVIDEO_SYS_LOG.info("DyVideoJRTTNotify.video.{}.upload,userId={},channel={},platform={}",eventType,na.getUserId(),na.getChannelId(),na.getPlatformId()); DYVIDEO_SYS_LOG.info("DyVideoJRTTNotify.video.{}.upload,userId={},channel={},platform={}",eventType,na.getUserId(),na.getChannelId(),na.getPlatformId());
return true; return resultCode == 0;
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
......
package com.lwby.marketing.po;
import lombok.Data;
/**
* @author songxinyu
* @version DyVideoUpload.java, v 0.1 2024年04月10日 17:06 songxinyu Exp $
*/
@Data
public class DyVideoUpload {
String openId;
Integer platformId;
}
...@@ -25,4 +25,9 @@ public class VideoUpload { ...@@ -25,4 +25,9 @@ public class VideoUpload {
private String perecpmSize; private String perecpmSize;
private long activeTime; private long activeTime;
private long clickTime; private long clickTime;
private Integer platformId;
private Long userId;
//来源
private String source;
} }
package com.lwby.marketing.service;
import com.lwby.marketing.notify.Media;
import java.util.Map;
/**
* @author songxinyu
* @version MediaClick.java, v 0.1 2024年04月10日 14:11 songxinyu Exp $
*/
public interface MediaClick {
String click(String s, Map<String, String> params);
Media getMedia();
}
package com.lwby.marketing.service.impl;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lwby.marketing.notify.Media;
import com.lwby.marketing.service.MediaClick;
import com.lwby.marketing.util.CacheKeyUtils;
import com.lwby.marketing.util.ResultConstant;
import com.lwby.marketing.vo.DeliveryDeviceInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author songxinyu
* @version JrttClickImpl.java, v 0.1 2024年04月10日 14:13 songxinyu Exp $
*/
@Service
@Slf4j
public class JrttClickImpl implements MediaClick {
/**
* 今日头条安卓平台标识
*/
private static final String JRTT_OS_ANDROID = "0";
/**
*
* 今日头条IOS平台标识
*
*/
private static final String JRTT_OS_IOS = "1";
/**
* 设备信息参数过滤无效信息
*/
@Value("${click.special.param:00000000-0000-0000-0000-000000000000,9f89c84a559f573636a47ff8daed0d33,__IMEI__,null,'null',NULL,'NULL'}")
public String specialParamStr;
@Resource
private RedisTemplate<String,String> oldMarketRedisTemplate;
@Resource
public RedisTemplate<String, String> redisTemplate;
@Value("${bookIdExpireTime:604800}")
private int bookIdExpireTime;
@Resource(name = "storyKafka")
public KafkaTemplate<String, String> storyKafkaTemplate;
@Override
public String click(String s, Map<String, String> params) {
String uuid = UUID.randomUUID().toString();
params.put("uuid", uuid);
params.put("media", "jrtt");
String result = "";
String idfa = params.get("idfa");
String idfaMd5 = SecureUtil.md5(idfa);
//idfaMd5 需要转一次小写
if (StringUtils.isNotEmpty(idfaMd5)) {
idfaMd5 = idfaMd5.toLowerCase();
}
String imeiMd5 = params.get("imei");
String oaid = params.get("oaid");
String androidid = params.get("androidid");
String os = params.get("os");//0–Android; 1–iOS
String callback_url = params.get("callback_url");
//头条新增上报字段 - 巨量引擎的关键广告信息
String callback_param = params.get("callback_param");
//广告计划id
String adPlanId = params.get("adid");
params.put("ad_plan_id", adPlanId);
//广告创意id
String adCreativeId = params.get("cid");
//广告投放位置
String adSite = params.get("csite");
//创意样式
String adType = params.get("ctype");
//弹窗字段
String cpm = params.get("cpm");
//点击渠道
String channel = params.get("channel");
String platformId = params.get("platform_id");
String advertiserId =params.get("advertiser_id");
String campaignId = params.get("campaign_id");
params.put("adgroup_id", campaignId);
String ip = params.get("ip");
String ua = params.get("ua");
String model = params.get("model");
String timeStamp = params.get("TIMESTAMP");
params.put("click_time", timeStamp);
String bookId = params.get("book");
if (StringUtils.isBlank(bookId)) {
bookId = params.get("books");
if (StringUtils.isBlank(bookId)) {
bookId = params.get("book_id");
}
}
String partId = params.get("part_id");
String adPlatformType = params.get("ad_platform_type");
String targetAudience = params.get("target_audience");
//通投智选union_site
String union_site = params.get("union_site");
//巨量广告体验版中特有的宏参,代表巨量广告体验版的广告ID
String promotionId = params.get("promotion_id");
//巨量广告体验版中特有的宏参,代表巨量广告体验版的项目ID
String projectId = params.get("project_id");
//巨量广告体验版中的广告名称
String promotionName = params.get("promotion_name");
//巨量广告体验版中的项目名称
String projectName = params.get("project_name");
String scheme = params.get("scheme");
//信息流投放广告来源(碎片 1 书籍 2)
String source = params.get("source");
//MatrixLog.build(option).add("MediaClickImpl Monitoring link imei:", imeiMd5).add("oaid", oaid).add("channel", channel).add("bookId",
// bookId).add("partId",partId).add("media", MediaEnum.TOU_TIAO.getMediaName()).add("platformId", platformId).info();
log.info("MediaClickImpl Monitoring link imei:{},oaid:{},channel:{},bookId:{},partId:{},media:{},platformId:{}",imeiMd5,oaid,channel,bookId,partId,Media.NOVEL_JRTT.name,platformId);
if (ua != null && ua.contains(" Chrome/")) {
ua = ua.substring(0,ua.indexOf(" Chrome/"));
}
String ipAndUaMd5 = SecureUtil.md5(ip + ua);
String ipMd5 = SecureUtil.md5(ip);
Map map = new HashMap();
List<String> specialParam = Arrays.asList(specialParamStr.split(","));
if(specialParam.contains(imeiMd5)){
imeiMd5 = "";
}
if(specialParam.contains(oaid)){
oaid = "";
}
if(specialParam.contains(idfa)){
idfa = "";
}
if(StringUtils.isBlank(os)){
map.put("status", ResultConstant.CALL_BACK_FAIL);
result = JSONObject.toJSONString(map) ;
return result;
}
//idfa或imei存储的redis key
String muidKey = StringUtils.EMPTY;
//oaid存储的redis key
String oaidKey = StringUtils.EMPTY;
// ip +ua redis key
String ipAndUaKey = StringUtils.EMPTY;
String ipKey = StringUtils.EMPTY;
//获取oaid MD5加密值
String oaidMd5 = SecureUtil.md5(oaid);
//0–Android 1–iOS
if (JRTT_OS_ANDROID.equals(os)) {
if (StringUtils.isNotEmpty(imeiMd5)) {
muidKey = CacheKeyUtils.getClickKeyByIdfaAndPlatformId(imeiMd5, platformId);
}
} else if (JRTT_OS_IOS.equals(os)) {
if (StringUtils.isNotEmpty(idfaMd5)) {
muidKey = CacheKeyUtils.getClickKeyByIdfaAndPlatformId(idfaMd5, platformId);
}
}
//oaid md5不为空 根据点击数据oaid与平台id构造缓存key
if (StringUtils.isNotEmpty(oaidMd5)) {
oaidKey = CacheKeyUtils.getClickKeyByIdfaAndPlatformId(oaidMd5, platformId);
}
if (StringUtils.isNotEmpty(ip) && StringUtils.isNotEmpty(ua)) {
ipAndUaKey = CacheKeyUtils.getClickKeyByIdfaAndPlatformId(ipAndUaMd5, platformId);
}
if (StringUtils.isNotEmpty(ip)) {
ipKey = CacheKeyUtils.getClickKey(ipMd5, platformId);
}
if("1".equals(os) && StringUtils.isNotEmpty(idfa)){
if (StringUtils.isNotEmpty(bookId) && StringUtils.isNumeric(bookId)) {
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(idfa, platformId),JSON.toJSONString(bookId), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(idfa, platformId),JSON.toJSONString(bookId), bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(channel)) {
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(idfaMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(idfaMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
}
}else {
if (StringUtils.isNotEmpty(oaidMd5)) {
if (StringUtils.isNotEmpty(channel)) {
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(oaidMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(oaidMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(bookId) && StringUtils.isNumeric(bookId)) {
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(oaidMd5, platformId),JSON.toJSONString(bookId), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(oaidMd5, platformId),JSON.toJSONString(bookId), bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(partId) && StringUtils.isNumeric(partId)) {
//缓存章节id
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(oaidMd5, platformId),JSON.toJSONString(partId), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(oaidMd5, platformId),JSON.toJSONString(partId), bookIdExpireTime, TimeUnit.SECONDS);
}
}
if (StringUtils.isNotEmpty(ip) && StringUtils.isNotEmpty(ua)) {
if (StringUtils.isNotEmpty(channel)) {
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(ipAndUaMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(ipAndUaMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(ipMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(ipMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
storyKafkaTemplate.send("growth_ad_click", JSONObject.toJSONString(params));
//服务器当前时间
long now = System.currentTimeMillis();
DeliveryDeviceInfo deliveryDeviceInfo = new DeliveryDeviceInfo();
deliveryDeviceInfo.setClick_time(now);
deliveryDeviceInfo.setAd_group_id(campaignId);
deliveryDeviceInfo.setAd_creative_id(adCreativeId);
deliveryDeviceInfo.setAd_plan_id(adPlanId);
deliveryDeviceInfo.setMedia(Media.NOVEL_JRTT.name);
deliveryDeviceInfo.setPlatform_id(platformId);
deliveryDeviceInfo.setDj_channel(channel);
deliveryDeviceInfo.setBook_id(bookId);
if (Objects.isNull(callback_param)) {
deliveryDeviceInfo.setCallback_url(callback_url);
}
deliveryDeviceInfo.setAdvertiser_id(advertiserId);
deliveryDeviceInfo.setUuid(uuid);
deliveryDeviceInfo.setAd_platform_type(adPlatformType);
deliveryDeviceInfo.setTarget_audience(targetAudience);
deliveryDeviceInfo.setUnion_site(union_site);
deliveryDeviceInfo.setCallback_param(callback_param);
deliveryDeviceInfo.setIp(ip);
deliveryDeviceInfo.setPartId(partId);
if (StringUtils.isNotEmpty(promotionId)) {
deliveryDeviceInfo.setPromotion_id(promotionId);
}
if (StringUtils.isNotEmpty(projectId)) {
deliveryDeviceInfo.setProject_id(projectId);
}
if (StringUtils.isNotEmpty(promotionName)) {
deliveryDeviceInfo.setPromotion_name(promotionName);
}
if (StringUtils.isNotEmpty(projectName)) {
deliveryDeviceInfo.setProject_name(projectName);
}
if (!specialParam.contains(oaid)) {
deliveryDeviceInfo.setOaid(oaid);
}
if (StringUtils.isNotEmpty(imeiMd5)) {
deliveryDeviceInfo.setImeiMd5(imeiMd5);
}
//存储有广告类型区分的用户 传递给业务方
if (StringUtils.isNotEmpty(source) && StringUtils.isNumeric(source)) {
deliveryDeviceInfo.setSource(Integer.valueOf(source));
}
if (StringUtils.isNotEmpty(model)) {
try {
model = URLEncoder.encode(model,"utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
if (StringUtils.isEmpty(model) && StringUtils.isNotEmpty(ua)) {
//Mozilla/5.0 (Linux; Android 11; PDVM00 Build/RKQ1.201217.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0
model = CacheKeyUtils.getModelByUa(ua);
}
if (StringUtils.isNotEmpty(ip) && StringUtils.isNotEmpty(model)) {
deliveryDeviceInfo.setModel(model);
String ipAndModelMd5 = SecureUtil.md5(ip + model);
//Mozilla/5.0 (Linux; Android 11; PDVM00 Build/RKQ1.201217.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0
if (StringUtils.isNotEmpty(channel)) {
oldMarketRedisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(ipAndModelMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(ipAndModelMd5, platformId),JSON.toJSONString(Integer.parseInt(channel)), bookIdExpireTime, TimeUnit.SECONDS);
}
//ip + phonemodel
String ipAndModelKey = CacheKeyUtils.getClickKeyByIdfaAndPlatformId(ipAndModelMd5, platformId);
oldMarketRedisTemplate.opsForValue().set(ipAndModelKey, JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(ipAndModelKey, JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(muidKey)) {
oldMarketRedisTemplate.opsForValue().set(muidKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(muidKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(oaidKey)) {
oldMarketRedisTemplate.opsForValue().set(oaidKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(oaidKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(ipAndUaKey)) {
oldMarketRedisTemplate.opsForValue().set(ipAndUaKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(ipAndUaKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
}
if (StringUtils.isNotEmpty(ipKey)) {
oldMarketRedisTemplate.opsForValue().set(ipKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(ipKey,JSON.toJSONString(deliveryDeviceInfo),bookIdExpireTime, TimeUnit.SECONDS);
}
map.put("status", ResultConstant.CALL_BACK_SUCCESS);
result = JSONObject.toJSONString(map) ;
return result;
}
@Override
public Media getMedia() {
return Media.NOVEL_JRTT;
}
}
package com.lwby.marketing.util; package com.lwby.marketing.util;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
...@@ -13,6 +17,13 @@ public class CacheKeyUtils { ...@@ -13,6 +17,13 @@ public class CacheKeyUtils {
static SimpleDateFormat df = new SimpleDateFormat("MMdd");//设置日期格式 static SimpleDateFormat df = new SimpleDateFormat("MMdd");//设置日期格式
private static final String CACHE_BOOK_PREFIX = "getBookId";
private static final String CACHE_PART_PREFIX = "getPartId";
private static final String CHANNEL_PREFIX_KEY = "getChannelBy";
public static String getBehavoirKey(Long userId) { public static String getBehavoirKey(Long userId) {
return CACHE_BEHAVIOR_PREFIX + userId + "_" + df.format(new Date()) + "_fv"; return CACHE_BEHAVIOR_PREFIX + userId + "_" + df.format(new Date()) + "_fv";
} }
...@@ -20,4 +31,43 @@ public class CacheKeyUtils { ...@@ -20,4 +31,43 @@ public class CacheKeyUtils {
public static String getVideoBehavoirKey(Long userId) { public static String getVideoBehavoirKey(Long userId) {
return CACHE_BEHAVIOR_PREFIX + userId + "_fv"; return CACHE_BEHAVIOR_PREFIX + userId + "_fv";
} }
public static String getClickKeyByIdfaAndPlatformId(String idfa, String platformId) {
return "getClickByIdfaAndPlatformId" + "_" + idfa + "_" + platformId;
}
public static String getClickKey(String idfa, String platformId) {
return "mck" + ":" + idfa + ":" + platformId;
}
public static String getDeliveryBookIdCacheKey(String deviceKey, String platformId) {
return CACHE_BOOK_PREFIX + "_" + deviceKey + "_" + platformId;
}
public static String getDeliveryPartIdCacheKey(String deviceKey, String platformId) {
return CACHE_PART_PREFIX + "_" + deviceKey + "_" + platformId;
}
public static String getChannelByDeviceIdKeyAndPlatformId(String deviceIdKey, String platformId) {
return CHANNEL_PREFIX_KEY + deviceIdKey + platformId;
}
public static String getModelByUa(String ua) {
String uasplit = ua.split("Build")[0];
String model = null;
try {
if (ua.startsWith("com.")) {
String[] split = uasplit.split(";");
model = split[4].trim();
} else {
if (uasplit.split(";").length >= 3 && StringUtils.isNotEmpty(uasplit.split(";")[2].trim())) {
model = uasplit.substring(uasplit.lastIndexOf(";") + 2, uasplit.length() - 1);
model = URLEncoder.encode(model, "utf-8");
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return model;
}
} }
...@@ -28,6 +28,14 @@ public class DateTimUtils { ...@@ -28,6 +28,14 @@ public class DateTimUtils {
return DATE_BOTTOM_FORMAT.format(new Date()); return DATE_BOTTOM_FORMAT.format(new Date());
} }
public static String getCurrentTimeString(){
return DATE_TIME_FORMAT.format(new Date());
}
public static String getCurrentTimeString(Date date){
return DATE_TIME_FORMAT.format(date);
}
/** /**
* 时间是否大于7天 * 时间是否大于7天
* *
......
package com.lwby.marketing.util;
public class ResultConstant {
public final static Integer CALL_BACK_SUCCESS = 0;
public final static Integer CALL_BACK_FAIL = 1;
public final static Integer CALL_BACK_UPED_FAIL = 2;
public final static String CALL_BACK_SUCCESS_MESSAGE = "上报成功";
public final static String CALL_BACK_FAIL_MESSAGE = "上报失败";
public final static String CALL_BACK_UPED_MESSAGE = "已上报一次";
}
package com.lwby.marketing.util;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
public enum Stats {
HTTP_MG_JRTT("HTTP接口jrtt", "http_mg_jrtt"),
HTTP_MG_WECHAT("HTTP接口jrtt", "http_mg_wechat"),
HTTP_MG_KUAISHOU("HTTP接口jrtt", "http_mg_kuaishou"),
HTTP_MG_YOUDAO("HTTP接口jrtt", "http_mg_kuaishou"),
HTTP_MG_XIAOMI("HTTP接口jrtt", "http_mg_xiaomi");
private String name;
private Counter counter;
private String indicator;
Stats(String name, String indicator) {
this.name = name;
this.indicator = indicator;
}
public void add() {
counter.increment();
}
public void add(long count) {
counter.increment(count);
}
public String getName() {
return this.name;
}
public long getCount() {
return (long) counter.count();
}
public void bind(MeterRegistry registry) {
this.counter = registry.counter(indicator);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment