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/data/UploadService.java |   82 +++++++++++++++++++++++++++++++----------
 1 files changed, 62 insertions(+), 20 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 2dccb6e..6d1668b 100644
--- a/src/main/java/com/lf/server/service/data/UploadService.java
+++ b/src/main/java/com/lf/server/service/data/UploadService.java
@@ -1,5 +1,6 @@
 package com.lf.server.service.data;
 
+import com.google.common.collect.Lists;
 import com.lf.server.entity.all.BaseEntity;
 import com.lf.server.entity.all.StaticData;
 import com.lf.server.entity.data.*;
@@ -95,11 +96,22 @@
                 mf.setMsg("鏂囦欢涓㈠け");
             }
 
-            MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
+            MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), null);
             if (null != old) {
                 mf.setMsg("宸插瓨鍦�");
             }
         }
+    }
+
+    /**
+     * 鑾峰彇鐩綍缂栫爜
+     */
+    private String getDirCode(MetaFileEntity mf) {
+        if (StringHelper.isEmpty(mf.getDircode())) {
+            return null;
+        }
+
+        return StringHelper.getRightLike(mf.getDircode().substring(0, 2));
     }
 
     /**
@@ -208,7 +220,7 @@
             return;
         }
 
-        MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName);
+        MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), tabName);
         if (null != old) {
             mf.setMsg("宸插瓨鍦�");
             return;
@@ -216,21 +228,40 @@
 
         List<?> list;
         if (StaticData.SHP.equals(mf.getExtName())) {
-            list = ShpHelper.readData(clazz, mf.getPath());
+            list = ShpHelper.readData(clazz, mf.getPath(), true);
         } else {
-            list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab());
+            list = GdbHelper.readData(clazz, mf.getPath(), mf.getTab(), true);
         }
         if (null == list || list.isEmpty()) {
             return;
         }
+        mf.setRecords(list.size());
         setCreateInfo(list, mf);
 
-        int rows = basicMapper.insertBatch(list);
+        int rows = batchInserts(basicMapper, list);
         if (rows > 0) {
             mf.setEntity(mf.getTab());
             mf.setTab(tabName);
             mf.setRows(rows);
         }
+    }
+
+    /**
+     * 鎵归噺鎻掑叆
+     */
+    private <T> int batchInserts(BasicMapper basicMapper, List<T> list) {
+        int rows = 0;
+        //int count = (int) Math.ceil(list.size() / StaticData.D100)
+        List<List<T>> subLists = Lists.partition(list, StaticData.I50);
+        for (List<T> sub : subLists) {
+            try {
+                rows += basicMapper.insertBatch(sub);
+            } catch (Exception ex) {
+                log.error(ex);
+            }
+        }
+
+        return rows;
     }
 
     /**
@@ -286,6 +317,9 @@
                 case StaticData.SHP:
                     copyMultiFile(mf, StaticData.SHP_EXT);
                     break;
+                case StaticData.OSGB:
+                    copyFolderFile(mf);
+                    break;
                 case StaticData.GDB:
                     if (gdbList.contains(mf.getPath())) {
                         String path = findPathByGuid(list, mf);
@@ -315,9 +349,10 @@
             return -1;
         }
 
-        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
+        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null);
         if (null != old) {
-            mf.setMsg("宸插瓨鍦�");
+            // mf.setMsg("宸插瓨鍦�")
+            setOldMeta(mf, old);
             file.delete();
             return 0;
         }
@@ -337,6 +372,16 @@
         mf.setPath(subPath);
 
         return 1;
+    }
+
+    /**
+     * 璁剧疆鏃у厓鏁版嵁淇℃伅
+     */
+    private void setOldMeta(MetaFileEntity mf, MetaEntity old) {
+        mf.setPath(old.getPath());
+        mf.setTab(old.getTab());
+        mf.setRows(old.getRows());
+        mf.setEntity(old.getEventid());
     }
 
     /**
@@ -384,9 +429,10 @@
             return;
         }
 
-        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
+        MetaEntity old = metaService.selectByGuid(mf.getGuid(), null, null);
         if (null != old) {
-            mf.setMsg("宸插瓨鍦�");
+            // mf.setMsg("宸插瓨鍦�")
+            setOldMeta(mf, old);
             FileHelper.deleteFiles(file);
             return;
         }
@@ -402,15 +448,11 @@
             return;
         }
 
-        newFile.mkdirs();
-        File[] files = file.listFiles();
-        if (null == files || files.length == 0) {
-            return;
-        }
-
-        for (File f : files) {
-            String subFile = targetPath + File.separator + FileHelper.getFileName(f.getPath());
-            f.renameTo(new File(subFile));
+        try {
+            // newFile.mkdirs()
+            FileUtils.moveDirectory(file, newFile);
+        } catch (Exception ex) {
+            log.error(ex);
         }
         mf.setPath(subPath);
     }
@@ -448,8 +490,8 @@
 
             MetaEntity me = createMeta(mf, metaId);
             metaService.insert(me);
-
-            mf.setMsg(me.getId() > 0 ? "鎴愬姛" : "澶辫触");
+            String err = mf.getRows() < mf.getRecords() ? "(" + (mf.getRecords() - mf.getRows()) + " 鏉″け璐�)" : "";
+            mf.setMsg(me.getId() > 0 ? String.format("鎴愬姛%s", err) : "澶辫触");
         }
     }
 

--
Gitblit v1.9.3