ソースを参照

手动处理特殊情况

xueyiming 4 ヶ月 前
コミット
ac71c81d36

+ 2 - 2
api-module/src/main/resources/application-test.properties

@@ -12,6 +12,6 @@ xxl.job.admin.addresses=http://xxl-job-test-internal.piaoquantv.com/xxl-job-admi
 
 small_page_url=https://testapi.piaoquantv.com
 
-pushMessage.callback.topic=3rd_party_push_message_callback_prod
-pushMessage.callback.groupId=GID_3RD_PARTY_PUSH_MESSAGE_CALLBACK_PROD
+pushMessage.callback.topic=3rd_party_push_message_callback_prod_test
+pushMessage.callback.groupId=GID_3RD_PARTY_PUSH_MESSAGE_CALLBACK_PROD_TEST
 pushMessage.callback.tag=mini

+ 5 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/dao/mapper/WeComUserMapper.java

@@ -36,4 +36,9 @@ public interface WeComUserMapper {
     Long selectIdByExternalUserId(String externalUserId);
 
     void insertList(@Param("list") List<WeComUser> list);
+
+    List<WeComUser> selectUserList(@Param("staffId") Long staffId,
+                        @Param("groupMsgDisabled") byte groupMsgDisabled,
+                        @Param("pageNum") Integer pageNum,
+                        @Param("pageSize") Integer pageSize);
 }

+ 10 - 0
common-module/src/main/resources/mapper/WeComUserMapper.xml

@@ -435,4 +435,14 @@
             )
         </foreach>
     </insert>
+
+
+    <select id="selectUserList" resultType="com.tzld.piaoquan.growth.common.model.po.WeComUser">
+        select t1.*
+        from we_com_user t1
+                 left join we_com_staff_with_user t2 on t1.id = t2.user_id
+        where t1.group_msg_disabled = #{groupMsgDisabled,jdbcType=TINYINT}
+          and t2.staff_id = #{staffId,jdbcType=BIGINT} and t2.is_delete = 0
+            limit #{pageNum}, #{pageSize}
+    </select>
 </mapper>

+ 122 - 86
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComMessageDataJob.java

@@ -81,44 +81,44 @@ public class WeComMessageDataJob {
     //初始化操作
     private void init(List<Long> staffIds) {
         List<PushMessage> list = new ArrayList<>();
-        try {
-            //历史优质视频获取分页获取
-            String countSql = String.format("SELECT count(*) FROM loghubods.history_good_video_can_push_user_list where dt = %s;",
-                    DateUtil.getBeforeDayDateString());
-            List<Record> countData = OdpsUtil.getOdpsData(countSql);
-            int size = 10;
-            if (!CollectionUtils.isEmpty(countData)) {
-                int count = Integer.parseInt((String) countData.get(0).get(0));
-                if (count > 0) {
-                    List<Record> dataList = new ArrayList<>();
-                    for (int i = 0; i < count; i += 10) {
-                        String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s order by score desc limit %s,%s;",
-                                DateUtil.getBeforeDayDateString(), i, size);
-                        List<Record> data = OdpsUtil.getOdpsData(sql);
-                        if (!CollectionUtils.isEmpty(data)) {
-                            dataList.addAll(data);
-                        }
-                    }
-                    for (Record record : dataList) {
-                        PushMessage pushMessage = new PushMessage();
-                        Long videoId = Long.parseLong((String) record.get(0));
-                        Set<Long> userIds = new HashSet<>(JSONObject.parseArray((String) record.get(1), Long.class));
-                        Long staffId = Long.parseLong((String) record.get(2));
-                        Double score = Double.parseDouble((String) record.get(3));
-                        pushMessage.setVideoId(videoId);
-                        pushMessage.setUserIds(userIds);
-                        pushMessage.setStaffId(staffId);
-                        pushMessage.setScore(score);
-                        list.add(pushMessage);
-                    }
-                }
-            }
-        } catch (Exception e) {
-            log.error("history good video error", e);
-        }
+//        try {
+//            //历史优质视频获取分页获取
+//            String countSql = String.format("SELECT count(*) FROM loghubods.history_good_video_can_push_user_list where dt = %s;",
+//                    DateUtil.getBeforeDayDateString());
+//            List<Record> countData = OdpsUtil.getOdpsData(countSql);
+//            int size = 10;
+//            if (!CollectionUtils.isEmpty(countData)) {
+//                int count = Integer.parseInt((String) countData.get(0).get(0));
+//                if (count > 0) {
+//                    List<Record> dataList = new ArrayList<>();
+//                    for (int i = 0; i < count; i += 10) {
+//                        String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s order by score desc limit %s,%s;",
+//                                DateUtil.getBeforeDayDateString(), i, size);
+//                        List<Record> data = OdpsUtil.getOdpsData(sql);
+//                        if (!CollectionUtils.isEmpty(data)) {
+//                            dataList.addAll(data);
+//                        }
+//                    }
+//                    for (Record record : dataList) {
+//                        PushMessage pushMessage = new PushMessage();
+//                        Long videoId = Long.parseLong((String) record.get(0));
+//                        Set<Long> userIds = new HashSet<>(JSONObject.parseArray((String) record.get(1), Long.class));
+//                        Long staffId = Long.parseLong((String) record.get(2));
+//                        Double score = Double.parseDouble((String) record.get(3));
+//                        pushMessage.setVideoId(videoId);
+//                        pushMessage.setUserIds(userIds);
+//                        pushMessage.setStaffId(staffId);
+//                        pushMessage.setScore(score);
+//                        list.add(pushMessage);
+//                    }
+//                }
+//            }
+//        } catch (Exception e) {
+//            log.error("history good video error", e);
+//        }
 
         if (CollectionUtils.isEmpty(list)) {
-            LarkRobotUtil.sendMessage("历史优质视频为空");
+//            LarkRobotUtil.sendMessage("历史优质视频为空");
         } else {
             historicalTopMap = list.stream()
                     .collect(Collectors.groupingBy(PushMessage::getStaffId,
@@ -272,6 +272,27 @@ public class WeComMessageDataJob {
         return ReturnT.SUCCESS;
     }
 
+
+    public void specialAssembleSendMessage(Long staffId, Integer pageNum) {
+        List<Long> staffIds = new ArrayList<>();
+        staffIds.add(staffId);
+        init(staffIds);
+        List<WeComUser> weComUserList = weComUserMapper.selectUserList(staffId, (byte) 1, pageNum, 200);
+        //落库逻辑
+        List<SendMessage> allSeneMessageList = new ArrayList<>();
+        for (WeComUser weComUser : weComUserList) {
+            List<SendMessage> sendMessageList = getSendMessage(weComUser, staffIds, 1L);
+            if (CollectionUtils.isEmpty(sendMessageList)) {
+                continue;
+            }
+            allSeneMessageList.addAll(sendMessageList);
+        }
+        sendMessageMapper.insertList(allSeneMessageList);
+
+        //组装好当天要发送的消息后  记录时间
+        saveGuaranteedVideoIdList(staffIds);
+    }
+
     private void saveGuaranteedVideoIdList(List<Long> staffIds) {
         GuaranteedParam guaranteedParam = messageAttachmentService.getGuaranteedVideo(DateUtil.getThatDayDateString());
         if (guaranteedParam == null || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
@@ -476,7 +497,7 @@ public class WeComMessageDataJob {
         sendMessage.setIsSend(0);
         sendMessage.setCreateTime(DateUtil.getThatDayDate());
         List<String> sendUserList = sendMessageMapper.selectExternalUserId(sendMessage);
-        boolean flag = pushMessage(sendUserList, sendMessage, true);
+        boolean flag = pushMessage(sendUserList, sendMessage, true, false, false);
         if (flag) {
             SendMessage updateSendMessage = new SendMessage();
             updateSendMessage.setIsSend(1);
@@ -491,7 +512,8 @@ public class WeComMessageDataJob {
         }
     }
 
-    private boolean pushMessage(List<String> sendUserList, SendMessage sendMessage, boolean hasLink) {
+    private boolean pushMessage(List<String> sendUserList, SendMessage sendMessage,
+                                boolean hasLink, boolean hasImage, boolean hasMiniprogram) {
         List<JSONObject> pushList = new ArrayList<>();
         StaffExample staffExample = new StaffExample();
         staffExample.createCriteria().andIdEqualTo(sendMessage.getStaffId());
@@ -500,66 +522,80 @@ public class WeComMessageDataJob {
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("chat_type", "single");
         JSONObject text = new JSONObject();
-        String content = messageService.getMessageText();
-        text.put("content", content);
+//        String content = messageService.getMessageText();
+//        text.put("content", content);
+        text.put("content", "叔叔阿姨好,明天就是“二月二,龙抬头”龙头节是中国的传统节日,主要活动包括祈福丰收、驱邪纳祥等,具体习俗如下:1、祭祀仪式;2、色饮食;3、驱虫祈福;4、禁忌与习俗;5、现代活动...这里是你的智能AI私人管家——小圈,想了解更多详情,戳我查看\uD83D\uDC47\uD83C\uDFFB\uD83D\uDC47\uD83C\uDFFB\uD83D\uDC47\uD83C\uDFFB");
         jsonObject.put("text", text);
         jsonObject.put("sender", staff.getCarrierId());
         JSONArray attachments = new JSONArray();
-        List<Long> videoIdList = new ArrayList<>();
-        videoIdList.add(sendMessage.getVideoId1());
-        videoIdList.add(sendMessage.getVideoId2());
-        videoIdList.add(sendMessage.getVideoId3());
-        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)) {
-                log.error("附件信息查询异常");
-                return false;
-            }
-            MessageAttachment messageAttachment = messageAttachmentList.get(0);
-            JSONObject miniprogram = new JSONObject();
-            miniprogram.put("appid", MessageConstant.appid);
-            String title = messageAttachment.getTitle();
-            if (title.getBytes(StandardCharsets.UTF_8).length > MAX_BYTES) {
-                title = ToolUtils.truncateString(title, MAX_BYTES - 3) + "...";
-            }
-            miniprogram.put("title", title);
-            String picMediaId = messageAttachmentService.getPicMediaId(messageAttachment.getCover(), sendMessage.getCorpId());
-            if (StringUtils.isEmpty(picMediaId)) {
-                log.error("pushMessage getPicMediaId error cover={}", messageAttachment.getCover());
-                return false;
-            }
-            miniprogram.put("pic_media_id", picMediaId);
-            String page = "";
-            String key = staff.getCarrierId() + "_" + videoId;
-            if (pageMap.containsKey(key)) {
-                page = pageMap.get(key);
-            } else {
-                page = messageAttachmentService.getPage(staff, videoId);
-                pageMap.put(key, page);
-            }
-            if (StringUtils.isEmpty(page)) {
-                log.error("pushMessage get page error videoId={} staff={}", videoId, staff);
-                return false;
+        if (hasMiniprogram) {
+            List<Long> videoIdList = new ArrayList<>();
+            videoIdList.add(sendMessage.getVideoId1());
+//            videoIdList.add(sendMessage.getVideoId2());
+//            videoIdList.add(sendMessage.getVideoId3());
+            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)) {
+                    log.error("附件信息查询异常");
+                    return false;
+                }
+                MessageAttachment messageAttachment = messageAttachmentList.get(0);
+                JSONObject miniprogram = new JSONObject();
+                miniprogram.put("appid", MessageConstant.appid);
+                String title = messageAttachment.getTitle();
+                if (title.getBytes(StandardCharsets.UTF_8).length > MAX_BYTES) {
+                    title = ToolUtils.truncateString(title, MAX_BYTES - 3) + "...";
+                }
+                miniprogram.put("title", title);
+                String picMediaId = messageAttachmentService.getPicMediaId(messageAttachment.getCover(), sendMessage.getCorpId());
+                if (StringUtils.isEmpty(picMediaId)) {
+                    log.error("pushMessage getPicMediaId error cover={}", messageAttachment.getCover());
+                    return false;
+                }
+                miniprogram.put("pic_media_id", picMediaId);
+                String page = "";
+                String key = staff.getCarrierId() + "_" + videoId;
+                if (pageMap.containsKey(key)) {
+                    page = pageMap.get(key);
+                } else {
+                    page = messageAttachmentService.getPage(staff, videoId);
+                    pageMap.put(key, page);
+                }
+                if (StringUtils.isEmpty(page)) {
+                    log.error("pushMessage get page error videoId={} staff={}", videoId, staff);
+                    return false;
+                }
+                miniprogram.put("page", page);
+                attachment.put("miniprogram", miniprogram);
+                attachments.add(0, attachment);
             }
-            miniprogram.put("page", page);
-            attachment.put("miniprogram", miniprogram);
-            attachments.add(0, attachment);
         }
         if (hasLink) {
             JSONObject linkAttachment = new JSONObject();
             JSONObject link = new JSONObject();
-            link.put("title", "测试");
-            link.put("desc", "今日推荐视频已送达~ 遇到问题随时点这里找管家聊聊➡\uFE0F[点击对话],陪您唠家常、解难题,24小时都在线❤\uFE0F");
-            link.put("url", "https://work.weixin.qq.com/kfid/kfc076d867871b81bfe");
+            link.put("title", "AI智能管家");
+            link.put("picurl", "https://rescdn.yishihui.com/we_com/image/ddee4897-34ef-4eb9-b935-d779901a7295");
+            link.put("desc", "点我开启对话,随时都在❤\uFE0F");
+            link.put("url", "https://work.weixin.qq.com/kfid/kfca9ef461bc07d0658");
             linkAttachment.put("msgtype", "link");
             linkAttachment.put("link", link);
             attachments.add(linkAttachment);
         }
-        jsonObject.put("attachments", attachments);
+        if (hasImage) {
+            JSONObject imageAttachment = new JSONObject();
+            JSONObject image = new JSONObject();
+            image.put("media_id", "3s8-EPyCrN1WPkfV43sGFRVQlqty7-sMmCW9YgrIBLLtrv5XqbLMls-_mZ5PjIFpctKkokTvyOKpkYma-GVioFw");
+            imageAttachment.put("msgtype", "image");
+            imageAttachment.put("image", image);
+            attachments.add(imageAttachment);
+        }
+        if(!attachments.isEmpty()){
+            jsonObject.put("attachments", attachments);
+        }
         List<List<String>> lists = Lists.partition(sendUserList, 10000);
         for (List<String> list : lists) {
             JSONArray externalUserIds = JSONArray.parseArray(JSON.toJSONString(list));