|
@@ -1,10 +1,16 @@
|
|
|
package com.tzld.piaoquan.wecom.job;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.odps.data.Record;
|
|
|
import com.tzld.piaoquan.wecom.common.constant.MiniprogramConstant;
|
|
|
+import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
|
|
|
import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
|
import com.tzld.piaoquan.wecom.model.bo.PushMessage;
|
|
|
+import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
|
|
|
+import com.tzld.piaoquan.wecom.model.po.MessageAttachmentExample;
|
|
|
import com.tzld.piaoquan.wecom.model.po.User;
|
|
|
+import com.tzld.piaoquan.wecom.model.po.UserExample;
|
|
|
+import com.tzld.piaoquan.wecom.utils.DateUtil;
|
|
|
import com.tzld.piaoquan.wecom.utils.OdpsUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -17,10 +23,12 @@ import java.util.stream.Collectors;
|
|
|
@Component
|
|
|
public class WeComMessageDataJob {
|
|
|
|
|
|
-
|
|
|
@Autowired
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MessageAttachmentMapper messageAttachmentMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
@@ -29,8 +37,10 @@ public class WeComMessageDataJob {
|
|
|
List<PushMessage> goodList = new ArrayList<>();
|
|
|
List<Long> saveList = new ArrayList<>();
|
|
|
|
|
|
+ //初始化操作
|
|
|
void init() {
|
|
|
- List<Record> recordList = OdpsUtil.getOdpsData("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = 20240922;");
|
|
|
+ String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", DateUtil.getBeforeDayDateString());
|
|
|
+ List<Record> recordList = OdpsUtil.getOdpsData(sql);
|
|
|
if (CollectionUtils.isEmpty(recordList)) {
|
|
|
return;
|
|
|
}
|
|
@@ -38,34 +48,49 @@ public class WeComMessageDataJob {
|
|
|
for (Record record : recordList) {
|
|
|
PushMessage pushMessage = new PushMessage();
|
|
|
Long videoId = Long.parseLong((String) record.get(0));
|
|
|
- StringBuilder stringBuilder = new StringBuilder((String) record.get(1));
|
|
|
- stringBuilder.delete(0, 1);
|
|
|
- stringBuilder.delete(stringBuilder.length() - 1, stringBuilder.length());
|
|
|
- Set<Long> userIds = Arrays.stream(stringBuilder.toString().split(",")).map(String::trim).map(Long::parseLong).collect(Collectors.toSet());
|
|
|
+ Set<Long> userIds = new HashSet<>(JSONObject.parseArray((String) record.get(1), Long.class));
|
|
|
pushMessage.setVideoId(videoId);
|
|
|
pushMessage.setUserIds(userIds);
|
|
|
list.add(pushMessage);
|
|
|
}
|
|
|
goodList = list;
|
|
|
- saveList = Objects.requireNonNull(redisTemplate.opsForList().range(MiniprogramConstant.GUARANTEED_MINIPROGRAM_KEY, 0, 2)).stream().map(o -> (Long) o).collect(Collectors.toList());
|
|
|
+ List<Long> saveVideoIds = Objects.requireNonNull(redisTemplate.opsForList().range(MiniprogramConstant.GUARANTEED_MINIPROGRAM_KEY, 0, 2)).stream().map(o -> (Long) o).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(saveVideoIds)) {
|
|
|
+ throw new RuntimeException("保底数据为空");
|
|
|
+ }
|
|
|
+ MessageAttachmentExample example = new MessageAttachmentExample();
|
|
|
+ example.createCriteria().andMiniprogramVideoIdIn(saveVideoIds);
|
|
|
+ List<MessageAttachment> messageAttachmentList = messageAttachmentMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(messageAttachmentList) || messageAttachmentList.size() < saveVideoIds.size()) {
|
|
|
+ throw new RuntimeException("保底数据获取失败");
|
|
|
+ }
|
|
|
+ for (MessageAttachment messageAttachment : messageAttachmentList) {
|
|
|
+ if (messageAttachment.getUpdateTime().compareTo(DateUtil.getThatDayDate()) < 0) {
|
|
|
+ throw new RuntimeException("保底数据不是最新的");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveList = saveVideoIds;
|
|
|
}
|
|
|
|
|
|
+ public void assemble(){
|
|
|
+ UserExample example = new UserExample();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public String getPushKey(User user) {
|
|
|
- int i = 0;
|
|
|
+ int n = 0;
|
|
|
StringBuilder key = new StringBuilder();
|
|
|
for (PushMessage pushMessage : goodList) {
|
|
|
if (pushMessage.getUserIds().contains(user.getId())) {
|
|
|
if (key.length() == 0) {
|
|
|
key.append(pushMessage.getVideoId());
|
|
|
- i++;
|
|
|
+ n++;
|
|
|
} else {
|
|
|
key.append("_");
|
|
|
key.append(pushMessage.getVideoId());
|
|
|
}
|
|
|
- i++;
|
|
|
- if (i > sum) {
|
|
|
+ n++;
|
|
|
+ if (n > sum) {
|
|
|
return key.toString();
|
|
|
}
|
|
|
}
|
|
@@ -73,13 +98,13 @@ public class WeComMessageDataJob {
|
|
|
for (Long videoId : saveList) {
|
|
|
if (key.length() == 0) {
|
|
|
key.append(videoId);
|
|
|
- i++;
|
|
|
+ n++;
|
|
|
} else {
|
|
|
key.append("_");
|
|
|
key.append(videoId);
|
|
|
}
|
|
|
- i++;
|
|
|
- if (i > sum) {
|
|
|
+ n++;
|
|
|
+ if (n > sum) {
|
|
|
return key.toString();
|
|
|
}
|
|
|
}
|