Browse Source

Merge branch 'dev-xym-log' of Server/we-com-manage into master

xueyiming 7 months ago
parent
commit
1949b7e96a

+ 31 - 16
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComHistoryDataJob.java

@@ -5,11 +5,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
 import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
 import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
+import com.tzld.piaoquan.wecom.dao.mapper.StaffWithUserMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
 import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
-import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
-import com.tzld.piaoquan.wecom.model.po.HistoryMessageExample;
-import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
+import com.tzld.piaoquan.wecom.model.bo.StaffWithUserParam;
+import com.tzld.piaoquan.wecom.model.po.*;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
@@ -22,6 +22,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
@@ -56,29 +57,35 @@ public class WeComHistoryDataJob {
     @Autowired
     private MessageAttachmentService messageAttachmentService;
 
+    @Autowired
+    private StaffWithUserMapper staffWithUserMapper;
+
     @XxlJob("saveHistoryMessageJob")
     public ReturnT<String> selectHistoryMessageByDay(String param) {
-        long endTime;
-        long startTime;
-        if (StringUtils.isEmpty(param)) {
+        StaffWithUserParam staffWithUserParam = new StaffWithUserParam();
+        if (StringUtils.isNotEmpty(param)) {
+            staffWithUserParam = JSONObject.parseObject(param, StaffWithUserParam.class);
+        }
+        if (staffWithUserParam.getStartTime() == null) {
             HistoryMessageExample example = new HistoryMessageExample();
             example.setOrderByClause("create_time desc");
             example.setPage(new Page<>(1, 1));
             List<HistoryMessage> historyMessages = historyMessageMapper.selectByExample(example);
-            startTime = historyMessages.get(0).getCreateTime().getTime() / 1000;
-            endTime = System.currentTimeMillis() / 1000;
-        } else {
-            String[] split = param.split(",");
-            startTime = Long.parseLong(split[0]);
-            endTime = Long.parseLong(split[1]);
+            staffWithUserParam.setStartTime(historyMessages.get(0).getCreateTime().getTime() / 1000);
+        }
+        if (staffWithUserParam.getEndTime() == null) {
+            staffWithUserParam.setEndTime(System.currentTimeMillis() / 1000);
         }
+        Long startTime = staffWithUserParam.getStartTime();
+        Long endTime = staffWithUserParam.getEndTime();
+
         for (; startTime < endTime; startTime += TimeConstant.DAY) {
-            selectHistoryMessage(startTime, Math.min(startTime + TimeConstant.DAY, endTime));
+            selectHistoryMessage(startTime, Math.min(startTime + TimeConstant.DAY, endTime), staffWithUserParam.getStaffId());
         }
         return ReturnT.SUCCESS;
     }
 
-    public void selectHistoryMessage(Long startTime, Long endTime) {
+    public void selectHistoryMessage(Long startTime, Long endTime, Long staffId) {
         try {
             Integer total = getHistoryDataTotal(startTime, endTime);
             if (total == null || total == 0) {
@@ -131,7 +138,7 @@ public class WeComHistoryDataJob {
                         }
                         allExternalUserList.addAll(externalUserList);
                     }
-                    insertHistoryMessageList(allExternalUserList, miniprogramRecordList, createdAt);
+                    insertHistoryMessageList(allExternalUserList, miniprogramRecordList, createdAt, staffId);
                     messageAttachmentService.addMiniprogram(messageAttachmentList);
                 }
             }
@@ -141,13 +148,21 @@ public class WeComHistoryDataJob {
     }
 
 
-    private void insertHistoryMessageList(List<String> allExternalUserList, List<MiniprogramRecord> miniprogramRecordList, Date sendTime) {
+    private void insertHistoryMessageList(List<String> allExternalUserList, List<MiniprogramRecord> miniprogramRecordList, Date sendTime, Long staffId) {
         List<HistoryMessage> historyMessageList = new ArrayList<>();
         for (String externalUserId3rdParty : allExternalUserList) {
             Long userId = userMapper.selectIdByExternalUserId3rdParty(externalUserId3rdParty);
             if (userId == null) {
                 continue;
             }
+            if (staffId != null) {
+                StaffWithUserExample example = new StaffWithUserExample();
+                example.createCriteria().andStaffIdEqualTo(staffId).andUserIdEqualTo(userId);
+                List<StaffWithUser> staffWithUserList = staffWithUserMapper.selectByExample(example);
+                if (staffWithUserList == null) {
+                    continue;
+                }
+            }
             for (MiniprogramRecord miniprogramRecord : miniprogramRecordList) {
                 HistoryMessage historyMessage = new HistoryMessage();
                 historyMessage.setSendTime(sendTime);

+ 29 - 21
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComUserDataJob.java

@@ -6,6 +6,7 @@ import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
 import com.tzld.piaoquan.wecom.dao.mapper.StaffMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.StaffWithUserMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
+import com.tzld.piaoquan.wecom.model.bo.StaffWithUserParam;
 import com.tzld.piaoquan.wecom.model.po.*;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
@@ -49,20 +50,24 @@ public class WeComUserDataJob {
 
     @XxlJob("insertStaffWithUserJob")
     public ReturnT<String> insertStaffWithUser(String param) {
-        long endTime;
-        long startTime;
-        if (StringUtils.isEmpty(param)) {
-            startTime = 1720540800L;
-            endTime = System.currentTimeMillis() / 1000;
-        } else {
-            String[] split = param.split(",");
-            startTime = Long.parseLong(split[0]);
-            endTime = Long.parseLong(split[1]);
+        StaffWithUserParam staffWithUserParam = new StaffWithUserParam();
+        if (StringUtils.isNotEmpty(param)) {
+            staffWithUserParam = JSONObject.parseObject(param, StaffWithUserParam.class);
+        }
+        if (staffWithUserParam.getStartTime() == null) {
+            staffWithUserParam.setStartTime(1720540800L);
+        }
+        if (staffWithUserParam.getEndTime() == null) {
+            staffWithUserParam.setEndTime(System.currentTimeMillis() / 1000);
         }
         StaffExample example = new StaffExample();
+        StaffExample.Criteria criteria = example.createCriteria();
+        if (staffWithUserParam.getStaffId() != null) {
+            criteria.andIdEqualTo(staffWithUserParam.getStaffId());
+        }
         List<Staff> staffList = staffMapper.selectByExample(example);
         for (Staff staff : staffList) {
-            insertAllUser(startTime, endTime, staff);
+            insertAllUser(staffWithUserParam.getStartTime(), staffWithUserParam.getEndTime(), staff);
         }
         return ReturnT.SUCCESS;
     }
@@ -144,25 +149,28 @@ public class WeComUserDataJob {
 
     @XxlJob("updateStaffWithUserJob")
     public ReturnT<String> updateStaffWithUser(String param) {
-
-        long endTime;
-        long startTime;
-        if (StringUtils.isEmpty(param)) {
+        StaffWithUserParam staffWithUserParam = new StaffWithUserParam();
+        if (StringUtils.isNotEmpty(param)) {
+            staffWithUserParam = JSONObject.parseObject(param, StaffWithUserParam.class);
+        }
+        if (staffWithUserParam.getStartTime() == null) {
             UserExample userExample = new UserExample();
             userExample.setOrderByClause("create_time desc");
             userExample.setPage(new Page<>(1, 1));
             List<User> userList = userMapper.selectByExample(userExample);
-            startTime = userList.get(0).getCreateTime().getTime() / 1000 - 2L * TimeConstant.HOUR;
-            endTime = System.currentTimeMillis() / 1000;
-        } else {
-            String[] split = param.split(",");
-            startTime = Long.parseLong(split[0]);
-            endTime = Long.parseLong(split[1]);
+            staffWithUserParam.setStartTime(userList.get(0).getCreateTime().getTime() / 1000 - 2L * TimeConstant.HOUR);
+        }
+        if (staffWithUserParam.getEndTime() == null) {
+            staffWithUserParam.setEndTime(System.currentTimeMillis() / 1000);
         }
         StaffExample example = new StaffExample();
+        StaffExample.Criteria criteria = example.createCriteria();
+        if (staffWithUserParam.getStaffId() != null) {
+            criteria.andIdEqualTo(staffWithUserParam.getStaffId());
+        }
         List<Staff> staffList = staffMapper.selectByExample(example);
         for (Staff staff : staffList) {
-            updateUser(startTime, endTime, staff);
+            updateUser(staffWithUserParam.getStartTime(), staffWithUserParam.getEndTime(), staff);
         }
         return ReturnT.SUCCESS;
     }

+ 13 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/model/bo/StaffWithUserParam.java

@@ -0,0 +1,13 @@
+package com.tzld.piaoquan.wecom.model.bo;
+
+import lombok.Data;
+
+@Data
+public class StaffWithUserParam {
+
+    private Long startTime;
+
+    private Long endTime;
+
+    private Long staffId;
+}