Jelajahi Sumber

Merge branch 'wyp/1211-recommendVideoSource' of Server/long-article-recommend into master

wangyunpeng 7 bulan lalu
induk
melakukan
99b38d0171
23 mengubah file dengan 303 tambahan dan 79 penghapusan
  1. 40 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/aigc/PublishPlanInputSourceTypesEnum.java
  2. 16 6
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/ContentPoolEnum.java
  3. 2 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/RankStrategyEnum.java
  4. 1 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/dto/Content.java
  5. 1 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/model/vo/ArticleSortResponseDataItem.java
  6. 72 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/RankService.java
  7. 1 5
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/HisJumpRankStrategy.java
  8. 3 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/InfiniteRankStrategy.java
  9. 3 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/LateRankStrategy.java
  10. 1 4
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RandomRankStrategy.java
  11. 2 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV10Strategy.java
  12. 3 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV11Strategy.java
  13. 3 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV12Strategy.java
  14. 3 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV13Strategy.java
  15. 3 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV14Strategy.java
  16. 133 0
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV15Strategy.java
  17. 2 9
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV3Strategy.java
  18. 2 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV4Strategy.java
  19. 3 4
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV5Strategy.java
  20. 2 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV7Strategy.java
  21. 3 3
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV8Strategy.java
  22. 2 2
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV9Strategy.java
  23. 2 1
      long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/score/ScoreService.java

+ 40 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/aigc/PublishPlanInputSourceTypesEnum.java

@@ -0,0 +1,40 @@
+package com.tzld.longarticle.recommend.server.common.enums.aigc;
+
+import lombok.Getter;
+
+import java.util.Objects;
+
+@Getter
+public enum PublishPlanInputSourceTypesEnum {
+    producePlan(1, "生成计划"),
+    produceContent(2, "单个生成内容"),
+    crawlerPlan(3, "抓取计划"),
+    crawlerContent(4, "单个抓取内容"),
+    publishPlan(5, "发布计划"),
+    publishContent(6, "单个发布内容"),
+    pretreatPlan(7, "处理计划"),
+    pretreatContent(8, "单个处理内容"),
+    monitor_plan_query_contents(9, "监控计划查找输入源"),
+    template(10, "评论/私信模板"),
+    monitor_plan(11, "监控计划内容"),
+    longArticleVideoPoolSource(12, "长文视频池内容"),
+    other(999, ""),
+    ;
+
+    private final Integer val;
+    private final String description;
+
+    PublishPlanInputSourceTypesEnum(Integer val, String description) {
+        this.val = val;
+        this.description = description;
+    }
+
+    public static PublishPlanInputSourceTypesEnum from(Integer val) {
+        for (PublishPlanInputSourceTypesEnum typesEnum : PublishPlanInputSourceTypesEnum.values()) {
+            if (Objects.equals(typesEnum.val, val)) {
+                return typesEnum;
+            }
+        }
+        return null;
+    }
+}

+ 16 - 6
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/common/enums/recommend/ContentPoolEnum.java

@@ -8,19 +8,20 @@ import java.util.Objects;
 
 @Getter
 public enum ContentPoolEnum {
-    autoArticlePoolLevel1("autoArticlePoolLevel1", "内容池1层"),
-    autoArticlePoolLevel2("autoArticlePoolLevel2", "内容池2层"),
-    autoArticlePoolLevel3("autoArticlePoolLevel3", "内容池3层"),
-    autoArticlePoolLevel4("autoArticlePoolLevel4", "冷启层"),
+    autoArticlePoolLevel1("autoArticlePoolLevel1", 1, "内容池1层"),
+    autoArticlePoolLevel2("autoArticlePoolLevel2", 2, "内容池2层"),
+    autoArticlePoolLevel3("autoArticlePoolLevel3", 3, "内容池3层"),
+    autoArticlePoolLevel4("autoArticlePoolLevel4", 4, "冷启层"),
 
     ;
 
-
     private final String contentPool;
+    private final Integer value;
     private final String description;
 
-    ContentPoolEnum(String contentPool, String description) {
+    ContentPoolEnum(String contentPool, Integer value, String description) {
         this.contentPool = contentPool;
+        this.value = value;
         this.description = description;
     }
 
@@ -33,6 +34,15 @@ public enum ContentPoolEnum {
         return autoArticlePoolLevel4;
     }
 
+    public static ContentPoolEnum from(Integer value) {
+        for (ContentPoolEnum poolEnum : ContentPoolEnum.values()) {
+            if (Objects.equals(poolEnum.value, value)) {
+                return poolEnum;
+            }
+        }
+        return autoArticlePoolLevel4;
+    }
+
     public static List<String> getOrderContentPool() {
         List<String> result = new ArrayList<>();
         result.add(autoArticlePoolLevel1.getContentPool());

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

@@ -20,6 +20,8 @@ public enum RankStrategyEnum {
     ArticleRankV13("ArticleRankV13", "ArticleRankV13", "rankV13Strategy"),
     ArticleRankV14("ArticleRankV14", "ArticleRankV14", "rankV14Strategy"),
 
+    ArticleRankV15("ArticleRankV15", "ArticleRankV15", "rankV15Strategy"),
+
     HIS_JUMP_STRATEGY("ArticleRankHisJump", "历史表现跳过相似度策略", "hisJumpRankStrategy"),
     INFINITE_STRATEGY("ArticleRankInfinite", "无限发表", "infiniteRankStrategy"),
     LATE_STRATEGY("ArticleRankLate", "晚间策略", "lateRankStrategy"),

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

@@ -18,6 +18,7 @@ import java.util.Map;
 @AllArgsConstructor
 public class Content {
     private String id;
+    private Integer sourceType;
     private String sourceId;
     private String title;
     private Long createTimestamp;

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

@@ -11,6 +11,7 @@ import java.util.Map;
 @Accessors(chain = true)
 public class ArticleSortResponseDataItem {
     private String id;
+    private Integer sourceType;
     private String sourceId;
     private String contentPoolType; // 内容池类别
     private String title;

+ 72 - 9
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/RankService.java

@@ -4,6 +4,10 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank;
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.ctrip.framework.apollo.model.ConfigChangeEvent;
+import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.longarticle.recommend.server.common.enums.aigc.PublishPlanInputSourceTypesEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.ServiceBeanFactory;
@@ -12,11 +16,13 @@ import com.tzld.longarticle.recommend.server.service.recommend.score.AccountInde
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 import static com.tzld.longarticle.recommend.server.common.constant.SceneConstants.FWH_COLD_START;
 
@@ -25,7 +31,38 @@ import static com.tzld.longarticle.recommend.server.common.constant.SceneConstan
  */
 @Service
 @Slf4j
-public class RankService {
+public class RankService implements InitializingBean {
+
+    private static Map<String, Map<String, Integer>> staticStrategyPoolSourceTypeMap;
+
+    @ApolloJsonValue("${strategyPoolSourceTypeConfig:{}}")
+    private Map<String, Map<String, Integer>> strategyPoolSourceTypeMap;
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        RankService.staticStrategyPoolSourceTypeMap = strategyPoolSourceTypeMap;
+    }
+
+    @ApolloConfigChangeListener(interestedKeys = {"strategyPoolSourceTypeConfig"})
+    public void configChange(ConfigChangeEvent changeEvent) {
+        RankService.staticStrategyPoolSourceTypeMap = JSONObject.parseObject(changeEvent.getChange(
+                "strategyPoolSourceTypeConfig").getNewValue(), Map.class);
+        log.info("strategyPoolSourceTypeConfig change updateStaticValue success newValue:{}",
+                JSONObject.toJSONString(staticStrategyPoolSourceTypeMap));
+    }
+
+    public static Integer getStrategyPoolSourceType(String strategy, Integer index) {
+        Integer sourceType = 0;
+        Map<String, Integer> indexSourceTypeMap = staticStrategyPoolSourceTypeMap.get(strategy);
+        if (Objects.nonNull(indexSourceTypeMap)) {
+            sourceType = indexSourceTypeMap.get(String.valueOf(index));
+        }
+        return sourceType;
+    }
+
+    public static Map<String, Integer> getStrategyPoolSourceType(String strategy) {
+        return staticStrategyPoolSourceTypeMap.get(strategy);
+    }
 
     public RankResult rank(RankParam param) {
         RankStrategy strategy = getRankStrategy(param);
@@ -60,11 +97,14 @@ public class RankService {
         log.info("{} 账号名称 {} {}评分结果 {}", strategy, accountName, position, JSONObject.toJSONString(jsonArray));
     }
 
-    public static void commonAddSecondContent(List<Content> result,
+    public static void commonAddSecondContent(RankParam param, List<Content> result,
                                               String[] publishPool, String[] contentPools,
                                               Map<String, List<Content>> contentMap,
                                               Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
         List<Content> pool = contentMap.get(contentPools[1]);
+        if (CollectionUtils.isNotEmpty(pool)) {
+            pool = contentSourceTypeFilter(param.getStrategy(), pool, 2);
+        }
         if (CollectionUtils.isNotEmpty(pool)) {
             int i = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
             int j = RandomUtils.nextInt(0, Math.min(pool.size(), 5));
@@ -82,20 +122,43 @@ public class RankService {
             }
         } else {
             // 替补 根据设置替补内容池查找内容进行替补
-            AccountIndexReplacePoolConfig replacePoolConfig = indexReplacePoolConfigMap.get(2);
-            if (Objects.nonNull(replacePoolConfig)) {
-                List<Content> poolReplace = contentMap.get(replacePoolConfig.getContentPool());
-                if (CollectionUtils.isNotEmpty(poolReplace)) {
-                    publishPool[1] = replacePoolConfig.getContentPool();
-                    result.add(poolReplace.get(0));
-                }
+            findReplacePoolContent(result, publishPool, contentMap, indexReplacePoolConfigMap);
+        }
+    }
+
+    public static void findReplacePoolContent(List<Content> result, String[] publishPool,
+                                              Map<String, List<Content>> contentMap,
+                                              Map<Integer, AccountIndexReplacePoolConfig> indexReplacePoolConfigMap) {
+        AccountIndexReplacePoolConfig replacePoolConfig = indexReplacePoolConfigMap.get(2);
+        if (Objects.nonNull(replacePoolConfig)) {
+            List<Content> poolReplace = contentMap.get(replacePoolConfig.getContentPool());
+            if (CollectionUtils.isNotEmpty(poolReplace)) {
+                publishPool[1] = replacePoolConfig.getContentPool();
+                result.add(poolReplace.get(0));
             }
         }
     }
 
+    public static List<Content> contentSourceTypeFilter(String strategy, List<Content> pool, Integer index) {
+        if (!staticStrategyPoolSourceTypeMap.containsKey(strategy)) {
+            return pool;
+        }
+        Integer sourceType = getStrategyPoolSourceType(strategy, index);
+        Integer videoSourceType = PublishPlanInputSourceTypesEnum.longArticleVideoPoolSource.getVal();
+        if (Objects.nonNull(sourceType) && sourceType.equals(videoSourceType)) {
+            pool = pool.stream().filter(o -> Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
+        } else {
+            pool = pool.stream().filter(o -> !Objects.equals(o.getSourceType(), videoSourceType)).collect(Collectors.toList());
+        }
+        return pool;
+    }
+
     public static void commonAdd38Content(RankParam param, List<Content> result, String[] contentPools,
                                           Map<String, List<Content>> contentMap, String strategy) {
         List<Content> pool = contentMap.get(contentPools[2]);
+        if (CollectionUtils.isNotEmpty(pool)) {
+            pool = contentSourceTypeFilter(param.getStrategy(), pool, 3);
+        }
         if (CollectionUtils.isNotEmpty(pool) && param.getSize() > result.size()) {
             RankService.printSortLog(strategy, param.getAccountName(), "3-8", pool.subList(0, Math.min(pool.size(), 200)));
             result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize() - result.size())));

+ 1 - 5
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/HisJumpRankStrategy.java

@@ -1,9 +1,7 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
-import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
-import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
 import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
@@ -28,8 +26,6 @@ public class HisJumpRankStrategy implements RankStrategy {
     @Autowired
     private AccountContentPoolConfigService accountContentPoolConfigService;
     @Autowired
-    private ArticleRepository articleRepository;
-    @Autowired
     private StrategyIndexScoreWeightService weightService;
 
     public RankResult rank(RankParam param) {
@@ -90,7 +86,7 @@ public class HisJumpRankStrategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.HIS_JUMP_STRATEGY.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             int i = RandomUtils.nextInt(0, Math.min(pool1.size(), 20));
             result.add(pool1.get(i));

+ 3 - 9
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/InfiniteRankStrategy.java

@@ -1,19 +1,16 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
+import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankItem;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankParam;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankResult;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankStrategy;
+import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreResult;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreService;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -76,10 +73,7 @@ public class InfiniteRankStrategy implements RankStrategy {
         }
 
         // 全部使用3-8内容池
-        List<Content> pool = contentMap.get(contentPools[2]);
-        if (CollectionUtils.isNotEmpty(pool)) {
-            result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize())));
-        }
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         return new RankResult(result);
     }

+ 3 - 9
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/LateRankStrategy.java

@@ -1,19 +1,16 @@
 package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
+import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankItem;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankParam;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankResult;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankStrategy;
+import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreResult;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreService;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -76,10 +73,7 @@ public class LateRankStrategy implements RankStrategy {
         }
 
         // 全部使用3-8内容池
-        List<Content> pool = contentMap.get(contentPools[2]);
-        if (CollectionUtils.isNotEmpty(pool)) {
-            result.addAll(pool.subList(0, Math.min(pool.size(), param.getSize())));
-        }
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         return new RankResult(result);
     }

+ 1 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RandomRankStrategy.java

@@ -3,10 +3,7 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankItem;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankParam;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankResult;
-import com.tzld.longarticle.recommend.server.service.recommend.rank.RankStrategy;
+import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreService;
 import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
 import lombok.extern.slf4j.Slf4j;

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV10Strategy.java

@@ -109,10 +109,10 @@ public class RankV10Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV10.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -121,7 +121,7 @@ public class RankV11Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV11.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -129,10 +129,10 @@ public class RankV11Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV11.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -121,7 +121,7 @@ public class RankV12Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV12.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -129,10 +129,10 @@ public class RankV12Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV12.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 3 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV13Strategy.java

@@ -122,7 +122,7 @@ public class RankV13Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV13.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -130,10 +130,10 @@ public class RankV13Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV13.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 3 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV14Strategy.java

@@ -122,7 +122,7 @@ public class RankV14Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV14.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -130,10 +130,10 @@ public class RankV14Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV14.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -0,0 +1,133 @@
+package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
+
+
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
+import com.tzld.longarticle.recommend.server.model.dto.Content;
+import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
+import com.tzld.longarticle.recommend.server.service.recommend.config.AccountContentPoolConfigService;
+import com.tzld.longarticle.recommend.server.service.recommend.config.StrategyIndexScoreWeightService;
+import com.tzld.longarticle.recommend.server.service.recommend.rank.*;
+import com.tzld.longarticle.recommend.server.service.recommend.score.AccountIndexReplacePoolConfig;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreResult;
+import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreService;
+import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * @author dyp
+ */
+@Service
+@Slf4j
+public class RankV15Strategy implements RankStrategy {
+
+    @Autowired
+    private ScoreService scoreService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
+    @Autowired
+    private ArticleRepository articleRepository;
+    @Autowired
+    private StrategyIndexScoreWeightService weightService;
+
+    @ApolloJsonValue("${touliu.account.ghIds:[\"gh_93e00e187787\", \"gh_ac43e43b253b\", \"gh_68e7fdc09fe4\",\"gh_77f36c109fb1\", \"gh_b181786a6c8c\", \"gh_1ee2e1b39ccf\"]}")
+    private List<String> touliuAccountGhIds;
+
+    public RankResult rank(RankParam param) {
+        List<Content> result = new ArrayList<>();
+
+        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;
+            int index = weightService.getIndex(item.getContent().getContentPoolType(), contentPools);
+            if (contentPools[0].equals(item.getContent().getContentPoolType())
+                    || contentPools[1].equals(item.getContent().getContentPoolType())) {
+                score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value());
+                if (item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value()) >= 0) {
+                    score += item.getScore(ScoreStrategyEnum.VIEW_COUNT_RATE.value())
+                            * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                            ScoreStrategyEnum.VIEW_COUNT_RATE.value());
+                }
+            } else {
+                score = item.getScore(ScoreStrategyEnum.SIMILARITY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.SIMILARITY.value())
+                        + item.getScore(ScoreStrategyEnum.CATEGORY.value())
+                        * weightService.getWeight(param.getStrategy(), param.getGhId(), index,
+                        ScoreStrategyEnum.CATEGORY.value())
+                        + item.getScore(ScoreStrategyEnum.ACCOUNT_PRE_DISTRIBUTE.value())
+                        + item.getScore(ScoreStrategyEnum.PUBLISH_TIMES.value())
+                        + item.getScore(ScoreStrategyEnum.CRAWLER_DAYS_DECREASE_STRATEGY.value())
+                        + item.getScore(ScoreStrategyEnum.FLOW_CTL_DECREASE.value());
+            }
+            c.setScore(score);
+            item.setScore(score);
+            return item;
+        });
+        // 相似度评分为0 报警返回
+        List<Article> hisPublishFirstArticleList = articleRepository.getByGhIdAndItemIndexAndTypeEqualsAndStatusEquals(
+                param.getGhId(), 1, param.getType(), 1);
+        if (RankStrategy.SimilarityScoreZero(items, param, hisPublishFirstArticleList)) {
+            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);
+
+        // 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)) {
+            pool1 = RankService.contentSourceTypeFilter(param.getStrategy(), pool1, 1);
+        }
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
+        if (CollectionUtils.isNotEmpty(pool1)) {
+            result.add(pool1.get(0));
+        } else {
+            RankStrategy.sendFeishuFirstPoolEmpty(param, contentPools[0]);
+            return new RankResult(result);
+        }
+        // 次
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+
+        // 3-8
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
+
+        RankStrategy.deduplication(result, contentMap, publishPool);
+
+        return new RankResult(result);
+    }
+
+}

+ 2 - 9
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV3Strategy.java

@@ -106,18 +106,11 @@ public class RankV3Strategy implements RankStrategy {
             result.add(pool2.get(i));
         } 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));
-                }
-            }
+            RankService.findReplacePoolContent(result, publishPool, contentMap, indexReplacePoolConfigMap);
         }
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV3.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV4Strategy.java

@@ -99,10 +99,10 @@ public class RankV4Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV4.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 3 - 4
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV5Strategy.java

@@ -2,7 +2,6 @@ package com.tzld.longarticle.recommend.server.service.recommend.rank.strategy;
 
 
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
-import com.tzld.longarticle.recommend.server.common.enums.recommend.RankStrategyEnum;
 import com.tzld.longarticle.recommend.server.common.enums.recommend.ScoreStrategyEnum;
 import com.tzld.longarticle.recommend.server.model.dto.Content;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
@@ -110,7 +109,7 @@ public class RankV5Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV5.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -118,10 +117,10 @@ public class RankV5Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV5.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV7Strategy.java

@@ -101,10 +101,10 @@ public class RankV7Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV7.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 3 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV8Strategy.java

@@ -105,7 +105,7 @@ public class RankV8Strategy implements RankStrategy {
 
         // 头
         List<Content> pool1 = contentMap.get(contentPools[0]);
-        RankService.printSortLog(RankStrategyEnum.ArticleRankV8.getStrategy(), param.getAccountName(), "头条", pool1);
+        RankService.printSortLog(param.getStrategy(), param.getAccountName(), "头条", pool1);
         if (CollectionUtils.isNotEmpty(pool1)) {
             result.add(pool1.get(0));
         } else {
@@ -113,10 +113,10 @@ public class RankV8Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV8.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

+ 2 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/rank/strategy/RankV9Strategy.java

@@ -101,10 +101,10 @@ public class RankV9Strategy implements RankStrategy {
             return new RankResult(result);
         }
         // 次
-        RankService.commonAddSecondContent(result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
+        RankService.commonAddSecondContent(param, result, publishPool, contentPools, contentMap, indexReplacePoolConfigMap);
 
         // 3-8
-        RankService.commonAdd38Content(param, result, contentPools, contentMap, RankStrategyEnum.ArticleRankV9.getStrategy());
+        RankService.commonAdd38Content(param, result, contentPools, contentMap, param.getStrategy());
 
         RankStrategy.deduplication(result, contentMap, publishPool);
 

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

@@ -122,7 +122,8 @@ public class ScoreService implements ApplicationContextAware {
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV11.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV12.getStrategy())
                 || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV13.getStrategy())
-                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV14.getStrategy())) {
+                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV14.getStrategy())
+                || StringUtils.equals(param.getStrategy(), RankStrategyEnum.ArticleRankV15.getStrategy())) {
             strategies.add(strategyMap.get(ScoreStrategyEnum.CATEGORY.value()));
             strategies.add(strategyMap.get(ScoreStrategyEnum.ACCOUNT_PRE_DISTRIBUTE.value()));
             strategies.add(strategyMap.get(ScoreStrategyEnum.FLOW_CTL_DECREASE.value()));