管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-04-11 4bc6c32f168cd4b4fda77b3a628c0fcd99268ec5
src/main/java/com/lf/server/service/show/DataLibService.java
@@ -1,7 +1,6 @@
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.data.DownloadEntity;
import com.lf.server.entity.sys.AttachEntity;
@@ -11,7 +10,7 @@
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;
@@ -20,7 +19,6 @@
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
/**
@@ -33,10 +31,10 @@
    PathHelper pathHelper;
    @Autowired
    DownloadMapper downloadMapper;
    MetaService metaService;
    @Autowired
    DownloadService downloadService;
    DownloadMapper downloadMapper;
    @Autowired
    BaseQueryService baseQueryService;
@@ -67,9 +65,7 @@
            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);
@@ -165,13 +161,13 @@
        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;
    }
    /**
@@ -186,34 +182,7 @@
                }
                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 (wrapper.isEmptyOfWhere()) {
                    wrapper.apply("1 = 1");
                }
                if ("bborehole".equals(entity)) {
                    wrapper.last("limit 100");
                }
                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);
            }
@@ -234,10 +203,10 @@
            // 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));
            }
        }
@@ -279,33 +248,6 @@
                    }
                    FileHelper.copyFile(srcFile, destFile);
                } catch (Exception ex) {
                    log.error(ex.getMessage(), ex);
                }
            }
        }
    }
    /**
     * 添加附件
     */
    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("annex" + File.separator + key + File.separator + ae.getName());
                    zip.addStream(new FileInputStream(srcFile), params);
                } catch (Exception ex) {
                    log.error(ex.getMessage(), ex);
                }