Browse Source

排序是获取文章品类

wangyunpeng 8 months ago
parent
commit
5580ef70df

+ 2 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/repository/longArticle/ArticlePoolPromotionSourceRepository.java

@@ -11,6 +11,8 @@ public interface ArticlePoolPromotionSourceRepository extends JpaRepository<Arti
 
     ArticlePoolPromotionSource getByChannelContentId(String channelContentId);
 
+    List<ArticlePoolPromotionSource> getByChannelContentIdIn(List<String> channelContentIds);
+
     List<ArticlePoolPromotionSource> getByChannelContentIdInAndStatusAndDeleted(List<String> channelContentIds, Integer status, Integer deleted);
 
     List<ArticlePoolPromotionSource> getByStatus(Integer status);

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

@@ -12,12 +12,16 @@ import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo
 import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountCorrelation;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
 import com.tzld.longarticle.recommend.server.model.entity.crawler.ArticleDetailInfo;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticleCategory;
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
 import com.tzld.longarticle.recommend.server.remote.AIGCRemoteService;
 import com.tzld.longarticle.recommend.server.repository.aigc.CrawlerMetaArticleRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.AccountCorrelationRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleDetailInfoRepository;
 import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticleCategoryRepository;
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticlePoolPromotionSourceRepository;
 import com.tzld.longarticle.recommend.server.service.recommend.config.AccountIndexAvgViewCountService;
 import com.tzld.longarticle.recommend.server.service.recommend.recall.strategy.DefaultRecallStrategy;
 import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrategy;
@@ -42,6 +46,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -67,6 +72,10 @@ public class RecallService implements ApplicationContextAware {
     CrawlerBaseMapper crawlerBaseMapper;
     @Autowired
     AccountCorrelationRepository accountCorrelationRepository;
+    @Autowired
+    ArticlePoolPromotionSourceRepository articlePoolPromotionSourceRepository;
+    @Autowired
+    ArticleCategoryRepository articleCategoryRepository;
 
     private final Map<String, RecallStrategy> strategyMap = new HashMap<>();
     private ApplicationContext applicationContext;
@@ -174,9 +183,23 @@ public class RecallService implements ApplicationContextAware {
 //            String md5 = articleMd5Map.get(content.getId());
 //            content.setCategory(categoryMap.get(md5));
 //        }
+        List<String> channelContentIds = contentList.stream().map(Content::getCrawlerChannelContentId).collect(Collectors.toList());
         // 查询晋升rootProduceContentId
+        List<ArticlePoolPromotionSource> sourceList = articlePoolPromotionSourceRepository.getByChannelContentIdIn(channelContentIds);
+        Map<String, ArticlePoolPromotionSource> sourceMap = sourceList.stream().collect(Collectors.toMap(ArticlePoolPromotionSource::getChannelContentId, Function.identity()));
+        List<String> produceContentIds = sourceMap.values().stream().map(ArticlePoolPromotionSource::getRootProduceContentId).collect(Collectors.toList());
         // 根据produceContentId查询category
-
+        List<ArticleCategory> articleCategoryList = articleCategoryRepository.getByProduceContentIdIn(produceContentIds);
+        Map<String, ArticleCategory> categoryMap = articleCategoryList.stream().collect(Collectors.toMap(ArticleCategory::getProduceContentId, Function.identity()));
+        contentList.forEach(content -> {
+            ArticlePoolPromotionSource source = sourceMap.get(content.getCrawlerChannelContentId());
+            if (Objects.nonNull(source) && Objects.nonNull(source.getRootProduceContentId())) {
+                ArticleCategory category = categoryMap.get(source.getRootProduceContentId());
+                if (Objects.nonNull(category)) {
+                    content.setCategory(Collections.singletonList(category.getCategory()));
+                }
+            }
+        });
     }
 
     private List<CrawlerMetaArticle> getByUniqueIndexIn(List<String> md5List) {