From df9b5941f4e4f59f56b3234942f810f83c99b501 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 25 五月 2023 16:33:54 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/data/UploadService.java |  211 +++++++++++++++++++++++++---------------------------
 1 files changed, 101 insertions(+), 110 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 3749d34..2dccb6e 100644
--- a/src/main/java/com/lf/server/service/data/UploadService.java
+++ b/src/main/java/com/lf/server/service/data/UploadService.java
@@ -3,7 +3,6 @@
 import com.lf.server.entity.all.BaseEntity;
 import com.lf.server.entity.all.StaticData;
 import com.lf.server.entity.data.*;
-import com.lf.server.entity.sys.DepEntity;
 import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.*;
 import com.lf.server.mapper.all.BasicMapper;
@@ -23,6 +22,7 @@
 
 /**
  * 鏁版嵁涓婁紶鏈嶅姟绫�
+ *
  * @author WWW
  */
 @Service
@@ -67,11 +67,13 @@
      */
     public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) {
         checkMetaFiles(ue, list);
-        excelLoader(list, req);
+        List<MetaFileEntity> xlsList = getExcelFiles(list);
         loadData(list);
         copyFiles(list);
-        publishFiles(list);
         insertMetas(list);
+        if (xlsList.size() > 0) {
+            String guid = excelLoader(xlsList, req);
+        }
     }
 
     /**
@@ -95,29 +97,9 @@
 
             MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
             if (null != old) {
-                mf.setMsg("宸插叆搴�");
+                mf.setMsg("宸插瓨鍦�");
             }
         }
-    }
-
-    /**
-     * Excel鍏ュ簱
-     */
-    private String excelLoader(List<MetaFileEntity> list, HttpServletRequest req) {
-        List<MetaFileEntity> xlsList = getExcelFiles(list);
-        if (xlsList.isEmpty()) {
-            return "";
-        }
-
-        String guid = null;
-        try {
-            MetaFileEntity meta = getExcelMeta(xlsList);
-            guid = fmeService.excelLoader(meta, req);
-        } catch (Exception ex) {
-            log.error(ex.getMessage(), ex);
-        }
-
-        return guid;
     }
 
     /**
@@ -126,48 +108,29 @@
     private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) {
         List<MetaFileEntity> xlsList = new ArrayList<>();
         for (MetaFileEntity mf : list) {
-            if (null != mf.getMsg()) {
-                continue;
-            }
-            if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) {
+            if (null == mf.getMsg() && isExcel(mf)) {
                 xlsList.add(mf);
             }
+        }
+        if (xlsList.isEmpty()) {
+            return xlsList;
+        }
+
+        String xlsBasePath = getXlsPath(xlsList.get(0).getPath());
+        for (int i = 0, c = xlsList.size(); i < c; i++) {
+            MetaFileEntity mf = xlsList.get(i);
+            String xlsPath = copyXlsFile(xlsBasePath, i, mf);
+            mf.setXlsPath(xlsPath);
         }
 
         return xlsList;
     }
 
     /**
-     * 鑾峰彇Excel鐨勫厓鏁版嵁
+     * 鏄�/鍚︿负Excel
      */
-    private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) {
-        List<String> pathList = new ArrayList<>();
-        List<String> dirList = new ArrayList<>();
-        List<String> pidList = new ArrayList<>();
-
-        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.getDircode());
-                pidList.add(mf.getEventid());
-            }
-        }
-
-        MetaFileEntity first = xlsList.get(0);
-        MetaFileEntity meta = new MetaFileEntity();
-        meta.setPath(StringHelper.join(pathList, ","));
-        meta.setEpsgCode(first.getEpsgCode());
-        meta.setName(StringHelper.join(dirList, ";"));
-        meta.setDepcode(first.getDepcode());
-        meta.setVerid(first.getVerid());
-        meta.setCreateUser(first.getCreateUser());
-        meta.setEventid(StringHelper.join(pidList, ";"));
-
-        return meta;
+    private boolean isExcel(MetaFileEntity mf) {
+        return StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName());
     }
 
     /**
@@ -226,7 +189,7 @@
     /**
      * 鍔犺浇绌洪棿鏁版嵁
      */
-    private void loadSpatialData(MetaFileEntity mf) {
+    public void loadSpatialData(MetaFileEntity mf) {
         BasicMapper basicMapper = ClassHelper.getBasicMapper(mf.getEntity());
         if (null == basicMapper) {
             return;
@@ -247,7 +210,7 @@
 
         MetaEntity old = metaService.selectByGuid(mf.getGuid(), tabName);
         if (null != old) {
-            mf.setMsg("宸插叆搴�");
+            mf.setMsg("宸插瓨鍦�");
             return;
         }
 
@@ -308,6 +271,9 @@
                 case StaticData.MPT:
                     copyMultiFile(mf, StaticData.MPT_EXT);
                     break;
+                case StaticData.JPG:
+                    copyMultiFile(mf, StaticData.JPG_EXT);
+                    break;
                 case StaticData.IMG:
                     copyMultiFile(mf, StaticData.IMG_EXT);
                     break;
@@ -351,7 +317,7 @@
 
         MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
         if (null != old) {
-            mf.setMsg("宸插叆搴�");
+            mf.setMsg("宸插瓨鍦�");
             file.delete();
             return 0;
         }
@@ -420,7 +386,7 @@
 
         MetaEntity old = metaService.selectByGuid(mf.getGuid(), null);
         if (null != old) {
-            mf.setMsg("宸插叆搴�");
+            mf.setMsg("宸插瓨鍦�");
             FileHelper.deleteFiles(file);
             return;
         }
@@ -463,53 +429,6 @@
     }
 
     /**
-     * 鍙戝竷鏂囦欢
-     */
-    private void publishFiles(List<MetaFileEntity> list) {
-        for (MetaFileEntity mf : list) {
-            if (null != mf.getMsg()) {
-                continue;
-            }
-            switch (mf.getExtName()) {
-                case StaticData.MPT:
-                    linkFiles(mf, StaticData.MPT_EXT, pathHelper.getConfig().getPublishMptPath());
-                    break;
-                case StaticData.D3DML:
-                    linkFiles(mf, null, pathHelper.getConfig().getPublish3dmlPath());
-                    break;
-                default:
-                    break;
-            }
-        }
-    }
-
-    /**
-     * 閾炬帴鏂囦欢
-     */
-    private void linkFiles(MetaFileEntity mf, List<String> exts, String publishPath) {
-        String uploadPath = pathHelper.getConfig().getUploadPath();
-        String source = uploadPath + File.separator + mf.getPath();
-        String target = publishPath + File.separator + mf.getName();
-
-        File sourceFile = new File(source);
-        if (!sourceFile.exists() || sourceFile.isDirectory()) {
-            return;
-        }
-
-        createFileLink(source, target);
-        if (null == exts) {
-            return;
-        }
-
-        for (String ext : exts) {
-            File f=new File(source.replace(mf.getExtName(), ext));
-            if (f.exists()&&!f.isDirectory()) {
-                createFileLink(source.replace(mf.getExtName(), ext), target.replace(mf.getExtName(), ext));
-            }
-        }
-    }
-
-    /**
      * 鍒涘缓鏂囦欢閾炬帴
      */
     private void createFileLink(String source, String target) {
@@ -521,12 +440,13 @@
      * 鎻掑叆鍏冩暟鎹�
      */
     private void insertMetas(List<MetaFileEntity> list) {
+        int metaId = insertParentMeta(list);
         for (MetaFileEntity mf : list) {
             if (null != mf.getMsg()) {
                 continue;
             }
 
-            MetaEntity me = createMeta(mf);
+            MetaEntity me = createMeta(mf, metaId);
             metaService.insert(me);
 
             mf.setMsg(me.getId() > 0 ? "鎴愬姛" : "澶辫触");
@@ -536,8 +456,9 @@
     /**
      * 鍒涘缓鍏冩暟鎹�
      */
-    private MetaEntity createMeta(MetaFileEntity mf) {
+    private MetaEntity createMeta(MetaFileEntity mf, int metaId) {
         MetaEntity me = new MetaEntity();
+        me.setMetaid(metaId);
         me.setEventid(mf.getEventid());
         me.setDircode(mf.getDircode());
         me.setDepcode(mf.getDepcode());
@@ -559,4 +480,74 @@
 
         return me;
     }
+
+    /**
+     * 鎻掑叆鐖跺厓鏁版嵁
+     */
+    private int insertParentMeta(List<MetaFileEntity> list) {
+        for (MetaFileEntity mf : list) {
+            if (null != mf.getMsg() || !mf.getIsMeta()) {
+                continue;
+            }
+
+            MetaEntity me = createMeta(mf, 0);
+            me.setIsmeta((short) 1);
+            metaService.insert(me);
+            mf.setMsg(me.getId() > 0 ? "鎴愬姛" : "澶辫触");
+
+            return me.getId();
+        }
+
+        return 0;
+    }
+
+    /**
+     * Excel鍏ュ簱
+     */
+    private String excelLoader(List<MetaFileEntity> xlsList, HttpServletRequest req) {
+        try {
+            MetaFileEntity xlsMeta = getExcelMeta(xlsList);
+            if (null != xlsMeta) {
+                return fmeService.excelLoader(xlsMeta, req);
+            }
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+        }
+
+        return null;
+    }
+
+    /**
+     * 鑾峰彇Excel鐨勫厓鏁版嵁
+     */
+    private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) {
+        if (null == xlsList || xlsList.isEmpty()) {
+            return null;
+        }
+
+        List<String> pathList = new ArrayList<>();
+        List<String> dirList = new ArrayList<>();
+        List<String> pidList = new ArrayList<>();
+
+        for (int i = 0, c = xlsList.size(); i < c; i++) {
+            MetaFileEntity mf = xlsList.get(i);
+            if ("鎴愬姛".equals(mf.getMsg()) && null != mf.getXlsPath()) {
+                pathList.add(mf.getXlsPath());
+                dirList.add(mf.getDircode());
+                pidList.add(mf.getEventid());
+            }
+        }
+
+        MetaFileEntity first = xlsList.get(0);
+        MetaFileEntity meta = new MetaFileEntity();
+        meta.setPath(StringHelper.join(pathList, ","));
+        meta.setEpsgCode(first.getEpsgCode());
+        meta.setName(StringHelper.join(dirList, ";"));
+        meta.setDepcode(first.getDepcode());
+        meta.setVerid(first.getVerid());
+        meta.setCreateUser(first.getCreateUser());
+        meta.setEventid(StringHelper.join(pidList, ";"));
+
+        return meta;
+    }
 }

--
Gitblit v1.9.3