From dc137d62c3c6bb62b3d43965b514ca9ebaf9c7f4 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 06 三月 2023 14:51:19 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/all/UploadAttachService.java |   36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 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..53cb4b3 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;
@@ -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());
+        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