diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index 0d9cfdc9c5..ea8c9d47e7 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java @@ -344,6 +344,9 @@ public class ApiReportService { ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); example.createCriteria().andTaskResourceIdEqualTo(taskId); List apiReportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); + if (CollectionUtils.isEmpty(apiReportRelateTasks)) { + return new ArrayList<>(); + } String reportId = apiReportRelateTasks.getFirst().getReportId(); return getDetail(reportId, taskItem.getResourceId()); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java index a609450145..d98b817bad 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java @@ -467,9 +467,11 @@ public class ApiScenarioReportService { private ApiScenarioReportDTO getScenarioReportDetail(String taskId, String taskItemId) { ExecTaskItem taskItem = execTaskItemMapper.selectByPrimaryKey(taskItemId); ApiScenarioReportDTO apiScenarioReportDTO = scenarioReportDetail(taskId); - List list = apiScenarioReportDTO.getChildren().stream() - .filter(step -> StringUtils.equals(step.getStepId(), taskItem.getResourceId())).toList(); - apiScenarioReportDTO.setChildren(list); + if (CollectionUtils.isNotEmpty(apiScenarioReportDTO.getChildren())) { + List list = apiScenarioReportDTO.getChildren().stream() + .filter(step -> StringUtils.equals(step.getStepId(), taskItem.getResourceId())).toList(); + apiScenarioReportDTO.setChildren(list); + } return apiScenarioReportDTO; } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java index 169e7faf52..eac6b6d670 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java @@ -27,7 +27,6 @@ import io.metersphere.sdk.mapper.ShareInfoMapper; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; -import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.TestResourcePoolExample; import io.metersphere.system.mapper.TestResourcePoolMapper; @@ -516,5 +515,7 @@ public class ApiReportControllerTests extends BaseTest { @Sql(scripts = {"/dml/init_task_item_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) public void getTaskReport() throws Exception { this.requestGet(TASK_REPORT, "1"); + this.requestGet(TASK_REPORT, "3"); + this.requestGet(TASK_REPORT, "4"); } } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java index f55b5419bb..e9e13383f0 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioReportControllerTests.java @@ -561,6 +561,7 @@ public class ApiScenarioReportControllerTests extends BaseTest { @Sql(scripts = {"/dml/init_scenario_task_item_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) public void getTaskStep() throws Exception { this.requestGet(TASK_STEP, "scenario_1"); + this.requestGet(TASK_STEP, "scenario_3"); } @Test diff --git a/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql b/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql index 745ae6fac2..e56ad157a5 100644 --- a/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql +++ b/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql @@ -1,14 +1,16 @@ INSERT INTO `exec_task`(`id`, `num`, `task_name`, `status`, `case_count`, `result`, `task_type`, `trigger_mode`, `project_id`, `organization_id`, `create_time`, `create_user`, `start_time`, `end_time`, `integrated`) VALUES ('scenario_1', 11, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), - ('scenario_2', 22, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'); + ('scenario_2', 22, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), + ('scenario_3', 22, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'1'); INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`) VALUES ('scenario_1', 'scenario_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), - ('scenario_2', 'scenario_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); + ('scenario_2', 'scenario_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), + ('scenario_3', 'scenario_3', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) diff --git a/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql b/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql index 1d62b80287..421efe864b 100644 --- a/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql +++ b/backend/services/api-test/src/test/resources/dml/init_task_item_test.sql @@ -3,14 +3,18 @@ VALUES ('1', 1, '测试任务1', 'SUCCESS', 10, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), ('2', 2, '测试任务2', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), ('3', 3, '测试任务3', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), - ('4', 4, '删除任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'); + ('4', 4, '删除任务4', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'0'), + ('5', 5, '删除任务5', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'1'), + ('6', 6, '删除任务6', 'SUCCESS', 11, 'SUCCESS', 'FUNCTIONAL', 'API', '100001100001', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, b'1'); INSERT INTO `exec_task_item`(`id`, `task_id`, `resource_id`, `resource_name`, `task_origin`, `status`, `result`, `resource_pool_id`, `resource_pool_node`, `resource_type`, `project_id`, `organization_id`, `thread_id`, `start_time`, `end_time`, `executor`) VALUES ('1', '1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), - ('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); + ('2', '2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), + ('3', '5', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'), + ('4', '6', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_CASE', '100001100001', '100001', '1', NULL, NULL, 'admin'); -INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) VALUES ('1', 'test-report-id'); +INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) VALUES ('1', 'test-report-id'), ('6', 'test-report-id'); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java index 48b019a620..9151a960c3 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java @@ -87,6 +87,9 @@ public class ProjectApplicationController { return configMap; } + /** + * ==========任务中心开始========== + */ @PostMapping("/update/task") @Operation(summary = "任务中心-配置") @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_TASK_UPDATE) @@ -102,6 +105,9 @@ public class ProjectApplicationController { List types = Arrays.stream(ProjectApplicationType.TASK.values()).map(ProjectApplicationType.TASK::name).collect(Collectors.toList()); return projectApplicationService.get(request, types); } + /** + * ==========任务中心结束========== + */ @GetMapping("/api/user/{projectId}") @Operation(summary = "接口测试-获取审核人") diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java index c0639519a9..7a99db3be1 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseTaskHubService.java @@ -193,8 +193,8 @@ public class BaseTaskHubService { * @param tasks 任务集合 */ private void setTaskReportId(List tasks) { - List reportTasks = tasks.stream().filter(task -> !StringUtils.equals(task.getTaskType(), ExecTaskType.API_SCENARIO_BATCH.name()) && - !StringUtils.equals(task.getTaskType(), ExecTaskType.API_CASE_BATCH.name())).toList(); + List reportTasks = tasks.stream().filter(task -> !StringUtils.equals(task.getTaskType(), ExecTaskType.API_SCENARIO_BATCH.name()) && !StringUtils.equals(task.getTaskType(), ExecTaskType.API_CASE_BATCH.name()) + && !StringUtils.equals(task.getTaskType(), ExecTaskType.TEST_PLAN_API_CASE_BATCH.name()) && !StringUtils.equals(task.getTaskType(), ExecTaskType.TEST_PLAN_API_SCENARIO_BATCH.name())).toList(); List integratedTaskIds = reportTasks.stream().filter(task -> StringUtils.equalsAny(task.getTaskType(), ExecTaskType.TEST_PLAN.name(), ExecTaskType.TEST_PLAN_GROUP.name()) || task.getIntegrated()).map(ExecTask::getId).toList(); List noIntegratedTasks = reportTasks.stream().map(ExecTask::getId).filter(id -> !integratedTaskIds.contains(id)).toList();