Bladeren bron

Merge branch 'dev-xym-update-we-com' of Server/growth-manager into master

xueyiming 2 maanden geleden
bovenliggende
commit
a3a3d2a765

+ 8 - 4
api-module/src/main/java/com/tzld/piaoquan/api/controller/TencentWeComController.java

@@ -233,7 +233,9 @@ public class TencentWeComController {
     @PostMapping("/send/post")
     public String sendPost(@RequestBody SendRequestParam sendRequestParam) throws IOException {
         log.info("sendPost sendRequestParam={}", sendRequestParam);
-        return httpPoolClient.post(sendRequestParam.getUrl(), sendRequestParam.getParam());
+        String res = httpPoolClient.post(sendRequestParam.getUrl(), sendRequestParam.getParam());
+        log.info("sendPost sendRequestParam={}, res={}", sendRequestParam, res);
+        return res;
     }
 
     @GetMapping("/send/post/file")
@@ -244,7 +246,7 @@ public class TencentWeComController {
         byte[] coverDecodedBytes = Base64.getDecoder().decode(cover);
         String targetCover = new String(coverDecodedBytes);
 
-
+        log.info("sendPostFile url={},cover={}", targetUrl, targetCover);
         String filePath = UUID.randomUUID() + ".jpg"; // 临时文件路径
         HttpURLConnection httpUrl = (HttpURLConnection) new URL(targetCover).openConnection();
         httpUrl.connect();
@@ -262,7 +264,7 @@ public class TencentWeComController {
         httpUrl.disconnect();
         File file = new File(filePath);
         String res = httpPoolClient.post(targetUrl, file);
-        log.info("sendPostFile res={}", res);
+        log.info("sendPostFile url={},cover={},res={}", targetUrl, targetCover, res);
         return res;
     }
 
@@ -271,6 +273,8 @@ public class TencentWeComController {
         byte[] decodedBytes = Base64.getDecoder().decode(url);
         String originalString = new String(decodedBytes);
         log.info("sendGet url={}", originalString);
-        return httpPoolClient.get(originalString);
+        String res = httpPoolClient.get(originalString);
+        log.info("sendGet url={} res={}", originalString, res);
+        return res;
     }
 }

+ 21 - 8
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComHistoryDataJob.java

@@ -13,10 +13,7 @@ import com.tzld.piaoquan.growth.common.model.bo.MiniprogramRecord;
 import com.tzld.piaoquan.growth.common.model.bo.SendDetail;
 import com.tzld.piaoquan.growth.common.model.bo.XxlJobParam;
 import com.tzld.piaoquan.growth.common.model.po.*;
-import com.tzld.piaoquan.growth.common.service.HistoryMessageService;
-import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
-import com.tzld.piaoquan.growth.common.service.WeComAccessTokenService;
-import com.tzld.piaoquan.growth.common.service.WeComUserService;
+import com.tzld.piaoquan.growth.common.service.*;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
 import com.tzld.piaoquan.growth.common.utils.LarkRobotUtil;
 import com.tzld.piaoquan.growth.common.utils.MessageUtil;
@@ -87,6 +84,9 @@ public class WeComHistoryDataJob {
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
 
+    @Autowired
+    private WeComSendService weComSendService;
+
     private static final String START_TIME_KEY = "start_time_key";
 
     @XxlJob("saveHistoryMessageJob1")
@@ -124,6 +124,7 @@ public class WeComHistoryDataJob {
 
     private long newSelectAlertHistoryMessage(Long startTime, Long endTime, Long corpId, String corpName) {
         StaffExample staffExample = new StaffExample();
+        staffExample.createCriteria().andCorpIdEqualTo(corpId).andIsDeleteEqualTo(0);
         List<Staff> staffList = staffMapper.selectByExample(staffExample);
         ArrayList<Integer> statusList = Lists.newArrayList(0, 1, 2, 3);
         List<SendDetail> sendDetailList = new ArrayList<>();
@@ -163,7 +164,7 @@ public class WeComHistoryDataJob {
                     LarkRobotUtil.sendTipMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
                 } else {
                     //8点前报警
-                    if(DateUtil.getHourOfDay() < 8){
+                    if (DateUtil.getHourOfDay() < 8) {
                         LarkRobotUtil.sendNotPushMessage("<at user_id=\"all\">所有人</at> " + sendDetail.getRemark() + " 存在未发送记录,请检查");
                     }
                 }
@@ -450,7 +451,11 @@ public class WeComHistoryDataJob {
         if (StringUtils.isNotEmpty(cursor)) {
             param.put("cursor", cursor);
         }
-        return httpPoolClient.post(url, param.toJSONString());
+        if (corpId == 1L) {
+            return httpPoolClient.post(url, param.toJSONString());
+        } else {
+            return weComSendService.sendPost(url, param.toJSONString());
+        }
     }
 
     private List<String> selectGroupMsgTask(String msgId, Long corpId) throws IOException {
@@ -490,7 +495,11 @@ public class WeComHistoryDataJob {
         if (StringUtils.isNotEmpty(cursor)) {
             param.put("cursor", cursor);
         }
-        return httpPoolClient.post(url, param.toJSONString());
+        if (corpId == 1L) {
+            return httpPoolClient.post(url, param.toJSONString());
+        } else {
+            return weComSendService.sendPost(url, param.toJSONString());
+        }
     }
 
     private void delHistoryMessageList(Long startTime, Long endTime, Long corpId, Long staffId) {
@@ -623,7 +632,11 @@ public class WeComHistoryDataJob {
         if (StringUtils.isNotEmpty(cursor)) {
             param.put("cursor", cursor);
         }
-        return httpPoolClient.post(url, param.toJSONString());
+        if (corpId == 1L) {
+            return httpPoolClient.post(url, param.toJSONString());
+        } else {
+            return weComSendService.sendPost(url, param.toJSONString());
+        }
     }
 
     @XxlJob("insetHistoryMessageSourceJob")

+ 123 - 104
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComUserDataJob.java

@@ -7,6 +7,7 @@ import com.tzld.piaoquan.growth.common.dao.mapper.*;
 import com.tzld.piaoquan.growth.common.model.bo.XxlJobParam;
 import com.tzld.piaoquan.growth.common.model.po.*;
 import com.tzld.piaoquan.growth.common.service.WeComAccessTokenService;
+import com.tzld.piaoquan.growth.common.service.WeComSendService;
 import com.tzld.piaoquan.growth.common.service.WeComStaffService;
 import com.tzld.piaoquan.growth.common.service.WeComUserService;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
@@ -65,6 +66,9 @@ public class WeComUserDataJob {
     @Autowired
     private WeComStaffService weComStaffService;
 
+    @Autowired
+    private WeComSendService weComSendService;
+
 
     @XxlJob("updateStaffWithUserJob")
     public ReturnT<String> updateStaffWithUser(String param) {
@@ -181,7 +185,11 @@ public class WeComUserDataJob {
         if (StringUtils.isNotEmpty(cursor)) {
             param.put("cursor", cursor);
         }
-        return httpPoolClient.post(url, param.toJSONString());
+        if (corpId == 1L) {
+            return httpPoolClient.post(url, param.toJSONString());
+        } else {
+            return weComSendService.sendPost(url, param.toJSONString());
+        }
     }
 
     @XxlJob("insertStaffWithUserJob")
@@ -237,7 +245,12 @@ public class WeComUserDataJob {
     public List<String> getUserList(String userId, Long corpId) throws IOException {
         String weComAccessToken = weComAccessTokenService.getWeComAccessToken(corpId);
         String url = String.format(GET_WE_COM_EXTERNAL_CONTACT_LIST + "?access_token=%s&userid=%s", weComAccessToken, userId);
-        String res = httpPoolClient.get(url);
+        String res;
+        if (corpId == 1L) {
+            res = httpPoolClient.get(url);
+        } else {
+            res = weComSendService.sendGet(url);
+        }
         JSONObject jsonObject = JSONObject.parseObject(res);
         Integer errcode = jsonObject.getInteger("errcode");
         if (errcode == 0) {
@@ -248,6 +261,7 @@ public class WeComUserDataJob {
 
     @XxlJob("statisticsUserCountJob")
     public ReturnT<String> statisticsUserCount(String param) {
+        refreshTag();
         StaffExample staffExample = new StaffExample();
         List<Staff> staffList = staffMapper.selectByExample(staffExample);
         String date;
@@ -345,116 +359,121 @@ public class WeComUserDataJob {
         return result;
     }
 
-    @XxlJob("getUserTagJob")
-    public ReturnT<String> getUserTag(String param) {
+//    @XxlJob("getUserTagJob")
+//    public ReturnT<String> getUserTag(String param) {
+//        try {
+//            refreshTag();
+//            XxlJobParam xxlJobParam = new XxlJobParam();
+//            if (StringUtils.isNotEmpty(param)) {
+//                xxlJobParam = JSONObject.parseObject(param, XxlJobParam.class);
+//            }
+//            CorpExample corpExample = new CorpExample();
+//            CorpExample.Criteria corpCriteria = corpExample.createCriteria();
+//            if (xxlJobParam.getCorpId() != null) {
+//                corpCriteria.andIdEqualTo(xxlJobParam.getCorpId());
+//            }
+//            List<Corp> corps = corpMapper.selectByExample(corpExample);
+//            for (Corp corp : corps) {
+//                StaffExample staffExample = new StaffExample();
+//                StaffExample.Criteria staffCriteria = staffExample.createCriteria();
+//                staffCriteria.andCorpIdEqualTo(corp.getId());
+//                List<Long> staffIds = new ArrayList<>();
+//                if (xxlJobParam.getStaffId() != null) {
+//                    staffIds.add(xxlJobParam.getStaffId());
+//                }
+//                if (!CollectionUtils.isEmpty(xxlJobParam.getStaffIds())) {
+//                    staffIds.addAll(xxlJobParam.getStaffIds());
+//                }
+//                if (!CollectionUtils.isEmpty(staffIds)) {
+//                    staffCriteria.andIdIn(staffIds);
+//                }
+//                List<Staff> staffList = staffMapper.selectByExample(staffExample);
+//                for (Staff staff : staffList) {
+//                    List<String> existExternalUserIds = getUserList(staff.getCarrierId(), corp.getId());
+//                    for (String externalUserId : existExternalUserIds) {
+//                        JSONObject userDetail = weComUserService.getUserDetail(externalUserId, corp.getId());
+//                        JSONObject externalContact = userDetail.getJSONObject("external_contact");
+//                        JSONArray followUserList = userDetail.getJSONArray("follow_user");
+//                        Long createAt = null;
+//                        for (int i = 0; i < followUserList.size(); i++) {
+//                            JSONObject followUser = followUserList.getJSONObject(i);
+//                            if (createAt == null) {
+//                                createAt = followUser.getLong("createtime");
+//                            } else {
+//                                createAt = Math.min(createAt, followUser.getLong("createtime"));
+//                            }
+//                            JSONArray tagIds = followUser.getJSONArray("tags");
+//                            if (!CollectionUtils.isEmpty(tagIds)) {
+//                                List<String> tagIdList = new ArrayList<>();
+//                                for (int j = 0; j < tagIds.size(); j++) {
+//                                    JSONObject jsonObject = tagIds.getJSONObject(j);
+//                                    tagIdList.add(jsonObject.getString("tag_id"));
+//                                }
+//                                for (String tagId : tagIdList) {
+//                                    TagExample example = new TagExample();
+//                                    example.createCriteria().andTagIdEqualTo(tagId);
+//                                    List<Tag> tags = tagMapper.selectByExample(example);
+//                                    if (!CollectionUtils.isEmpty(tags)) {
+//                                        Long userId = weComUserMapper.selectIdByExternalUserId(externalUserId);
+//                                        userId = addAndUpdateUser(externalContact, corp.getId(), externalUserId,
+//                                                createAt, staff.getId(), userId);
+//                                        Tag tag = tags.get(0);
+//                                        UserWithTag userWithTag = new UserWithTag();
+//                                        userWithTag.setUserId(userId);
+//                                        userWithTag.setTagId(tag.getId());
+//                                        weComUserService.addUserWithTag(userWithTag);
+//                                    }
+//                                }
+//                            }
+//                        }
+//                    }
+//                }
+//            }
+//        } catch (Exception e) {
+//            log.error("getUserTag error", e);
+//        }
+//
+//        return ReturnT.SUCCESS;
+//
+//    }
+
+
+    public void refreshTag() {
         try {
-            refreshTag();
-            XxlJobParam xxlJobParam = new XxlJobParam();
-            if (StringUtils.isNotEmpty(param)) {
-                xxlJobParam = JSONObject.parseObject(param, XxlJobParam.class);
-            }
-            CorpExample corpExample = new CorpExample();
-            CorpExample.Criteria corpCriteria = corpExample.createCriteria();
-            if (xxlJobParam.getCorpId() != null) {
-                corpCriteria.andIdEqualTo(xxlJobParam.getCorpId());
-            }
-            List<Corp> corps = corpMapper.selectByExample(corpExample);
-            for (Corp corp : corps) {
-                StaffExample staffExample = new StaffExample();
-                StaffExample.Criteria staffCriteria = staffExample.createCriteria();
-                staffCriteria.andCorpIdEqualTo(corp.getId());
-                List<Long> staffIds = new ArrayList<>();
-                if (xxlJobParam.getStaffId() != null) {
-                    staffIds.add(xxlJobParam.getStaffId());
-                }
-                if (!CollectionUtils.isEmpty(xxlJobParam.getStaffIds())) {
-                    staffIds.addAll(xxlJobParam.getStaffIds());
-                }
-                if (!CollectionUtils.isEmpty(staffIds)) {
-                    staffCriteria.andIdIn(staffIds);
-                }
-                List<Staff> staffList = staffMapper.selectByExample(staffExample);
-                for (Staff staff : staffList) {
-                    List<String> existExternalUserIds = getUserList(staff.getCarrierId(), corp.getId());
-                    for (String externalUserId : existExternalUserIds) {
-                        JSONObject userDetail = weComUserService.getUserDetail(externalUserId, corp.getId());
-                        JSONObject externalContact = userDetail.getJSONObject("external_contact");
-                        JSONArray followUserList = userDetail.getJSONArray("follow_user");
-                        Long createAt = null;
-                        for (int i = 0; i < followUserList.size(); i++) {
-                            JSONObject followUser = followUserList.getJSONObject(i);
-                            if (createAt == null) {
-                                createAt = followUser.getLong("createtime");
-                            } else {
-                                createAt = Math.min(createAt, followUser.getLong("createtime"));
-                            }
-                            JSONArray tagIds = followUser.getJSONArray("tags");
-                            if (!CollectionUtils.isEmpty(tagIds)) {
-                                List<String> tagIdList = new ArrayList<>();
-                                for (int j = 0; j < tagIds.size(); j++) {
-                                    JSONObject jsonObject = tagIds.getJSONObject(j);
-                                    tagIdList.add(jsonObject.getString("tag_id"));
-                                }
-                                for (String tagId : tagIdList) {
-                                    TagExample example = new TagExample();
-                                    example.createCriteria().andTagIdEqualTo(tagId);
-                                    List<Tag> tags = tagMapper.selectByExample(example);
-                                    if (!CollectionUtils.isEmpty(tags)) {
-                                        Long userId = weComUserMapper.selectIdByExternalUserId(externalUserId);
-                                        userId = addAndUpdateUser(externalContact, corp.getId(), externalUserId,
-                                                createAt, staff.getId(), userId);
-                                        Tag tag = tags.get(0);
-                                        UserWithTag userWithTag = new UserWithTag();
-                                        userWithTag.setUserId(userId);
-                                        userWithTag.setTagId(tag.getId());
-                                        weComUserService.addUserWithTag(userWithTag);
-                                    }
-                                }
-                            }
+            String weComAccessToken = weComAccessTokenService.getWeComAccessToken(1L);
+            String url = String.format(POST_CORP_TAG_LIST + "?access_token=%s", weComAccessToken);
+            String res = httpPoolClient.post(url);
+            JSONObject jsonObject = JSONObject.parseObject(res);
+            Integer errcode = jsonObject.getInteger("errcode");
+            if (errcode == 0) {
+                JSONArray tagGroup = jsonObject.getJSONArray("tag_group");
+                if (!tagGroup.isEmpty()) {
+                    for (int i = 0; i < tagGroup.size(); i++) {
+                        JSONObject tagGroupJSONObject = tagGroup.getJSONObject(i);
+                        String groupId = tagGroupJSONObject.getString("group_id");
+                        String groupName = tagGroupJSONObject.getString("group_name");
+                        JSONArray tags = tagGroupJSONObject.getJSONArray("tag");
+                        if (tags.isEmpty()) {
+                            continue;
+                        }
+                        for (int j = 0; j < tags.size(); j++) {
+                            JSONObject tagsJSONObject = tags.getJSONObject(j);
+                            String tagId = tagsJSONObject.getString("id");
+                            String tagName = tagsJSONObject.getString("name");
+                            Tag tag = new Tag();
+                            tag.setTagGroupId(groupId);
+                            tag.setTagGroupName(groupName);
+                            tag.setTagId(tagId);
+                            tag.setTagName(tagName);
+                            addAndUpdateTag(tag);
                         }
                     }
                 }
             }
         } catch (Exception e) {
-            log.error("getUserTag error", e);
+            log.error("refreshTag error", e);
         }
 
-        return ReturnT.SUCCESS;
-
-    }
-
-
-    public void refreshTag() throws IOException {
-        String weComAccessToken = weComAccessTokenService.getWeComAccessToken(1L);
-        String url = String.format(POST_CORP_TAG_LIST + "?access_token=%s", weComAccessToken);
-        String res = httpPoolClient.post(url);
-        JSONObject jsonObject = JSONObject.parseObject(res);
-        Integer errcode = jsonObject.getInteger("errcode");
-        if (errcode == 0) {
-            JSONArray tagGroup = jsonObject.getJSONArray("tag_group");
-            if (!tagGroup.isEmpty()) {
-                for (int i = 0; i < tagGroup.size(); i++) {
-                    JSONObject tagGroupJSONObject = tagGroup.getJSONObject(i);
-                    String groupId = tagGroupJSONObject.getString("group_id");
-                    String groupName = tagGroupJSONObject.getString("group_name");
-                    JSONArray tags = tagGroupJSONObject.getJSONArray("tag");
-                    if (tags.isEmpty()) {
-                        continue;
-                    }
-                    for (int j = 0; j < tags.size(); j++) {
-                        JSONObject tagsJSONObject = tags.getJSONObject(j);
-                        String tagId = tagsJSONObject.getString("id");
-                        String tagName = tagsJSONObject.getString("name");
-                        Tag tag = new Tag();
-                        tag.setTagGroupId(groupId);
-                        tag.setTagGroupName(groupName);
-                        tag.setTagId(tagId);
-                        tag.setTagName(tagName);
-                        addAndUpdateTag(tag);
-                    }
-                }
-            }
-        }
     }
 
     private void addAndUpdateTag(Tag tag) {