refactor: jenkins 通知发送

This commit is contained in:
Captain.B 2021-08-27 16:57:21 +08:00 committed by 刘瑞斌
parent 58ef571fdd
commit 812f0c9147
4 changed files with 58 additions and 39 deletions

View File

@ -83,8 +83,11 @@ public class NoticeSendService {
} }
} }
/**
* jenkins 和定时任务触发的发送
*/
public void send(String triggerMode, String taskType, NoticeModel noticeModel) { public void send(String triggerMode, String taskType, NoticeModel noticeModel) {
// api和定时任务调用排除自己 // api和定时任务调用排除自己
noticeModel.setExcludeSelf(false); noticeModel.setExcludeSelf(false);
try { try {
List<MessageDetail> messageDetails = new ArrayList<>(); List<MessageDetail> messageDetails = new ArrayList<>();
@ -117,9 +120,24 @@ public class NoticeSendService {
} }
} }
/**
* 后台触发的发送没有session
*/
public void send(Organization organization, String taskType, NoticeModel noticeModel) { public void send(Organization organization, String taskType, NoticeModel noticeModel) {
try { try {
List<MessageDetail> messageDetails = noticeService.searchMessageByTypeAndOrganizationId(taskType, organization.getId()); List<MessageDetail> messageDetails;
// switch (taskType) {
// case NoticeConstants.Mode.API:
// String projectId = (String) noticeModel.getParamMap().get("projectId");
// messageDetails = noticeService.searchMessageByTypeBySend(NoticeConstants.TaskType.JENKINS_TASK, projectId);
// break;
// case NoticeConstants.Mode.SCHEDULE:
// messageDetails = noticeService.searchMessageByTestId(noticeModel.getTestId());
// break;
// default:
// break;
// }
messageDetails = noticeService.searchMessageByTypeAndOrganizationId(taskType, organization.getId());
// 异步发送通知 // 异步发送通知
messageDetails.stream() messageDetails.stream()

View File

@ -31,6 +31,7 @@ import io.metersphere.track.request.report.QueryTestPlanReportRequest;
import io.metersphere.track.request.report.TestPlanReportSaveRequest; import io.metersphere.track.request.report.TestPlanReportSaveRequest;
import io.metersphere.track.request.testcase.QueryTestPlanRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest;
import io.metersphere.track.request.testplan.LoadCaseRequest; import io.metersphere.track.request.testplan.LoadCaseRequest;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -195,7 +196,8 @@ public class TestPlanReportService {
testPlanReport.setUpdateTime(System.currentTimeMillis()); testPlanReport.setUpdateTime(System.currentTimeMillis());
try { try {
testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date())); testPlanReport.setName(testPlan.getName() + "-" + DateUtils.getTimeString(new Date()));
} catch (Exception ignored) {} } catch (Exception ignored) {
}
testPlanReport.setTriggerMode(saveRequest.getTriggerMode()); testPlanReport.setTriggerMode(saveRequest.getTriggerMode());
testPlanReport.setCreator(saveRequest.getUserId()); testPlanReport.setCreator(saveRequest.getUserId());
@ -803,12 +805,11 @@ public class TestPlanReportService {
} else { } else {
event = NoticeConstants.Event.EXECUTE_SUCCESSFUL; event = NoticeConstants.Event.EXECUTE_SUCCESSFUL;
} }
Map<String, Object> paramMap = new HashMap<>(); Map paramMap = new HashMap();
paramMap.put("testName", testPlan.getName());
paramMap.put("id", testPlanReport.getId());
paramMap.put("type", "testPlan"); paramMap.put("type", "testPlan");
paramMap.put("url", url); paramMap.put("url", url);
paramMap.put("status", testPlanReport.getStatus()); paramMap.put("projectId", projectId);
paramMap.putAll(new BeanMap(testPlanReport));
String successfulMailTemplate = ""; String successfulMailTemplate = "";
String errfoMailTemplate = ""; String errfoMailTemplate = "";
@ -831,8 +832,8 @@ public class TestPlanReportService {
.paramMap(paramMap) .paramMap(paramMap)
.build(); .build();
// noticeSendService.send(testPlanReport.getTriggerMode(), noticeModel); // noticeSendService.send(testPlanReport.getTriggerMode(), noticeModel);
Organization organization = projectService.getOrganizationByProjectId(projectId); // Organization organization = projectService.getOrganizationByProjectId(projectId);
noticeSendService.send(organization, testPlanReport.getTriggerMode(), noticeModel); noticeSendService.send(testPlanReport.getTriggerMode(), noticeModel);
} }
public TestPlanReport getTestPlanReport(String planId) { public TestPlanReport getTestPlanReport(String planId) {

View File

@ -82,7 +82,7 @@ export default {
this.totalCount = response.data.itemCount; this.totalCount = response.data.itemCount;
this.systemNoticeData.forEach(n => { this.systemNoticeData.forEach(n => {
n.user = this.userMap[n.operator]; n.user = this.userMap[n.operator] || {name: "MS"};
}); });
}); });
}, },

View File

@ -81,7 +81,7 @@ export default {
this.totalPage = response.data.pageCount; this.totalPage = response.data.pageCount;
this.totalCount = response.data.itemCount; this.totalCount = response.data.itemCount;
this.systemNoticeData.forEach(n => { this.systemNoticeData.forEach(n => {
n.user = this.userMap[n.operator]; n.user = this.userMap[n.operator] || {name: "MS"};
}); });
}); });
}, },