Kaynağa Gözat

增加客服消息提醒

Cyan 2 ay önce
ebeveyn
işleme
7933904a01

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

@@ -662,14 +662,15 @@ public class IFeiShuCommonService {
             JSONObject jsonObject = jsonArray.getJSONObject(i);
 //            log.info("jsonObject:{}", jsonObject.toJSONString());
             if (!jsonObject.isEmpty()) {
-                JSONObject enNameFieldsObj = jsonObject.getJSONObject("英文名称");
-                JSONArray enNameDataArray = enNameFieldsObj.getJSONArray("value");
-                String enNameKey = enNameDataArray.getJSONObject(0).getString("text");
-
-                if (!kfGroupData.containsKey(enNameKey)) {
-                    kfGroupData.put(enNameKey, new ArrayList<>());
+                if (jsonObject.containsKey("英文名称")) {
+                    JSONObject enNameFieldsObj = jsonObject.getJSONObject("英文名称");
+                    JSONArray enNameDataArray = enNameFieldsObj.getJSONArray("value");
+                    String enNameKey = enNameDataArray.getJSONObject(0).getString("text");
+                    if (!kfGroupData.containsKey(enNameKey)) {
+                        kfGroupData.put(enNameKey, new ArrayList<>());
+                    }
+                    kfGroupData.get(enNameKey).add(jsonObject);
                 }
-                kfGroupData.get(enNameKey).add(jsonObject);
             }
         }
         log.info("kfGroupData:{}", FastJsonUtil.toJSONString(kfGroupData));
@@ -714,4 +715,77 @@ public class IFeiShuCommonService {
             log.error("******* sendGroupMsg-error ******** :{}", String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
         }
     }
+
+    /**
+     * 拉入机器人加入飞书群
+     *
+     * @param chatId
+     * @param needJoinIdList
+     */
+    public void joinFeiShuGroupRequest(String chatId, List<String> needJoinIdList) {
+        FeiShuConfigEnum configEnum = FeiShuConfigManager.getInstance().getConfigEnum();
+
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
+        String[] needJoinIdsArr = needJoinIdList.toArray(new String[0]);
+
+        // 创建请求对象
+        CreateChatMembersReq req = CreateChatMembersReq.newBuilder()
+                .chatId(chatId)
+                .memberIdType("app_id")
+                .createChatMembersReqBody(CreateChatMembersReqBody.newBuilder()
+                        .idList(needJoinIdsArr)
+                        .build())
+                .build();
+
+        // 发起请求
+        CreateChatMembersResp resp = null;
+        try {
+            resp = client.im().chatMembers().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()));
+    }
+
+    /**
+     * 检查机器人或用户是否在群里
+     *
+     * @param chatId
+     */
+    public boolean checkBotOrUserIsExistGroup(String chatId) {
+        FeiShuConfigEnum configEnum = FeiShuConfigManager.getInstance().getConfigEnum();
+        // 构建client
+        Client client = Client.newBuilder(configEnum.getAppId(), configEnum.getAppSecret()).build();
+
+        // 创建请求对象
+        IsInChatChatMembersReq req = IsInChatChatMembersReq.newBuilder()
+                .chatId(chatId)
+                .build();
+
+        // 发起请求
+        IsInChatChatMembersResp resp = null;
+        try {
+            resp = client.im().chatMembers().isInChat(req);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        // 处理服务端错误
+        if (!resp.success()) {
+            log.error(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
+        }
+
+        // 业务数据处理
+//        log.info(Jsons.DEFAULT.toJson(resp.getData()));
+
+        return resp.getData().getIsInChat();
+    }
 }

+ 38 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/job/CheckBotIsExistJobGroup.java

@@ -0,0 +1,38 @@
+package org.jeecg.modules.okki.wechatgroup.job;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.okki.site.service.IOkCommonService;
+import org.jeecg.modules.okki.wechatgroup.service.IOkkiShopWechatGroupMsgService;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import javax.annotation.Resource;
+
+/**
+ * 检测机器人或用户是否在群中
+ *
+ * @author Chen
+ */
+@Slf4j
+public class CheckBotIsExistJobGroup implements Job {
+
+    @Resource
+    private IOkkiShopWechatGroupMsgService okkiShopWechatGroupMsgService;
+
+    private String parameter;
+
+    public void setParameter(String parameter) {
+        this.parameter = parameter;
+    }
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        long start = System.currentTimeMillis();
+        log.info(String.format("开始检测机器人或用户是否在群中-普通定时任务 CheckBotIsExistJobGroup !  时间:" + DateUtils.now()));
+        okkiShopWechatGroupMsgService.checkBotOrUserIsExistGroup();
+        long end = System.currentTimeMillis();
+        log.info("请求检测机器人或用户是否在群中-普通定时任务 CheckBotIsExistJobGroup !结束,耗时:{}s", (end - start) / 1000);
+    }
+}

+ 6 - 1
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/service/IOkkiShopWechatGroupMsgService.java

@@ -26,5 +26,10 @@ public interface IOkkiShopWechatGroupMsgService extends IService<OkkiShopWechatG
      * @param siteId
      * @return
      */
-    public void getWechatNoReplySiteByDays(String siteId,Integer days);
+    public void getWechatNoReplySiteByDays(String siteId, Integer days);
+
+    /**
+     * 检测机器人或用户是否在群中
+     */
+    public void checkBotOrUserIsExistGroup();
 }

+ 21 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/okki/wechatgroup/service/impl/OkkiShopWechatGroupMsgServiceImpl.java

@@ -272,4 +272,25 @@ public class OkkiShopWechatGroupMsgServiceImpl extends ServiceImpl<OkkiShopWecha
 //            });
         }
     }
+
+    /**
+     * 检测机器人或用户是否在群中
+     */
+    @Override
+    public void checkBotOrUserIsExistGroup() {
+        List<JSONObject> feiShuGroupNoExistList = new ArrayList<>();
+        List<JSONObject> allSiteList = getKfAllSiteList();
+        for (JSONObject jsonObject : allSiteList) {
+            String feiShuGroupId = jsonObject.getString("feiShuGroupId");
+            String feiShuGroupName = jsonObject.getString("companyName");
+            boolean isExistGroup = feiShuCommonService.checkBotOrUserIsExistGroup(feiShuGroupId);
+            if (!isExistGroup) {
+                JSONObject feiShuGroupInfoObj = new JSONObject();
+                feiShuGroupInfoObj.put("feiShuGroupId", feiShuGroupId);
+                feiShuGroupInfoObj.put("feiShuGroupName", feiShuGroupName);
+                feiShuGroupNoExistList.add(feiShuGroupInfoObj);
+            }
+        }
+        log.info("不存在“ OK助手” 机器人的群聊有:{}", FastJsonUtil.toJSONString(feiShuGroupNoExistList));
+    }
 }