管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-13 58c8284e68369fe95a7b200c5fe8821a852469c1
src/main/java/com/lf/server/service/show/DataLibService.java
@@ -4,6 +4,7 @@
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.mapper.all.BasicMapper;
import com.lf.server.mapper.all.GeomBaseMapper;
import com.lf.server.mapper.data.DownloadMapper;
import com.lf.server.service.all.BaseQueryService;
@@ -53,14 +54,15 @@
                QueryWrapper wrapper = new QueryWrapper();
                wrapper.select("depid");
                wrapper.gt("depid", 0);
                wrapper.apply(String.format("depid != ALL(fn_rec_array(%d, 'dep')", ue.getDepid()));
                wrapper.apply(String.format("depid != ALL(fn_rec_array(%d, 'dep'))", ue.getDepid()));
                wrapper.groupBy("depid");
                Integer srid = baseQueryService.getSrid(baseMapper);
                if (null != srid) {
                    wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", wkt, srid));
                }
                List<Integer> ids = baseMapper.selectList(wrapper);
                List<Integer> ids = baseMapper.selectObjs(wrapper);
                addDepIds(rs, ids);
            } catch (Exception ex) {
@@ -201,4 +203,58 @@
        return de;
    }
    /**
     * 打包DB数据
     */
    public String zipDbData(UserEntity ue, String name, String filter, String pwd) throws Exception {
        BasicMapper baseMapper = ClassHelper.getBasicMapper(name);
        if (baseMapper == null) {
            return null;
        }
        QueryWrapper wrapper = new QueryWrapper();
        baseQueryService.addFilterWrapper(wrapper, filter);
        if (baseMapper instanceof GeomBaseMapper) {
            wrapper.select("ST_AsText(geom) as geom, *");
        }
        List<?> list = baseMapper.selectList(wrapper);
        if (null == list || 0 == list.size()) {
            return null;
        }
        Map<String, List<?>> map = new HashMap<>(1);
        map.put(name, list);
        return zipData(ue, map, pwd);
    }
    /**
     * 打包数据
     */
    private String zipData(UserEntity ue, Map<String, List<?>> map, String pwd) throws Exception {
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String tempPath = pathHelper.getTempPath(tempName);
        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, pwd);
        ZipParameters params = Zip4jHelper.getZipParams();
        addZipFiles(zip, params, file.listFiles());
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd);
        int rows = downloadMapper.insert(downloadEntity);
        return rows > 0 ? downloadEntity.getGuid() : null;
    }
}