From adcaf3e378b90c8173958233ca6fa1f162a7b71d Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 30 三月 2023 16:46:58 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/show/DataLibService.java | 44 +++++++++++++++++++++++++++++++++----------- 1 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/lf/server/service/show/DataLibService.java b/src/main/java/com/lf/server/service/show/DataLibService.java index e5cda4e..dc41a8c 100644 --- a/src/main/java/com/lf/server/service/show/DataLibService.java +++ b/src/main/java/com/lf/server/service/show/DataLibService.java @@ -20,6 +20,7 @@ import org.springframework.stereotype.Service; import java.io.File; +import java.io.FileInputStream; import java.util.*; /** @@ -152,7 +153,6 @@ String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); String tempPath = pathHelper.getTempPath(tempName); String gdbPath = tempPath + File.separator + "tabs.gdb"; - String annexPath = tempPath + File.separator + "annex"; File gdbFile = new File(gdbPath); if (gdbFile.exists() && gdbFile.isDirectory()) { @@ -160,17 +160,12 @@ } GdbHelper.createGdb(gdbPath, dataMap); - File annexFile = new File(annexPath); - if (!annexFile.exists() || !annexFile.isDirectory()) { - annexFile.mkdirs(); - } - createAnnex(annexPath, annexMap); - String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".gdb.zip"; ZipFile zip = Zip4jHelper.createZipFile(zipFile, dr.getPwd()); ZipParameters params = Zip4jHelper.getZipParams(true); zip.addFolder(new File(gdbPath), params); - zip.addFolder(new File(annexPath), params); + // zip.addFolder(new File(annexPath), params) + addAnnex(zip, params, annexMap); String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); @@ -215,9 +210,9 @@ } if (!annexMap.containsKey(entity)) { - annexMap.put(entity, annex); + annexMap.put(tab.replace(".", "_"), annex); } else { - annexMap.get(entity).addAll(annex); + annexMap.get(tab.replace(".", "_")).addAll(annex); } } catch (Exception ex) { log.error(ex.getMessage(), ex); @@ -256,7 +251,7 @@ } /** - * 鍒涘缓闄勪欢 + * 鍒涘缓闄勪欢 * */ private void createAnnex(String annexPath, Map<String, List<AttachEntity>> annexMap) { if (annexMap.size() == 0) { @@ -292,6 +287,33 @@ } /** + * 娣诲姞闄勪欢 + */ + private void addAnnex(ZipFile zip, ZipParameters params, Map<String, List<AttachEntity>> annexMap) { + List<String> files = new ArrayList<>(); + String uploadPath = pathHelper.getConfig().getUploadPath(); + for (String key : annexMap.keySet()) { + for (AttachEntity ae : annexMap.get(key)) { + try { + File srcFile = new File(uploadPath + File.separator + ae.getPath()); + if (!srcFile.exists() || srcFile.isDirectory()) { + continue; + } + if (files.contains(srcFile.getPath())) { + continue; + } + + files.add(srcFile.getPath()); + params.setFileNameInZip(key + File.separator + ae.getName()); + zip.addStream(new FileInputStream(srcFile), params); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + } + } + + /** * 鑾峰彇涓嬭浇瀹炰綋绫� */ private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { -- Gitblit v1.9.3