From ddbb93dae803ea73b06bad25fb12eaa322768d18 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 09 七月 2024 19:14:19 +0800
Subject: [PATCH] 提交一把

---
 server/service/src/main/java/com/doumee/core/utils/Constants.java |   47 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/core/utils/Constants.java b/server/service/src/main/java/com/doumee/core/utils/Constants.java
index 838ddac..a76e3db 100644
--- a/server/service/src/main/java/com/doumee/core/utils/Constants.java
+++ b/server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -1,5 +1,6 @@
 package com.doumee.core.utils;
 
+import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.IdcardUtil;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
@@ -9,6 +10,7 @@
 import com.doumee.dao.business.vo.CountCyclePriceVO;
 import io.swagger.models.auth.In;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.compress.archivers.zip.Zip64Mode;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.commons.lang3.StringUtils;
@@ -2202,7 +2204,13 @@
             InputStream inStream = null;
             OutputStream os = null;
             try {
-                String tempDir = System.getProperty("java.io.tmpdir")+fileName;
+                String tempDir = "C:\\hj\\jars\\temp\\";
+                File f =  new File(tempDir);
+                if(!f.exists() ){
+                    f.mkdirs();
+                }
+                tempDir +=  fileName;
+                System.out.println(url+"================="+tempDir);
                 file = new File(tempDir);
                 //涓嬭浇
                 urlfile = new URL(url);
@@ -2228,26 +2236,45 @@
                 }
             }
         }catch (Exception e){
-
+            e.printStackTrace();
         }
 
         return file;
     }
-    public static void packFilesToZip(List<File> files,    ServletOutputStream os) throws IOException {
-        try (ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(os)) {
+    public static void packFilesToZip(List<File> files,    OutputStream os) throws IOException {
+        try {
+            ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(os);
+            zipOutputStream.setUseZip64(Zip64Mode.AsNeeded);
             for (File file : files) {
+                if(!file.exists()){
+                    System.out.println("===鏂囦欢涓嶅瓨鍦�======="+file.getPath());
+                    continue;
+                }else{
+                    System.out.println("===鏂囦欢瀛樺湪======="+file.getPath());
+                }
                 ZipArchiveEntry entry = new ZipArchiveEntry(file.getName());
                 zipOutputStream.putArchiveEntry(entry);
-                try (FileInputStream fileInputStream = new FileInputStream(file)) {
-                    byte[] buffer = new byte[1024];
-                    int length;
-                    while ((length = fileInputStream.read(buffer)) > 0) {
-                        zipOutputStream.write(buffer, 0, length);
-                    }
+                FileInputStream fileInputStream = new FileInputStream(file);
+                byte[] buffer = new byte[1024];
+                int length;
+                while ((length = fileInputStream.read(buffer)) > 0) {
+                    zipOutputStream.write(buffer, 0, length);
                 }
                 zipOutputStream.closeArchiveEntry();
+                zipOutputStream.flush();
+                IoUtil.close(fileInputStream);
                 file.delete();
             }
+        }catch (Exception e){
+            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR.getCode(),"瀵逛笉璧凤紝涓嬭浇鍘嬬缉鏂囦欢澶辫触");
+        }finally {
+            if (os != null) {
+                try {
+                    os.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
         }
     }
 

--
Gitblit v1.9.3