From 740265134189a7370f0d410cc03186e03339d65e Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 20 十二月 2022 11:20:50 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/show/DataLibService.java |   65 +++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/lf/server/service/show/DataLibService.java b/src/main/java/com/lf/server/service/show/DataLibService.java
index c5f5a59..9835765 100644
--- a/src/main/java/com/lf/server/service/show/DataLibService.java
+++ b/src/main/java/com/lf/server/service/show/DataLibService.java
@@ -1,11 +1,17 @@
 package com.lf.server.service.show;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.lf.server.entity.data.DownloadEntity;
 import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.*;
 import com.lf.server.mapper.all.GeomBaseMapper;
+import com.lf.server.mapper.data.DownloadMapper;
 import com.lf.server.service.all.BaseQueryService;
 import com.lf.server.service.data.DownloadService;
+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;
 import org.springframework.stereotype.Service;
 
@@ -25,10 +31,15 @@
     PathHelper pathHelper;
 
     @Autowired
-    BaseQueryService baseQueryService;
+    DownloadMapper downloadMapper;
 
     @Autowired
     DownloadService downloadService;
+
+    @Autowired
+    BaseQueryService baseQueryService;
+
+    private final static Log log = LogFactory.getLog(DataLibService.class);
 
     /**
      * 鍒涘缓Zip鍖�
@@ -41,6 +52,7 @@
 
         String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
         String tempPath = pathHelper.getTempPath(tempName);
+        // String filePath = "D:\\LF\\temp\\20221219202706\\2022.gdb"
         String filePath = tempPath + File.separator + tempName + ".gdb";
 
         File file = new File(filePath);
@@ -49,7 +61,18 @@
         }
         GdbHelper.createGdb(filePath, map);
 
-        return null;
+        String zipName = tempName + ".gdb.zip";
+        String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName;
+
+        ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd);
+        ZipParameters params = Zip4jHelper.getZipParams();
+        addZipFiles(zip, params, file.listFiles());
+
+        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
+        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd);
+        int rows = downloadMapper.insert(downloadEntity);
+
+        return rows > 0 ? downloadEntity.getGuid() : null;
     }
 
     /**
@@ -92,4 +115,42 @@
 
         return wrapper;
     }
+
+    /**
+     * 娣诲姞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) throws Exception {
+        DownloadEntity de = new DownloadEntity();
+        de.setName(FileHelper.getFileName(file));
+        // 1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁
+        de.setType(4);
+        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