From 3e00db101134cdb2216a9207103fc20d02ea3f35 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 3 Dec 2020 15:57:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=80=9A=E7=9F=A5=E7=9A=84=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/jmeter/APIBackendListenerClient.java | 8 ++++++++ .../io/metersphere/notice/sender/NoticeModel.java | 4 ++++ .../notice/service/NoticeSendService.java | 13 ++++++++++--- .../performance/notice/PerformanceNoticeTask.java | 9 +++++++++ .../io/metersphere/track/service/IssuesService.java | 1 + .../track/service/TestCaseCommentService.java | 1 + .../track/service/TestCaseReviewService.java | 4 ++++ .../metersphere/track/service/TestPlanService.java | 10 +++++++--- 8 files changed, 44 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 1110787a35..46dd2f08b8 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -216,6 +216,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl String successContext = ""; String failedContext = ""; String subject = ""; + String event = ""; if (StringUtils.equals(NoticeConstants.Mode.API, report.getTriggerMode())) { successContext = "接口测试 API任务通知:'" + report.getName() + "'执行成功" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; failedContext = "接口测试 API任务通知:'" + report.getName() + "'执行失败" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; @@ -226,6 +227,12 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl failedContext = "接口测试定时任务通知:'" + report.getName() + "'执行失败" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; subject = Translator.get("task_notification"); } + if (StringUtils.equals("Success", report.getStatus())) { + event = NoticeConstants.Event.EXECUTE_SUCCESSFUL; + } + if (StringUtils.equals("Error", report.getStatus())) { + event = NoticeConstants.Event.EXECUTE_FAILED; + } NoticeModel noticeModel = NoticeModel.builder() .successContext(successContext) @@ -234,6 +241,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl .failedMailTemplate("ApiFailedNotification") .testId(testResult.getTestId()) .status(report.getStatus()) + .event(event) .subject(subject) .build(); noticeSendService.send(report.getTriggerMode(), noticeModel); diff --git a/backend/src/main/java/io/metersphere/notice/sender/NoticeModel.java b/backend/src/main/java/io/metersphere/notice/sender/NoticeModel.java index bdfec0b3d0..bef8bda4d0 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/NoticeModel.java +++ b/backend/src/main/java/io/metersphere/notice/sender/NoticeModel.java @@ -17,6 +17,10 @@ public class NoticeModel { * 保存状态 */ private String status; + /** + * Event + */ + private String event; /** * 消息主题 */ 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 597820a06a..1adc46a06b 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeSendService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeSendService.java @@ -1,5 +1,6 @@ package io.metersphere.notice.service; +import com.alibaba.nacos.client.utils.StringUtils; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.notice.domain.MessageDetail; @@ -22,6 +23,10 @@ public class NoticeSendService { @Resource private DingNoticeSender dingNoticeSender; + private void event(String event) { + + } + private NoticeSender getNoticeSender(MessageDetail messageDetail) { NoticeSender noticeSender = null; switch (messageDetail.getType()) { @@ -56,8 +61,10 @@ public class NoticeSendService { messageDetails = noticeService.searchMessageByType(taskType); break; } - messageDetails.forEach(messageDetail -> - this.getNoticeSender(messageDetail).send(messageDetail, noticeModel) - ); + messageDetails.forEach(messageDetail -> { + if (StringUtils.equals(messageDetail.getEvent(), noticeModel.getEvent())) { + this.getNoticeSender(messageDetail).send(messageDetail, noticeModel); + } + }); } } diff --git a/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java index 8525f51a34..6b9ea8226f 100644 --- a/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java +++ b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java @@ -63,6 +63,7 @@ public class PerformanceNoticeTask { String successContext = ""; String failedContext = ""; String subject = ""; + String event = ""; if (StringUtils.equals(NoticeConstants.Mode.API, loadTestReport.getTriggerMode())) { successContext = "性能测试 API任务通知:" + loadTestReport.getName() + "执行成功" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; failedContext = "性能测试 API任务通知:" + loadTestReport.getName() + "执行失败" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + url; @@ -74,6 +75,13 @@ public class PerformanceNoticeTask { subject = Translator.get("task_notification"); } + if (PerformanceTestStatus.Completed.name().equals(loadTestReport.getStatus())) { + event = NoticeConstants.Event.EXECUTE_SUCCESSFUL; + } + if (PerformanceTestStatus.Error.name().equals(loadTestReport.getStatus())) { + event = NoticeConstants.Event.EXECUTE_FAILED; + } + NoticeModel noticeModel = NoticeModel.builder() .successContext(successContext) .successMailTemplate("PerformanceApiSuccessNotification") @@ -82,6 +90,7 @@ public class PerformanceNoticeTask { .testId(loadTestReport.getTestId()) .status(loadTestReport.getStatus()) .subject(subject) + .event(event) .build(); noticeSendService.send(loadTestReport.getTriggerMode(), noticeModel); } diff --git a/backend/src/main/java/io/metersphere/track/service/IssuesService.java b/backend/src/main/java/io/metersphere/track/service/IssuesService.java index c2aefecbf9..4239dbb49e 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -100,6 +100,7 @@ public class IssuesService { .subject(Translator.get("task_defect_notification")) .mailTemplate("IssuesCreate") .paramMap(paramMap) + .event(NoticeConstants.Event.CREATE) .build(); noticeSendService.send(NoticeConstants.TaskType.DEFECT_TASK, noticeModel); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java index 1aa688a420..1410744fc1 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java @@ -73,6 +73,7 @@ public class TestCaseCommentService { .subject(Translator.get("test_review_task_notice")) .mailTemplate("ReviewComments") .paramMap(paramMap) + .event(NoticeConstants.Event.COMMENT) .build(); noticeSendService.send(NoticeConstants.TaskType.REVIEW_TASK, noticeModel); } 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 a3ab852fa1..cf68b5e59a 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -112,6 +112,7 @@ public class TestCaseReviewService { .subject(Translator.get("test_review_task_notice")) .mailTemplate("ReviewInitiate") .paramMap(paramMap) + .event(NoticeConstants.Event.CREATE) .build(); noticeSendService.send(NoticeConstants.TaskType.REVIEW_TASK, noticeModel); } @@ -216,6 +217,7 @@ public class TestCaseReviewService { .subject(Translator.get("test_review_task_notice")) .mailTemplate("ReviewEnd") .paramMap(paramMap) + .event(NoticeConstants.Event.UPDATE) .build(); noticeSendService.send(NoticeConstants.TaskType.REVIEW_TASK, noticeModel); } @@ -318,6 +320,7 @@ public class TestCaseReviewService { .subject(Translator.get("test_review_task_notice")) .mailTemplate("ReviewDelete") .paramMap(paramMap) + .event(NoticeConstants.Event.DELETE) .build(); noticeSendService.send(NoticeConstants.TaskType.REVIEW_TASK, noticeModel); } catch (Exception e) { @@ -460,6 +463,7 @@ public class TestCaseReviewService { .subject(Translator.get("test_review_task_notice")) .mailTemplate("ReviewEnd") .paramMap(paramMap) + .event(NoticeConstants.Event.UPDATE) .build(); noticeSendService.send(NoticeConstants.TaskType.REVIEW_TASK, noticeModel); } catch (Exception e) { diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 850e9fd3e8..36bfad4a84 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -115,6 +115,7 @@ public class TestPlanService { .subject(Translator.get("test_plan_notification")) .mailTemplate("TestPlanStart") .paramMap(paramMap) + .event(NoticeConstants.Event.CREATE) .build(); noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel); } @@ -158,6 +159,7 @@ public class TestPlanService { .subject(Translator.get("test_plan_notification")) .mailTemplate("TestPlanEnd") .paramMap(paramMap) + .event(NoticeConstants.Event.UPDATE) .build(); noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel); } @@ -258,9 +260,9 @@ public class TestPlanService { deleteTestCaseByPlanId(planId); testPlanProjectService.deleteTestPlanProjectByPlanId(planId); int num = testPlanMapper.deleteByPrimaryKey(planId); - List userIds = new ArrayList<>(); + List relatedUsers = new ArrayList<>(); AddTestPlanRequest testPlans = new AddTestPlanRequest(); - userIds.add(testPlan.getCreator()); + relatedUsers.add(testPlan.getCreator()); try { BeanUtils.copyBean(testPlans, testPlan); String context = getTestPlanContext(testPlans, NoticeConstants.Event.DELETE); @@ -269,10 +271,11 @@ public class TestPlanService { paramMap.put("creator", user.getName()); NoticeModel noticeModel = NoticeModel.builder() .context(context) - .relatedUsers(userIds) + .relatedUsers(relatedUsers) .subject(Translator.get("test_plan_notification")) .mailTemplate("TestPlanDelete") .paramMap(paramMap) + .event(NoticeConstants.Event.DELETE) .build(); noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel); } catch (Exception e) { @@ -510,6 +513,7 @@ public class TestPlanService { .subject(Translator.get("test_plan_notification")) .mailTemplate("TestPlanEnd") .paramMap(paramMap) + .event(NoticeConstants.Event.UPDATE) .build(); noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel); } catch (Exception e) {