From ac20dc99bf1f463365dba071973e08fffbd294b4 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 14 七月 2023 14:12:21 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/all/BaseUploadService.java |  195 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 133 insertions(+), 62 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 17509af..2bb8137 100644
--- a/src/main/java/com/lf/server/service/all/BaseUploadService.java
+++ b/src/main/java/com/lf/server/service/all/BaseUploadService.java
@@ -28,10 +28,10 @@
 @Service
 public class BaseUploadService {
     @Autowired
-    private DirService dirService;
+    protected DirService dirService;
 
     @Autowired
-    private PathHelper pathHelper;
+    protected PathHelper pathHelper;
 
     public final Log log = LogFactory.getLog(getClass());
 
@@ -45,7 +45,7 @@
     /**
      * 涓婁紶鏂囦欢
      */
-    public <T> List<MetaFileEntity> uploadData(T t, String path, HttpServletRequest req, HttpServletResponse res) throws Exception {
+    public <T> List<MetaFileEntity> uploadData(T t, String path, boolean isGetGuid, HttpServletRequest req, HttpServletResponse res) throws Exception {
         StandardMultipartHttpServletRequest request = (StandardMultipartHttpServletRequest) req;
         req.setCharacterEncoding("utf-8");
         res.setContentType("application/json;charset=utf-8");
@@ -54,7 +54,7 @@
             setEntity(t, request);
         }
 
-        return getFiles(path, request);
+        return getFiles(path, isGetGuid, request);
     }
 
     /**
@@ -97,7 +97,7 @@
     /**
      * 鑾峰彇鏂囦欢
      */
-    public List<MetaFileEntity> getFiles(String subPath, StandardMultipartHttpServletRequest req) throws Exception {
+    public List<MetaFileEntity> getFiles(String subPath, boolean isGetGuid, StandardMultipartHttpServletRequest req) throws Exception {
         List<MetaFileEntity> list = new ArrayList<>();
 
         String path = pathHelper.getTempPath(subPath);
@@ -116,7 +116,9 @@
             mf.setPath(path + File.separator + mf.getName());
 
             file.transferTo(new File(mf.getPath()));
-            mf.setGuid(FileHelper.getFileMd5(mf.getPath()));
+            if (isGetGuid) {
+                mf.setGuid(FileHelper.getFileMd5(mf.getPath()));
+            }
 
             list.add(mf);
         }
@@ -127,7 +129,7 @@
     /**
      * 鏌ヨ鏂囦欢
      */
-    public List<MetaFileEntity> selectFiles(String subPath, List<String> extList) {
+    public List<MetaFileEntity> selectFiles(String subPath) {
         String root = pathHelper.getConfig().getTempPath() + File.separator + subPath;
 
         File file = new File(root);
@@ -143,7 +145,7 @@
         for (File f : files) {
             String fileName = FileHelper.getFileName(f.getPath());
             String extName = FileHelper.getExtension(fileName);
-            if (null != extList && !extList.contains(extName)) {
+            if (!isExtValid(extName)) {
                 continue;
             }
 
@@ -188,17 +190,17 @@
      * 鏌ヨ鏄犲皠
      */
     public List<MetaFileEntity> selectMappers(UserEntity ue, String path, DirEntity dir, VerEntity ver, String epsgCode) {
-        List<MetaFileEntity> metas = selectFiles(path, StaticData.ALL_EXTENSION);
+        List<MetaFileEntity> metas = selectFiles(path);
         if (null == metas || metas.isEmpty()) {
             return null;
         }
 
         List<MetaFileEntity> list = new ArrayList<>();
-        List<DirEntity> dirs = dirService.selectDirRecursive(dir.getName());
+        List<DirEntity> dirs = dirService.selectRecursiveById(dir.getId());
         for (MetaFileEntity meta : metas) {
             meta.setEventid(StringHelper.getGuid());
-            meta.setDirid(dir.getId());
-            meta.setDepid(ue.getDepid());
+            meta.setDircode(dir.getCode());
+            meta.setDepcode(ue.getDepcode());
             meta.setVerid(ver.getId());
             meta.setCreateUser(ue.getId());
             meta.setEpsgCode(epsgCode);
@@ -234,7 +236,8 @@
             zipFolder.mkdirs();
         }
 
-        String subPath = zipFolder + File.separator + meta.getName().toLowerCase().replace(".zip", "");
+        // String subPath = zipFolder + File.separator + meta.getName().toLowerCase().replace(".zip", "") .replace("锛�","").replace("锛�","").replace(" ","")
+        String subPath = zipFolder.getPath();
         ZipHelper.unzip(zipFile, subPath);
 
         List<File> files = new ArrayList<>();
@@ -250,13 +253,13 @@
         File file = new File(path);
         if (!file.isDirectory()) {
             String extName = FileHelper.getExtension(file);
-            if (StaticData.ALL_EXTENSION.contains(extName)) {
+            if (isExtValid(extName)) {
                 list.add(file);
             }
             return;
         }
 
-        if (isGdbFile(file)) {
+        if (isGdbFile(file) || isOsgbFile(file)) {
             list.add(file);
             return;
         }
@@ -270,11 +273,18 @@
                 getFilesByPath(list, f.getPath());
             } else {
                 String extName = FileHelper.getExtension(f);
-                if (StaticData.ALL_EXTENSION.contains(extName)) {
+                if (isExtValid(extName)) {
                     list.add(f);
                 }
             }
         }
+    }
+
+    /**
+     * 鎵╁睍鏄惁鏈夋晥
+     */
+    private boolean isExtValid(String extName) {
+        return StaticData.ALL_EXTENSION.contains(extName) && !StaticData.MAPPER_EXCLUDE_EXT.contains(extName);
     }
 
     /**
@@ -284,42 +294,34 @@
         List<MetaFileEntity> list = new ArrayList<>();
         for (File f : files) {
             boolean isGdb = isGdbFile(f);
-            if (!isGdb && f.isDirectory()) {
+            boolean isOsgb = isOsgbFile(f);
+            boolean isFile = isGdb || isOsgb;
+            if (f.isDirectory() && !isFile) {
                 continue;
             }
 
             String fileName = FileHelper.getFileName(f.getPath());
-            String extName = FileHelper.getExtension(fileName);
-            if (!StaticData.ALL_EXTENSION.contains(extName)) {
+            String extName = isOsgb ? StaticData.OSGB : FileHelper.getExtension(fileName);
+            if (!isExtValid(extName) || fileName.startsWith("~")) {
                 continue;
             }
 
-            int dirid = getDirByPath(f.getPath(), fileName, dir, dirs);
-            boolean isShp = StaticData.SHP.equals(extName);
+            String dircode = getDirByPath(f.getPath(), fileName, dir, dirs);
             if (isGdb) {
-                List<MetaFileEntity> rs = getGdbMappers(f, meta, dirid, start);
+                List<MetaFileEntity> rs = getGdbMappers(f, meta, dircode, start);
                 if (null != rs && rs.size() > 0) {
                     list.addAll(rs);
                 }
                 continue;
             }
-
-            MetaFileEntity mf = createMetaFileEntity(meta);
-            mf.setDirid(dirid);
-            mf.setEventid(StringHelper.getGuid());
-            mf.setName(fileName);
-            mf.setExtName(extName);
-            mf.setPath(f.getPath().substring(start));
-
-            if (isShp) {
-                List<String> shpFiles = getShpFiles(f.getPath());
-                mf.setTab(fileName);
-                mf.setSizes(getFilesSize(shpFiles));
-                mf.setGuid(getFilesMd5(shpFiles));
-            } else {
-                mf.setSizes(FileHelper.sizeToMb(f.length()));
-                mf.setGuid(FileHelper.getFileMd5(f.getPath()));
+            if (isOsgb) {
+                list.add(getOsgbMapper(f, meta, dircode, start));
+                continue;
             }
+
+            MetaFileEntity mf = createMetaFileEntity(f, meta, fileName, extName);
+            mf.setPath(f.getPath().substring(start));
+            mf.setDircode(dircode);
             list.add(mf);
         }
 
@@ -329,10 +331,34 @@
     /**
      * 鍒涘缓鍏冩暟鎹枃浠跺疄浣撶被
      */
+    private MetaFileEntity createMetaFileEntity(File f, MetaFileEntity meta, String fileName, String extName) {
+        boolean isShp = StaticData.SHP.equals(extName);
+
+        MetaFileEntity mf = createMetaFileEntity(meta);
+        mf.setEventid(StringHelper.getGuid());
+        mf.setName(fileName);
+        mf.setExtName(extName);
+
+        if (isShp) {
+            List<String> shpFiles = getShpFiles(f.getPath());
+            mf.setTab(fileName.replace(StaticData.SHP, ""));
+            mf.setSizes(getFilesSize(shpFiles));
+            mf.setGuid(getFilesMd5(shpFiles));
+        } else {
+            mf.setSizes(FileHelper.sizeToMb(f.length()));
+            mf.setGuid(FileHelper.getFileMd5(f.getPath()));
+        }
+
+        return mf;
+    }
+
+    /**
+     * 鍒涘缓鍏冩暟鎹枃浠跺疄浣撶被
+     */
     private MetaFileEntity createMetaFileEntity(MetaFileEntity meta) {
         MetaFileEntity mf = new MetaFileEntity();
-        mf.setDirid(meta.getDirid());
-        mf.setDepid(meta.getDepid());
+        mf.setDircode(meta.getDircode());
+        mf.setDepcode(meta.getDepcode());
         mf.setVerid(meta.getVerid());
         mf.setCreateUser(meta.getCreateUser());
         mf.setEpsgCode(meta.getEpsgCode());
@@ -343,32 +369,34 @@
     /**
      * 鏍规嵁鏂囦欢璺緞鑾峰彇鐩綍ID
      */
-    private int getDirByPath(String filePath,String fileName, DirEntity dir, List<DirEntity> dirs) {
+    private String getDirByPath(String filePath,String fileName, DirEntity dir, List<DirEntity> dirs) {
         if (0 != dir.getPid() || null == dirs || dirs.isEmpty()) {
-            return dir.getId();
+            return dir.getCode();
         }
-        if ("/".equals(File.separator)) {
+        if (StaticData.SLASH.equals(File.separator)) {
             filePath = filePath.replace("/", "\\");
         }
 
+        fileName = fileName.toLowerCase();
+        filePath = filePath.toLowerCase();
         for (DirEntity entity : dirs) {
-            if (filePath.contains(entity.getFullName() + "\\" + fileName)) {
-                return entity.getId();
+            if (filePath.contains(entity.getFullName().toLowerCase() + "\\" + fileName)) {
+                return entity.getCode();
             }
         }
 
-        return dir.getId();
+        return dir.getCode();
     }
 
     /**
      * 鑾峰彇SHP鏂囦欢闆嗗悎
      */
-    private  List<String> getShpFiles(String shpPath) {
+    private List<String> getShpFiles(String shpPath) {
         List<String> list = new ArrayList<>();
         list.add(shpPath);
 
-        for (int i = 1, c = StaticData.SHP_EXTENSION.size(); i < c; i++) {
-            String path = shpPath.replace(".shp", StaticData.SHP_EXTENSION.get(i));
+        for (int i = 0, c = StaticData.SHP_EXT.size(); i < c; i++) {
+            String path = shpPath.replace(".shp", StaticData.SHP_EXT.get(i));
 
             File f = new File(path);
             if (f.exists() && !f.isDirectory()) {
@@ -434,7 +462,7 @@
     /**
      * 鑾峰彇GDB鏂囦欢鏄犲皠
      */
-    private List<MetaFileEntity> getGdbMappers(File f, MetaFileEntity meta, int dirid, int start) {
+    private List<MetaFileEntity> getGdbMappers(File f, MetaFileEntity meta, String dircode, int start) {
         List<String> tabs = GdbHelper.getTabNames(f.getPath());
         if (null == tabs || tabs.size() == 0) {
             return null;
@@ -450,9 +478,9 @@
         List<MetaFileEntity> list = new ArrayList<>();
         for (String tab : tabs) {
             MetaFileEntity mf = createMetaFileEntity(meta);
-            mf.setDirid(dirid);
+            mf.setDircode(dircode);
             mf.setEventid(StringHelper.getGuid());
-            mf.setName(fileName);
+            mf.setName(fileName + "\\" + tab);
             mf.setExtName(extName);
             mf.setSizes(FileHelper.sizeToMb(f.length()));
             mf.setPath(f.getPath().substring(start));
@@ -470,16 +498,9 @@
      */
     private boolean isGdbFile(File f) {
         if (f.isDirectory() && f.getName().toLowerCase().endsWith(StaticData.GDB)) {
-            File[] files = f.listFiles();
-            if (null == files || files.length == 0) {
-                return false;
-            }
+            File gdb = new File(f.getPath() + File.separator + "gdb");
 
-            for (File file : files) {
-                if ("gdb".equals(file.getName())) {
-                    return true;
-                }
-            }
+            return gdb.exists() && !gdb.isDirectory();
         }
 
         return false;
@@ -497,12 +518,62 @@
     }
 
     /**
+     * 澶勭悊鐩綍
+     */
+    public void copePath(List<MetaFileEntity> list) {
+        String basePath = pathHelper.getConfig().getTempPath() + File.separator;
+        for (MetaFileEntity mf : list) {
+            mf.setPath(mf.getPath().replace(basePath, ""));
+        }
+    }
+
+    /**
+     * 鏄�/鍚︿负OSGB鏂囦欢
+     */
+    private boolean isOsgbFile(File f) {
+        if (f.isDirectory()) {
+            File meta = new File(f.getPath() + File.separator + "metadata.xml");
+            File data = new File(f.getPath() + File.separator + "Data");
+
+            return meta.exists() && !meta.isDirectory() && data.exists() && data.isDirectory();
+        }
+
+        return false;
+    }
+
+
+    /**
+     * 鑾峰彇OSGB鏂囦欢鏄犲皠
+     */
+    private MetaFileEntity getOsgbMapper(File f,  MetaFileEntity meta, String dircode, int start) {
+        String fileName = FileHelper.getFileName(f.getPath());
+
+        List<String> files = new ArrayList<>();
+        FileHelper.getFilesByPath(files, f.getPath());
+
+        String md5 = getFilesMd5(files);
+        double sizes = getFilesSize(files);
+
+        MetaFileEntity mf = createMetaFileEntity(meta);
+        mf.setDircode(dircode);
+        mf.setEventid(StringHelper.getGuid());
+        mf.setName(fileName);
+        mf.setExtName(StaticData.OSGB);
+        mf.setSizes(FileHelper.sizeToMb(f.length()));
+        mf.setPath(f.getPath().substring(start));
+        mf.setSizes(sizes);
+        mf.setGuid(md5);
+
+        return mf;
+    }
+
+    /**
      * 鑾峰彇鍙傛暟 *
      * Enumeration<String> headers = req.getHeaderNames();
      * Enumeration<String> attributes = req.getAttributeNames();
      */
     public Map<String, String> getParams(StandardMultipartHttpServletRequest req) {
-        Map<String, String> map = new HashMap<String, String>(3);
+        Map<String, String> map = new HashMap<>(3);
 
         Enumeration<String> enumeration = req.getParameterNames();
         while (enumeration.hasMoreElements()) {

--
Gitblit v1.9.3