| | |
| | | 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.ctrl.KeyValueEntity; |
| | | 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.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; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class DataLibService { |
| | | @Autowired |
| | | PathHelper pathHelper; |
| | | |
| | | @Autowired |
| | | DownloadMapper downloadMapper; |
| | | MetaService metaService; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | DownloadMapper downloadMapper; |
| | | |
| | | @Autowired |
| | | BaseQueryService baseQueryService; |
| | |
| | | |
| | | 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); |
| | |
| | | ZipParameters params = Zip4jHelper.getZipParams(true); |
| | | zip.addFolder(new File(gdbPath), params); |
| | | // zip.addFolder(new File(annexPath), params) |
| | | addAnnex(zip, params, annexMap); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | 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(tab.replace(".", "_"), annex); |
| | | } else { |
| | | annexMap.get(tab.replace(".", "_")).addAll(annex); |
| | | } |
| | | metaService.addData(entity, baseMapper, wrapper, dataMap, annexMap); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | |
| | | // 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)); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 添加附件 |
| | | */ |
| | | private void addAnnex(ZipFile zip, ZipParameters params, Map<String, List<AttachEntity>> annexMap) { |
| | | List<String> files = new ArrayList<>(); |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | for (String key : annexMap.keySet()) { |
| | | for (AttachEntity ae : annexMap.get(key)) { |
| | | try { |
| | | File srcFile = new File(uploadPath + File.separator + ae.getPath()); |
| | | if (!srcFile.exists() || srcFile.isDirectory()) { |
| | | continue; |
| | | } |
| | | if (files.contains(srcFile.getPath())) { |
| | | continue; |
| | | } |
| | | |
| | | files.add(srcFile.getPath()); |
| | | params.setFileNameInZip(key + File.separator + ae.getName()); |
| | | zip.addStream(new FileInputStream(srcFile), params); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | 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()); |
| | |
| | | return null; |
| | | } |
| | | |
| | | List<String> list = codesAsList(codes); |
| | | removeDuplicate(list); |
| | | List<String> list = Arrays.asList(codes.split(",")); |
| | | //List<String> list = codesAsList(codes); |
| | | //list = copeDirCodes(list); |
| | | setRightLike(list, field); |
| | | |
| | | return "(" + StringHelper.join(list, " or ") + ")"; |
| | | } |
| | | |
| | | /** |
| | | * 单位编码转集合 |
| | | * 单位编码转集合 * |
| | | */ |
| | | private static List<String> codesAsList(String codes) { |
| | | List<String> list = Arrays.asList(codes.split(",")); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 去除重复 |
| | | * 处理目录编码 * |
| | | */ |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 设置 右like |
| | | */ |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据资料类别获取目录编码 |
| | | */ |
| | | public String getDirsByTypes(String types, String dirs, String field) { |
| | | if (StringUtils.isEmpty(types) && StringUtils.isEmpty(dirs)) { |
| | | return null; |
| | | } |
| | | |
| | | if (!StringUtils.isEmpty(types)) { |
| | | List<KeyValueEntity> list = baseQueryService.selectDirsByTypes(types, dirs); |
| | | if (null == list || list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | return copeDirs(list, field); |
| | | } |
| | | |
| | | return copeCodes(dirs, field); |
| | | } |
| | | |
| | | /** |
| | | * 处理目录编码 |
| | | */ |
| | | public static String copeDirs(List<KeyValueEntity> kvs, String field) { |
| | | List<String> list = new ArrayList<>(); |
| | | for (KeyValueEntity kv : kvs) { |
| | | String[] dirs = kv.getValue().split(","); |
| | | for (String dir : dirs) { |
| | | list.add(String.format("%s like '%s%%'", field, dir)); |
| | | } |
| | | } |
| | | |
| | | return "(" + StringHelper.join(list, " or ") + ")"; |
| | | } |
| | | } |