diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index f9e9bf0528..09b1c6cdcb 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -333,10 +333,14 @@ public class ApiTestCaseService { extApiDefinitionExecResultMapper.deleteByResourceId(testId); apiTestCaseMapper.deleteByPrimaryKey(testId); esbApiParamService.deleteByResourceId(testId); - deleteBodyFiles(testId); // 删除附件关系 extFileAssociationService.deleteByResourceId(testId); deleteFollows(testId); + ApiTestCase apiTestCase = apiTestCaseMapper.selectByPrimaryKey(testId); + if (apiTestCase != null) { + String filePath = StringUtils.join(BODY_FILE_DIR, File.separator, apiTestCase.getId()); + FileUtil.deleteContents(new File(filePath)); + } } private void deleteFollows(String testId) { @@ -362,14 +366,6 @@ public class ApiTestCaseService { } } - public void deleteBodyFiles(String testId) { - File file = new File(BODY_FILE_DIR + "/" + testId); - FileUtil.deleteContents(file); - if (file.exists()) { - file.delete(); - } - } - public void checkNameExist(SaveApiTestCaseRequest request) { if (hasSameCase(request)) { MSException.throwException(Translator.get("case_name_is_already_exist") + ": " + request.getName());