|
@@ -1,6 +1,7 @@
|
|
|
package com.tzld.piaoquan.recommend.server.service.filter;
|
|
|
|
|
|
import com.google.common.base.Stopwatch;
|
|
|
+import com.thoughtworks.xstream.mapper.Mapper;
|
|
|
import com.tzld.piaoquan.recommend.server.service.PreViewedService;
|
|
|
import com.tzld.piaoquan.recommend.server.service.ViewedService;
|
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
@@ -9,7 +10,9 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -18,15 +21,23 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public abstract class AbstractFilterService implements FilterService {
|
|
|
+ public Integer forceTruncation;
|
|
|
@Autowired
|
|
|
private PreViewedService preViewedService;
|
|
|
|
|
|
@Autowired
|
|
|
private ViewedService viewedService;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
protected List<Long> viewFilter(FilterParam param) {
|
|
|
log.info("filterParam={}", JSONUtils.toJson(param));
|
|
|
- List<Long> videoIds = filterByPreViewed(param.getAppType(), param.getMid(), param.getVideoIds());
|
|
|
+ // 风险过滤
|
|
|
+ List<Long> videoIds = filterWithRiskVideo(param.getRiskFilterFlag(),
|
|
|
+ param.getAppType(), param.getRegionCode(), param.getAppRegionFiltered(), param.getVideosWithRisk(),
|
|
|
+ param.getVideoIds());
|
|
|
+ log.info("filterByRiskVideos videoIds={}", JSONUtils.toJson(videoIds));
|
|
|
+ videoIds = filterByPreViewed(param.getAppType(), param.getMid(), param.getVideoIds());
|
|
|
log.info("filterByPreViewed videoIds={}", JSONUtils.toJson(videoIds));
|
|
|
videoIds = filterByViewed(param.getAppType(), param.getMid(), param.getUid(), videoIds);
|
|
|
log.info("filterByViewed videoIds={}", JSONUtils.toJson(videoIds));
|
|
@@ -56,4 +67,43 @@ public abstract class AbstractFilterService implements FilterService {
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private List<Long> filterWithRiskVideo(boolean riskFlag,
|
|
|
+ int appType,
|
|
|
+ String regionCode,
|
|
|
+ Map<Integer, List<String>> rules,
|
|
|
+ List<Long> videosWithRisk,
|
|
|
+ List<Long> videoIds){
|
|
|
+ if (!riskFlag){
|
|
|
+ return this.truncation(videoIds);
|
|
|
+ }
|
|
|
+ // 1 判断是否过滤,不展示的app+区域列表。
|
|
|
+ boolean filterFlag;
|
|
|
+ if (rules.containsKey(appType)){
|
|
|
+ filterFlag = false;
|
|
|
+ if (rules.get(appType).contains(regionCode)){
|
|
|
+ filterFlag = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ filterFlag = true;
|
|
|
+ }
|
|
|
+ if (!filterFlag){
|
|
|
+ return this.truncation(videoIds);
|
|
|
+ }
|
|
|
+ // 2 开始过滤。
|
|
|
+ List<Long> videoIdNew = new ArrayList<>();
|
|
|
+ for (Long videoId : videoIds) {
|
|
|
+ if (!videosWithRisk.contains(videoId)) {
|
|
|
+ videoIdNew.add(videoId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.truncation(videoIdNew);
|
|
|
+ }
|
|
|
+ private List<Long> truncation(List<Long> videoIds){
|
|
|
+ if (this.forceTruncation == null){
|
|
|
+ return videoIds;
|
|
|
+ }else{
|
|
|
+ return videoIds.subList(0, Math.min(this.forceTruncation, videoIds.size()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|