Commit d5168b1f authored by 宋新宇's avatar 宋新宇

Merge branch 'release_20240411' into 'main'

Release 20240411

See merge request !52
parents ccfedbac ba1f79fd
......@@ -78,7 +78,9 @@ public class UniversalProcess {
public long incrby(String key, int increment) {
return redisTemplate.opsForValue().increment(key,increment);
}
public void del(String key) {
redisTemplate.delete(key);
}
/******************************************** INNER CLASS ******************************************************/
......
package com.lwby.marketing.att.dyvideo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.CacheType;
......@@ -10,7 +11,9 @@ import com.lwby.marketing.att.UniversalProcess;
import com.lwby.marketing.att.CallBackType;
import com.lwby.marketing.att.novel.AttributionType;
import com.lwby.marketing.po.ThirdAccountDy;
import com.lwby.marketing.po.VideoUpload;
import com.lwby.marketing.util.CacheKeyUtils;
import com.lwby.marketing.util.DateTimUtils;
import com.lwby.marketing.util.HttpUtil;
import com.lwby.marketing.vo.AppChannelVO;
import com.lwby.marketing.vo.DeliveryDeviceInfo;
......@@ -18,6 +21,7 @@ import com.lwby.marketing.vo.StoryNovelAction;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.redis.core.RedisTemplate;
......@@ -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 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 {
);
}
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) {
String value = oldMarketRedisTemplate.opsForValue().get(key);
if(!Objects.isNull(value)){
......@@ -120,7 +149,7 @@ public class DyVideoUniversalProcess extends UniversalProcess {
public String getFirstCheckerKey(StoryNovelAction action) {
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", action.getUserId(), action.getPlatformId(),action.getMediaName());
: String.format("fc_%s_%d_%s", action.getOpenId(), action.getPlatformId(),action.getMediaName());
}
public int getExpire(StoryNovelAction action) {
......@@ -151,7 +180,7 @@ public class DyVideoUniversalProcess extends UniversalProcess {
thirdAccountDy.setClientId(client_id);
String tokenDy = "token_dy_" + client_id;
//往老的market缓存写,防止token一直失效
setToken(tokenDy, Integer.parseInt(String.valueOf(expiresIn)),JSON.toJSONString(thirdAccountDy));
set(tokenDy, Integer.parseInt(String.valueOf(expiresIn)),JSON.toJSONString(thirdAccountDy));
} else {
log.warn("dy_access_token_error,code={},resultdy={}", resultCode, JSONObject.toJSONString(result));
}
......@@ -243,7 +272,7 @@ public class DyVideoUniversalProcess extends UniversalProcess {
DYVIDEO_SYS_LOG.info("DouyinBehaviorKafkaConsumer.douyin code error,userId={},result={}",userId,JSON.toJSONString(result));
if (resultCode == 28001008) {
//删除授权过期token
delToken(tokenDy);
del(tokenDy);
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));
}
......@@ -259,4 +288,108 @@ public class DyVideoUniversalProcess extends UniversalProcess {
return resultCountMap;
}
public void uploadCallbackUserInfo(StoryNovelAction action) {
VideoUpload videoUpload = action.getVideoUpload();
String url = Objects.equals(env.getActiveProfiles()[0],"prod") ? lottoProdUrl : lottoDevUrl;
String result = "";
String resultCode = "";
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 = (String) JSON.parseObject(result).get("code");
if ("0".equals(resultCode)) {
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),e);
}
}
public void uploadCallbackAdsInfo(StoryNovelAction action, String jsonBody) {
VideoUpload videoUpload = action.getVideoUpload();
String url = Objects.equals(env.getActiveProfiles()[0],"prod") ? lottoProdUrl : lottoDevUrl;
String result = "";
String resultCode = "";
try {
url += "microapp/record/info/apxsbkjc";
result = HttpUtil.post(url, jsonBody);
resultCode = (String) JSON.parseObject(result).get("code");
if ("0".equals(resultCode)) {
DYVIDEO_SYS_LOG.info("dyvideo upload ads success,result={},videoUpload={}",JSONObject.toJSONString(result),JSONObject.toJSONString(videoUpload));
} else {
DYVIDEO_ERROR_LOG.error("dyvideo upload ads fail,result={},videoUpload={}",JSONObject.toJSONString(result),JSONObject.toJSONString(videoUpload));
}
} catch (Throwable e) {
DYVIDEO_ERROR_LOG.error("dyvideo upload ads error,videoUpload={}",JSONObject.toJSONString(videoUpload),e);
}
}
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")) * 1000)));
obj.put("event_name",jsonObject.getString("ad_type"));
jsonArray.add(obj);
}
}
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.douyin code succ,userId={},jsonArray={}",userId,JSON.toJSONString(jsonArray));
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> {
@Override
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);
}
}
......
package com.lwby.marketing.att.dyvideo.handle;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lwby.marketing.att.AttributionStatus;
import com.lwby.marketing.att.BehavoirType;
......@@ -63,23 +64,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
public void process(StoryNovelAction action) {
VideoUpload videoUpload = action.getVideoUpload();
long userId = action.getUserId();
int platformId = action.getPlatformId();
Long channelId = action.getChannelId();
long activeTime = videoUpload.getActiveTime();
long currentTime = System.currentTimeMillis();
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(
"{\n"
+ " \"400\": \"ttf2f6844b6dc9702901_d4ac08a22f80f73256836fdd9655dbb0b6e6de7c\",\n"
......@@ -89,58 +78,89 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
//走平台
String dyMarketPlatformAppId = dyMarketPlatformAppIdJson.getString(platformKey);
List<String> dyMarketPlatformAppIdList = new ArrayList<>();
String tokenDy = "";
ThirdAccountDy thirdAccountDy = null;
if (dyMarketPlatformAppId != null) {
dyMarketPlatformAppIdList = Arrays.asList(dyMarketPlatformAppId.split("_"));
String tokenDy = "token_dy_" + dyMarketPlatformAppIdList.get(0);
ThirdAccountDy thirdAccountDy = null;
DYVIDEO_SYS_LOG.info("thirdAccountDy url={}",Objects.equals(env.getActiveProfiles()[0],"prod") ? tokenDyProdUrl : tokenDyDevUrl);
if (up.existsOld(tokenDy)) {
thirdAccountDy = up.getOld(ThirdAccountDy.class, tokenDy);
tokenDy = "token_dy_" + dyMarketPlatformAppIdList.get(0);
DYVIDEO_SYS_LOG.info("thirdAccountDy url={}",
Objects.equals(env.getActiveProfiles()[0], "prod") ? tokenDyProdUrl : tokenDyDevUrl);
if (up.exists(tokenDy)) {
thirdAccountDy = up.get(ThirdAccountDy.class, tokenDy);
} else {
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) {
//平均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();
LocalTime two = LocalTime.of(2, 0, 0); // 获取当天6点的时间
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指标
JSONArray jsonArray = new JSONArray();
if (now.toLocalTime().isBefore(two)) {
//当天2点之前,查两天,先查昨天的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);
if (resultCountMap != null && resultCountMap.size() != 0) {
tvcCount = resultCountMap.get("tvc");
if (tvcCount != null) {
tvcCount = tvcCount / 100;
}
motivateCount = resultCountMap.get("motivate");
pecpmCount = resultCountMap.get("pecpm");
}
jsonArray = up.getUploadAdsInfo(jsonArray,day,action, thirdAccountDy.getAccessToken(),tokenDy, dyMarketPlatformAppIdList,env);
}
jsonArray = up.getUploadAdsInfo(jsonArray,date,action, thirdAccountDy.getAccessToken(),tokenDy, dyMarketPlatformAppIdList,env);
if (jsonArray.size()>0) {
up.uploadCallbackAdsInfo(action,jsonArray.toJSONString());
}
//查询今天的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);
if (resultCountMap != null && resultCountMap.size() != 0) {
tvcCount = resultCountMap.get("tvc");
......@@ -150,90 +170,101 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
motivateCount = resultCountMap.get("motivate");
pecpmCount = resultCountMap.get("pecpm");
}
if ((tvcCount != 0 && motivateCount != 0)) {
Double ecpmAvgCountD = (double)tvcCount / motivateCount;
ecpmAvgCount = ecpmAvgCountD.intValue();
DYVIDEO_SYS_LOG.info("ecpmAvgCount success,ecpmAvgCount={},tvcCount={},motivateCount={},djChanel={},userId={}",ecpmAvgCount,tvcCount,motivateCount,channelId,userId);
} else {
DYVIDEO_SYS_LOG.info("behavoir not receive data,tvcCount={},motivateCount={},djChanel={},userId={}",tvcCount,motivateCount,channelId,userId);
action.stop(true);
return;
}
//查询今天的ecpm指标
resultCountMap = up.getResultCountList(date, openId, accessToken, tvcCount, motivateCount, pecpmCount,
pecpmModel, userId, tokenDy, dyMarketPlatformAppIdList,env);
if (resultCountMap != null && resultCountMap.size() != 0) {
tvcCount = resultCountMap.get("tvc");
if (tvcCount != null) {
tvcCount = tvcCount / 100;
}
motivateCount = resultCountMap.get("motivate");
pecpmCount = resultCountMap.get("pecpm");
}
if ((tvcCount != 0 && motivateCount != 0)) {
Double ecpmAvgCountD = (double)tvcCount / motivateCount;
ecpmAvgCount = ecpmAvgCountD.intValue();
DYVIDEO_SYS_LOG.info("ecpmAvgCount success,ecpmAvgCount={},tvcCount={},motivateCount={},djChanel={},userId={}",ecpmAvgCount,tvcCount,motivateCount,channelId,userId);
} else {
DYVIDEO_SYS_LOG.info("behavoir not receive data,tvcCount={},motivateCount={},djChanel={},userId={}",tvcCount,motivateCount,channelId,userId);
action.stop(true);
return;
}
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;
}
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);
return;
}
if (type.getValue().startsWith(BehavoirType.ECPMAVGMODELCOUNT.getValue()) && null != ecpmAvgCount) {
if (ecpmAvgCount < behavoirVal.intValue()) {
DYVIDEO_SYS_LOG.info("ecpm not up to the standard,ecpmAvgCount={},ecpmAvgModelCount={},djChanel={},userId={}",ecpmAvgCount,behavoirVal,channelId,userId);
action.stop(true);
break;
}
deliveryDeviceInfo.setEcpmAvgCount(String.valueOf(ecpmAvgCount));
continue;
deliveryDeviceInfo.setMotivateCount(String.valueOf(motivateCount));
continue;
}
if (type.getValue().startsWith(BehavoirType.ECPMAVGMODELCOUNT.getValue()) && null != ecpmAvgCount) {
if (ecpmAvgCount < behavoirVal.intValue()) {
DYVIDEO_SYS_LOG.info("ecpm not up to the standard,ecpmAvgCount={},ecpmAvgModelCount={},djChanel={},userId={}",ecpmAvgCount,behavoirVal,channelId,userId);
action.stop(true);
return;
}
if (type.getValue().startsWith(BehavoirType.PECPMMODELCOUNT.getValue()) && null != pecpmCount) {
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);
break;
}
deliveryDeviceInfo.setPecpmCount(String.valueOf(behavoirVal));
deliveryDeviceInfo.setPerecpmSize(String.valueOf(pecpmCount));
break;
deliveryDeviceInfo.setEcpmAvgCount(String.valueOf(ecpmAvgCount));
continue;
}
if (type.getValue().startsWith(BehavoirType.PECPMMODELCOUNT.getValue()) && null != pecpmCount) {
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);
return;
}
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());
//等于空 或 100直接回传
if (sprDedu == null || sprDedu == 100) {
action.getMedia().notify(action);
up.notifyResult(action, type.getTopic()+"_test",type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
return;
}
CallBackType type = CallBackType.getCallBackTypeByType(action.getType());
//等于空 或 100直接回传
if (sprDedu == null || sprDedu == 100) {
action.getMedia().notify(action);
up.notifyResult(action, type.getTopic(),type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
return;
}
//总数
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());
long channelTotalCount = up.incrby(channelTotal, 0, 60 * 60 * 24);
long channelCallbackCount = up.incrby(channelCallback, 0, 60 * 60 * 24);
up.incrby(channelTotal, 1);
if (isCallback(channelTotalCount, channelCallbackCount, sprDedu)) {
//回传,回传个数 + 1
up.incrby(channelCallback, 1);
action.getMedia().notify(action);
up.notifyResult(action, type.getTopic()+"_test",type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
DYVIDEO_SYS_LOG.info(
"ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}",
action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 1);
} else {
up.notifyResult(action,"ocpc_behavior_test", AttributionStatus.NORMAL_DEDUCTION_CALLBACK);
up.set(up.getFirstCheckerKey(action), up.getExpire(action), "1");
DYVIDEO_SYS_LOG.info(
"ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}",
action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 0);
}
//总数
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());
long channelTotalCount = up.incrby(channelTotal, 0, 60 * 60 * 24);
long channelCallbackCount = up.incrby(channelCallback, 0, 60 * 60 * 24);
up.incrby(channelTotal, 1);
if (isCallback(channelTotalCount, channelCallbackCount, sprDedu)) {
//回传,回传个数 + 1
up.incrby(channelCallback, 1);
action.getMedia().notify(action);
up.notifyResult(action, type.getTopic(),type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
DYVIDEO_SYS_LOG.info(
"ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}",
action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 1);
} else {
up.notifyResult(action,type.getTopic(), AttributionStatus.NORMAL_DEDUCTION_CALLBACK);
up.set(up.getFirstCheckerKey(action), up.getExpire(action), "1");
DYVIDEO_SYS_LOG.info(
"ChannelAttributionFlow.process0.deduction doing dynamic, platformId = {}, channel = {}, planId={}, sprDedu = {}, channelTotalCount = {}, channelCallbackCount = {}, v = {}",
action.getPlatformId(), action.getChannelId(),action.getPlanId(), sprDedu, channelTotalCount, channelCallbackCount, 0);
}
}
}
......
......@@ -20,7 +20,7 @@ public class StoreDyVideoAttributionFlow extends NodeFlow<StoryNovelAction> {
//商店归因通知
if(Objects.isNull(action.getDeliveryDeviceInfo())){
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); //结束后面所有执行流程
}
......
package com.lwby.marketing.att.dyvideo.handle;
import com.alibaba.fastjson.JSON;
import com.lwby.marketing.att.CallBackType;
import com.lwby.marketing.att.dyvideo.DyVideoUniversalProcess;
import com.lwby.marketing.flow.NodeFlow;
......@@ -7,6 +8,7 @@ import com.lwby.marketing.vo.StoryNovelAction;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Objects;
/**
* @author songxinyu
......@@ -24,8 +26,14 @@ public class UploadDyVideoCallFlow extends NodeFlow<StoryNovelAction> {
boolean success = action.getMedia().notify(action);
if (success) {
//根据source判断是否给指定外包上报
if (Objects.equals(action.getVideoUpload().getSource(),"lotto")) {
up.uploadCallbackUserInfo(action);
action.getDeliveryDeviceInfo().setSrc(action.getVideoUpload().getSource());
}
action.getVideoUpload().setActiveTime(System.currentTimeMillis());
up.notifyResult(action, type.getTopic()+"_test",type.getStatus());
up.set(String.format("video:upload:%s", action.getOpenId()),60 * 60 * 24 * 7, JSON.toJSONString(action.getVideoUpload()));
up.notifyResult(action, type.getTopic(),type.getStatus());
up.set(up.getFirstCheckerKey(action),up.getExpire(action),"1");
}
}
......
......@@ -50,7 +50,7 @@ public class ParameterSetupVideoAppFlow extends NodeFlow<NovelAction> {
//匹配设备ID
for(DeviceVideoType type: DeviceVideoType.values()){
deviceIdKey = type.getDeviceId(clientInfo);
if(null != deviceIdKey && null != (deliveryDeviceInfo = up.getOldMarket(DeliveryDeviceInfo.class,assembleKey(deviceIdKey,platformId)))){
if(null != deviceIdKey && null != (deliveryDeviceInfo = up.get(DeliveryDeviceInfo.class,assembleKey(deviceIdKey,platformId)))){
clientInfo.setOaid(deliveryDeviceInfo.getOaid()); //回补OAID
action.setDeliveryDeviceInfo(deliveryDeviceInfo);
action.setDeviceVideoType(type);
......
......@@ -25,19 +25,19 @@ import java.util.Map;
@EnableKafka
public class DyVideoActiveKafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}")
@Value("${spring.kafka.bootstrap-servers}")
private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}")
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}")
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${system.consumer.dyvideo.active.group_id}")
private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}")
@Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig;
......
......@@ -24,19 +24,19 @@ import java.util.Map;
@EnableKafka
public class DyVideoBehavoirKafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}")
@Value("${spring.kafka.bootstrap-servers}")
private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}")
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}")
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${system.consumer.dyvideo.behavoir.group_id}")
private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}")
@Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig;
......
......@@ -25,19 +25,19 @@ import java.util.Map;
@EnableKafka
public class KafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}")
@Value("${spring.kafka.bootstrap-servers}")
private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}")
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}")
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${system.consumer.novel.active.group_id}")
private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}")
@Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig;
......
......@@ -25,19 +25,19 @@ import java.util.Map;
@EnableKafka
public class KafkaStoreConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}")
@Value("${spring.kafka.bootstrap-servers}")
private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}")
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}")
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${system.consumer.novel.storeActive.group_id}")
private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}")
@Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig;
......
......@@ -24,19 +24,19 @@ import java.util.Map;
@EnableKafka
public class VideoAppActiveKafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}")
@Value("${spring.kafka.bootstrap-servers}")
private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}")
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}")
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${system.consumer.videoapp.active.group_id}")
private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}")
@Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig;
......
......@@ -25,19 +25,19 @@ import java.util.Map;
@EnableKafka
public class VideoAppBehavoirKafkaConsumerConfig {
@Value("${spring.kafka2.bootstrap-servers}")
@Value("${spring.kafka.bootstrap-servers}")
private String servers;
@Value("${spring.kafka2.consumer.enable-auto-commit}")
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka2.consumer.auto-offset-reset}")
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${system.consumer.videoapp.behavoir.group_id}")
private String groupId;
@Value("${spring.kafka2.consumer.max-poll-records}")
@Value("${spring.kafka.consumer.max-poll-records}")
private int maxPollRecordsConfig;
......
package com.lwby.marketing.controller;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.lwby.marketing.notify.Media;
import com.lwby.marketing.util.CacheKeyUtils;
import com.lwby.marketing.util.ResultConstant;
import com.lwby.marketing.vo.ClientInfo;
import com.lwby.marketing.vo.DeliveryDeviceInfo;
import com.lwby.marketing.vo.NovelAction;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController
@Slf4j
@RequestMapping(value = "/market_growth")
public class ClickbackService extends ServiceHelper{
final static ImmutableSet<String> filter = ImmutableSet.of("click.special.param:00000000-0000-0000-0000-000000000000","9f89c84a559f573636a47ff8daed0d33","__IMEI__","null","NULL");
final static ImmutableMap<String, Integer> RESULT_SUCCESS = ImmutableMap.of("status", ResultConstant.CALL_BACK_SUCCESS);
final static int bookIdExpireTime = 604800;
@Resource
public RedisTemplate<String, String> redisTemplate;
@Resource(name = "storyKafka")
public KafkaTemplate<String, String> storyKafkaTemplate;
private static final String UAPRE = "Mozilla/5.0 (iPhone; CPU iPhone OS ";
private static final String UASUF = " like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148";
@RequestMapping("/jrtt")
@ResponseBody
public Object jrttClick(@RequestParam Map<String, String> params){
NovelAction action = fullJrtt(params);
for(DeviceType type: DeviceType.values()){
String deviceIdKey = type.getDeviceId(action.getClientInfo());
if(null != deviceIdKey){
DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo();
if (StringUtils.isNotEmpty(ddi.getDj_channel())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getBook_id())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getBook_id()), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getPartId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getPartId()), bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
if (type == DeviceType.IP) {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} else {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
log.info("jrttClick param,params={}",JSON.toJSONString(params));
return RESULT_SUCCESS;
}
@RequestMapping("/weChat")
@ResponseBody
public Object wechatClick(@RequestParam Map<String, String> params){
NovelAction action = fullWeChat(params);
for(DeviceType type: DeviceType.values()){
String deviceIdKey = type.getDeviceId(action.getClientInfo());
if(null != deviceIdKey){
DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo();
if (StringUtils.isNotEmpty(ddi.getDj_channel())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getBook_id())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryBookIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getBook_id()), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getPartId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryPartIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getPartId()), bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
if (type == DeviceType.IP) {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} else {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
log.info("wechatClick param,params={}",JSON.toJSONString(params));
return RESULT_SUCCESS;
}
@RequestMapping("/jrttFreeVideo")
@ResponseBody
public Object jrttFreeVideoClick(@RequestParam Map<String, String> params){
NovelAction action = fullJrttFreeVideo(params);
for(DeviceVideoType type: DeviceVideoType.values()){
String deviceIdKey = type.getDeviceId(action.getClientInfo());
if(null != deviceIdKey){
DeliveryDeviceInfo ddi = action.getDeliveryDeviceInfo();
if (StringUtils.isNotEmpty(ddi.getDj_channel())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getChannelByDeviceIdKeyAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(Integer.parseInt(ddi.getDj_channel())), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getVideoResourceId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryVRIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getVideoResourceId()), bookIdExpireTime, TimeUnit.SECONDS);
if (StringUtils.isNumeric(ddi.getVideoId())) {
redisTemplate.opsForValue().set(CacheKeyUtils.getDeliveryVIIdCacheKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi.getVideoId()), bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
if (type == DeviceVideoType.IDFA) {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKey(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
} else {
redisTemplate.opsForValue().set(CacheKeyUtils.getClickKeyByIdfaAndPlatformId(deviceIdKey, ddi.getPlatform_id()),JSON.toJSONString(ddi),bookIdExpireTime, TimeUnit.SECONDS);
}
}
}
log.info("jrttFreeVideoClick param,params={}",JSON.toJSONString(params));
return RESULT_SUCCESS;
}
public NovelAction fullJrtt(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo();
clientInfo.setOaid(params.get("oaid_md5"));
clientInfo.setIdfa(params.get("idfaMd5"));
clientInfo.setClientIp(params.get("ip"));
clientInfo.setUa(params.get("ua"));
//TODO;没有验证
clientInfo.setPhoneModel(StringUtils.defaultIfEmpty(encode(params.get("model")), getModelByUa(clientInfo.getUa())));
return getNovelAction(params,Media.NOVEL_JRTT,clientInfo);
}
public NovelAction fullWeChat(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo();
String deviceOsType = params.get("device_os_type");
if ("ios".equals(deviceOsType)) {
clientInfo.setIdfa(params.get("muid"));
}
clientInfo.setOaid(params.get("hash_oaid"));
clientInfo.setClientIp(params.get("ip"));
clientInfo.setUa(params.get("user_agent"));
clientInfo.setPhoneModel(StringUtils.defaultIfEmpty(encode(params.get("model")), getModelByUa(clientInfo.getUa())));
return getNovelAction(params,Media.NOVEL_GDT,clientInfo);
}
public NovelAction fullJrttFreeVideo(Map<String, String> params) {
ClientInfo clientInfo = new ClientInfo();
clientInfo.setOaid(params.get("oaid_md5"));
String idfa = params.get("idfa");
if (!filter.contains(idfa) && StringUtils.isNotEmpty(idfa)) {
clientInfo.setIdfa(SecureUtil.md5(idfa));
}
clientInfo.setClientIp(params.get("ip"));
clientInfo.setUa(params.get("ua"));
clientInfo.setOs(params.get("os"));
clientInfo.setPhoneModel(StringUtils.defaultIfEmpty(encode(params.get("model")), getModelByUa(clientInfo.getUa())));
return getNovelAction(params,Media.VIDEOAPP_JRTT,clientInfo);
}
public NovelAction getNovelAction(Map<String, String> params,Media media,ClientInfo clientInfo){
DeliveryDeviceInfo deliveryDeviceInfo = new DeliveryDeviceInfo();
deliveryDeviceInfo.setClick_time(System.currentTimeMillis());
deliveryDeviceInfo.setAd_group_id(params.get("campaign_id"));
deliveryDeviceInfo.setMedia(media.name);
deliveryDeviceInfo.setDj_channel(params.get("channel"));
//短剧视频合集和视频id
deliveryDeviceInfo.setVideoResourceId(params.get("videoResourceId"));
deliveryDeviceInfo.setVideoId(params.get("videoId"));
deliveryDeviceInfo.setBook_id(StringUtils.defaultIfBlank(params.get("book"), StringUtils.defaultIfBlank(params.get("books"), params.get("book_id"))));
if (media.name.equals(Media.NOVEL_GDT.name)) {
deliveryDeviceInfo.setClick_id(params.get("click_id"));
deliveryDeviceInfo.setAd_creative_id(params.get("ad_id"));
deliveryDeviceInfo.setAd_plan_id(params.get("adgroup_id"));
deliveryDeviceInfo.setPlatform_id(params.get("platformId"));
deliveryDeviceInfo.setCallback_url(params.get("callback"));
deliveryDeviceInfo.setAdvertiser_id(params.get("account_id"));
} else {
deliveryDeviceInfo.setAd_creative_id(params.get("cid"));
deliveryDeviceInfo.setAd_plan_id(params.get("adid"));
deliveryDeviceInfo.setCallback_param(params.get("callback_param"));
deliveryDeviceInfo.setPlatform_id(params.get("platform_id"));
if (Objects.isNull(deliveryDeviceInfo.getCallback_param())) {
deliveryDeviceInfo.setCallback_url(params.get("callback_url"));
}
deliveryDeviceInfo.setAdvertiser_id(params.get("advertiser_id"));
}
deliveryDeviceInfo.setUuid(UUID.randomUUID().toString());
deliveryDeviceInfo.setAd_platform_type(params.get("ad_platform_type"));
deliveryDeviceInfo.setTarget_audience(params.get("target_audience"));
deliveryDeviceInfo.setIp(params.get("ip"));
deliveryDeviceInfo.setOaid(filter.contains(params.get("oaid"))?null:params.get("oaid"));
deliveryDeviceInfo.setModel(emptyIsNull(clientInfo.getPhoneModel()));
//通投智选union_site
deliveryDeviceInfo.setUnion_site(params.get("union_site"));
deliveryDeviceInfo.setPartId(params.get("part_id"));
//巨量广告体验版中特有的宏参,代表巨量广告体验版的广告ID
deliveryDeviceInfo.setPromotion_id(emptyIsNull(params.get("promotion_id")));
//巨量广告体验版中特有的宏参,代表巨量广告体验版的项目ID
deliveryDeviceInfo.setProject_id(emptyIsNull(params.get("project_id")));
//巨量广告体验版中的广告名称
deliveryDeviceInfo.setPromotion_name(emptyIsNull(params.get("promotion_name")));
//巨量广告体验版中的项目名称
deliveryDeviceInfo.setProject_name(emptyIsNull(params.get("project_name")));
//信息流投放广告来源(碎片 1 书籍 2)
deliveryDeviceInfo.setSource(parseInt(params.get("source")));
deliveryDeviceInfo.setMid1(emptyIsNull(params.get("mid1")));
deliveryDeviceInfo.setMid2(emptyIsNull(params.get("mid2")));
deliveryDeviceInfo.setMid3(emptyIsNull(params.get("mid3")));
deliveryDeviceInfo.setMid4(emptyIsNull(params.get("mid4")));
deliveryDeviceInfo.setMid5(emptyIsNull(params.get("mid5")));
deliveryDeviceInfo.setMid6(emptyIsNull(params.get("mid6")));
storyKafkaTemplate.send("growth_ad_click", JSONObject.toJSONString(params));
return new NovelAction(clientInfo,deliveryDeviceInfo);
}
enum DeviceType {
OAID("oaid", (c) -> isNotEmptyAndSNull(c.getOaid())?c.getOaid():null),
IDFA("idfa",(c) -> isNotEmptyAndSNull(c.getIdfa())?c.getIdfa():null),
IP_UA("ipua",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getUa())?SecureUtil.md5(c.getClientIp().concat(StringUtils.substringBefore(c.getUa(), " Chrome/"))):null),
IP_MODEL("ipmodel",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getPhoneModel())?SecureUtil.md5(c.getClientIp().concat(c.getPhoneModel())):null),
IP("ip",(c) -> isNotEmptyAndSNull(c.getClientIp())?SecureUtil.md5(c.getClientIp()):null);
private String value;
private Function<ClientInfo,String> fun;
DeviceType(String value,Function<ClientInfo,String> fun) {
this.value = value;
this.fun = fun;
}
public String getValue() {
return this.value;
}
public String getDeviceId(ClientInfo clientInfo){
return fun.apply(clientInfo);
}
private static boolean isNotEmptyAndSNull(String str) {
return StringUtils.isNotEmpty(str) && !filter.contains(str);
}
}
enum DeviceVideoType {
OAID("oaid", (c) -> isNotEmptyAndSNull(c.getOaid())?c.getOaid():null),
IDFA("idfa",(c) -> isNotEmptyAndSNull(c.getIdfa())?c.getIdfa():null),
IP_UA("ipua",(c) ->
(isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getUa())) ?
(("0".equals(c.getOs()) ? SecureUtil.md5(c.getClientIp().concat(StringUtils.substringBefore(c.getUa(), " Chrome/"))) :
( c.getUa().startsWith("bi kan duan ju") ? SecureUtil.md5(c.getClientIp().concat(UAPRE + Arrays.stream(c.getSystemVersion().split("\\.")).collect(Collectors.joining("_")) + UASUF)):
SecureUtil.md5(c.getClientIp().concat(c.getUa()))))):null),
IP_MODEL("ipmodel",(c) -> isNotEmptyAndSNull(c.getClientIp()) && isNotEmptyAndSNull(c.getPhoneModel())?SecureUtil.md5(c.getClientIp().concat(c.getPhoneModel())):null);
private String value;
private Function<ClientInfo,String> fun;
DeviceVideoType(String value, Function<ClientInfo,String> fun) {
this.value = value;
this.fun = fun;
}
public String getValue() {
return this.value;
}
public String getDeviceId(ClientInfo clientInfo){
return fun.apply(clientInfo);
}
private static boolean isNotEmptyAndSNull(String str) {
return StringUtils.isNotEmpty(str) && !"null".equals(str);
}
}
public static void main(String[] args) {
String json = "{\"adgroup_id\":\"15559122058\",\"ad_type\":\"11\",\"billing_event\":\"4\",\"channel\":\"220605870\","
+ "\"source\":\"2\",\"media\":\"gdt\",\"hash_oaid\":\"36d7f0dcdba566fd4cf4775372302f32\",\"process_time\":\"1713339657\","
+ "\"promoted_object_id\":\"1109849597\",\"click_time\":\"1713339698\","
+ "\"hash_android_id\":\"c6098b0524291a98633d0f67f7e84555\",\"model\":\"\",\"part_id\":\"1\",\"agcrycy_id\":\"14731783\","
+ "\"campaign_id\":\"15455482127\",\"oaid\":\"C8A752559EBB4D20992DA25295B71770edf45536a4126fd1a6bda0ff4c2a86ef\","
+ "\"user_agent\":\"Mozilla/5.0 (Linux; Android 14; PHW110 Build/UKQ1.230924.001; wv) AppleWebKit/537.36 (KHTML, like "
+ "Gecko) Version/4.0 Chrome/117.0.5938.60 Mobile Safari/537.36\",\"impression_id\":\"wx0e4e3enptdabdi02\",\"ip\":\"117"
+ ".136.73.227\",\"deeplink_url\":\"\",\"platformId\":\"6\",\"ad_platform_type\":\"1\","
+ "\"muid\":\"0924aa8b5262b4e499badcb465c54a27\",\"device_os_type\":\"android\",\"ad_id\":\"15559122968\","
+ "\"account_id\":\"39369307\",\"books\":\"4264277\",\"click_id\":\"wxadclickmjt7d7ppq7loy\","
+ "\"promoted_object_type\":\"12\",\"callback\":\"http://tracking.e.qq"
+ ".com/conv?cb=8Vi3l97GT09y6swCAmoS2jxWwesCA3RFdloqWbslnfr7rRn2qQGqogWHeVOy6ZNF&conv_id=39378482\","
+ "\"request_id\":\"wx0e4e3enptdabdi\",\"click_sku_id\":\"4264277\"}";
Map<String,String> map = JSONObject.parseObject(json,Map.class);
ClientInfo clientInfo = new ClientInfo();
clientInfo.setUa("Mozilla/5.0 (Linux; Android 14; PHW110 Build/UKQ1.230924.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/117.0.5938.60 Mobile Safari/537.36");
clientInfo.setPhoneModel(StringUtils.defaultIfEmpty(encode1(map.get("model")), getModelByUa1(clientInfo.getUa())));
System.out.println(clientInfo.getPhoneModel());
}
public static String encode1(String params){
try {
return URLEncoder.encode(params,"utf-8");
} catch (UnsupportedEncodingException e) {
return null;
}
}
public static String getModelByUa1(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;
}
}
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
import java.util.Objects;
/**
* @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";
private static final Logger DYVIDEO_SYS_LOG = LoggerFactory.getLogger("dyvideo.sys");
private static final Logger DYVIDEO_ERROR_LOG = LoggerFactory.getLogger("dyvideo.error");
@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));
if (Objects.nonNull(videoUpload)) {
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);
DYVIDEO_SYS_LOG.error("DyVideoController uploadBehavoir uped,uploadKey={}",uploadKey);
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) ;
DYVIDEO_SYS_LOG.error("DyVideoController uploadBehavoir send back fail,uploadKey={},code={}",uploadKey,resultCode);
}
} catch (Exception e) {
map.put("code", ResultConstant.CALL_BACK_FAIL);
map.put("message",ResultConstant.CALL_BACK_FAIL_MESSAGE);
result = JSONObject.toJSONString(map) ;
DYVIDEO_ERROR_LOG.error("DyVideoController uploadBehavoir exception,uploadKey={}",uploadKey,e);
return result;
}
} else {
map.put("code", ResultConstant.CALL_BACK_NOCACHE_FAIL);
map.put("message",ResultConstant.CALL_BACK_NOCACHE_MESSAGE);
result = JSONObject.toJSONString(map) ;
DYVIDEO_SYS_LOG.error("DyVideoController uploadBehavoir no cache,videoUpload={}",JSONObject.toJSONString(videoUpload));
}
return result;
}
public String assembleKey(String openId) {
return String.format("video:upload:%s", openId);
}
}
package com.lwby.marketing.controller;
import cn.hutool.crypto.SecureUtil;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class ServiceHelper {
public String emptyIsNull(String params){
return StringUtils.defaultIfEmpty(params,null);
}
public String encode(String params){
try {
return URLEncoder.encode(params,"utf-8");
} catch (UnsupportedEncodingException e) {
return null;
}
}
public Integer parseInt(String params){
try {
return Integer.valueOf(params);
}catch (Exception e){
return null;
}
}
public 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;
}
}
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 {
DY_VIDEO_JRTT("jrtt", Platform.DY_VIDEO, "今日头条",new DyVideoJRTTNotify()),
VIDEOAPP_JRTT("jrtt_freevideo", Platform.VIDEO, "今日头条",new VideoAppJRTTNotify());
final String name;
public final String name;
final Platform platform;
final String desc;
final BaseNotiry baseNotify;
......
......@@ -46,12 +46,10 @@ public class DyVideoJRTTNotify extends DYNotify {
String userJson = JSONObject.toJSONString(request);
try {
//TODO;测试不执行
//String result = HttpUtil.post(ATTRIBUTE_URL, userJson);
//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());
return true;
String result = HttpUtil.post(ATTRIBUTE_URL, userJson);
Integer resultCode = (Integer) JSON.parseObject(result).get("code");
DYVIDEO_SYS_LOG.info("DyVideoJRTTNotify.video.{}.upload,userId={},channel={},platform={},code={}",eventType,na.getUserId(),na.getChannelId(),na.getPlatformId(),resultCode);
return resultCode == 0;
} catch (Exception e) {
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 {
private String perecpmSize;
private long activeTime;
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;
import org.apache.commons.lang3.StringUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
......@@ -13,6 +17,17 @@ public class CacheKeyUtils {
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";
private static final String CACHE_VRID_PRE = "vr:";
private static final String CACHE_VID_PRE = "vi:";
public static String getBehavoirKey(Long userId) {
return CACHE_BEHAVIOR_PREFIX + userId + "_" + df.format(new Date()) + "_fv";
}
......@@ -20,4 +35,51 @@ public class CacheKeyUtils {
public static String getVideoBehavoirKey(Long userId) {
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;
}
public static String getDeliveryVRIdCacheKey(String deviceKey, String platformId) {
return CACHE_VRID_PRE + deviceKey + ":" + platformId;
}
public static String getDeliveryVIIdCacheKey(String deviceKey, String platformId) {
return CACHE_VID_PRE + deviceKey + ":" + platformId;
}
}
......@@ -28,6 +28,14 @@ public class DateTimUtils {
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天
*
......
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 Integer CALL_BACK_NOCACHE_FAIL = 3;
public final static String CALL_BACK_SUCCESS_MESSAGE = "上报成功";
public final static String CALL_BACK_FAIL_MESSAGE = "上报失败";
public final static String CALL_BACK_UPED_MESSAGE = "已上报一次";
public final static String CALL_BACK_NOCACHE_MESSAGE = "无点击缓存,用户超过7天";
}
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
......@@ -125,4 +125,6 @@ public class DeliveryDeviceInfo {
private String openId;
private String src;
}
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