refactor: 兼容context为空的问题

This commit is contained in:
Captain.B 2021-08-24 18:09:00 +08:00 committed by 刘瑞斌
parent 29fc874449
commit 5799a1b3c8
3 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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());
}