From c518caf85891966a0e57f5760731c7f4e7044a05 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 21 十一月 2022 12:26:43 +0800
Subject: [PATCH] 12

---
 src/main/java/com/lf/server/service/data/DataLoaderService.java |  168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 164 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/lf/server/service/data/DataLoaderService.java b/src/main/java/com/lf/server/service/data/DataLoaderService.java
index 36211f4..d36ecec 100644
--- a/src/main/java/com/lf/server/service/data/DataLoaderService.java
+++ b/src/main/java/com/lf/server/service/data/DataLoaderService.java
@@ -8,6 +8,7 @@
 import com.lf.server.helper.ClassHelper;
 import com.lf.server.helper.ExcelHelper;
 import com.lf.server.helper.FileHelper;
+import com.lf.server.helper.ZipHelper;
 import com.lf.server.mapper.all.GeomBaseMapper;
 import com.lf.server.service.all.BaseQueryService;
 import com.lf.server.service.all.BaseUploadService;
@@ -16,6 +17,7 @@
 
 import java.io.File;
 import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -34,9 +36,167 @@
 
     private final static String MDB = ".mdb";
 
-    private final static String SHP = ".shp.zip";
+    private final static String GDB = ".gdb";
 
-    private final static String GDB = ".gdb.zip";
+    private final static String SHP_ZIP = ".shp.zip";
+
+    private final static String GDB_ZIP = ".gdb.zip";
+
+    private final static String ZIP = ".zip";
+
+    /**
+     * 鏌ヨ鏄犲皠
+     */
+    public List<TabMapperEntity> selectMappers(String subPath) {
+        String root = pathHelper.getConfig().getTempPath() + File.separator + subPath;
+
+        File file = new File(root);
+        if (!file.exists() && !file.isDirectory()) {
+            return null;
+        }
+
+        File[] files = file.listFiles();
+        if (null == files || files.length == 0) {
+            return null;
+        }
+
+        File zipFile = new File(root + "_zip");
+        if (!zipFile.exists() || !zipFile.isDirectory()) {
+            zipFile.mkdirs();
+        }
+
+        return getMappers(zipFile.getPath(), files);
+    }
+
+    /**
+     * 鑾峰彇鏄犲皠
+     */
+    private List<TabMapperEntity> getMappers(String zipPath, File[] files) {
+        List<TabMapperEntity> list = new ArrayList<>();
+        for (File f : files) {
+            String fileName = FileHelper.getFileName(f.getPath());
+            if (fileName.contains(XLS)) {
+                list.add(new TabMapperEntity(fileName, "xls", fileName));
+                continue;
+            }
+            if (fileName.contains(MDB)) {
+                list.add(new TabMapperEntity(fileName, "mdb", fileName));
+                continue;
+            }
+            if (fileName.contains(SHP_ZIP)) {
+                String subPath = zipPath + File.separator + f.getName().toLowerCase().replace(".zip", "");
+                ZipHelper.unzip(f.getPath(), subPath);
+                getShpFiles(f.getName(), subPath, list);
+                continue;
+            }
+            if (fileName.contains(GDB_ZIP)) {
+                String subPath = zipPath + File.separator + f.getName().toLowerCase().replace(".zip", "");
+                ZipHelper.unzip(f.getPath(), subPath);
+                getGdbFiles(f.getName(), subPath, list);
+                continue;
+            }
+            if (!fileName.contains(ZIP)){
+                //
+            }
+        }
+
+        return list;
+    }
+
+    /**
+     * 鑾峰彇Shp鏂囦欢
+     */
+    private void getShpFiles(String sourceName, String subPath, List<TabMapperEntity> list) {
+        List<String> files = new ArrayList<>();
+        getShpFiles(subPath, files);
+
+        String root = subPath.substring(0, subPath.lastIndexOf(File.separator) + 1);
+        for (String file : files) {
+            String name = FileHelper.getFileName(file);
+            String path = file.replace(root, "");
+            list.add(new TabMapperEntity(sourceName, "shp", name, path));
+        }
+    }
+
+    /**
+     * 鑾峰彇Shp鏂囦欢
+     */
+    private void getShpFiles(String shpPath, List<String> list) {
+        File file = new File(shpPath);
+
+        File[] files = file.listFiles();
+        if (null == files || files.length == 0) {
+            return;
+        }
+
+        for (File f : files) {
+            if (f.isDirectory()) {
+                getShpFiles(f.getPath(), list);
+                continue;
+            }
+
+            if (f.getName().toLowerCase().endsWith(".shp")) {
+                list.add(f.getPath());
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇Gdb鏂囦欢
+     */
+    private void getGdbFiles(String sourceName, String subPath, List<TabMapperEntity> list){
+        List<String> files = new ArrayList<>();
+        getGdbFiles(subPath, files);
+
+        String root = subPath.substring(0, subPath.lastIndexOf(File.separator) + 1);
+        for (String file : files) {
+            String name = FileHelper.getFileName(file);
+            String path = file.replace(root, "");
+            list.add(new TabMapperEntity(sourceName, "shp", name, path));
+        }
+    }
+
+    /**
+     * 鑾峰彇Gdb鏂囦欢
+     */
+    private void getGdbFiles(String shpPath, List<String> list) {
+        File file = new File(shpPath);
+
+        File[] files = file.listFiles();
+        if (null == files || files.length == 0) {
+            return;
+        }
+
+        for (File f : files) {
+            if (!f.isDirectory()) {
+                continue;
+            }
+
+            if (isGdbFile(f)) {
+                list.add(f.getPath());
+                continue;
+            }
+
+            getGdbFiles(f.getPath(), list);
+        }
+    }
+
+    private boolean isGdbFile(File f) {
+        if (f.getName().toLowerCase().endsWith(GDB)) {
+            File[] files = f.listFiles();
+            if (null == files || files.length == 0) {
+                return false;
+            }
+
+            for (File file : files) {
+                if ("gdb".equals(file.getName())) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
 
     /**
      * 鎻掑叆鏂囦欢
@@ -152,10 +312,10 @@
         if (name.contains(MDB)) {
             return "mdb";
         }
-        if (name.contains(SHP)) {
+        if (name.contains(SHP_ZIP)) {
             return "shp";
         }
-        if (name.contains(GDB)) {
+        if (name.contains(GDB_ZIP)) {
             return "gdb";
         }
 

--
Gitblit v1.9.3