|
@@ -66,15 +66,15 @@ public class WeComMessageDataJob {
|
|
|
@Autowired
|
|
|
private CorpMapper corpMapper;
|
|
|
|
|
|
-
|
|
|
//发送小程序标题限制字节数
|
|
|
private static final int MAX_BYTES = 64;
|
|
|
|
|
|
//历史优质视频可推送用户列表
|
|
|
- Map<Long, List<PushMessage>> goodHistoryPushMap = new HashMap<>();
|
|
|
+ Map<Long, List<PushMessage>> historicalTopMap = new HashMap<>();
|
|
|
|
|
|
//保底视频列表
|
|
|
Map<Long, List<Long>> guaranteedVideoMap = new HashMap<>();
|
|
|
+
|
|
|
Map<String, String> pageMap = new HashMap<>();
|
|
|
|
|
|
//初始化操作
|
|
@@ -111,7 +111,7 @@ public class WeComMessageDataJob {
|
|
|
.sorted(Comparator.comparing(PushMessage::getScore).reversed()) // 根据 score 降序排序
|
|
|
.collect(Collectors.toList())
|
|
|
));
|
|
|
- goodHistoryPushMap = groupedMap;
|
|
|
+ historicalTopMap = groupedMap;
|
|
|
|
|
|
//保底视频获取
|
|
|
String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, DateUtil.getThatDayDateString());
|
|
@@ -246,70 +246,84 @@ public class WeComMessageDataJob {
|
|
|
}
|
|
|
List<StaffWithUser> staffWithUserList = staffWithUserMapper.selectByExample(example);
|
|
|
if (CollectionUtils.isEmpty(staffWithUserList)) {
|
|
|
- return null;
|
|
|
+ return Collections.emptyList();
|
|
|
}
|
|
|
List<SendMessage> sendMessageList = new ArrayList<>();
|
|
|
for (StaffWithUser staffWithUser : staffWithUserList) {
|
|
|
- int n = 0;
|
|
|
SendMessage sendMessage = new SendMessage();
|
|
|
- List<PushMessage> list = goodHistoryPushMap.get(staffWithUser.getStaffId());
|
|
|
- if (!CollectionUtils.isEmpty(list)) {
|
|
|
- for (PushMessage pushMessage : list) {
|
|
|
- if (pushMessage.getUserIds().contains(user.getId())) {
|
|
|
- if (n == 0) {
|
|
|
- sendMessage.setVideoId1(pushMessage.getVideoId());
|
|
|
- }
|
|
|
- if (n == 1) {
|
|
|
- sendMessage.setVideoId2(pushMessage.getVideoId());
|
|
|
- }
|
|
|
- if (n == 2) {
|
|
|
- sendMessage.setVideoId3(pushMessage.getVideoId());
|
|
|
- }
|
|
|
- n++;
|
|
|
- if (n >= MAX_VIDEO_NUM) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //保底数据
|
|
|
- List<Long> guaranteedVideoIdList = guaranteedVideoMap.get(staffWithUser.getStaffId());
|
|
|
- if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
|
|
|
- guaranteedVideoIdList = guaranteedVideoMap.get(0L);
|
|
|
- }
|
|
|
- if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
|
|
|
- LarkRobotUtil.sendMessage("组装数据时,保底数据获取异常");
|
|
|
- throw new RuntimeException();
|
|
|
- }
|
|
|
+ int n = fillHistoricalTopMessages(sendMessage, user.getId(), staffWithUser.getStaffId());
|
|
|
if (n < MAX_VIDEO_NUM) {
|
|
|
- for (Long videoId : guaranteedVideoIdList) {
|
|
|
- if (n == 0) {
|
|
|
- sendMessage.setVideoId1(videoId);
|
|
|
- }
|
|
|
- if (n == 1) {
|
|
|
- sendMessage.setVideoId2(videoId);
|
|
|
- }
|
|
|
- if (n == 2) {
|
|
|
- sendMessage.setVideoId3(videoId);
|
|
|
- }
|
|
|
- n++;
|
|
|
- if (n >= MAX_VIDEO_NUM) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 保底数据
|
|
|
+ n = fillGuaranteedMessages(sendMessage, staffWithUser.getStaffId(), n);
|
|
|
}
|
|
|
if (n < MAX_VIDEO_NUM) {
|
|
|
LarkRobotUtil.sendMessage("组装数据失败 user=" + user);
|
|
|
- throw new RuntimeException();
|
|
|
+ throw new RuntimeException("组装数据失败");
|
|
|
}
|
|
|
sendMessage.setCorpId(corpId);
|
|
|
sendMessage.setStaffId(staffWithUser.getStaffId());
|
|
|
sendMessage.setUserId(staffWithUser.getUserId());
|
|
|
sendMessageList.add(sendMessage);
|
|
|
}
|
|
|
+
|
|
|
return sendMessageList;
|
|
|
}
|
|
|
|
|
|
+ private int fillHistoricalTopMessages(SendMessage sendMessage, Long userId, Long staffId) {
|
|
|
+ List<PushMessage> list = historicalTopMap.get(staffId);
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ int n = 0;
|
|
|
+ for (PushMessage pushMessage : list) {
|
|
|
+ if (pushMessage.getUserIds().contains(userId)) {
|
|
|
+ setVideoId(sendMessage, n, pushMessage.getVideoId());
|
|
|
+ n++;
|
|
|
+ if (n >= MAX_VIDEO_NUM) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return n;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int fillGuaranteedMessages(SendMessage sendMessage, Long staffId, int currentCount) {
|
|
|
+ List<Long> guaranteedVideoIdList = guaranteedVideoMap.get(staffId);
|
|
|
+ if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
|
|
|
+ guaranteedVideoIdList = guaranteedVideoMap.get(0L);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(guaranteedVideoIdList)) {
|
|
|
+ LarkRobotUtil.sendMessage("组装数据时,保底数据获取异常");
|
|
|
+ throw new RuntimeException("保底数据获取异常");
|
|
|
+ }
|
|
|
+ if (currentCount < MAX_VIDEO_NUM) {
|
|
|
+ for (Long videoId : guaranteedVideoIdList) {
|
|
|
+ setVideoId(sendMessage, currentCount, videoId);
|
|
|
+ currentCount++;
|
|
|
+ if (currentCount >= MAX_VIDEO_NUM) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return currentCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setVideoId(SendMessage sendMessage, int index, Long videoId) {
|
|
|
+ switch (index) {
|
|
|
+ case 0:
|
|
|
+ sendMessage.setVideoId1(videoId);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ sendMessage.setVideoId2(videoId);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ sendMessage.setVideoId3(videoId);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@XxlJob("pushSendMessageJob")
|
|
|
public ReturnT<String> pushSendMessage(String param) {
|