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 ff217e1114..9ead72359b 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 @@ -133,4 +133,12 @@ public class ApiReportController { public void batchExportLog(@Validated @RequestBody ApiReportBatchRequest request) { apiReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId()); } + + + @GetMapping("/task-report/{id}") + @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/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index 8f971da6a9..b650ac01a4 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 @@ -15,8 +15,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; @@ -67,6 +69,10 @@ public class ApiReportService { private ApiReportNoticeService apiReportNoticeService; @Resource private ApiReportRelateTaskMapper apiReportRelateTaskMapper; + @Resource + private ApiReportStepMapper apiReportStepMapper; + @Resource + private ExtExecTaskMapper extExecTaskMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) public void insertApiReport(ApiReport report) { @@ -312,4 +318,45 @@ public class ApiReportService { apiReportLogService.exportLog(reports, userId, projectId, "/api/report/case/batch-export"); } } + + public List viewCaseTaskItemReport(String id) { + List taskList = extExecTaskMapper.selectTypeByItemId(id); + + if (CollectionUtils.isNotEmpty(taskList)) { + if (taskList.getFirst().getIntegrated()) { + //集合报告 TODO + return new ArrayList<>(); + } else { + //非集合报告 + return reportDetail(id); + } + } + return new ArrayList<>(); + } + + private List reportDetail(String id) { + List list = new ArrayList<>(); + ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); + example.createCriteria().andTaskResourceIdEqualTo(id); + List apiReportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(apiReportRelateTasks)) { + //报告id + String reportId = apiReportRelateTasks.getFirst().getReportId(); + //获取步骤id + String stepId = getStepId(reportId); + + list = getDetail(reportId, stepId); + } + return list; + } + + private String getStepId(String reportId) { + ApiReportStepExample example = new ApiReportStepExample(); + example.createCriteria().andReportIdEqualTo(reportId); + List apiReportSteps = apiReportStepMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(apiReportSteps)) { + return apiReportSteps.getFirst().getStepId(); + } + return null; + } } 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 3ef762bcea..169e7faf52 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,6 +27,7 @@ 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; @@ -37,6 +38,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; @@ -83,6 +86,7 @@ public class ApiReportControllerTests 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_REPORT = BASIC + "/task-report/{0}"; @Test @@ -506,4 +510,11 @@ public class ApiReportControllerTests extends BaseTest { request.setSelectAll(true); this.requestPost(BATCH_EXPORT_REPORT, request); } + + @Test + @Order(7) + @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"); + } } 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 new file mode 100644 index 0000000000..1d62b80287 --- /dev/null +++ b/backend/services/api-test/src/test/resources/dml/init_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 + ('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'); + + + +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'); + + +INSERT INTO `api_report_relate_task`(`task_resource_id`, `report_id`) VALUES ('1', 'test-report-id'); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java index 0d3f28c7e5..ec655a0d98 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectTaskHubControllerTests.java @@ -114,7 +114,7 @@ public class ProjectTaskHubControllerTests extends BaseTest { @Test - @Order(4) + @Order(5) public void getProStatistics() throws Exception { List ids = List.of("pro_1", "pro_2"); MvcResult mvcResult = this.requestPostWithOkAndReturn(PROJECT_STATISTICS, ids); @@ -219,7 +219,7 @@ public class ProjectTaskHubControllerTests extends BaseTest { @Test - @Order(4) + @Order(5) public void projectTaskItemBatchStop() throws Exception { mockPost("/api/task/item/stop", ""); TaskHubItemBatchRequest request = new TaskHubItemBatchRequest(); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java index ff4227e1bf..a0f8b90b4c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.java @@ -1,5 +1,6 @@ package io.metersphere.system.mapper; +import io.metersphere.system.domain.ExecTask; import io.metersphere.system.dto.sdk.BasePageRequest; import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.taskhub.TaskHubDTO; @@ -26,4 +27,6 @@ public interface ExtExecTaskMapper { * @return 任务ID列表 */ List getTaskIdsByTime(@Param("timeMills") long timeMills, @Param("projectId") String projectId); + + List selectTypeByItemId(@Param("itemId") String itemId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml index 3d6105eaf4..8b1d26e034 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtExecTaskMapper.xml @@ -118,4 +118,9 @@ + + + \ No newline at end of file diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java index b0bdf6b216..38f3832c27 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/BaseTaskHubControllerTests.java @@ -191,7 +191,7 @@ public class BaseTaskHubControllerTests extends BaseTest { * 系统任务项停止 */ @Test - @Order(4) + @Order(5) public void systemTaskItemStop() throws Exception { mockPost("/api/task/item/stop", ""); this.requestGet(SYSTEM_TASK_ITEM_STOP + "1"); @@ -200,7 +200,7 @@ public class BaseTaskHubControllerTests extends BaseTest { } @Test - @Order(4) + @Order(5) public void systemGetTaskItemOrder() throws Exception { MvcResult mvcResult = this.requestPostWithOkAndReturn(SYSTEM_TASK_ITEM_ORDER, List.of("1")); HashMap resultData = getResultData(mvcResult, HashMap.class); @@ -392,7 +392,7 @@ public class BaseTaskHubControllerTests extends BaseTest { } @Test - @Order(4) + @Order(5) public void getOrgStatistics() throws Exception { List ids = List.of("1", "2"); MvcResult mvcResult = this.requestPostWithOkAndReturn(ORG_STATISTICS, ids);