Browse Source

Merge branch '20251128-wyp-autoGuaranteesVideo' of Server/growth-manager into master

wangyunpeng 3 tuần trước cách đây
mục cha
commit
46a053b471

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/impl/ThirdPartyServiceImpl.java

@@ -95,7 +95,7 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
         GhDetail ghDetail = ghDetails.get(0);
         String channel = ghDetail.getChannel();
         if (channel == null) {
-            LarkRobotUtil.sendMessage("channel不存在,请查看详情 ghId=", param.getGhId());
+            LarkRobotUtil.sendMessage("channel不存在,请查看详情 ghId=" + param.getGhId());
             return CommonResponse.create(404, "ghId异常,请联系管理员检查");
         }
         if (!Objects.equals(account.getChannel(), channel)) {

+ 1 - 1
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/Impl/MessageAttachmentServiceImpl.java

@@ -285,7 +285,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
         example.createCriteria().andDateEqualTo(date).andIsDeleteEqualTo(0);
         List<GuaranteesVideo> guaranteesVideos = guaranteesVideoMapper.selectByExample(example);
         if (CollectionUtils.isEmpty(guaranteesVideos)) {
-            LarkRobotUtil.sendMessage("获保底视频空,@薛一鸣");
+            LarkRobotUtil.sendMessage("获保底视频空,<at user_id=\"g6732afb\">王云鹏</at>");
             return null;
         }
         GuaranteedParam guaranteedParam = new GuaranteedParam();

+ 1 - 1
common-module/src/main/java/com/tzld/piaoquan/growth/common/service/Impl/MessageServiceImpl.java

@@ -111,7 +111,7 @@ public class MessageServiceImpl implements MessageService {
             log.info("sendAutoReplyMessage res={}", res);
             Integer code = res.getInteger("errcode");
             msgResult.setErrcode(code);
-            if (code != 0) {
+            if (code != 0 && code != 41051) {
                 msgResult.setErrmsg(res.getString("errmsg"));
                 LarkRobotUtil.sendMessage("sendAutoReplyMessage error" + "res:" + res.toJSONString());
             }

+ 16 - 1
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/LarkRobotUtil.java

@@ -21,7 +21,6 @@ public class LarkRobotUtil {
 
     private static final String WE_COM_NOT_PUSH_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/6fa54ed6-12f7-45c1-a33b-020d4f4483ef";
 
-
     private static final String AUTO_REPLY_VIDEO_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/0d80b7dc-47d1-4c27-a7e1-97f2fb6ba26e";
 
     private static final String WE_COM_THIRDPART_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/d5a61df6-7a74-4fa1-808f-e388cfa9b16c";
@@ -50,6 +49,14 @@ public class LarkRobotUtil {
         }
     }
 
+    public static void sendMessage(JSONObject param) {
+        try {
+            HTTP_POOL_CLIENT_UTIL_DEFAULT.post(URL, param.toJSONString());
+        } catch (Exception e) {
+            log.error("Lark sendMessage error", e);
+        }
+    }
+
     public static void sendTipMessage(String msg) {
         sendTipMessage("text", "企微推送结果:" + msg);
     }
@@ -67,6 +74,14 @@ public class LarkRobotUtil {
         }
     }
 
+    public static void sendTipMessage(JSONObject param) {
+        try {
+            HTTP_POOL_CLIENT_UTIL_DEFAULT.post(TIP_URL, param.toJSONString());
+        } catch (Exception e) {
+            log.error("Lark sendMessage error", e);
+        }
+    }
+
 
     public static void sendAutoReplyVideoMessage(JSONObject param) {
         try {

+ 76 - 41
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComHistoryDataJob.java

@@ -3,16 +3,13 @@ package com.tzld.piaoquan.offline.job;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
-import com.tzld.piaoquan.growth.common.common.constant.MessageConstant;
 import com.tzld.piaoquan.growth.common.common.constant.TimeConstant;
+import com.tzld.piaoquan.growth.common.common.enums.FieshuTableColumnDataTypeEnum;
 import com.tzld.piaoquan.growth.common.common.enums.MessageAttachmentTypeEnum;
 import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
 import com.tzld.piaoquan.growth.common.component.ProxyHttpPoolClient;
 import com.tzld.piaoquan.growth.common.dao.mapper.*;
-import com.tzld.piaoquan.growth.common.model.bo.ExternalUser;
-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.bo.*;
 import com.tzld.piaoquan.growth.common.model.po.*;
 import com.tzld.piaoquan.growth.common.service.*;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
@@ -151,14 +148,12 @@ public class WeComHistoryDataJob {
             sendDetail.setSendCountList(countList);
             sendDetailList.add(sendDetail);
         }
-        StringBuilder stringBuilder = new StringBuilder();
-        stringBuilder.append(corpName).append("\n");
         long allCount = 0;
         long notSendCount = 0;
         long successSendCount = 0;
         long notFriendCount = 0;
         long failSendCount = 0;
-
+        List<JSONObject> rows = new ArrayList<>();
         for (SendDetail sendDetail : sendDetailList) {
             List<Long> sendCountList = sendDetail.getSendCountList();
             if (CollectionUtils.isEmpty(sendCountList)) {
@@ -168,41 +163,79 @@ public class WeComHistoryDataJob {
             if (count == 0) {
                 continue;
             }
-            stringBuilder.append(sendDetail.getRemark());
             allCount += count;
             notSendCount += sendCountList.get(0);
             successSendCount += sendCountList.get(1);
             notFriendCount += sendCountList.get(2);
             failSendCount += sendCountList.get(3);
             if (sendCountList.get(0) > 0 && !specialStaffIdList.contains(sendDetail.getStaffId())) {
-                LarkRobotUtil.sendMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
-                LarkRobotUtil.sendTipMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
+                //LarkRobotUtil.sendMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
+                //LarkRobotUtil.sendTipMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
                 //8点前报警
                 if (DateUtil.getHourOfDay() < 8 && (corpId == 1 || corpId == 3)) {
-                    LarkRobotUtil.sendNotPushMessage("<at user_id=\"all\">所有人</at> " + sendDetail.getRemark() + " 存在未发送记录,请检查");
+                    LarkRobotUtil.sendNotPushMessage("<at user_id=\"g6732afb\">王云鹏</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");
+
+            JSONObject row = new JSONObject();
+            row.put("name", sendDetail.getRemark());
+            row.put("totalCount", count);
+            row.put("notSendCount", sendCountList.get(0));
+            row.put("successSendCount", sendCountList.get(1));
+            row.put("notFriendCount", sendCountList.get(2));
+            row.put("failSendCount", sendCountList.get(3));
+            rows.add(row);
         }
-        stringBuilder.append(corpName).append("汇总发送数量:").append("   ");
-        stringBuilder.append("总发送数量:").append(allCount).append("   ");
-        stringBuilder.append("未发送数量:").append(notSendCount).append("   ");
-        stringBuilder.append("已发送数量:").append(successSendCount).append("   ");
-        stringBuilder.append("不是好友发送失败数量:").append(notFriendCount).append("   ");
-        stringBuilder.append("已经收到其他群发消息失败发送数量:").append(failSendCount).append("   ");
-        stringBuilder.append("\n");
+
+        JSONObject row = new JSONObject();
+        row.put("name", "TOTAL");
+        row.put("totalCount", allCount);
+        row.put("notSendCount", notSendCount);
+        row.put("successSendCount", successSendCount);
+        row.put("notFriendCount", notFriendCount);
+        row.put("failSendCount", failSendCount);
+        rows.add(row);
         if (allCount > 0) {
-            LarkRobotUtil.sendMessage(stringBuilder.toString());
-            LarkRobotUtil.sendTipMessage(stringBuilder.toString());
+            JSONObject bodyParam = buildCheckQWMsg(corpName, rows);
+            LarkRobotUtil.sendMessage(bodyParam);
+            LarkRobotUtil.sendTipMessage(bodyParam);
         }
         return notSendCount;
     }
 
+    private JSONObject buildCheckQWMsg(String corpName, List<JSONObject> rows) {
+        List<FeishuTableDTO.Column> columns = buildCheckQWMsgSendColumns();
+        FeishuTableDTO tableDTO = FeishuTableDTO.createTable(corpName, columns, rows, false);
+        JSONObject content = JSONObject.parseObject(JSONObject.toJSONString(tableDTO));
+        JSONObject bodyParam = new JSONObject();
+        bodyParam.put("msg_type", "interactive");
+        bodyParam.put("card", content);
+        return bodyParam;
+    }
+
+    private List<FeishuTableDTO.Column> buildCheckQWMsgSendColumns() {
+        List<FeishuTableDTO.Column> columns = new ArrayList<>();
+        FeishuTableDTO.Column nameColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "name", "账号名称", null);
+        columns.add(nameColumn);
+        FeishuTableDTO.Column totalCountColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "totalCount", "总发送数量", null);
+        columns.add(totalCountColumn);
+        FeishuTableDTO.Column notSendCountColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "notSendCount", "未发送数量", null);
+        columns.add(notSendCountColumn);
+        FeishuTableDTO.Column successSendCountColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "successSendCount", "已发送数量", null);
+        columns.add(successSendCountColumn);
+        FeishuTableDTO.Column notFriendCountColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "notFriendCount", "不是好友发送失败数量", null);
+        columns.add(notFriendCountColumn);
+        FeishuTableDTO.Column failSendCountColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "failSendCount", "已经收到其他群发消息失败发送数量", null);
+        columns.add(failSendCountColumn);
+        return columns;
+    }
+
 
     @XxlJob("saveHistoryMessageJob")
     public ReturnT<String> selectHistoryMessageByDay(String param) {
@@ -271,8 +304,7 @@ public class WeComHistoryDataJob {
             sendDetail.setSendCountList(countList);
             sendDetailList.add(sendDetail);
         }
-        StringBuilder stringBuilder = new StringBuilder();
-        stringBuilder.append(corpName).append("\n");
+        List<JSONObject> rows = new ArrayList<>();
         for (SendDetail sendDetail : sendDetailList) {
             List<Long> sendCountList = sendDetail.getSendCountList();
             if (CollectionUtils.isEmpty(sendCountList)) {
@@ -282,25 +314,28 @@ public class WeComHistoryDataJob {
             if (count == 0) {
                 continue;
             }
-            stringBuilder.append(sendDetail.getRemark());
+
 
             if (count == sendCountList.get(0)) {
-                LarkRobotUtil.sendMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
+                //LarkRobotUtil.sendMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
                 if (sendDetail.getStaffId() == 3) {
-                    LarkRobotUtil.sendTipMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
+                    //LarkRobotUtil.sendTipMessage(sendDetail.getRemark() + "存在未发送记录,请检查");
                 } else {
-                    LarkRobotUtil.sendNotPushMessage("<at user_id=\"all\">所有人</at> " + sendDetail.getRemark() + " 存在未发送记录,请检查");
+                    LarkRobotUtil.sendNotPushMessage("<at user_id=\"g6732afb\">王云鹏</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");
+            JSONObject row = new JSONObject();
+            row.put("name", sendDetail.getRemark());
+            row.put("totalCount", count);
+            row.put("notSendCount", sendCountList.get(0));
+            row.put("successSendCount", sendCountList.get(1));
+            row.put("notFriendCount", sendCountList.get(2));
+            row.put("failSendCount", sendCountList.get(3));
+            rows.add(row);
         }
-        LarkRobotUtil.sendMessage(stringBuilder.toString());
-        LarkRobotUtil.sendTipMessage(stringBuilder.toString());
+        JSONObject bodyParam = buildCheckQWMsg(corpName, rows);
+        LarkRobotUtil.sendMessage(bodyParam);
+        LarkRobotUtil.sendTipMessage(bodyParam);
     }
 
     private void selectGroupMsgList(Long startTime, Long endTime, Long corpId, Long staffId) {

+ 92 - 2
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComMessageDataJob.java

@@ -5,6 +5,7 @@ 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.growth.common.common.base.CommonResponse;
 import com.tzld.piaoquan.growth.common.common.constant.MessageConstant;
 import com.tzld.piaoquan.growth.common.dao.mapper.*;
 import com.tzld.piaoquan.growth.common.model.bo.*;
@@ -17,6 +18,7 @@ import com.tzld.piaoquan.growth.common.utils.*;
 import com.tzld.piaoquan.growth.common.utils.page.Page;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xxl.job.core.log.XxlJobLogger;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -479,7 +481,7 @@ public class WeComMessageDataJob {
         example.createCriteria().andIsSendEqualTo(0).andCreateTimeGreaterThan(DateUtil.getThatDayDate());
         long l = sendMessageMapper.countByExample(example);
         if (l > 0) {
-            LarkRobotUtil.sendMessage("存在发送失败消息,请检查@薛一鸣");
+            LarkRobotUtil.sendMessage("存在发送失败消息,请检查<at user_id=\"g6732afb\">王云鹏</at>");
         }
         return ReturnT.SUCCESS;
     }
@@ -590,10 +592,98 @@ public class WeComMessageDataJob {
         GuaranteedParam guaranteedParam = messageAttachmentService.getGuaranteedVideo(DateUtil.getNextDayDateString());
         if (guaranteedParam == null
                 || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
-            LarkRobotUtil.sendMessage("@薛一鸣 保底视频异常,请检查" + DateUtil.getNextDayDateString());
+            LarkRobotUtil.sendMessage("<at user_id=\"g6732afb\">王云鹏</at> 保底视频异常,请检查" + DateUtil.getNextDayDateString());
         }
         return ReturnT.SUCCESS;
     }
 
 
+    @XxlJob("addMessageAttachmentJob")
+    public ReturnT<String> addMessageAttachment(String param) {
+        String dt = DateUtil.getBeforeDayDateString(-1, "yyyy-MM-dd");
+        List<Long> videoIds = getTopThousandVideoIds();
+        if (CollectionUtils.isEmpty(videoIds)) {
+            XxlJobLogger.log("保底视频查询异常");
+            LarkRobotUtil.sendMessage("addMessageAttachmentJob 保底视频添加任务异常,请检查 " + dt
+                    + " <at user_id=\"g6732afb\">王云鹏</at>");
+            return ReturnT.FAIL;
+        }
+
+        List<Long> currentVideoIds = new ArrayList<>();
+        int index = 0;
+
+        while (true) {
+            while (currentVideoIds.size() < MAX_VIDEO_NUM && index < videoIds.size()) {
+                currentVideoIds.add(videoIds.get(index++));
+            }
+            if (currentVideoIds.size() < MAX_VIDEO_NUM) {
+                XxlJobLogger.log("保底视频可用数量不足,无法凑齐3个有效视频");
+                LarkRobotUtil.sendMessage("addMessageAttachmentJob 保底视频可用数量不足,无法凑齐3个有效视频,请检查 " + dt
+                        + " <at user_id=\"g6732afb\">王云鹏</at>");
+                return ReturnT.FAIL;
+            }
+            GuaranteedParam guaranteedParam = new GuaranteedParam();
+            guaranteedParam.setDate(dt);
+            guaranteedParam.setVideoParamList(buildVideoParamList(new ArrayList<>(currentVideoIds)));
+            CommonResponse<Void> commonResponse = messageAttachmentService.createGuaranteedMiniProgram(guaranteedParam);
+            if (commonResponse.isSuccess() && commonResponse.getCode() == 0) {
+                return ReturnT.SUCCESS;
+            }
+
+            String msg = commonResponse.getMsg();
+            if (StringUtils.isNotEmpty(msg) && msg.contains("保底视频30天内已发送,请查看videoId=")) {
+                String errorVideoId = msg.substring(msg.indexOf("videoId=") + 8);
+                try {
+                    Long removeId = Long.parseLong(errorVideoId);
+                    currentVideoIds.remove(removeId);
+                } catch (Exception e) {
+                    XxlJobLogger.log("保底视频异常,解析videoId失败: " + errorVideoId);
+                }
+            } else {
+                XxlJobLogger.log("创建保底视频失败: " + msg);
+            }
+            if (currentVideoIds.size() == MAX_VIDEO_NUM) {
+                currentVideoIds.clear();
+            }
+        }
+    }
+
+    private List<Long> getTopThousandVideoIds() {
+        int releaseDays = 1;
+        String dt = DateUtil.getBeforeDayDateString(releaseDays, "yyyyMMdd");
+        int retryTimes = 3;
+        List<Long> videoIds = new ArrayList<>();
+        do {
+            String sql = String.format("SELECT videoid FROM loghubods.lastday_return WHERE dt=%s limit 2000;", dt);
+            List<Record> dataList = OdpsUtil.getOdpsData(sql);
+            if (!CollectionUtils.isEmpty(dataList)) {
+                for (Record record : dataList) {
+                    Long videoId = Long.parseLong((String) record.get(0));
+                    videoIds.add(videoId);
+                }
+                return videoIds;
+            }
+            retryTimes--;
+            releaseDays++;
+            dt = DateUtil.getBeforeDayDateString(releaseDays, "yyyyMMdd");
+        } while (retryTimes > 0);
+        return videoIds;
+    }
+
+    private List<VideoParam> buildVideoParamList(List<Long> videoIds) {
+        List<VideoParam> videoParamList = new ArrayList<>();
+        VideoParam videoParam = new VideoParam();
+        videoParam.setStaffIds(Arrays.asList(0L, 3L, 7L, 9L, 10L, 12L, 16L, 17L, 100L, 103L, 104L, 106L, 107L, 108L, 109L, 110L));
+        videoParam.setVideoIds(videoIds);
+        videoParamList.add(videoParam);
+        VideoParam videoParam2 = new VideoParam();
+        videoParam2.setStaffIds(Arrays.asList(5L, 15L));
+        videoParam2.setVideoIds(videoIds);
+        videoParamList.add(videoParam2);
+        VideoParam videoParam3 = new VideoParam();
+        videoParam3.setStaffIds(Arrays.asList(8L, 11L, 13L, 14L));
+        videoParam3.setVideoIds(videoIds);
+        videoParamList.add(videoParam3);
+        return videoParamList;
+    }
 }