‘linchangsheng’ 4 mesi fa
parent
commit
12a871864a

+ 5 - 1
mall-server-api/src/main/java/com/gree/mall/manager/logic/policy/AgreementLogic.java

@@ -55,6 +55,10 @@ public class AgreementLogic {
     private String active;
 
 
+    @Value("${web.upload-path}")
+    private String uploadUrl;
+
+
     @Autowired
     CommonLogic commonLogic;
 
@@ -355,7 +359,7 @@ public class AgreementLogic {
             rows.add(row);
         }
         // 获取资源文件存放路径,用于临时存放生成的excel文件
-        String path = "/tmp";
+        String path = uploadUrl;
         if (active.equals("dev")) {
             path = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath();
         }

+ 10 - 0
mall-server-api/src/main/java/com/gree/mall/manager/utils/excel/ExcelUtils.java

@@ -3,6 +3,7 @@ package com.gree.mall.manager.utils.excel;
 
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.EasyExcelFactory;
 import com.alibaba.excel.ExcelWriter;
@@ -188,6 +189,15 @@ public class ExcelUtils {
     public static void createExcel(String filePath,ExcelData excelData) throws IOException {
         OutputStream out = null;
         try {
+            File file = new File(filePath);
+
+            // 确保文件路径存在
+            if (!file.getParentFile().exists()) {
+                // 尝试创建父目录
+                if (!file.getParentFile().mkdirs()) {
+                   log.info("无法创建文件夹");
+                }
+            }
             //标题
             List<List<String>> titles = new ArrayList<>();
             for(String title : excelData.getTitles()){