diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index f70591799a..6699105e70 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -137,6 +137,8 @@ public class ApiDefinitionService { private ProjectApplicationService projectApplicationService; @Resource private EsbApiParamsMapper esbApiParamsMapper; + @Resource + private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; private ThreadLocal currentApiOrder = new ThreadLocal<>(); private ThreadLocal currentApiCaseOrder = new ThreadLocal<>(); @@ -1110,7 +1112,9 @@ public class ApiDefinitionService { CollectionUtils.isNotEmpty(request.getTestElement().getHashTree()) && CollectionUtils.isNotEmpty(request.getTestElement().getHashTree().get(0).getHashTree()) ? request.getTestElement().getHashTree().get(0).getHashTree().get(0).getName() : request.getId(); + String reportName = this.getReportNameByTestId(testId); ApiDefinitionExecResultWithBLOBs result = ApiDefinitionExecResultUtil.add(testId, APITestStatus.Running.name(), request.getId(), Objects.requireNonNull(SessionUtils.getUser()).getId()); + result.setName(reportName); result.setProjectId(request.getProjectId()); result.setTriggerMode(TriggerMode.MANUAL.name()); apiDefinitionExecResultMapper.insert(result); @@ -1125,6 +1129,20 @@ public class ApiDefinitionService { return apiExecuteService.debug(request, bodyFiles); } + private String getReportNameByTestId(String testId) { + String testName = extApiDefinitionMapper.selectNameById(testId); + if(StringUtils.isEmpty(testName)){ + testName = extApiTestCaseMapper.selectNameById(testId); + if(StringUtils.isEmpty(testName)){ + String resourceID = extTestPlanApiCaseMapper.getApiTestCaseIdById(testId); + if(StringUtils.isNotEmpty(resourceID)){ + testName = extApiTestCaseMapper.selectNameById(resourceID); + } + } + } + return testName; + } + /** * 获取存储执行结果报告 * diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java index 3edbf6a884..b088e3b601 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java @@ -88,4 +88,5 @@ public interface ExtApiDefinitionMapper { List selectRefIdsForVersionChange(@Param("versionId") String versionId, @Param("projectId") String projectId); + String selectNameById(String testId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index b98c476558..17a4fe94eb 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -938,4 +938,8 @@ WHERE version_id = #{versionId} AND project_id = #{projectId} ) AND project_id = #{projectId} + + diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java index 69946285b5..065ab080b0 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.java @@ -28,6 +28,7 @@ public interface ExtTestPlanApiCaseMapper { ApiTestCaseWithBLOBs getApiTestCaseById(String testPlanApiCaseId); + String getApiTestCaseIdById(String testPlanApiCaseId); List selectLegalDataByTestPlanId(String planId); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml index 0e93fad61c..8bee177fa5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanApiCaseMapper.xml @@ -18,7 +18,9 @@ INNER JOIN test_plan_api_case tpac ON t.id = tpac.api_case_id WHERE tpac.id = #{0} - +