revert: 接口自动化定时任务和api调用发送通知回退
This commit is contained in:
parent
6fe07ab74b
commit
ae4e05a713
|
@ -18,6 +18,7 @@ import io.metersphere.track.request.testcase.TrackCount;
|
||||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||||
import io.metersphere.track.service.TestPlanScenarioCaseService;
|
import io.metersphere.track.service.TestPlanScenarioCaseService;
|
||||||
import io.metersphere.track.service.TestPlanTestCaseService;
|
import io.metersphere.track.service.TestPlanTestCaseService;
|
||||||
|
import org.apache.commons.beanutils.BeanMap;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -150,7 +151,12 @@ public class TestResultService {
|
||||||
testPlanTestCaseService.updateTestCaseStates(ids, TestPlanTestCaseStatus.Failure.name());
|
testPlanTestCaseService.updateTestCaseStates(ids, TestPlanTestCaseStatus.Failure.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (reportTask != null) {
|
||||||
|
if (StringUtils.equals(ReportTriggerMode.API.name(), reportTask.getTriggerMode())
|
||||||
|
|| StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), reportTask.getTriggerMode())) {
|
||||||
|
sendTask(reportTask, reportUrl, testResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
@ -189,4 +195,60 @@ public class TestResultService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sendTask(ApiTestReportVariable report, String reportUrl, TestResult testResult) {
|
||||||
|
if (report == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||||
|
NoticeSendService noticeSendService = CommonBeanFactory.getBean(NoticeSendService.class);
|
||||||
|
assert systemParameterService != null;
|
||||||
|
assert noticeSendService != null;
|
||||||
|
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||||
|
String url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId();
|
||||||
|
String url2 = baseSystemConfigDTO.getUrl() + "/#/api/automation/report/view/" + report.getId();
|
||||||
|
|
||||||
|
String successContext = "";
|
||||||
|
String failedContext = "";
|
||||||
|
String subject = "";
|
||||||
|
String event = "";
|
||||||
|
if (StringUtils.equals(ReportTriggerMode.API.name(), report.getTriggerMode())) {
|
||||||
|
successContext = "接口测试 API任务通知:jenkins所执行的" + report.getName() + "'执行成功" + "\n" + "执行环境:" + report.getExecutionEnvironment() + "\n" + "[接口定义暂无报告链接]" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + "(旧版)接口测试路径" + url + "\n" + "(新版)接口测试路径" + url2;
|
||||||
|
failedContext = "接口测试 API任务通知:jenkins所执行的" + report.getName() + "'执行失败" + "\n" + "执行环境:" + report.getExecutionEnvironment() + "\n" + "[接口定义暂无报告链接]" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + "(旧版)接口测试路径" + url + "\n" + "(新版)接口测试路径" + url2;
|
||||||
|
subject = Translator.get("task_notification_jenkins");
|
||||||
|
}
|
||||||
|
if (StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), report.getTriggerMode())) {
|
||||||
|
successContext = "接口测试定时任务通知:定时任务所执行的" + report.getName() + "'执行成功" + "\n" + "执行环境:" + report.getExecutionEnvironment() + "\n" + "[接口定义暂无报告链接]" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + "(旧版)接口测试路径" + url + "\n" + "(新版)接口测试路径" + url2;
|
||||||
|
failedContext = "接口测试定时任务通知:定时任务所执行的" + report.getName() + "'执行失败" + "\n" + "执行环境:" + report.getExecutionEnvironment() + "\n" + "[接口定义暂无报告链接]" + "\n" + "请点击下面链接进入测试报告页面" + "\n" + "(旧版)接口测试路径" + url + "\n" + "(新版)接口测试路径" + url2;
|
||||||
|
subject = Translator.get("task_notification");
|
||||||
|
}
|
||||||
|
if (StringUtils.equals("Success", report.getStatus())) {
|
||||||
|
event = NoticeConstants.Event.EXECUTE_SUCCESSFUL;
|
||||||
|
}
|
||||||
|
if (StringUtils.equals("success", report.getStatus())) {
|
||||||
|
event = NoticeConstants.Event.EXECUTE_SUCCESSFUL;
|
||||||
|
}
|
||||||
|
if (StringUtils.equals("Error", report.getStatus())) {
|
||||||
|
event = NoticeConstants.Event.EXECUTE_FAILED;
|
||||||
|
}
|
||||||
|
if (StringUtils.equals("error", report.getStatus())) {
|
||||||
|
event = NoticeConstants.Event.EXECUTE_FAILED;
|
||||||
|
}
|
||||||
|
Map paramMap = new HashMap<>();
|
||||||
|
paramMap.put("type", "api");
|
||||||
|
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
||||||
|
paramMap.putAll(new BeanMap(report));
|
||||||
|
NoticeModel noticeModel = NoticeModel.builder()
|
||||||
|
.operator(SessionUtils.getUserId())
|
||||||
|
.successContext(successContext)
|
||||||
|
.successMailTemplate("ApiSuccessfulNotification")
|
||||||
|
.failedContext(failedContext)
|
||||||
|
.failedMailTemplate("ApiFailedNotification")
|
||||||
|
.testId(testResult.getTestId())
|
||||||
|
.status(report.getStatus())
|
||||||
|
.event(event)
|
||||||
|
.subject(subject)
|
||||||
|
.paramMap(paramMap)
|
||||||
|
.build();
|
||||||
|
noticeSendService.send(report.getTriggerMode(), NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class NoticeService {
|
||||||
public List<MessageDetail> searchMessageByTypeBySend(String type, String projectId) {
|
public List<MessageDetail> searchMessageByTypeBySend(String type, String projectId) {
|
||||||
try {
|
try {
|
||||||
String orgId = "";
|
String orgId = "";
|
||||||
if (StringUtils.isNotEmpty(projectId)) {
|
if (null == SessionUtils.getUser()) {
|
||||||
Organization organization = extProjectMapper.getOrganizationByProjectId(projectId);
|
Organization organization = extProjectMapper.getOrganizationByProjectId(projectId);
|
||||||
orgId = organization.getId();
|
orgId = organization.getId();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue