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

dy短剧关键行为优化

parent 9ae599ed
......@@ -66,6 +66,7 @@ public class DyVideoBehavoirConsumer {
event.getUserUploadEvent());
executorByDyVideoBehavoir.execute(action);
DYVIDEO_SYS_LOG.info("media.behavoir.dyVideo.end,topic={}, bookStoreEvent={}", data.topic(), JSON.toJSONString(event));
} catch (Throwable e) {
DYVIDEO_ERROR_LOG.error("dy.video.behavoir.onMessage failed, data={}, costTime={} ms", data.value(),
System.currentTimeMillis() - begin, e);
......
......@@ -10,6 +10,7 @@ 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.util.CacheKeyUtils;
import com.lwby.marketing.util.HttpUtil;
import com.lwby.marketing.vo.AppChannelVO;
import com.lwby.marketing.vo.DeliveryDeviceInfo;
......@@ -17,6 +18,7 @@ import com.lwby.marketing.vo.StoryNovelAction;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
......@@ -26,9 +28,8 @@ import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Slf4j
......@@ -42,6 +43,14 @@ public class DyVideoUniversalProcess extends UniversalProcess {
@Resource
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 {
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;
}
}
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