소스 검색

Merge branch 'wyp/0921-rankV12' of Server/long-article-recommend into master

TODO: 减少冗余代码,减少冗余的日志
fengzhoutian 9 달 전
부모
커밋
e6613347eb

+ 2 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/RankStrategyEnum.java

@@ -15,7 +15,8 @@ public enum RankStrategyEnum {
     ArticleRankV8("ArticleRankV8", "ArticleRankV8", "rankV8Strategy"),
     ArticleRankV9("ArticleRankV9", "ArticleRankV9", "rankV9Strategy"),
     ArticleRankV10("ArticleRankV10", "ArticleRankV10", "rankV10Strategy"),
-    ArticleRankV11("ArticleRankV11", "ArticleRankV11", "rankV9Strategy"),
+    ArticleRankV11("ArticleRankV11", "ArticleRankV11", "rankV11Strategy"),
+    ArticleRankV12("ArticleRankV12", "ArticleRankV12", "rankV12Strategy"),
 
     default_strategy("ArticleRankV1", "默认策略", "defaultRankStrategy"),
     ;

+ 1 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/dto/Content.java

@@ -39,6 +39,7 @@ public class Content {
     private Double t0FissionByReadAvgCorrelationMean;
     private Double t0FissionByFansSumAvg;
     private Double t0FissionByReadAvgSumAvg;
+    private Double t0FissionDeWeightByReadAvgSumAvg;
 
     private Map<String, Double> scoreMap;
     private double score;

+ 31 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/StrategyIndexScoreWeightService.java

@@ -0,0 +1,31 @@
+package com.tzld.longarticle.recommend.server.service;
+
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+@Slf4j
+public class StrategyIndexScoreWeightService {
+
+    @ApolloJsonValue("${strategyIndexScoreWeightConfig:{}}")
+    private Map<String, Map<String, Map<String, Double>>> strategyIndexScoreWeightMap;
+
+    public double getWeight(String strategy, Integer index, String score) {
+        Map<String, Map<String, Double>> indexMap = strategyIndexScoreWeightMap.get(strategy);
+        if (indexMap == null) {
+            return 1.0;
+        }
+        Map<String, Double> scoreMap = indexMap.get(String.valueOf(index));
+        if (scoreMap == null) {
+            return 1.0;
+        }
+        Double weight = scoreMap.get(score);
+        if (weight == null) {
+            return 1.0;
+        }
+        return weight;
+    }
+}

+ 165 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV11Strategy.java

@@ -0,0 +1,165 @@
+package com.tzld.longarticle.recommend.server.service.rank.strategy;
+
+
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.StrategyIndexScoreWeightService;
+import com.tzld.longarticle.recommend.server.service.rank.RankItem;
+import com.tzld.longarticle.recommend.server.service.rank.RankParam;
+import com.tzld.longarticle.recommend.server.service.rank.RankResult;
+import com.tzld.longarticle.recommend.server.service.rank.RankStrategy;
+import com.tzld.longarticle.recommend.server.service.score.AccountIndexReplacePoolConfig;
+import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
+import com.tzld.longarticle.recommend.server.service.score.ScoreService;
+import com.tzld.longarticle.recommend.server.service.score.strategy.*;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class RankV11Strategy implements RankStrategy {
+
+    @Autowired
+    private ScoreService scoreService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
+
+    public RankResult rank(RankParam param) {
+        List<Content> result = new ArrayList<>();
+        //log.info("RankParam {}", JSONUtils.toJson(param));
+        ScoreResult scoreResult = scoreService.score(RankStrategy.convertToScoreParam(param));
+
+        Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
+        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
+        Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap = accountContentPoolConfigService.getContentReplacePools(param.getAccountName());
+
+        List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
+            RankItem item = new RankItem();
+            item.setContent(c);
+            c.setScoreMap(scoreMap.get(c.getId()));
+            item.setScoreMap(scoreMap.get(c.getId()));
+            double score;
+            if (contentPools[0].equals(item.getContent().getContentPoolType())) {
+                score = item.getScore(HisFissionAvgReadRateRateStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        HisFissionAvgReadRateRateStrategy.class.getSimpleName());
+                score += item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        SimilarityStrategy.class.getSimpleName());
+            } else if (contentPools[1].equals(item.getContent().getContentPoolType())) {
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 2,
+                        SimilarityStrategy.class.getSimpleName()))
+                        + item.getScore(CategoryStrategy.class.getSimpleName())
+                        + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
+                if (item.getScore(PublishTimesStrategy.class.getSimpleName()) >= 0) {
+                    score += item.getScore(ViewCountRateStrategy.class.getSimpleName())
+                            * weightService.getWeight(param.getStrategy(), 2,
+                            ViewCountRateStrategy.class.getSimpleName());
+                }
+            } else {
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        SimilarityStrategy.class.getSimpleName()))
+                        + item.getScore(CategoryStrategy.class.getSimpleName())
+                        + (item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        AccountPreDistributeStrategy.class.getSimpleName()))
+                        + item.getScore(PublishTimesStrategy.class.getSimpleName())
+                        + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
+            }
+            c.setScore(score);
+            item.setScore(score);
+            return item;
+        });
+        // 相似度评分为0 报警返回
+        if (CollectionUtils.isNotEmpty(items) && items.get(0).getScoreMap().get(SimilarityStrategy.class.getSimpleName()) == 0) {
+            FeishuMessageSender.sendWebHookMessage("07026a9f-43f5-448b-ba40-a8d71bd6e634",
+                    "内容评分为0\n"
+                            + "ghId: " + param.getGhId() + "\n"
+                            + "账号名称: " + param.getAccountName() + "\n"
+                            + "策略: " + this.getClass().getSimpleName());
+            return new RankResult(result);
+        }
+
+        // 1 排序
+        Collections.sort(items, (o1, o2) -> -Double.compare(o1.getScore(), o2.getScore()));
+        // 2 相似去重
+        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
+//        contents = deduplication(contents);
+
+        // 3 文章按照内容池分组
+        Map<String, List<Content>> contentMap = new HashMap<>();
+        for (Content c : contents) {
+            List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
+            data.add(c);
+        }
+        // 4 选文章
+        String[] publishPool = Arrays.copyOf(contentPools, contentPools.length);
+
+        // 头
+        List<Content> pool1 = contentMap.get(contentPools[0]);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            result.add(pool1.get(0));
+        } else {
+            FeishuMessageSender.sendWebHookMessage("07026a9f-43f5-448b-ba40-a8d71bd6e634",
+                    "内容池1为空\n"
+                            + "ghId: " + param.getGhId() + "\n"
+                            + "账号名称: " + param.getAccountName() + "\n"
+                            + "内容池: " + contentPools[0] + "\n"
+                            + "策略: " + this.getClass().getSimpleName());
+            return new RankResult(result);
+        }
+        // 次
+        List<Content> pool2 = contentMap.get(contentPools[1]);
+        if (CollectionUtils.isNotEmpty(pool2)) {
+            int i = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
+            int j = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
+            result.add(pool2.get(i));
+            // 替补 头条内容不足使用次条内容
+            if (result.size() == 1 && pool2.size() > 1) {
+                while (i == j && pool2.size() > 1) {
+                    j = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
+                    if (i != j) {
+                        publishPool[0] = contentPools[1];
+                        result.add(pool2.get(1));
+                        break;
+                    }
+                }
+            }
+        } else {
+            // 替补 根据设置替补内容池查找内容尽心替补
+            AccountIndexReplacePoolConfig replacePoolConfig = indexReplacePoolConfigMap.get(2);
+            if (Objects.nonNull(replacePoolConfig)) {
+                List<Content> pool2Replace = contentMap.get(replacePoolConfig.getContentPool());
+                if (CollectionUtils.isNotEmpty(pool2Replace)) {
+                    publishPool[1] = replacePoolConfig.getContentPool();
+                    result.add(pool2Replace.get(0));
+                }
+            }
+        }
+
+        // 3-8
+        List<Content> pool = contentMap.get(contentPools[2]);
+        if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
+            result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize() - result.size())));
+        }
+
+        RankStrategy.deduplication(result, contentMap, publishPool);
+
+        return new RankResult(result);
+    }
+
+}

+ 165 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/rank/strategy/RankV12Strategy.java

@@ -0,0 +1,165 @@
+package com.tzld.longarticle.recommend.server.service.rank.strategy;
+
+
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.StrategyIndexScoreWeightService;
+import com.tzld.longarticle.recommend.server.service.rank.RankItem;
+import com.tzld.longarticle.recommend.server.service.rank.RankParam;
+import com.tzld.longarticle.recommend.server.service.rank.RankResult;
+import com.tzld.longarticle.recommend.server.service.rank.RankStrategy;
+import com.tzld.longarticle.recommend.server.service.score.AccountIndexReplacePoolConfig;
+import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
+import com.tzld.longarticle.recommend.server.service.score.ScoreService;
+import com.tzld.longarticle.recommend.server.service.score.strategy.*;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class RankV12Strategy implements RankStrategy {
+
+    @Autowired
+    private ScoreService scoreService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
+
+    public RankResult rank(RankParam param) {
+        List<Content> result = new ArrayList<>();
+        //log.info("RankParam {}", JSONUtils.toJson(param));
+        ScoreResult scoreResult = scoreService.score(RankStrategy.convertToScoreParam(param));
+
+        Map<String, Map<String, Double>> scoreMap = scoreResult.getScoreMap();
+        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
+        Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap = accountContentPoolConfigService.getContentReplacePools(param.getAccountName());
+
+        List<RankItem> items = CommonCollectionUtils.toList(param.getContents(), c -> {
+            RankItem item = new RankItem();
+            item.setContent(c);
+            c.setScoreMap(scoreMap.get(c.getId()));
+            item.setScoreMap(scoreMap.get(c.getId()));
+            double score;
+            if (contentPools[0].equals(item.getContent().getContentPoolType())) {
+                score = item.getScore(HisFissionDeWeightAvgReadSumRateStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        HisFissionDeWeightAvgReadSumRateStrategy.class.getSimpleName());
+                score += item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 1,
+                        SimilarityStrategy.class.getSimpleName());
+            } else if (contentPools[1].equals(item.getContent().getContentPoolType())) {
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 2,
+                        SimilarityStrategy.class.getSimpleName()))
+                        + item.getScore(CategoryStrategy.class.getSimpleName())
+                        + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
+                if (item.getScore(PublishTimesStrategy.class.getSimpleName()) >= 0) {
+                    score += item.getScore(ViewCountRateStrategy.class.getSimpleName())
+                            * weightService.getWeight(param.getStrategy(), 2,
+                            ViewCountRateStrategy.class.getSimpleName());
+                }
+            } else {
+                score = (item.getScore(SimilarityStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        SimilarityStrategy.class.getSimpleName()))
+                        + item.getScore(CategoryStrategy.class.getSimpleName())
+                        + (item.getScore(AccountPreDistributeStrategy.class.getSimpleName())
+                        * weightService.getWeight(param.getStrategy(), 3,
+                        AccountPreDistributeStrategy.class.getSimpleName()))
+                        + item.getScore(PublishTimesStrategy.class.getSimpleName())
+                        + item.getScore(FlowCtlDecreaseStrategy.class.getSimpleName());
+            }
+            c.setScore(score);
+            item.setScore(score);
+            return item;
+        });
+        // 相似度评分为0 报警返回
+        if (CollectionUtils.isNotEmpty(items) && items.get(0).getScoreMap().get(SimilarityStrategy.class.getSimpleName()) == 0) {
+            FeishuMessageSender.sendWebHookMessage("07026a9f-43f5-448b-ba40-a8d71bd6e634",
+                    "内容评分为0\n"
+                            + "ghId: " + param.getGhId() + "\n"
+                            + "账号名称: " + param.getAccountName() + "\n"
+                            + "策略: " + this.getClass().getSimpleName());
+            return new RankResult(result);
+        }
+
+        // 1 排序
+        Collections.sort(items, (o1, o2) -> -Double.compare(o1.getScore(), o2.getScore()));
+        // 2 相似去重
+        List<Content> contents = CommonCollectionUtils.toList(items, RankItem::getContent);
+//        contents = deduplication(contents);
+
+        // 3 文章按照内容池分组
+        Map<String, List<Content>> contentMap = new HashMap<>();
+        for (Content c : contents) {
+            List<Content> data = contentMap.computeIfAbsent(c.getContentPoolType(), k -> new ArrayList<>());
+            data.add(c);
+        }
+        // 4 选文章
+        String[] publishPool = Arrays.copyOf(contentPools, contentPools.length);
+
+        // 头
+        List<Content> pool1 = contentMap.get(contentPools[0]);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            result.add(pool1.get(0));
+        } else {
+            FeishuMessageSender.sendWebHookMessage("07026a9f-43f5-448b-ba40-a8d71bd6e634",
+                    "内容池1为空\n"
+                            + "ghId: " + param.getGhId() + "\n"
+                            + "账号名称: " + param.getAccountName() + "\n"
+                            + "内容池: " + contentPools[0] + "\n"
+                            + "策略: " + this.getClass().getSimpleName());
+            return new RankResult(result);
+        }
+        // 次
+        List<Content> pool2 = contentMap.get(contentPools[1]);
+        if (CollectionUtils.isNotEmpty(pool2)) {
+            int i = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
+            int j = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
+            result.add(pool2.get(i));
+            // 替补 头条内容不足使用次条内容
+            if (result.size() == 1 && pool2.size() > 1) {
+                while (i == j && pool2.size() > 1) {
+                    j = RandomUtils.nextInt(0, Math.min(pool2.size(), 5));
+                    if (i != j) {
+                        publishPool[0] = contentPools[1];
+                        result.add(pool2.get(1));
+                        break;
+                    }
+                }
+            }
+        } else {
+            // 替补 根据设置替补内容池查找内容尽心替补
+            AccountIndexReplacePoolConfig replacePoolConfig = indexReplacePoolConfigMap.get(2);
+            if (Objects.nonNull(replacePoolConfig)) {
+                List<Content> pool2Replace = contentMap.get(replacePoolConfig.getContentPool());
+                if (CollectionUtils.isNotEmpty(pool2Replace)) {
+                    publishPool[1] = replacePoolConfig.getContentPool();
+                    result.add(pool2Replace.get(0));
+                }
+            }
+        }
+
+        // 3-8
+        List<Content> pool = contentMap.get(contentPools[2]);
+        if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
+            result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize() - result.size())));
+        }
+
+        RankStrategy.deduplication(result, contentMap, publishPool);
+
+        return new RankResult(result);
+    }
+
+}

+ 19 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recall/RecallService.java

@@ -1,5 +1,6 @@
 package com.tzld.longarticle.recommend.server.service.recall;
 
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.collect.Lists;
 import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
@@ -69,8 +70,14 @@ public class RecallService implements ApplicationContextAware {
     private ApplicationContext applicationContext;
     private final ExecutorService pool = ThreadPoolFactory.recallPool();
 
-    @Value("${recall.content.his.fieshu.enable:false}")
-    private Boolean contentHisFieshuEnable;
+    @Value("${recall.content.his.feishu.enable:false}")
+    private Boolean contentHisFeishuEnable;
+    @Value("${morning.noon.fission.rate:0.64}")
+    private double morningNoonFissionRate;
+    @ApolloJsonValue("${morning.publish.account.ghId:[]}")
+    private List<String> morningPublishAccountGhIds;
+    @ApolloJsonValue("${noon.publish.account.ghId:[]}")
+    private List<String> noonPublishAccountGhIds;
 
 
     @PostConstruct
@@ -337,6 +344,7 @@ public class RecallService implements ApplicationContextAware {
         }
         int firstLevelSize = 0;
         int fissionSum = 0;
+        double fissionWeightSum = 0;
         int fansSum = 0;
         int avgReadCountSum = 0;
         Double t0FissionByFansSum = 0.0;
@@ -348,7 +356,7 @@ public class RecallService implements ApplicationContextAware {
             }
             if (CollectionUtils.isEmpty(article.getArticleDetailInfoList())) {
                 // 仅判断7.12以后发布文章
-                if (article.getUpdateTime() > 1720713600 && contentHisFieshuEnable) {
+                if (article.getUpdateTime() > 1720713600 && contentHisFeishuEnable) {
                     FeishuMessageSender.sendWebHookMessage("07026a9f-43f5-448b-ba40-a8d71bd6e634", "历史表现裂变特征获取失败\n"
                             + "ghId: " + article.getGhId() + "\n"
                             + "账号名称: " + article.getAccountName() + "\n"
@@ -383,6 +391,11 @@ public class RecallService implements ApplicationContextAware {
                 t0FissionByReadAvgCorrelationSum += article.getT0FissionByReadAvg() * correlation;
             }
             fissionSum += sumFission0;
+            if (noonPublishAccountGhIds.contains(article.getGhId())) {
+                fissionWeightSum += sumFission0 / morningNoonFissionRate;
+            } else {
+                fissionWeightSum += sumFission0;
+            }
             firstLevelSize++;
         }
         if (firstLevelSize > 0) {
@@ -395,6 +408,9 @@ public class RecallService implements ApplicationContextAware {
             if (avgReadCountSum > 0) {
                 content.setT0FissionByReadAvgSumAvg(fissionSum * 1.0 / avgReadCountSum);
             }
+            if (avgReadCountSum > 0) {
+                content.setT0FissionDeWeightByReadAvgSumAvg(fissionWeightSum / avgReadCountSum);
+            }
         }
     }
 

+ 3 - 1
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/ScoreService.java

@@ -96,7 +96,8 @@ public class ScoreService implements ApplicationContextAware {
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV8.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV9.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV10.getStrategy())
-                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV11.getStrategy())) {
+                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV11.getStrategy())
+                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV12.getStrategy())) {
             strategies.add(strategyMap.get(CategoryStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(AccountPreDistributeStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(FlowCtlDecreaseStrategy.class.getSimpleName()));
@@ -108,6 +109,7 @@ public class ScoreService implements ApplicationContextAware {
             strategies.add(strategyMap.get(HisFissionAvgReadRateRateStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(HisFissionAvgReadRateCorrelationRateStrategy.class.getSimpleName()));
             strategies.add(strategyMap.get(HisFissionAvgReadSumRateStrategy.class.getSimpleName()));
+            strategies.add(strategyMap.get(HisFissionDeWeightAvgReadSumRateStrategy.class.getSimpleName()));
         }
 
         return strategies;

+ 40 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/score/strategy/HisFissionDeWeightAvgReadSumRateStrategy.java

@@ -0,0 +1,40 @@
+package com.tzld.longarticle.recommend.server.service.score.strategy;
+
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.service.AccountIndexAvgViewCountService;
+import com.tzld.longarticle.recommend.server.service.score.Score;
+import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
+import com.tzld.longarticle.recommend.server.service.score.ScoreStrategy;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+@Slf4j
+public class HisFissionDeWeightAvgReadSumRateStrategy implements ScoreStrategy {
+
+    @Autowired
+    AccountIndexAvgViewCountService accountIndexAvgViewCountService;
+
+    @Override
+    public List<Score> score(ScoreParam param) {
+        long start = System.currentTimeMillis();
+        List<Score> scores = new ArrayList<>();
+        for (Content content : param.getContents()) {
+            if (CollectionUtils.isEmpty(content.getHisPublishArticleList())) {
+                continue;
+            }
+            Score score = new Score();
+            score.setStrategy(this);
+            score.setContentId(content.getId());
+            score.setScore(content.getT0FissionDeWeightByReadAvgSumAvg());
+            scores.add(score);
+        }
+        log.info("HisFissionAvgReadSumRateStrategy cost:{}", System.currentTimeMillis() - start);
+        return scores;
+    }
+}