From 80fa6cd4b6b0b09b0fa8040f3734627ea73c0b99 Mon Sep 17 00:00:00 2001 From: wenyann Date: Fri, 9 Apr 2021 15:56:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E9=A3=9E=E4=B9=A6=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/constants/NoticeConstants.java | 1 + .../notice/sender/impl/LarkNoticeSender.java | 23 ++++++++ .../notice/service/NoticeSendService.java | 5 ++ .../metersphere/notice/util/LarkClient.java | 57 +++++++++++++++++++ .../components/DefectTaskNotification.vue | 4 +- .../components/JenkinsNotification.vue | 3 +- .../components/TestPlanTaskNotification.vue | 3 +- .../components/TestReviewNotification.vue | 4 +- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 11 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java create mode 100644 backend/src/main/java/io/metersphere/notice/util/LarkClient.java diff --git a/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java b/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java index 7708f1e78a..6371cb2ce3 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/NoticeConstants.java @@ -18,6 +18,7 @@ public interface NoticeConstants { String EMAIL = "EMAIL"; String NAIL_ROBOT = "NAIL_ROBOT"; String WECHAT_ROBOT = "WECHAT_ROBOT"; + String LARK = "LARK"; } interface Event { diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java new file mode 100644 index 0000000000..5c87507cdc --- /dev/null +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java @@ -0,0 +1,23 @@ +package io.metersphere.notice.sender.impl; + +import io.metersphere.notice.domain.MessageDetail; +import io.metersphere.notice.message.TextMessage; +import io.metersphere.notice.sender.AbstractNoticeSender; +import io.metersphere.notice.sender.NoticeModel; +import io.metersphere.notice.util.LarkClient; +import org.springframework.stereotype.Component; + +@Component +public class LarkNoticeSender extends AbstractNoticeSender { + + public void sendLark(MessageDetail messageDetail, String context) { + //TextMessage message = new TextMessage(context); + LarkClient.send(messageDetail.getWebhook(), context); + } + + @Override + public void send(MessageDetail messageDetail, NoticeModel noticeModel) { + String context = super.getContext(messageDetail, noticeModel); + sendLark(messageDetail, context); + } +} diff --git a/backend/src/main/java/io/metersphere/notice/service/NoticeSendService.java b/backend/src/main/java/io/metersphere/notice/service/NoticeSendService.java index e94433c6fd..453b7aec5d 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeSendService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeSendService.java @@ -7,6 +7,7 @@ import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.sender.NoticeSender; import io.metersphere.notice.sender.impl.DingNoticeSender; +import io.metersphere.notice.sender.impl.LarkNoticeSender; import io.metersphere.notice.sender.impl.MailNoticeSender; import io.metersphere.notice.sender.impl.WeComNoticeSender; import org.springframework.stereotype.Component; @@ -23,6 +24,8 @@ public class NoticeSendService { @Resource private DingNoticeSender dingNoticeSender; @Resource + private LarkNoticeSender larkNoticeSender; + @Resource private NoticeService noticeService; private NoticeSender getNoticeSender(MessageDetail messageDetail) { @@ -37,6 +40,8 @@ public class NoticeSendService { case NoticeConstants.Type.NAIL_ROBOT: noticeSender = dingNoticeSender; break; + case NoticeConstants.Type.LARK: + noticeSender = larkNoticeSender; default: break; } diff --git a/backend/src/main/java/io/metersphere/notice/util/LarkClient.java b/backend/src/main/java/io/metersphere/notice/util/LarkClient.java new file mode 100644 index 0000000000..024de5c177 --- /dev/null +++ b/backend/src/main/java/io/metersphere/notice/util/LarkClient.java @@ -0,0 +1,57 @@ +package io.metersphere.notice.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import io.metersphere.notice.message.Message; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +public class LarkClient { + public static SendResult send(String webhook, String context) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = null; + Map mp = new LinkedHashMap<>(); + JSONObject js = new JSONObject(); + js.put("text", context); + mp.put("msg_type", "text"); + mp.put("content", js); + SendResult sendResult = new SendResult(); + try { + // 创建Http Post请求 + HttpPost httpPost = new HttpPost(webhook); + // 创建请求内容 + StringEntity entity = new StringEntity(JSON.toJSONString(mp), ContentType.APPLICATION_JSON); + httpPost.setEntity(entity); + // 执行http请求 + response = httpClient.execute(httpPost); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + String result = EntityUtils.toString(response.getEntity()); + JSONObject obj = JSONObject.parseObject(result); + Integer errcode = obj.getInteger("errcode"); + sendResult.setErrorCode(errcode); + sendResult.setErrorMsg(obj.getString("errmsg")); + sendResult.setIsSuccess(errcode.equals(0)); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return sendResult; + } +} diff --git a/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue b/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue index 5ecf49e25a..dcf6799914 100644 --- a/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue +++ b/frontend/src/business/components/settings/organization/components/DefectTaskNotification.vue @@ -182,7 +182,9 @@ export default { receiveTypeOptions: [ {value: 'EMAIL', label: this.$t('organization.message.mail')}, {value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')}, - {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')} + {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}, + {value: 'LARK', label: this.$t('organization.message.lark')} + ], }; }, diff --git a/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue b/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue index f66c54bbbf..57e51e0358 100644 --- a/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue +++ b/frontend/src/business/components/settings/organization/components/JenkinsNotification.vue @@ -203,7 +203,8 @@ export default { receiveTypeOptions: [ {value: 'EMAIL', label: this.$t('organization.message.mail')}, {value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')}, - {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')} + {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}, + {value: 'LARK', label: this.$t('organization.message.lark')} ], } }, diff --git a/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue b/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue index 2731e06c65..a5fdf40d64 100644 --- a/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue +++ b/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue @@ -192,7 +192,8 @@ export default { receiveTypeOptions: [ {value: 'EMAIL', label: this.$t('organization.message.mail')}, {value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')}, - {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')} + {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}, + {value: 'LARK', label: this.$t('organization.message.lark')} ], }; }, diff --git a/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue b/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue index a95baa9301..5d3896b62e 100644 --- a/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue +++ b/frontend/src/business/components/settings/organization/components/TestReviewNotification.vue @@ -192,7 +192,9 @@ export default { receiveTypeOptions: [ {value: 'EMAIL', label: this.$t('organization.message.mail')}, {value: 'NAIL_ROBOT', label: this.$t('organization.message.nail_robot')}, - {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')} + {value: 'WECHAT_ROBOT', label: this.$t('organization.message.enterprise_wechat_robot')}, + {value: 'LARK', label: this.$t('organization.message.lark')} + ], }; }, diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 68f4cbc1be..5da889c3f0 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -298,6 +298,7 @@ export default { mail: 'mail', nail_robot: 'Nail robot', enterprise_wechat_robot: 'Enterprise wechat robot', + lark: "Flying Book Robot", notes: '1. Nail and create a custom robot in the enterprise group, and then copy the webhook address on our platform;\n' + '\n' + '2. Robots are selected as swarm robots, and "custom keyword" is selected for security verification: "task notification";\n' + diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 1e07b802c3..c23c7ad2cb 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -299,6 +299,7 @@ export default { mail: '邮件', nail_robot: '钉钉机器人', enterprise_wechat_robot: '企业微信机器人', + lark: '飞书机器人', notes: '1.钉钉和企业群里新建一个自定义机器人,然后复制 webhook 地址在我们平台上;\n' + ' 2.机器人选择为群机器人,安全验证选择“自定义关键词” :"任务通知";\n' + ' 3.选择接收人时必须是你所建的群里包含的人,接收人手机号为必填项且为钉钉企业所使用的手机号,', diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 3026149b9f..554e2e83f8 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -299,6 +299,7 @@ export default { mail: '郵件', nail_robot: '釘釘機器人', enterprise_wechat_robot: '企業微信機器人', + lark: '飛書機器人', notes: '1.釘釘和企業群裏新建壹個自定義機器人,然後復制 webhook 地址在我們平臺上;\n' + ' 2.機器人選擇為群機器人,安全驗證選擇“自定義關鍵詞” :"任務通知";\n' + ' 3.選擇接收人時必須是妳所建的群裏包含的人,接收人手機號為必填項且為釘釘企業所使用的手機號,',