管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-12-20 740265134189a7370f0d410cc03186e03339d65e
1
已修改2个文件
67 ■■■■■ 文件已修改
data/db_tab.sql 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/show/DataLibService.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db_tab.sql
@@ -800,7 +800,7 @@
comment on table lf.sys_download is '下载记录表';
comment on column lf.sys_download.id is '主键ID';
comment on column lf.sys_download.name is '名称';
comment on column lf.sys_download.type is '类型:1-Shp文件,2-专题图,3-元数据';
comment on column lf.sys_download.type is '类型:1-Shp文件,2-专题图,3-元数据,4-业务数据';
comment on column lf.sys_download.depid is '单位ID';
comment on column lf.sys_download.sizes is '文件大小:单位MB';
comment on column lf.sys_download.dcount is '下载次数';
src/main/java/com/lf/server/service/show/DataLibService.java
@@ -1,11 +1,17 @@
package com.lf.server.service.show;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lf.server.entity.data.DownloadEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.*;
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 net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -25,10 +31,15 @@
    PathHelper pathHelper;
    @Autowired
    BaseQueryService baseQueryService;
    DownloadMapper downloadMapper;
    @Autowired
    DownloadService downloadService;
    @Autowired
    BaseQueryService baseQueryService;
    private final static Log log = LogFactory.getLog(DataLibService.class);
    /**
     * 创建Zip包
@@ -41,6 +52,7 @@
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String tempPath = pathHelper.getTempPath(tempName);
        // String filePath = "D:\\LF\\temp\\20221219202706\\2022.gdb"
        String filePath = tempPath + File.separator + tempName + ".gdb";
        File file = new File(filePath);
@@ -49,7 +61,18 @@
        }
        GdbHelper.createGdb(filePath, map);
        return null;
        String zipName = tempName + ".gdb.zip";
        String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName;
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd);
        ZipParameters params = Zip4jHelper.getZipParams();
        addZipFiles(zip, params, file.listFiles());
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd);
        int rows = downloadMapper.insert(downloadEntity);
        return rows > 0 ? downloadEntity.getGuid() : null;
    }
    /**
@@ -92,4 +115,42 @@
        return wrapper;
    }
    /**
     * 添加Zip文件
     */
    private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) {
        if (null == files || files.length == 0) {
            return;
        }
        for (File f : files) {
            try {
                zip.addFile(f, params);
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }
        }
    }
    /**
     * 获取下载实体类
     */
    private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception {
        DownloadEntity de = new DownloadEntity();
        de.setName(FileHelper.getFileName(file));
        // 1-Shp文件,2-专题图,3-元数据,4-业务数据
        de.setType(4);
        de.setSizes(FileHelper.sizeToMb(new File(file).length()));
        de.setDepid(ue.getDepid());
        de.setDcount(0);
        de.setPwd(pwd);
        de.setUrl(FileHelper.getRelativePath(file));
        de.setDescr("业务数据文件");
        de.setGuid(FileHelper.getFileMd5(file));
        de.setCreateUser(ue.getId());
        // de.setGeom(null)
        return de;
    }
}