refactor: 测试计划发送通知
This commit is contained in:
parent
da7b8d0e76
commit
093bf40a51
|
@ -790,6 +790,7 @@ public class ApiDefinitionService {
|
|||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("url", request.getSwaggerUrl());
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.context(context)
|
||||
.testId(scheduleId)
|
||||
.subject(Translator.get("swagger_url_scheduled_import_notification"))
|
||||
|
@ -814,6 +815,7 @@ public class ApiDefinitionService {
|
|||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("url", request.getSwaggerUrl());
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.context(context)
|
||||
.testId(scheduleId)
|
||||
.subject(Translator.get("swagger_url_scheduled_import_notification"))
|
||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.commons.constants.*;
|
|||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.DateUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.notice.sender.NoticeModel;
|
||||
|
@ -242,6 +243,7 @@ public class TestResultService {
|
|||
paramMap.put("executionEnvironment", report.getExecutionEnvironment());
|
||||
paramMap.put("principal", report.getPrincipal());
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.successContext(successContext)
|
||||
.successMailTemplate("ApiSuccessfulNotification")
|
||||
.failedContext(failedContext)
|
||||
|
|
|
@ -38,6 +38,7 @@ public interface NoticeConstants {
|
|||
String CREATE = "CREATE";
|
||||
String UPDATE = "UPDATE";
|
||||
String DELETE = "DELETE";
|
||||
String COMPLETE = "COMPLETE";
|
||||
|
||||
String CASE_CREATE = "CASE_CREATE";
|
||||
String CASE_UPDATE = "CASE_UPDATE";
|
||||
|
|
|
@ -141,6 +141,7 @@ public class SendNoticeAspect {
|
|||
.mailTemplate(sendNotice.mailTemplate())
|
||||
.paramMap(paramMap)
|
||||
.event(sendNotice.event())
|
||||
.status((String) paramMap.get("status"))
|
||||
.build();
|
||||
noticeSendService.send(sendNotice.taskType(), noticeModel);
|
||||
}
|
||||
|
@ -170,6 +171,9 @@ public class SendNoticeAspect {
|
|||
case NoticeConstants.Event.COMMENT:
|
||||
operation = "评论了";
|
||||
break;
|
||||
case NoticeConstants.Event.COMPLETE:
|
||||
operation = "完成了";
|
||||
break;
|
||||
case NoticeConstants.Event.CLOSE_SCHEDULE:
|
||||
operation = "关闭了定时任务";
|
||||
break;
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class InSiteNoticeSender extends AbstractNoticeSender {
|
||||
|
@ -28,20 +29,22 @@ public class InSiteNoticeSender extends AbstractNoticeSender {
|
|||
|
||||
receivers.forEach(receiver -> {
|
||||
LogUtil.debug("发送站内通知: {}, 内容: {}", receiver, context);
|
||||
|
||||
Map<String, Object> paramMap = noticeModel.getParamMap();
|
||||
Notification notification = new Notification();
|
||||
notification.setTitle(noticeModel.getSubject());
|
||||
notification.setContent(context);
|
||||
notification.setOperator(noticeModel.getOperator());
|
||||
notification.setOperation(noticeModel.getEvent());
|
||||
notification.setResourceId((String) noticeModel.getParamMap().get("id"));
|
||||
notification.setResourceId((String) paramMap.get("id"));
|
||||
notification.setResourceType(messageDetail.getTaskType());
|
||||
//
|
||||
if (noticeModel.getParamMap().get("name") != null) {
|
||||
notification.setResourceName((String) noticeModel.getParamMap().get("name"));
|
||||
if (paramMap.get("name") != null) {
|
||||
notification.setResourceName((String) paramMap.get("name"));
|
||||
}
|
||||
|
||||
if (noticeModel.getParamMap().get("title") != null) {
|
||||
notification.setResourceName((String) noticeModel.getParamMap().get("title"));
|
||||
if (paramMap.get("title") != null) {
|
||||
notification.setResourceName((String) paramMap.get("title"));
|
||||
}
|
||||
|
||||
notification.setType(receiver.getType());
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.commons.constants.PerformanceTestStatus;
|
|||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.consumer.LoadTestFinishEvent;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.notice.sender.NoticeModel;
|
||||
|
@ -57,6 +58,7 @@ public class PerformanceNoticeEvent implements LoadTestFinishEvent {
|
|||
paramMap.put("status", loadTestReport.getStatus());
|
||||
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.successContext(successContext)
|
||||
.successMailTemplate("PerformanceApiSuccessNotification")
|
||||
.failedContext(failedContext)
|
||||
|
|
|
@ -123,7 +123,6 @@ public class TestCaseReviewController {
|
|||
|
||||
@PostMapping("/edit/status/{reviewId}")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_REVIEW_READ_EDIT)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.REVIEW_TASK, event = NoticeConstants.Event.UPDATE, mailTemplate = "track/ReviewEnd", subject = "测试评审通知")
|
||||
public void editTestPlanStatus(@PathVariable String reviewId) {
|
||||
checkPermissionService.checkTestReviewOwner(reviewId);
|
||||
testCaseReviewService.editTestReviewStatus(reviewId);
|
||||
|
|
|
@ -122,7 +122,8 @@ public class TestPlanController {
|
|||
@PostMapping("/delete/{testPlanId}")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_DELETE)
|
||||
@MsAuditLog(module = "track_test_plan", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#testPlanId)", msClass = TestPlanService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.TEST_PLAN_TASK, event = NoticeConstants.Event.DELETE, mailTemplate = "track/TestPlanDelete", subject = "测试计划通知")
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.TEST_PLAN_TASK, target = "#targetClass.getTestPlan(#testPlanId)", targetClass = TestPlanService.class,
|
||||
event = NoticeConstants.Event.DELETE, mailTemplate = "track/TestPlanDelete", subject = "测试计划通知")
|
||||
public int deleteTestPlan(@PathVariable String testPlanId) {
|
||||
checkPermissionService.checkTestPlanOwner(testPlanId);
|
||||
return testPlanService.deleteTestPlan(testPlanId);
|
||||
|
|
|
@ -18,7 +18,6 @@ import io.metersphere.commons.utils.ServiceUtils;
|
|||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.controller.request.member.QueryMemberRequest;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.log.utils.ReflexObjectUtil;
|
||||
import io.metersphere.log.vo.DetailColumn;
|
||||
import io.metersphere.log.vo.OperatingLogDetails;
|
||||
|
@ -79,19 +78,6 @@ public class TestCaseReviewService {
|
|||
private NoticeSendService noticeSendService;
|
||||
@Resource
|
||||
private SystemParameterService systemParameterService;
|
||||
@Resource
|
||||
private TestCaseReviewLoadMapper testCaseReviewLoadMapper;
|
||||
@Resource
|
||||
private TestCaseReviewApiCaseMapper testCaseReviewApiCaseMapper;
|
||||
@Resource
|
||||
private TestCaseReviewScenarioMapper testCaseReviewScenarioMapper;
|
||||
@Resource
|
||||
private ApiTestCaseMapper apiTestCaseMapper;
|
||||
@Resource
|
||||
private ApiScenarioMapper apiScenarioMapper;
|
||||
@Resource
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
|
||||
|
||||
public TestCaseReview saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) {
|
||||
checkCaseReviewExist(reviewRequest);
|
||||
|
@ -137,9 +123,8 @@ public class TestCaseReviewService {
|
|||
Map<String, String> paramMap = new HashMap<>();
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
paramMap.put("url", baseSystemConfigDTO.getUrl());
|
||||
User user = userMapper.selectByPrimaryKey(reviewRequest.getCreator());
|
||||
paramMap.put("creator", user.getName());
|
||||
paramMap.put("reviewName", reviewRequest.getName());
|
||||
paramMap.put("creator", reviewRequest.getCreator());
|
||||
paramMap.put("name", reviewRequest.getName());
|
||||
paramMap.put("start", start);
|
||||
paramMap.put("end", end);
|
||||
paramMap.put("id", reviewRequest.getId());
|
||||
|
@ -421,6 +406,28 @@ public class TestCaseReviewService {
|
|||
}
|
||||
testCaseReview.setStatus(TestCaseReviewStatus.Completed.name());
|
||||
testCaseReviewMapper.updateByPrimaryKeySelective(testCaseReview);
|
||||
SaveTestCaseReviewRequest testCaseReviewRequest = new SaveTestCaseReviewRequest();
|
||||
TestCaseReview _testCaseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId);
|
||||
|
||||
if (StringUtils.equals(TestCaseReviewStatus.Completed.name(), _testCaseReview.getStatus())) {
|
||||
try {
|
||||
BeanUtils.copyProperties(testCaseReviewRequest, _testCaseReview);
|
||||
String context = getReviewContext(testCaseReviewRequest, NoticeConstants.Event.UPDATE);
|
||||
Map<String, Object> paramMap = new HashMap<>(getReviewParamMap(testCaseReviewRequest));
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.context(context)
|
||||
.subject("测试评审通知")
|
||||
.mailTemplate("track/ReviewEnd")
|
||||
.paramMap(paramMap)
|
||||
.event(NoticeConstants.Event.COMPLETE)
|
||||
.status(TestCaseReviewStatus.Completed.name())
|
||||
.build();
|
||||
noticeSendService.send(NoticeConstants.TaskType.REVIEW_TASK, noticeModel);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<TestReviewDTOWithMetric> listRelateAll(ReviewRelateRequest relateRequest) {
|
||||
|
|
|
@ -982,6 +982,7 @@ public class TestPlanReportService {
|
|||
}
|
||||
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.successContext(successContext)
|
||||
.successMailTemplate(successfulMailTemplate)
|
||||
.failedContext(failedContext)
|
||||
|
|
|
@ -14,14 +14,20 @@ import io.metersphere.api.dto.definition.TestPlanApiCaseDTO;
|
|||
import io.metersphere.api.dto.definition.request.*;
|
||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||
import io.metersphere.api.jmeter.JMeterService;
|
||||
import io.metersphere.api.service.*;
|
||||
import io.metersphere.api.service.ApiAutomationService;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.api.service.ApiScenarioReportService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.*;
|
||||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.MathUtils;
|
||||
import io.metersphere.commons.utils.ServiceUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.BaseSystemConfigDTO;
|
||||
import io.metersphere.dto.IssueTemplateDao;
|
||||
import io.metersphere.i18n.Translator;
|
||||
|
@ -190,7 +196,7 @@ public class TestPlanService {
|
|||
return Optional.ofNullable(testPlanMapper.selectByPrimaryKey(testPlanId)).orElse(new TestPlanWithBLOBs());
|
||||
}
|
||||
|
||||
public TestPlan editTestPlan(TestPlanDTO testPlan) {
|
||||
public TestPlan editTestPlan(TestPlanWithBLOBs testPlan) {
|
||||
checkTestPlanExist(testPlan);
|
||||
TestPlan res = testPlanMapper.selectByPrimaryKey(testPlan.getId()); // 先查一次库
|
||||
testPlan.setUpdateTime(System.currentTimeMillis());
|
||||
|
@ -226,7 +232,7 @@ public class TestPlanService {
|
|||
i = testPlanMapper.updateByPrimaryKeyWithBLOBs(testPlan); // 更新
|
||||
}
|
||||
|
||||
return testPlan;
|
||||
return testPlanMapper.selectByPrimaryKey(testPlan.getId());
|
||||
}
|
||||
|
||||
//计划内容
|
||||
|
@ -248,7 +254,7 @@ public class TestPlanService {
|
|||
Map<String, Object> context = new HashMap<>();
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
context.put("url", baseSystemConfigDTO.getUrl());
|
||||
context.put("testPlanName", testPlan.getName());
|
||||
context.put("name", testPlan.getName());
|
||||
context.put("start", start);
|
||||
context.put("end", end);
|
||||
context.put("id", testPlan.getId());
|
||||
|
@ -374,11 +380,11 @@ public class TestPlanService {
|
|||
statusList.addAll(testPlanApiCaseService.getExecResultByPlanId(testPlanId));
|
||||
statusList.addAll(testPlanScenarioCaseService.getExecResultByPlanId(testPlanId));
|
||||
statusList.addAll(testPlanLoadCaseService.getStatus(testPlanId));
|
||||
TestPlanDTO testPlanDTO = new TestPlanDTO();
|
||||
testPlanDTO.setId(testPlanId);
|
||||
TestPlanWithBLOBs testPlanWithBLOBs = testPlanMapper.selectByPrimaryKey(testPlanId);
|
||||
testPlanWithBLOBs.setId(testPlanId);
|
||||
if (statusList.size() == 0) { // 原先status不是prepare, 但删除所有关联用例的情况
|
||||
testPlanDTO.setStatus(TestPlanStatus.Prepare.name());
|
||||
editTestPlan(testPlanDTO);
|
||||
testPlanWithBLOBs.setStatus(TestPlanStatus.Prepare.name());
|
||||
editTestPlan(testPlanWithBLOBs);
|
||||
return;
|
||||
}
|
||||
int passNum = 0, prepareNum = 0, failNum = 0;
|
||||
|
@ -394,14 +400,16 @@ public class TestPlanService {
|
|||
}
|
||||
}
|
||||
if (passNum == statusList.size()) { // 全部通过
|
||||
testPlanDTO.setStatus(TestPlanStatus.Completed.name());
|
||||
this.editTestPlan(testPlanDTO);
|
||||
testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name());
|
||||
this.editTestPlan(testPlanWithBLOBs);
|
||||
// 发送成功通知
|
||||
sendCompletedNotice(testPlanWithBLOBs);
|
||||
} else if (prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束
|
||||
testPlanDTO.setStatus(TestPlanStatus.Finished.name());
|
||||
editTestPlan(testPlanDTO);
|
||||
testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name());
|
||||
editTestPlan(testPlanWithBLOBs);
|
||||
} else if (prepareNum != 0) { // 进行中
|
||||
testPlanDTO.setStatus(TestPlanStatus.Underway.name());
|
||||
editTestPlan(testPlanDTO);
|
||||
testPlanWithBLOBs.setStatus(TestPlanStatus.Underway.name());
|
||||
editTestPlan(testPlanWithBLOBs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -606,30 +614,28 @@ public class TestPlanService {
|
|||
testPlan.setStatus(status);
|
||||
testPlanMapper.updateByPrimaryKeySelective(testPlan);
|
||||
TestPlan testPlans = getTestPlan(planId);
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add(testPlans.getCreator());
|
||||
AddTestPlanRequest _testPlans = new AddTestPlanRequest();
|
||||
if (StringUtils.equals(TestPlanStatus.Completed.name(), testPlans.getStatus())) {
|
||||
|
||||
sendCompletedNotice(testPlans);
|
||||
}
|
||||
|
||||
private void sendCompletedNotice(TestPlan testPlan) {
|
||||
if (StringUtils.equals(TestPlanStatus.Completed.name(), testPlan.getStatus())) {
|
||||
try {
|
||||
BeanUtils.copyBean(_testPlans, testPlans);
|
||||
String context = getTestPlanContext(_testPlans, NoticeConstants.Event.UPDATE);
|
||||
User user = userMapper.selectByPrimaryKey(_testPlans.getCreator());
|
||||
Map<String, Object> paramMap = getTestPlanParamMap(_testPlans);
|
||||
paramMap.put("operator", user.getName());
|
||||
String context = getTestPlanContext(testPlan, NoticeConstants.Event.UPDATE);
|
||||
Map<String, Object> paramMap = getTestPlanParamMap(testPlan);
|
||||
NoticeModel noticeModel = NoticeModel.builder()
|
||||
.operator(SessionUtils.getUserId())
|
||||
.context(context)
|
||||
.relatedUsers(userIds)
|
||||
.subject(Translator.get("test_plan_notification"))
|
||||
.mailTemplate("track/TestPlanEnd")
|
||||
.paramMap(paramMap)
|
||||
.event(NoticeConstants.Event.UPDATE)
|
||||
.event(NoticeConstants.Event.COMPLETE)
|
||||
.build();
|
||||
noticeSendService.send(NoticeConstants.TaskType.TEST_PLAN_TASK, noticeModel);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -691,7 +697,7 @@ public class TestPlanService {
|
|||
return projectName;
|
||||
}
|
||||
|
||||
private String getTestPlanContext(AddTestPlanRequest testPlan, String type) {
|
||||
private String getTestPlanContext(TestPlan testPlan, String type) {
|
||||
User user = userMapper.selectByPrimaryKey(testPlan.getCreator());
|
||||
Long startTime = testPlan.getPlannedStartTime();
|
||||
Long endTime = testPlan.getPlannedEndTime();
|
||||
|
@ -984,7 +990,7 @@ public class TestPlanService {
|
|||
|
||||
String planReportId = testPlanReport.getId();
|
||||
|
||||
testPlanLog.info("ReportId[" + planReportId + "] created. TestPlanID:[" + testPlanID + "]. "+"API Run Config:【"+apiRunConfig+"】");
|
||||
testPlanLog.info("ReportId[" + planReportId + "] created. TestPlanID:[" + testPlanID + "]. " + "API Run Config:【" + apiRunConfig + "】");
|
||||
|
||||
//不同任务的执行ID
|
||||
Map<String, String> executePerformanceIdMap = new HashMap<>();
|
||||
|
@ -992,7 +998,7 @@ public class TestPlanService {
|
|||
Map<String, String> executeScenarioCaseIdMap = new HashMap<>();
|
||||
|
||||
//执行性能测试任务
|
||||
Map<String,String> performaneReportIDMap = new LinkedHashMap<>();
|
||||
Map<String, String> performaneReportIDMap = new LinkedHashMap<>();
|
||||
|
||||
for (Map.Entry<String, String> entry : performanceIdMap.entrySet()) {
|
||||
String id = entry.getKey();
|
||||
|
@ -1011,7 +1017,7 @@ public class TestPlanService {
|
|||
try {
|
||||
reportId = performanceTestService.run(performanceRequest);
|
||||
if (reportId != null) {
|
||||
performaneReportIDMap.put(reportId,caseID);
|
||||
performaneReportIDMap.put(reportId, caseID);
|
||||
TestPlanLoadCase testPlanLoadCase = new TestPlanLoadCase();
|
||||
testPlanLoadCase.setId(performanceRequest.getTestPlanLoadId());
|
||||
testPlanLoadCase.setLoadReportId(reportId);
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<table tableName="test_plan"/>
|
||||
<table tableName="test_case_test"/>-->
|
||||
<!-- <table tableName="api_test_environment"></table>-->
|
||||
<table tableName="api_test_case"/>
|
||||
<table tableName="notification"/>
|
||||
<!-- <table tableName="custom_field"></table>-->
|
||||
<!-- <table tableName="test_case"></table>-->
|
||||
<!-- <table tableName="test_case"></table>-->
|
||||
|
|
|
@ -12,6 +12,9 @@ export function getOperation(operation) {
|
|||
case "COMMENT":
|
||||
operation = "评论了";
|
||||
break;
|
||||
case "COMPLETE":
|
||||
operation = "完成了";
|
||||
break;
|
||||
case "CLOSE_SCHEDULE":
|
||||
operation = "关闭了定时任务";
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue