From 663cfd4e985bcab5df890e335936a2e1655670bc Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 19 十月 2023 08:42:40 +0800 Subject: [PATCH] 解决元数据删除出错 --- src/main/java/com/lf/server/service/show/DataLibService.java | 140 +++++++++++++++++++++++----------------------- 1 files changed, 70 insertions(+), 70 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..cb9c738 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,6 @@ 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; @@ -11,7 +10,7 @@ import com.lf.server.mapper.all.GeomBaseMapper; import com.lf.server.mapper.data.DownloadMapper; import com.lf.server.service.all.BaseQueryService; -import com.lf.server.service.data.DownloadService; +import com.lf.server.service.data.MetaService; import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.model.ZipParameters; import org.apache.commons.logging.Log; @@ -32,10 +31,10 @@ PathHelper pathHelper; @Autowired - DownloadMapper downloadMapper; + MetaService metaService; @Autowired - DownloadService downloadService; + DownloadMapper downloadMapper; @Autowired BaseQueryService baseQueryService; @@ -66,9 +65,7 @@ QueryWrapper wrapper = getWrapper4DbOverflow(ue, dr); Integer srid = baseQueryService.getSrid(baseMapper); - if (null != srid) { - wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", dr.getWkt(), srid)); - } + wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", dr.getWkt(), srid)); List<String> ids = baseMapper.selectObjs(wrapper); addDepCodes(rs, ids); @@ -152,7 +149,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,23 +156,18 @@ } 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) + metaService.addAnnex(zip, params, annexMap); String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); - DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); - int rows = downloadMapper.insert(downloadEntity); + DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd); + int rows = downloadMapper.insert(de); - return rows > 0 ? downloadEntity.getGuid() : null; + return rows > 0 ? de.getGuid() : null; } /** @@ -191,34 +182,7 @@ } QueryWrapper wrapper = createQueryWrapper(baseMapper, dr); - List list = baseMapper.selectList(wrapper); - if (null == list || list.size() == 0) { - continue; - } - - if (!dataMap.containsKey(entity)) { - dataMap.put(entity, list); - } else { - dataMap.get(entity).addAll(list); - } - if ("bborehole".equals(entity)) { - continue; - } - if (wrapper.isEmptyOfWhere()) { - wrapper.apply("1 = 1"); - } - - String tab = BaseQueryService.getTabName(baseMapper); - List<AttachEntity> annex = baseMapper.selectAnnex(tab, wrapper); - if (null == annex || annex.isEmpty()) { - continue; - } - - if (!annexMap.containsKey(entity)) { - annexMap.put(entity, annex); - } else { - annexMap.get(entity).addAll(annex); - } + metaService.addData(entity, baseMapper, wrapper, dataMap, annexMap); } catch (Exception ex) { log.error(ex.getMessage(), ex); } @@ -239,10 +203,10 @@ // wrapper.apply(String.format("depid like '%s'", StringHelper.getRightLike(dr.getDepcode()))) wrapper.likeRight("depid", dr.getDepcode()); } - if (baseMapper instanceof GeomBaseMapper && !StringHelper.isEmpty(dr.getWkt())) { + if (baseMapper instanceof GeomBaseMapper) { wrapper.select("ST_AsText(geom) as geom, *"); - Integer srid = baseQueryService.getSrid((GeomBaseMapper) baseMapper); - if (null != srid) { + if (!StringHelper.isEmpty(dr.getWkt())) { + Integer srid = baseQueryService.getSrid((GeomBaseMapper) baseMapper); wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", dr.getWkt(), srid)); } } @@ -256,7 +220,7 @@ } /** - * 鍒涘缓闄勪欢 + * 鍒涘缓闄勪欢 * */ private void createAnnex(String annexPath, Map<String, List<AttachEntity>> annexMap) { if (annexMap.size() == 0) { @@ -297,7 +261,7 @@ 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-缁熻鎶ュ憡 + // 1-Shp鏂囦欢锛�2-涓撻鍥撅紝3-鍏冩暟鎹紝4-涓氬姟鏁版嵁锛�5-绠¢亾鍒嗘瀽锛�6-缁熻鎶ュ憡锛�7-闄勪欢鏂囦欢锛�8-鐡︾墖鏂囦欢 de.setType(4); de.setSizes(FileHelper.sizeToMb(new File(file).length())); de.setDepid(ue.getDepid()); @@ -321,7 +285,7 @@ } List<String> list = codesAsList(codes); - removeDuplicate(list); + list = copeDirCodes(list); setRightLike(list, field); return "(" + StringHelper.join(list, " or ") + ")"; @@ -341,39 +305,75 @@ } /** - * 鍘婚櫎閲嶅 + * 澶勭悊鐩綍缂栫爜 */ - private static void removeDuplicate(List<String> list) { - int i = 0; - while (i < list.size()) { - int j = findStr(list, i); - if (j > -1) { - list.remove(j); - continue; - } - - i++; + private static List<String> copeDirCodes(List<String> list) { + List<String> prjList = getDirCodesByLen(list, 0, 2); + List<String> appList = getDirCodesByLen(list, 3, 30); + if (prjList.isEmpty() && appList.isEmpty()) { + return list; } + if (prjList.isEmpty()) { + return appList; + } + if (appList.isEmpty()) { + return prjList; + } + + return filterCodes(prjList, appList); } /** - * 鏌ユ壘瀛楃涓� + * 鏍规嵁闀垮害鑾峰彇鍗曚綅缂栫爜 */ - private static int findStr(List<String> list, int i) { - String source = list.get(i); - for (int j = i + 1, c = list.size(); j < c; j++) { - if (list.get(j).startsWith(source)) { - return j; + private static List<String> getDirCodesByLen(List<String> list, int start, int end) { + List<String> rs = new ArrayList<>(); + for (String code : list) { + if (StringHelper.isEmpty(code)) { + continue; + } + + if (code.length() >= start && code.length() <= end) { + rs.add(code); } } - return -1; + return rs; + } + + /** + * 杩囨护椤圭洰缂栫爜 + */ + private static List<String> filterCodes(List<String> prjList, List<String> appList) { + int i = 0; + while (i < appList.size()) { + boolean flag = false; + for (String prj : prjList) { + if (appList.get(i).startsWith(prj)) { + flag = true; + break; + } + } + + if (!flag) { + appList.remove(i); + continue; + } + i++; + } + + return appList; } /** * 璁剧疆 鍙砽ike */ private static void setRightLike(List<String> list, String field) { + if (list.isEmpty()) { + list.add("1 = 2"); + return; + } + 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); -- Gitblit v1.9.3