|
@@ -1,7 +1,9 @@
|
|
|
package com.tzld.piaoquan.wecom.job;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.odps.data.Record;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.tzld.piaoquan.wecom.common.constant.MiniprogramConstant;
|
|
|
import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
|
|
|
import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
|
|
@@ -12,6 +14,7 @@ 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 com.tzld.piaoquan.wecom.utils.page.Page;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -39,7 +42,9 @@ public class WeComMessageDataJob {
|
|
|
|
|
|
//初始化操作
|
|
|
void init() {
|
|
|
- String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", DateUtil.getBeforeDayDateString());
|
|
|
+// String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", DateUtil.getBeforeDayDateString());
|
|
|
+ String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", "20240922");
|
|
|
+
|
|
|
List<Record> recordList = OdpsUtil.getOdpsData(sql);
|
|
|
if (CollectionUtils.isEmpty(recordList)) {
|
|
|
return;
|
|
@@ -54,7 +59,8 @@ public class WeComMessageDataJob {
|
|
|
list.add(pushMessage);
|
|
|
}
|
|
|
goodList = list;
|
|
|
- List<Long> saveVideoIds = 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 -> (Integer) o).map(String::valueOf).map(Long::parseLong).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(saveVideoIds)) {
|
|
|
throw new RuntimeException("保底数据为空");
|
|
|
}
|
|
@@ -72,8 +78,32 @@ public class WeComMessageDataJob {
|
|
|
saveList = saveVideoIds;
|
|
|
}
|
|
|
|
|
|
- public void assemble(){
|
|
|
+ public void assemble() {
|
|
|
+ init();
|
|
|
+ Map<String, List<String>> res = new HashMap<>();
|
|
|
UserExample example = new UserExample();
|
|
|
+ long count = userMapper.countByExample(example);
|
|
|
+ int page = 1;
|
|
|
+ int pageSize = 1000;
|
|
|
+ long totalPageSize = count / pageSize + 1;
|
|
|
+ for (; page <= totalPageSize; page++) {
|
|
|
+ example.setPage(new Page<>(page, pageSize));
|
|
|
+ List<User> userList = userMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(userList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (User user : userList) {
|
|
|
+ String pushKey = getPushKey(user);
|
|
|
+ if (res.containsKey(pushKey)) {
|
|
|
+ res.get(pushKey).add(user.getExternalUserId3rdParty());
|
|
|
+ } else {
|
|
|
+ res.put(pushKey, Lists.newArrayList(user.getExternalUserId3rdParty()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println(res.size());
|
|
|
+ pushMessage(res);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -110,4 +140,44 @@ public class WeComMessageDataJob {
|
|
|
}
|
|
|
return key.toString();
|
|
|
}
|
|
|
+
|
|
|
+ public void pushMessage(Map<String, List<String>> map) {
|
|
|
+ List<JSONObject> pushList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<String>> entry : map.entrySet()) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", "群发名称");
|
|
|
+ JSONArray attachments = new JSONArray();
|
|
|
+ List<Long> videoIdList = Arrays.stream(entry.getKey().split("_")).map(Long::parseLong).collect(Collectors.toList());
|
|
|
+ for (Long videoId : videoIdList) {
|
|
|
+ JSONObject attachment = new JSONObject();
|
|
|
+ attachment.put("msgtype", "miniprogram");
|
|
|
+ MessageAttachmentExample example = new MessageAttachmentExample();
|
|
|
+ example.createCriteria().andMiniprogramVideoIdEqualTo(videoId);
|
|
|
+ List<MessageAttachment> messageAttachmentList = messageAttachmentMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(messageAttachmentList)) {
|
|
|
+ throw new RuntimeException("附件信息查询异常");
|
|
|
+ }
|
|
|
+ MessageAttachment messageAttachment = messageAttachmentList.get(0);
|
|
|
+ JSONObject miniprogram = new JSONObject();
|
|
|
+ miniprogram.put("appid", messageAttachment.getAppid());
|
|
|
+ miniprogram.put("title", messageAttachment.getTitle());
|
|
|
+ miniprogram.put("page", messageAttachment.getPage());
|
|
|
+ miniprogram.put("cover", messageAttachment.getCover());
|
|
|
+ attachment.put("miniprogram", miniprogram);
|
|
|
+ attachments.add(attachment);
|
|
|
+ }
|
|
|
+ jsonObject.put("attachments", attachments);
|
|
|
+ List<List<String>> lists = Lists.partition(entry.getValue(), 10000);
|
|
|
+ for (List<String> list : lists) {
|
|
|
+ JSONObject newJSONObject = new JSONObject();
|
|
|
+ newJSONObject.putAll(jsonObject);
|
|
|
+ JSONObject staff_eu_list = new JSONObject();
|
|
|
+ staff_eu_list.put("staff_ext_id", "员工id");
|
|
|
+ staff_eu_list.put("eu_ext_ids", list);
|
|
|
+ newJSONObject.put("staff_eu_list", staff_eu_list);
|
|
|
+ pushList.add(newJSONObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println(pushList.get(0));
|
|
|
+ }
|
|
|
}
|