管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-28 8bebd7becead5b3d8cdbaa25b891645ea4faf7ce
1
已修改1个文件
42 ■■■■ 文件已修改
src/main/java/com/lf/server/service/data/DownloadService.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DownloadService.java
@@ -7,6 +7,7 @@
import com.lf.server.helper.*;
import com.lf.server.mapper.data.DownloadMapper;
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;
@@ -160,7 +161,7 @@
     * @param pwd  密码
     * @return 下载文件GUID
     */
    public String zipFiles(UserEntity ue, List<MetaFileEntity> list, String pwd) {
    public String zipFiles(UserEntity ue, List<MetaFileEntity> list, String pwd) throws Exception {
        rmRepeatMetaFiles(list);
        String downloadPath = pathHelper.getDownloadFullPath();
@@ -169,8 +170,9 @@
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd);
        ZipParameters params = Zip4jHelper.getZipParams();
        addMetaFiles(zip, params, list);
        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, pwd);
        return null;
    }
@@ -200,18 +202,38 @@
    private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaFileEntity> list) {
        String uploadPath = pathHelper.getConfig().getUploadPath();
        for (MetaFileEntity entity : list) {
            String filePath = uploadPath + File.separator + entity.getPath();
            File file = new File(filePath);
            File newFile = new File(filePath.replace(entity.getGuid(), entity.getName()));
            try {
                file.renameTo(newFile);
                zip.addFile(newFile, params);
                File file = new File(uploadPath + File.separator + entity.getPath());
                zip.addFile(file, params);
                FileHeader header = zip.getFileHeader(entity.getGuid());
                if (null != header) {
                    zip.renameFile(header, entity.getName());
                }
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            } finally {
                newFile.renameTo(file);
            }
        }
    }
    /**
     * 获取下载实体类
     */
    private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception {
        DownloadEntity de = new DownloadEntity();
        de.setName(FileHelper.getFileName(file));
        // 1-Shp文件,2-专题图,3-元数据
        de.setType(3);
        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
        de.setDepid(ue.getDepid());
        de.setDcount(0);
        // de.setPwd(null)
        de.setUrl(FileHelper.getRelativePath(file));
        de.setDescr("元数据文件");
        de.setGuid(FileHelper.getFileMd5(file));
        de.setCreateUser(ue.getId());
        // de.setGeom(null)
        return de;
    }
}