Bladeren bron

内容池交互 calRecommendScore

wangyunpeng 1 week geleden
bovenliggende
commit
ae2551b06a

+ 35 - 5
api-module/src/main/java/com/tzld/piaoquan/api/job/contentplatform/ContentPlatformVideoJob.java

@@ -48,6 +48,8 @@ public class ContentPlatformVideoJob {
     private ContentPlatformUploadVideoMapper uploadVideoMapper;
     @Autowired
     private ContentPlatformAccountMapper accountMapper;
+    @Autowired
+    private ContentPlatformVideoAccountRelMapper videoAccountRelMapper;
 
     @Value("${video.agg.days:3}")
     private Integer videoAggDays;
@@ -527,12 +529,21 @@ public class ContentPlatformVideoJob {
         List<String> typeList = Arrays.asList("自动回复", "服务号推送", "公众号推送", "企微-社群", "企微-自动回复");
         List<ContentPlatformAccount> accountList = getAllContentPlatformAccount();
         List<String> channelList = accountList.stream().map(ContentPlatformAccount::getChannel).collect(Collectors.toList());
+        List<Long> accountIds = accountList.stream().map(ContentPlatformAccount::getId).collect(Collectors.toList());
+        List<ContentPlatformVideoAccountRel> videoAccountRelList = getContentPlatformVideoAccountRelList(accountIds);
+        Map<Long, List<ContentPlatformVideoAccountRel>> videoAccountRelMap = videoAccountRelList.stream()
+                .collect(Collectors.groupingBy(ContentPlatformVideoAccountRel::getVideoId));
+        Map<String, ContentPlatformAccount> accountMap = accountList.stream().collect(Collectors.toMap(ContentPlatformAccount::getChannel, o -> o));
         channelList.add("sum");
         List<ContentPlatformVideoDataStatAgg> saveList = new ArrayList<>();
         Long now = System.currentTimeMillis();
         String strategy = "recommend";
-        for (String type : typeList) {
-            for (String channel : channelList) {
+        for (String channel : channelList) {
+            ContentPlatformAccount account = accountMap.get(channel);
+            List<ContentPlatformVideoAccountRel> accoutnVideoAccountRelList = videoAccountRelMap.getOrDefault(account.getId(), new ArrayList<>());
+            Map<Long, Double> videoSimScoreMap = accoutnVideoAccountRelList.stream().collect(
+                    Collectors.toMap(ContentPlatformVideoAccountRel::getVideoId, ContentPlatformVideoAccountRel::getSimScore));
+            for (String type : typeList) {
                 for (ContentPlatformVideoAgg video : videoList) {
                     if (!videoIdTypeChannelScoreMap.containsKey(type)) {
                         continue;
@@ -551,7 +562,8 @@ public class ContentPlatformVideoJob {
                     if (Objects.nonNull(typeVideoScoreMap) && typeVideoScoreMap.containsKey(video.getVideoId())) {
                         typeRate = typeVideoScoreMap.get(video.getVideoId());
                     }
-                    Double recommendScore = calRecommendScore(platformScore, channelRate, typeRate);
+                    Double simScore = videoSimScoreMap.getOrDefault(video.getVideoId(), 0.0);
+                    Double recommendScore = calRecommendScore(platformScore, channelRate, typeRate, simScore);
                     ContentPlatformVideoDataStatAgg agg = new ContentPlatformVideoDataStatAgg();
                     agg.setDt(datastatDt);
                     agg.setVideoId(video.getVideoId());
@@ -574,7 +586,13 @@ public class ContentPlatformVideoJob {
         return ReturnT.SUCCESS;
     }
 
-    private Double calRecommendScore(Double platformScore, Double channelRate, Double typeRate) {
+    private List<ContentPlatformVideoAccountRel> getContentPlatformVideoAccountRelList(List<Long> accountIds) {
+        ContentPlatformVideoAccountRelExample example = new ContentPlatformVideoAccountRelExample();
+        example.createCriteria().andAccountIdIn(accountIds);
+        return videoAccountRelMapper.selectByExample(example);
+    }
+
+    private Double calRecommendScore(Double platformScore, Double channelRate, Double typeRate, Double simScore) {
         // channelRate 本渠道传播率,不存在的为0
         if (Objects.isNull(channelRate)) {
             channelRate = 0.0;
@@ -583,13 +601,18 @@ public class ContentPlatformVideoJob {
         if (Objects.isNull(typeRate)) {
             typeRate = 0.0;
         }
+        // simScore 不存在的为0
+        if (Objects.isNull(simScore)) {
+            simScore = 0.0;
+        }
         Double platformWeight = recommendScoreConfig.getOrDefault("platformWeight", 0.5);
         Double channelWeight = recommendScoreConfig.getOrDefault("channelWeight", 0.5);
+        Double simWeight = recommendScoreConfig.getOrDefault("simWeight", 30.0);
         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;
+        Double score = platformWeight * platformScore + channelWeight * channelRate + scaleScore(simWeight * simScore, 3.0);
         score += typeWeight * (10 - Math.min(10, typeRate));
         score *= scalingWeight;
 
@@ -600,6 +623,13 @@ public class ContentPlatformVideoJob {
         return bdScore.setScale(2, RoundingMode.HALF_UP).doubleValue();
     }
 
+    public static double scaleScore(Double score, Double maxScore) {
+        if (score > maxScore) {
+            return maxScore + (score - maxScore) / 10;
+        }
+        return score;
+    }
+
 
     private List<ContentPlatformAccount> getAllContentPlatformAccount() {
         ContentPlatformAccountExample example = new ContentPlatformAccountExample();