Commit 870c5e6d authored by 宋新宇's avatar 宋新宇

dy短剧关键行为优化

parent 9ae599ed
...@@ -66,6 +66,7 @@ public class DyVideoBehavoirConsumer { ...@@ -66,6 +66,7 @@ public class DyVideoBehavoirConsumer {
event.getUserUploadEvent()); event.getUserUploadEvent());
executorByDyVideoBehavoir.execute(action); executorByDyVideoBehavoir.execute(action);
DYVIDEO_SYS_LOG.info("media.behavoir.dyVideo.end,topic={}, bookStoreEvent={}", data.topic(), JSON.toJSONString(event));
} catch (Throwable e) { } catch (Throwable e) {
DYVIDEO_ERROR_LOG.error("dy.video.behavoir.onMessage failed, data={}, costTime={} ms", data.value(), DYVIDEO_ERROR_LOG.error("dy.video.behavoir.onMessage failed, data={}, costTime={} ms", data.value(),
System.currentTimeMillis() - begin, e); System.currentTimeMillis() - begin, e);
......
...@@ -10,6 +10,7 @@ import com.lwby.marketing.att.UniversalProcess; ...@@ -10,6 +10,7 @@ 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.util.CacheKeyUtils;
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;
...@@ -17,6 +18,7 @@ import com.lwby.marketing.vo.StoryNovelAction; ...@@ -17,6 +18,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.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;
import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.BeanPropertyRowMapper;
...@@ -26,9 +28,8 @@ import org.springframework.stereotype.Component; ...@@ -26,9 +28,8 @@ import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFuture;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.text.SimpleDateFormat;
import java.util.Map; import java.util.*;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
...@@ -42,6 +43,14 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -42,6 +43,14 @@ public class DyVideoUniversalProcess extends UniversalProcess {
@Resource @Resource
private RedisTemplate<String,String> oldMarketRedisTemplate; private RedisTemplate<String,String> oldMarketRedisTemplate;
SimpleDateFormat dfh = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
private static final String url = "https://open.douyin.com/api/traffic/v1/rt_ecpm/query/";
private static final String tokenDyDevUrl = "https://open-sandbox.douyin.com/oauth/client_token/";
private static final String tokenDyProdUrl = "https://open.douyin.com/oauth/client_token/";
/** /**
* 通知处理结果 * 通知处理结果
*/ */
...@@ -169,4 +178,86 @@ public class DyVideoUniversalProcess extends UniversalProcess { ...@@ -169,4 +178,86 @@ public class DyVideoUniversalProcess extends UniversalProcess {
return null; return null;
} }
} }
public Map<String,Integer> getResultCountList(Date day, String openid, String accessToken, Integer tvcCount, Integer motivateCount, Integer pecpmCount, Integer pecpmModelCount, Long userId, String tokenDy, List<String> dyMarketPlatformAppIdList,
Environment env) {
int pageNumer = 1;
Map<String,Integer> resultCountMap = new HashMap<>();
String upcBehaviorKey = CacheKeyUtils.getVideoBehavoirKey(userId);
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) {
if (Objects.isNull(tvcCount)) {
tvcCount = 0;
}
if (Objects.isNull(motivateCount)) {
motivateCount = 0;
}
if (Objects.isNull(pecpmCount)) {
pecpmCount = 0;
}
motivateCount += records.size();
for(JSONObject jsonObject : records) {
String cost = jsonObject.getString("cost");
Integer costI = Integer.parseInt(cost);
Double c = (double)(costI / 100);
int ct = c.intValue();
if (pecpmModelCount != null) {
if (ct>=pecpmModelCount) {
pecpmCount ++;
}
}
tvcCount += costI;
}
hsetNew(upcBehaviorKey,"tvc",60 * 60 * 24 * 3,JSON.toJSONString(tvcCount));
hsetNew(upcBehaviorKey,"mvc",60 * 60 * 24 * 3,JSON.toJSONString(motivateCount));
hsetNew(upcBehaviorKey,"vec",60 * 60 * 24 * 3,JSON.toJSONString(pecpmCount));
}
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("DouyinBehaviorKafkaConsumer.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("DyvideoBehaviorFlow.douyin code auth token expired,userId={},result={}",userId,JSON.toJSONString(result));
}
return null;
}
resultCountMap.put("tvc",tvcCount);
resultCountMap.put("motivate",motivateCount);
resultCountMap.put("pecpm",pecpmCount);
} catch (Throwable e) {
e.printStackTrace();
}
}
return resultCountMap;
}
} }
...@@ -3,6 +3,7 @@ package com.lwby.marketing.att.dyvideo.handle; ...@@ -3,6 +3,7 @@ package com.lwby.marketing.att.dyvideo.handle;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
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.CallBackType; import com.lwby.marketing.att.CallBackType;
import com.lwby.marketing.att.dyvideo.DyVideoUniversalProcess; import com.lwby.marketing.att.dyvideo.DyVideoUniversalProcess;
import com.lwby.marketing.att.novel.AttributionType; import com.lwby.marketing.att.novel.AttributionType;
...@@ -12,6 +13,7 @@ import com.lwby.marketing.po.VideoUpload; ...@@ -12,6 +13,7 @@ import com.lwby.marketing.po.VideoUpload;
import com.lwby.marketing.util.CacheKeyUtils; import com.lwby.marketing.util.CacheKeyUtils;
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.StoryNovelAction; import com.lwby.marketing.vo.StoryNovelAction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -51,11 +53,6 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -51,11 +53,6 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
private static final String tokenDyProdUrl = "https://open.douyin.com/oauth/client_token/"; private static final String tokenDyProdUrl = "https://open.douyin.com/oauth/client_token/";
SimpleDateFormat dfh = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
private static final String url = "https://open.douyin.com/api/traffic/v1/rt_ecpm/query/";
@Override @Override
public boolean checked(StoryNovelAction action) { public boolean checked(StoryNovelAction action) {
return action.getType() == 3; return action.getType() == 3;
...@@ -69,10 +66,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -69,10 +66,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
long activeTime = videoUpload.getActiveTime(); long activeTime = videoUpload.getActiveTime();
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
DeliveryDeviceInfo deliveryDeviceInfo = action.getDeliveryDeviceInfo();
long hour = TimeUnit.MILLISECONDS.toHours(currentTime - activeTime); long hour = TimeUnit.MILLISECONDS.toHours(currentTime - activeTime);
if (hour > 6) { if (hour > 6) {
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow expeed six hour ,videoUpload={},userId={}",JSON.toJSONString(videoUpload),userId); DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow expeed six hour ,videoUpload={},userId={}",JSON.toJSONString(videoUpload),userId);
//action.stop(true);
return; return;
} }
int platformId = action.getPlatformId(); int platformId = action.getPlatformId();
...@@ -80,29 +78,8 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -80,29 +78,8 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
AppChannelVO appChannel = up.getAppChannelByPlatformAndChannel(platformId,channelId); AppChannelVO appChannel = up.getAppChannelByPlatformAndChannel(platformId,channelId);
//处理关键行为上报 //处理关键行为上报
Integer ecpmAvgModelCount = null ;
Integer pecpmModelCount = null;
Integer motivateModelCount = null ;
String media = action.getMediaName();
String openId = action.getOpenId(); String openId = action.getOpenId();
if (Objects.nonNull(appChannel) && ((Objects.nonNull(appChannel.getEcpmAvgCount()) && Objects.nonNull(appChannel.getMotivationCount()))
|| (Objects.nonNull(appChannel.getEcpmPerCount()) && Objects.nonNull(appChannel.getMotivationCount())))) {
if (Objects.nonNull(appChannel.getEcpmAvgCount()) && Objects.nonNull(appChannel.getMotivationCount())) {
ecpmAvgModelCount = appChannel.getEcpmAvgCount().intValue();
motivateModelCount = appChannel.getMotivationCount().intValue();
}
if (Objects.nonNull(appChannel.getEcpmPerCount()) && Objects.nonNull(appChannel.getMotivationCount())) {
pecpmModelCount = appChannel.getEcpmPerCount().intValue();
motivateModelCount = appChannel.getMotivationCount().intValue();
}
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.cacheModel in table is set value,djChanel={},userId={},ecpmAvgModelCount={},pecpmModelCount={},motivateModelCount={}",channelId,userId,ecpmAvgModelCount,pecpmModelCount,motivateModelCount);
} else {
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.cacheModel in table is not set value,djChanel={},userId={}",channelId,userId);
//action.stop(true);
return;
}
JSONObject dyMarketPlatformAppIdJson = JSON.parseObject( JSONObject dyMarketPlatformAppIdJson = JSON.parseObject(
"{\n" "{\n"
+ " \"400\": \"ttf2f6844b6dc9702901_d4ac08a22f80f73256836fdd9655dbb0b6e6de7c\",\n" + " \"400\": \"ttf2f6844b6dc9702901_d4ac08a22f80f73256836fdd9655dbb0b6e6de7c\",\n"
...@@ -126,13 +103,13 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -126,13 +103,13 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
} }
if (thirdAccountDy != null) { if (thirdAccountDy != null) {
//平均ecpm次数 //平均ecpm次数
Integer ecpmAvgCount = null; Integer ecpmAvgCount = 0;
//每次ecpm次数 //每次ecpm次数
Integer pecpmCount = null; Integer pecpmCount = 0;
//激励视频次数 //激励视频次数
Integer motivateCount = null; Integer motivateCount = 0;
//激励视频总ecpm次数 //激励视频总ecpm次数
Integer tvcCount = null; Integer tvcCount = 0;
LocalDateTime now = LocalDateTime.now(); // 获取当前日期时间 LocalDateTime now = LocalDateTime.now(); // 获取当前日期时间
LocalTime six = LocalTime.of(6, 0, 0); // 获取当天6点的时间 LocalTime six = LocalTime.of(6, 0, 0); // 获取当天6点的时间
...@@ -146,8 +123,8 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -146,8 +123,8 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
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 = getResultCountList(day, openId, accessToken, tvcCount, motivateCount, pecpmCount, resultCountMap = up.getResultCountList(day, openId, accessToken, tvcCount, motivateCount, pecpmCount,
pecpmModelCount, userId, tokenDy, dyMarketPlatformAppIdList); BehavoirType.PECPMMODELCOUNT.getBehavoirType(appChannel).intValue(), userId, tokenDy, dyMarketPlatformAppIdList,env);
if (resultCountMap != null && resultCountMap.size() != 0) { if (resultCountMap != null && resultCountMap.size() != 0) {
tvcCount = resultCountMap.get("tvc"); tvcCount = resultCountMap.get("tvc");
if (tvcCount != null) { if (tvcCount != null) {
...@@ -158,8 +135,8 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -158,8 +135,8 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
} }
} }
//查询今天的ecpm指标 //查询今天的ecpm指标
resultCountMap = getResultCountList(date, openId, accessToken, tvcCount, motivateCount, pecpmCount, resultCountMap = up.getResultCountList(date, openId, accessToken, tvcCount, motivateCount, pecpmCount,
pecpmModelCount, userId, tokenDy, dyMarketPlatformAppIdList); BehavoirType.PECPMMODELCOUNT.getBehavoirType(appChannel).intValue(), userId, tokenDy, dyMarketPlatformAppIdList,env);
if (resultCountMap != null && resultCountMap.size() != 0) { if (resultCountMap != null && resultCountMap.size() != 0) {
tvcCount = resultCountMap.get("tvc"); tvcCount = resultCountMap.get("tvc");
if (tvcCount != null) { if (tvcCount != null) {
...@@ -169,67 +146,48 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -169,67 +146,48 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
pecpmCount = resultCountMap.get("pecpm"); pecpmCount = resultCountMap.get("pecpm");
} }
if (Objects.nonNull(tvcCount) && Objects.nonNull(motivateCount)) { if ((tvcCount != 0 && motivateCount != 0)) {
if (Objects.nonNull(pecpmCount)) { Double ecpmAvgCountD = (double)tvcCount / motivateCount;
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow pecpmcount not null,tvcCount={},motivateCount={},pecpmCount={},djChanel={},userId={}", tvcCount,
motivateCount, pecpmCount, channelId, userId);
}
Double ecpmAvgCountD = (double) tvcCount / motivateCount;
ecpmAvgCount = ecpmAvgCountD.intValue(); ecpmAvgCount = ecpmAvgCountD.intValue();
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow.ecpm success,tvcCount={},motivateCount={},djChanel={},userId={}", tvcCount, motivateCount, channelId, DYVIDEO_SYS_LOG.info("ecpmAvgCount success,ecpmAvgCount={},tvcCount={},motivateCount={},djChanel={},userId={}",ecpmAvgCount,tvcCount,motivateCount,channelId,userId);
userId);
} else {
if (Objects.nonNull(pecpmCount) && Objects.nonNull(motivateCount)) {
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow pempcount and motivate not null,tvcCount={},motivateCount={},pecpmCount={},djChanel={},userId={}",
tvcCount, motivateCount, pecpmCount, channelId, userId);
} else { } else {
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow tvcandmo not up to the standard,tvcCount={},motivateCount={},djChanel={},userId={}", tvcCount, DYVIDEO_SYS_LOG.info("behavoir not receive data,tvcCount={},motivateCount={},djChanel={},userId={}",tvcCount,motivateCount,channelId,userId);
motivateCount, channelId, userId); action.stop(true);
//action.stop(true);
return; return;
} }
}
if (Objects.nonNull(motivateModelCount) && Objects.nonNull(motivateCount)) { for (BehavoirType type : BehavoirType.values()) {
if (motivateCount < motivateModelCount) { Number behavoirVal = type.getBehavoirType(appChannel);
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow motivate not up to the standard,motivateCount={},motivateModelCount={},djChanel={},userId={}", if (null != behavoirVal && behavoirVal instanceof Integer) {
motivateCount, motivateModelCount, channelId, userId); if (type.getValue().startsWith(BehavoirType.MOTIVATEMODELCOUNT.getValue()) && null != motivateCount) {
//action.stop(true); if (motivateCount < behavoirVal.intValue()) {
return; DYVIDEO_SYS_LOG.info("motivate not up to the standard,motivateCount={},motivateModelCount={},djChanel={},userId={}",motivateCount,behavoirVal,channelId,userId);
action.stop(true);
break;
} }
videoUpload.setMotivateCount(String.valueOf(motivateCount)); deliveryDeviceInfo.setMotivateCount(String.valueOf(motivateCount));
continue;
} }
if (type.getValue().startsWith(BehavoirType.ECPMAVGMODELCOUNT.getValue()) && null != ecpmAvgCount) {
if (Objects.nonNull(ecpmAvgModelCount) && Objects.nonNull(ecpmAvgCount)) { if (ecpmAvgCount < behavoirVal.intValue()) {
if ((ecpmAvgCount < ecpmAvgModelCount)) { DYVIDEO_SYS_LOG.info("ecpm not up to the standard,ecpmAvgCount={},ecpmAvgModelCount={},djChanel={},userId={}",ecpmAvgCount,behavoirVal,channelId,userId);
DYVIDEO_SYS_LOG.info("DyvideoBehaviorFlow ecpm not up to the standard,ecpmAvgCount={},ecpmAvgModelCount={},djChanel={},userId={}", action.stop(true);
ecpmAvgCount, ecpmAvgModelCount, channelId, userId); break;
//action.stop(true); }
return; deliveryDeviceInfo.setEcpmAvgCount(String.valueOf(ecpmAvgCount));
continue;
} }
videoUpload.setEcpmAvgCount(String.valueOf(ecpmAvgCount)); 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;
} }
if (Objects.nonNull(pecpmModelCount) && Objects.nonNull(motivateModelCount) && Objects.nonNull(motivateCount)) { deliveryDeviceInfo.setPecpmCount(String.valueOf(behavoirVal));
if (Objects.nonNull(pecpmCount)) { deliveryDeviceInfo.setPerecpmSize(String.valueOf(pecpmCount));
if (pecpmCount < motivateModelCount) { break;
DYVIDEO_SYS_LOG.info(
"DyvideoBehaviorFlow pecpmCount not up to the standard,pecpmModelCount={},pecpmCount={},motivateModelCount={},motivateCount={},djChanel={},userId={}",
pecpmModelCount, pecpmCount, motivateModelCount, motivateCount, channelId, userId);
//action.stop(true);
return;
} }
videoUpload.setPecpmCount(String.valueOf(pecpmModelCount));
videoUpload.setPerecpmSize(String.valueOf(pecpmCount));
DYVIDEO_SYS_LOG.info(
"DyvideoBehaviorFlow pecpmCount up to the standard,pecpmModelCount={},pecpmCount={},motivateModelCount={},motivateCount={},djChanel={},userId={}",
pecpmModelCount, pecpmCount, motivateModelCount, motivateCount, channelId, userId);
} else {
DYVIDEO_SYS_LOG.info(
"DyvideoBehaviorFlow pecpmCount is null not to the standard,pecpmModelCount={},pecpmCount={},motivateModelCount={},motivateCount={},djChanel={},userId={}",
pecpmModelCount, pecpmCount, motivateModelCount, motivateCount, channelId, userId);
//action.stop(true);
return;
} }
} }
...@@ -271,94 +229,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> { ...@@ -271,94 +229,11 @@ public class DyvideoBehaviorFlow extends NodeSwitchFlow<StoryNovelAction> {
"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);
} }
//action.stop(true);
} else {
//action.stop(true);
} }
} else {
//action.stop(true);
}
}
public Map<String,Integer> getResultCountList(Date day,String openid,String accessToken,Integer tvcCount,Integer motivateCount,Integer pecpmCount,Integer pecpmModelCount,Long userId,String tokenDy,List<String> dyMarketPlatformAppIdList) {
int pageNumer = 1;
Map<String,Integer> resultCountMap = new HashMap<>();
String upcBehaviorKey = CacheKeyUtils.getVideoBehavoirKey(userId);
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) {
if (Objects.isNull(tvcCount)) {
tvcCount = 0;
}
if (Objects.isNull(motivateCount)) {
motivateCount = 0;
} }
if (Objects.isNull(pecpmCount)) {
pecpmCount = 0;
} }
motivateCount += records.size();
for(JSONObject jsonObject : records) {
String cost = jsonObject.getString("cost");
Integer costI = Integer.parseInt(cost);
Double c = (double)(costI / 100);
int ct = c.intValue();
if (pecpmModelCount != null) {
if (ct>=pecpmModelCount) {
pecpmCount ++;
}
}
tvcCount += costI;
}
up.hsetNew(upcBehaviorKey,"tvc",60 * 60 * 24 * 3,JSON.toJSONString(tvcCount));
up.hsetNew(upcBehaviorKey,"mvc",60 * 60 * 24 * 3,JSON.toJSONString(motivateCount));
up.hsetNew(upcBehaviorKey,"vec",60 * 60 * 24 * 3,JSON.toJSONString(pecpmCount));
}
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("DouyinBehaviorKafkaConsumer.douyin code error,userId={},result={}",userId,JSON.toJSONString(result));
if (resultCode == 28001008) {
//删除授权过期token
up.delToken(tokenDy);
up.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));
}
return null;
}
resultCountMap.put("tvc",tvcCount);
resultCountMap.put("motivate",motivateCount);
resultCountMap.put("pecpm",pecpmCount);
} catch (Throwable e) {
e.printStackTrace();
}
}
return resultCountMap;
}
private boolean isCallback(long channelTotalCount, long channelCallbackCount, Integer sprDedu) { private boolean isCallback(long channelTotalCount, long channelCallbackCount, Integer sprDedu) {
if (channelTotalCount == 0) { if (channelTotalCount == 0) {
......
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