管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-04-03 105fc752691e15d79715827dc58f22c9a2b87b96
1
已修改2个文件
110 ■■■■ 文件已修改
src/main/java/com/lf/server/service/data/DownloadService.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/show/DataLibService.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DownloadService.java
@@ -10,7 +10,6 @@
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.mapper.data.DownloadMapper;
import com.lf.server.service.show.DataLibService;
import com.lf.server.service.sys.MetaDownService;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.FileHeader;
@@ -21,6 +20,7 @@
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
/**
@@ -34,9 +34,6 @@
    @Autowired
    DownloadMapper downloadMapper;
    @Autowired
    DataLibService dataLibService;
    @Autowired
    MetaDownService metaDownService;
@@ -201,10 +198,6 @@
        Map<String, List<AttachEntity>> annexMap = new HashMap<>(2);
        queryData(tabs, dataMap, annexMap);
        //String downloadPath = pathHelper.getDownloadFullPath();
        //String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip";
        //String zipFile = downloadPath + File.separator + zipName;
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String tempPath = pathHelper.getTempPath(tempName);
        String gdbPath = tempPath + File.separator + "tabs.gdb";
@@ -217,12 +210,12 @@
            GdbHelper.createGdb(gdbPath, dataMap);
        }
        String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".gdb.zip";
        String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".zip";
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd);
        ZipParameters params = Zip4jHelper.getZipParams(true);
        //addMetaFiles(zip, params, list);
        addMetaFiles(zip, params, list);
        zip.addFolder(new File(gdbPath), params);
        dataLibService.addAnnex(zip, params, annexMap);
        addAnnex(zip, params, annexMap);
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
        DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd);
@@ -284,37 +277,69 @@
    }
    /**
     * 添加附件
     */
    public 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);
                }
            }
        }
    }
    /**
     * 添加元数据文件至Zip包
     */
    private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) {
        int i = 1;
        List<String> names = new ArrayList<>();
        String uploadPath = pathHelper.getConfig().getUploadPath();
        for (MetaEntity mf : list) {
            if (names.contains(mf.getName())) {
                mf.setName(mf.getId() + "_" + mf.getName());
            } else {
                names.add(mf.getName());
            }
            try {
                switch ("." + mf.getType()) {
                    case StaticData.MPT:
                        addMultiFile(i++, uploadPath, mf, zip, params, StaticData.MPT_EXT);
                        addMultiFile(uploadPath, mf, zip, params, StaticData.MPT_EXT);
                        break;
                    case StaticData.IMG:
                        addMultiFile(i++, uploadPath, mf, zip, params, StaticData.IMG_EXT);
                        addMultiFile(uploadPath, mf, zip, params, StaticData.IMG_EXT);
                        break;
                    case StaticData.TIF:
                        addMultiFile(i++, uploadPath, mf, zip, params, StaticData.TIF_EXT);
                        addMultiFile(uploadPath, mf, zip, params, StaticData.TIF_EXT);
                        break;
                    case StaticData.TIFF:
                        addMultiFile(i++, uploadPath, mf, zip, params, StaticData.TIFF_EXT);
                        addMultiFile(uploadPath, mf, zip, params, StaticData.TIFF_EXT);
                        break;
                    case StaticData.SHP:
                        addMultiFile(i++, uploadPath, mf, zip, params, StaticData.SHP_EXT);
                        addMultiFile(uploadPath, mf, zip, params, StaticData.SHP_EXT);
                        break;
                    case StaticData.GDB:
                        addFolderFile(i++, uploadPath, mf, zip, params);
                        addFolderFile(uploadPath, mf, zip, params);
                        break;
                    default:
                        addSingleFile(i++, uploadPath, mf, zip, params);
                        addSingleFile(uploadPath, mf, zip, params);
                        break;
                }
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }
@@ -324,7 +349,7 @@
    /**
     * 添加目录文件
     */
    private void addFolderFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception {
    private void addFolderFile(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;
@@ -334,15 +359,15 @@
        String fileName = FileHelper.getFileName(file.getPath());
        FileHeader header = zip.getFileHeader(fileName);
        if (null != header) {
            zip.renameFile(header, i + "_" + mf.getName());
            zip.renameFile(header, mf.getName());
        }
    }
    /**
     * 添加多文件
     */
    private void addMultiFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params, List<String> extList) throws Exception {
        addSingleFile(i, uploadPath, mf, zip, params);
    private void addMultiFile(String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params, List<String> extList) throws Exception {
        addSingleFile(uploadPath, mf, zip, params);
        for (String ext : extList) {
            File file = new File(uploadPath + File.separator + mf.getPath().replace("." + mf.getType(), ext));
@@ -354,7 +379,7 @@
            String fileName = FileHelper.getFileName(file.getPath());
            FileHeader header = zip.getFileHeader(fileName);
            if (null != header) {
                zip.renameFile(header, i + "_" + mf.getName().replace("." + mf.getType(), ext));
                zip.renameFile(header, mf.getName().replace("." + mf.getType(), ext));
            }
        }
    }
@@ -362,14 +387,14 @@
    /**
     * 添加单文件
     */
    private void addSingleFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception {
    private void addSingleFile(String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception {
        File file = new File(uploadPath + File.separator + mf.getPath());
        zip.addFile(file, params);
        String fileName = FileHelper.getFileName(file.getPath());
        FileHeader header = zip.getFileHeader(fileName);
        if (null != header) {
            zip.renameFile(header, i + "_" + mf.getName());
            zip.renameFile(header, mf.getName());
        }
    }
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;
@@ -20,7 +19,6 @@
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
/**
@@ -165,7 +163,7 @@
        ZipParameters params = Zip4jHelper.getZipParams(true);
        zip.addFolder(new File(gdbPath), params);
        // zip.addFolder(new File(annexPath), params)
        addAnnex(zip, params, annexMap);
        downloadService.addAnnex(zip, params, annexMap);
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd()));
        DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd);
@@ -279,33 +277,6 @@
                    }
                    FileHelper.copyFile(srcFile, destFile);
                } catch (Exception ex) {
                    log.error(ex.getMessage(), ex);
                }
            }
        }
    }
    /**
     * 添加附件
     */
    public 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);
                }