瀏覽代碼

飞书增加表格

xueyiming 3 月之前
父節點
當前提交
6841331f00

+ 28 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/common/enums/FieshuTableColumnDataTypeEnum.java

@@ -0,0 +1,28 @@
+package com.tzld.piaoquan.growth.common.common.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum FieshuTableColumnDataTypeEnum {
+    TEXT("text"),
+    LARK_MD("lark_md"),
+    NUMBER("number"),
+    DATE("date"),
+    OPTIONS("options"),
+    ;
+
+    private String type;
+
+    FieshuTableColumnDataTypeEnum(String type) {
+        this.type = type;
+    }
+
+    public static FieshuTableColumnDataTypeEnum from(String type) {
+        for (FieshuTableColumnDataTypeEnum typeEnum : FieshuTableColumnDataTypeEnum.values()) {
+            if (typeEnum.getType().equals(type)) {
+                return typeEnum;
+            }
+        }
+        return null;
+    }
+}

+ 148 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/bo/FeishuTableDTO.java

@@ -0,0 +1,148 @@
+package com.tzld.piaoquan.growth.common.model.bo;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.growth.common.common.enums.FieshuTableColumnDataTypeEnum;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class FeishuTableDTO {
+    private Header header;
+    private List<Element> elements;
+
+    @Data
+    public static class Element {
+        private String tag;
+        private JSONObject text;
+        private long page_size;
+        private String row_height;
+        private HeaderStyle header_style;
+        private List<Column> columns;
+        private List<JSONObject> rows;
+    }
+
+    @Data
+    public static class Column {
+        private String name;
+        private String display_name;
+        private String data_type;
+        private String horizontal_align;
+        private String vertical_align;
+        private String width;
+        private String format;
+        private String dateFormat;
+    }
+
+    @Data
+    public static class HeaderStyle {
+        private String text_align;
+        private String text_size;
+        private String background_style;
+        private String text_color;
+        private boolean bold;
+        private long lines;
+    }
+
+    @Data
+    public static class Header {
+        private String template;
+        private Title title;
+    }
+
+    @Data
+    public static class Title {
+        private String content;
+        private String tag;
+    }
+
+    public static FeishuTableDTO createTable(String title, List<Column> columns, List<JSONObject> rows, boolean atAll) {
+        String tableStr = "{\n" +
+                "    \"header\":\n" +
+                "    {\n" +
+                "        \"template\": \"blue\",\n" +
+                "        \"title\":\n" +
+                "        {\n" +
+                "            \"content\": \"" + title + "\",\n " +
+                "            \"tag\": \"plain_text\"\n" +
+                "        }\n" +
+                "    },\n" +
+                "    \"elements\":\n" +
+                "    [\n" +
+                "        {\n" +
+                "            \"tag\": \"table\",\n" +
+                "            \"page_size\": " + rows.size() + ",\n" +
+                "            \"row_height\": \"low\",\n" +
+                "            \"header_style\":\n" +
+                "            {\n" +
+                "                \"text_align\": \"left\",\n" +
+                "                \"text_size\": \"normal\",\n" +
+                "                \"background_style\": \"none\",\n" +
+                "                \"text_color\": \"grey\",\n" +
+                "                \"bold\": true,\n" +
+                "                \"lines\": 1\n" +
+                "            },\n" +
+                "            \"columns\":\n" +
+                JSONObject.toJSONString(columns) +
+                "            ,\n" +
+                "            \"rows\":\n" +
+                JSONObject.toJSONString(rows) +
+                "        }\n" +
+                "    ]\n" +
+                "}";
+        FeishuTableDTO result =  JSONObject.parseObject(tableStr, FeishuTableDTO.class);
+        if (atAll) {
+            FeishuTableDTO.Element atAllElement = new FeishuTableDTO.Element();
+            atAllElement.setTag("div");
+            JSONObject atAllElementText = new JSONObject();
+            atAllElementText.put("content", "<at id=all></at>");
+            atAllElementText.put("tag", "lark_md");
+            atAllElement.setText(atAllElementText);
+            result.getElements().add(atAllElement);
+        }
+        return result;
+    }
+
+    public static Column createFeishuColumns(
+            String dataType,
+            String columnName,
+            String displayName,
+            String numberFormat) {
+
+        String width = "auto";
+        String verticalAlign = "top";
+        String horizontalAlign = "left";
+        Column column = new Column();
+
+        if (FieshuTableColumnDataTypeEnum.TEXT.getType().equals(dataType)) {
+            column.setName(columnName);
+            column.setDisplay_name(displayName);
+            column.setWidth(width);
+            column.setData_type(dataType);
+            column.setVertical_align(verticalAlign);
+            column.setHorizontal_align(horizontalAlign);
+        } else if (FieshuTableColumnDataTypeEnum.LARK_MD.getType().equals(dataType)) {
+            column.setName(columnName);
+            column.setDisplay_name(displayName);
+            column.setData_type(dataType);
+        } else if (FieshuTableColumnDataTypeEnum.NUMBER.getType().equals(dataType)) {
+            column.setName(columnName);
+            column.setDisplay_name(displayName);
+            column.setData_type(dataType);
+            column.setFormat(numberFormat);
+            column.setWidth(width);
+        } else if (FieshuTableColumnDataTypeEnum.DATE.getType().equals(dataType)) {
+            column.setName(columnName);
+            column.setDisplay_name(displayName);
+            column.setData_type(dataType);
+            column.setDateFormat("YYYY/MM/DD");
+        } else if (FieshuTableColumnDataTypeEnum.OPTIONS.getType().equals(dataType)) {
+            column.setName(columnName);
+            column.setDisplay_name(displayName);
+            column.setData_type(dataType);
+        }
+
+        return column;
+    }
+}
+

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

@@ -66,13 +66,8 @@ public class LarkRobotUtil {
     }
 
 
-    public static void sendAutoReplyVideoMessage(String msg) {
+    public static void sendAutoReplyVideoMessage(JSONObject param) {
         try {
-            JSONObject param = new JSONObject();
-            param.put("msg_type", "text");
-            JSONObject content = new JSONObject();
-            content.put("text", msg);
-            param.put("content", content);
             HTTP_POOL_CLIENT_UTIL_DEFAULT.post(AUTO_REPLY_VIDEO_URL, param.toJSONString());
         } catch (Exception e) {
             log.error("Lark sendMessage error", e);

+ 49 - 12
offline-module/src/main/java/com/tzld/piaoquan/offline/job/AutoReplyVideoDataJob.java

@@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
+import com.tzld.piaoquan.growth.common.common.enums.FieshuTableColumnDataTypeEnum;
 import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
 import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
 import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
 import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
 import com.tzld.piaoquan.growth.common.dao.mapper.GhDetailMapper;
+import com.tzld.piaoquan.growth.common.model.bo.FeishuTableDTO;
 import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
 import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketDataExample;
 import com.tzld.piaoquan.growth.common.model.po.GhDetail;
@@ -136,9 +138,9 @@ public class AutoReplyVideoDataJob {
         if (CollectionUtils.isEmpty(auditFailedVideoIds)) {
             return ReturnT.SUCCESS;
         }
-        String videoMsg = String.format("审核不通过的视频列表:%s", auditFailedVideoIds);
-        System.out.println(videoMsg);
-        LarkRobotUtil.sendAutoReplyVideoMessage(videoMsg);
+
+        List<FeishuTableDTO.Column> columns = buildCheckPublishPlanAccountColumns();
+        List<JSONObject> rows = new ArrayList<>();
 
         for (Long videoId : auditFailedVideoIds) {
             CgiReplyBucketDataExample example = new CgiReplyBucketDataExample();
@@ -149,9 +151,13 @@ public class AutoReplyVideoDataJob {
             for (CgiReplyBucketData cgiReplyBucketData : cgiReplyBucketDataList) {
                 String ghId = cgiReplyBucketData.getGhId();
                 GhDetailExample ghDetailExample = new GhDetailExample();
-                ghDetailExample.createCriteria().andGhIdEqualTo(ghId).andTypeEqualTo(GhTypeEnum.THIRD_PARTY_GH.type);
+                ghDetailExample.createCriteria().andGhIdEqualTo(ghId);
                 List<GhDetail> ghDetails = ghDetailMapper.selectByExample(ghDetailExample);
+                if (CollectionUtils.isEmpty(ghDetails)) {
+                    continue;
+                }
                 GhDetail ghDetail = ghDetails.get(0);
+
 //                if (Objects.equals(cgiReplyBucketData.getStrategy(), "manual")) {
 //                    ghDetail1.setStrategyStatus(StrategyStatusEnum.STRATEGY.status);
 //                    ghDetailMapper.updateByPrimaryKeySelective(ghDetail1);
@@ -159,18 +165,49 @@ public class AutoReplyVideoDataJob {
 //                }
 
 //                ghIds.add(cgiReplyBucketData.getGhId());
-                String msg = String.format("账号名称:%s \n 渠道id:%s \n 审核不通过的视频id:%s \n ghId:%s",
-                        ghDetail.getGhName(), ghDetail.getChannel(), videoId, ghDetail.getGhId());
-                LarkRobotUtil.sendAutoReplyVideoMessage(msg);
-                if (auditGhIds.contains(ghId)) {
-                    String url = REFRESH_GZH_URL + "?ghId=" + cgiReplyBucketData.getGhId();
-                    String res = httpPoolClient.get(url);
-                    log.info("refresh ghId={}, res={}", cgiReplyBucketData.getGhId(), res);
+                JSONObject row = new JSONObject();
+                row.put("name", ghDetail.getGhName());
+                row.put("channel", ghDetail.getChannel());
+                row.put("video", videoId);
+                row.put("ghId", ghDetail.getGhId());
+                rows.add(row);
+                try {
+                    if (auditGhIds.contains(ghId)) {
+                        String url = REFRESH_GZH_URL + "?ghId=" + cgiReplyBucketData.getGhId();
+                        String res = httpPoolClient.get(url);
+                        log.info("refresh ghId={}, res={}", cgiReplyBucketData.getGhId(), res);
+                    }
+                } catch (Exception e) {
+                    log.error("refresh error", e);
                 }
+
             }
         }
-
+        FeishuTableDTO tableDTO = FeishuTableDTO.createTable("自动回复视频审核失败报警", columns, rows, false);
+        JSONObject content = JSONObject.parseObject(JSONObject.toJSONString(tableDTO));
+        JSONObject bodyParam = new JSONObject();
+        bodyParam.put("msg_type", "interactive");
+        bodyParam.put("card", content);
+        LarkRobotUtil.sendAutoReplyVideoMessage(bodyParam);
         return ReturnT.SUCCESS;
     }
 
+
+    private List<FeishuTableDTO.Column> buildCheckPublishPlanAccountColumns() {
+        List<FeishuTableDTO.Column> columns = new ArrayList<>();
+        FeishuTableDTO.Column nameColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "name", "账号名称", null);
+        columns.add(nameColumn);
+        FeishuTableDTO.Column channelColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "channel", "渠道id", null);
+        columns.add(channelColumn);
+        FeishuTableDTO.Column videoColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "video", "审核不通过的视频id", null);
+        columns.add(videoColumn);
+        FeishuTableDTO.Column ghIdColumn = FeishuTableDTO.createFeishuColumns(
+                FieshuTableColumnDataTypeEnum.TEXT.getType(), "ghId", "ghId", null);
+        columns.add(ghIdColumn);
+        return columns;
+    }
+
 }