diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java index 9dfe757549..6bbe3a2a00 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ExecuteReportDTO.java @@ -48,6 +48,9 @@ public class ExecuteReportDTO implements Serializable { @Schema(description = "测试计划Num") private String testPlanNum; + @Schema(description = "结果是否被删除") + private Boolean resultDeleted = true; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java index 063e198105..ac65f74b7d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiTestCaseService.java @@ -46,6 +46,8 @@ import io.metersphere.system.utils.ServiceUtils; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -111,6 +113,8 @@ public class ApiTestCaseService extends MoveNodeService { private ExtApiScenarioMapper extApiScenarioMapper; private static final String CASE_TABLE = "api_test_case"; + @Resource + private ApiReportRelateTaskMapper apiReportRelateTaskMapper; private void checkProjectExist(String projectId) { Project project = projectMapper.selectByPrimaryKey(projectId); @@ -578,10 +582,11 @@ public class ApiTestCaseService extends MoveNodeService { private List handleList(List historyList) { List executeReportDTOList = new ArrayList<>(); - if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(historyList)) { + if (CollectionUtils.isNotEmpty(historyList)) { List userIds = historyList.stream().map(ExecHistoryDTO::getCreateUser).toList(); Map userNameMap = userLoginService.getUserNameMap(userIds); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + Map reportMap = getReportMap(historyList); historyList.forEach(item -> { ExecuteReportDTO reportDTO = new ExecuteReportDTO(); BeanUtils.copyBean(reportDTO, item); @@ -591,12 +596,32 @@ public class ApiTestCaseService extends MoveNodeService { if (StringUtils.isNotBlank(item.getTestPlanNum())) { reportDTO.setTestPlanNum(StringUtils.join(Translator.get("test_plan"), ": ", item.getTestPlanNum())); } + if (BooleanUtils.isTrue(item.getIntegrated()) && reportMap.containsKey(item.getTaskId())) { + reportDTO.setResultDeleted(false); + } + if (BooleanUtils.isFalse(item.getIntegrated()) && reportMap.containsKey(item.getItemId())) { + reportDTO.setResultDeleted(false); + } executeReportDTOList.add(reportDTO); }); } return executeReportDTOList; } + private Map getReportMap(List list) { + Map reportMap = new HashMap<>(); + List integratedTaskIds = list.stream().filter(item -> BooleanUtils.isTrue(item.getIntegrated())).map(ExecHistoryDTO::getTaskId).toList(); + List noIntegratedTaskItemIds = list.stream().filter(item -> BooleanUtils.isFalse(item.getIntegrated())).map(ExecHistoryDTO::getItemId).toList(); + List resourceIds = ListUtils.union(integratedTaskIds, noIntegratedTaskItemIds); + if (CollectionUtils.isNotEmpty(resourceIds)) { + ApiReportRelateTaskExample example = new ApiReportRelateTaskExample(); + example.createCriteria().andTaskResourceIdIn(resourceIds); + List reportRelateTasks = apiReportRelateTaskMapper.selectByExample(example); + reportMap = reportRelateTasks.stream().collect(Collectors.toMap(ApiReportRelateTask::getTaskResourceId, ApiReportRelateTask::getReportId)); + } + return reportMap; + } + public List operationHistoryList(OperationHistoryRequest request) { return operationHistoryService.listWidthTable(request, CASE_TABLE); } diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index 66849375a9..94d828f940 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -77,6 +77,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; +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.ResultMatcher; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -2704,6 +2706,7 @@ public class ApiScenarioControllerTests extends BaseTest { @Test @Order(10) + @Sql(scripts = {"/dml/init_exec_history_test.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) public void testExecuteList() throws Exception { ApiScenario first = apiScenarioMapper.selectByExample(new ApiScenarioExample()).getFirst(); List reports = new ArrayList<>(); @@ -2749,7 +2752,7 @@ public class ApiScenarioControllerTests extends BaseTest { } apiScenarioReportService.insertApiScenarioReport(reports, records); ExecutePageRequest request = new ExecutePageRequest(); - request.setId(first.getId()); + request.setId("1"); request.setPageSize(10); request.setCurrent(1); MvcResult mvcResult = responsePost(BASE_PATH + "execute/page", request); diff --git a/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql b/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql new file mode 100644 index 0000000000..0a1c647a6c --- /dev/null +++ b/backend/services/api-test/src/test/resources/dml/init_exec_history_test.sql @@ -0,0 +1,11 @@ +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 + ('my_1', 1111, '测试1', 'SUCCESS', 10, 'SUCCESS', 'API_SCENARIO', 'API', '100001100001', '100001', 1727676089639, 'wx', 1727676089639, 1727676089639, 1), + ('my_2', 2222, '测试2', 'SUCCESS', 11, 'SUCCESS', 'API_SCENARIO', 'API', '12345567', '11234', 1727676089639, 'wx', 1727676089639, 1727676089639, 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`, `case_id`) +VALUES + ('my_1', 'my_1', '1', '1', '1', 'SUCCESS', 'SUCCESS', '1', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '1'), + ('my_2', 'my_2', '1', '2', '3', 'SUCCESS', 'SUCCESS', '2', '1', 'API_SCENARIO', '100001100001', '100001', '1', NULL, NULL, 'admin', '2'); +