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); + }