Bläddra i källkod

Merge branch 'master' into feature/zhangbo_rank

zhangbo 1 år sedan
förälder
incheckning
ea857198c6

+ 1 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/common/base/Constant.java

@@ -14,5 +14,5 @@ public class Constant {
     /**
      * 流量池头部视频redis key
      */
-    public static final String FLOW_POOL_LAST_24_HOUR_VIDEO_REDIS_KEY = "flowpool:last:24:hour:video";
+    public static final String VIDEO_PERFORMANCE_DATA_REDIS_KEY = "video_performance_data_redis_key:";
 }

+ 1 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/rank/RankService.java

@@ -163,6 +163,7 @@ public class RankService {
             rovRecallRank.addAll(extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM));
             if (param.getAbCode().equals("60110")) {
                 rovRecallRank.addAll(extractAndSort(param, FlowPoolLastDayTopRecallStrategy.PUSH_FORM));
+                rovRecallRank.addAll(extractAndSort(param, TopGoodPerformanceVideoRecallStrategy.PUSH_FORM));
             }
             removeDuplicate(rovRecallRank);
 

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

@@ -152,9 +152,10 @@ public class RecallService implements ApplicationContextAware {
                     strategies.add(strategyMap.get(ReturnVideoRecallStrategy.class.getSimpleName()));
                     break;
                 case "60110": // 新内容的召回(流量池的Top内容)
+                    strategies.add(strategyMap.get(TopGoodPerformanceVideoRecallStrategy.class.getSimpleName()));
+                    strategies.add(strategyMap.get(FlowPoolLastDayTopRecallStrategy.class.getSimpleName()));
                     strategies.add(strategyMap.get(SimHotVideoRecallStrategy.class.getSimpleName()));
                     strategies.add(strategyMap.get(ReturnVideoRecallStrategy.class.getSimpleName()));
-                    strategies.add(strategyMap.get(FlowPoolLastDayTopRecallStrategy.class.getSimpleName()));
                     break;
                 default:
                     // todo 做兜底吗?

+ 5 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractFlowPoolTopRecallStrategy.java → recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/AbstractNewContentVideoRecallStrategy.java

@@ -26,7 +26,7 @@ import java.util.stream.Collectors;
  * @author sunxy
  */
 @Slf4j
-public abstract class AbstractFlowPoolTopRecallStrategy implements RecallStrategy {
+public abstract class AbstractNewContentVideoRecallStrategy implements RecallStrategy {
 
     @Resource
     protected RedisTemplate<String, String> redisTemplate;
@@ -39,10 +39,10 @@ public abstract class AbstractFlowPoolTopRecallStrategy implements RecallStrateg
 
     @Override
     public List<Video> recall(RecallParam param) {
-        boolean checkIfInTimeRange = checkIfInTimeRange();
-        if (!checkIfInTimeRange) {
-            return Collections.emptyList();
-        }
+//        boolean checkIfInTimeRange = checkIfInTimeRange();
+//        if (!checkIfInTimeRange) {
+//            return Collections.emptyList();
+//        }
         String key = recallKey(param);
         if (StringUtils.isBlank(key)) {
             return Collections.emptyList();

+ 2 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/FlowPoolLastDayTopRecallStrategy.java

@@ -8,7 +8,7 @@ import org.springframework.stereotype.Service;
  * @author sunxy
  */
 @Service
-public class FlowPoolLastDayTopRecallStrategy extends AbstractFlowPoolTopRecallStrategy {
+public class FlowPoolLastDayTopRecallStrategy extends AbstractNewContentVideoRecallStrategy {
 
     public static final String PUSH_FORM = "flow_pool_top_video_recall";
 
@@ -19,6 +19,6 @@ public class FlowPoolLastDayTopRecallStrategy extends AbstractFlowPoolTopRecallS
 
     @Override
     public String recallKey(RecallParam param) {
-        return Constant.FLOW_POOL_LAST_24_HOUR_VIDEO_REDIS_KEY;
+        return Constant.VIDEO_PERFORMANCE_DATA_REDIS_KEY + PUSH_FORM;
     }
 }

+ 24 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/recall/strategy/TopGoodPerformanceVideoRecallStrategy.java

@@ -0,0 +1,24 @@
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
+
+import com.tzld.piaoquan.recommend.server.common.base.Constant;
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author sunxy
+ */
+@Service
+public class TopGoodPerformanceVideoRecallStrategy extends AbstractNewContentVideoRecallStrategy {
+
+    public static final String PUSH_FORM = "top_good_performance_video_recall";
+
+    @Override
+    public String pushFrom() {
+        return PUSH_FORM;
+    }
+
+    @Override
+    protected String recallKey(RecallParam param) {
+        return Constant.VIDEO_PERFORMANCE_DATA_REDIS_KEY + PUSH_FORM;
+    }
+}

+ 31 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/xxl/SyncFlowPoolRecentTopVideoJob.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.aliyun.odps.data.Record;
 import com.tzld.piaoquan.recommend.server.common.base.Constant;
 import com.tzld.piaoquan.recommend.server.service.odps.ODPSManager;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.FlowPoolLastDayTopRecallStrategy;
+import com.tzld.piaoquan.recommend.server.service.recall.strategy.TopGoodPerformanceVideoRecallStrategy;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xxl.job.core.log.XxlJobLogger;
@@ -33,15 +35,15 @@ public class SyncFlowPoolRecentTopVideoJob {
     @XxlJob("syncFlowPoolRecentTopVideo")
     public ReturnT<String> syncFlowPoolRecentTopVideo(String params) {
         // 执行 ODPS Sql,获取数据
-        List<Long> videoIds = queryTopVideoIdsByLast6Hour(100);
+        List<Long> videoIds = queryTopVideoIdsByLast6Hour(200);
         if (CollectionUtils.isEmpty(videoIds)) {
             XxlJobLogger.log("syncFlowPoolRecentTopVideo, videoIds is empty");
             return ReturnT.SUCCESS;
         }
         XxlJobLogger.log("syncFlowPoolRecentTopVideo, videoIds:{}", videoIds);
         // 将数据写入 Redis
-        redisTemplate.opsForValue().set(Constant.FLOW_POOL_LAST_24_HOUR_VIDEO_REDIS_KEY,
-                JSONObject.toJSONString(videoIds), 2, TimeUnit.DAYS);
+        redisTemplate.opsForValue().set(Constant.VIDEO_PERFORMANCE_DATA_REDIS_KEY + FlowPoolLastDayTopRecallStrategy.PUSH_FORM,
+                JSONObject.toJSONString(videoIds), 2, TimeUnit.HOURS);
         return ReturnT.SUCCESS;
     }
 
@@ -56,5 +58,31 @@ public class SyncFlowPoolRecentTopVideoJob {
         return records.stream().map(record -> record.getBigint(0)).collect(Collectors.toList());
     }
 
+    @XxlJob("syncGoodPerformanceVideo")
+    public ReturnT<String> syncGoodPerformanceVideo(String params) {
+        // 执行 ODPS Sql,获取数据
+        List<Long> videoIds = queryGoodPerformanceVideo(100);
+        if (CollectionUtils.isEmpty(videoIds)) {
+            XxlJobLogger.log("syncGoodPerformanceVideo, videoIds is empty");
+            return ReturnT.SUCCESS;
+        }
+        XxlJobLogger.log("syncGoodPerformanceVideo, videoIds:{}", videoIds);
+        // 将数据写入 Redis
+        redisTemplate.opsForValue().set(Constant.VIDEO_PERFORMANCE_DATA_REDIS_KEY + TopGoodPerformanceVideoRecallStrategy.PUSH_FORM,
+                JSONObject.toJSONString(videoIds), 2, TimeUnit.HOURS);
+        return ReturnT.SUCCESS;
+    }
+
+    private List<Long> queryGoodPerformanceVideo(int limit) {
+        String sql = "SELECT videoid FROM loghubods.long_period_good_performance_video " +
+                "WHERE dt = '" + odpsManager.getNowHour() + "' " +
+                "ORDER BY rov DESC LIMIT " + limit + ";";
+        List<Record> records = odpsManager.query(sql);
+        if (records == null || records.size() == 0) {
+            return null;
+        }
+        return records.stream().map(record -> record.getBigint(0)).collect(Collectors.toList());
+    }
+
 
 }