管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-30 e2cfc347670213e159da4b9e68e814953d48b0dc
src/main/java/com/lf/server/service/show/DataLibService.java
@@ -59,23 +59,19 @@
    public List<String> selectDbOverflowDep4Wkt(UserEntity ue, DownloadReqEntity dr) {
        List<String> rs = new ArrayList<>();
        for (String entity : dr.getEntities()) {
            try {
                GeomBaseMapper<?> baseMapper = ClassHelper.getGeoBaseMapper(entity);
                if (null == baseMapper) {
                    continue;
                }
                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));
                }
                List<String> ids = baseMapper.selectObjs(wrapper);
                addDepCodes(rs, ids);
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            GeomBaseMapper<?> baseMapper = ClassHelper.getGeoBaseMapper(entity);
            if (null == baseMapper) {
                continue;
            }
            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));
            }
            List<String> ids = baseMapper.selectObjs(wrapper);
            addDepCodes(rs, ids);
        }
        return rs;
@@ -86,19 +82,14 @@
     */
    public List<String> selectDbOverflowDep4Prop(UserEntity ue, DownloadReqEntity dr) {
        List<String> rs = new ArrayList<>();
        try {
            BasicMapper<?> baseMapper = ClassHelper.getBasicMapper(dr.getEntities().get(0));
            if (null == baseMapper) {
                return rs;
            }
            QueryWrapper wrapper = getWrapper4DbOverflow(ue, dr);
            List<String> ids = baseMapper.selectObjs(wrapper);
            addDepCodes(rs, ids);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        BasicMapper<?> baseMapper = ClassHelper.getBasicMapper(dr.getEntities().get(0));
        if (null == baseMapper) {
            return rs;
        }
        QueryWrapper wrapper = getWrapper4DbOverflow(ue, dr);
        List<String> ids = baseMapper.selectObjs(wrapper);
        addDepCodes(rs, ids);
        return rs;
    }
@@ -138,6 +129,9 @@
        }
        for (String id : ids) {
            if (StringHelper.isEmpty(id)) {
                continue;
            }
            if (!rs.contains(id)) {
                rs.add(id);
            }
@@ -147,43 +141,76 @@
    /**
     * 请求DB数据下载
     */
    public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) {
        Map<String, String> annexMap = new HashMap<>(3);
        Map<String, List<?>> dataMap = new HashMap<>(3);
    public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) throws Exception {
        Map<String, List<?>> dataMap = new HashMap<>(2);
        Map<String, List<AttachEntity>> annexMap = new HashMap<>(2);
        queryData(dr, dataMap, annexMap);
        if (dataMap.size() == 0) {
            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);
        return null;
        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;
    }
    /**
     * 查询数据
     * 查询数据+附件
     */
    private void queryData(DownloadReqEntity dr, Map<String, List<?>> dataMap , Map<String, String> annexMap) {
        for (String enity : dr.getEntities()) {
    private void queryData(DownloadReqEntity dr, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) {
        for (String entity : dr.getEntities()) {
            try {
                BasicMapper baseMapper = ClassHelper.getBasicMapper(enity);
                BasicMapper baseMapper = ClassHelper.getBasicMapper(entity);
                if (null == baseMapper) {
                    continue;
                }
                QueryWrapper wrapper = createQueryWrapper(baseMapper, dr);
                List<?> list = baseMapper.selectList(wrapper);
                List list = baseMapper.selectList(wrapper);
                if (null == list || list.size() == 0) {
                    continue;
                }
                // SQL片段
                String sqlSegment = wrapper.getSqlSegment();
                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");
                }
                if (!dataMap.containsKey(enity)) {
                    dataMap.put(enity, list);
                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);
                }
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
@@ -202,6 +229,7 @@
            wrapper.apply(dirs);
        }
        if (!StringHelper.isEmpty(dr.getDepcode())) {
            // wrapper.apply(String.format("depid like '%s'", StringHelper.getRightLike(dr.getDepcode())))
            wrapper.likeRight("depid", dr.getDepcode());
        }
        if (baseMapper instanceof GeomBaseMapper && !StringHelper.isEmpty(dr.getWkt())) {
@@ -215,95 +243,6 @@
            wrapper.apply(String.format("gid in (%s)", StringHelper.join(dr.getIds(), ",")));
        } else {
            baseQueryService.addFilterWrapper(wrapper, dr.getFilter());
        }
        return wrapper;
    }
    /**
     * 请求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;
@@ -328,48 +267,6 @@
        // 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());
    }
    /**
@@ -421,7 +318,7 @@
        removeDuplicate(list);
        setRightLike(list, field);
        return StringHelper.join(list, " or ");
        return "(" + StringHelper.join(list, " or ") + ")";
    }
    /**