refactor: 兼容context为空的问题
This commit is contained in:
parent
29fc874449
commit
5799a1b3c8
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<String> relatedUsers = (List<String>) paramMap.get("userIds");
|
||||
List<String> relatedUsers = (List<String>) paramMap.get("userIds");
|
||||
List<Receiver> 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<String> relatedUsers = (List<String>) paramMap.get("userIds");
|
||||
List<String> relatedUsers = (List<String>) paramMap.get("userIds");
|
||||
List<Receiver> receivers = relatedUsers.stream()
|
||||
.map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name()))
|
||||
.collect(Collectors.toList());
|
||||
|
|
Loading…
Reference in New Issue