管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-04-10 7911d40e365c6d7c3cb5832609a9b6e30c1a6641
src/main/java/com/lf/server/service/data/DownloadService.java
@@ -1,5 +1,6 @@
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;
@@ -9,7 +10,9 @@
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;
@@ -214,8 +217,10 @@
        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);
@@ -273,7 +278,69 @@
     * 查询数据
     */
    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;
    }
    /**
@@ -389,6 +456,9 @@
     */
    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());