|
@@ -5,13 +5,19 @@ import com.tzld.longarticle.recommend.server.remote.AIGCRemoteService;
|
|
|
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.ContentCategory;
|
|
|
import com.tzld.longarticle.recommend.server.service.recall.FilterParamFactory;
|
|
|
import com.tzld.longarticle.recommend.server.service.recall.RecallParam;
|
|
|
import com.tzld.longarticle.recommend.server.service.recall.RecallStrategy;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
|
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -24,11 +30,15 @@ public class DefaultRecallStrategy implements RecallStrategy {
|
|
|
private FilterService filterService;
|
|
|
@Autowired
|
|
|
private AIGCRemoteService aigcRemoteService;
|
|
|
+ @Autowired
|
|
|
+ NamedParameterJdbcTemplate piaoquanCrawlerJdbcTemplate;
|
|
|
|
|
|
@Override
|
|
|
public List<Content> recall(RecallParam param) {
|
|
|
|
|
|
List<Content> content = aigcRemoteService.getAllContent(param);
|
|
|
+ // category 查询
|
|
|
+ setContentCategory(content);
|
|
|
// 处理 content
|
|
|
FilterParam filterParam = FilterParamFactory.create(param, content);
|
|
|
FilterResult filterResult = filterService.filter(filterParam);
|
|
@@ -38,4 +48,27 @@ public class DefaultRecallStrategy implements RecallStrategy {
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ 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, String> categoryMap = categoryList.stream().collect(Collectors.toMap(ContentCategory::getChannelContentId,
|
|
|
+ ContentCategory::getCategory));
|
|
|
+ for (Content content : contentList) {
|
|
|
+ content.setCategory(categoryMap.get(content.getCrawlerChannelContentId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ContentCategory> getContentCategoryByChannelContentId(List<String> channelContentIds) {
|
|
|
+ MapSqlParameterSource parameters = new MapSqlParameterSource();
|
|
|
+ parameters.addValue("channelContentIds", channelContentIds);
|
|
|
+ List<ContentCategory> result = piaoquanCrawlerJdbcTemplate.query(
|
|
|
+ "select content_channel_id, category from cold_start_article_pool where content_channel_id in (:channelContentIds)",
|
|
|
+ parameters,
|
|
|
+ new BeanPropertyRowMapper<>(ContentCategory.class));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|