From adcaf3e378b90c8173958233ca6fa1f162a7b71d Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 30 三月 2023 16:46:58 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/show/DataLibService.java |   44 +++++++++++++++++++++++++++++++++-----------
 src/main/java/com/lf/server/helper/Zip4jHelper.java          |    2 ++
 src/main/java/com/lf/server/helper/GdbHelper.java            |    2 +-
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/lf/server/helper/GdbHelper.java b/src/main/java/com/lf/server/helper/GdbHelper.java
index eaa458e..1d1a06c 100644
--- a/src/main/java/com/lf/server/helper/GdbHelper.java
+++ b/src/main/java/com/lf/server/helper/GdbHelper.java
@@ -440,7 +440,7 @@
         SpatialReference sr = new SpatialReference();
         sr.ImportFromEPSG(null == srid ? 4490 : srid);
 
-        return dataSource.CreateLayer(tab, sr, getGeomType(geomType), null);
+        return dataSource.CreateLayer(tab.replace(".", "_"), sr, getGeomType(geomType), null);
     }
 
     /**
diff --git a/src/main/java/com/lf/server/helper/Zip4jHelper.java b/src/main/java/com/lf/server/helper/Zip4jHelper.java
index aebf380..5440578 100644
--- a/src/main/java/com/lf/server/helper/Zip4jHelper.java
+++ b/src/main/java/com/lf/server/helper/Zip4jHelper.java
@@ -11,6 +11,7 @@
 import org.apache.commons.logging.LogFactory;
 
 import java.io.File;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
 /**
@@ -64,6 +65,7 @@
     public static ZipFile createZipFile(String zipFile, String pwd) {
         try {
             ZipFile zip = StringHelper.isEmpty(pwd) ? new ZipFile(zipFile) : new ZipFile(zipFile, pwd.toCharArray());
+            // zip.setCharset(Charset.forName("GBK"))
             zip.setCharset(StandardCharsets.UTF_8);
 
             File f = zip.getFile();
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 e5cda4e..dc41a8c 100644
--- a/src/main/java/com/lf/server/service/show/DataLibService.java
+++ b/src/main/java/com/lf/server/service/show/DataLibService.java
@@ -20,6 +20,7 @@
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.util.*;
 
 /**
@@ -152,7 +153,6 @@
         String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
         String tempPath = pathHelper.getTempPath(tempName);
         String gdbPath = tempPath + File.separator + "tabs.gdb";
-        String annexPath = tempPath + File.separator + "annex";
 
         File gdbFile = new File(gdbPath);
         if (gdbFile.exists() && gdbFile.isDirectory()) {
@@ -160,17 +160,12 @@
         }
         GdbHelper.createGdb(gdbPath, dataMap);
 
-        File annexFile = new File(annexPath);
-        if (!annexFile.exists() || !annexFile.isDirectory()) {
-            annexFile.mkdirs();
-        }
-        createAnnex(annexPath, annexMap);
-
         String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".gdb.zip";
         ZipFile zip = Zip4jHelper.createZipFile(zipFile, dr.getPwd());
         ZipParameters params = Zip4jHelper.getZipParams(true);
         zip.addFolder(new File(gdbPath), params);
-        zip.addFolder(new File(annexPath), params);
+        // zip.addFolder(new File(annexPath), params)
+        addAnnex(zip, params, annexMap);
 
         String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd()));
         DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd);
@@ -215,9 +210,9 @@
                 }
 
                 if (!annexMap.containsKey(entity)) {
-                    annexMap.put(entity, annex);
+                    annexMap.put(tab.replace(".", "_"), annex);
                 } else {
-                    annexMap.get(entity).addAll(annex);
+                    annexMap.get(tab.replace(".", "_")).addAll(annex);
                 }
             } catch (Exception ex) {
                 log.error(ex.getMessage(), ex);
@@ -256,7 +251,7 @@
     }
 
     /**
-     * 鍒涘缓闄勪欢
+     * 鍒涘缓闄勪欢 *
      */
     private void createAnnex(String annexPath, Map<String, List<AttachEntity>> annexMap) {
         if (annexMap.size() == 0) {
@@ -292,6 +287,33 @@
     }
 
     /**
+     * 娣诲姞闄勪欢
+     */
+    private void addAnnex(ZipFile zip, ZipParameters params, Map<String, List<AttachEntity>> annexMap) {
+        List<String> files = new ArrayList<>();
+        String uploadPath = pathHelper.getConfig().getUploadPath();
+        for (String key : annexMap.keySet()) {
+            for (AttachEntity ae : annexMap.get(key)) {
+                try {
+                    File srcFile = new File(uploadPath + File.separator + ae.getPath());
+                    if (!srcFile.exists() || srcFile.isDirectory()) {
+                        continue;
+                    }
+                    if (files.contains(srcFile.getPath())) {
+                        continue;
+                    }
+
+                    files.add(srcFile.getPath());
+                    params.setFileNameInZip(key + File.separator + ae.getName());
+                    zip.addStream(new FileInputStream(srcFile), params);
+                } catch (Exception ex) {
+                    log.error(ex.getMessage(), ex);
+                }
+            }
+        }
+    }
+
+    /**
      * 鑾峰彇涓嬭浇瀹炰綋绫�
      */
     private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) {

--
Gitblit v1.9.3