diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java index 7889098880..2b3326cbd5 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java @@ -432,10 +432,10 @@ public class FunctionalCaseFileService { Project project = projectMapper.selectByPrimaryKey(request.getProjectId()); String fileType = ""; try { - tmpDir = new File(getClass().getClassLoader().getResource(StringUtils.EMPTY).getPath() + - EXPORT_CASE_TMP_DIR + File.separatorChar + EXPORT_CASE_TMP_DIR + "_" + IDGenerator.nextStr()); - // 生成tmp随机目录 - tmpDir.mkdirs(); + tmpDir = new File(LocalRepositoryDir.getSystemTempDir() + File.separatorChar + EXPORT_CASE_TMP_DIR + "_" + IDGenerator.nextStr()); + if (!tmpDir.exists() && !tmpDir.mkdirs()) { + throw new MSException(Translator.get("upload_fail")); + } //获取导出的ids集合 List batchExcels = new ArrayList<>(); List ids = functionalCaseService.doSelectIds(request, request.getProjectId()); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java index fddad4b378..3f7d007d52 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java @@ -9,6 +9,7 @@ import io.metersphere.functional.socket.ExportWebSocketHandler; import io.metersphere.functional.xmind.domain.FunctionalCaseXmindDTO; import io.metersphere.functional.xmind.domain.FunctionalCaseXmindData; import io.metersphere.functional.xmind.utils.XmindExportUtil; +import io.metersphere.sdk.constants.LocalRepositoryDir; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.constants.MsgType; import io.metersphere.sdk.dto.ExportMsgDTO; @@ -30,7 +31,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -115,12 +115,16 @@ public class FunctionalCaseXmindService { if (CollectionUtils.isEmpty(ids)) { return null; } + File dir = null; File tmpFile = null; try { FunctionalCaseXmindData xmindData = buildXmindData(ids, request); - tmpFile = new File(getClass().getClassLoader().getResource(StringUtils.EMPTY).getPath() + + dir = new File(LocalRepositoryDir.getSystemTempDir()); + if (!dir.exists() && !dir.mkdir()) { + throw new MSException(Translator.get("upload_fail")); + } + tmpFile = new File(LocalRepositoryDir.getSystemTempDir() + File.separatorChar + EXPORT_CASE_TMP_DIR + "_" + IDGenerator.nextStr() + ".xmind"); - tmpFile.createNewFile(); List templateCustomFields = functionalCaseFileService.getCustomFields(request.getProjectId()); TemplateCustomFieldDTO templateCustomFieldDTO = templateCustomFields.stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get(); XmindExportUtil.export(xmindData, request, tmpFile, templateCustomFieldDTO); @@ -146,7 +150,7 @@ public class FunctionalCaseXmindService { } LogUtils.error(e); throw new MSException(e); - }finally { + } finally { try { FileUtils.delete(tmpFile); } catch (Exception e) {