Browse Source

ADD:filterViewedVideo

sunxy 1 year ago
parent
commit
3e27024f87

+ 2 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/model/RecommendParam.java

@@ -58,5 +58,7 @@ public class RecommendParam {
 
     private Integer categoryId;
 
+    private Long hotSceneType;
+
 }
 

+ 4 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -440,6 +440,8 @@ public class RecommendService {
             param.setCategoryId(Integer.parseInt(request.getCategoryId()));
         }
 
+        param.setHotSceneType(request.getHotSceneType());
+
         return param;
     }
 
@@ -527,6 +529,8 @@ public class RecommendService {
         recallParam.setCityCode(param.getCityCode());
         recallParam.setAbCode(param.getAbCode());
 
+        recallParam.setHotSceneType(param.getHotSceneType());
+
         return recallParam;
     }
 

+ 5 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/ViewedService.java

@@ -24,8 +24,8 @@ import java.util.*;
 @Service
 @Slf4j
 public class ViewedService {
-    private Map<Integer, List<Integer>> viewedTypesMap = new HashMap<>();
-    private List<Integer> defaultViewedTypes = Lists.newArrayList(1, 6, 7, 5);
+    private final Map<Integer, List<Integer>> viewedTypesMap = new HashMap<>();
+    private final List<Integer> defaultViewedTypes = Lists.newArrayList(1, 6, 7, 5);
 
     @Value("${video.filter.url:}")
     private String videoFilterUrl;
@@ -44,11 +44,11 @@ public class ViewedService {
 
     // TODO 如果过滤失败,那么认为所有视频都被过滤掉
     public List<Long> filterViewedVideo(int appType, String mid, String uid, List<Long> videoIds, String cityCode,
-                                        String abCode) {
+                                        String abCode, Long hotSceneType) {
 
         Stopwatch stopwatch = Stopwatch.createStarted();
         List<Integer> viewedTypes = viewedTypesMap.getOrDefault(appType, defaultViewedTypes);
-        if ("60106".equals(abCode)){
+        if ("60106".equals(abCode)) {
             viewedTypes.add(8);
         }
         CloseableHttpResponse chr = null;
@@ -63,6 +63,7 @@ public class ViewedService {
             param.put("types", viewedTypes);
             param.put("videoIds", videoIds);
             param.put("cityCode", cityCode);
+            param.put("hotSceneType", hotSceneType);
             List<Integer> recommendStatus = new ArrayList<>();
             recommendStatus.add(-6);
             param.put("recommendStatus", recommendStatus);

+ 10 - 8
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/AbstractFilterService.java

@@ -68,9 +68,9 @@ public abstract class AbstractFilterService {
             videoIds = filterByPreViewed(param.getAppType(), param.getMid(), videoIds);
         }
         if (param.isConcurrent()) {
-            videoIds = filterByViewedConcurrent(param.getAppType(), param.getMid(), param.getUid(), videoIds, param.getCityCode(), param.getAbCode());
+            videoIds = filterByViewedConcurrent(param, videoIds);
         } else {
-            videoIds = filterByViewed(param.getAppType(), param.getMid(), param.getUid(), videoIds, param.getCityCode(), param.getAbCode());
+            videoIds = filterByViewed(param, videoIds);
         }
         return videoIds;
     }
@@ -96,9 +96,9 @@ public abstract class AbstractFilterService {
         }
     }
 
-    private List<Long> filterByViewedConcurrent(int appType, String mid, String uid, List<Long> videoIds, String cityCode, String abCode) {
+    private List<Long> filterByViewedConcurrent(FilterParam param, List<Long> videoIds) {
         // TODO uid为空时,还需要过滤么?
-        if (StringUtils.isBlank(mid)
+        if (StringUtils.isBlank(param.getMid())
                 || CollectionUtils.isEmpty(videoIds)) {
             return videoIds;
         }
@@ -118,7 +118,8 @@ public abstract class AbstractFilterService {
         List<Future<List<Long>>> futures = new ArrayList<>();
         for (final List<Long> ids : chunks) {
             Future<List<Long>> future = pool.submit(() ->
-                    viewedService.filterViewedVideo(appType, mid, uid, ids, cityCode, abCode));
+                    viewedService.filterViewedVideo(param.getAppType(), param.getMid(), param.getUid(), ids, param.getCityCode(),
+                            param.getAbCode(), param.getHotSceneType()));
             futures.add(future);
         }
         try {
@@ -142,13 +143,14 @@ public abstract class AbstractFilterService {
 
     }
 
-    private List<Long> filterByViewed(int appType, String mid, String uid, List<Long> videoIds, String cityCode, String abCode) {
+    private List<Long> filterByViewed(FilterParam param, List<Long> videoIds) {
         // TODO uid为空时,还需要过滤么?
-        if (StringUtils.isBlank(mid)
+        if (StringUtils.isBlank(param.getMid())
                 || CollectionUtils.isEmpty(videoIds)) {
             return videoIds;
         }
-        return viewedService.filterViewedVideo(appType, mid, uid, videoIds, cityCode, abCode);
+        return viewedService.filterViewedVideo(param.getAppType(), param.getMid(), param.getUid(), videoIds, param.getCityCode(),
+                param.getAbCode(), param.getHotSceneType());
 
     }
 

+ 3 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/FilterParam.java

@@ -32,6 +32,8 @@ public class FilterParam {
     // 层 - 实验
     private Map<String, String> expIdMap;
 
-    private String cityCode;
     private String abCode;
+
+    private Long hotSceneType;
+
 }

+ 2 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/FilterParamFactory.java

@@ -27,6 +27,7 @@ public class FilterParamFactory {
         filterParam.setAbExpCodes(param.getAbExpCodes());
         filterParam.setCityCode(param.getCityCode());
         filterParam.setAbCode(param.getAbCode());
+        filterParam.setHotSceneType(param.getHotSceneType());
         return filterParam;
     }
 
@@ -46,6 +47,7 @@ public class FilterParamFactory {
         filterParam.setAbExpCodes(param.getAbExpCodes());
         filterParam.setCityCode(param.getCityCode());
         filterParam.setAbCode(param.getAbCode());
+        filterParam.setHotSceneType(param.getHotSceneType());
         return filterParam;
     }
 }

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/RecallParam.java

@@ -39,6 +39,6 @@ public class RecallParam {
     private Map<String, String> expIdMap;
     private Integer categoryId;
 
-    private String cityCode;
+    private Long hotSceneType;
 
 }