From f8e3eb16cea22cacfa135f24ede946a853c7e5dc Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 22 May 2024 12:11:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E7=94=A8=E4=BE=8B=E5=BD=BB=E5=BA=95=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E5=8F=8A=E8=81=94=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/ApiTestCaseService.java | 12 +++++++++-- .../service/scenario/ApiScenarioService.java | 21 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) 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 ff2650123b..997bae286c 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 @@ -1,6 +1,5 @@ package io.metersphere.api.service.definition; -import io.metersphere.sdk.constants.ApiFileResourceType; import io.metersphere.api.constants.ApiResourceType; import io.metersphere.api.domain.*; import io.metersphere.api.dto.*; @@ -13,6 +12,8 @@ import io.metersphere.api.service.ApiCommonService; import io.metersphere.api.service.ApiExecuteService; import io.metersphere.api.service.ApiFileResourceService; import io.metersphere.api.utils.ApiDataUtils; +import io.metersphere.functional.domain.FunctionalCaseTestExample; +import io.metersphere.functional.mapper.FunctionalCaseTestMapper; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.domain.FileAssociation; import io.metersphere.project.domain.FileMetadata; @@ -104,6 +105,8 @@ public class ApiTestCaseService extends MoveNodeService { private ApiTestCaseNoticeService apiTestCaseNoticeService; @Resource private ExtApiReportMapper extApiReportMapper; + @Resource + private FunctionalCaseTestMapper functionalCaseTestMapper; private static final String CASE_TABLE = "api_test_case"; private static final int MAX_TAG_SIZE = 10; @@ -380,7 +383,7 @@ public class ApiTestCaseService extends MoveNodeService { if (CollectionUtils.isEmpty(ids)) { return; } - SubListUtils.dealForSubList(ids, 2000, subList -> deleteResourceByIds(subList, request.getProjectId(), userId)); + SubListUtils.dealForSubList(ids, 200, subList -> deleteResourceByIds(subList, request.getProjectId(), userId)); } public void deleteResourceByIds(List ids, String projectId, String userId) { @@ -400,6 +403,10 @@ public class ApiTestCaseService extends MoveNodeService { //记录删除日志 apiTestCaseLogService.deleteBatchLog(caseLists, userId, projectId); //TODO 需要删除测试计划与用例的中间表 功能用例的关联表等 + FunctionalCaseTestExample functionalCaseTestExample = new FunctionalCaseTestExample(); + functionalCaseTestExample.createCriteria().andSourceIdIn(ids).andSourceTypeEqualTo("API"); + functionalCaseTestMapper.deleteByExample(functionalCaseTestExample); + //TODO 删除附件关系 不需要删除报告 //extFileAssociationService.deleteByResourceIds(ids); } @@ -836,6 +843,7 @@ public class ApiTestCaseService extends MoveNodeService { /** * 校验TAG长度 + * * @param tags 标签集合 */ public void checkTagLength(List tags) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index de11b8c62e..cacf1229cf 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -27,6 +27,8 @@ import io.metersphere.api.service.definition.ApiDefinitionService; import io.metersphere.api.service.definition.ApiTestCaseService; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.api.utils.ApiScenarioBatchOperationUtils; +import io.metersphere.functional.domain.FunctionalCaseTestExample; +import io.metersphere.functional.mapper.FunctionalCaseTestMapper; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.project.api.processor.MsProcessor; import io.metersphere.project.api.processor.TimeWaitingProcessor; @@ -41,7 +43,9 @@ import io.metersphere.project.dto.environment.http.HttpConfigModuleMatchRule; import io.metersphere.project.dto.environment.http.SelectModule; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.project.service.*; +import io.metersphere.project.service.EnvironmentGroupService; +import io.metersphere.project.service.EnvironmentService; +import io.metersphere.project.service.MoveNodeService; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.domain.EnvironmentExample; @@ -188,12 +192,15 @@ public class ApiScenarioService extends MoveNodeService { private ApiScenarioNoticeService apiScenarioNoticeService; @Resource private ExtApiScenarioReportMapper extApiScenarioReportMapper; + @Resource + private FunctionalCaseTestMapper functionalCaseTestMapper; public static final String PRIORITY = "Priority"; public static final String STATUS = "Status"; public static final String TAGS = "Tags"; public static final String ENVIRONMENT = "Environment"; private static final String SCENARIO_TABLE = "api_scenario"; + private static final String SCENARIO = "SCENARIO"; public List getScenarioPage(ApiScenarioPageRequest request) { @@ -454,6 +461,7 @@ public class ApiScenarioService extends MoveNodeService { /** * 处理复制场景时的文件复制 + * * @param request * @param scenario */ @@ -1187,6 +1195,12 @@ public class ApiScenarioService extends MoveNodeService { //删除定时任务 scheduleService.deleteByResourceId(scenario.getId(), ApiScenarioScheduleJob.class.getName()); + + //删除功能用例关联关系 + FunctionalCaseTestExample functionalCaseTestExample = new FunctionalCaseTestExample(); + functionalCaseTestExample.createCriteria().andSourceIdEqualTo(scenario.getId()).andSourceTypeEqualTo(SCENARIO); + functionalCaseTestMapper.deleteByExample(functionalCaseTestExample); + } private void deleteCsvByScenarioId(String id) { @@ -1237,6 +1251,11 @@ public class ApiScenarioService extends MoveNodeService { } apiScenarioCsvMapper.deleteByExample(csvExample); + //删除功能用例关联关系 + FunctionalCaseTestExample functionalCaseTestExample = new FunctionalCaseTestExample(); + functionalCaseTestExample.createCriteria().andSourceIdIn(scenarioIdList).andSourceTypeEqualTo(SCENARIO); + functionalCaseTestMapper.deleteByExample(functionalCaseTestExample); + }