Просмотр исходного кода

1.每天首次下载文档没有路径报错处理

赵越越 4 недель назад
Родитель
Сommit
ecf32ac2c3

+ 4 - 1
assistMg/src/main/java/com/hotent/project/manager/impl/CostProjectDocumentManagerImpl.java

@@ -36,6 +36,7 @@ import com.hotent.uc.exception.BaseException;
 import com.hotent.uc.manager.UserManager;
 import com.hotent.uc.model.User;
 import com.hotent.uc.util.ContextUtil;
+import com.hotent.util.FileUtils;
 import com.hotent.util.HtmlUtils;
 import com.hotent.util.wordexcelutils.*;
 import org.apache.commons.lang.StringUtils;
@@ -546,7 +547,9 @@ public class CostProjectDocumentManagerImpl extends BaseManagerImpl<CostProjectD
         String outputPath = FileUploadUtil.generateSavePath(EipConfig.getUploadPath(), fileName, fileExtension);
         try (FileInputStream fis = new FileInputStream(templatePath);
              XWPFDocument document = new XWPFDocument(fis);
-             FileOutputStream fos = new FileOutputStream(outputPath)) {
+             FileOutputStream fos = FileUtils.createFileOutputStream(outputPath);) {
+
+            //FileOutputStream fos = new FileOutputStream(outputPath);
             //SimpleStylePreserver.smartReplaceKeepStyle(document,map);
             //BestPracticeReplacer.replaceTextBestPractice(document,map);
             //BestPracticeReplacer.applySmartStyles(document);

+ 33 - 0
assistMg/src/main/java/com/hotent/util/FileUtils.java

@@ -0,0 +1,33 @@
+package com.hotent.util;/**
+ * @program: cbjs-mvue-master
+ * @description:
+ * @author: zhao yue yue
+ * @create: 2025-11-28 09:43
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+
+/**
+ *@author: zhao yue yue
+ *@create: 2025-11-28 09:43
+ */
+public class FileUtils {
+
+    public static FileOutputStream createFileOutputStream(String filePath) throws IOException {
+        File file = new File(filePath);
+
+        // 确保目录存在
+        File parentDir = file.getParentFile();
+        if (parentDir != null && !parentDir.exists()) {
+            boolean created = parentDir.mkdirs();
+            if (!created) {
+                throw new IOException("无法创建目录: " + parentDir.getAbsolutePath());
+            }
+        }
+
+        return new FileOutputStream(file);
+    }
+}