diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index bb9e5ad15b..0fb69691d7 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1026,13 +1026,17 @@ public class ApiAutomationService { planEnvMap = JSON.parseObject(environment, Map.class); } } + String projectId = testPlanScenarioCaseService.getProjectIdById(testPlanScenarioId); + if(StringUtils.isEmpty(projectId)){ + projectId = item.getProjectId(); + } if (request.isTestPlanScheduleJob()) { String savedScenarioId = testPlanScenarioId + ":" + request.getTestPlanReportId(); report = createScenarioReport(reportId, savedScenarioId, item.getName(), request.getTriggerMode(), - request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(),item.getId()); + request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(),item.getId()); } else { report = createScenarioReport(reportId, testPlanScenarioId, item.getName(), request.getTriggerMode(), - request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(),item.getId()); + request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(),item.getId()); } } else { report = createScenarioReport(reportId, ExecuteType.Marge.name().equals(request.getExecuteType()) ? serialReportId : item.getId(), item.getName(), request.getTriggerMode(), @@ -1251,13 +1255,19 @@ public class ApiAutomationService { scenario.setEnvironmentMap(JSON.parseObject(environment, Map.class)); } } + + String projectId = testPlanScenarioCaseService.getProjectIdById(testPlanScenarioId); + if(StringUtils.isEmpty(projectId)){ + projectId = item.getProjectId(); + } + if (request.isTestPlanScheduleJob()) { String savedScenarioId = testPlanScenarioId + ":" + request.getTestPlanReportId(); report = createScenarioReport(group.getName(), savedScenarioId, item.getName(), request.getTriggerMode(), - request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(),item.getId()); + request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(),item.getId()); } else { report = createScenarioReport(group.getName(), testPlanScenarioId, item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), - request.getExecuteType(), item.getProjectId(), request.getReportUserID(), request.getConfig(),item.getId()); + request.getExecuteType(), projectId, request.getReportUserID(), request.getConfig(),item.getId()); } } else { report = createScenarioReport(group.getName(), item.getId(), item.getName(), request.getTriggerMode() == null ? ReportTriggerMode.MANUAL.name() : request.getTriggerMode(), diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java index 9b5c973742..83a75c6f4b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.java @@ -34,4 +34,6 @@ public interface ExtTestPlanScenarioCaseMapper { List getFailureListByIds(@Param("ids") Collection ids, @Param("planId") String planId, @Param("status") String status); List getUnderwaySteps(@Param("ids") List underwayIds); + + String getProjectIdById(String testPlanScenarioId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml index d8996827d0..b7271c9211 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml @@ -247,4 +247,10 @@ + + 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 2034105527..7995a92d43 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -685,9 +685,9 @@ public class TestPlanReportService { status = TestPlanReportStatus.SUCCESS.name(); try { if (CollectionUtils.isNotEmpty(reportDTO.getFunctionFailureCases()) - && CollectionUtils.isNotEmpty(reportDTO.getApiFailureCases()) - && CollectionUtils.isNotEmpty(reportDTO.getScenarioFailureCases()) - && CollectionUtils.isNotEmpty(reportDTO.getLoadFailureCases())) { + || CollectionUtils.isNotEmpty(reportDTO.getApiFailureCases()) + || CollectionUtils.isNotEmpty(reportDTO.getScenarioFailureCases()) + || CollectionUtils.isNotEmpty(reportDTO.getLoadFailureCases())) { status = TestPlanReportStatus.FAILED.name(); return status; } @@ -751,7 +751,7 @@ public class TestPlanReportService { //更新TestPlan状态为完成 TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId()); if (testPlan != null) { - testPlan.setStatus(TestPlanStatus.Completed.name()); +// testPlan.setStatus(TestPlanStatus.Completed.name()); testPlanMapper.updateByPrimaryKeySelective(testPlan); } if (StringUtils.equalsAny(report.getTriggerMode(), ReportTriggerMode.API.name(), ReportTriggerMode.SCHEDULE.name())) { @@ -813,7 +813,7 @@ public class TestPlanReportService { } NoticeModel noticeModel = NoticeModel.builder() - .operator(SessionUtils.getUserId()) + .operator("MeterSphere") .successContext(successContext) .successMailTemplate(successfulMailTemplate) .failedContext(failedContext) diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java index 283b808112..1b02876765 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -468,4 +468,8 @@ public class TestPlanScenarioCaseService { } return null; } + + public String getProjectIdById(String testPlanScenarioId) { + return extTestPlanScenarioCaseMapper.getProjectIdById(testPlanScenarioId); + } } 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 e4673922a0..8286425c79 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -990,6 +990,7 @@ public class TestPlanService { @Transactional(propagation = Propagation.NOT_SUPPORTED) public String run(String testPlanID, String projectID, String userId, String triggerMode, String apiRunConfig) { + triggerMode = ReportTriggerMode.SCHEDULE.name(); //创建测试报告,然后返回的ID重新赋值为resourceID,作为后续的参数 TestPlanScheduleReportInfoDTO reportInfoDTO = testPlanReportService.genTestPlanReportBySchedule(projectID, testPlanID, userId, triggerMode);