Przeglądaj źródła

增加站点同步至飞书表格

Cyan 7 miesięcy temu
rodzic
commit
f60d009d66

+ 1 - 3
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/controller/ShopApiController.java

@@ -1,17 +1,15 @@
 package org.jeecg.modules.okki.site.controller;
 
-import com.alibaba.fastjson.JSON;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.HttpHeaders;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.FastJsonUtil;
 import org.jeecg.modules.okki.site.dto.FeiShuRecordSheetDto;
-import org.jeecg.modules.okki.site.entity.OkkiSite;
 import org.jeecg.modules.okki.site.param.ChangeSiteStatusParam;
 import org.jeecg.modules.okki.site.param.OkkiSiteParam;
+import org.jeecg.modules.okki.site.service.IFeiShuGroupService;
 import org.jeecg.modules.okki.site.service.IFeiShuSheetService;
 import org.jeecg.modules.okki.site.service.IOkkiSiteService;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 

+ 5 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/dto/FeiShuRecordSheetDto.java

@@ -26,4 +26,9 @@ public class FeiShuRecordSheetDto {
      * 客户名称
      */
     private String customerName;
+
+    /**
+     * 套餐名称
+     */
+    private String planName;
 }

+ 44 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/entity/FeiShuConfigEnum.java

@@ -0,0 +1,44 @@
+package org.jeecg.modules.okki.site.entity;
+
+/**
+ * @author Chen
+ */
+public enum FeiShuConfigEnum {
+    PROD("cli_a61c977059f01013", "saNlFj2YdMXZ0uEAucyRodfSEp5ZHikR", "X16RbjCVCasCmds7fn0c0k21nju", "tblSkc8HfEYDL99U", "tblzjztd3MnAAkGx"),
+    DEV("cli_a61c977059f01013", "saNlFj2YdMXZ0uEAucyRodfSEp5ZHikR", "W0zSbiooNa4Z9tsI2RFcJ0W1nfc", "tblqGDRNN9cDgCJm", "tblYXpaYDOYTPpp8");
+
+    private final String appId;
+    private final String appSecret;
+    private final String appToken;
+    private final String kfTableId;
+    private final String projectTeamTableId;
+
+    FeiShuConfigEnum(String appId, String appSecret, String appToken, String kfTableId, String projectTeamTableId) {
+        this.appId = appId;
+        this.appSecret = appSecret;
+        this.appToken = appToken;
+        this.kfTableId = kfTableId;
+        this.projectTeamTableId = projectTeamTableId;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public String getAppSecret() {
+        return appSecret;
+    }
+
+    public String getAppToken() {
+        return appToken;
+    }
+
+    public String getKfTableId() {
+        return kfTableId;
+    }
+
+    public String getProjectTeamTableId() {
+        return projectTeamTableId;
+    }
+
+}

+ 8 - 31
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/service/IFeiShuCommonService.java

@@ -4,13 +4,13 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.lark.oapi.Client;
-import com.lark.oapi.core.utils.Jsons;
 import com.lark.oapi.service.bitable.v1.model.AppTableRecord;
 import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordReq;
 import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordResp;
 import com.lark.oapi.service.bitable.v1.model.ListAppTableRecordRespBody;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.FastJsonUtil;
+import org.jeecg.modules.okki.site.entity.FeiShuConfigEnum;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -26,32 +26,17 @@ import java.util.Map;
 @Service
 public class IFeiShuCommonService {
 
-    public static String APP_ID = "cli_a61c977059f01013";
-
-    public static String APP_SECRET = "saNlFj2YdMXZ0uEAucyRodfSEp5ZHikR";
-
-    public static String APP_TOKEN = "X16RbjCVCasCmds7fn0c0k21nju";
-
     /**
-     * prod:项目分组ID
+     * @param targetGroups
      */
-    public static String PROJECT_TEAM_TABLE_ID = "tblzjztd3MnAAkGx";
-
-    /*
-      dev:项目分组ID
-     */
-//    public static String PROJECT_TEAM_TABLE_ID = "tblSkc8HfEYDL99U";
-
-    /**
-     * @param groupName
-     */
-    public Map<String, List<JSONObject>> getFeiShuTeamSheet(String groupName) {
+    public Map<String, List<JSONObject>> getFeiShuTeamSheet(List<String> targetGroups) {
+        FeiShuConfigEnum configEnum = FeiShuConfigEnum.valueOf("DEV");
         List<Map<String, Object>> mapList = new ArrayList<>();
-        Client client = Client.newBuilder(APP_ID, APP_SECRET).build();
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
 
         // 创建请求对象
         ListAppTableRecordReq listAppTableRecordReq = ListAppTableRecordReq.newBuilder()
-                .appToken(APP_TOKEN).tableId(PROJECT_TEAM_TABLE_ID).build();
+                .appToken(configEnum.getAppToken()).tableId(configEnum.getProjectTeamTableId()).build();
 
         // 发起请求
         ListAppTableRecordResp resp = null;
@@ -63,7 +48,7 @@ public class IFeiShuCommonService {
 
         // 处理服务端错误
         if (!resp.success()) {
-            System.out.println(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
+            log.error("******** getFeiShuTeamSheet ******* :{}", String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
         }
 
         if (resp.success()) {
@@ -74,18 +59,11 @@ public class IFeiShuCommonService {
             }
         }
 
-        // 业务数据处理
-        System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
         log.info("mapList:{}", FastJsonUtil.toJSONString(mapList));
-
+        // 业务数据处理
         String jsonData = FastJsonUtil.toJSONString(mapList);
         JSONArray jsonArray = JSON.parseArray(jsonData);
         Map<String, List<JSONObject>> targetGroupData = new HashMap<>();
-        List<String> targetGroups = new ArrayList<>();
-        targetGroups.add(groupName);
-        targetGroups.add("UI设计");
-        targetGroups.add("质检组");
-        targetGroups.add("项目管理");
         for (int i = 0; i < jsonArray.size(); i++) {
             JSONObject jsonObject = jsonArray.getJSONObject(i);
             String groupNameData = jsonObject.getString("组名");
@@ -131,7 +109,6 @@ public class IFeiShuCommonService {
             List<String> ids = entry.getValue();
             List<Map<String, Object>> newArray = new ArrayList<>();
 
-            // 将每个 ID 转换为 {"id": "id_value"} 的格式
             for (String id : ids) {
                 Map<String, Object> idObject = new HashMap<>();
                 idObject.put("id", id);

+ 28 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/service/IFeiShuGroupService.java

@@ -0,0 +1,28 @@
+package org.jeecg.modules.okki.site.service;
+
+/**
+ * @author Chen
+ */
+public interface IFeiShuGroupService {
+
+    /**
+     * 发送创建飞书群
+     *
+     * @param customerName
+     * @param siteId
+     * @param planName
+     * @param groupName
+     */
+    public void createFeiShuGroup(String customerName, String siteId, String planName, String groupName);
+
+    /**
+     * 发起创建群聊请求
+     *
+     * @param customerName
+     * @param siteId
+     * @param groupName
+     * @param ownerId
+     * @param needJoinFeiShuIdsArray
+     */
+    public void sendCreateFeiShuGroupRequest(String customerName, String siteId, String groupName, String ownerId, String[] needJoinFeiShuIdsArray);
+}

+ 11 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/service/IFeiShuMsgService.java

@@ -17,10 +17,21 @@ public interface IFeiShuMsgService {
 
     /**
      * 发送更新-飞书消息
+     *
      * @param customerName
      * @param siteId
      * @param groupName
      * @param syncStatus
      */
     public void sendUpdateFeiShuSheetMsg(String customerName, String siteId, String groupName, String syncStatus);
+
+    /**
+     * 发送创建群聊-飞书消息
+     *
+     * @param customerName
+     * @param siteId
+     * @param feiShuGroupName
+     * @param status
+     */
+    public void sendCreateFeiShuGroupMsg(String customerName, String siteId, String feiShuGroupName, String status);
 }

+ 191 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/service/impl/FeiShuGroupServiceImpl.java

@@ -0,0 +1,191 @@
+package org.jeecg.modules.okki.site.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.lark.oapi.Client;
+import com.lark.oapi.core.utils.Jsons;
+import com.lark.oapi.service.im.v1.model.*;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.FastJsonUtil;
+import org.jeecg.modules.okki.site.entity.FeiShuConfigEnum;
+import org.jeecg.modules.okki.site.service.IFeiShuCommonService;
+import org.jeecg.modules.okki.site.service.IFeiShuGroupService;
+import org.jeecg.modules.okki.site.service.IFeiShuMsgService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Chen
+ */
+@Slf4j
+@Service
+public class FeiShuGroupServiceImpl implements IFeiShuGroupService {
+
+    @Autowired
+    private IFeiShuMsgService feiShuMsgService;
+
+    @Autowired
+    private IFeiShuCommonService feiShuCommonService;
+
+    /**
+     * 创建飞书群
+     *
+     * @param customerName
+     * @param planName
+     * @param groupName
+     */
+    @Override
+    public void createFeiShuGroup(String customerName, String siteId, String planName, String groupName) {
+        List<String> targetGroups = new ArrayList<>();
+        targetGroups.add(groupName);
+        targetGroups.add("UI设计");
+        targetGroups.add("质检组");
+        targetGroups.add("技术支持");
+//        targetGroups.add("项目管理");
+//        targetGroups.add("SNS组");
+        Map<String, List<JSONObject>> teamSheetMap = feiShuCommonService.getFeiShuTeamSheet(targetGroups);
+        log.info("******* createFeiShuGroup ******* 需要加入群聊的人员:teamSheetMap:{}", FastJsonUtil.toJSONString(teamSheetMap));
+//
+        List<String> needJoinFeiShuIds = new ArrayList<>();
+        for (Map.Entry<String, List<JSONObject>> entry : teamSheetMap.entrySet()) {
+            List<JSONObject> groupList = entry.getValue();
+            for (JSONObject group : groupList) {
+                JSONArray personnelArray = group.getJSONArray("人员");
+                if (personnelArray != null) {
+                    for (int i = 0; i < personnelArray.size(); i++) {
+                        JSONObject person = personnelArray.getJSONObject(i);
+                        String id = person.getString("id");
+                        if (id != null && !id.isEmpty()) {
+                            needJoinFeiShuIds.add(id);
+                        }
+                    }
+                }
+            }
+        }
+        log.info("needJoinFeiShuIds:{}", FastJsonUtil.toJSONString(needJoinFeiShuIds));
+
+        // 群主
+        String ownerId = "";
+        for (Map.Entry<String, List<JSONObject>> entry : teamSheetMap.entrySet()) {
+            if ("技术支持".equals(entry.getKey())) {
+                List<JSONObject> groupList = entry.getValue();
+                for (JSONObject group : groupList) {
+                    JSONArray personnelArray = group.getJSONArray("人员");
+                    if (personnelArray != null) {
+                        for (int i = 0; i < personnelArray.size(); i++) {
+                            JSONObject person = personnelArray.getJSONObject(i);
+                            if ("陈云".equals(person.getString("name"))) {
+                                ownerId = person.getString("id");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        log.info("ownerId:{}", ownerId);
+
+        // 群名称
+        String feiShuGroupName = customerName + " - " + planName + " - OK项目组";
+
+        //群成员
+        String[] needJoinFeiShuIdsArray = needJoinFeiShuIds.stream().toArray(String[]::new);
+
+        //创建群聊
+        sendCreateFeiShuGroupRequest(customerName, siteId, feiShuGroupName, ownerId, needJoinFeiShuIdsArray);
+    }
+
+    /**
+     * 发起创建群聊请求
+     *
+     * @param feiShuGroupName
+     * @param ownerId
+     * @param needJoinFeiShuIdsArray
+     */
+    @Override
+    public void sendCreateFeiShuGroupRequest(String customerName, String siteId, String feiShuGroupName, String ownerId, String[] needJoinFeiShuIdsArray) {
+        FeiShuConfigEnum configEnum = FeiShuConfigEnum.valueOf("DEV");
+        // 构建client
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
+
+        // 创建请求对象
+        CreateChatReq req = CreateChatReq.newBuilder()
+                .createChatReqBody(CreateChatReqBody.newBuilder()
+                        .name(feiShuGroupName)
+                        .description(feiShuGroupName)
+                        .ownerId(ownerId)
+                        .userIdList(needJoinFeiShuIdsArray)
+                        .botIdList(new String[]{configEnum.getAppId()})
+                        .build())
+                .build();
+
+        // 发起请求
+        CreateChatResp resp = null;
+        try {
+            resp = client.im().chat().create(req);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        // 处理服务端错误
+        String status = "成功";
+        if (!resp.success()) {
+            status = "失败";
+            log.error("********** sendCreateFeiShuGroupRequest-error *********:{}",String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
+        }
+
+        // 发送飞书消息通知
+        feiShuMsgService.sendCreateFeiShuGroupMsg(customerName, siteId, feiShuGroupName, status);
+        if (resp.success()) {
+            // 业务数据处理
+            log.info("********* sendCreateFeiShuGroupRequest **********:{}", Jsons.DEFAULT.toJson(resp.getData()));
+
+            // 发送群消息
+            String feiShuGroupId = resp.getData().getChatId();
+            sendGroupMsg(feiShuGroupName, feiShuGroupId);
+        }
+    }
+
+    /**
+     * 发送群消息
+     *
+     * @param feiShuGroupName
+     */
+    public void sendGroupMsg(String feiShuGroupName, String feiShuGroupId) {
+        FeiShuConfigEnum configEnum = FeiShuConfigEnum.valueOf("DEV");
+        // 构建client
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("text", "<at user_id=\"all\"></at> \n大家好!\uD83E\uDD16\n" +
+                "我是 " + feiShuGroupName + " 的机器人助理。欢迎加入项目群!我的任务是协助大家顺利推进项目进程,解答疑问,和处理各种信息。如果有任何问题或需要帮助,请随时联系我。期待与大家的合作,共同推动项目成功!\n" +
+                "谢谢大家的配合!\uD83D\uDE80!");
+
+        // 创建请求对象
+        CreateMessageReq req = CreateMessageReq.newBuilder()
+                .receiveIdType("chat_id")
+                .createMessageReqBody(CreateMessageReqBody.newBuilder()
+                        .receiveId(feiShuGroupId)
+                        .msgType("text")
+                        .content(FastJsonUtil.toJSONString(map))
+                        .build())
+                .build();
+
+        // 发起请求
+        CreateMessageResp resp = null;
+        try {
+            resp = client.im().message().create(req);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        // 处理服务端错误
+        if (!resp.success()) {
+            log.error("******* sendGroupMsg-error ******** :{}",String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
+        }
+    }
+}

+ 137 - 3
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/service/impl/FeiShuMsgServiceImpl.java

@@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
 public class FeiShuMsgServiceImpl implements IFeiShuMsgService {
 
     /**
-     * 发送飞书消息
+     * 发送同步站点-飞书消息
      *
      * @param customerName
      * @param siteId
@@ -147,10 +147,11 @@ public class FeiShuMsgServiceImpl implements IFeiShuMsgService {
     }
 
     /**
+     * 发送更新表格-飞书消息
      *
      * @param customerName
      * @param siteId
-     * @param planName
+     * @param groupName
      * @param status
      */
     public void sendUpdateFeiShuSheetMsg(String customerName, String siteId, String groupName, String status) {
@@ -266,7 +267,7 @@ public class FeiShuMsgServiceImpl implements IFeiShuMsgService {
                 "        }\n" +
                 "    }\n" +
                 "}";
-        template = template.replace("${title}", "【"+customerName+"】分配建站小组通知");
+        template = template.replace("${title}", "【" + customerName + "】分配建站小组通知");
         template = template.replace("${customerName}", customerName);
         template = template.replace("${siteId}", siteId);
         template = template.replace("${groupName}", groupName);
@@ -277,4 +278,137 @@ public class FeiShuMsgServiceImpl implements IFeiShuMsgService {
         object.put("card", template);
         HttpClientUtil.doPostJson(botUrl, object.toJSONString());
     }
+
+    /**
+     * 发送创建飞书群聊-飞书消息
+     *
+     * @param customerName
+     * @param siteId
+     * @param feiShuGroupName
+     * @param status
+     */
+    public void sendCreateFeiShuGroupMsg(String customerName, String siteId, String feiShuGroupName, String status) {
+        String botUrl = "https://open.feishu.cn/open-apis/bot/v2/hook/f77f9317-5f15-4aa7-8036-32ce771f40c1";
+
+        String template = "{\n" +
+                "    \"config\": {\n" +
+                "        \"update_multi\": true\n" +
+                "    },\n" +
+                "    \"i18n_elements\": {\n" +
+                "        \"zh_cn\": [\n" +
+                "            {\n" +
+                "                \"tag\": \"markdown\",\n" +
+                "                \"content\": \"<at id=\\\"all\\\">所有人</at> \",\n" +
+                "                \"text_align\": \"left\",\n" +
+                "                \"text_size\": \"normal\"\n" +
+                "            },\n" +
+                "            {\n" +
+                "                \"tag\": \"column_set\",\n" +
+                "                \"flex_mode\": \"none\",\n" +
+                "                \"background_style\": \"default\",\n" +
+                "                \"horizontal_spacing\": \"8px\",\n" +
+                "                \"horizontal_align\": \"left\",\n" +
+                "                \"columns\": [\n" +
+                "                    {\n" +
+                "                        \"tag\": \"column\",\n" +
+                "                        \"width\": \"weighted\",\n" +
+                "                        \"vertical_align\": \"top\",\n" +
+                "                        \"vertical_spacing\": \"8px\",\n" +
+                "                        \"background_style\": \"default\",\n" +
+                "                        \"elements\": [\n" +
+                "                            {\n" +
+                "                                \"tag\": \"markdown\",\n" +
+                "                                \"content\": \"**公司名称:**\\n${customerName}\",\n" +
+                "                                \"text_align\": \"left\",\n" +
+                "                                \"text_size\": \"normal\"\n" +
+                "                            },\n" +
+                "                            {\n" +
+                "                                \"tag\": \"markdown\",\n" +
+                "                                \"content\": \"**群聊名称:**\\n${feiShuGroupName}\",\n" +
+                "                                \"text_align\": \"left\",\n" +
+                "                                \"text_size\": \"normal\"\n" +
+                "                            }\n" +
+                "                        ],\n" +
+                "                        \"weight\": 1\n" +
+                "                    },\n" +
+                "                    {\n" +
+                "                        \"tag\": \"column\",\n" +
+                "                        \"width\": \"weighted\",\n" +
+                "                        \"vertical_align\": \"top\",\n" +
+                "                        \"vertical_spacing\": \"8px\",\n" +
+                "                        \"background_style\": \"default\",\n" +
+                "                        \"elements\": [\n" +
+                "                            {\n" +
+                "                                \"tag\": \"markdown\",\n" +
+                "                                \"content\": \"**站点ID:**\\n${siteId}\",\n" +
+                "                                \"text_align\": \"left\",\n" +
+                "                                \"text_size\": \"normal\"\n" +
+                "                            },\n" +
+                "                            {\n" +
+                "                                \"tag\": \"markdown\",\n" +
+                "                                \"content\": \"**状态:**\\n${status}\",\n" +
+                "                                \"text_align\": \"left\",\n" +
+                "                                \"text_size\": \"normal\"\n" +
+                "                            }\n" +
+                "                        ],\n" +
+                "                        \"weight\": 1\n" +
+                "                    }\n" +
+                "                ],\n" +
+                "                \"margin\": \"16px 0px 0px 0px\"\n" +
+                "            },\n" +
+                "            {\n" +
+                "                \"tag\": \"hr\"\n" +
+                "            },\n" +
+                "            {\n" +
+                "                \"tag\": \"column_set\",\n" +
+                "                \"flex_mode\": \"none\",\n" +
+                "                \"horizontal_spacing\": \"default\",\n" +
+                "                \"background_style\": \"default\",\n" +
+                "                \"columns\": [\n" +
+                "                    {\n" +
+                "                        \"tag\": \"column\",\n" +
+                "                        \"elements\": [\n" +
+                "                            {\n" +
+                "                                \"tag\": \"div\",\n" +
+                "                                \"text\": {\n" +
+                "                                    \"tag\": \"plain_text\",\n" +
+                "                                    \"content\": \"来自 OK项目组-文档机器人\",\n" +
+                "                                    \"text_size\": \"normal\",\n" +
+                "                                    \"text_align\": \"left\",\n" +
+                "                                    \"text_color\": \"default\"\n" +
+                "                                }\n" +
+                "                            }\n" +
+                "                        ],\n" +
+                "                        \"width\": \"weighted\",\n" +
+                "                        \"weight\": 1\n" +
+                "                    }\n" +
+                "                ]\n" +
+                "            }\n" +
+                "        ]\n" +
+                "    },\n" +
+                "    \"i18n_header\": {\n" +
+                "        \"zh_cn\": {\n" +
+                "            \"title\": {\n" +
+                "                \"tag\": \"plain_text\",\n" +
+                "                \"content\": \"${title}\"\n" +
+                "            },\n" +
+                "            \"subtitle\": {\n" +
+                "                \"tag\": \"plain_text\",\n" +
+                "                \"content\": \"\"\n" +
+                "            },\n" +
+                "            \"template\": \"green\"\n" +
+                "        }\n" +
+                "    }\n" +
+                "}";
+        template = template.replace("${title}", "【" + customerName + "】创建飞书项目群通知");
+        template = template.replace("${customerName}", customerName);
+        template = template.replace("${siteId}", siteId);
+        template = template.replace("${feiShuGroupName}", feiShuGroupName);
+        template = template.replace("${status}", status);
+
+        JSONObject object = new JSONObject();
+        object.put("msg_type", "interactive");
+        object.put("card", template);
+        HttpClientUtil.doPostJson(botUrl, object.toJSONString());
+    }
 }

+ 22 - 91
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/site/service/impl/FeiShuSheetServiceImpl.java

@@ -1,20 +1,18 @@
 package org.jeecg.modules.okki.site.service.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.lark.oapi.Client;
-import com.lark.oapi.core.utils.Jsons;
 import com.lark.oapi.service.bitable.v1.model.*;
-import com.lark.oapi.service.im.v1.model.*;
 import lombok.extern.slf4j.Slf4j;
-import org.checkerframework.checker.units.qual.A;
 import org.jeecg.common.util.FastJsonUtil;
 import org.jeecg.modules.okki.account.entity.OkkiAccount;
 import org.jeecg.modules.okki.account.service.IOkkiAccountService;
 import org.jeecg.modules.okki.site.dto.FeiShuRecordSheetDto;
+import org.jeecg.modules.okki.site.entity.FeiShuConfigEnum;
 import org.jeecg.modules.okki.site.entity.OkkiSite;
 import org.jeecg.modules.okki.site.service.IFeiShuCommonService;
+import org.jeecg.modules.okki.site.service.IFeiShuGroupService;
 import org.jeecg.modules.okki.site.service.IFeiShuMsgService;
 import org.jeecg.modules.okki.site.service.IFeiShuSheetService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,21 +39,8 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
     @Autowired
     private IOkkiAccountService okkiAccountService;
 
-    public static String APP_ID = "cli_a61c977059f01013";
-
-    public static String APP_SECRET = "saNlFj2YdMXZ0uEAucyRodfSEp5ZHikR";
-
-    public static String APP_TOKEN = "X16RbjCVCasCmds7fn0c0k21nju";
-
-    /*
-      prod:客服团队表格ID
-     */
-    public static String KF_TABLE_ID = "tblSkc8HfEYDL99U";
-
-    /*
-     * dev:客服团队表格ID
-     */
-//    public static String KF_TABLE_ID = "tblqGDRNN9cDgCJm";
+    @Autowired
+    private IFeiShuGroupService feiShuGroupService;
 
 
     /**
@@ -63,14 +48,15 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
      */
     @Override
     public void syncWebsiteToFeiShuSheet(OkkiSite okkiSite) {
-        Client client = Client.newBuilder(APP_ID, APP_SECRET).build();
+        FeiShuConfigEnum configEnum = FeiShuConfigEnum.valueOf("DEV");
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
 
         Map<String, Object> map = new HashMap<>();
         map.put("公司名称", okkiSite.getCompanyName());
         map.put("网站ID", Integer.valueOf(okkiSite.getSiteId()));
         map.put("服务套餐", okkiSite.getTcName());
         map.put("状态", "正常");
-        CreateAppTableRecordReq req = CreateAppTableRecordReq.newBuilder().appToken(APP_TOKEN).tableId(KF_TABLE_ID)
+        CreateAppTableRecordReq req = CreateAppTableRecordReq.newBuilder().appToken(configEnum.getAppToken()).tableId(configEnum.getKfTableId())
                 .appTableRecord(AppTableRecord.newBuilder()
                         .fields(map)
                         .build())
@@ -101,7 +87,14 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
      */
     @Override
     public boolean updateFeiShuTableSheetField(FeiShuRecordSheetDto recordSheetDto) {
-        Map<String, List<JSONObject>> teamSheetMap = feiShuCommonService.getFeiShuTeamSheet(recordSheetDto.getGroupName());
+        List<String> targetGroups = new ArrayList<>();
+        targetGroups.add(recordSheetDto.getGroupName());
+        targetGroups.add("UI设计");
+        targetGroups.add("质检组");
+        // todo 临时增加
+        targetGroups.add("技术支持");
+//        targetGroups.add("项目管理");
+        Map<String, List<JSONObject>> teamSheetMap = feiShuCommonService.getFeiShuTeamSheet(targetGroups);
         log.info("teamSheetMap:{}", FastJsonUtil.toJSONString(teamSheetMap));
 
         List<JSONObject> jzGroups = teamSheetMap.get(recordSheetDto.getGroupName());
@@ -139,12 +132,9 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
         if (result) {
             List<String> omsAccountIds = new ArrayList<>();
             for (Map.Entry<String, List<JSONObject>> entry : teamSheetMap.entrySet()) {
-                String groupName = entry.getKey();
                 List<JSONObject> groupList = entry.getValue();
-                System.out.println("组名: " + groupName);
                 for (JSONObject group : groupList) {
                     String omsId = group.getString("OMS系统ID");
-                    System.out.println("OMS系统ID: " + omsId);
                     omsAccountIds.add(omsId);
                 }
             }
@@ -163,10 +153,13 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
                 sb.append(",").append(recordSheetDto.getSiteId());
                 account.setSiteIds(sb.toString());
 
-                okkiAccountService.bindSites(account);
+//                okkiAccountService.bindSites(account);
                 log.info("结束:第{}个 omsId:{} 的用户,绑定新站点", i + 1, omsId);
                 log.info("```````````````````");
             }
+
+            // 创建飞书群
+            feiShuGroupService.createFeiShuGroup(recordSheetDto.getCustomerName(), recordSheetDto.getSiteId(), recordSheetDto.getPlanName(), recordSheetDto.getGroupName());
         }
         return result;
     }
@@ -178,11 +171,12 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
      * @return
      */
     public boolean sendUpdateRequestFeiShuSheet(Map<String, Object> updateMap, FeiShuRecordSheetDto recordSheetDto) {
-        Client client = Client.newBuilder(APP_ID, APP_SECRET).build();
+        FeiShuConfigEnum configEnum = FeiShuConfigEnum.valueOf("DEV");
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
 
         UpdateAppTableRecordReq updateReq = UpdateAppTableRecordReq.newBuilder()
                 .appTableRecord(AppTableRecord.newBuilder()
-                        .fields(updateMap).build()).appToken(APP_TOKEN).tableId(KF_TABLE_ID).recordId(recordSheetDto.getRecordId())
+                        .fields(updateMap).build()).appToken(configEnum.getAppToken()).tableId(configEnum.getKfTableId()).recordId(recordSheetDto.getRecordId())
                 .build();
 
         // 发起请求
@@ -203,67 +197,4 @@ public class FeiShuSheetServiceImpl implements IFeiShuSheetService {
         feiShuMsgService.sendUpdateFeiShuSheetMsg(recordSheetDto.getCustomerName(), recordSheetDto.getSiteId(), recordSheetDto.getGroupName(), status);
         return updateResp.success();
     }
-
-    /**
-     * 发送创建飞书群
-     *
-     * @return
-     */
-    public void sendCreateFeiShuGroupRequest() {
-        // 构建client
-        Client client = Client.newBuilder("YOUR_APP_ID", "YOUR_APP_SECRET").build();
-
-        // 创建请求对象
-        CreateChatReq req = CreateChatReq.newBuilder()
-                .createChatReqBody(CreateChatReqBody.newBuilder()
-                        .avatar("default-avatar_44ae0ca3-e140-494b-956f-78091e348435")
-                        .name("测试群名称")
-                        .description("测试群描述")
-                        .i18nNames(I18nNames.newBuilder()
-                                .zhCn("群聊")
-                                .enUs("group chat")
-                                .build())
-                        .ownerId("ou_7d8a6e6df7621556ce0d21922b676706ccs")
-                        .userIdList(new String[]{
-                                "ou_7d8a6e6df7621556ce0d21922b676706ccs"
-                        })
-                        .botIdList(new String[]{
-                                "cli_a10fbf7e94b8d01d"
-                        })
-                        .groupMessageType("chat")
-                        .chatMode("group")
-                        .chatType("private")
-                        .joinMessageVisibility("all_members")
-                        .leaveMessageVisibility("all_members")
-                        .membershipApproval("no_approval_required")
-                        .restrictedModeSetting(RestrictedModeSetting.newBuilder()
-                                .status(false)
-                                .screenshotHasPermissionSetting("all_members")
-                                .downloadHasPermissionSetting("all_members")
-                                .messageHasPermissionSetting("all_members")
-                                .build())
-                        .urgentSetting("all_members")
-                        .videoConferenceSetting("all_members")
-                        .editPermission("all_members")
-                        .hideMemberCountSetting("all_members")
-                        .build())
-                .build();
-
-        // 发起请求
-        CreateChatResp resp = null;
-        try {
-            resp = client.im().chat().create(req);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-
-        // 处理服务端错误
-        if (!resp.success()) {
-            System.out.println(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
-            return;
-        }
-
-        // 业务数据处理
-        System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
-    }
 }