|
|
@@ -0,0 +1,82 @@
|
|
|
+package com.tzld.longarticle.recommend.server.service.recommend.filter.strategy;
|
|
|
+
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.Content;
|
|
|
+import com.tzld.longarticle.recommend.server.model.dto.ContentHisPublishArticle;
|
|
|
+import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
|
|
|
+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.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class HistoryHighViewStrategy implements FilterStrategy {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AccountAvgInfoRepository accountAvgInfoRepository;
|
|
|
+
|
|
|
+ @Value("${filter.history-high-view-rate:0.002}")
|
|
|
+ private Double historyHighViewRate;
|
|
|
+ @ApolloJsonValue("${filter.history-high-view.account.list:[]}")
|
|
|
+ private List<String> historyHighViewAccountList;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 该账号历史已发布文章中,点击量/粉丝数 > 0.002 的文章,过滤掉
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public FilterResult filter(FilterParam param) {
|
|
|
+ FilterResult filterResult = new FilterResult();
|
|
|
+ List<String> result = new ArrayList<>(param.getContents().size());
|
|
|
+ List<Content> filterContents = new ArrayList<>();
|
|
|
+ if (!historyHighViewAccountList.contains(param.getAccountName())) {
|
|
|
+ result.addAll(param.getContents().stream().map(Content::getId).collect(Collectors.toList()));
|
|
|
+ filterResult.setContentIds(result);
|
|
|
+ return filterResult;
|
|
|
+ }
|
|
|
+ List<AccountAvgInfo> avgInfoList = accountAvgInfoRepository.getAllByGhIdEqualsAndStatusEquals(param.getGhId(), 1);
|
|
|
+ Map<String, AccountAvgInfo> avgInfoMap = avgInfoList.stream().collect(Collectors.toMap(AccountAvgInfo::getPosition, o -> o, (o1, o2) -> o2));
|
|
|
+ AccountAvgInfo info = avgInfoMap.get("1");
|
|
|
+ Integer fans = Objects.nonNull(info) ? info.getFans() : null;
|
|
|
+ for (Content content : param.getContents()) {
|
|
|
+ List<ContentHisPublishArticle> historyArticleList = content.getHisPublishArticleList();
|
|
|
+ if (CollectionUtils.isNotEmpty(historyArticleList)) {
|
|
|
+ boolean filter = false;
|
|
|
+ for (ContentHisPublishArticle article : historyArticleList) {
|
|
|
+ if (article.getGhId().equals(param.getGhId()) && article.getItemIndex() == 1) {
|
|
|
+ if (article.getViewCount() / (double) (Objects.nonNull(fans) ? fans : article.getFans()) > historyHighViewRate) {
|
|
|
+ content.setFilterReason("历史已发布高阅读率文章");
|
|
|
+ filterContents.add(content);
|
|
|
+ filter = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!filter) {
|
|
|
+ result.add(content.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.add(content.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ filterResult.setContentIds(result);
|
|
|
+ filterResult.setFilterContent(filterContents);
|
|
|
+ return filterResult;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|