Prechádzať zdrojové kódy

HistoryTitleStrategy

wangyunpeng 11 mesiacov pred
rodič
commit
39dfda9535

+ 5 - 3
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/filter/FilterService.java

@@ -38,9 +38,11 @@ public class FilterService {
         List<Future<List<String>>> futures = new ArrayList<>();
         for (final FilterStrategy strategy : strategies) {
             Future<List<String>> future = pool.submit(() -> {
-                List<String> result = strategy.filter(param);
-                cdl.countDown();
-                return result;
+                try {
+                    return strategy.filter(param);
+                } finally {
+                    cdl.countDown();
+                }
             });
             futures.add(future);
         }

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

@@ -1,18 +1,22 @@
 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.filter.FilterParam;
 import com.tzld.longarticle.recommend.server.service.filter.FilterStrategy;
 import com.tzld.longarticle.recommend.server.util.TitleSimilarCheckUtil;
 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.Arrays;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -28,6 +32,9 @@ public class HistoryTitleStrategy implements FilterStrategy {
     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 List<String> filter(FilterParam param) {
         List<String> result = new ArrayList<>();
@@ -35,10 +42,19 @@ public class HistoryTitleStrategy implements FilterStrategy {
         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<>();
+        if (Objects.nonNull(contentPoolConfig)) {
+            firstSecondContentPool = Arrays.asList(contentPoolConfig.getContentPools()[0], contentPoolConfig.getContentPools()[1]);
+        }
         for (Content content : param.getContents()) {
             boolean isDuplicate;
-            if (content.getProducePlanName().contains("【1】")
-                    || content.getProducePlanName().contains("【2】")) {
+            if (CollectionUtils.isNotEmpty(firstSecondContentPool) && firstSecondContentPool.contains(content.getContentPoolType())) {
+                // 四个内容池 配置 判断头条,次头条
+                isDuplicate = TitleSimilarCheckUtil.isDuplicateContent(content.getTitle(), firstSecondTitleList);
+            } else if (CollectionUtils.isEmpty(firstSecondContentPool) && (content.getProducePlanName().contains("【1】")
+                    || content.getProducePlanName().contains("【2】"))) {
+                // 原始发布内容 生成计划名称判断头条,次头条
                 isDuplicate = TitleSimilarCheckUtil.isDuplicateContent(content.getTitle(), firstSecondTitleList);
             } else {
                 isDuplicate = TitleSimilarCheckUtil.isDuplicateContent(content.getTitle(), allTitleList);
@@ -50,4 +66,13 @@ public class HistoryTitleStrategy implements FilterStrategy {
         return result;
     }
 
+    private AccountContentPoolConfig getContentPoolConfig(String accountName) {
+        for (AccountContentPoolConfig contentPoolConfig : accountContentPoolConfigList) {
+            if (accountName.equals(contentPoolConfig.getAccount())) {
+                return contentPoolConfig;
+            }
+        }
+        return null;
+    }
+
 }

+ 2 - 6
long-article-recommend.iml

@@ -1,14 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
-    <output url="file://$MODULE_DIR$/target/classes" />
-    <output-test url="file://$MODULE_DIR$/target/test-classes" />
-    <content url="file://$MODULE_DIR$">
+  <component name="AdditionalModuleElements">
+    <content url="file://$MODULE_DIR$" dumb="true">
       <excludeFolder url="file://$MODULE_DIR$/${project.build.directory}/classes" />
       <excludeFolder url="file://$MODULE_DIR$/${project.build.directory}/test-classes" />
       <excludeFolder url="file://$MODULE_DIR$/target" />
     </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
   </component>
 </module>