| | |
| | | /** |
| | | * 请求DB数据下载 |
| | | */ |
| | | public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) { |
| | | public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) throws Exception { |
| | | Map<String, List<?>> dataMap = new HashMap<>(2); |
| | | Map<String, List<AttachEntity>> annexMap = new HashMap<>(2); |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | return null; |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String tempPath = pathHelper.getTempPath(tempName); |
| | | String filePath = tempPath + File.separator + "tabs.gdb"; |
| | | |
| | | File file = new File(filePath); |
| | | if (file.exists() && file.isDirectory()) { |
| | | FileHelper.deleteDir(filePath); |
| | | } |
| | | GdbHelper.createGdb(filePath, dataMap); |
| | | |
| | | 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()); |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); |
| | | int rows = downloadMapper.insert(downloadEntity); |
| | | |
| | | return rows > 0 ? downloadEntity.getGuid() : null; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 请求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; |
| | | } |
| | | |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String tempPath = pathHelper.getTempPath(tempName); |
| | | // String filePath = "D:\\LF\\temp\\20221219202706\\2022.gdb" |
| | | String filePath = tempPath + File.separator + tempName + ".gdb"; |
| | | |
| | | File file = new File(filePath); |
| | | if (file.exists() && file.isDirectory()) { |
| | | FileHelper.deleteDir(filePath); |
| | | } |
| | | GdbHelper.createGdb(filePath, map); |
| | | |
| | | String zipName = tempName + ".gdb.zip"; |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName; |
| | | |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, dr.getPwd()); |
| | | ZipParameters params = Zip4jHelper.getZipParams(true); |
| | | addZipFiles(zip, params, file.listFiles()); |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); |
| | | int rows = downloadMapper.insert(downloadEntity); |
| | | |
| | | return rows > 0 ? downloadEntity.getGuid() : null; |
| | | } |
| | | |
| | | /** |
| | | * 查询数据 |
| | | */ |
| | | private Map<String, List<?>> queryData(List<String> entities, String depcode, String dirs, String wkt) { |
| | | Map<String, List<?>> map = new HashMap<>(5); |
| | | for (String enity : entities) { |
| | | try { |
| | | GeomBaseMapper<?> baseMapper = ClassHelper.getGeoBaseMapper(enity); |
| | | if (null == baseMapper) { |
| | | continue; |
| | | } |
| | | |
| | | QueryWrapper wrapper = createWrapper(baseMapper, depcode, dirs, wkt); |
| | | List<?> list = baseMapper.selectList(wrapper); |
| | | if (null == list || list.size() == 0) { |
| | | continue; |
| | | } |
| | | |
| | | if (!map.containsKey(enity)) { |
| | | map.put(enity, list); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 创建QueryWrapper |
| | | */ |
| | | private QueryWrapper createWrapper(BasicMapper baseMapper, String depcode, String dirs, String wkt) { |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | if (baseMapper instanceof GeomBaseMapper) { |
| | | wrapper.select("ST_AsText(geom) as geom, *"); |
| | | |
| | | Integer srid = baseQueryService.getSrid((GeomBaseMapper) baseMapper); |
| | | if (null != srid) { |
| | | wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", wkt, srid)); |
| | | } |
| | | } |
| | | if (!StringHelper.isEmpty(depcode)) { |
| | | wrapper.likeRight("depid", depcode); |
| | | } |
| | | |
| | | dirs = DataLibService.copeCodes(dirs, "dirid"); |
| | | if (!StringHelper.isEmpty(dirs)) { |
| | | wrapper.apply(dirs); |
| | | } |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { |
| | |
| | | // de.setGeom(null) |
| | | |
| | | return de; |
| | | } |
| | | |
| | | /** |
| | | * 请求DB数据下载-属性查询 |
| | | */ |
| | | 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, dr.getFilter()); |
| | | if (baseMapper instanceof GeomBaseMapper) { |
| | | wrapper.select("ST_AsText(geom) as geom, *"); |
| | | } |
| | | if (!StringHelper.isEmpty(depcode)) { |
| | | wrapper.likeRight("depid", depcode); |
| | | } |
| | | |
| | | dirs = DataLibService.copeCodes(dirs, "dirid"); |
| | | if (!StringHelper.isEmpty(dirs)) { |
| | | wrapper.apply(dirs); |
| | | } |
| | | |
| | | List<?> list = baseMapper.selectList(wrapper); |
| | | if (null == list || 0 == list.size()) { |
| | | return null; |
| | | } |
| | | |
| | | 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); |
| | | |
| | | Map<String, List<?>> map = new HashMap<>(1); |
| | | map.put(entity, list); |
| | | |
| | | return zipData(ue, map, annex, dr.getPwd()); |
| | | } |
| | | |
| | | /** |