From cf17a1a7a9916fe8be67f70c9f1ae1b5c61d8bb5 Mon Sep 17 00:00:00 2001 From: zhn <947514737@qq.com> Date: Wed, 26 Oct 2022 16:46:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E6=B8=85=E5=8D=95=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E5=92=8C=E6=92=A4=E5=9B=9E--=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=A3=9E=E4=B9=A6=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DummyInventoryBaseEOServiceImpl.java | 21 ++- .../feishu/service/IFeishuService.java | 10 ++ .../service/impl/FeishuServiceImpl.java | 127 ++++++++++++++++++ 3 files changed, 156 insertions(+), 2 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/dummy/service/impl/DummyInventoryBaseEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/dummy/service/impl/DummyInventoryBaseEOServiceImpl.java index 6af72e8d9..4df36d4e4 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/dummy/service/impl/DummyInventoryBaseEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/dummy/service/impl/DummyInventoryBaseEOServiceImpl.java @@ -29,6 +29,7 @@ import com.jero.modules.dummy.service.IDummyInventoryInfoEOService; import com.jero.modules.dummy.service.IDummyReadEOService; import com.jero.modules.dummy.vo.VirtualCreaterVo; import com.jero.modules.feishu.service.IFeishuService; +import com.jero.modules.feishu.vo.FeishuMsgVo; import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.system.entity.SysAnnouncement; @@ -366,6 +367,7 @@ public class DummyInventoryBaseEOServiceImpl extends ServiceImpl dummyInventoryInfoEOList = iDummyInventoryInfoEOService.list(lambdaQueryWrapper); String contentLog = "The "+ baseEO.getName()+" virtual list you subscribed to has been updated as follows:" + "
"; String contentLogFeishu = "The "+ baseEO.getName()+" virtual list you subscribed to has been updated as follows:" + " "; + String contentLogFeishuTemp = "The "+ baseEO.getName()+" virtual list you subscribed to has been updated as follows:" + " "; if(dummyContentChangeEOList.size() == 0){ //没有添加过需要进行第一次添加 @@ -449,7 +451,15 @@ public class DummyInventoryBaseEOServiceImpl extends ServiceImpl serialNumberAddList,List serialNumberDeleteList) throws IOException; + /** * 翻译文本 * @param params diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java index 9aa482c6f..0092c6858 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/feishu/service/impl/FeishuServiceImpl.java @@ -453,6 +453,133 @@ public class FeishuServiceImpl implements IFeishuService { + contentSb.append("\"header\": {"); + contentSb.append("\"template\": \"green\","); + contentSb.append("\"title\": {"); + contentSb.append("\"content\": \" " + feishuMsgVo.getTitle() + " \","); + contentSb.append("\"tag\": \"plain_text\""); + contentSb.append("}"); + contentSb.append("}"); + contentSb.append("}"); + + JSONObject jsonObject = JSONObject.parseObject(contentSb.toString()); + + // 设置请求参数 + JSONObject paramsMap = new JSONObject(); + paramsMap.put("user_ids", userIds); + paramsMap.put("msg_type", "interactive"); + paramsMap.put("card", jsonObject); + + // 发送请求给飞书 + String response = HttpRequestUtil.getResponseOfPOST(batchSendMessageUrl, headerMap, paramsMap.toJSONString()); + // 获取返回结果 + JSONObject tokenJson = JSONObject.parseObject(response); + if(!tokenJson.get("code").toString().equals("0")) { + log.error("请求出现异常:" + tokenJson.get("msg") + " " + tokenJson); + } + return tokenJson.get("msg").toString(); + } + /** + * 虚拟清单发布(飞书消息) + * @param userIds + * @param feishuMsgVo + * @return + * @throws IOException + */ + public String sendCardMsgVirtua(String[] userIds, FeishuMsgVo feishuMsgVo, + List serialNumberAddList,List serialNumberDeleteList) throws IOException { + String token = getTenantAccessToken(); + // 设置请求头 + Map headerMap = new HashMap<>(); + headerMap.put("Authorization", "Bearer " + token); + headerMap.put("Content-Type", "application/json; charset=utf-8"); + + // 示例 + StringBuilder contentSb = new StringBuilder(); + contentSb.append("{"); + contentSb.append("\"elements\": ["); + // 内容中文 + if (StrUtil.isNotEmpty(feishuMsgVo.getContent())){ + contentSb.append("{"); + contentSb.append("\"tag\": \"div\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"" + feishuMsgVo.getContent() + "\"\n,"); + contentSb.append("\"tag\": \"lark_md\""); + contentSb.append("}"); + contentSb.append("},"); + }; + if(ObjectUtils.isNotEmpty(serialNumberAddList)){ + int count = 1; + contentSb.append("{"); + contentSb.append("\"tag\": \"div\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"" + count + ". 新增文档: " + StringUtils.join(serialNumberAddList,",") + "\"\n,"); + contentSb.append("\"tag\": \"lark_md\""); + contentSb.append("}"); + contentSb.append("},"); + } + if(ObjectUtils.isNotEmpty(serialNumberDeleteList)){ + int count = 2; + contentSb.append("{"); + contentSb.append("\"tag\": \"div\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"" + count + ". 删除文档: " + StringUtils.join(serialNumberDeleteList,",") + "\"\n,"); + contentSb.append("\"tag\": \"lark_md\""); + contentSb.append("}"); + contentSb.append("},"); + } + contentSb.append("{\"tag\": \"hr\"},"); + + //内容英文 + if (StrUtil.isNotEmpty(feishuMsgVo.getContentEn())){ + contentSb.append("{"); + contentSb.append("\"tag\": \"div\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"" + feishuMsgVo.getContentEn() + "\"\n,"); + contentSb.append("\"tag\": \"lark_md\""); + contentSb.append("}"); + contentSb.append("},"); + }; + + if (ObjectUtils.isNotEmpty(serialNumberAddList)) { + int count = 1; + contentSb.append("{"); + contentSb.append("\"tag\": \"div\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"" + count + ". New regulations: " + StringUtils.join(serialNumberAddList,",") + "\"\n,"); + contentSb.append("\"tag\": \"lark_md\""); + contentSb.append("}"); + contentSb.append("},"); + } + if (ObjectUtils.isNotEmpty(serialNumberDeleteList)) { + int count = 2; + contentSb.append("{"); + contentSb.append("\"tag\": \"div\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"" + count + ". Remove regulations: " + StringUtils.join(serialNumberDeleteList,",") + "\"\n,"); + contentSb.append("\"tag\": \"lark_md\""); + contentSb.append("}"); + contentSb.append("},"); + } + + contentSb.append("{"); + contentSb.append("\"actions\": ["); + contentSb.append("{"); + contentSb.append("\"tag\": \"button\","); + contentSb.append("\"text\": {"); + contentSb.append("\"content\": \"view\","); + contentSb.append("\"tag\": \"plain_text\""); + contentSb.append("},"); + contentSb.append("\"type\": \"primary\","); + contentSb.append("\"url\": \" "+ feishuMsgVo.getUrl() +" \""); + contentSb.append("}"); + contentSb.append("],"); + contentSb.append("\"tag\": \"action\""); + contentSb.append("}"); + contentSb.append("],"); + + + contentSb.append("\"header\": {"); contentSb.append("\"template\": \"green\","); contentSb.append("\"title\": {");