管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-06 dc137d62c3c6bb62b3d43965b514ca9ebaf9c7f4
1
已修改1个文件
36 ■■■■ 文件已修改
src/main/java/com/lf/server/service/all/UploadAttachService.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/all/UploadAttachService.java
@@ -14,6 +14,7 @@
import com.lf.server.mapper.data.DownloadMapper;
import com.lf.server.service.sys.AttachService;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.FileHeader;
import net.lingala.zip4j.model.ZipParameters;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -435,20 +436,12 @@
            return null;
        }
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String filePath = pathHelper.getTempPath(tempName) + File.separator + tempName;
        File file = new File(filePath);
        if (file.exists() && file.isDirectory()) {
            FileHelper.deleteDir(filePath);
        }
        String zipName = tempName + ".zip";
        String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip";
        String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName;
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, null);
        ZipParameters params = Zip4jHelper.getZipParams();
        addZipFiles(zip, params, file.listFiles());
        addZipFiles(zip, params, list);
        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, null);
        int rows = downloadMapper.insert(downloadEntity);
@@ -459,14 +452,23 @@
    /**
     * 添加Zip文件
     */
    private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) {
        if (null == files || files.length == 0) {
            return;
        }
        for (File f : files) {
    private void addZipFiles(ZipFile zip, ZipParameters params, List<AttachEntity> list) {
        int i = 1;
        String uploadPath = pathHelper.getConfig().getUploadPath();
        for (AttachEntity ae : list) {
            try {
                zip.addFile(f, params);
                String filePath = uploadPath + File.separator + ae.getPath();
                File file = new File(filePath);
                if (!file.exists() || file.isDirectory()) {
                    continue;
                }
                zip.addFile(file, params);
                FileHeader header = zip.getFileHeader(file.getName());
                if (null != header) {
                    zip.renameFile(header, i + "_" + ae.getName());
                }
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }