From 666532bd8cbbb079b30859dd0d620522717cb77e Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Sun, 27 Sep 2020 11:26:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E6=9E=84=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/jmeter/APIBackendListenerClient.java | 12 +- .../service/ApiAndPerformanceHelper.java | 8 + .../notice/service/MailService.java | 240 ++++++++++-------- .../notice/service/NoticeService.java | 66 ++--- .../service/PerformanceTestService.java | 39 ++- .../track/service/TestCaseCommentService.java | 2 +- .../track/service/TestCaseReviewService.java | 34 +-- .../main/resources/mail/failPerformance.html | 22 ++ .../components/api/test/OneClickOperation.vue | 11 +- .../common/components/MsScheduleEdit.vue | 7 + 10 files changed, 251 insertions(+), 190 deletions(-) create mode 100644 backend/src/main/resources/mail/failPerformance.html 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 db6e914c48..85fb04dd4d 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -119,18 +119,14 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl queue.clear(); super.teardownTest(context); NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class); - List notice = null; try { - notice = noticeService.queryNotice(testResult.getTestId()); - } catch (Exception e) { - LogUtil.error(e); - } - MailService mailService = CommonBeanFactory.getBean(MailService.class); - try { - mailService.sendHtml(report.getId(), notice, report.getStatus(), "api"); + List noticeList = noticeService.queryNotice(testResult.getTestId()); + MailService mailService = CommonBeanFactory.getBean(MailService.class); + mailService.sendApiNotification(report, noticeList); } catch (Exception e) { LogUtil.error(e); } + } private RequestResult getRequestResult(SampleResult result) { diff --git a/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java b/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java index f74f04bc49..fee24a5b72 100644 --- a/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java +++ b/backend/src/main/java/io/metersphere/notice/service/ApiAndPerformanceHelper.java @@ -2,8 +2,10 @@ package io.metersphere.notice.service; import io.metersphere.api.dto.APIReportResult; import io.metersphere.base.domain.ApiTestReportDetail; +import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.domain.Schedule; import io.metersphere.base.mapper.ApiTestReportDetailMapper; +import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtApiTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.commons.constants.ScheduleGroup; @@ -28,6 +30,8 @@ public class ApiAndPerformanceHelper { private ApiTestReportDetailMapper apiTestReportDetailMapper; @Resource private ScheduleService scheduleService; + @Resource + private LoadTestReportMapper loadTestReportMapper; public APIReportResult getApi(String reportId) { APIReportResult result = extApiTestReportMapper.get(reportId); @@ -50,5 +54,9 @@ public class ApiAndPerformanceHelper { } return null; } + + public LoadTestReportWithBLOBs getLoadTestReport(String id) { + return loadTestReportMapper.selectByPrimaryKey(id); + } } 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 df2b3b9f2c..81c5429b0a 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -1,13 +1,13 @@ package io.metersphere.notice.service; -import io.metersphere.api.dto.APIReportResult; +import io.metersphere.base.domain.ApiTestReport; +import io.metersphere.base.domain.LoadTestWithBLOBs; import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.commons.constants.ParamConstants; import io.metersphere.commons.utils.EncryptUtils; import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.BaseSystemConfigDTO; -import io.metersphere.dto.LoadTestDTO; import io.metersphere.i18n.Translator; import io.metersphere.notice.domain.NoticeDetail; import io.metersphere.service.SystemParameterService; @@ -24,6 +24,7 @@ import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; @@ -38,86 +39,99 @@ public class MailService { @Resource private SystemParameterService systemParameterService; - - public void sendHtml(String id, List notice, String status, String type) { + public void sendPerformanceNotification(List noticeList, String status, LoadTestWithBLOBs loadTest) { BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); - String testName = ""; - if (type.equals("api")) { - APIReportResult reportResult = apiAndPerformanceHelper.getApi(id); - testName = reportResult.getTestName(); - } else if (type.equals("performance")) { - LoadTestDTO performanceResult = apiAndPerformanceHelper.getPerformance(id); - testName = performanceResult.getName(); - } - Map context = new HashMap<>(); - context.put("title", type + Translator.get("timing_task_result_notification")); - context.put("testName", testName); + context.put("title", "Performance" + Translator.get("timing_task_result_notification")); + context.put("testName", loadTest.getName()); + context.put("id", loadTest.getId()); context.put("url", baseSystemConfigDTO.getUrl()); - context.put("id", id); - context.put("type", type); - + String performanceTemplate = ""; try { - String failTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8); - String successTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8); - String successPerformanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8); - - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject(Translator.get("timing_task_result_notification")); - String[] users; - List successEmailList = new ArrayList<>(); - List failEmailList = new ArrayList<>(); - if (notice.size() > 0) { - for (NoticeDetail n : notice) { - if (n.getEnable().equals("true") && n.getEvent().equals("执行成功")) { - successEmailList = userService.queryEmail(n.getNames()); - } - if (n.getEnable().equals("true") && n.getEvent().equals("执行失败")) { - failEmailList = userService.queryEmail(n.getNames()); - } - } - } else { - LogUtil.error("Recipient information is empty"); + if (status.equals("Completed")) { + performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8); + } else if (status.equals("Error")) { + performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/failPerformance.html"), StandardCharsets.UTF_8); } - - if (status.equals("Success")) { - users = successEmailList.toArray(new String[0]); - helper.setText(getContent(successTemplate, context), true); - } else if (status.equals("Starting") && type.equals("performance")) { - users = successEmailList.toArray(new String[0]); - helper.setText(getContent(successPerformanceTemplate, context), true); - } else { - users = failEmailList.toArray(new String[0]); - helper.setText(getContent(failTemplate, context), true); - } - helper.setTo(users); + sendHtmlTimeTasks(noticeList, status, context, performanceTemplate); } catch (Exception e) { LogUtil.error(e); } + } + + public void sendApiNotification(ApiTestReport apiTestReport, List noticeList) { + 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()); + context.put("id", apiTestReport.getId()); + String apiTemplate = ""; try { - javaMailSender.send(mimeMessage); - } catch (MailException e) { + if (apiTestReport.getStatus().equals("Success")) { + apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8); + } else if (apiTestReport.getStatus().equals("Error")) { + apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8); + } + sendHtmlTimeTasks(noticeList, apiTestReport.getStatus(), context, apiTemplate); + } catch (Exception e) { LogUtil.error(e); } } - private String getContent(String template, Map context) { - if (MapUtils.isNotEmpty(context)) { - for (String k : context.keySet()) { - if (StringUtils.isNotBlank(context.get(k))) { - template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k)); - } - } + 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("Failed to send mail"); } - return template; } + public void sendEndNotice(List userIds, SaveTestCaseReviewRequest reviewRequest) { + Map context = getReviewContext(reviewRequest); + try { + String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/end.html"), StandardCharsets.UTF_8); + sendReviewNotice(userIds, context, endTemplate); + } catch (Exception e) { + LogUtil.error(e); + } + } - public void sendHtml(List userIds, String type, SaveTestCaseReviewRequest reviewRequest, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) { + public void sendCommentNotice(List userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) { BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + Map context = new HashMap<>(); + context.put("maintainer", testCaseWithBLOBs.getMaintainer()); + context.put("testCaseName", testCaseWithBLOBs.getName()); + context.put("description", request.getDescription()); + context.put("url", baseSystemConfigDTO.getUrl()); + context.put("id", testCaseWithBLOBs.getId()); + try { + String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/comment.html"), StandardCharsets.UTF_8); + sendReviewNotice(userIds, context, commentTemplate); + } catch (Exception e) { + LogUtil.error(e); + } + } + + public void sendReviewerNotice(List userIds, SaveTestCaseReviewRequest reviewRequest) { + Map context = getReviewContext(reviewRequest); + try { + String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8); + sendReviewNotice(userIds, context, reviewerTemplate); + } catch (Exception e) { + LogUtil.error(e); + } + } + + private Map getReviewContext(SaveTestCaseReviewRequest reviewRequest) { Long startTime = reviewRequest.getCreateTime(); Long endTime = reviewRequest.getEndTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -131,60 +145,35 @@ public class MailService { if (!eTime.equals("null")) { end = sdf.format(new Date(Long.parseLong(eTime))); } - JavaMailSenderImpl javaMailSender = getMailSender(); - MimeMessage mimeMessage = javaMailSender.createMimeMessage(); Map context = new HashMap<>(); + BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); + context.put("url", baseSystemConfigDTO.getUrl()); context.put("creator", reviewRequest.getCreator()); - context.put("maintainer", testCaseWithBLOBs.getMaintainer()); - context.put("testCaseName", testCaseWithBLOBs.getName()); context.put("reviewName", reviewRequest.getName()); - context.put("description", request.getDescription()); context.put("start", start); context.put("end", end); - context.put("url", baseSystemConfigDTO.getUrl()); context.put("id", reviewRequest.getId()); + return context; + } + private void sendReviewNotice(List userIds, 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("test_review_task_notice")); + String[] users; + List emails = new ArrayList<>(); try { - String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8); - String commentTemplate = IOUtils.toString(this.getClass().getResource("/mail/comment.html"), StandardCharsets.UTF_8); - String endTemplate = IOUtils.toString(this.getClass().getResource("/mail/end.html"), StandardCharsets.UTF_8); - - - MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - helper.setSubject(Translator.get("test_review_task_notice")); - String[] users; - List emails = new ArrayList<>(); - try { - emails = userService.queryEmailByIds(userIds); - } catch (Exception e) { - LogUtil.error("Recipient information is empty"); - } - users = emails.toArray(new String[0]); - switch (type) { - case "reviewer": - helper.setText(getContent(reviewerTemplate, context), true); - break; - case "comment": - helper.setText(getContent(commentTemplate, context), true); - break; - case "end": - helper.setText(getContent(endTemplate, context), true); - break; - default: - break; - } - helper.setTo(users); - + emails = userService.queryEmailByIds(userIds); } catch (Exception e) { - LogUtil.error(e); - } - try { - javaMailSender.send(mimeMessage); - } catch (MailException e) { - LogUtil.error(e); + LogUtil.error("Recipient information is empty"); } + users = emails.toArray(new String[0]); + helper.setText(getContent(Template, context), true); + helper.setTo(users); + javaMailSender.send(mimeMessage); } private JavaMailSenderImpl getMailSender() { @@ -215,5 +204,42 @@ public class MailService { javaMailSender.setJavaMailProperties(props); return javaMailSender; } + + private String getContent(String template, Map context) { + if (MapUtils.isNotEmpty(context)) { + for (String k : context.keySet()) { + if (StringUtils.isNotBlank(context.get(k))) { + template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k)); + } + } + } + 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 (n.getEnable().equals("true") && n.getEvent().equals("执行成功")) { + successEmailList = userService.queryEmail(n.getNames()); + } + if (n.getEnable().equals("true") && n.getEvent().equals("执行失败")) { + failEmailList = userService.queryEmail(n.getNames()); + } + } + } else { + LogUtil.error("Recipient information is empty"); + } + + if (status.equals("Success") || status.equals("Completed")) { + recipientEmails = successEmailList.toArray(new String[0]); + } else { + recipientEmails = failEmailList.toArray(new String[0]); + } + return recipientEmails; + } + } 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 88c1156d21..80e73f6f6f 100644 --- a/backend/src/main/java/io/metersphere/notice/service/NoticeService.java +++ b/backend/src/main/java/io/metersphere/notice/service/NoticeService.java @@ -23,46 +23,30 @@ public class NoticeService { List notices = noticeMapper.selectByExample(example); if (notices.size() > 0) { noticeMapper.deleteByExample(example); - noticeRequest.getNotices().forEach(n -> { - if (n.getNames().length > 0) { - for (String x : n.getNames()) { - notice.setEvent(n.getEvent()); - notice.setEmail(n.getEmail()); - notice.setEnable(n.getEnable()); - notice.setTestId(noticeRequest.getTestId()); - notice.setName(x); - noticeMapper.insert(notice); - } - } else { - notice.setEvent(n.getEvent()); - notice.setEmail(n.getEmail()); - notice.setEnable(n.getEnable()); - notice.setTestId(noticeRequest.getTestId()); - notice.setName(""); - noticeMapper.insert(notice); - } - }); - } else { - noticeRequest.getNotices().forEach(n -> { - if (n.getNames().length > 0) { - for (String x : n.getNames()) { - notice.setEvent(n.getEvent()); - notice.setEmail(n.getEmail()); - notice.setEnable(n.getEnable()); - notice.setTestId(noticeRequest.getTestId()); - notice.setName(x); - noticeMapper.insert(notice); - } - } else { - notice.setEvent(n.getEvent()); - notice.setEmail(n.getEmail()); - notice.setEnable(n.getEnable()); - notice.setTestId(noticeRequest.getTestId()); - notice.setName(""); - noticeMapper.insert(notice); - } - }); } + saveNotice(noticeRequest, notice); + } + + private void saveNotice(NoticeRequest noticeRequest, Notice notice) { + noticeRequest.getNotices().forEach(n -> { + if (n.getNames().length > 0) { + for (String x : n.getNames()) { + notice.setEvent(n.getEvent()); + notice.setEmail(n.getEmail()); + notice.setEnable(n.getEnable()); + notice.setTestId(noticeRequest.getTestId()); + notice.setName(x); + noticeMapper.insert(notice); + } + } else { + notice.setEvent(n.getEvent()); + notice.setEmail(n.getEmail()); + notice.setEnable(n.getEnable()); + notice.setTestId(noticeRequest.getTestId()); + notice.setName(""); + noticeMapper.insert(notice); + } + }); } public List queryNotice(String id) { @@ -72,8 +56,8 @@ public class NoticeService { List notice = new ArrayList<>(); List success = new ArrayList<>(); List fail = new ArrayList<>(); - String[] successArray = new String[success.size()]; - String[] failArray = new String[fail.size()]; + String[] successArray; + String[] failArray; NoticeDetail notice1 = new NoticeDetail(); NoticeDetail notice2 = new NoticeDetail(); if (notices.size() > 0) { 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 16880b8bc4..f76044f407 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -238,6 +238,15 @@ 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); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + } + } return engine.getReportId(); } @@ -280,7 +289,7 @@ public class PerformanceTestService { testReport.setUserId(SessionUtils.getUser().getId()); } // 启动测试 - + List noticeList = null; try { engine.start(); // 启动正常修改状态 starting @@ -305,24 +314,15 @@ public class PerformanceTestService { reportResult.setReportKey(ReportKeys.ResultStatus.name()); reportResult.setReportValue("Ready"); // 初始化一个 result_status, 这个值用在data-streaming中 loadTestReportResultMapper.insertSelective(reportResult); - if (triggerMode.equals("SCHEDULE")) { - List notice = null; - try { - notice = noticeService.queryNotice(loadTest.getId()); - } catch (Exception e) { - LogUtil.error(e); - } - try { - mailService.sendHtml(engine.getReportId(), notice, loadTest.getStatus(), "performance"); - } catch (Exception e) { - LogUtil.error(e); - } - } } catch (MSException e) { LogUtil.error(e); 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); + } throw e; } } @@ -445,6 +445,17 @@ public class PerformanceTestService { reportService.stopEngine(loadTest, engine); // 停止测试之后设置报告的状态 reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name()); + List noticeList = null; + if (loadTestReport.getTriggerMode().equals("SCHEDULE")) { + try { + noticeList = noticeService.queryNotice(loadTest.getId()); + mailService.sendPerformanceNotification(noticeList, loadTestReport.getStatus(), loadTest); + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + } + } + + } } 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 68922df0eb..42c7800298 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseCommentService.java @@ -49,7 +49,7 @@ public class TestCaseCommentService { SaveTestCaseReviewRequest caseReviewRequest = new SaveTestCaseReviewRequest(); List userIds = new ArrayList<>(); userIds.add(testCaseWithBLOBs.getMaintainer()); - mailService.sendHtml(userIds, "comment", caseReviewRequest, request, testCaseWithBLOBs); + mailService.sendCommentNotice(userIds, request, testCaseWithBLOBs); } 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 56d2ab1891..d0b7e590f9 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseReviewService.java @@ -20,7 +20,10 @@ import io.metersphere.service.UserService; import io.metersphere.track.dto.TestCaseReviewDTO; import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.dto.TestReviewDTOWithMetric; -import io.metersphere.track.request.testreview.*; +import io.metersphere.track.request.testreview.QueryCaseReviewRequest; +import io.metersphere.track.request.testreview.QueryTestReviewRequest; +import io.metersphere.track.request.testreview.ReviewRelevanceRequest; +import io.metersphere.track.request.testreview.SaveTestCaseReviewRequest; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; @@ -31,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; -import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.stream.Collectors; @@ -73,7 +75,6 @@ public class TestCaseReviewService { String reviewId = UUID.randomUUID().toString(); List projectIds = reviewRequest.getProjectIds(); List userIds = reviewRequest.getUserIds(); - projectIds.forEach(projectId -> { TestCaseReviewProject testCaseReviewProject = new TestCaseReviewProject(); testCaseReviewProject.setProjectId(projectId); @@ -94,9 +95,11 @@ public class TestCaseReviewService { reviewRequest.setCreator(SessionUtils.getUser().getId()); reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name()); testCaseReviewMapper.insert(reviewRequest); - SaveCommentRequest request = new SaveCommentRequest(); - TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); - mailService.sendHtml(userIds, "reviewer", reviewRequest, request, testCaseWithBLOBs); + try { + mailService.sendReviewerNotice(userIds, reviewRequest); + } catch (Exception e) { + LogUtil.error(e); + } } @@ -153,9 +156,11 @@ public class TestCaseReviewService { testCaseReview.setUpdateTime(System.currentTimeMillis()); checkCaseReviewExist(testCaseReview); testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); - SaveCommentRequest request = new SaveCommentRequest(); - TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); - mailService.sendHtml(testCaseReview.getUserIds(), "reviewer", testCaseReview, request, testCaseWithBLOBs); + try { + mailService.sendReviewerNotice(testCaseReview.getUserIds(), testCaseReview); + } catch (Exception e) { + LogUtil.error(e); + } } private void editCaseReviewer(SaveTestCaseReviewRequest testCaseReview) { @@ -342,22 +347,17 @@ public class TestCaseReviewService { } } testCaseReview.setStatus(TestPlanStatus.Completed.name()); - SaveCommentRequest request = new SaveCommentRequest(); - TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest(); TestCaseReview _testCaseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId); List userIds = new ArrayList<>(); userIds.add(_testCaseReview.getCreator()); - + testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); try { BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview); - } catch (IllegalAccessException e) { - LogUtil.error(e); - } catch (InvocationTargetException e) { + mailService.sendEndNotice(userIds, testCaseReviewRequest); + } catch (Exception e) { LogUtil.error(e); } - mailService.sendHtml(userIds, "end", testCaseReviewRequest, request, testCaseWithBLOBs); - testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); } public List listRelateAll(String type) { diff --git a/backend/src/main/resources/mail/failPerformance.html b/backend/src/main/resources/mail/failPerformance.html new file mode 100644 index 0000000000..e9e70b33d2 --- /dev/null +++ b/backend/src/main/resources/mail/failPerformance.html @@ -0,0 +1,22 @@ + + + + + MeterSphere + + +
+
+

${title}

+
+
+

尊敬的用户:

+

您好: +

+
+

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

+ +
+ + \ No newline at end of file diff --git a/frontend/src/business/components/api/test/OneClickOperation.vue b/frontend/src/business/components/api/test/OneClickOperation.vue index 6423235559..579dea0d8c 100644 --- a/frontend/src/business/components/api/test/OneClickOperation.vue +++ b/frontend/src/business/components/api/test/OneClickOperation.vue @@ -22,11 +22,12 @@