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

---
 src/main/java/com/lf/server/service/all/UploadAttachService.java |   70 ++++++++++++++++++++++++++++++++--
 1 files changed, 65 insertions(+), 5 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 ec0a2f4..ab48101 100644
--- a/src/main/java/com/lf/server/service/all/UploadAttachService.java
+++ b/src/main/java/com/lf/server/service/all/UploadAttachService.java
@@ -4,13 +4,17 @@
 import com.lf.server.controller.all.BaseController;
 import com.lf.server.entity.all.*;
 import com.lf.server.entity.ctrl.KeyValueEntity;
+import com.lf.server.entity.data.DownloadEntity;
 import com.lf.server.entity.data.MetaEntity;
 import com.lf.server.entity.data.MetaFileEntity;
 import com.lf.server.entity.sys.AttachEntity;
 import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.*;
 import com.lf.server.mapper.all.BasicMapper;
+import com.lf.server.mapper.data.DownloadMapper;
 import com.lf.server.service.sys.AttachService;
+import net.lingala.zip4j.ZipFile;
+import net.lingala.zip4j.model.ZipParameters;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,10 +24,7 @@
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 涓婁紶闄勪欢鏈嶅姟绫�
@@ -36,6 +37,9 @@
 
     @Autowired
     AttachService attachService;
+
+    @Autowired
+    DownloadMapper downloadMapper;
 
     private static String tabs = "''";
 
@@ -431,6 +435,62 @@
             return null;
         }
 
-        return "";
+        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 zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName;
+
+        ZipFile zip = Zip4jHelper.createZipFile(zipFile, null);
+        ZipParameters params = Zip4jHelper.getZipParams();
+        addZipFiles(zip, params, file.listFiles());
+
+        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, null);
+        int rows = downloadMapper.insert(downloadEntity);
+
+        return rows > 0 ? downloadEntity.getGuid() : null;
+    }
+
+    /**
+     * 娣诲姞Zip鏂囦欢
+     */
+    private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) {
+        if (null == files || files.length == 0) {
+            return;
+        }
+
+        for (File f : files) {
+            try {
+                zip.addFile(f, params);
+            } catch (Exception ex) {
+                log.error(ex.getMessage(), ex);
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇涓嬭浇瀹炰綋绫�
+     */
+    private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) {
+        DownloadEntity de = new DownloadEntity();
+        de.setName(FileHelper.getFileName(file));
+        // 1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁锛�5-绠¢亾鍒嗘瀽锛�6-缁熻鎶ュ憡锛�7-闄勪欢
+        de.setType(7);
+        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
+        de.setDepid(ue.getDepid());
+        de.setDcount(0);
+        de.setPwd(pwd);
+        de.setUrl(FileHelper.getRelativePath(file));
+        de.setDescr("闄勪欢鏂囦欢");
+        de.setGuid(FileHelper.getFileMd5(file));
+        de.setCreateUser(ue.getId());
+        // de.setGeom(null)
+
+        return de;
     }
 }

--
Gitblit v1.9.3