From e26af85e049516e6ce2b082bc2bc90bf71643e95 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 24 三月 2023 09:06:30 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/all/UploadAttachService.java |   42 ++++++++++++++++++++++--------------------
 1 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/lf/server/service/all/UploadAttachService.java b/src/main/java/com/lf/server/service/all/UploadAttachService.java
index ab48101..84de858 100644
--- a/src/main/java/com/lf/server/service/all/UploadAttachService.java
+++ b/src/main/java/com/lf/server/service/all/UploadAttachService.java
@@ -14,6 +14,7 @@
 import com.lf.server.mapper.data.DownloadMapper;
 import com.lf.server.service.sys.AttachService;
 import net.lingala.zip4j.ZipFile;
+import net.lingala.zip4j.model.FileHeader;
 import net.lingala.zip4j.model.ZipParameters;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -412,7 +413,7 @@
     /**
      * 璇锋眰涓嬭浇
      */
-    public String downloadReqForGuids(UserEntity ue, String[] guids) {
+    public String downloadReqForGuids(UserEntity ue, List<String> guids) {
         List<AttachEntity> list = attachService.selectByGuids(guids);
 
         return downloadReq(ue, list);
@@ -421,7 +422,7 @@
     /**
      * 璇锋眰涓嬭浇
      */
-    public String downloadReqForTabGuids(UserEntity ue, String tab, String[] guids) {
+    public String downloadReqForTabGuids(UserEntity ue, String tab, List<String> guids) {
         List<AttachEntity> list = attachService.selectByTabGuids(tab, guids);
 
         return downloadReq(ue, list);
@@ -435,20 +436,12 @@
             return null;
         }
 
-        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
-        String filePath = pathHelper.getTempPath(tempName) + File.separator + tempName;
-
-        File file = new File(filePath);
-        if (file.exists() && file.isDirectory()) {
-            FileHelper.deleteDir(filePath);
-        }
-
-        String zipName = tempName + ".zip";
+        String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip";
         String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName;
 
         ZipFile zip = Zip4jHelper.createZipFile(zipFile, null);
-        ZipParameters params = Zip4jHelper.getZipParams();
-        addZipFiles(zip, params, file.listFiles());
+        ZipParameters params = Zip4jHelper.getZipParams(false);
+        addZipFiles(zip, params, list);
 
         DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, null);
         int rows = downloadMapper.insert(downloadEntity);
@@ -459,14 +452,23 @@
     /**
      * 娣诲姞Zip鏂囦欢
      */
-    private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) {
-        if (null == files || files.length == 0) {
-            return;
-        }
-
-        for (File f : files) {
+    private void addZipFiles(ZipFile zip, ZipParameters params, List<AttachEntity> list) {
+        int i = 1;
+        String uploadPath = pathHelper.getConfig().getUploadPath();
+        for (AttachEntity ae : list) {
             try {
-                zip.addFile(f, params);
+                String filePath = uploadPath + File.separator + ae.getPath();
+
+                File file = new File(filePath);
+                if (!file.exists() || file.isDirectory()) {
+                    continue;
+                }
+
+                zip.addFile(file, params);
+                FileHeader header = zip.getFileHeader(file.getName());
+                if (null != header) {
+                    zip.renameFile(header, i + "_" + ae.getName());
+                }
             } catch (Exception ex) {
                 log.error(ex.getMessage(), ex);
             }

--
Gitblit v1.9.3