丁云鹏 há 11 meses atrás
pai
commit
b17ce119aa

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

@@ -1,15 +0,0 @@
-package com.tzld.longarticle.recommend.server.service;
-
-import lombok.Data;
-
-/**
- * @author dyp
- */
-@Data
-public class AccountContentPoolConfig {
-    private String account;
-    /**
-     * 0-头条 1-次条 2-其他位置
-     */
-    private String[] contentPools;
-}

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

@@ -0,0 +1,25 @@
+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;
+
+/**
+ * @author dyp
+ */
+@Component
+@Slf4j
+public class AccountContentPoolConfigService {
+
+    @ApolloJsonValue("${accountContentPoolConfig:{}}")
+    private Map<String, String[]> accountContentPoolMap;
+
+    public String[] getContentPools(String accountName) {
+        if (accountContentPoolMap.containsKey(accountName)) {
+            return accountContentPoolMap.get(accountName);
+        }
+        return accountContentPoolMap.get("default");
+    }
+}

+ 8 - 16
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/strategy/HistoryTitleStrategy.java

@@ -1,10 +1,9 @@
 package com.tzld.longarticle.recommend.server.service.filter.strategy;
 
-import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.tzld.longarticle.recommend.server.model.Content;
 import com.tzld.longarticle.recommend.server.model.remote.Article;
 import com.tzld.longarticle.recommend.server.remote.ArticleListRemoteService;
-import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfig;
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.filter.FilterParam;
 import com.tzld.longarticle.recommend.server.service.filter.FilterResult;
 import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy;
@@ -29,26 +28,28 @@ public class HistoryTitleStrategy implements FilterStrategy {
 
     @Autowired
     private ArticleListRemoteService articleListRemoteService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
 
     private static final List<Integer> firstSecondIndex = Arrays.asList(1, 2);
     private static final List<Integer> allIndex = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
 
-    @ApolloJsonValue("${accountContentPoolConfig:[]}")
-    private List<AccountContentPoolConfig> accountContentPoolConfigList;
 
     @Override
     public FilterResult filter(FilterParam param) {
         FilterResult filterResult = new FilterResult();
         List<String> result = new ArrayList<>();
-        List<Content> filterContents  = new ArrayList<>();
+        List<Content> filterContents = new ArrayList<>();
         List<Article> firstSecondArticleList = articleListRemoteService.articleList(param.getAccountName(), firstSecondIndex);
         List<String> firstSecondTitleList = firstSecondArticleList.stream().map(Article::getTitle).collect(Collectors.toList());
         List<Article> allArticleList = articleListRemoteService.articleList(param.getAccountName(), allIndex);
         List<String> allTitleList = allArticleList.stream().map(Article::getTitle).collect(Collectors.toList());
-        AccountContentPoolConfig contentPoolConfig = getContentPoolConfig(param.getAccountName());
+
+
         List<String> firstSecondContentPool = new ArrayList<>();
+        String[] contentPoolConfig = accountContentPoolConfigService.getContentPools(param.getAccountName());
         if (Objects.nonNull(contentPoolConfig)) {
-            firstSecondContentPool = Arrays.asList(contentPoolConfig.getContentPools()[0], contentPoolConfig.getContentPools()[1]);
+            firstSecondContentPool = Arrays.asList(contentPoolConfig[0], contentPoolConfig[1]);
         }
         for (Content content : param.getContents()) {
             boolean isDuplicate;
@@ -70,13 +71,4 @@ public class HistoryTitleStrategy implements FilterStrategy {
         return filterResult;
     }
 
-    private AccountContentPoolConfig getContentPoolConfig(String accountName) {
-        for (AccountContentPoolConfig contentPoolConfig : accountContentPoolConfigList) {
-            if (accountName.equals(contentPoolConfig.getAccount())) {
-                return contentPoolConfig;
-            }
-        }
-        return null;
-    }
-
 }

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

@@ -2,7 +2,7 @@ package com.tzld.longarticle.recommend.server.service.rank;
 
 
 import com.tzld.longarticle.recommend.server.model.Content;
-import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfig;
+import com.tzld.longarticle.recommend.server.service.AccountContentPoolConfigService;
 import com.tzld.longarticle.recommend.server.service.score.ScoreParam;
 import com.tzld.longarticle.recommend.server.service.score.ScoreResult;
 import com.tzld.longarticle.recommend.server.service.score.ScoreService;
@@ -29,6 +29,8 @@ public class RankService {
 
     @Autowired
     private ScoreService scoreService;
+    @Autowired
+    private AccountContentPoolConfigService accountContentPoolConfigService;
 
     public RankResult rank(RankParam param) {
 
@@ -60,8 +62,7 @@ public class RankService {
         }
         // 3 按位置选文章
         List<Content> result = new ArrayList<>();
-        AccountContentPoolConfig config = null;
-        String[] contentPools = config.getContentPools();
+        String[] contentPools = accountContentPoolConfigService.getContentPools(param.getAccountName());
 
         // 头
         List<Content> pool = contentMap.get(contentPools[0]);