管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-30 e2cfc347670213e159da4b9e68e814953d48b0dc
1
已修改3个文件
183 ■■■■ 文件已修改
src/main/java/com/lf/server/controller/all/BaseQueryController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/show/ApplyService.java 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/show/DataLibService.java 154 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/all/BaseQueryController.java
@@ -607,7 +607,7 @@
        }
    }
    @SysLog()
    /*@SysLog()
    @ApiOperation(value = "请求DB数据下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dr", value = "请求下载实体", dataType = "DownloadReqEntity", paramType = "body")
@@ -671,7 +671,7 @@
        } catch (Exception ex) {
            return fail(ex, null);
        }
    }
    }*/
    @SysLog()
    @ApiOperation(value = "查看文件")
src/main/java/com/lf/server/service/show/ApplyService.java
@@ -1,5 +1,6 @@
package com.lf.server.service.show;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.ctrl.DownloadReqEntity;
import com.lf.server.entity.show.ApplyEntity;
import com.lf.server.entity.show.FlowEntity;
@@ -191,21 +192,33 @@
     */
    public void zipDbData(UserEntity ue, ApplyEntity entity) {
        try {
            List<String> entities = Arrays.asList(entity.getEntities().split(","));
            List<String> entities = Arrays.asList(entity.getEntities().split(StaticData.COMMA));
            String pwd = AesHelper.decrypt(entity.getPwd());
            DownloadReqEntity dr = new DownloadReqEntity();
            dr.setEntities(entities);
            dr.setWkt(dr.getWkt());
            dr.setPwd(pwd);
            dr.setIds(null);
            dr.setDirs(null);
            dr.setFilter(null);
            dr.setDepcodes(null);
            dr.setIds(getIds(entity));
            dr.setDirs(entity.getDircodes());
            dr.setFilter(entity.getFilters());
            dr.setDepcode(entity.getDepcode());
            dataLibService.downloadDbReq4Wkt(ue, dr);
            dataLibService.downloadDbReq(ue, dr);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    /**
     * 获取ID集合
     */
    private List<Integer> getIds(ApplyEntity entity) {
        List<Integer> list = new ArrayList<>();
        for (String str : entity.getGids().split(StaticData.COMMA)) {
            list.add(Integer.parseInt(str));
        }
        return list;
    }
}
src/main/java/com/lf/server/service/show/DataLibService.java
@@ -141,7 +141,7 @@
    /**
     * 请求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);
@@ -150,7 +150,26 @@
            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;
    }
    /**
@@ -230,95 +249,6 @@
    }
    /**
     * 请求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) {
@@ -337,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());
    }
    /**