管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-12-24 09b6ca0c60b882d6ba13bd7f7b37576203d93d3f
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;
@@ -116,15 +117,15 @@
    }
    /**
     * 校验密码有效性
     * 解密
     *
     * @param reqEntity 请求下载实体类
     * @return 是/否有效
     * @return 是/否解密成功
     */
    public boolean validatePwd(DownloadReqEntity reqEntity) {
    public static boolean decryptPwd(DownloadReqEntity reqEntity) {
        try {
            String pwd = RsaHelper.decrypt(reqEntity.getPwd());
            if (StringHelper.isEmpty(pwd) || !StringHelper.checkPwdValid(pwd)) {
            if (StringHelper.isEmpty(pwd)) {
                return false;
            }
@@ -143,7 +144,7 @@
     * @param pwd 加密密码
     * @return 原始密码
     */
    public String decryptPwd(String pwd) {
    public static String decryptPwd(String pwd) {
        try {
            return RsaHelper.decrypt(pwd);
        } catch (Exception ex) {
@@ -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,10 +170,13 @@
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd);
        ZipParameters params = Zip4jHelper.getZipParams();
        addMetaFiles(zip, params, list);
        return null;
        String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd));
        DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd);
        int rows = downloadMapper.insert(downloadEntity);
        return rows > 0 ? downloadEntity.getGuid() : null;
    }
    /**
@@ -199,19 +203,41 @@
     */
    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()));
        int i = 1;
        for (MetaFileEntity entity : list) {
            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, i++ + "_" + 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(pwd);
        de.setUrl(FileHelper.getRelativePath(file));
        de.setDescr("元数据文件");
        de.setGuid(FileHelper.getFileMd5(file));
        de.setCreateUser(ue.getId());
        // de.setGeom(null)
        return de;
    }
}