fix: 重构邮箱代码,修复一键运行报错

This commit is contained in:
wenyann 2020-09-27 11:26:28 +08:00
parent ea9a2cef59
commit 666532bd8c
10 changed files with 251 additions and 190 deletions

View File

@ -119,18 +119,14 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
queue.clear(); queue.clear();
super.teardownTest(context); super.teardownTest(context);
NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class); NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class);
List<NoticeDetail> notice = null;
try { try {
notice = noticeService.queryNotice(testResult.getTestId()); List<NoticeDetail> noticeList = noticeService.queryNotice(testResult.getTestId());
} catch (Exception e) { MailService mailService = CommonBeanFactory.getBean(MailService.class);
LogUtil.error(e); mailService.sendApiNotification(report, noticeList);
}
MailService mailService = CommonBeanFactory.getBean(MailService.class);
try {
mailService.sendHtml(report.getId(), notice, report.getStatus(), "api");
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
} }
} }
private RequestResult getRequestResult(SampleResult result) { private RequestResult getRequestResult(SampleResult result) {

View File

@ -2,8 +2,10 @@ package io.metersphere.notice.service;
import io.metersphere.api.dto.APIReportResult; import io.metersphere.api.dto.APIReportResult;
import io.metersphere.base.domain.ApiTestReportDetail; import io.metersphere.base.domain.ApiTestReportDetail;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.domain.Schedule; import io.metersphere.base.domain.Schedule;
import io.metersphere.base.mapper.ApiTestReportDetailMapper; 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.ExtApiTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.commons.constants.ScheduleGroup; import io.metersphere.commons.constants.ScheduleGroup;
@ -28,6 +30,8 @@ public class ApiAndPerformanceHelper {
private ApiTestReportDetailMapper apiTestReportDetailMapper; private ApiTestReportDetailMapper apiTestReportDetailMapper;
@Resource @Resource
private ScheduleService scheduleService; private ScheduleService scheduleService;
@Resource
private LoadTestReportMapper loadTestReportMapper;
public APIReportResult getApi(String reportId) { public APIReportResult getApi(String reportId) {
APIReportResult result = extApiTestReportMapper.get(reportId); APIReportResult result = extApiTestReportMapper.get(reportId);
@ -50,5 +54,9 @@ public class ApiAndPerformanceHelper {
} }
return null; return null;
} }
public LoadTestReportWithBLOBs getLoadTestReport(String id) {
return loadTestReportMapper.selectByPrimaryKey(id);
}
} }

View File

@ -1,13 +1,13 @@
package io.metersphere.notice.service; 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.SystemParameter;
import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.ParamConstants; import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.utils.EncryptUtils; import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import io.metersphere.notice.domain.NoticeDetail; import io.metersphere.notice.domain.NoticeDetail;
import io.metersphere.service.SystemParameterService; import io.metersphere.service.SystemParameterService;
@ -24,6 +24,7 @@ import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -38,86 +39,99 @@ public class MailService {
@Resource @Resource
private SystemParameterService systemParameterService; private SystemParameterService systemParameterService;
public void sendPerformanceNotification(List<NoticeDetail> noticeList, String status, LoadTestWithBLOBs loadTest) {
public void sendHtml(String id, List<NoticeDetail> notice, String status, String type) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); 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<String, String> context = new HashMap<>(); Map<String, String> context = new HashMap<>();
context.put("title", type + Translator.get("timing_task_result_notification")); context.put("title", "Performance" + Translator.get("timing_task_result_notification"));
context.put("testName", testName); context.put("testName", loadTest.getName());
context.put("id", loadTest.getId());
context.put("url", baseSystemConfigDTO.getUrl()); context.put("url", baseSystemConfigDTO.getUrl());
context.put("id", id); String performanceTemplate = "";
context.put("type", type);
try { try {
String failTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8); if (status.equals("Completed")) {
String successTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8); performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8);
String successPerformanceTemplate = 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);
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom(javaMailSender.getUsername());
helper.setSubject(Translator.get("timing_task_result_notification"));
String[] users;
List<String> successEmailList = new ArrayList<>();
List<String> 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");
} }
sendHtmlTimeTasks(noticeList, status, context, performanceTemplate);
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);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error(e);
} }
}
public void sendApiNotification(ApiTestReport apiTestReport, List<NoticeDetail> noticeList) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Map<String, String> 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 { try {
javaMailSender.send(mimeMessage); if (apiTestReport.getStatus().equals("Success")) {
} catch (MailException e) { 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); LogUtil.error(e);
} }
} }
private String getContent(String template, Map<String, String> context) { private void sendHtmlTimeTasks(List<NoticeDetail> noticeList, String status, Map<String, String> context, String template) throws MessagingException {
if (MapUtils.isNotEmpty(context)) { JavaMailSenderImpl javaMailSender = getMailSender();
for (String k : context.keySet()) { MimeMessage mimeMessage = javaMailSender.createMimeMessage();
if (StringUtils.isNotBlank(context.get(k))) { MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
template = RegExUtils.replaceAll(template, "\\$\\{" + k + "}", context.get(k)); 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<String> userIds, SaveTestCaseReviewRequest reviewRequest) {
Map<String, String> 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<String> userIds, String type, SaveTestCaseReviewRequest reviewRequest, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) { public void sendCommentNotice(List<String> userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Map<String, String> 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<String> userIds, SaveTestCaseReviewRequest reviewRequest) {
Map<String, String> 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<String, String> getReviewContext(SaveTestCaseReviewRequest reviewRequest) {
Long startTime = reviewRequest.getCreateTime(); Long startTime = reviewRequest.getCreateTime();
Long endTime = reviewRequest.getEndTime(); Long endTime = reviewRequest.getEndTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ -131,60 +145,35 @@ public class MailService {
if (!eTime.equals("null")) { if (!eTime.equals("null")) {
end = sdf.format(new Date(Long.parseLong(eTime))); end = sdf.format(new Date(Long.parseLong(eTime)));
} }
JavaMailSenderImpl javaMailSender = getMailSender();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
Map<String, String> context = new HashMap<>(); Map<String, String> context = new HashMap<>();
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
context.put("url", baseSystemConfigDTO.getUrl());
context.put("creator", reviewRequest.getCreator()); context.put("creator", reviewRequest.getCreator());
context.put("maintainer", testCaseWithBLOBs.getMaintainer());
context.put("testCaseName", testCaseWithBLOBs.getName());
context.put("reviewName", reviewRequest.getName()); context.put("reviewName", reviewRequest.getName());
context.put("description", request.getDescription());
context.put("start", start); context.put("start", start);
context.put("end", end); context.put("end", end);
context.put("url", baseSystemConfigDTO.getUrl());
context.put("id", reviewRequest.getId()); context.put("id", reviewRequest.getId());
return context;
}
private void sendReviewNotice(List<String> userIds, Map<String, String> 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<String> emails = new ArrayList<>();
try { try {
String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8); emails = userService.queryEmailByIds(userIds);
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<String> 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);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e); LogUtil.error("Recipient information is empty");
}
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);
} }
private JavaMailSenderImpl getMailSender() { private JavaMailSenderImpl getMailSender() {
@ -215,5 +204,42 @@ public class MailService {
javaMailSender.setJavaMailProperties(props); javaMailSender.setJavaMailProperties(props);
return javaMailSender; return javaMailSender;
} }
private String getContent(String template, Map<String, String> 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<NoticeDetail> noticeList, String status) {
String[] recipientEmails;
List<String> successEmailList = new ArrayList<>();
List<String> 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;
}
} }

View File

@ -23,46 +23,30 @@ public class NoticeService {
List<Notice> notices = noticeMapper.selectByExample(example); List<Notice> notices = noticeMapper.selectByExample(example);
if (notices.size() > 0) { if (notices.size() > 0) {
noticeMapper.deleteByExample(example); 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<NoticeDetail> queryNotice(String id) { public List<NoticeDetail> queryNotice(String id) {
@ -72,8 +56,8 @@ public class NoticeService {
List<NoticeDetail> notice = new ArrayList<>(); List<NoticeDetail> notice = new ArrayList<>();
List<String> success = new ArrayList<>(); List<String> success = new ArrayList<>();
List<String> fail = new ArrayList<>(); List<String> fail = new ArrayList<>();
String[] successArray = new String[success.size()]; String[] successArray;
String[] failArray = new String[fail.size()]; String[] failArray;
NoticeDetail notice1 = new NoticeDetail(); NoticeDetail notice1 = new NoticeDetail();
NoticeDetail notice2 = new NoticeDetail(); NoticeDetail notice2 = new NoticeDetail();
if (notices.size() > 0) { if (notices.size() > 0) {

View File

@ -238,6 +238,15 @@ public class PerformanceTestService {
} }
startEngine(loadTest, engine, request.getTriggerMode()); startEngine(loadTest, engine, request.getTriggerMode());
List<NoticeDetail> 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(); return engine.getReportId();
} }
@ -280,7 +289,7 @@ public class PerformanceTestService {
testReport.setUserId(SessionUtils.getUser().getId()); testReport.setUserId(SessionUtils.getUser().getId());
} }
// 启动测试 // 启动测试
List<NoticeDetail> noticeList = null;
try { try {
engine.start(); engine.start();
// 启动正常修改状态 starting // 启动正常修改状态 starting
@ -305,24 +314,15 @@ public class PerformanceTestService {
reportResult.setReportKey(ReportKeys.ResultStatus.name()); reportResult.setReportKey(ReportKeys.ResultStatus.name());
reportResult.setReportValue("Ready"); // 初始化一个 result_status, 这个值用在data-streaming中 reportResult.setReportValue("Ready"); // 初始化一个 result_status, 这个值用在data-streaming中
loadTestReportResultMapper.insertSelective(reportResult); loadTestReportResultMapper.insertSelective(reportResult);
if (triggerMode.equals("SCHEDULE")) {
List<NoticeDetail> 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) { } catch (MSException e) {
LogUtil.error(e); LogUtil.error(e);
loadTest.setStatus(PerformanceTestStatus.Error.name()); loadTest.setStatus(PerformanceTestStatus.Error.name());
loadTest.setDescription(e.getMessage()); loadTest.setDescription(e.getMessage());
loadTestMapper.updateByPrimaryKeySelective(loadTest); loadTestMapper.updateByPrimaryKeySelective(loadTest);
if (triggerMode.equals("SCHEDULE")) {
noticeList = noticeService.queryNotice(loadTest.getId());
mailService.sendPerformanceNotification(noticeList, loadTest.getStatus(), loadTest);
}
throw e; throw e;
} }
} }
@ -445,6 +445,17 @@ public class PerformanceTestService {
reportService.stopEngine(loadTest, engine); reportService.stopEngine(loadTest, engine);
// 停止测试之后设置报告的状态 // 停止测试之后设置报告的状态
reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name()); reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name());
List<NoticeDetail> 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);
}
}
} }
} }

View File

@ -49,7 +49,7 @@ public class TestCaseCommentService {
SaveTestCaseReviewRequest caseReviewRequest = new SaveTestCaseReviewRequest(); SaveTestCaseReviewRequest caseReviewRequest = new SaveTestCaseReviewRequest();
List<String> userIds = new ArrayList<>(); List<String> userIds = new ArrayList<>();
userIds.add(testCaseWithBLOBs.getMaintainer()); userIds.add(testCaseWithBLOBs.getMaintainer());
mailService.sendHtml(userIds, "comment", caseReviewRequest, request, testCaseWithBLOBs); mailService.sendCommentNotice(userIds, request, testCaseWithBLOBs);
} }

View File

@ -20,7 +20,10 @@ import io.metersphere.service.UserService;
import io.metersphere.track.dto.TestCaseReviewDTO; import io.metersphere.track.dto.TestCaseReviewDTO;
import io.metersphere.track.dto.TestReviewCaseDTO; import io.metersphere.track.dto.TestReviewCaseDTO;
import io.metersphere.track.dto.TestReviewDTOWithMetric; 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.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
@ -31,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -73,7 +75,6 @@ public class TestCaseReviewService {
String reviewId = UUID.randomUUID().toString(); String reviewId = UUID.randomUUID().toString();
List<String> projectIds = reviewRequest.getProjectIds(); List<String> projectIds = reviewRequest.getProjectIds();
List<String> userIds = reviewRequest.getUserIds(); List<String> userIds = reviewRequest.getUserIds();
projectIds.forEach(projectId -> { projectIds.forEach(projectId -> {
TestCaseReviewProject testCaseReviewProject = new TestCaseReviewProject(); TestCaseReviewProject testCaseReviewProject = new TestCaseReviewProject();
testCaseReviewProject.setProjectId(projectId); testCaseReviewProject.setProjectId(projectId);
@ -94,9 +95,11 @@ public class TestCaseReviewService {
reviewRequest.setCreator(SessionUtils.getUser().getId()); reviewRequest.setCreator(SessionUtils.getUser().getId());
reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name()); reviewRequest.setStatus(TestCaseReviewStatus.Prepare.name());
testCaseReviewMapper.insert(reviewRequest); testCaseReviewMapper.insert(reviewRequest);
SaveCommentRequest request = new SaveCommentRequest(); try {
TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); mailService.sendReviewerNotice(userIds, reviewRequest);
mailService.sendHtml(userIds, "reviewer", reviewRequest, request, testCaseWithBLOBs); } catch (Exception e) {
LogUtil.error(e);
}
} }
@ -153,9 +156,11 @@ public class TestCaseReviewService {
testCaseReview.setUpdateTime(System.currentTimeMillis()); testCaseReview.setUpdateTime(System.currentTimeMillis());
checkCaseReviewExist(testCaseReview); checkCaseReviewExist(testCaseReview);
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview); testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
SaveCommentRequest request = new SaveCommentRequest(); try {
TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs(); mailService.sendReviewerNotice(testCaseReview.getUserIds(), testCaseReview);
mailService.sendHtml(testCaseReview.getUserIds(), "reviewer", testCaseReview, request, testCaseWithBLOBs); } catch (Exception e) {
LogUtil.error(e);
}
} }
private void editCaseReviewer(SaveTestCaseReviewRequest testCaseReview) { private void editCaseReviewer(SaveTestCaseReviewRequest testCaseReview) {
@ -342,22 +347,17 @@ public class TestCaseReviewService {
} }
} }
testCaseReview.setStatus(TestPlanStatus.Completed.name()); testCaseReview.setStatus(TestPlanStatus.Completed.name());
SaveCommentRequest request = new SaveCommentRequest();
TestCaseWithBLOBs testCaseWithBLOBs = new TestCaseWithBLOBs();
SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest(); SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest();
TestCaseReview _testCaseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId); TestCaseReview _testCaseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId);
List<String> userIds = new ArrayList<>(); List<String> userIds = new ArrayList<>();
userIds.add(_testCaseReview.getCreator()); userIds.add(_testCaseReview.getCreator());
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
try { try {
BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview); BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview);
} catch (IllegalAccessException e) { mailService.sendEndNotice(userIds, testCaseReviewRequest);
LogUtil.error(e); } catch (Exception e) {
} catch (InvocationTargetException e) {
LogUtil.error(e); LogUtil.error(e);
} }
mailService.sendHtml(userIds, "end", testCaseReviewRequest, request, testCaseWithBLOBs);
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
} }
public List<TestReviewDTOWithMetric> listRelateAll(String type) { public List<TestReviewDTOWithMetric> listRelateAll(String type) {

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MeterSphere</title>
</head>
<body>
<div>
<div style="text-align: left">
<h3>${title}</h3>
</div>
<div style="text-align: left">
<p>尊敬的用户:</p>
<p style="margin-left: 60px">您好:
</div>
<div style="margin-left: 100px">
<p>您所执行的 ${testName} 启动失败<br/>
</div>
</div>
</body>
</html>

View File

@ -22,11 +22,12 @@
<script> <script>
import MsDialogFooter from '../../common/components/MsDialogFooter' import MsDialogFooter from '../../common/components/MsDialogFooter'
import {Scenario, Test} from "./model/ScenarioModel" import {Test} from "./model/ScenarioModel"
import MsApiScenarioConfig from "./components/ApiScenarioConfig"; import MsApiScenarioConfig from "./components/ApiScenarioConfig";
import MsApiReportStatus from "../report/ApiReportStatus"; import MsApiReportStatus from "../report/ApiReportStatus";
import MsApiReportDialog from "./ApiReportDialog"; import MsApiReportDialog from "./ApiReportDialog";
import {getUUID} from "@/common/js/utils"; import {getUUID} from "@/common/js/utils";
import {parseEnvironment} from "./model/EnvironmentModel";
export default { export default {
@ -105,11 +106,17 @@
let environments = response.data; let environments = response.data;
let environmentMap = new Map(); let environmentMap = new Map();
environments.forEach(environment => { environments.forEach(environment => {
parseEnvironment(environment);
environmentMap.set(environment.id, environment); environmentMap.set(environment.id, environment);
}); });
this.test.scenarioDefinition.forEach(scenario => { this.test.scenarioDefinition.forEach(scenario => {
if (scenario.environmentId) { if (scenario.environmentId) {
scenario.environment = environmentMap.get(scenario.environmentId); let env = environmentMap.get(scenario.environmentId);
if (!env) {
scenario.environmentId = undefined;
} else {
scenario.environment = env;
}
} }
} }
) )

View File

@ -174,6 +174,13 @@ export default {
this.result = this.$get('notice/query/' + this.testId, response => { this.result = this.$get('notice/query/' + this.testId, response => {
if (response.data.length > 0) { if (response.data.length > 0) {
this.tableData = response.data this.tableData = response.data
this.tableData[0].email="邮箱"
this.tableData[0].event="执行成功"
this.tableData[1].email="邮箱"
this.tableData[1].event="执行失败"
}else{
this.tableData[0].names=[]
this.tableData[1].names=[]
} }
}) })
} }