瀏覽代碼

模版上传oss

lyhzzz 2 年之前
父節點
當前提交
756adfc324

+ 2 - 1
src/main/java/com/fdkankan/sale/common/FilePath.java

@@ -2,6 +2,7 @@ package com.fdkankan.sale.common;
 
 public class FilePath {
 
-    public static String file_path = "/home/backend/4dkankan/sale/file/";
+    public static String common = "common";
+    public static String file_path = "/home/backend/4dkankan_v4/sale/file/";
     public static String oss_file_path = "sale/file/%s/%s";
 }

+ 11 - 9
src/main/java/com/fdkankan/sale/util/MyExcelUtil.java

@@ -1,5 +1,7 @@
 package com.fdkankan.sale.util;
 
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.sale.common.FilePath;
 import com.fdkankan.sale.entity.Customer;
 import com.fdkankan.sale.entity.PriceList;
 import com.fdkankan.sale.service.IPriceListService;
@@ -12,6 +14,7 @@ import com.alibaba.excel.write.metadata.fill.FillConfig;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -20,6 +23,8 @@ import java.util.*;
 
 @Component
 public class MyExcelUtil {
+    @Autowired
+    FYunFileServiceInterface fYunFileServiceInterface;
 
     //根据模板导出excel
     public void listFill(HttpServletResponse response,String excelName,Object obj,Object obj2,Integer type) {
@@ -35,16 +40,13 @@ public class MyExcelUtil {
         // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
         // 填充list 的时候还要注意 模板中{.} 多了个点 表示list
         //获取文件路径
-        ClassPathResource resource= new ClassPathResource("file/excel/orderList.xlsx");
-        if(type == 1 ){
-             resource= new ClassPathResource("file/excel/repairWork.xlsx");
-        }
-        String templateFileName = null;
-        try {
-            templateFileName = resource.getFile().getPath();
-        } catch (IOException e) {
-            e.printStackTrace();
+        String ossPath =   String.format(FilePath.oss_file_path,FilePath.common,fileName);
+        String localPath = FilePath.file_path  + ossPath;
+        File file = new File(localPath);
+        if(!file.exists()){
+            fYunFileServiceInterface.downloadFile(ossPath,localPath );
         }
+        String templateFileName = file.getPath();
 
         ExcelWriter excelWriter = null;
         try {

二進制
src/main/resources/file/excel/orderList.xlsx


二進制
src/main/resources/file/excel/repairWork.xlsx