From 58a671a7c81c5bd71ebd1dbcb9b3f3aadb41aac4 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 10 一月 2023 17:51:12 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/all/BaseUploadService.java |   33 +++++++++++++++------------------
 1 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/lf/server/service/all/BaseUploadService.java b/src/main/java/com/lf/server/service/all/BaseUploadService.java
index a875bfd..0a5af79 100644
--- a/src/main/java/com/lf/server/service/all/BaseUploadService.java
+++ b/src/main/java/com/lf/server/service/all/BaseUploadService.java
@@ -194,6 +194,7 @@
         }
 
         List<MetaFileEntity> list = new ArrayList<>();
+        List<DirEntity> dirs = dirService.selectDirRecursive(dir.getName());
         for (MetaFileEntity meta : metas) {
             meta.setEventid(StringHelper.getGuid());
             meta.setDirid(dir.getId());
@@ -203,7 +204,7 @@
             meta.setEpsgCode(epsgCode);
 
             if (StaticData.ZIP.equals(meta.getExtName())) {
-                List<MetaFileEntity> subs = getMapperFiles(path, dir, meta);
+                List<MetaFileEntity> subs = getMapperFiles(path, dir, dirs, meta);
                 if (null != subs && subs.size() > 0) {
                     list.addAll(subs);
                     continue;
@@ -219,8 +220,9 @@
     /**
      * 鑾峰彇鏄犲皠鏂囦欢
      */
-    private List<MetaFileEntity> getMapperFiles(String path, DirEntity dir, MetaFileEntity meta) {
-        String zipFile = pathHelper.getConfig().getTempPath() + File.separator + meta.getPath();
+    private List<MetaFileEntity> getMapperFiles(String path, DirEntity dir, List<DirEntity> dirs, MetaFileEntity meta) {
+        String tempPath = pathHelper.getConfig().getTempPath();
+        String zipFile = tempPath + File.separator + meta.getPath();
         File file = new File(zipFile);
         if (!file.exists() || file.isDirectory()) {
             return null;
@@ -240,13 +242,13 @@
             return null;
         }
 
-        return getMapperFiles(files, dir, meta, subPath);
+        return getMapperFiles(files, dir, dirs, meta, tempPath.length() + 1);
     }
 
     /**
      * 鑾峰彇鏄犲皠鏂囦欢
      */
-    private List<MetaFileEntity> getMapperFiles(File[] files, DirEntity dir, MetaFileEntity meta, String subPath) {
+    private List<MetaFileEntity> getMapperFiles(File[] files, DirEntity dir, List<DirEntity> dirs, MetaFileEntity meta, int start) {
         List<MetaFileEntity> list = new ArrayList<>();
         for (File f : files) {
             boolean isGdb = isGdbFile(f);
@@ -260,10 +262,10 @@
                 continue;
             }
 
-            int dirid = getDirByPath(f.getPath(), dir);
+            int dirid = getDirByPath(f.getPath(), dir, dirs);
             boolean isShp = StaticData.SHP.equals(extName);
             if (isGdb) {
-                List<MetaFileEntity> rs = getGdbMappers(f, meta, dirid, subPath);
+                List<MetaFileEntity> rs = getGdbMappers(f, meta, dirid, start);
                 if (null != rs && rs.size() > 0) {
                     list.addAll(rs);
                 }
@@ -275,7 +277,7 @@
             mf.setEventid(StringHelper.getGuid());
             mf.setName(fileName);
             mf.setExtName(extName);
-            mf.setPath(f.getPath().substring(subPath.length()));
+            mf.setPath(f.getPath().substring(start));
 
             if (isShp) {
                 List<String> shpFiles = getShpFiles(f.getPath());
@@ -309,20 +311,15 @@
     /**
      * 鏍规嵁鏂囦欢璺緞鑾峰彇鐩綍ID
      */
-    private int getDirByPath(String filePath, DirEntity dir) {
-        if (0 != dir.getPid()) {
-            return dir.getId();
-        }
-
-        List<DirEntity> list = dirService.selectDirRecursive(dir.getName());
-        if (null == list || list.isEmpty()) {
+    private int getDirByPath(String filePath, DirEntity dir, List<DirEntity> dirs) {
+        if (0 != dir.getPid() || null == dirs || dirs.isEmpty()) {
             return dir.getId();
         }
         if ("/".equals(File.separator)) {
             filePath = filePath.replace("/", "\\");
         }
 
-        for (DirEntity entity : list) {
+        for (DirEntity entity : dirs) {
             if (filePath.contains(entity.getFullName())) {
                 return entity.getId();
             }
@@ -405,7 +402,7 @@
     /**
      * 鑾峰彇GDB鏂囦欢鏄犲皠
      */
-    private List<MetaFileEntity> getGdbMappers(File f, MetaFileEntity meta, int dirid, String subPath) {
+    private List<MetaFileEntity> getGdbMappers(File f, MetaFileEntity meta, int dirid, int start) {
         List<String> tabs = GdbHelper.getTabNames(f.getPath());
         if (null == tabs || tabs.size() == 0) {
             return null;
@@ -426,7 +423,7 @@
             mf.setName(fileName);
             mf.setExtName(extName);
             mf.setSizes(FileHelper.sizeToMb(f.length()));
-            mf.setPath(f.getPath().substring(subPath.length()));
+            mf.setPath(f.getPath().substring(start));
             mf.setTab(tab);
             mf.setSizes(sizes);
             mf.setGuid(md5);

--
Gitblit v1.9.3