From 7f65bcb71ae47abbf563f79ce83c7d580af89b3c Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 27 三月 2023 11:10:40 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/show/DataLibService.java | 196 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 154 insertions(+), 42 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 39a578b..5bda047 100644 --- a/src/main/java/com/lf/server/service/show/DataLibService.java +++ b/src/main/java/com/lf/server/service/show/DataLibService.java @@ -1,7 +1,10 @@ package com.lf.server.service.show; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.lf.server.entity.all.BaseEntity; +import com.lf.server.entity.ctrl.DownloadReqEntity; import com.lf.server.entity.data.DownloadEntity; +import com.lf.server.entity.sys.AttachEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.*; import com.lf.server.mapper.all.BasicMapper; @@ -42,11 +45,22 @@ /** * 鏌ヨDB涓孩鍑虹殑鍗曚綅缂栫爜 */ - public List<String> selectDbOverflowDep(UserEntity ue, List<String> entities, String wkt) { + public List<String> selectDbOverflowDep(UserEntity ue, DownloadReqEntity dr) { + if (StringHelper.isEmpty(dr.getWkt())) { + return selectDbOverflowDep4Wkt(ue, dr.getEntities(), dr.getWkt()); + } + + return selectDbOverflowDep4Prop(ue, dr.getEntities().get(0), dr.getIds(), dr.getFilter()); + } + + /** + * 鏌ヨDB涓孩鍑虹殑鍗曚綅缂栫爜-绌洪棿鏌ヨ + */ + public List<String> selectDbOverflowDep4Wkt(UserEntity ue, List<String> entities, String wkt) { List<String> rs = new ArrayList<>(); - for (String enity : entities) { + for (String entity : entities) { try { - GeomBaseMapper<?> baseMapper = ClassHelper.getGeoBaseMapper(enity); + GeomBaseMapper<?> baseMapper = ClassHelper.getGeoBaseMapper(entity); if (null == baseMapper) { continue; } @@ -63,11 +77,38 @@ } List<String> ids = baseMapper.selectObjs(wrapper); - addDepCodes(rs, ids); } catch (Exception ex) { log.error(ex.getMessage(), ex); } + } + + return rs; + } + + /** + * 鏌ヨDB涓孩鍑虹殑鍗曚綅缂栫爜-灞炴�ф煡璇� + */ + public List<String> selectDbOverflowDep4Prop(UserEntity ue, String entity, List<Integer> gids, String filter) { + List<String> rs = new ArrayList<>(); + try { + BasicMapper<?> baseMapper = ClassHelper.getBasicMapper(entity); + if (null == baseMapper) { + return rs; + } + + QueryWrapper wrapper = new QueryWrapper(); + wrapper.select("depid"); + baseQueryService.addFilterWrapper(wrapper, filter); + if (null != gids && gids.size() > 0) { + wrapper.apply(String.format("gid in (%s)", StringHelper.join(gids, ","))); + } + wrapper.groupBy("depid"); + + List<String> ids = baseMapper.selectObjs(wrapper); + addDepCodes(rs, ids); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); } return rs; @@ -89,10 +130,22 @@ } /** - * 鍒涘缓Zip鍖� + * 璇锋眰DB鏁版嵁涓嬭浇 */ - public String createZipFile(UserEntity ue, List<String> entities, String depcode, String dirs, String wkt, String pwd) throws Exception { - Map<String, List<?>> map = queryData(entities, depcode, dirs, wkt); + public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) throws Exception { + if (StringHelper.isEmpty(dr.getWkt())) { + return downloadDbReq4Wkt(ue, dr); + } + + return downloadDbReq4Prop(ue, dr); + } + + /** + * 璇锋眰DB鏁版嵁涓嬭浇-绌洪棿鏌ヨ + */ + public String downloadDbReq4Wkt(UserEntity ue, DownloadReqEntity dr) throws Exception { + String depcode = null == dr.getDepcodes() || dr.getDepcodes().isEmpty() ? null : dr.getDepcodes().get(0); + Map<String, List<?>> map = queryData(dr.getEntities(), depcode, dr.getDirs(), dr.getWkt()); if (map.size() == 0) { return null; } @@ -111,11 +164,11 @@ String zipName = tempName + ".gdb.zip"; String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName; - ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); - ZipParameters params = Zip4jHelper.getZipParams(); + ZipFile zip = Zip4jHelper.createZipFile(zipFile, dr.getPwd()); + ZipParameters params = Zip4jHelper.getZipParams(true); addZipFiles(zip, params, file.listFiles()); - String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); + String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); int rows = downloadMapper.insert(downloadEntity); @@ -177,26 +230,9 @@ } /** - * 娣诲姞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 DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception { + private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { DownloadEntity de = new DownloadEntity(); de.setName(FileHelper.getFileName(file)); // 1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁锛�5-绠¢亾鍒嗘瀽锛�6-缁熻鎶ュ憡 @@ -215,16 +251,20 @@ } /** - * 鎵撳寘DB鏁版嵁 + * 璇锋眰DB鏁版嵁涓嬭浇-灞炴�ф煡璇� */ - public String zipDbData(UserEntity ue, String name, String depcode, String dirs, String filter, String pwd) throws Exception { - BasicMapper baseMapper = ClassHelper.getBasicMapper(name); + public String downloadDbReq4Prop(UserEntity ue, DownloadReqEntity dr) throws Exception { + String dirs = dr.getDirs(); + String entity = dr.getEntities().get(0); + String depcode = null == dr.getDepcodes() || dr.getDepcodes().isEmpty() ? null : dr.getDepcodes().get(0); + + BasicMapper baseMapper = ClassHelper.getBasicMapper(entity); if (baseMapper == null) { return null; } QueryWrapper wrapper = new QueryWrapper(); - baseQueryService.addFilterWrapper(wrapper, filter); + baseQueryService.addFilterWrapper(wrapper, dr.getFilter()); if (baseMapper instanceof GeomBaseMapper) { wrapper.select("ST_AsText(geom) as geom, *"); } @@ -242,32 +282,45 @@ return null; } - Map<String, List<?>> map = new HashMap<>(1); - map.put(name, list); + String tab = BaseQueryService.getTabName(baseMapper); + String ids = getAnnexFilter(StringHelper.isEmpty(depcode) && StringHelper.isEmpty(dirs) && StringHelper.isEmpty(dr.getFilter()), list); + List<AttachEntity> annex = baseQueryService.selectAnnexByTab(tab, ids); - return zipData(ue, map, pwd); + Map<String, List<?>> map = new HashMap<>(1); + map.put(entity, list); + + return zipData(ue, map, annex, dr.getPwd()); } /** * 鎵撳寘鏁版嵁 */ - private String zipData(UserEntity ue, Map<String, List<?>> map, String pwd) throws Exception { + 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 filePath = tempPath + File.separator + tempName + ".gdb"; + String gdbPath = tempPath + File.separator + tempName + ".gdb"; + String annexPath = tempPath + File.separator + "annex"; - File file = new File(filePath); + File file = new File(gdbPath); if (file.exists() && file.isDirectory()) { - FileHelper.deleteDir(filePath); + FileHelper.deleteDir(gdbPath); } - GdbHelper.createGdb(filePath, map); + 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(); - addZipFiles(zip, params, file.listFiles()); + 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); @@ -343,4 +396,63 @@ 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