Bläddra i källkod

修改拼装保底数据

xueyiming 5 månader sedan
förälder
incheckning
cd27e89290

+ 67 - 16
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComMessageDataJob.java

@@ -7,6 +7,7 @@ import com.aliyun.odps.data.Record;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.wecom.dao.mapper.*;
 import com.tzld.piaoquan.wecom.model.bo.PushMessage;
+import com.tzld.piaoquan.wecom.model.bo.VideoCombination;
 import com.tzld.piaoquan.wecom.model.bo.VideoParam;
 import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
 import com.tzld.piaoquan.wecom.model.po.*;
@@ -73,7 +74,7 @@ public class WeComMessageDataJob {
     Map<Long, List<PushMessage>> historicalTopMap = new HashMap<>();
 
     //保底视频列表
-    Map<Long, List<Long>> guaranteedVideoMap = new HashMap<>();
+    Map<Long, VideoCombination> guaranteedVideoMap = new HashMap<>();
 
     Map<String, String> pageMap = new HashMap<>();
 
@@ -99,7 +100,7 @@ public class WeComMessageDataJob {
             pushMessage.setScore(score);
             list.add(pushMessage);
         }
-        Map<Long, List<PushMessage>> groupedMap = list.stream()
+        historicalTopMap = list.stream()
                 .collect(Collectors.groupingBy(PushMessage::getStaffId,
                         Collectors.mapping(pushMessage -> pushMessage,
                                 Collectors.toList())))
@@ -111,7 +112,6 @@ public class WeComMessageDataJob {
                                 .sorted(Comparator.comparing(PushMessage::getScore).reversed()) // 根据 score 降序排序
                                 .collect(Collectors.toList())
                 ));
-        historicalTopMap = groupedMap;
 
         //保底视频获取
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
@@ -121,7 +121,7 @@ public class WeComMessageDataJob {
             LarkRobotUtil.sendMessage("保底视频获取异常,请检查" + DateUtil.getThatDayDateString());
             throw new RuntimeException();
         }
-        Map<Long, List<Long>> videoMap = new HashMap<>();
+        Map<Long, VideoCombination> videoMap = new HashMap<>();
         for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
             if (videoParam.getStaffId() == null) {
                 LarkRobotUtil.sendMessage("保底视频获取异常,StaffId为空" + DateUtil.getThatDayDateString());
@@ -129,10 +129,10 @@ public class WeComMessageDataJob {
             }
             //默认组视频不做查询
             if (videoParam.getStaffId() == 0L) {
-                if(videoParam.getVideoIds().size() < MAX_VIDEO_NUM){
+                if (videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
                     LarkRobotUtil.sendMessage("默认组视频数量不足" + DateUtil.getThatDayDateString());
                 }
-                videoMap.put(videoParam.getStaffId(), videoParam.getVideoIds());
+                videoMap.put(videoParam.getStaffId(), combination(videoParam.getVideoIds()));
                 continue;
             }
             if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
@@ -154,7 +154,8 @@ public class WeComMessageDataJob {
                     throw new RuntimeException();
                 }
             }
-            videoMap.put(videoParam.getStaffId(), videoParam.getVideoIds());
+            //重新组合视频id
+            videoMap.put(videoParam.getStaffId(), combination(videoParam.getVideoIds()));
         }
         if (!videoMap.containsKey(0L)) {
             LarkRobotUtil.sendMessage("保底视频没有默认组,请查看" + guaranteedParam.getDate());
@@ -163,6 +164,30 @@ public class WeComMessageDataJob {
         this.guaranteedVideoMap = videoMap;
     }
 
+    private VideoCombination combination(List<Long> videoIds) {
+        VideoCombination videoCombination = new VideoCombination();
+        videoCombination.setThreeVideoList(combinedVideoList(videoIds, 3));
+        videoCombination.setThreeVideoIndex(0);
+        videoCombination.setTwoVideoList(combinedVideoList(videoIds, 2));
+        videoCombination.setTwoVideoIndex(0);
+        videoCombination.setOneVideoList(combinedVideoList(videoIds, 1));
+        videoCombination.setOneVideoIndex(0);
+        return videoCombination;
+    }
+
+    private List<List<Long>> combinedVideoList(List<Long> videoIds, int count) {
+        List<List<Long>> res = new ArrayList<>();
+        for (int i = 0; i < videoIds.size(); i++) {
+            List<Long> list = new ArrayList<>();
+            for (int j = 0; j < count; j++) {
+                int index = (i + j) % videoIds.size();
+                list.add(videoIds.get(index));
+            }
+            res.add(list);
+        }
+        return res;
+    }
+
     @XxlJob("assembleSendMessageJob")
     public ReturnT<String> assembleSendMessage(String param) {
         XxlJobParam xxlJobParam = new XxlJobParam();
@@ -292,21 +317,47 @@ public class WeComMessageDataJob {
     }
 
     private int fillGuaranteedMessages(SendMessage sendMessage, Long staffId, int currentCount) {
-        List<Long> guaranteedVideoIdList = guaranteedVideoMap.get(staffId);
-        if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
-            guaranteedVideoIdList = guaranteedVideoMap.get(0L);
+        VideoCombination videoCombination = guaranteedVideoMap.get(staffId);
+        if (videoCombination == null) {
+            videoCombination = guaranteedVideoMap.get(0L);
         }
-        if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
+        if (videoCombination == null) {
             LarkRobotUtil.sendMessage("组装数据时,保底数据获取异常");
             throw new RuntimeException("保底数据获取异常");
         }
         if (currentCount < MAX_VIDEO_NUM) {
-            for (Long videoId : guaranteedVideoIdList) {
-                setVideoId(sendMessage, currentCount, videoId);
-                currentCount++;
-                if (currentCount >= MAX_VIDEO_NUM) {
+            switch (currentCount) {
+                case 0:
+                    currentCount = setVideoId(sendMessage, videoCombination.getThreeVideoList().get(videoCombination.getThreeVideoIndex()),
+                            currentCount);
+                    videoCombination.setThreeVideoIndex(
+                            (videoCombination.getThreeVideoIndex() + 1) % videoCombination.getThreeVideoList().size());
                     break;
-                }
+                case 1:
+                    currentCount = setVideoId(sendMessage, videoCombination.getTwoVideoList().get(videoCombination.getTwoVideoIndex()),
+                            currentCount);
+                    videoCombination.setTwoVideoIndex(
+                            (videoCombination.getTwoVideoIndex() + 1) % videoCombination.getTwoVideoList().size());
+                    break;
+                case 2:
+                    currentCount = setVideoId(sendMessage, videoCombination.getOneVideoList().get(videoCombination.getOneVideoIndex()),
+                            currentCount);
+                    videoCombination.setOneVideoIndex(
+                            (videoCombination.getOneVideoIndex() + 1) % videoCombination.getOneVideoList().size());
+                    break;
+                default:
+                    break;
+            }
+        }
+        return currentCount;
+    }
+
+    private int setVideoId(SendMessage sendMessage, List<Long> videoIds, Integer currentCount) {
+        for (Long videoId : videoIds) {
+            setVideoId(sendMessage, currentCount, videoId);
+            currentCount++;
+            if (currentCount >= MAX_VIDEO_NUM) {
+                break;
             }
         }
         return currentCount;

+ 24 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/model/bo/VideoCombination.java

@@ -0,0 +1,24 @@
+package com.tzld.piaoquan.wecom.model.bo;
+
+import lombok.Data;
+import lombok.ToString;
+
+import java.util.List;
+
+@ToString
+@Data
+public class VideoCombination {
+
+    private List<List<Long>> threeVideoList;
+
+    private Integer threeVideoIndex;
+
+    private List<List<Long>> twoVideoList;
+
+    private Integer twoVideoIndex;
+
+    private List<List<Long>> oneVideoList;
+
+    private Integer oneVideoIndex;
+
+}