diff --git a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java index b2bf900010..9c84d4d589 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MockConfigService.java @@ -27,6 +27,9 @@ import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.service.NoticeSendService; import io.metersphere.service.definition.ApiDefinitionService; import io.metersphere.service.ext.ExtProjectApplicationService; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -39,9 +42,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import org.xml.sax.InputSource; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.ByteArrayInputStream; @@ -678,6 +678,21 @@ public class MockConfigService { mockConfigMapper.deleteByExample(configExample); } + public void deleteMockConfigByApiIds(List apiIds) { + MockConfigExample configExample = new MockConfigExample(); + configExample.createCriteria().andApiIdIn(apiIds); + List mockConfigList = mockConfigMapper.selectByExample(configExample); + MockExpectConfigExample example = new MockExpectConfigExample(); + List mockConfigIds = mockConfigList.stream().map(MockConfig::getId).toList(); + example.createCriteria().andMockConfigIdIn(mockConfigIds); + List deleteBlobs = mockExpectConfigMapper.selectByExampleWithBLOBs(example); + for (MockExpectConfigWithBLOBs model : deleteBlobs) { + this.deleteMockExpectFiles(model); + } + mockExpectConfigMapper.deleteByExample(example); + mockConfigMapper.deleteByExample(configExample); + } + public Map> getApiParamsByApiDefinitionBLOBs(ApiDefinitionWithBLOBs apiModel) { if (apiModel == null) { return new HashMap<>(); diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index e1cd457a3d..8e64c15a8f 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -1219,9 +1219,19 @@ public class ApiDefinitionService { example.createCriteria().andRefIdIn(refIds); List apiDefinitions = apiDefinitionMapper.selectByExample(example); List apiIds = apiDefinitions.stream().map(ApiDefinition::getId).collect(Collectors.toList()); - //删除Api、ApiCase中resourceID被删除了的执行记录 - apiTestCaseService.deleteBatchByDefinitionId(apiIds); - apiDefinitionMapper.deleteByExample(example); + if (CollectionUtils.isNotEmpty(apiIds)) { + //删除Api、ApiCase中resourceID被删除了的执行记录 + apiTestCaseService.deleteBatchByDefinitionId(apiIds); + apiDefinitionMapper.deleteByExample(example); + // 删除附件关系 + extFileAssociationService.deleteByResourceIds(apiIds); + // 删除自定义字段关联关系 + customFieldApiService.deleteByResourceIds(apiIds); + // 删除关系图 + relationshipEdgeService.delete(apiIds); + mockConfigService.deleteMockConfigByApiIds(apiIds); + deleteFollows(apiIds); + } } public ApiDefinitionExample getBatchExample(ApiBatchRequest request) {