diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java index 9ead72359b..8845e88fa3 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java @@ -136,7 +136,7 @@ public class ApiReportController { @GetMapping("/task-report/{id}") - @Operation(summary = "系统-任务中心-场景用例执行任务详情-查看") + @Operation(summary = "系统-任务中心-接口用例执行任务详情-查看") @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ) public List viewCaseItemReport(@PathVariable String id) { return apiReportService.viewCaseTaskItemReport(id); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java index f59232dd2b..44cfc55321 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java @@ -3,6 +3,7 @@ package io.metersphere.api.controller.scenario; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.definition.ApiReportBatchRequest; +import io.metersphere.api.dto.definition.ApiReportDetailDTO; import io.metersphere.api.dto.definition.ApiReportPageRequest; import io.metersphere.api.dto.report.ApiScenarioReportListDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDTO; @@ -133,4 +134,20 @@ public class ApiScenarioReportController { public void batchExportLog(@Validated @RequestBody ApiReportBatchRequest request) { apiScenarioReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId()); } + + + @GetMapping("/task-step/{id}") + @Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(任务步骤)") + @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ) + public ApiScenarioReportDTO viewScenarioItemReport(@PathVariable String id) { + return apiScenarioReportService.viewScenarioItemReport(id); + } + + @GetMapping("/task-report/{reportId}/{stepId}") + @Operation(summary = "系统-任务中心-场景用例执行任务详情-查看(步骤结果)") + @RequiresPermissions(PermissionConstants.SYSTEM_CASE_TASK_CENTER_READ) + public List getScenarioReportDetail(@PathVariable String reportId, + @PathVariable String stepId) { + return apiScenarioReportService.getDetail(reportId, stepId); + } } 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 00cbb75e75..fe192def58 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 @@ -3,6 +3,7 @@ package io.metersphere.api.service.scenario; import io.metersphere.api.constants.ApiScenarioStepType; import io.metersphere.api.domain.*; import io.metersphere.api.dto.definition.ApiReportBatchRequest; +import io.metersphere.api.dto.definition.ApiReportDetailDTO; import io.metersphere.api.dto.definition.ApiReportPageRequest; import io.metersphere.api.dto.report.ApiScenarioReportListDTO; import io.metersphere.api.dto.scenario.ApiScenarioReportDTO; @@ -18,8 +19,10 @@ import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.domain.ExecTask; import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.User; +import io.metersphere.system.mapper.ExtExecTaskMapper; import io.metersphere.system.mapper.TestResourcePoolMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.notice.constants.NoticeConstants; @@ -73,6 +76,8 @@ public class ApiScenarioReportService { private static final String SPLITTER = "_"; private static final int MAX = 50000; private static final int BATCH_SIZE = 1000; + @Resource + private ExtExecTaskMapper extExecTaskMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiScenarioReport(ApiScenarioReport report, ApiReportRelateTask taskRelation) { @@ -440,4 +445,31 @@ public class ApiScenarioReportService { apiScenarioReportLogService.exportLog(reports, userId, projectId, "/api/report/scenario/batch-export"); } } + + public ApiScenarioReportDTO viewScenarioItemReport(String id) { + List taskList = extExecTaskMapper.selectTypeByItemId(id); + + if (CollectionUtils.isNotEmpty(taskList)) { + if (taskList.getFirst().getIntegrated()) { + //场景集合报告 TODO + return new ApiScenarioReportDTO(); + } else { + //场景非集合报告 + return scenarioReportDetail(id); + } + } + return new ApiScenarioReportDTO(); + } + + private ApiScenarioReportDTO scenarioReportDetail(String id) { + ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); + example.createCriteria().andTaskResourceIdEqualTo(id); + List apiReportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(apiReportRelateTasks)) { + //报告id + String reportId = apiReportRelateTasks.getFirst().getReportId(); + return get(reportId); + } + return new ApiScenarioReportDTO(); + } } 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 d04727cfd2..f55b5419bb 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 @@ -42,6 +42,8 @@ import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -90,6 +92,8 @@ public class ApiScenarioReportControllerTests extends BaseTest { private static final String DETAIL = BASIC + "/get/detail/"; private static final String EXPORT_REPORT = BASIC + "/export/{0}"; private static final String BATCH_EXPORT_REPORT = BASIC + "/batch-export"; + private static final String TASK_STEP = BASIC + "/task-step/{0}"; + private static final String TASK_REPORT = BASIC + "/task-report/"; @Test @Order(1) @@ -551,4 +555,17 @@ public class ApiScenarioReportControllerTests extends BaseTest { request.setSelectAll(true); this.requestPost(BATCH_EXPORT_REPORT, request); } + + @Test + @Order(11) + @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"); + } + + @Test + @Order(12) + public void getTaskReport() throws Exception { + this.requestGet(TASK_REPORT + "test-scenario-report-id" + "/" + "test-scenario-report-step-id1"); + } } 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 new file mode 100644 index 0000000000..745ae6fac2 --- /dev/null +++ b/backend/services/api-test/src/test/resources/dml/init_scenario_task_item_test.sql @@ -0,0 +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'); + + + +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'); + + +INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) +VALUES + ('scenario_1', 'test-scenario-report-id'); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java index b91fc6c2a0..23b3a5ef67 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectTaskHubController.java @@ -183,7 +183,7 @@ public class ProjectTaskHubController { @PostMapping("/schedule/update-cron") @Operation(summary = "项目-任务中心-后台任务更新cron表达式") @RequiresPermissions(PermissionConstants.PROJECT_SCHEDULE_TASK_CENTER_READ_UPDATE) - public void updateValue(@PathVariable ScheduleRequest request) { + public void updateValue(@Validated @RequestBody ScheduleRequest request) { baseTaskHubService.updateCron(request); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java index 173052e396..09f19dc5e0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationTaskHubController.java @@ -199,7 +199,7 @@ public class OrganizationTaskHubController { @PostMapping("/schedule/update-cron") @Operation(summary = "组织-任务中心-后台任务更新cron表达式") @RequiresPermissions(PermissionConstants.ORGANIZATION_SCHEDULE_TASK_CENTER_READ_UPDATE) - public void updateValue(@PathVariable ScheduleRequest request) { + public void updateValue(@Validated @RequestBody ScheduleRequest request) { baseTaskHubService.updateCron(request); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java index 1bfbab3467..c2ed338c78 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemTaskHubController.java @@ -205,7 +205,7 @@ public class SystemTaskHubController { @PostMapping("/schedule/update-cron") @Operation(summary = "系统-任务中心-后台任务更新cron表达式") @RequiresPermissions(PermissionConstants.SYSTEM_SCHEDULE_TASK_CENTER_READ_UPDATE) - public void updateValue(@PathVariable ScheduleRequest request) { + public void updateValue(@Validated @RequestBody ScheduleRequest request) { baseTaskHubService.updateCron(request); }