管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-04-03 b885fe8d0c0f7c7053b998758f84da054e8cfc6a
src/main/java/com/lf/server/service/data/DownloadService.java
@@ -5,10 +5,12 @@
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.AttachEntity;
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.show.DataLibService;
import com.lf.server.service.sys.MetaDownService;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.FileHeader;
@@ -19,9 +21,7 @@
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
 * 下载记录
@@ -36,34 +36,37 @@
    DownloadMapper downloadMapper;
    @Autowired
    DataLibService dataLibService;
    @Autowired
    MetaDownService metaDownService;
    private final static Log log = LogFactory.getLog(DownloadService.class);
    @Override
    public Integer selectCount(String name) {
        name = StringHelper.getLikeStr(name);
        name = StringHelper.getLikeUpperStr(name);
        return downloadMapper.selectCount(name);
    }
    @Override
    public List<DownloadEntity> selectByPage(String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeStr(name);
        name = StringHelper.getLikeUpperStr(name);
        return downloadMapper.selectByPage(name, limit, offset);
    }
    @Override
    public Integer selectCountForUser(Integer createUser, Integer type, String name) {
        name = StringHelper.getLikeStr(name);
        name = StringHelper.getLikeUpperStr(name);
        return downloadMapper.selectCountForUser(createUser, type, name);
    }
    @Override
    public List<DownloadEntity> selectByPageForUser(Integer createUser, Integer type, String name, Integer limit, Integer offset) {
        name = StringHelper.getLikeStr(name);
        name = StringHelper.getLikeUpperStr(name);
        return downloadMapper.selectByPageForUser(createUser, type, name, limit, offset);
    }
@@ -191,19 +194,38 @@
     * @return 下载文件GUID
     */
    public String zipFiles(UserEntity ue, List<MetaEntity> list, String pwd) throws Exception {
        rmRepeatMetaFiles(list);
        Map<String, List<String>> tabs = getTabs(list);
        rmRepeatMetas(list);
        String downloadPath = pathHelper.getDownloadFullPath();
        String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip";
        String zipFile = downloadPath + File.separator + zipName;
        Map<String, List<?>> dataMap = new HashMap<>(2);
        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";
        File gdbFile = new File(gdbPath);
        if (gdbFile.exists() && gdbFile.isDirectory()) {
            FileHelper.deleteDir(gdbPath);
        }
        if (dataMap.size() > 0) {
            GdbHelper.createGdb(gdbPath, dataMap);
        }
        String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".gdb.zip";
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd);
        ZipParameters params = Zip4jHelper.getZipParams();
        addMetaFiles(zip, params, list);
        ZipParameters params = Zip4jHelper.getZipParams(true);
        //addMetaFiles(zip, params, list);
        zip.addFolder(new File(gdbPath), params);
        dataLibService.addAnnex(zip, params, annexMap);
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
        DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd);
        int rows = downloadMapper.insert(de);
        if (de.getId() > 0) {
            insertMetaDown(ue, list, de);
@@ -213,9 +235,32 @@
    }
    /**
     * 获取数据表
     */
    private Map<String, List<String>> getTabs(List<MetaEntity> list) {
        Map<String, List<String>> tabs = new HashMap<>(2);
        for (MetaEntity meta : list) {
            if (StringHelper.isEmpty(meta.getTab()) || meta.getRows() == 0 || StringHelper.isEmpty(meta.getEventid())) {
                continue;
            }
            if (!tabs.containsKey(meta.getTab())) {
                tabs.put(meta.getTab(), new ArrayList<>());
            }
            List<String> ids = tabs.get(meta.getTab());
            if (!ids.contains(meta.getEventid())) {
                ids.add(meta.getEventid());
            }
        }
        return tabs;
    }
    /**
     * 移除重复的元数据文件
     */
    private void rmRepeatMetaFiles(List<MetaEntity> list) {
    private void rmRepeatMetas(List<MetaEntity> list) {
        List<String> guidList = new ArrayList<>();
        int i = 0;
@@ -232,6 +277,13 @@
    }
    /**
     * 查询数据
     */
    private void queryData(Map<String, List<String>> tabs, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) {
        //
    }
    /**
     * 添加元数据文件至Zip包
     */
    private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) {