浏览代码

合并冲突

xueyiming 3 月之前
父节点
当前提交
859704161e

+ 1 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/WeComUserService.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.growth.common.service;
 package com.tzld.piaoquan.growth.common.service;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.growth.common.model.bo.GroupSendWeComUserParam;
 import com.tzld.piaoquan.growth.common.model.bo.GroupSendWeComUserParam;
 import com.tzld.piaoquan.growth.common.model.po.Staff;
 import com.tzld.piaoquan.growth.common.model.po.Staff;
 import com.tzld.piaoquan.growth.common.model.po.WeComUser;
 import com.tzld.piaoquan.growth.common.model.po.WeComUser;

+ 88 - 0
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComHistoryDataJob.java

@@ -25,11 +25,13 @@ import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.io.IOException;
 import java.io.IOException;
 import java.util.*;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 import static com.tzld.piaoquan.growth.common.common.constant.MessageConstant.MAX_VIDEO_NUM;
 import static com.tzld.piaoquan.growth.common.common.constant.MessageConstant.MAX_VIDEO_NUM;
@@ -80,6 +82,92 @@ public class WeComHistoryDataJob {
     @Autowired
     @Autowired
     private AttachmentWithMsgResultMapper attachmentWithMsgResultMapper;
     private AttachmentWithMsgResultMapper attachmentWithMsgResultMapper;
 
 
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    private static final String START_TIME_KEY = "start_time_key";
+
+    @XxlJob("saveHistoryMessageJob1")
+    public ReturnT<String> saveHistoryMessageJob1(String param) {
+        Long startTime = (Long) redisTemplate.opsForValue().get(START_TIME_KEY);
+        if (startTime == null) {
+            startTime = DateUtil.getBeforeDayStart(0);
+        }
+        Long endTime = System.currentTimeMillis() / 1000;
+        CorpExample example = new CorpExample();
+        List<Corp> corps = corpMapper.selectByExample(example);
+        if (CollectionUtils.isEmpty(corps)) {
+            return ReturnT.SUCCESS;
+        }
+        for (Corp corp : corps) {
+            selectGroupMsgList(startTime, endTime, corp.getId(), null);
+        }
+        for (Corp corp : corps) {
+            long notSentCount = newSelectAlertHistoryMessage(startTime, endTime, corp.getId(), corp.getName());
+            if (notSentCount == 0) {
+                redisTemplate.opsForValue().set(START_TIME_KEY, endTime, 1, TimeUnit.DAYS);
+            }
+        }
+        return ReturnT.SUCCESS;
+    }
+
+    private long newSelectAlertHistoryMessage(Long startTime, Long endTime, Long corpId, String corpName) {
+        StaffExample staffExample = new StaffExample();
+        List<Staff> staffList = staffMapper.selectByExample(staffExample);
+        ArrayList<Integer> statusList = Lists.newArrayList(0, 1, 2, 3);
+        List<SendDetail> sendDetailList = new ArrayList<>();
+        for (Staff staff : staffList) {
+            SendDetail sendDetail = new SendDetail();
+            sendDetail.setRemark(staff.getRemark());
+            sendDetail.setStaffId(staff.getId());
+            List<Long> countList = new ArrayList<>();
+            for (Integer status : statusList) {
+                SendMsgResultExample example = new SendMsgResultExample();
+                example.createCriteria().andSendTimeBetween(new Date(startTime * 1000), new Date(endTime * 1000))
+                        .andStaffIdEqualTo(staff.getId())
+                        .andStatusEqualTo(status)
+                        .andIsDeleteEqualTo(0);
+                long l = sendMsgResultMapper.countByExample(example);
+                countList.add(l);
+            }
+            sendDetail.setSendCountList(countList);
+            sendDetailList.add(sendDetail);
+        }
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append(corpName).append("\n");
+        long allCount = 0;
+        long notSend = 0;
+        for (SendDetail sendDetail : sendDetailList) {
+            List<Long> sendCountList = sendDetail.getSendCountList();
+            if (CollectionUtils.isEmpty(sendCountList)) {
+                continue;
+            }
+            stringBuilder.append(sendDetail.getRemark());
+            long count = sendCountList.get(0) + sendCountList.get(1) + sendCountList.get(2) + sendCountList.get(3);
+            allCount += count;
+            notSend += sendCountList.get(0);
+            if (count != 0 && sendCountList.get(0) > 0) {
+                LarkRobotUtil.sendMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
+//                if (sendDetail.getStaffId() == 3) {
+//                    LarkRobotUtil.sendTipMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
+//                } else {
+//                    LarkRobotUtil.sendNotPushMessage("<at user_id=\"all\">所有人</at> " + sendDetail.getRemark() + " 存在未发送记录,请检查");
+//                }
+            }
+            stringBuilder.append("总发送数量:").append(count).append("   ");
+            stringBuilder.append("未发送数量:").append(sendCountList.get(0)).append("   ");
+            stringBuilder.append("已发送数量:").append(sendCountList.get(1)).append("   ");
+            stringBuilder.append("不是好友发送失败数量:").append(sendCountList.get(2)).append("   ");
+            stringBuilder.append("已经收到其他群发消息失败发送数量:").append(sendCountList.get(3)).append("   ");
+            stringBuilder.append("\n");
+        }
+        if (allCount > 0) {
+            LarkRobotUtil.sendMessage(stringBuilder.toString());
+            LarkRobotUtil.sendTipMessage(stringBuilder.toString());
+        }
+        return notSend;
+    }
+
 
 
     @XxlJob("saveHistoryMessageJob")
     @XxlJob("saveHistoryMessageJob")
     public ReturnT<String> selectHistoryMessageByDay(String param) {
     public ReturnT<String> selectHistoryMessageByDay(String param) {