From 6b5361f8b200e88cdce704519996cc3a9df84d4b Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Mon, 26 Oct 2020 17:12:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(=E6=B6=88=E6=81=AF=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/service/MailService.java | 21 ++- .../notice/PerformanceNoticeTask.java | 148 ++++++++++++++++++ .../service/PerformanceTestService.java | 12 +- .../common/components/MsScheduleEdit.vue | 1 + 4 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index 0cc41c63e0..bc1367ce5d 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -112,6 +112,25 @@ public class MailService { LogUtil.error(e); } } + public void sendLoadJenkinsNotification(String context, MessageDetail messageDetail) throws MessagingException { + JavaMailSenderImpl javaMailSender = getMailSender(); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setFrom(javaMailSender.getUsername()); + helper.setSubject("MeterSphere平台" + Translator.get("task_notification")); + helper.setText(context); + List list = userService.queryTypeByIds(messageDetail.getUserIds()); + List EmailList = new ArrayList<>(); + list.forEach(u -> { + EmailList.add(u.getEmail()); + }); + helper.setTo(EmailList.toArray(new String[0])); + try { + javaMailSender.send(mimeMessage); + } catch (MailException e) { + LogUtil.error(e); + } + } private void sendHtmlTimeTasks(List noticeList, String status, Map context, String template) throws MessagingException { JavaMailSenderImpl javaMailSender = getMailSender(); @@ -168,7 +187,7 @@ public class MailService { } } -/*新建评审*/ + //新建评审 public void sendReviewerNotice(MessageDetail messageDetail, List userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) { Map context = getReviewContext(reviewRequest); try { diff --git a/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java new file mode 100644 index 0000000000..5e5eb45d51 --- /dev/null +++ b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java @@ -0,0 +1,148 @@ +package io.metersphere.performance.notice; + +import io.metersphere.base.domain.LoadTest; +import io.metersphere.base.domain.LoadTestWithBLOBs; +import io.metersphere.base.mapper.LoadTestMapper; +import io.metersphere.commons.constants.NoticeConstants; +import io.metersphere.commons.constants.PerformanceTestStatus; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.notice.domain.MessageDetail; +import io.metersphere.notice.domain.MessageSettingDetail; +import io.metersphere.notice.domain.NoticeDetail; +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 org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.PreDestroy; +import javax.annotation.Resource; +import javax.mail.MessagingException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +@Component +public class PerformanceNoticeTask { + @Resource + private NoticeService noticeService; + @Resource + private DingTaskService dingTaskService; + @Resource + private WxChatTaskService wxChatTaskService; + @Resource + private MailService mailService; + @Resource + private LoadTestMapper loadTestMapper; + private final ExecutorService executorService = Executors.newFixedThreadPool(20); + private boolean isRunning = true; + + @PreDestroy + public void preDestroy() { + isRunning = false; + } + public void registerNoticeTask(String triggerMode,LoadTestWithBLOBs loadTest) { + executorService.submit(() -> { + while (isRunning) { + LoadTestWithBLOBs result = loadTestMapper.selectByPrimaryKey(loadTest.getId()); + if (StringUtils.equals(result.getStatus(), PerformanceTestStatus.Completed.name())) { + isRunning = false; + sendSuccessNotice(triggerMode,loadTest); + return; + } + if (StringUtils.equals(result.getStatus(), PerformanceTestStatus.Error.name())) { + isRunning = false; + sendFailNotice(triggerMode,loadTest); + return; + } + try { + Thread.sleep(1000 * 60);// 每分钟检查 loadtest 的状态 + } catch (InterruptedException e) { + LogUtil.error(e); + } + } + }); + } + + public void sendSuccessNotice(String triggerMode,LoadTestWithBLOBs loadTest) { + if (StringUtils.equals(NoticeConstants.API, "API")||StringUtils.equals(NoticeConstants.SCHEDULE,"SCHEDULE")) { + List userIds = new ArrayList<>(); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getJenkinsTask(); + if(StringUtils.equals(triggerMode,NoticeConstants.SCHEDULE)){ + List noticeList = null; + noticeList = noticeService.queryNotice(loadTest.getId()); + mailService.sendPerformanceNotification(noticeList, PerformanceTestStatus.Completed.name(), loadTest, loadTest.getId()); }else{ + return; + } + + if(StringUtils.equals(triggerMode,NoticeConstants.SCHEDULE)){ + String contextSuccess=""; + contextSuccess = "jenkins任务通知:" + loadTest.getName() + "执行成功"; + String finalContextSuccess = contextSuccess; + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) + && StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) { + dingTaskService.sendNailRobot(r, userIds, finalContextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); + } + break; + case NoticeConstants.WECHAT_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) + && StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) { + wxChatTaskService.sendWechatRobot(r, userIds, finalContextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); + } + break; + case NoticeConstants.EMAIL: + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) + && StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) { + try { + mailService.sendLoadJenkinsNotification(finalContextSuccess, r); + } catch (MessagingException messagingException) { + messagingException.printStackTrace(); + } + } + break; + } + }); + } + + } + } + + public void sendFailNotice(String triggerMode,LoadTestWithBLOBs loadTest) { + if (StringUtils.equals(NoticeConstants.API, "API")) { + List userIds = new ArrayList<>(); + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + List taskList = messageSettingDetail.getJenkinsTask(); + String contextFailed = "jenkins任务通知:" + loadTest.getName() + "执行失败"; + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) { + dingTaskService.sendNailRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); + } + break; + case NoticeConstants.WECHAT_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) { + wxChatTaskService.sendWechatRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); + } + break; + case NoticeConstants.EMAIL: + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) { + try { + mailService.sendLoadJenkinsNotification(contextFailed, r); + } catch (MessagingException messagingException) { + messagingException.printStackTrace(); + } + } + break; + } + }); + } + } + +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index b875affa93..104535e532 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -24,6 +24,7 @@ import io.metersphere.notice.service.MailService; import io.metersphere.notice.service.NoticeService; import io.metersphere.performance.engine.Engine; import io.metersphere.performance.engine.EngineFactory; +import io.metersphere.performance.notice.PerformanceNoticeTask; import io.metersphere.service.FileService; import io.metersphere.service.QuotaService; import io.metersphere.service.ScheduleService; @@ -68,25 +69,21 @@ public class PerformanceTestService { @Resource private ExtLoadTestReportDetailMapper extLoadTestReportDetailMapper; @Resource - private LoadTestReportLogMapper loadTestReportLogMapper; - @Resource private LoadTestReportResultMapper loadTestReportResultMapper; @Resource - private TestResourceService testResourceService; - @Resource private ReportService reportService; @Resource private KafkaProperties kafkaProperties; @Resource private ScheduleService scheduleService; @Resource - private TestCaseMapper testCaseMapper; - @Resource private TestCaseService testCaseService; @Resource private NoticeService noticeService; @Resource private MailService mailService; + @Resource + private PerformanceNoticeTask performanceNoticeTask; public List list(QueryTestPlanRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); @@ -247,6 +244,9 @@ public class PerformanceTestService { LogUtil.error(e.getMessage(), e); } } + if(request.getTriggerMode().equals("API")){ + performanceNoticeTask.registerNoticeTask(request.getTriggerMode(),loadTest); + } return engine.getReportId(); } diff --git a/frontend/src/business/components/common/components/MsScheduleEdit.vue b/frontend/src/business/components/common/components/MsScheduleEdit.vue index bebe10f7fc..a81ed058ee 100644 --- a/frontend/src/business/components/common/components/MsScheduleEdit.vue +++ b/frontend/src/business/components/common/components/MsScheduleEdit.vue @@ -66,6 +66,7 @@ prop="type" :label="$t('schedule.receiving_mode')" > + Date: Wed, 28 Oct 2020 18:54:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/jmeter/APIBackendListenerClient.java | 70 ++-- .../metersphere/base/domain/MessageTask.java | 5 +- .../base/domain/MessageTaskExample.java | 70 ++++ .../base/mapper/MessageTaskMapper.xml | 66 ++-- .../notice/controller/NoticeController.java | 18 +- .../notice/domain/MessageDetail.java | 2 +- .../notice/service/MailService.java | 325 +++++++----------- .../notice/service/NoticeService.java | 120 +++---- .../notice/PerformanceNoticeTask.java | 162 +++++---- .../service/PerformanceTestService.java | 26 +- .../V37__modify_message_task_test_id.sql | 2 + .../resources/i18n/messages_en_US.properties | 2 +- .../resources/i18n/messages_zh_CN.properties | 5 +- .../resources/i18n/messages_zh_TW.properties | 3 +- .../{fail.html => ApiFailedNotification.html} | 5 +- ...ss.html => ApiSuccessfulNotification.html} | 2 +- .../{issuesCreate.html => IssuesCreate.html} | 0 ...=> PerformanceApiSuccessNotification.html} | 3 - ...tml => PerformanceFailedNotification.html} | 3 - .../{comment.html => ReviewComments.html} | 0 .../{deleteReview.html => ReviewDelete.html} | 0 .../mail/{end.html => ReviewEnd.html} | 0 .../{reviewer.html => ReviewInitiate.html} | 0 ...estPlanDelete.html => TestPlanDelete.html} | 0 .../{testPlanEnd.html => TestPlanEnd.html} | 0 ...{testPlanStart.html => TestPlanStart.html} | 0 .../common/components/MsScheduleEdit.vue | 120 ++----- .../components/DefectTaskNotification.vue | 9 + .../components/JenkinsNotification.vue | 11 +- .../components/ScheduleTaskNotification.vue | 222 ++++++++++++ .../components/TestPlanTaskNotification.vue | 9 + .../components/TestReviewNotification.vue | 9 + 32 files changed, 722 insertions(+), 547 deletions(-) create mode 100644 backend/src/main/resources/db/migration/V37__modify_message_task_test_id.sql rename backend/src/main/resources/mail/{fail.html => ApiFailedNotification.html} (77%) rename backend/src/main/resources/mail/{success.html => ApiSuccessfulNotification.html} (87%) rename backend/src/main/resources/mail/{issuesCreate.html => IssuesCreate.html} (100%) rename backend/src/main/resources/mail/{successPerformance.html => PerformanceApiSuccessNotification.html} (88%) rename backend/src/main/resources/mail/{failPerformance.html => PerformanceFailedNotification.html} (82%) rename backend/src/main/resources/mail/{comment.html => ReviewComments.html} (100%) rename backend/src/main/resources/mail/{deleteReview.html => ReviewDelete.html} (100%) rename backend/src/main/resources/mail/{end.html => ReviewEnd.html} (100%) rename backend/src/main/resources/mail/{reviewer.html => ReviewInitiate.html} (100%) rename backend/src/main/resources/mail/{testPlanDelete.html => TestPlanDelete.html} (100%) rename backend/src/main/resources/mail/{testPlanEnd.html => TestPlanEnd.html} (100%) rename backend/src/main/resources/mail/{testPlanStart.html => TestPlanStart.html} (100%) create mode 100644 frontend/src/business/components/settings/organization/components/ScheduleTaskNotification.vue 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 a483fd82a4..d4a4a98a8d 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -9,13 +9,14 @@ import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.TestPlanTestCaseStatus; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.MessageSettingDetail; -import io.metersphere.notice.domain.NoticeDetail; 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.SystemParameterService; import io.metersphere.track.service.TestPlanTestCaseService; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.assertions.AssertionResult; @@ -24,7 +25,6 @@ import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient; import org.apache.jmeter.visualizers.backend.BackendListenerContext; import org.springframework.http.HttpMethod; -import javax.mail.MessagingException; import java.io.Serializable; import java.util.*; @@ -174,51 +174,55 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl MailService mailService = CommonBeanFactory.getBean(MailService.class); DingTaskService dingTaskService = CommonBeanFactory.getBean(DingTaskService.class); WxChatTaskService wxChatTaskService = CommonBeanFactory.getBean(WxChatTaskService.class); - if (StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) { - List noticeList = noticeService.queryNotice(testResult.getTestId()); - mailService.sendApiNotification(report, noticeList); - } - if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode())) { + SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); + if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode()) || StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) { List userIds = new ArrayList<>(); - MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); - List taskList = messageSettingDetail.getJenkinsTask(); - String contextSuccess = "jenkins任务通知" + report.getName() + "执行成功"; - String contextFailed = "jenkins任务通知" + report.getName() + "执行失败"; + List taskList = new ArrayList<>(); + String successContext = ""; + String failedContext = ""; + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + String url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId(); + if (StringUtils.equals(NoticeConstants.API, report.getTriggerMode())) { + MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); + taskList = messageSettingDetail.getJenkinsTask(); + successContext = "jenkins任务通知:" + report.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url; + failedContext = "jenkins任务通知:" + report.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url; + } + if (StringUtils.equals(NoticeConstants.SCHEDULE, report.getTriggerMode())) { + taskList = noticeService.searchMessageSchedule(testResult.getTestId()); + successContext = "定时任务通知:" + report.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url; + failedContext = "定时任务通知:" + report.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url; + } + String finalSuccessContext = successContext; + String finalFailedContext = failedContext; taskList.forEach(r -> { switch (r.getType()) { case NoticeConstants.NAIL_ROBOT: if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) { - dingTaskService.sendNailRobot(r, userIds, contextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); + dingTaskService.sendNailRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL); } if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) { - dingTaskService.sendNailRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); + dingTaskService.sendNailRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED); } break; case NoticeConstants.WECHAT_ROBOT: - if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) { - wxChatTaskService.sendWechatRobot(r, userIds, contextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); - } - if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) { - wxChatTaskService.sendWechatRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); - } + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) { + wxChatTaskService.sendWechatRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL); + } + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) { + wxChatTaskService.sendWechatRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED); + } break; case NoticeConstants.EMAIL: - if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) { - try { - mailService.sendApiJenkinsNotification(contextSuccess, r); - } catch (MessagingException messagingException) { - messagingException.printStackTrace(); - } - } - if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) { - try { - mailService.sendApiJenkinsNotification(contextFailed, r); - } catch (MessagingException messagingException) { - messagingException.printStackTrace(); - } - } + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(report.getStatus(), "Success")) { + mailService.sendApiNotification(r, report, NoticeConstants.EXECUTE_SUCCESSFUL); + } + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(report.getStatus(), "Error")) { + mailService.sendApiNotification(r, report, NoticeConstants.EXECUTE_FAILED); + } break; } + }); } } diff --git a/backend/src/main/java/io/metersphere/base/domain/MessageTask.java b/backend/src/main/java/io/metersphere/base/domain/MessageTask.java index 37171c38f7..4cd0f6414c 100644 --- a/backend/src/main/java/io/metersphere/base/domain/MessageTask.java +++ b/backend/src/main/java/io/metersphere/base/domain/MessageTask.java @@ -1,8 +1,9 @@ package io.metersphere.base.domain; -import java.io.Serializable; import lombok.Data; +import java.io.Serializable; + @Data public class MessageTask implements Serializable { private String id; @@ -23,5 +24,7 @@ public class MessageTask implements Serializable { private String organizationId; + private String testId; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java b/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java index 5c41e252c8..b3d4c40f81 100644 --- a/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/MessageTaskExample.java @@ -723,6 +723,76 @@ public class MessageTaskExample { addCriterion("organization_id not between", value1, value2, "organizationId"); return (Criteria) this; } + + public Criteria andTestIdIsNull() { + addCriterion("test_id is null"); + return (Criteria) this; + } + + public Criteria andTestIdIsNotNull() { + addCriterion("test_id is not null"); + return (Criteria) this; + } + + public Criteria andTestIdEqualTo(String value) { + addCriterion("test_id =", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotEqualTo(String value) { + addCriterion("test_id <>", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdGreaterThan(String value) { + addCriterion("test_id >", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdGreaterThanOrEqualTo(String value) { + addCriterion("test_id >=", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdLessThan(String value) { + addCriterion("test_id <", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdLessThanOrEqualTo(String value) { + addCriterion("test_id <=", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdLike(String value) { + addCriterion("test_id like", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotLike(String value) { + addCriterion("test_id not like", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdIn(List values) { + addCriterion("test_id in", values, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotIn(List values) { + addCriterion("test_id not in", values, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdBetween(String value1, String value2) { + addCriterion("test_id between", value1, value2, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotBetween(String value1, String value2) { + addCriterion("test_id not between", value1, value2, "testId"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml index a8e662fb8a..b1bc62303a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/MessageTaskMapper.xml @@ -11,6 +11,7 @@ + @@ -71,7 +72,8 @@ - id, `type`, event, user_id, task_type, webhook, identification, is_set, organization_id + id, `type`, event, user_id, task_type, webhook, identification, is_set, organization_id, + test_id @@ -210,6 +218,9 @@ organization_id = #{record.organizationId,jdbcType=VARCHAR}, + + test_id = #{record.testId,jdbcType=VARCHAR}, + @@ -218,14 +229,15 @@ update message_task set id = #{record.id,jdbcType=VARCHAR}, - `type` = #{record.type,jdbcType=VARCHAR}, - event = #{record.event,jdbcType=VARCHAR}, - user_id = #{record.userId,jdbcType=VARCHAR}, - task_type = #{record.taskType,jdbcType=VARCHAR}, - webhook = #{record.webhook,jdbcType=VARCHAR}, - identification = #{record.identification,jdbcType=VARCHAR}, - is_set = #{record.isSet,jdbcType=BIT}, - organization_id = #{record.organizationId,jdbcType=VARCHAR} + `type` = #{record.type,jdbcType=VARCHAR}, + event = #{record.event,jdbcType=VARCHAR}, + user_id = #{record.userId,jdbcType=VARCHAR}, + task_type = #{record.taskType,jdbcType=VARCHAR}, + webhook = #{record.webhook,jdbcType=VARCHAR}, + identification = #{record.identification,jdbcType=VARCHAR}, + is_set = #{record.isSet,jdbcType=BIT}, + organization_id = #{record.organizationId,jdbcType=VARCHAR}, + test_id = #{record.testId,jdbcType=VARCHAR} @@ -257,19 +269,23 @@ organization_id = #{organizationId,jdbcType=VARCHAR}, + + test_id = #{testId,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} update message_task - set `type` = #{type,jdbcType=VARCHAR}, - event = #{event,jdbcType=VARCHAR}, - user_id = #{userId,jdbcType=VARCHAR}, - task_type = #{taskType,jdbcType=VARCHAR}, - webhook = #{webhook,jdbcType=VARCHAR}, - identification = #{identification,jdbcType=VARCHAR}, - is_set = #{isSet,jdbcType=BIT}, - organization_id = #{organizationId,jdbcType=VARCHAR} + set `type` = #{type,jdbcType=VARCHAR}, + event = #{event,jdbcType=VARCHAR}, + user_id = #{userId,jdbcType=VARCHAR}, + task_type = #{taskType,jdbcType=VARCHAR}, + webhook = #{webhook,jdbcType=VARCHAR}, + identification = #{identification,jdbcType=VARCHAR}, + is_set = #{isSet,jdbcType=BIT}, + organization_id = #{organizationId,jdbcType=VARCHAR}, + test_id = #{testId,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file 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 7ea36285a4..67583ce4b0 100644 --- a/backend/src/main/java/io/metersphere/notice/controller/NoticeController.java +++ b/backend/src/main/java/io/metersphere/notice/controller/NoticeController.java @@ -1,9 +1,8 @@ package io.metersphere.notice.controller; 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 io.metersphere.notice.service.NoticeService; import org.springframework.web.bind.annotation.*; @@ -16,16 +15,6 @@ public class NoticeController { @Resource private NoticeService noticeService; - @PostMapping("/save") - public void saveNotice(@RequestBody NoticeRequest noticeRequest) { - noticeService.saveNotice(noticeRequest); - } - - @GetMapping("/query/{testId}") - public List queryNotice(@PathVariable String testId) { - return noticeService.queryNotice(testId); - } - @PostMapping("save/message/task") public void saveMessage(@RequestBody MessageRequest messageRequest) { noticeService.saveMessageTask(messageRequest); @@ -36,6 +25,11 @@ public class NoticeController { return noticeService.searchMessage(); } + @GetMapping("/search/message/{testId}") + public List searchMessageSchedule(@PathVariable String testId) { + return noticeService.searchMessageSchedule(testId); + } + @GetMapping("/delete/message/{identification}") public int deleteMessage(@PathVariable String identification) { return noticeService.delMessage(identification); 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 1c4faecf48..e3ed51a172 100644 --- a/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java +++ b/backend/src/main/java/io/metersphere/notice/domain/MessageDetail.java @@ -1,6 +1,5 @@ package io.metersphere.notice.domain; -import io.metersphere.base.domain.MessageTask; import lombok.Data; import java.util.ArrayList; @@ -16,4 +15,5 @@ public class MessageDetail { private String identification; private String organizationId; private Boolean isSet; + private String testId; } diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index bc1367ce5d..86416020a2 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -1,7 +1,7 @@ package io.metersphere.notice.service; import io.metersphere.base.domain.ApiTestReport; -import io.metersphere.base.domain.LoadTestWithBLOBs; +import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.commons.constants.APITestStatus; @@ -14,7 +14,6 @@ import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.i18n.Translator; import io.metersphere.notice.domain.MessageDetail; -import io.metersphere.notice.domain.NoticeDetail; import io.metersphere.notice.domain.UserDetail; import io.metersphere.service.SystemParameterService; import io.metersphere.service.UserService; @@ -27,7 +26,6 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; @@ -49,32 +47,33 @@ public class MailService { @Resource private SystemParameterService systemParameterService; - public void sendPerformanceNotification(List noticeList, String status, LoadTestWithBLOBs loadTest, String id) { + //接口和性能测试 + public void sendLoadNotification(MessageDetail messageDetail, LoadTestReportWithBLOBs loadTestReport, String eventType) { + List userIds = new ArrayList<>(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); Map context = new HashMap<>(); context.put("title", "Performance" + Translator.get("timing_task_result_notification")); - context.put("testName", loadTest.getName()); - context.put("id", id); + context.put("testName", loadTestReport.getName()); + context.put("id", loadTestReport.getId()); context.put("type", "performance"); context.put("url", baseSystemConfigDTO.getUrl()); String performanceTemplate = ""; try { - if (StringUtils.equals(status, PerformanceTestStatus.Completed.name())) { - performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8); - } else if (StringUtils.equals(status, PerformanceTestStatus.Error.name())) { - performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/failPerformance.html"), StandardCharsets.UTF_8); + if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) { + performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/PerformanceApiSuccessNotification.html"), StandardCharsets.UTF_8); + } else if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) { + performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/PerformanceFailedNotification.html"), StandardCharsets.UTF_8); } - sendHtmlTimeTasks(noticeList, status, context, performanceTemplate); + sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, performanceTemplate, loadTestReport.getTriggerMode()); } catch (Exception e) { LogUtil.error(e); } } - - public void sendApiNotification(ApiTestReport apiTestReport, List noticeList) { + public void sendApiNotification(MessageDetail messageDetail, ApiTestReport apiTestReport, String eventType) { + List userIds = new ArrayList<>(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); Map context = new HashMap<>(); - context.put("title", "api" + Translator.get("timing_task_result_notification")); context.put("testName", apiTestReport.getName()); context.put("type", "api"); context.put("url", baseSystemConfigDTO.getUrl()); @@ -82,95 +81,63 @@ public class MailService { String apiTemplate = ""; try { if (StringUtils.equals(APITestStatus.Success.name(), apiTestReport.getStatus())) { - apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8); + apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/ApiSuccessfulNotification.html"), StandardCharsets.UTF_8); } else if (StringUtils.equals(APITestStatus.Error.name(), apiTestReport.getStatus())) { - apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8); + apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/ApiFailedNotification.html"), StandardCharsets.UTF_8); } - sendHtmlTimeTasks(noticeList, apiTestReport.getStatus(), context, apiTemplate); + sendApiOrLoadNotification(addresseeIdList(messageDetail, userIds, eventType), context, apiTemplate, apiTestReport.getTriggerMode()); } catch (Exception e) { LogUtil.error(e); } } - //jenkins - public void sendApiJenkinsNotification(String context, MessageDetail messageDetail) throws MessagingException { + private void sendApiOrLoadNotification(List userIds, Map context, String Template, String type) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } JavaMailSenderImpl javaMailSender = getMailSender(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); helper.setFrom(javaMailSender.getUsername()); - helper.setSubject("MeterSphere平台" + Translator.get("task_notification")); - helper.setText(context); - List list = userService.queryTypeByIds(messageDetail.getUserIds()); - List EmailList = new ArrayList<>(); + if (StringUtils.equals(type, NoticeConstants.API)) { + helper.setSubject("MeterSphere平台" + Translator.get("task_notification")); + } + if (StringUtils.equals(type, NoticeConstants.SCHEDULE)) { + helper.setSubject("MeterSphere平台" + Translator.get("timing_task_notification")); + } + String[] users; + List emails = new ArrayList<>(); + List list = userService.queryTypeByIds(userIds); list.forEach(u -> { - EmailList.add(u.getEmail()); + emails.add(u.getEmail()); }); - helper.setTo(EmailList.toArray(new String[0])); - try { - javaMailSender.send(mimeMessage); - } catch (MailException e) { - LogUtil.error(e); - } + users = emails.toArray(new String[0]); + helper.setText(getContent(Template, context), true); + helper.setTo(users); + javaMailSender.send(mimeMessage); } - public void sendLoadJenkinsNotification(String context, MessageDetail messageDetail) throws MessagingException { - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject("MeterSphere平台" + Translator.get("task_notification")); - helper.setText(context); - List list = userService.queryTypeByIds(messageDetail.getUserIds()); - List EmailList = new ArrayList<>(); - list.forEach(u -> { - EmailList.add(u.getEmail()); - }); - helper.setTo(EmailList.toArray(new String[0])); - try { - javaMailSender.send(mimeMessage); - } catch (MailException e) { - LogUtil.error(e); - } - } - - private void sendHtmlTimeTasks(List noticeList, String status, Map context, String template) throws MessagingException { - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject(Translator.get("timing_task_result_notification")); - helper.setText(getContent(template, context), true); - helper.setTo(getRecipientEmail(noticeList, status)); - try { - javaMailSender.send(mimeMessage); - } catch (MailException e) { - LogUtil.error(e); - } - } - //测试评审 public void sendEndNotice(MessageDetail messageDetail, List userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) { Map context = getReviewContext(reviewRequest); try { - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/end.html"), StandardCharsets.UTF_8); + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewEnd.html"), StandardCharsets.UTF_8); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } } - public void sendDeleteNotice(MessageDetail messageDetail, List userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) { Map context = getReviewContext(reviewRequest); try { - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/deleteReview.html"), StandardCharsets.UTF_8); + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewDelete.html"), StandardCharsets.UTF_8); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } } - public void sendCommentNotice(MessageDetail messageDetail, List userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs, String eventType) { BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); Map context = new HashMap<>(); @@ -180,74 +147,139 @@ public class MailService { context.put("url", baseSystemConfigDTO.getUrl()); context.put("id", testCaseWithBLOBs.getId()); try { - String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/comment.html"), StandardCharsets.UTF_8); + String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewComments.html"), StandardCharsets.UTF_8); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, commentTemplate); } catch (Exception e) { LogUtil.error(e); } } - //新建评审 public void sendReviewerNotice(MessageDetail messageDetail, List userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) { Map context = getReviewContext(reviewRequest); try { - String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8); + String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/ReviewInitiate.html"), StandardCharsets.UTF_8); sendReviewNotice(addresseeIdList(messageDetail, userIds, eventType), context, reviewerTemplate); } catch (Exception e) { LogUtil.error(e); } } + private void sendReviewNotice(List userIds, Map context, String Template) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } + JavaMailSenderImpl javaMailSender = getMailSender(); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setFrom(javaMailSender.getUsername()); + helper.setSubject("MeterSphere平台" + Translator.get("test_review_task_notice")); + String[] users; + List emails = new ArrayList<>(); + List list = userService.queryTypeByIds(userIds); + list.forEach(u -> { + emails.add(u.getEmail()); + }); + users = emails.toArray(new String[0]); + helper.setText(getContent(Template, context), true); + helper.setTo(users); + if (users.length > 0) { + javaMailSender.send(mimeMessage); + } + } + //测试计划 public void sendTestPlanStartNotice(MessageDetail messageDetail, List userIds, AddTestPlanRequest testPlan, String eventType) { Map context = getTestPlanContext(testPlan); context.put("creator", testPlan.getCreator()); try { - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/testPlanStart.html"), StandardCharsets.UTF_8); + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanStart.html"), StandardCharsets.UTF_8); sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } } - public void sendTestPlanEndNotice(MessageDetail messageDetail, List userIds, AddTestPlanRequest testPlan, String eventType) { Map context = getTestPlanContext(testPlan); context.put("creator", userIds.toString()); try { - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/testPlanEnd.html"), StandardCharsets.UTF_8); + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanEnd.html"), StandardCharsets.UTF_8); sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } } - public void sendTestPlanDeleteNotice(MessageDetail messageDetail, List userIds, AddTestPlanRequest testPlan, String eventType) { Map context = getTestPlanContext(testPlan); context.put("creator", userIds.toString()); try { - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/testPlanDelete.html"), StandardCharsets.UTF_8); + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/TestPlanDelete.html"), StandardCharsets.UTF_8); sendTestPlanNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } } + private void sendTestPlanNotice(List userIds, Map context, String Template) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } + JavaMailSenderImpl javaMailSender = getMailSender(); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setFrom(javaMailSender.getUsername()); + helper.setSubject("MeterSphere平台" + Translator.get("test_plan_notification")); + String[] users; + List emails = new ArrayList<>(); + List list = userService.queryTypeByIds(userIds); + list.forEach(u -> { + emails.add(u.getEmail()); + }); + users = emails.toArray(new String[0]); + helper.setText(getContent(Template, context), true); + helper.setTo(users); + javaMailSender.send(mimeMessage); + + } + //缺陷任务 public void sendIssuesNotice(MessageDetail messageDetail, List userIds, IssuesRequest issuesRequest, String eventType, SessionUser user) { Map context = new HashMap<>(); context.put("issuesName", issuesRequest.getTitle()); context.put("creator", user.getName()); try { - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/issuesCreate.html"), StandardCharsets.UTF_8); + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/IssuesCreate.html"), StandardCharsets.UTF_8); sendIssuesNotice(addresseeIdList(messageDetail, userIds, eventType), context, endTemplate); } catch (Exception e) { LogUtil.error(e); } } + private void sendIssuesNotice(List userIds, Map context, String Template) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } + JavaMailSenderImpl javaMailSender = getMailSender(); + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setFrom(javaMailSender.getUsername()); + helper.setSubject("MeterSphere平台" + Translator.get("task_defect_notification")); + String[] users; + List emails = new ArrayList<>(); + List list = userService.queryTypeByIds(userIds); + list.forEach(u -> { + emails.add(u.getEmail()); + }); + users = emails.toArray(new String[0]); + helper.setText(getContent(Template, context), true); + helper.setTo(users); + javaMailSender.send(mimeMessage); + + } + + //评审内容 private Map getReviewContext(SaveTestCaseReviewRequest reviewRequest) { Long startTime = reviewRequest.getCreateTime(); Long endTime = reviewRequest.getEndTime(); @@ -274,6 +306,7 @@ public class MailService { return context; } + //计划内容 private Map getTestPlanContext(AddTestPlanRequest testPlan) { Long startTime = testPlan.getPlannedStartTime(); Long endTime = testPlan.getPlannedEndTime(); @@ -299,72 +332,8 @@ public class MailService { return context; } - private void sendReviewNotice(List userIds, Map context, String Template) throws MessagingException { - if (CollectionUtils.isEmpty(userIds)) { - return; - } - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject("MeterSphere平台" + Translator.get("test_review_task_notice")); - String[] users; - List emails = new ArrayList<>(); - List list = userService.queryTypeByIds(userIds); - list.forEach(u -> { - emails.add(u.getEmail()); - }); - users = emails.toArray(new String[0]); - helper.setText(getContent(Template, context), true); - helper.setTo(users); - if (users.length > 0) { - javaMailSender.send(mimeMessage); - } - } - private void sendTestPlanNotice(List userIds, Map context, String Template) throws MessagingException { - if (CollectionUtils.isEmpty(userIds)) { - return; - } - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject("MeterSphere平台" + Translator.get("test_plan_notification")); - String[] users; - List emails = new ArrayList<>(); - List list = userService.queryTypeByIds(userIds); - list.forEach(u -> { - emails.add(u.getEmail()); - }); - users = emails.toArray(new String[0]); - helper.setText(getContent(Template, context), true); - helper.setTo(users); - javaMailSender.send(mimeMessage); - } - - private void sendIssuesNotice(List userIds, Map context, String Template) throws MessagingException { - if (CollectionUtils.isEmpty(userIds)) { - return; - } - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject("MeterSphere平台" + Translator.get("task_defect_notification")); - String[] users; - List emails = new ArrayList<>(); - List list = userService.queryTypeByIds(userIds); - list.forEach(u -> { - emails.add(u.getEmail()); - }); - users = emails.toArray(new String[0]); - helper.setText(getContent(Template, context), true); - helper.setTo(users); - javaMailSender.send(mimeMessage); - - } private JavaMailSenderImpl getMailSender() { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); @@ -404,7 +373,7 @@ public class MailService { for (String k : context.keySet()) { if (StringUtils.isNotBlank(context.get(k))) { template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k)); - }else{ + } else { template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", ""); } } @@ -412,62 +381,32 @@ public class MailService { return template; } - private String[] getRecipientEmail(List noticeList, String status) { - String[] recipientEmails; - List successEmailList = new ArrayList<>(); - List failEmailList = new ArrayList<>(); - if (noticeList.size() > 0) { - for (NoticeDetail n : noticeList) { - if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_SUCCESSFUL)) { - List list = userService.queryTypeByIds(n.getUserIds()); - list.forEach(u -> { - successEmailList.add(u.getEmail()); - }); - } - if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_FAILED)) { - List list = userService.queryTypeByIds(n.getUserIds()); - list.forEach(u -> { - failEmailList.add(u.getEmail()); - }); - } - } - } else { - LogUtil.error("Recipient information is empty"); - } - - if (StringUtils.equalsAny(status, PerformanceTestStatus.Completed.name(), APITestStatus.Success.name())) { - recipientEmails = successEmailList.toArray(new String[0]); - } else { - recipientEmails = failEmailList.toArray(new String[0]); - } - return recipientEmails; - } - private List addresseeIdList(MessageDetail messageDetail, List userIds, String eventType) { List addresseeIdList = new ArrayList<>(); - if (StringUtils.equals(eventType, messageDetail.getEvent())) { - messageDetail.getUserIds().forEach(u -> { - if (!StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.MAINTAINER, u)) { - addresseeIdList.add(u); - } - if (StringUtils.equals(NoticeConstants.CREATE, eventType) && StringUtils.equals(NoticeConstants.EXECUTOR, u)) { - addresseeIdList.addAll(userIds); - } - if (StringUtils.equals(NoticeConstants.UPDATE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { - addresseeIdList.addAll(userIds); - } - if (StringUtils.equals(NoticeConstants.DELETE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { - addresseeIdList.addAll(userIds); - } - if (StringUtils.equals(NoticeConstants.COMMENT, eventType) && StringUtils.equals(NoticeConstants.MAINTAINER, u)) { - addresseeIdList.addAll(userIds); - } + if (StringUtils.equals(eventType, messageDetail.getEvent())) { + messageDetail.getUserIds().forEach(u -> { + if (!StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.EXECUTOR, u) && !StringUtils.equals(NoticeConstants.MAINTAINER, u)) { + addresseeIdList.add(u); + } + if (StringUtils.equals(NoticeConstants.CREATE, eventType) && StringUtils.equals(NoticeConstants.EXECUTOR, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.UPDATE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.DELETE, eventType) && StringUtils.equals(NoticeConstants.FOUNDER, u)) { + addresseeIdList.addAll(userIds); + } + if (StringUtils.equals(NoticeConstants.COMMENT, eventType) && StringUtils.equals(NoticeConstants.MAINTAINER, u)) { + addresseeIdList.addAll(userIds); + } - }); - } + }); + } return addresseeIdList; } + } 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 ffa82d455e..24ee9ed8fc 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -2,19 +2,13 @@ package io.metersphere.notice.service; import io.metersphere.base.domain.MessageTask; import io.metersphere.base.domain.MessageTaskExample; -import io.metersphere.base.domain.Notice; -import io.metersphere.base.domain.NoticeExample; import io.metersphere.base.mapper.MessageTaskMapper; -import io.metersphere.base.mapper.NoticeMapper; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.utils.SessionUtils; 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; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,79 +16,22 @@ import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; -import static io.metersphere.commons.constants.NoticeConstants.EXECUTE_FAILED; -import static io.metersphere.commons.constants.NoticeConstants.EXECUTE_SUCCESSFUL; - @Service @Transactional(rollbackFor = Exception.class) public class NoticeService { - @Resource - private NoticeMapper noticeMapper; @Resource private MessageTaskMapper messageTaskMapper; - public void saveNotice(NoticeRequest noticeRequest) { - NoticeExample example = new NoticeExample(); - example.createCriteria().andTestIdEqualTo(noticeRequest.getTestId()); - List notices = noticeMapper.selectByExample(example); - if (notices.size() > 0) { - noticeMapper.deleteByExample(example); - } - noticeRequest.getNotices().forEach(n -> { - if (CollectionUtils.isNotEmpty(n.getUserIds())) { - for (String x : n.getUserIds()) { - Notice notice = new Notice(); - notice.setId(UUID.randomUUID().toString()); - notice.setEvent(n.getEvent()); - notice.setEnable(n.getEnable()); - notice.setTestId(noticeRequest.getTestId()); - notice.setUserId(x); - notice.setType(n.getType()); - noticeMapper.insert(notice); - } - } - }); - } - - public List queryNotice(String id) { - NoticeExample example = new NoticeExample(); - example.createCriteria().andTestIdEqualTo(id); - List notices = noticeMapper.selectByExample(example); - List result = new ArrayList<>(); - List successList = new ArrayList<>(); - List failList = new ArrayList<>(); - NoticeDetail notice1 = new NoticeDetail(); - NoticeDetail notice2 = new NoticeDetail(); - if (notices.size() > 0) { - for (Notice n : notices) { - if (n.getEvent().equals(EXECUTE_SUCCESSFUL)) { - successList.add(n.getUserId()); - notice1.setEnable(n.getEnable()); - notice1.setTestId(id); - notice1.setType(n.getType()); - notice1.setEvent(n.getEvent()); - } - if (n.getEvent().equals(EXECUTE_FAILED)) { - failList.add(n.getUserId()); - notice2.setEnable(n.getEnable()); - notice2.setTestId(id); - notice2.setType(n.getType()); - notice2.setEvent(n.getEvent()); - } - } - notice1.setUserIds(successList); - notice2.setUserIds(failList); - result.add(notice1); - result.add(notice2); - } - return result; - } - public void saveMessageTask(MessageRequest messageRequest) { - String identification = UUID.randomUUID().toString(); SessionUser user = SessionUtils.getUser(); String orgId = user.getLastOrganizationId(); messageRequest.getMessageDetail().forEach(list -> { + MessageTaskExample example = new MessageTaskExample(); + example.createCriteria().andIdentificationEqualTo(list.getIdentification()); + List messageTaskLists = messageTaskMapper.selectByExample(example); + if (messageTaskLists.size() > 0) { + delMessage(list.getIdentification()); + String identification = UUID.randomUUID().toString(); list.getUserIds().forEach(m -> { MessageTask message = new MessageTask(); message.setId(UUID.randomUUID().toString()); @@ -106,9 +43,52 @@ public class NoticeService { message.setIdentification(identification); message.setIsSet(list.getIsSet()); message.setOrganizationId(orgId); + message.setTestId(list.getTestId()); messageTaskMapper.insert(message); }); - }); + } else { + String identification = UUID.randomUUID().toString(); + list.getUserIds().forEach(m -> { + MessageTask message = new MessageTask(); + message.setId(UUID.randomUUID().toString()); + message.setEvent(list.getEvent()); + message.setTaskType(list.getTaskType()); + message.setUserId(m); + message.setType(list.getType()); + message.setWebhook(list.getWebhook()); + message.setIdentification(identification); + message.setIsSet(list.getIsSet()); + message.setOrganizationId(orgId); + message.setTestId(list.getTestId()); + messageTaskMapper.insert(message); + }); + } + + }); + } + + public List searchMessageSchedule(String testId) { + MessageTaskExample example = new MessageTaskExample(); + example.createCriteria().andTestIdEqualTo(testId); + List messageTaskLists = messageTaskMapper.selectByExample(example); + List scheduleMessageTask = new ArrayList<>(); + Map> MessageTaskMap = messageTaskLists.stream().collect(Collectors.groupingBy(e -> e.getIdentification())); + MessageTaskMap.forEach((k, v) -> { + Set userIds = new HashSet(); + MessageDetail messageDetail = new MessageDetail(); + for (MessageTask m : v) { + userIds.add(m.getUserId()); + messageDetail.setEvent(m.getEvent()); + messageDetail.setTaskType(m.getTaskType()); + messageDetail.setWebhook(m.getWebhook()); + messageDetail.setIdentification(m.getIdentification()); + messageDetail.setType(m.getType()); + messageDetail.setIsSet(m.getIsSet()); + } + messageDetail.setUserIds(new ArrayList(userIds)); + scheduleMessageTask.add(messageDetail); + }); + return scheduleMessageTask; } public MessageSettingDetail searchMessage() { 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 5e5eb45d51..b4b4d85e76 100644 --- a/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java +++ b/backend/src/main/java/io/metersphere/performance/notice/PerformanceNoticeTask.java @@ -1,24 +1,22 @@ package io.metersphere.performance.notice; -import io.metersphere.base.domain.LoadTest; -import io.metersphere.base.domain.LoadTestWithBLOBs; -import io.metersphere.base.mapper.LoadTestMapper; +import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.utils.LogUtil; +import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.MessageSettingDetail; -import io.metersphere.notice.domain.NoticeDetail; 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.SystemParameterService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import javax.annotation.PreDestroy; import javax.annotation.Resource; -import javax.mail.MessagingException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; @@ -35,7 +33,7 @@ public class PerformanceNoticeTask { @Resource private MailService mailService; @Resource - private LoadTestMapper loadTestMapper; + private SystemParameterService systemParameterService; private final ExecutorService executorService = Executors.newFixedThreadPool(20); private boolean isRunning = true; @@ -43,18 +41,18 @@ public class PerformanceNoticeTask { public void preDestroy() { isRunning = false; } - public void registerNoticeTask(String triggerMode,LoadTestWithBLOBs loadTest) { + + public void registerNoticeTask(LoadTestReportWithBLOBs loadTestReport) { executorService.submit(() -> { while (isRunning) { - LoadTestWithBLOBs result = loadTestMapper.selectByPrimaryKey(loadTest.getId()); - if (StringUtils.equals(result.getStatus(), PerformanceTestStatus.Completed.name())) { + if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) { isRunning = false; - sendSuccessNotice(triggerMode,loadTest); + sendSuccessNotice(loadTestReport); return; } - if (StringUtils.equals(result.getStatus(), PerformanceTestStatus.Error.name())) { + if (StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) { isRunning = false; - sendFailNotice(triggerMode,loadTest); + sendFailNotice(loadTestReport); return; } try { @@ -66,83 +64,81 @@ public class PerformanceNoticeTask { }); } - public void sendSuccessNotice(String triggerMode,LoadTestWithBLOBs loadTest) { - if (StringUtils.equals(NoticeConstants.API, "API")||StringUtils.equals(NoticeConstants.SCHEDULE,"SCHEDULE")) { - List userIds = new ArrayList<>(); + public void sendSuccessNotice(LoadTestReportWithBLOBs loadTestReport) { + List userIds = new ArrayList<>(); + List taskList = new ArrayList<>(); + String successContext = ""; + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + String url = baseSystemConfigDTO.getUrl() + "/#/performance/report/view/" + loadTestReport.getId(); + if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode())) { MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); - List taskList = messageSettingDetail.getJenkinsTask(); - if(StringUtils.equals(triggerMode,NoticeConstants.SCHEDULE)){ - List noticeList = null; - noticeList = noticeService.queryNotice(loadTest.getId()); - mailService.sendPerformanceNotification(noticeList, PerformanceTestStatus.Completed.name(), loadTest, loadTest.getId()); }else{ - return; - } - - if(StringUtils.equals(triggerMode,NoticeConstants.SCHEDULE)){ - String contextSuccess=""; - contextSuccess = "jenkins任务通知:" + loadTest.getName() + "执行成功"; - String finalContextSuccess = contextSuccess; - taskList.forEach(r -> { - switch (r.getType()) { - case NoticeConstants.NAIL_ROBOT: - if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) - && StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) { - dingTaskService.sendNailRobot(r, userIds, finalContextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); - } - break; - case NoticeConstants.WECHAT_ROBOT: - if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) - && StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) { - wxChatTaskService.sendWechatRobot(r, userIds, finalContextSuccess, NoticeConstants.EXECUTE_SUCCESSFUL); - } - break; - case NoticeConstants.EMAIL: - if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) - && StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Completed.name())) { - try { - mailService.sendLoadJenkinsNotification(finalContextSuccess, r); - } catch (MessagingException messagingException) { - messagingException.printStackTrace(); - } - } - break; - } - }); - } - + taskList = messageSettingDetail.getJenkinsTask(); + successContext = "jenkins性能测试任务通知" + loadTestReport.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url; } + if (StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) { + taskList = noticeService.searchMessageSchedule(loadTestReport.getId()); + successContext = "定时任务性能测试任务通知" + loadTestReport.getName() + "执行成功" + "请点击下面链接进入测试报告页面" + url; + } + String finalSuccessContext = successContext; + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) { + dingTaskService.sendNailRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL); + } + break; + case NoticeConstants.WECHAT_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) { + wxChatTaskService.sendWechatRobot(r, userIds, finalSuccessContext, NoticeConstants.EXECUTE_SUCCESSFUL); + } + break; + case NoticeConstants.EMAIL: + if (StringUtils.equals(NoticeConstants.EXECUTE_SUCCESSFUL, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Completed.name())) { + mailService.sendLoadNotification(r, loadTestReport, NoticeConstants.EXECUTE_SUCCESSFUL); + } + break; + } + + }); } - public void sendFailNotice(String triggerMode,LoadTestWithBLOBs loadTest) { - if (StringUtils.equals(NoticeConstants.API, "API")) { - List userIds = new ArrayList<>(); + + public void sendFailNotice(LoadTestReportWithBLOBs loadTestReport) { + List userIds = new ArrayList<>(); + List taskList = new ArrayList<>(); + String failedContext = ""; + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + String url = baseSystemConfigDTO.getUrl() + "/#/performance/report/view/" + loadTestReport.getId(); + if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode())) { MessageSettingDetail messageSettingDetail = noticeService.searchMessage(); - List taskList = messageSettingDetail.getJenkinsTask(); - String contextFailed = "jenkins任务通知:" + loadTest.getName() + "执行失败"; - taskList.forEach(r -> { - switch (r.getType()) { - case NoticeConstants.NAIL_ROBOT: - if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) { - dingTaskService.sendNailRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); - } - break; - case NoticeConstants.WECHAT_ROBOT: - if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) { - wxChatTaskService.sendWechatRobot(r, userIds, contextFailed, NoticeConstants.EXECUTE_FAILED); - } - break; - case NoticeConstants.EMAIL: - if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent())) { - try { - mailService.sendLoadJenkinsNotification(contextFailed, r); - } catch (MessagingException messagingException) { - messagingException.printStackTrace(); - } - } - break; - } - }); + taskList = messageSettingDetail.getJenkinsTask(); + failedContext = "jenkins性能测试任务通知" + loadTestReport.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url; } + if (StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) { + taskList = noticeService.searchMessageSchedule(loadTestReport.getId()); + failedContext = "定时任务性能测试任务通知" + loadTestReport.getName() + "执行失败" + "请点击下面链接进入测试报告页面" + url; + } + String finalFailedContext = failedContext; + taskList.forEach(r -> { + switch (r.getType()) { + case NoticeConstants.NAIL_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) { + dingTaskService.sendNailRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED); + } + break; + case NoticeConstants.WECHAT_ROBOT: + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) { + wxChatTaskService.sendWechatRobot(r, userIds, finalFailedContext, NoticeConstants.EXECUTE_FAILED); + } + break; + case NoticeConstants.EMAIL: + if (StringUtils.equals(NoticeConstants.EXECUTE_FAILED, r.getEvent()) && StringUtils.equals(loadTestReport.getStatus(), PerformanceTestStatus.Error.name())) { + mailService.sendLoadNotification(r, loadTestReport, NoticeConstants.EXECUTE_FAILED); + } + break; + } + + }); } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 104535e532..8e3884dfe6 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -28,7 +28,6 @@ import io.metersphere.performance.notice.PerformanceNoticeTask; import io.metersphere.service.FileService; import io.metersphere.service.QuotaService; import io.metersphere.service.ScheduleService; -import io.metersphere.service.TestResourceService; import io.metersphere.track.request.testplan.*; import io.metersphere.track.service.TestCaseService; import org.apache.commons.collections4.ListUtils; @@ -235,17 +234,10 @@ public class PerformanceTestService { } startEngine(loadTest, engine, request.getTriggerMode()); - List noticeList = null; - if (request.getTriggerMode().equals("SCHEDULE")) { - try { - noticeList = noticeService.queryNotice(loadTest.getId()); - mailService.sendPerformanceNotification(noticeList, PerformanceTestStatus.Completed.name(), loadTest, engine.getReportId()); - } catch (Exception e) { - LogUtil.error(e.getMessage(), e); - } - } - if(request.getTriggerMode().equals("API")){ - performanceNoticeTask.registerNoticeTask(request.getTriggerMode(),loadTest); + + LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(engine.getReportId()); + if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode()) || StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) { + performanceNoticeTask.registerNoticeTask(loadTestReport); } return engine.getReportId(); } @@ -319,9 +311,9 @@ public class PerformanceTestService { loadTest.setStatus(PerformanceTestStatus.Error.name()); loadTest.setDescription(e.getMessage()); loadTestMapper.updateByPrimaryKeySelective(loadTest); - if (triggerMode.equals("SCHEDULE")) { - noticeList = noticeService.queryNotice(loadTest.getId()); - mailService.sendPerformanceNotification(noticeList, loadTest.getStatus(), loadTest, loadTest.getId()); + LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(engine.getReportId()); + if (StringUtils.equals(NoticeConstants.API, loadTestReport.getTriggerMode()) || StringUtils.equals(NoticeConstants.SCHEDULE, loadTestReport.getTriggerMode())) { + performanceNoticeTask.registerNoticeTask(loadTestReport); } throw e; } @@ -447,12 +439,12 @@ public class PerformanceTestService { reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name()); List noticeList = null; if (loadTestReport.getTriggerMode().equals("SCHEDULE")) { - try { + /* try { noticeList = noticeService.queryNotice(loadTest.getId()); mailService.sendPerformanceNotification(noticeList, loadTestReport.getStatus(), loadTest, loadTestReport.getId()); } catch (Exception e) { LogUtil.error(e.getMessage(), e); - } + }*/ } diff --git a/backend/src/main/resources/db/migration/V37__modify_message_task_test_id.sql b/backend/src/main/resources/db/migration/V37__modify_message_task_test_id.sql new file mode 100644 index 0000000000..02501a3de9 --- /dev/null +++ b/backend/src/main/resources/db/migration/V37__modify_message_task_test_id.sql @@ -0,0 +1,2 @@ +alter table message_task + add test_id varchar(255) null; \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index bd58c4e206..8e1afed80b 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -155,7 +155,6 @@ email_subject=Metersphere timing task result notification import_xmind_count_error=The number of use cases imported into the mind map cannot exceed 500 import_xmind_not_found=Test case not found license_valid_license_error=Authorization authentication failed -timing_task_result_notification=Timing task result notification test_review_task_notice=Test review task notice test_track.length_less_than=The title is too long, the length must be less than # check owner @@ -168,6 +167,7 @@ upload_content_is_null=Imported content is empty test_plan_notification=Test plan notification task_defect_notification=Task defect notification task_notification=Jenkins Task notification +timing_task_notification=Timing task result notification diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 91d5ffa4b6..2e55e678e2 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -155,7 +155,7 @@ email_subject=MeterSphere定时任务结果通知 import_xmind_count_error=思维导图导入用例数量不能超过 500 条 license_valid_license_error=授权认证失败 import_xmind_not_found=未找到测试用例 -timing_task_result_notification=定时任务结果通知 + test_review_task_notice=测试评审任务通知 test_track.length_less_than=标题过长,字数必须小于 # check owner @@ -167,4 +167,5 @@ check_owner_review=当前用户没有操作此评审的权限 upload_content_is_null=导入内容为空 test_plan_notification=测试计划通知 task_defect_notification=缺陷任务通知 -task_notification=jenkins任务通知 \ No newline at end of file +task_notification=jenkins任务通知 +timing_task_notification=定时任务结果通知 \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index a34799eac5..1c96965e8d 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -156,7 +156,7 @@ license_valid_license_code=授權碼已經存在 email_subject=MeterSphere定時任務結果通知 import_xmind_count_error=思維導圖導入用例數量不能超過 500 條 import_xmind_not_found=未找到测试用例 -timing_task_result_notification=定時任務結果通知 + test_review_task_notice=測試評審任務通知 test_track.length_less_than=標題過長,字數必須小於 # check owner @@ -169,4 +169,5 @@ upload_content_is_null=導入內容為空 test_plan_notification=測試計畫通知 task_defect_notification=缺陷任務通知 task_notification=jenkins任務通知 +timing_task_notification=定時任務通知 diff --git a/backend/src/main/resources/mail/fail.html b/backend/src/main/resources/mail/ApiFailedNotification.html similarity index 77% rename from backend/src/main/resources/mail/fail.html rename to backend/src/main/resources/mail/ApiFailedNotification.html index 37809ed008..aed24551e0 100644 --- a/backend/src/main/resources/mail/fail.html +++ b/backend/src/main/resources/mail/ApiFailedNotification.html @@ -6,15 +6,12 @@
-
-

${title}

-

尊敬的用户:

您好:

-

您所执行的 ${testName} 运行失败
+

您所执行的 ${testName} 接口测试运行失败
请点击下面链接进入测试报告页面

${url}/#/${type}/report/view/${id}
diff --git a/backend/src/main/resources/mail/success.html b/backend/src/main/resources/mail/ApiSuccessfulNotification.html similarity index 87% rename from backend/src/main/resources/mail/success.html rename to backend/src/main/resources/mail/ApiSuccessfulNotification.html index 7193b56eec..c951c6b7ab 100644 --- a/backend/src/main/resources/mail/success.html +++ b/backend/src/main/resources/mail/ApiSuccessfulNotification.html @@ -13,7 +13,7 @@

您好:

-

您所执行的 ${testName} 运行成功
+

您所执行的 ${testName} 接口测试运行成功
请点击下面链接进入测试报告页面

${url}/#/${type}/report/view/${id}
diff --git a/backend/src/main/resources/mail/issuesCreate.html b/backend/src/main/resources/mail/IssuesCreate.html similarity index 100% rename from backend/src/main/resources/mail/issuesCreate.html rename to backend/src/main/resources/mail/IssuesCreate.html diff --git a/backend/src/main/resources/mail/successPerformance.html b/backend/src/main/resources/mail/PerformanceApiSuccessNotification.html similarity index 88% rename from backend/src/main/resources/mail/successPerformance.html rename to backend/src/main/resources/mail/PerformanceApiSuccessNotification.html index fb51647a68..047ce019c1 100644 --- a/backend/src/main/resources/mail/successPerformance.html +++ b/backend/src/main/resources/mail/PerformanceApiSuccessNotification.html @@ -5,9 +5,6 @@ MeterSphere -
-

${title}

-

尊敬的用户:

您好: diff --git a/backend/src/main/resources/mail/failPerformance.html b/backend/src/main/resources/mail/PerformanceFailedNotification.html similarity index 82% rename from backend/src/main/resources/mail/failPerformance.html rename to backend/src/main/resources/mail/PerformanceFailedNotification.html index e9e70b33d2..97ee5ec1fb 100644 --- a/backend/src/main/resources/mail/failPerformance.html +++ b/backend/src/main/resources/mail/PerformanceFailedNotification.html @@ -6,9 +6,6 @@

-
-

${title}

-

尊敬的用户:

您好: diff --git a/backend/src/main/resources/mail/comment.html b/backend/src/main/resources/mail/ReviewComments.html similarity index 100% rename from backend/src/main/resources/mail/comment.html rename to backend/src/main/resources/mail/ReviewComments.html diff --git a/backend/src/main/resources/mail/deleteReview.html b/backend/src/main/resources/mail/ReviewDelete.html similarity index 100% rename from backend/src/main/resources/mail/deleteReview.html rename to backend/src/main/resources/mail/ReviewDelete.html diff --git a/backend/src/main/resources/mail/end.html b/backend/src/main/resources/mail/ReviewEnd.html similarity index 100% rename from backend/src/main/resources/mail/end.html rename to backend/src/main/resources/mail/ReviewEnd.html diff --git a/backend/src/main/resources/mail/reviewer.html b/backend/src/main/resources/mail/ReviewInitiate.html similarity index 100% rename from backend/src/main/resources/mail/reviewer.html rename to backend/src/main/resources/mail/ReviewInitiate.html diff --git a/backend/src/main/resources/mail/testPlanDelete.html b/backend/src/main/resources/mail/TestPlanDelete.html similarity index 100% rename from backend/src/main/resources/mail/testPlanDelete.html rename to backend/src/main/resources/mail/TestPlanDelete.html diff --git a/backend/src/main/resources/mail/testPlanEnd.html b/backend/src/main/resources/mail/TestPlanEnd.html similarity index 100% rename from backend/src/main/resources/mail/testPlanEnd.html rename to backend/src/main/resources/mail/TestPlanEnd.html diff --git a/backend/src/main/resources/mail/testPlanStart.html b/backend/src/main/resources/mail/TestPlanStart.html similarity index 100% rename from backend/src/main/resources/mail/testPlanStart.html rename to backend/src/main/resources/mail/TestPlanStart.html diff --git a/frontend/src/business/components/common/components/MsScheduleEdit.vue b/frontend/src/business/components/common/components/MsScheduleEdit.vue index a81ed058ee..499b7c45d5 100644 --- a/frontend/src/business/components/common/components/MsScheduleEdit.vue +++ b/frontend/src/business/components/common/components/MsScheduleEdit.vue @@ -3,7 +3,7 @@ @close="close"> + + + diff --git a/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue b/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue index 630f769e87..e44215182b 100644 --- a/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue +++ b/frontend/src/business/components/settings/organization/components/TestPlanTaskNotification.vue @@ -79,6 +79,12 @@ @click.native.prevent="removeRowTask(scope.$index,form.testCasePlanTask)" >{{ $t('commons.cancel') }} + {{ $t('commons.edit') }} {{ $t('commons.cancel') }} + {{ $t('commons.edit') }}