From 1b4047386ee6a6090d1b67ce666d3191a99a7f7b Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Mon, 19 Oct 2020 18:48:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/controller/NoticeController.java | 2 +- .../notice/domain/MessageDetail.java | 1 - .../notice/service/NoticeService.java | 43 ++++++++++++++++--- .../track/service/TestCaseReviewService.java | 8 ++++ .../V34__modify_message_task_webhook.sql | 1 + .../organization/TaskNotification.vue | 14 +++--- 6 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 backend/src/main/resources/db/migration/V34__modify_message_task_webhook.sql diff --git a/backend/src/main/java/io/metersphere/notice/controller/NoticeController.java b/backend/src/main/java/io/metersphere/notice/controller/NoticeController.java index fdfe68436c..7696b2ba0f 100644 --- a/backend/src/main/java/io/metersphere/notice/controller/NoticeController.java +++ b/backend/src/main/java/io/metersphere/notice/controller/NoticeController.java @@ -32,7 +32,7 @@ public class NoticeController { } @GetMapping("/search/message") - public List searchMessage() { + public MessageSettingDetail searchMessage() { return noticeService.searchMessage(); } diff --git a/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java b/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java index 45f40beabf..2550cbc864 100644 --- a/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java +++ b/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java @@ -9,7 +9,6 @@ import java.util.List; @Data public class MessageDetail extends MessageTask { private List userIds = new ArrayList<>(); - private List userNames = new ArrayList<>(); private List events = new ArrayList<>(); private String taskType; private String webhook; diff --git a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java index 658001a1db..a46f49964e 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -8,6 +8,7 @@ import io.metersphere.base.mapper.MessageTaskMapper; import io.metersphere.base.mapper.NoticeMapper; import io.metersphere.notice.controller.request.MessageRequest; import io.metersphere.notice.controller.request.NoticeRequest; +import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.MessageSettingDetail; import io.metersphere.notice.domain.NoticeDetail; import org.apache.commons.collections4.CollectionUtils; @@ -16,7 +17,9 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; import static io.metersphere.commons.constants.NoticeConstants.EXECUTE_FAILED; import static io.metersphere.commons.constants.NoticeConstants.EXECUTE_SUCCESSFUL; @@ -86,7 +89,7 @@ public class NoticeService { } public void saveMessageTask(MessageRequest messageRequest) { - String identification=UUID.randomUUID().toString(); + String identification = UUID.randomUUID().toString(); messageRequest.getMessageDetail().forEach(list -> { list.getEvents().forEach(n -> { list.getUserIds().forEach(m -> { @@ -106,12 +109,42 @@ public class NoticeService { } - public List searchMessage() { + public MessageSettingDetail searchMessage() { MessageTaskExample messageTaskExample = new MessageTaskExample(); messageTaskExample.createCriteria(); - List messageTasks = new ArrayList<>(); - List messageSettingDetail = new ArrayList<>(); - messageTasks = messageTaskMapper.selectByExample(messageTaskExample); + List messageTaskLists = new ArrayList<>(); + List userIds = new ArrayList<>(); + List events = new ArrayList<>(); + MessageSettingDetail messageSettingDetail = new MessageSettingDetail(); + MessageDetail messageDetail = new MessageDetail(); + List MessageDetailList = new ArrayList<>(); + messageTaskLists = messageTaskMapper.selectByExample(messageTaskExample); + Map> MessageTaskMap = messageTaskLists.stream().collect(Collectors.groupingBy(e -> fetchGroupKey(e))); + MessageTaskMap.forEach((k, v) -> { + for (MessageTask m : v) { + userIds.add(m.getId()); + events.add(m.getEvent()); + messageDetail.setTaskType(m.getTaskType()); + messageDetail.setWebhook(m.getWebhook()); + messageDetail.setIdentification(m.getIdentification()); + messageDetail.setType(m.getType()); + } + messageDetail.setEvents(events); + messageDetail.setUserIds(userIds); + MessageDetailList.add(messageDetail); + }); + List jenkinsTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals("jenkinsTask")).collect(Collectors.toList()); + List testCasePlanTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals("testPlanTask")).collect(Collectors.toList()); + List reviewTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals("reviewTask")).collect(Collectors.toList()); + List defectTask = MessageDetailList.stream().filter(a -> a.getTaskType().equals("defect")).collect(Collectors.toList()); + messageSettingDetail.setJenkinsTask(jenkinsTask); + messageSettingDetail.setTestCasePlanTask(testCasePlanTask); + messageSettingDetail.setReviewTask(reviewTask); + messageSettingDetail.setDefectTask(defectTask); return messageSettingDetail; } + + private static String fetchGroupKey(MessageTask user) { + return user.getTaskType() + "#" + user.getIdentification(); + } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java index 5c61abc8a3..cfa95c4f88 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -15,8 +15,11 @@ import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.member.QueryMemberRequest; +import io.metersphere.notice.domain.MessageDetail; +import io.metersphere.notice.domain.MessageSettingDetail; import io.metersphere.notice.service.DingTaskService; import io.metersphere.notice.service.MailService; +import io.metersphere.notice.service.NoticeService; import io.metersphere.notice.service.WxChatTaskService; import io.metersphere.service.UserService; import io.metersphere.track.dto.TestCaseReviewDTO; @@ -77,6 +80,8 @@ public class TestCaseReviewService { DingTaskService dingTaskService; @Resource WxChatTaskService wxChatTaskService; + @Resource + NoticeService noticeService; public void saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) { checkCaseReviewExist(reviewRequest); @@ -105,6 +110,9 @@ public class TestCaseReviewService { reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name()); testCaseReviewMapper.insert(reviewRequest); String context = getReviewContext(reviewRequest, "create"); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List reviewTasklist = messageSettingDetail.getReviewTask(); + try { if (StringUtils.equals(NoticeConstants.NAIL_ROBOT, "NAIL_ROBOT")) { dingTaskService.sendDingTask(context, userIds); diff --git a/backend/src/main/resources/db/migration/V34__modify_message_task_webhook.sql b/backend/src/main/resources/db/migration/V34__modify_message_task_webhook.sql new file mode 100644 index 0000000000..7257542a37 --- /dev/null +++ b/backend/src/main/resources/db/migration/V34__modify_message_task_webhook.sql @@ -0,0 +1 @@ +alter table message_task modify webhook varchar(255) null comment 'webhook地址'; \ No newline at end of file diff --git a/frontend/src/business/components/settings/organization/TaskNotification.vue b/frontend/src/business/components/settings/organization/TaskNotification.vue index fac0df555f..1ce4d535b8 100644 --- a/frontend/src/business/components/settings/organization/TaskNotification.vue +++ b/frontend/src/business/components/settings/organization/TaskNotification.vue @@ -26,7 +26,7 @@ >