From 1ef1e36cda961e1c348b22049932b05cd21d397e Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 11 一月 2023 15:58:52 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/data/UploadService.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 106 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/lf/server/service/data/UploadService.java b/src/main/java/com/lf/server/service/data/UploadService.java
index 4b6806d..874160e 100644
--- a/src/main/java/com/lf/server/service/data/UploadService.java
+++ b/src/main/java/com/lf/server/service/data/UploadService.java
@@ -2,10 +2,7 @@
 
 import com.lf.server.entity.all.BaseEntity;
 import com.lf.server.entity.all.StaticData;
-import com.lf.server.entity.data.CoordEntity;
-import com.lf.server.entity.data.DirEntity;
-import com.lf.server.entity.data.FmeLogEntity;
-import com.lf.server.entity.data.MetaFileEntity;
+import com.lf.server.entity.data.*;
 import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.*;
 import com.lf.server.mapper.all.BasicMapper;
@@ -32,6 +29,9 @@
 
     @Autowired
     FmeService fmeService;
+
+    @Autowired
+    MetaService metaService;
 
     @Override
     public List<CoordEntity> selectCoords(String zoning) {
@@ -77,8 +77,8 @@
 
             File f = new File(mf.getPath());
             if (!f.exists()) {
+                mf.setMsg("鏂囦欢涓㈠け");
                 mf.setRows(-1);
-                mf.setMsg("鏂囦欢涓嶅瓨鍦�");
             }
         }
     }
@@ -165,6 +165,7 @@
      * 澶嶅埗鏂囦欢
      */
     private void copyFiles(List<MetaFileEntity> list) {
+        List<String> gdbList = new ArrayList<>();
         for (MetaFileEntity mf : list) {
             switch (mf.getExtName()) {
                 case StaticData.MPT:
@@ -183,6 +184,15 @@
                     copyMultiFile(mf, StaticData.SHP_EXT);
                     break;
                 case StaticData.GDB:
+                    if (gdbList.contains(mf.getPath())) {
+                        MetaEntity meta = metaService.selectByGuid(mf.getGuid());
+                        if (null != meta) {
+                            mf.setPath(meta.getPath());
+                        }
+                        continue;
+                    }
+
+                    gdbList.add(mf.getPath());
                     copyFolderFile(mf);
                     break;
                 default:
@@ -195,28 +205,116 @@
     /**
      * 澶嶅埗鍗曚釜鏂囦欢
      */
-    private void copySingleFile(MetaFileEntity mf) {
+    private int copySingleFile(MetaFileEntity mf) {
+        File file = new File(mf.getPath());
+        if (!file.exists()) {
+            mf.setMsg("鏂囦欢涓㈠け");
+            return -1;
+        }
 
+        MetaEntity old = metaService.selectByGuid(mf.getGuid());
+        if (null != old) {
+            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            file.delete();
+            return 0;
+        }
+
+        String uploadPath = pathHelper.getUploadFullPath();
+        String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName();
+
+        File newFile = new File(targetPath);
+        if (newFile.exists()) {
+            file.delete();
+            return 0;
+        }
+
+        file.renameTo(newFile);
+
+        String subPath = FileHelper.getRelativePath(targetPath);
+        mf.setPath(subPath);
+
+        return 1;
     }
 
     /**
      * 澶嶅埗澶氫釜鏂囦欢
      */
     private void copyMultiFile(MetaFileEntity mf, List<String> extList) {
+        String path = mf.getPath();
 
+        int status = copySingleFile(mf);
+        if (status < 1) {
+            for (int i = 0, c = extList.size(); i < c; i++) {
+                String subPath = path.replace(mf.getExtName(), extList.get(i));
+                File file = new File(subPath);
+                if (file.exists()) {
+                    file.delete();
+                }
+            }
+            return;
+        }
+
+        String uploadPath = pathHelper.getConfig().getUploadPath();
+        for (int i = 0, c = extList.size(); i < c; i++) {
+            String sourcePath = path.replace(mf.getExtName(), extList.get(i));
+            File file = new File(sourcePath);
+            if (!file.exists()) {
+                continue;
+            }
+
+            String targetPath = uploadPath + File.separator + mf.getPath().replace(mf.getExtName(), extList.get(i));
+            File newFile = new File(targetPath);
+            if (newFile.exists()) {
+                continue;
+            }
+
+            file.renameTo(newFile);
+        }
     }
 
     /**
      * 澶嶅埗鏂囦欢澶规枃浠�
      */
     private void copyFolderFile(MetaFileEntity mf) {
+        File file = new File(mf.getPath());
+        if (!file.exists()) {
+            mf.setMsg("鏂囦欢涓㈠け");
+            return;
+        }
 
+        MetaEntity old = metaService.selectByGuid(mf.getGuid());
+        if (null != old) {
+            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            FileHelper.deleteFiles(file);
+            return;
+        }
+
+        String uploadPath = pathHelper.getUploadFullPath();
+        String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName();
+
+        File newFile = new File(targetPath);
+        if (newFile.exists() && newFile.isDirectory()) {
+            FileHelper.deleteFiles(file);
+            return;
+        }
+
+        newFile.mkdirs();
+        File[] files = file.listFiles();
+        if (null == files || files.length == 0) {
+            return;
+        }
+
+        for (File f : files) {
+            String subPath = targetPath + File.separator + FileHelper.getFileName(f.getPath());
+            f.renameTo(new File(subPath));
+        }
+
+        String subPath = FileHelper.getRelativePath(targetPath);
+        mf.setPath(subPath);
     }
 
     /**
      * 鎻掑叆鍏冩暟鎹�
-     *
-     * @param list
      */
     private void insertMetas(List<MetaFileEntity> list) {
         for (MetaFileEntity mf : list) {

--
Gitblit v1.9.3