瀏覽代碼

ADD: 610 推荐状态过滤

sunxy 1 年之前
父節點
當前提交
38540f847b

+ 9 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/implement/recall/ViewedHistoryFilter.java

@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
 
 public class ViewedHistoryFilter extends AbstractFilter<Video> {
 
-    private VideoCityFilterService videoCityFilterService;
+    private final VideoCityFilterService videoCityFilterService;
 
     protected Set<String> historySet;
 
@@ -48,6 +48,7 @@ public class ViewedHistoryFilter extends AbstractFilter<Video> {
         if (historySet == null) {
             historySet = new HashSet<>();
         }
+        videoCityFilterService = SpringContextHolder.getBean(VideoCityFilterService.class);
 
     }
 
@@ -57,6 +58,13 @@ public class ViewedHistoryFilter extends AbstractFilter<Video> {
             return;
         }
         videoList.removeIf(video -> this.historySet.contains(String.valueOf(video.getVideoId())));
+        if (CollectionUtils.isEmpty(videoList)) {
+            return;
+        }
+        List<Long> filterVideosByCity = videoCityFilterService.filterVideosByCity(videoList.stream().map(Video::getVideoId).collect(Collectors.toList()),
+                new HashSet<>(requestContext.getAbExpCodeList()), requestContext.getHotSceneType(), requestContext.getCityCode());
+        Set<Long> filterVideosSet = new HashSet<>(filterVideosByCity);
+        videoList.removeIf(video -> !filterVideosSet.contains(video.getVideoId()));
     }
 
 

+ 20 - 10
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/VideoCityFilterService.java

@@ -4,9 +4,12 @@ import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.base.Stopwatch;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoTagRel;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoTagRelRepository;
+import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
@@ -35,7 +38,10 @@ public class VideoCityFilterService {
 
     @ApolloJsonValue("${video.filter.city.tagid.json:{}}")
     private Map<String, List<Long>> videoFilterCityTagIdMap;
-
+    @Value("#{'${block.hotscenetype.list:}'.split(',')}")
+    private Set<Long> excludeScenes;
+    @Value("${securityAbExpCode:625}")
+    private String securityAbExpCode;
     @Resource
     private WxVideoTagRelRepository wxVideoTagRelRepository;
     private Map<String, Set<Long>> videoTagCache = new ConcurrentHashMap<>();
@@ -66,27 +72,31 @@ public class VideoCityFilterService {
             if (Objects.isNull(cityCode) || Objects.isNull(tagList) || tagList.isEmpty()) {
                 continue;
             }
-            for (Long tagId : tagList) {
-                if (tagId == null || tagId <= 0L) {
-                    continue;
-                }
-                Set<Long> videosByTag = wxVideoTagRelRepository.findAllByTagId(tagId).stream().map(WxVideoTagRel::getVideoId).collect(Collectors.toSet());
-                tmp.put(cityCode, videosByTag);
-            }
+            Set<Long> videosByTag = wxVideoTagRelRepository.findAllByTagIdIn(tagList).stream()
+                    .map(WxVideoTagRel::getVideoId).collect(Collectors.toSet());
+            tmp.put(cityCode, videosByTag);
         }
         videoTagCache = tmp;
         logger.info("initCacheByValue videoTagCache.size = {} execute time = {}", videoTagCache.size(), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
 
     }
 
-    public List<Long> filterVideosByCity(List<Long> videoIds, String cityCode) {
-        if (videoIds == null || videoIds.isEmpty() || StringUtils.isBlank(cityCode)) {
+    public List<Long> filterVideosByCity(List<Long> videoIds, Set<String> abExpCodes,
+                                         Long hotSceneType, String cityCode) {
+        if (CollectionUtils.isEmpty(videoIds) || StringUtils.isBlank(cityCode) || hotSceneType == null) {
+            return videoIds;
+        }
+        if (CollectionUtils.isNotEmpty(excludeScenes) && excludeScenes.contains(hotSceneType)) {
+            return videoIds;
+        }
+        if (!CommonCollectionUtils.contains(abExpCodes, securityAbExpCode)) {
             return videoIds;
         }
         List<Long> tagIdList = videoFilterCityTagIdMap.get(cityCode);
         if (tagIdList == null || tagIdList.isEmpty()) {
             return videoIds;
         }
+
         videoIds.removeIf(videoId -> {
             if (videoId == null || videoId <= 0L) {
                 return true;