From 984544e4a3c21a367699e717a60402a9910ae7d9 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 30 三月 2023 13:58:02 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/show/DataLibService.java | 153 ++++++++++++++++---------------------------------- 1 files changed, 50 insertions(+), 103 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 42e4b3e..e5cda4e 100644 --- a/src/main/java/com/lf/server/service/show/DataLibService.java +++ b/src/main/java/com/lf/server/service/show/DataLibService.java @@ -144,7 +144,6 @@ public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) throws Exception { Map<String, List<?>> dataMap = new HashMap<>(2); Map<String, List<AttachEntity>> annexMap = new HashMap<>(2); - queryData(dr, dataMap, annexMap); if (dataMap.size() == 0) { return null; @@ -152,18 +151,26 @@ String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); String tempPath = pathHelper.getTempPath(tempName); - String filePath = tempPath + File.separator + "tabs.gdb"; + String gdbPath = tempPath + File.separator + "tabs.gdb"; + String annexPath = tempPath + File.separator + "annex"; - File file = new File(filePath); - if (file.exists() && file.isDirectory()) { - FileHelper.deleteDir(filePath); + File gdbFile = new File(gdbPath); + if (gdbFile.exists() && gdbFile.isDirectory()) { + FileHelper.deleteDir(gdbPath); } - GdbHelper.createGdb(filePath, dataMap); + 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); - addZipFiles(zip, params, file.listFiles()); + zip.addFolder(new File(gdbPath), params); + zip.addFolder(new File(annexPath), params); String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); @@ -249,6 +256,42 @@ } /** + * 鍒涘缓闄勪欢 + */ + private void createAnnex(String annexPath, Map<String, List<AttachEntity>> annexMap) { + if (annexMap.size() == 0) { + return; + } + + String uploadPath = pathHelper.getConfig().getUploadPath(); + for (String key : annexMap.keySet()) { + String targetPath = annexPath + File.separator + key; + File targetFile = new File(targetPath); + if (!targetFile.exists() || !targetFile.isDirectory()) { + targetFile.mkdirs(); + } + + for (AttachEntity ae : annexMap.get(key)) { + try { + File srcFile = new File(uploadPath + File.separator + ae.getPath()); + if (!srcFile.exists() || srcFile.isDirectory()) { + continue; + } + + File destFile = new File(targetPath + File.separator + ae.getName()); + if (destFile.exists() && !destFile.isDirectory()) { + continue; + } + + FileHelper.copyFile(srcFile, destFile); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + } + } + + /** * 鑾峰彇涓嬭浇瀹炰綋绫� */ private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { @@ -267,43 +310,6 @@ // de.setGeom(null) return de; - } - - /** - * 鎵撳寘鏁版嵁 - */ - private String zipData(UserEntity ue, Map<String, List<?>> map, List<AttachEntity> annex, String pwd) throws Exception { - String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); - String tempPath = pathHelper.getTempPath(tempName); - String gdbPath = tempPath + File.separator + tempName + ".gdb"; - String annexPath = tempPath + File.separator + "annex"; - - File file = new File(gdbPath); - if (file.exists() && file.isDirectory()) { - FileHelper.deleteDir(gdbPath); - } - file = new File(annexPath); - if (!file.exists() || !file.isDirectory()) { - file.mkdirs(); - } - - GdbHelper.createGdb(gdbPath, map); - createAnnex(annexPath, annex); - - String zipName = tempName + ".gdb.zip"; - String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName; - - ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); - ZipParameters params = Zip4jHelper.getZipParams(true); - // addZipFiles(zip, params, file.listFiles()) - zip.addFolder(new File(gdbPath), params); - zip.addFolder(new File(annexPath), params); - - String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); - DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); - int rows = downloadMapper.insert(downloadEntity); - - return rows > 0 ? downloadEntity.getGuid() : null; } /** @@ -371,65 +377,6 @@ for (int i = 0, c = list.size(); i < c; i++) { String str = String.format("%s like '%s%%'", field, list.get(i)); list.set(i, str); - } - } - - /** - * 娣诲姞Zip鏂囦欢 - */ - private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) { - if (null == files || files.length == 0) { - return; - } - - for (File f : files) { - try { - zip.addFile(f, params); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } - } - } - - /** - * 鑾峰彇鏌ヨ闄勪欢鏉′欢 - */ - private String getAnnexFilter(boolean flag, List<?> list) { - if (flag) { - return null; - } - - List<Integer> gids = new ArrayList<>(); - for (Object obj : list) { - BaseEntity be = (BaseEntity) obj; - gids.add(be.getGid()); - } - - return StringHelper.join(gids, ","); - } - - /** - * 娣诲姞闄勪欢鏂囦欢 - */ - private void createAnnex(String targetPath, List<AttachEntity> list) { - if (null == list || list.isEmpty()) { - return; - } - - int i = 1; - String uploadPath = pathHelper.getConfig().getUploadPath(); - for (AttachEntity attach : list) { - try { - File srcFile = new File(uploadPath + File.separator + attach.getPath()); - if (!srcFile.exists() || srcFile.isDirectory()) { - continue; - } - - File destFile = new File(targetPath + File.separator + i++ + "_" + attach.getName()); - FileHelper.copyFile(srcFile, destFile); - } catch (Exception ex) { - log.error(ex.getMessage(), ex); - } } } } -- Gitblit v1.9.3