From f65a05ff45c7117ef08f666428f05223b465fd59 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 04 二月 2023 17:15:53 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/all/UploadAttachService.java | 77 ++++++++++++++++++++++++++++++++++---- 1 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/lf/server/service/all/UploadAttachService.java b/src/main/java/com/lf/server/service/all/UploadAttachService.java index cef6160..c5bdb3e 100644 --- a/src/main/java/com/lf/server/service/all/UploadAttachService.java +++ b/src/main/java/com/lf/server/service/all/UploadAttachService.java @@ -10,10 +10,7 @@ import com.lf.server.entity.data.MetaFileEntity; import com.lf.server.entity.sys.AttachEntity; import com.lf.server.entity.sys.UserEntity; -import com.lf.server.helper.FileHelper; -import com.lf.server.helper.PathHelper; -import com.lf.server.helper.StringHelper; -import com.lf.server.helper.WebHelper; +import com.lf.server.helper.*; import com.lf.server.service.sys.AttachService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -169,17 +166,79 @@ /** * 涓婁紶Excel闄勪欢 */ - public Map<String, Integer> uploadXlsAnnex(List<MetaEntity> ms, List<MetaFileEntity> list) { + public Map<String, Integer> uploadXlsAnnex(List<MetaEntity> ms, List<MetaFileEntity> list, String path) { Map<String, Integer> map = new HashMap<>(3); - for (MetaEntity me:ms) { - - } + List<String> files = getAttachFiles(list, path); return map; } - private void getAttachFiles(List<MetaFileEntity> list){ + /** + * 鑾峰彇闄勪欢鏂囦欢 + */ + private List<String> getAttachFiles(List<MetaFileEntity> list, String path) { + List<String> files = new ArrayList<>(); + for (MetaFileEntity mf : list) { + if (mf.getName().contains(StaticData.ZIP)) { + List<String> subs = getZipFiles(mf, path); + if (null == subs || subs.size() > 0) { + files.addAll(subs); + } + continue; + } + + files.add(mf.getPath()); + } + + return files; + } + + /** + * 鑾峰彇zip涓殑鏂囦欢 + */ + private List<String> getZipFiles(MetaFileEntity mf, String path) { + File file = new File(mf.getPath()); + if (!file.exists() || file.isDirectory()) { + return null; + } + + File zipFolder = new File(pathHelper.getConfig().getTempPath() + File.separator + path + "_zip"); + if (!zipFolder.exists() || !zipFolder.isDirectory()) { + zipFolder.mkdirs(); + } + + String subPath = zipFolder + File.separator + mf.getName().toLowerCase().replace(".zip", ""); + ZipHelper.unzip(mf.getPath(), subPath); + + List<String> files = new ArrayList<>(); + getFilesByPath(files, subPath); + + return files; + } + + /** + * 鏍规嵁璺緞鑾峰彇鏂囦欢 + */ + private void getFilesByPath(List<String> list, String path) { + File file = new File(path); + if (!file.isDirectory()) { + list.add(file.getPath()); + return; + } + + File[] files = file.listFiles(); + if (null == files) { + return; + } + + for (File f : files) { + if (f.isDirectory()) { + getFilesByPath(list, f.getPath()); + } else { + list.add(f.getPath()); + } + } } } -- Gitblit v1.9.3