| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.ctrl.DownloadReqEntity; |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | |
| | | import com.lf.server.entity.sys.MetaDownEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | | import com.lf.server.mapper.data.DownloadMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | | import com.lf.server.service.sys.MetaDownService; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.FileHeader; |
| | |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); |
| | | ZipParameters params = Zip4jHelper.getZipParams(true); |
| | | addMetaFiles(zip, params, list); |
| | | zip.addFolder(new File(gdbPath), params); |
| | | addAnnex(zip, params, annexMap); |
| | | if (dataMap.size() > 0) { |
| | | zip.addFolder(new File(gdbPath), params); |
| | | addAnnex(zip, params, annexMap); |
| | | } |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); |
| | | DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd); |
| | |
| | | * 查询数据 |
| | | */ |
| | | private void queryData(Map<String, List<String>> tabs, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) { |
| | | // |
| | | for (String tab : tabs.keySet()) { |
| | | try { |
| | | String entity = tab.toLowerCase().replace("_", "").split("\\.")[1]; |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(entity); |
| | | if (null == baseMapper) { |
| | | continue; |
| | | } |
| | | |
| | | QueryWrapper wrapper = createQueryWrapper(baseMapper, tabs.get(tab)); |
| | | addData(entity, baseMapper, wrapper, dataMap, annexMap); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加数据 |
| | | */ |
| | | public void addData(String entity, BasicMapper baseMapper, QueryWrapper wrapper, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) { |
| | | List list = baseMapper.selectList(wrapper); |
| | | if (null == list || list.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | if (!dataMap.containsKey(entity)) { |
| | | dataMap.put(entity, list); |
| | | } else { |
| | | dataMap.get(entity).addAll(list); |
| | | } |
| | | if (wrapper.isEmptyOfWhere()) { |
| | | wrapper.apply("1 = 1"); |
| | | } |
| | | if (StaticData.BBOREHOLE.equals(entity)) { |
| | | wrapper.last("limit 100"); |
| | | } |
| | | |
| | | String tab = BaseQueryService.getTabName(baseMapper); |
| | | List<AttachEntity> annex = baseMapper.selectAnnex(tab, wrapper); |
| | | if (null == annex || annex.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | if (!annexMap.containsKey(entity)) { |
| | | annexMap.put(tab.replace(StaticData.POINT, "_"), annex); |
| | | } else { |
| | | annexMap.get(tab.replace(StaticData.POINT, "_")).addAll(annex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建查询包装器 |
| | | */ |
| | | private <T> QueryWrapper<T> createQueryWrapper(BasicMapper baseMapper, List<String> ids) { |
| | | for (int i = 0, c = ids.size(); i < c; i++) { |
| | | ids.set(i, "'" + ids.get(i) + "'"); |
| | | } |
| | | String filter = String.format("parentid in (%s)", StringHelper.join(ids, ",")); |
| | | |
| | | QueryWrapper<T> wrapper = new QueryWrapper<T>(); |
| | | wrapper.apply(filter); |
| | | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | private void addSingleFile(String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { |
| | | File file = new File(uploadPath + File.separator + mf.getPath()); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | return; |
| | | } |
| | | zip.addFile(file, params); |
| | | |
| | | String fileName = FileHelper.getFileName(file.getPath()); |
| | |
| | | |
| | | metaDownService.inserts(list); |
| | | } |
| | | |
| | | /** |
| | | * 查询元数据中溢出的单位ID |
| | | */ |
| | | public List<String> selectMetaOverflowDep(UserEntity ue, DownloadReqEntity dr) { |
| | | List<String> rs = new ArrayList<>(); |
| | | |
| | | return rs; |
| | | } |
| | | } |