|
@@ -7,6 +7,7 @@ import com.aliyun.odps.data.Record;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.*;
|
|
import com.tzld.piaoquan.wecom.dao.mapper.*;
|
|
import com.tzld.piaoquan.wecom.model.bo.PushMessage;
|
|
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.VideoParam;
|
|
import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
|
|
import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
|
|
import com.tzld.piaoquan.wecom.model.po.*;
|
|
import com.tzld.piaoquan.wecom.model.po.*;
|
|
@@ -73,7 +74,7 @@ public class WeComMessageDataJob {
|
|
Map<Long, List<PushMessage>> historicalTopMap = new HashMap<>();
|
|
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<>();
|
|
Map<String, String> pageMap = new HashMap<>();
|
|
|
|
|
|
@@ -99,7 +100,7 @@ public class WeComMessageDataJob {
|
|
pushMessage.setScore(score);
|
|
pushMessage.setScore(score);
|
|
list.add(pushMessage);
|
|
list.add(pushMessage);
|
|
}
|
|
}
|
|
- Map<Long, List<PushMessage>> groupedMap = list.stream()
|
|
|
|
|
|
+ historicalTopMap = list.stream()
|
|
.collect(Collectors.groupingBy(PushMessage::getStaffId,
|
|
.collect(Collectors.groupingBy(PushMessage::getStaffId,
|
|
Collectors.mapping(pushMessage -> pushMessage,
|
|
Collectors.mapping(pushMessage -> pushMessage,
|
|
Collectors.toList())))
|
|
Collectors.toList())))
|
|
@@ -111,7 +112,6 @@ public class WeComMessageDataJob {
|
|
.sorted(Comparator.comparing(PushMessage::getScore).reversed()) // 根据 score 降序排序
|
|
.sorted(Comparator.comparing(PushMessage::getScore).reversed()) // 根据 score 降序排序
|
|
.collect(Collectors.toList())
|
|
.collect(Collectors.toList())
|
|
));
|
|
));
|
|
- historicalTopMap = groupedMap;
|
|
|
|
|
|
|
|
//保底视频获取
|
|
//保底视频获取
|
|
String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
|
|
String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
|
|
@@ -121,7 +121,7 @@ public class WeComMessageDataJob {
|
|
LarkRobotUtil.sendMessage("保底视频获取异常,请检查" + DateUtil.getThatDayDateString());
|
|
LarkRobotUtil.sendMessage("保底视频获取异常,请检查" + DateUtil.getThatDayDateString());
|
|
throw new RuntimeException();
|
|
throw new RuntimeException();
|
|
}
|
|
}
|
|
- Map<Long, List<Long>> videoMap = new HashMap<>();
|
|
|
|
|
|
+ Map<Long, VideoCombination> videoMap = new HashMap<>();
|
|
for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
|
|
for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
|
|
if (videoParam.getStaffId() == null) {
|
|
if (videoParam.getStaffId() == null) {
|
|
LarkRobotUtil.sendMessage("保底视频获取异常,StaffId为空" + DateUtil.getThatDayDateString());
|
|
LarkRobotUtil.sendMessage("保底视频获取异常,StaffId为空" + DateUtil.getThatDayDateString());
|
|
@@ -129,10 +129,10 @@ public class WeComMessageDataJob {
|
|
}
|
|
}
|
|
//默认组视频不做查询
|
|
//默认组视频不做查询
|
|
if (videoParam.getStaffId() == 0L) {
|
|
if (videoParam.getStaffId() == 0L) {
|
|
- if(videoParam.getVideoIds().size() < MAX_VIDEO_NUM){
|
|
|
|
|
|
+ if (videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
|
|
LarkRobotUtil.sendMessage("默认组视频数量不足" + DateUtil.getThatDayDateString());
|
|
LarkRobotUtil.sendMessage("默认组视频数量不足" + DateUtil.getThatDayDateString());
|
|
}
|
|
}
|
|
- videoMap.put(videoParam.getStaffId(), videoParam.getVideoIds());
|
|
|
|
|
|
+ videoMap.put(videoParam.getStaffId(), combination(videoParam.getVideoIds()));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
|
|
if (CollectionUtils.isEmpty(videoParam.getVideoIds()) || videoParam.getVideoIds().size() < MAX_VIDEO_NUM) {
|
|
@@ -154,7 +154,8 @@ public class WeComMessageDataJob {
|
|
throw new RuntimeException();
|
|
throw new RuntimeException();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- videoMap.put(videoParam.getStaffId(), videoParam.getVideoIds());
|
|
|
|
|
|
+ //重新组合视频id
|
|
|
|
+ videoMap.put(videoParam.getStaffId(), combination(videoParam.getVideoIds()));
|
|
}
|
|
}
|
|
if (!videoMap.containsKey(0L)) {
|
|
if (!videoMap.containsKey(0L)) {
|
|
LarkRobotUtil.sendMessage("保底视频没有默认组,请查看" + guaranteedParam.getDate());
|
|
LarkRobotUtil.sendMessage("保底视频没有默认组,请查看" + guaranteedParam.getDate());
|
|
@@ -163,6 +164,31 @@ public class WeComMessageDataJob {
|
|
this.guaranteedVideoMap = videoMap;
|
|
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")
|
|
@XxlJob("assembleSendMessageJob")
|
|
public ReturnT<String> assembleSendMessage(String param) {
|
|
public ReturnT<String> assembleSendMessage(String param) {
|
|
XxlJobParam xxlJobParam = new XxlJobParam();
|
|
XxlJobParam xxlJobParam = new XxlJobParam();
|
|
@@ -292,21 +318,47 @@ public class WeComMessageDataJob {
|
|
}
|
|
}
|
|
|
|
|
|
private int fillGuaranteedMessages(SendMessage sendMessage, Long staffId, int currentCount) {
|
|
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("组装数据时,保底数据获取异常");
|
|
LarkRobotUtil.sendMessage("组装数据时,保底数据获取异常");
|
|
throw new RuntimeException("保底数据获取异常");
|
|
throw new RuntimeException("保底数据获取异常");
|
|
}
|
|
}
|
|
if (currentCount < MAX_VIDEO_NUM) {
|
|
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;
|
|
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;
|
|
return currentCount;
|