From ed8c7a5effd0d423ce1118b680ecdca6fe732609 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 02 七月 2025 16:43:13 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.11.205:9000/r/P2022036_Service

---
 src/main/java/com/lf/server/service/data/UploadService.java |  192 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 183 insertions(+), 9 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 3efcf9d..336ea2d 100644
--- a/src/main/java/com/lf/server/service/data/UploadService.java
+++ b/src/main/java/com/lf/server/service/data/UploadService.java
@@ -17,6 +17,10 @@
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
+import java.lang.reflect.Field;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.List;
@@ -94,6 +98,9 @@
             File f = new File(mf.getPath());
             if (!f.exists()) {
                 mf.setMsg("鏂囦欢涓㈠け");
+            }
+            if (f.exists() && StringHelper.isNull(mf.getGuid())) {
+                mf.setGuid(FileHelper.getFileMd5(f.getPath()));
             }
 
             MetaEntity old = metaService.selectByGuid(mf.getGuid(), getDirCode(mf), null);
@@ -317,6 +324,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);
@@ -445,15 +455,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);
     }
@@ -484,12 +490,22 @@
      */
     private void insertMetas(List<MetaFileEntity> list) {
         int metaId = insertParentMeta(list);
+
+        List<String> guids = new ArrayList<>();
         for (MetaFileEntity mf : list) {
             if (null != mf.getMsg()) {
                 continue;
             }
 
             MetaEntity me = createMeta(mf, metaId);
+            if (StaticData.NGDB.equals(me.getType())) {
+                if (guids.contains(me.getGuid())) {
+                    me.setIsmeta((short) -1);
+                } else {
+                    guids.add(me.getGuid());
+                }
+            }
+
             metaService.insert(me);
             String err = mf.getRows() < mf.getRecords() ? "(" + (mf.getRecords() - mf.getRows()) + " 鏉″け璐�)" : "";
             mf.setMsg(me.getId() > 0 ? String.format("鎴愬姛%s", err) : "澶辫触");
@@ -593,4 +609,162 @@
 
         return meta;
     }
+
+    /**
+     * 鎻掑叆KML鏂囦欢
+     */
+    public void insertKml(UserEntity ue, List<MetaFileEntity> list) {
+        checkMetaFiles(ue, list);
+        loadKml(list);
+        copyFiles(list);
+        insertMetas(list);
+    }
+
+    /**
+     * 鍔犺浇Kml
+     */
+    private void loadKml(List<MetaFileEntity> list) {
+        for (MetaFileEntity mf : list) {
+            if (null != mf.getMsg() || StringHelper.isEmpty(mf.getEntity()) || !StaticData.KML.equals(mf.getExtName())) {
+                continue;
+            }
+
+            String wkt = readKml(mf.getPath());
+            if (StringHelper.isEmpty(wkt)) {
+                continue;
+            }
+
+            loadKmlData(mf, wkt);
+        }
+    }
+
+    /**
+     * 璇诲彇KML
+     */
+    private String readKml(String path) {
+        try {
+            List<String> list = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8);
+            for (String str : list) {
+                if (!str.contains("<coordinates>")) {
+                    continue;
+                }
+
+                return getWktFromCoordinates(str);
+            }
+
+            return null;
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
+     * 鑾峰彇KWT
+     */
+    private String getWktFromCoordinates(String coords) {
+        String[] strs = coords.replace("\t", "").replace("<coordinates>", "").replace("</coordinates>", "").split(" ");
+        if (strs.length == 0) {
+            return null;
+        }
+
+        // MULTILINESTRING((108.99843373100003 34.736292580000054,108.99818970700005 34.73764945000005,108.99831780400007 34.738880547000065,108.99812184300004 34.739564029000064))
+        StringBuilder sb = new StringBuilder();
+        sb.append("MULTILINESTRING((");
+        for (String str : strs) {
+            if (StringHelper.isEmpty(str)) {
+                continue;
+            }
+
+            String[] vals = str.split(StaticData.COMMA);
+            sb.append(vals[0]).append(" ").append(vals[1]).append(StaticData.COMMA);
+        }
+        sb.deleteCharAt(sb.length() - 1);
+        sb.append("))");
+
+        return sb.toString();
+    }
+
+    /**
+     * 鍔犺浇Kml鏁版嵁
+     */
+    private void loadKmlData(MetaFileEntity mf, String wkt) {
+        BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity());
+        if (null == basicMapper) {
+            return;
+        }
+
+        String tabName = BaseQueryService.getTabName(basicMapper);
+        String className = ClassHelper.getClassName(basicMapper);
+        Class clazz = ClassHelper.getEntityClass(className);
+        if (null == clazz || null == tabName) {
+            return;
+        }
+
+        String stage = getPipeStage(tabName);
+        String name = FileHelper.getName(mf.getPath());
+        List<?> list = createKmlEntity(clazz, wkt, name, mf, stage);
+        if (null == list || list.isEmpty()) {
+            return;
+        }
+        mf.setRecords(list.size());
+        setCreateInfo(list, mf);
+
+        int rows = batchInserts(basicMapper, list);
+        if (rows > 0) {
+            mf.setEntity(mf.getTab());
+            mf.setTab(tabName);
+            mf.setRows(rows);
+        }
+    }
+
+    /**
+     * 鍒涘缓KML瀹炰綋绫�
+     */
+    private <T> List<T> createKmlEntity(Class clazz, String wkt, String name, MetaFileEntity mf, String stage) {
+        try {
+            T t = (T) clazz.newInstance();
+
+            setEntityVal(clazz.getSuperclass(), t, "geom", null == wkt ? "null" : String.format("ST_GeomFromText('%s')", wkt));
+            setEntityVal(clazz, t, "pipename", name);
+            setEntityVal(clazz, t, "projname", name);
+            setEntityVal(clazz, t, "medium", mf.getMedium());
+            setEntityVal(clazz, t, "pipestage", stage);
+
+            List<T> list = new ArrayList<>();
+            list.add(t);
+
+            return list;
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
+     * 璁剧疆瀹炰綋鍊�
+     */
+    private <T> void setEntityVal(Class clazz, T t, String field, String val) throws Exception {
+        Field pField = clazz.getDeclaredField(field);
+        pField.setAccessible(true);
+        pField.set(t, val);
+    }
+
+    /**
+     * 鑾峰彇绠¢亾闃舵
+     */
+    private String getPipeStage(String tab) {
+        switch (tab) {
+            case "si.pl_pipeline_f":
+                return "鍙爺闃舵";
+            case "si.pl_pipeline_b":
+                return "鍒濊闃舵";
+            case "si.pl_pipeline_d":
+                return "鏂藉伐鍥鹃樁娈�";
+            case "si.pl_pipeline_a":
+                return "绔e伐鍥鹃樁娈�";
+            default:
+                return null;
+        }
+    }
 }

--
Gitblit v1.9.3