diff --git a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java index af9d28d7d0..b9a5404915 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java @@ -217,7 +217,7 @@ public class TestResultService { String environment = StringUtils.EMPTY; //执行人 - String userName = StringUtils.EMPTY; + String userName = apiAutomationService.getUser(scenarioReport.getUserId()); //负责人 String principal = StringUtils.EMPTY; @@ -227,14 +227,21 @@ public class TestResultService { ApiScenarioWithBLOBs apiScenario = apiScenarioMapper.selectByPrimaryKey(testPlanApiScenario.getApiScenarioId()); if (apiScenario != null) { scenarioExecutionInfoService.insertScenarioInfo(apiScenario, scenarioReport, dto); + environment = apiScenarioReportService.getEnvironment(apiScenario); + principal = apiAutomationService.getUser(apiScenario.getPrincipal()); } } } else { ApiScenarioWithBLOBs apiScenario = apiScenarioMapper.selectByPrimaryKey(scenarioReport.getScenarioId()); - scenarioExecutionInfoService.insertScenarioInfo(apiScenario, scenarioReport, dto); - environment = apiScenarioReportService.getEnvironment(apiScenario); - userName = apiAutomationService.getUser(apiScenario.getUserId()); - principal = apiAutomationService.getUser(apiScenario.getPrincipal()); + //集合报告查不出场景。场景的执行次数统计是在margeReport函数中进行的。所以这里要进行一个判断。 + if (apiScenario != null) { + scenarioExecutionInfoService.insertScenarioInfo(apiScenario, scenarioReport, dto); + environment = apiScenarioReportService.getEnvironment(apiScenario); + principal = apiAutomationService.getUser(apiScenario.getPrincipal()); + } else { + //负责人取当前负责人 + principal = apiAutomationService.getUser(scenarioReport.getUserId()); + } } //报告内容 diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioExecutionInfoService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioExecutionInfoService.java index 8a41a2f416..48a7bde299 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioExecutionInfoService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioExecutionInfoService.java @@ -9,14 +9,14 @@ import io.metersphere.commons.enums.ExecutionExecuteTypeEnum; import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; import io.metersphere.dto.ResultDTO; +import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import jakarta.annotation.Resource; - import java.util.List; import java.util.UUID; @@ -48,6 +48,9 @@ public class ApiScenarioExecutionInfoService { @Lazy public void insertScenarioInfo(ApiScenarioWithBLOBs apiScenario, ApiScenarioReport scenarioReport, ResultDTO dto) { + if (ObjectUtils.anyNull(apiScenario, scenarioReport, dto)) { + return; + } if (StringUtils.equalsAnyIgnoreCase(dto.getRunMode(), ApiRunMode.SCENARIO_PLAN.name(), ApiRunMode.SCHEDULE_SCENARIO_PLAN.name(), ApiRunMode.JENKINS_SCENARIO_PLAN.name())) { this.insertExecutionInfo(dto.getTestId(), scenarioReport.getStatus(), scenarioReport.getTriggerMode(), scenarioReport.getProjectId() == null ? apiScenario.getProjectId() : scenarioReport.getProjectId(), ExecutionExecuteTypeEnum.TEST_PLAN.name(), apiScenario.getVersionId()); } else {