From c509bd8047cfd582c59bba66d148b236e45d038d Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 12 一月 2023 10:15:15 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/data/UploadService.java |   72 +++++++++++++++++++++++++++++-------
 1 files changed, 58 insertions(+), 14 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..af502c7 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;
 
@@ -219,24 +220,23 @@
 
         MetaEntity old = metaService.selectByGuid(mf.getGuid());
         if (null != old) {
-            mf.setMsg("鏂囦欢宸插瓨鍦�");
+            mf.setPath(old.getPath());
             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;
@@ -290,17 +290,18 @@
 
         MetaEntity old = metaService.selectByGuid(mf.getGuid());
         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 +313,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);
     }
 
@@ -419,10 +418,16 @@
         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();
@@ -436,4 +441,43 @@
 
         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