From 8cdd6aa032dd72c5101099b7e8f156394e90b83c Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 30 一月 2023 16:15:41 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/data/UploadService.java |  106 ++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 84 insertions(+), 22 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 472fdc0..09c4b08 100644
--- a/src/main/java/com/lf/server/service/data/UploadService.java
+++ b/src/main/java/com/lf/server/service/data/UploadService.java
@@ -9,6 +9,7 @@
 import com.lf.server.mapper.data.UploadMapper;
 import com.lf.server.service.all.BaseQueryService;
 import com.lf.server.service.all.BaseUploadService;
+import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -124,7 +125,15 @@
             return;
         }
 
-        List<?> list = null;
+        MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName);
+        if (old != null) {
+            mf.setEntity(old.getLayer());
+            mf.setTab(old.getTab());
+            mf.setRows(old.getRows());
+            return;
+        }
+
+        List<?> list;
         if (StaticData.SHP.equals(mf.getExtName())) {
             list = ShpHelper.readData(clazz, mf.getPath());
         } else {
@@ -137,6 +146,7 @@
 
         int rows = basicMapper.insertBatch(list);
         if (rows > 0) {
+            mf.setEntity(mf.getTab());
             mf.setTab(tabName);
             mf.setRows(rows);
         }
@@ -193,8 +203,8 @@
                         String path = findPathByGuid(list, mf);
                         if (null != path) {
                             mf.setPath(path);
+                            continue;
                         }
-                        continue;
                     }
 
                     gdbList.add(mf.getPath());
@@ -217,26 +227,28 @@
             return -1;
         }
 
-        MetaEntity old = metaService.selectByGuid(mf.getGuid());
+        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
         if (null != old) {
-            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            mf.setPath(old.getPath());
+            mf.setTab(old.getTab());
+            mf.setEntity(old.getLayer());
+            mf.setRows(old.getRows());
             file.delete();
             return 0;
         }
 
         String uploadPath = pathHelper.getUploadFullPath();
         String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName();
+        String subPath = FileHelper.getRelativePath(targetPath);
 
         File newFile = new File(targetPath);
         if (newFile.exists()) {
-            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            mf.setPath(subPath);
             file.delete();
             return 0;
         }
 
         file.renameTo(newFile);
-
-        String subPath = FileHelper.getRelativePath(targetPath);
         mf.setPath(subPath);
 
         return 1;
@@ -288,19 +300,20 @@
             return;
         }
 
-        MetaEntity old = metaService.selectByGuid(mf.getGuid());
+        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
         if (null != old) {
-            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            mf.setPath(old.getPath());
             FileHelper.deleteFiles(file);
             return;
         }
 
         String uploadPath = pathHelper.getUploadFullPath();
         String targetPath = uploadPath + File.separator + mf.getGuid() + mf.getExtName();
+        String subPath = FileHelper.getRelativePath(targetPath);
 
         File newFile = new File(targetPath);
         if (newFile.exists() && newFile.isDirectory()) {
-            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            mf.setPath(subPath);
             FileHelper.deleteFiles(file);
             return;
         }
@@ -312,11 +325,9 @@
         }
 
         for (File f : files) {
-            String subPath = targetPath + File.separator + FileHelper.getFileName(f.getPath());
-            f.renameTo(new File(subPath));
+            String subFile = targetPath + File.separator + FileHelper.getFileName(f.getPath());
+            f.renameTo(new File(subFile));
         }
-
-        String subPath = FileHelper.getRelativePath(targetPath);
         mf.setPath(subPath);
     }
 
@@ -325,7 +336,7 @@
      */
     private String findPathByGuid(List<MetaFileEntity> list, MetaFileEntity mf) {
         for (MetaFileEntity meta : list) {
-            if (meta.getGuid().equals(mf.getGuid())) {
+            if (meta.getGuid().equals(mf.getGuid()) && !meta.getPath().equals(mf.getPath())) {
                 return meta.getPath();
             }
         }
@@ -369,6 +380,9 @@
         if (mf.getRows() > 0) {
             me.setTab(mf.getTab());
         }
+        if (!StringHelper.isEmpty(mf.getEntity())) {
+            me.setLayer(mf.getEntity());
+        }
         me.setRows(mf.getRows());
         me.setCreateUser(mf.getCreateUser());
         me.setCreateTime(mf.getCreateTime());
@@ -404,7 +418,10 @@
         for (MetaFileEntity mf : list) {
             boolean isXls = StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName());
             if (mf.getRows() > -1 && isXls) {
-                xlsList.add(mf);
+                MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
+                if (null == old) {
+                    xlsList.add(mf);
+                }
             }
         }
 
@@ -419,21 +436,66 @@
         List<String> dirList = new ArrayList<>();
         List<String> pidList = new ArrayList<>();
 
-        for (MetaFileEntity mf : xlsList) {
-            pathList.add(mf.getPath());
-            dirList.add(mf.getDirid() + "");
-            pidList.add(mf.getEventid());
+        String xlsBasePath = getXlsPath(xlsList.get(0).getPath());
+        for (int i = 0, c = xlsList.size(); i < c; i++) {
+            MetaFileEntity mf = xlsList.get(i);
+
+            String path = copyXlsFile(xlsBasePath, i, mf);
+            if (null != path) {
+                pathList.add(path);
+                dirList.add(mf.getDirid() + "");
+                pidList.add(mf.getEventid());
+            }
         }
 
         MetaFileEntity meta = new MetaFileEntity();
         meta.setPath(StringHelper.join(pathList, ","));
         meta.setEpsgCode(xlsList.get(0).getEpsgCode());
-        meta.setName(StringHelper.join(dirList, ","));
+        meta.setName(StringHelper.join(dirList, ";"));
         meta.setDepid(xlsList.get(0).getDepid());
         meta.setVerid(xlsList.get(0).getVerid());
         meta.setCreateUser(xlsList.get(0).getCreateUser());
-        meta.setEventid(StringHelper.join(pidList, ","));
+        meta.setEventid(StringHelper.join(pidList, ";"));
 
         return meta;
     }
+
+    /**
+     * 鑾峰彇Xls鐩綍
+     */
+    private String getXlsPath(String filePath) {
+        String tempPath = pathHelper.getConfig().getTempPath() + File.separator;
+        String subPath = filePath.substring(tempPath.length());
+        subPath = tempPath + subPath.substring(0, subPath.indexOf(File.separator)).replace("_zip", "") + "_xls";
+
+        File f = new File(subPath);
+        if (!f.exists() || !f.isDirectory()) {
+            f.mkdirs();
+        }
+
+        return subPath;
+    }
+
+    /**
+     * 澶嶅埗Xls鏂囦欢
+     */
+    private String copyXlsFile(String xlsBasePath, int i, MetaFileEntity mf) {
+        try {
+            String xlsPath = xlsBasePath + File.separator + i;
+
+            File file = new File(xlsPath);
+            if (!file.exists() || !file.isDirectory()) {
+                file.mkdirs();
+            }
+            file = new File(mf.getPath());
+
+            File newFile = new File(xlsPath + File.separator + FileHelper.getFileName(file.getPath()));
+            FileUtils.copyFile(file, newFile);
+
+            return newFile.getPath();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
 }

--
Gitblit v1.9.3