|
@@ -0,0 +1,52 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.recommend.filter.strategy;
|
|
|
+
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.longArticle.ArticlePoolPromotionSource;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.longArticle.ArticlePoolPromotionSourceRepository;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterParam;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterResult;
|
|
|
+import com.tzld.longarticle.recommend.server.service.recommend.filter.FilterStrategy;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ContentPoolStrategy implements FilterStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ArticlePoolPromotionSourceRepository repository;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FilterResult filter(FilterParam param) {
|
|
|
+ FilterResult filterResult = new FilterResult();
|
|
|
+ List<String> result = new ArrayList<>();
|
|
|
+ List<Content> contents = param.getContents();
|
|
|
+ List<Content> filterContents = new ArrayList<>();
|
|
|
+ List<String> channelContentIds = contents.stream().map(Content::getCrawlerChannelContentId).collect(Collectors.toList());
|
|
|
+ List<ArticlePoolPromotionSource> promotionSourceList = repository.getByChannelContentIdInAndStatusAndDeleted(channelContentIds, 1, 0);
|
|
|
+ Map<String, ArticlePoolPromotionSource> promotionSourceMap = promotionSourceList.stream().collect(Collectors.toMap(ArticlePoolPromotionSource::getChannelContentId, a -> a));
|
|
|
+ for (Content content : contents) {
|
|
|
+ if (promotionSourceMap.containsKey(content.getCrawlerChannelContentId())) {
|
|
|
+ ArticlePoolPromotionSource promotionSource = promotionSourceMap.get(content.getCrawlerChannelContentId());
|
|
|
+ if (promotionSource.getLevel().equals(content.getContentPoolType())) {
|
|
|
+ content.setFilterReason("内容已晋级过滤");
|
|
|
+ filterContents.add(content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(content.getFilterReason())) {
|
|
|
+ result.add(content.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ filterResult.setContentIds(result);
|
|
|
+ filterResult.setFilterContent(filterContents);
|
|
|
+ return filterResult;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|