|
@@ -0,0 +1,71 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.recall.strategy;
|
|
|
+
|
|
|
+import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.remote.AIGCRemoteService;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.CrawlerBaseMapper;
|
|
|
+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.FilterService;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recall.*;
|
|
|
+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;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author dyp
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class ColdStartBackupRecallStrategy implements RecallStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FilterService filterService;
|
|
|
+ @Autowired
|
|
|
+ private AIGCRemoteService aigcRemoteService;
|
|
|
+ @Autowired
|
|
|
+ CrawlerBaseMapper crawlerBaseMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RecallResult.RecallData recall(RecallParam param) {
|
|
|
+
|
|
|
+ List<Content> content = aigcRemoteService.getAllContent(param);
|
|
|
+ // category 查询
|
|
|
+ setContentCategory(content);
|
|
|
+ // 处理 content
|
|
|
+ FilterParam filterParam = FilterParamFactory.create(param, content);
|
|
|
+ filterParam.setBackup(true);
|
|
|
+ FilterResult filterResult = filterService.filter(filterParam);
|
|
|
+ // 处理 content
|
|
|
+ RecallResult.RecallData result = new RecallResult.RecallData();
|
|
|
+ result.setContents(content.stream().filter(o -> filterResult.getContentIds().contains(o.getId()))
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ result.setFilterContents(filterResult.getFilterContent());
|
|
|
+ result.setBackup(true);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setContentCategory(List<Content> contentList) {
|
|
|
+ List<String> channelContentIds = contentList.stream().map(Content::getCrawlerChannelContentId).collect(Collectors.toList());
|
|
|
+ List<ContentCategory> categoryList = getContentCategoryByChannelContentId(channelContentIds);
|
|
|
+ if (CollectionUtils.isEmpty(categoryList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, List<String>> categoryMap = categoryList.stream().collect(Collectors.groupingBy(ContentCategory::getContentChannelId,
|
|
|
+ Collectors.mapping(ContentCategory::getCategory, Collectors.toList())));
|
|
|
+ for (Content content : contentList) {
|
|
|
+ content.setCategory(categoryMap.get(content.getCrawlerChannelContentId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ContentCategory> getContentCategoryByChannelContentId(List<String> channelContentIds) {
|
|
|
+ if (CollectionUtils.isEmpty(channelContentIds)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return crawlerBaseMapper.getContentCategory(channelContentIds);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|