管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-02-27 f15294cf82b71dfbf75d0821dd8eb13d14a9d936
src/main/java/com/lf/server/service/data/DownloadService.java
@@ -5,9 +5,11 @@
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.show.PipelineEntity;
import com.lf.server.entity.sys.MetaDownEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
import com.lf.server.mapper.data.DownloadMapper;
import com.lf.server.service.sys.MetaDownService;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.FileHeader;
import net.lingala.zip4j.model.ZipParameters;
@@ -32,6 +34,9 @@
    @Autowired
    DownloadMapper downloadMapper;
    @Autowired
    MetaDownService metaDownService;
    private final static Log log = LogFactory.getLog(DownloadService.class);
@@ -197,10 +202,14 @@
        addMetaFiles(zip, params, list);
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd);
        int rows = downloadMapper.insert(downloadEntity);
        DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd);
        return rows > 0 ? downloadEntity.getGuid() : null;
        int rows = downloadMapper.insert(de);
        if (de.getId() > 0) {
            insertMetaDown(ue, list, de);
        }
        return rows > 0 ? de.getGuid() : null;
    }
    /**
@@ -264,7 +273,17 @@
     * 添加目录文件
     */
    private void addFolderFile(int i, 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.addFolder(file, params);
        String fileName = FileHelper.getFileName(file.getPath());
        FileHeader header = zip.getFileHeader(fileName);
        if (null != header) {
            zip.renameFile(header, i + "_" + mf.getName());
        }
    }
    /**
@@ -275,7 +294,7 @@
        for (String ext : extList) {
            File file = new File(uploadPath + File.separator + mf.getPath().replace("." + mf.getType(), ext));
            if (!file.exists() || !file.isDirectory()) {
            if (!file.exists() || file.isDirectory()) {
                continue;
            }
            zip.addFile(file, params);
@@ -305,10 +324,10 @@
    /**
     * 获取下载实体类
     */
    private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception {
    private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) {
        DownloadEntity de = new DownloadEntity();
        de.setName(FileHelper.getFileName(file));
        // 1-Shp文件,2-专题图,3-元数据
        // 1-Shp文件,2-专题图,3-元数据,4-业务数据,5-管道分析,6-统计报告
        de.setType(3);
        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
        de.setDepid(ue.getDepid());
@@ -322,4 +341,21 @@
        return de;
    }
    /**
     * 插入元数据-下载表
     */
    private void insertMetaDown(UserEntity ue, List<MetaEntity> metas, DownloadEntity de) {
        List<MetaDownEntity> list = new ArrayList<>();
        for (MetaEntity me : metas) {
            MetaDownEntity md = new MetaDownEntity();
            md.setMetaid(me.getId());
            md.setDownid(de.getId());
            md.setCreateUser(ue.getId());
            list.add(md);
        }
        metaDownService.inserts(list);
    }
}