|
|
@@ -1,6 +1,7 @@
|
|
|
package com.tzld.piaoquan.api.job.contentplatform;
|
|
|
|
|
|
import com.aliyun.odps.data.Record;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.tzld.piaoquan.api.common.enums.contentplatform.UploadVideoAuditStatusEnum;
|
|
|
import com.tzld.piaoquan.api.dao.mapper.contentplatform.*;
|
|
|
@@ -31,28 +32,29 @@ public class ContentPlatformVideoJob {
|
|
|
|
|
|
@Autowired
|
|
|
private ContentPlatformPlanMapperExt planMapperExt;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ContentPlatformVideoMapper videoMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ContentPlatformVideoAggMapper videoAggMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ContentPlatformVideoDataStatMapper videoDataStatMapper;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformVideoDataStatAggMapper videoDataStatAggMapper;
|
|
|
@Autowired
|
|
|
private ContentPlatformIllegalVideoMapper illegalVideoMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private MessageAttachmentService messageAttachmentService;
|
|
|
-
|
|
|
@Autowired
|
|
|
- ContentPlatformUploadVideoMapper uploadVideoMapper;
|
|
|
+ private ContentPlatformUploadVideoMapper uploadVideoMapper;
|
|
|
+ @Autowired
|
|
|
+ private ContentPlatformAccountMapper accountMapper;
|
|
|
|
|
|
@Value("${video.agg.days:3}")
|
|
|
private Integer videoAggDays;
|
|
|
|
|
|
+ @ApolloJsonValue("${video.recommend.score.config:{}}")
|
|
|
+ private Map<String, Double> recommendScoreConfig;
|
|
|
+
|
|
|
@XxlJob("syncContentPlatformVideoJob")
|
|
|
public ReturnT<String> syncContentPlatformVideoJob(String param) {
|
|
|
String aggDt = DateUtil.getBeforeDayDateString("yyyyMMdd");
|
|
|
@@ -233,6 +235,12 @@ public class ContentPlatformVideoJob {
|
|
|
return videoAggMapper.selectByExample(example);
|
|
|
}
|
|
|
|
|
|
+ private List<ContentPlatformVideoDataStatAgg> getVideoDatastatAggList(String dt, String strategy) {
|
|
|
+ ContentPlatformVideoDataStatAggExample example = new ContentPlatformVideoDataStatAggExample();
|
|
|
+ example.createCriteria().andDtEqualTo(dt).andStrategyEqualTo(strategy);
|
|
|
+ return videoDataStatAggMapper.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
@XxlJob("syncContentPlatformVideoDatastatJob")
|
|
|
public ReturnT<String> syncContentPlatformVideoDatastatJob(String param) {
|
|
|
String aggDt = DateUtil.getBeforeDayDateString("yyyyMMdd");
|
|
|
@@ -276,9 +284,10 @@ public class ContentPlatformVideoJob {
|
|
|
// 聚合最近14天视频
|
|
|
List<ContentPlatformVideoDataStatAgg> saveAggList = buildVideoDataStatAggList(aggDt, dtList);
|
|
|
if (CollectionUtils.isNotEmpty(saveAggList)) {
|
|
|
- planMapperExt.deleteContentPlatformVideoDatastatAgg(aggDt);
|
|
|
+ planMapperExt.deleteContentPlatformVideoDatastatAgg(aggDt, null);
|
|
|
planMapperExt.batchInsertContentPlatformVideoDatastatAgg(saveAggList);
|
|
|
}
|
|
|
+ calContentPlatformVideoDatastatAggRecommendRateJob(param);
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
|
@@ -314,6 +323,7 @@ public class ContentPlatformVideoJob {
|
|
|
item.setVideoId(videoId);
|
|
|
item.setType(type);
|
|
|
item.setChannel(channel);
|
|
|
+ item.setStrategy("normal");
|
|
|
item.setFirstLevel(sumFirstLevel);
|
|
|
item.setFission0(sumFission0);
|
|
|
if (sumFirstLevel > 0) {
|
|
|
@@ -334,6 +344,98 @@ public class ContentPlatformVideoJob {
|
|
|
return videoDataStatMapper.selectByExample(example);
|
|
|
}
|
|
|
|
|
|
+ @XxlJob("calContentPlatformVideoDatastatAggRecommendRateJob")
|
|
|
+ public ReturnT<String> calContentPlatformVideoDatastatAggRecommendRateJob(String param) {
|
|
|
+ String dt = planMapperExt.getVideoMaxDt();
|
|
|
+ String datastatDt = planMapperExt.getVideoDatastatMaxDt();
|
|
|
+ if (StringUtils.hasText(param)) {
|
|
|
+ dt = param;
|
|
|
+ datastatDt = param;
|
|
|
+ }
|
|
|
+ List<ContentPlatformVideoAgg> videoList = getVideoListByDt(dt);
|
|
|
+ List<ContentPlatformVideoDataStatAgg> aggList = getVideoDatastatAggList(datastatDt, "normal");
|
|
|
+ Map<String, Map<String, Map<Long, Double>>> videoIdTypeChannelScoreMap = aggList.stream()
|
|
|
+ .filter(o -> "normal".equals(o.getStrategy()))
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ ContentPlatformVideoDataStatAgg::getType,
|
|
|
+ Collectors.groupingBy(ContentPlatformVideoDataStatAgg::getChannel,
|
|
|
+ Collectors.toMap(ContentPlatformVideoDataStatAgg::getVideoId, ContentPlatformVideoDataStatAgg::getFissionRate))));
|
|
|
+ List<String> typeList = Arrays.asList("自动回复", "服务号推送", "公众号推送", "企微-社群", "企微-自动回复");
|
|
|
+ List<ContentPlatformAccount> accountList = getAllContentPlatformAccount();
|
|
|
+ List<String> channelList = accountList.stream().map(ContentPlatformAccount::getChannel).collect(Collectors.toList());
|
|
|
+ channelList.add("sum");
|
|
|
+ List<ContentPlatformVideoDataStatAgg> saveList = new ArrayList<>();
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ String strategy = "recommend";
|
|
|
+ for (String type : typeList) {
|
|
|
+ for (String channel : channelList) {
|
|
|
+ for (ContentPlatformVideoAgg video : videoList) {
|
|
|
+ if (!videoIdTypeChannelScoreMap.containsKey(type)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<Long, Double> typeVideoScoreMap = videoIdTypeChannelScoreMap.getOrDefault(type, new HashMap<>())
|
|
|
+ .getOrDefault("sum", new HashMap<>());
|
|
|
+ Map<Long, Double> channelVideoScoreMap = videoIdTypeChannelScoreMap.getOrDefault(type, new HashMap<>())
|
|
|
+ .getOrDefault(channel, new HashMap<>());
|
|
|
+ Double platformScore = video.getScore();
|
|
|
+ Double channelRate = channel.equals("sum") ? 0.0 : channelVideoScoreMap.get(video.getVideoId());
|
|
|
+ Double typeRate = typeVideoScoreMap.get(video.getVideoId());
|
|
|
+ Double recommendScore = calRecommendScore(platformScore, channelRate, typeRate);
|
|
|
+ ContentPlatformVideoDataStatAgg agg = new ContentPlatformVideoDataStatAgg();
|
|
|
+ agg.setDt(datastatDt);
|
|
|
+ agg.setVideoId(video.getVideoId());
|
|
|
+ agg.setType(type);
|
|
|
+ agg.setChannel(channel);
|
|
|
+ agg.setStrategy(strategy);
|
|
|
+ agg.setFissionRate(recommendScore);
|
|
|
+ agg.setCreateTimestamp(now);
|
|
|
+ saveList.add(agg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(saveList)) {
|
|
|
+ planMapperExt.deleteContentPlatformVideoDatastatAgg(datastatDt, strategy);
|
|
|
+ for (List<ContentPlatformVideoDataStatAgg> partition : Lists.partition(saveList, 1000)) {
|
|
|
+ planMapperExt.batchInsertContentPlatformVideoDatastatAgg(partition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double calRecommendScore(Double platformScore, Double channelRate, Double typeRate) {
|
|
|
+ // channelRate 本渠道传播率,不存在的为0
|
|
|
+ if (Objects.isNull(channelRate)) {
|
|
|
+ channelRate = 0.0;
|
|
|
+ }
|
|
|
+ // typeRate 行业裂变率, 不存在的为0
|
|
|
+ if (Objects.isNull(typeRate)) {
|
|
|
+ typeRate = 0.0;
|
|
|
+ }
|
|
|
+ Double platformWeight = recommendScoreConfig.getOrDefault("platformWeight", 0.5);
|
|
|
+ Double channelWeight = recommendScoreConfig.getOrDefault("channelWeight", 0.5);
|
|
|
+ Double typeWeight = recommendScoreConfig.getOrDefault("typeWeight", 0.1);
|
|
|
+ Double scalingWeight = recommendScoreConfig.getOrDefault("scalingWeight", 1.5);
|
|
|
+ Double maxScore = recommendScoreConfig.getOrDefault("maxScore", 10.0);
|
|
|
+
|
|
|
+ Double score = platformWeight * platformScore + channelWeight * channelRate;
|
|
|
+ score += typeWeight * (10 - Math.min(10, typeRate));
|
|
|
+ score *= scalingWeight;
|
|
|
+
|
|
|
+ if (score > maxScore) {
|
|
|
+ score = maxScore + (score - maxScore) / 10;
|
|
|
+ }
|
|
|
+ BigDecimal bdScore = new BigDecimal(score);
|
|
|
+ return bdScore.setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<ContentPlatformAccount> getAllContentPlatformAccount() {
|
|
|
+ ContentPlatformAccountExample example = new ContentPlatformAccountExample();
|
|
|
+ example.createCriteria().andStatusEqualTo(1);
|
|
|
+ return accountMapper.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
@XxlJob("syncContentPlatformUploadVideoScoreJob")
|
|
|
public ReturnT<String> syncContentPlatformUploadVideoScoreJob(String param) {
|
|
|
String aggDt = DateUtil.getBeforeDayDateString("yyyyMMdd");
|