diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index fc234d90f9..4eaf2239f1 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -139,16 +139,19 @@ public class ApiDefinitionExecResultService { BeanMap beanMap = new BeanMap(apiTestCaseWithBLOBs); String event; + String status; if (StringUtils.equals(result.getStatus(), "success")) { event = NoticeConstants.Event.EXECUTE_SUCCESSFUL; + status = "成功"; } else { event = NoticeConstants.Event.EXECUTE_FAILED; + status = "失败"; } Map paramMap = new HashMap<>(beanMap); paramMap.put("operator", SessionUtils.getUserId()); paramMap.put("status", result.getStatus()); - String context = "${operator}执行了接口用例: ${name}, 执行结果: ${status}"; + String context = "${operator}执行接口用例" + status + ": ${name}"; NoticeModel noticeModel = NoticeModel.builder() .operator(SessionUtils.getUserId()) .context(context) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index bb20542865..c0001012d0 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -601,16 +601,19 @@ public class ApiScenarioReportService { BeanMap beanMap = new BeanMap(result); String event; + String status; if (StringUtils.equals(result.getLastResult(), "Success")) { event = NoticeConstants.Event.EXECUTE_SUCCESSFUL; + status = "成功"; } else { event = NoticeConstants.Event.EXECUTE_FAILED; + status = "失败"; } Map paramMap = new HashMap<>(beanMap); paramMap.put("operator", SessionUtils.getUserId()); paramMap.put("status", result.getLastResult()); - String context = "${operator}执行了接口用例: ${name}, 执行结果: ${status}"; + String context = "${operator}执行接口自动化" + status + ": ${name}"; NoticeModel noticeModel = NoticeModel.builder() .operator(SessionUtils.getUserId()) .context(context) diff --git a/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java index 0e6e9cfecc..45eea5ddc2 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java @@ -51,6 +51,10 @@ public abstract class AbstractNoticeSender implements NoticeSender { context = noticeModel.getContext(); break; } + // 兼容 + if (StringUtils.isBlank(context)) { + context = noticeModel.getContext(); + } return getContent(context, noticeModel.getParamMap()); } @@ -82,6 +86,12 @@ public abstract class AbstractNoticeSender implements NoticeSender { } } catch (IOException e) { LogUtil.error(e); + // 兼容 + try { + URL resource3 = this.getClass().getResource("/mail/" + noticeModel.getMailTemplate() + ".html"); + context = IOUtils.toString(resource3, StandardCharsets.UTF_8); + } catch (IOException ex) { + } } return getContent(context, noticeModel.getParamMap()); } @@ -126,7 +136,7 @@ public abstract class AbstractNoticeSender implements NoticeSender { switch (userId) { case NoticeConstants.RelatedUser.EXECUTOR: if (StringUtils.equals(NoticeConstants.Event.CREATE, event)) { - List relatedUsers = (List) paramMap.get("userIds"); + List relatedUsers = (List) paramMap.get("userIds"); List receivers = relatedUsers.stream() .map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name())) .collect(Collectors.toList()); @@ -151,7 +161,7 @@ public abstract class AbstractNoticeSender implements NoticeSender { break; case NoticeConstants.RelatedUser.MAINTAINER: if (StringUtils.equals(NoticeConstants.Event.COMMENT, event)) { - List relatedUsers = (List) paramMap.get("userIds"); + List relatedUsers = (List) paramMap.get("userIds"); List receivers = relatedUsers.stream() .map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name())) .collect(Collectors.toList());