diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java index db1adf8ac2..4b1df6a573 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.java @@ -35,4 +35,6 @@ public interface ExtTestPlanMapper { List findIdByPerformanceReportId(String reportId); List listRecent(@Param("userId") String userId, @Param("projectId") String currentProjectId); + + int updateActualEndTimeIsNullById(String testPlanID); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml index bc2bff3b90..2c567160ec 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanMapper.xml @@ -279,5 +279,9 @@ order by test_plan.update_time desc - + + update test_plan + set actual_end_time = null + where id = #{0} + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 62b716396d..d9b5754079 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -805,8 +805,9 @@ public class TestPlanReportService { //更新TestPlan状态为完成 TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId()); if (testPlan != null) { + testPlanService.checkStatus(testPlan); // testPlan.setStatus(TestPlanStatus.Completed.name()); - testPlanMapper.updateByPrimaryKeySelective(testPlan); +// testPlanMapper.updateByPrimaryKeySelective(testPlan); } if (testPlan != null && StringUtils.equalsAny(report.getTriggerMode(), ReportTriggerMode.MANUAL.name(), diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 2a05480071..d02709bced 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -509,6 +509,43 @@ public class TestPlanService { } } + public void checkStatus(TestPlanWithBLOBs testPlanWithBLOBs) { // 检查执行结果,自动更新计划状态 + List statusList = new ArrayList<>(); + statusList.addAll(extTestPlanTestCaseMapper.getExecResultByPlanId(testPlanWithBLOBs.getId())); + statusList.addAll(testPlanApiCaseService.getExecResultByPlanId(testPlanWithBLOBs.getId())); + statusList.addAll(testPlanScenarioCaseService.getExecResultByPlanId(testPlanWithBLOBs.getId())); + statusList.addAll(testPlanLoadCaseService.getStatus(testPlanWithBLOBs.getId())); + if (statusList.size() == 0) { // 原先status不是prepare, 但删除所有关联用例的情况 + testPlanWithBLOBs.setStatus(TestPlanStatus.Prepare.name()); + editTestPlan(testPlanWithBLOBs); + return; + } + int passNum = 0, prepareNum = 0, failNum = 0; + for (String res : statusList) { + if (StringUtils.equals(res, TestPlanTestCaseStatus.Pass.name()) + || StringUtils.equals(res, "success") + || StringUtils.equals(res, ScenarioStatus.Success.name())) { + passNum++; + } else if (res == null || StringUtils.equals(TestPlanStatus.Prepare.name(), res)) { + prepareNum++; + } else { + failNum++; + } + } + if (passNum == statusList.size()) { // 全部通过 + testPlanWithBLOBs.setStatus(TestPlanStatus.Completed.name()); + this.editTestPlan(testPlanWithBLOBs); + // 发送成功通知 +// sendCompletedNotice(testPlanWithBLOBs); + } else if (prepareNum == 0 && passNum + failNum == statusList.size()) { // 已结束 + testPlanWithBLOBs.setStatus(TestPlanStatus.Finished.name()); + editTestPlan(testPlanWithBLOBs); + } else if (prepareNum != 0) { // 进行中 + testPlanWithBLOBs.setStatus(TestPlanStatus.Underway.name()); + editTestPlan(testPlanWithBLOBs); + } + } + public List listTestPlanByProject(QueryTestPlanRequest request) { List testPlans = extTestPlanMapper.list(request); return testPlans; @@ -1086,6 +1123,7 @@ public class TestPlanService { @Transactional(propagation = Propagation.NOT_SUPPORTED) public String run(String testPlanID, String projectID, String userId, String triggerMode, String apiRunConfig) { + extTestPlanMapper.updateActualEndTimeIsNullById(testPlanID); //创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数 TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, testPlanID, userId, triggerMode);