|
|
@@ -0,0 +1,55 @@
|
|
|
+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.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.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class CategoryFilterStrategy implements FilterStrategy {
|
|
|
+
|
|
|
+ @ApolloJsonValue("${accountCategoryFilterConfig:{}}")
|
|
|
+ private Map<String, String[]> accountCategoryFilterConfigMap;
|
|
|
+
|
|
|
+ @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<>();
|
|
|
+ if (accountCategoryFilterConfigMap.containsKey(param.getAccountName())) {
|
|
|
+ for (Content content : contents) {
|
|
|
+ if (CollectionUtils.isNotEmpty(content.getCategory())) {
|
|
|
+ boolean isFilter = false;
|
|
|
+ for (String category : content.getCategory()) {
|
|
|
+ if (Arrays.asList(accountCategoryFilterConfigMap.get(param.getAccountName())).contains(category)) {
|
|
|
+ content.setFilterReason("品类过滤");
|
|
|
+ filterContents.add(content);
|
|
|
+ isFilter = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isFilter) {
|
|
|
+ result.add(content.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.add(content.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.addAll(contents.stream().map(Content::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ filterResult.setContentIds(result);
|
|
|
+ filterResult.setFilterContent(filterContents);
|
|
|
+ return filterResult;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|