浏览代码

下载文件

lyhzzz 2 年之前
父节点
当前提交
73fdf2b774
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      src/main/java/com/fdkankan/sale/util/MyExcelUtil.java

+ 10 - 3
src/main/java/com/fdkankan/sale/util/MyExcelUtil.java

@@ -1,6 +1,7 @@
 package com.fdkankan.sale.util;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.io.FileUtil;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.sale.common.CacheUtil;
 import com.fdkankan.sale.common.FilePath;
@@ -101,10 +102,14 @@ public class MyExcelUtil {
      */
     private void imageHandleByParam(Map<String, Object> param) {
         for (Map.Entry<String, Object> entry : param.entrySet()) {
+            String mapKey = entry.getKey();
+            String ossPath = entry.getValue().toString();
+            String downloadPath = FilePath.file_path + ossPath.replaceAll(CacheUtil.host,"");
             try {
-                String mapKey = entry.getKey();
-                String ossPath = entry.getValue().toString();
-                String downloadPath = FilePath.file_path + ossPath.replaceAll(CacheUtil.host,"");
+                File file = new File(downloadPath);
+                if(!file.exists()){
+                    fYunFileServiceInterface.downloadFile(ossPath,downloadPath );
+                }
                 // 填充图片
                 ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
                 BufferedImage bufferImg = ImageIO.read(new File(downloadPath));
@@ -120,6 +125,8 @@ public class MyExcelUtil {
                 param.put(mapKey, byteArrayOut.toByteArray());
             } catch (IOException e) {
                 e.printStackTrace();
+            }finally {
+                FileUtil.del(downloadPath);
             }
         }
     }