管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2023-03-26 861f963ab4750c3efcc19d0d3abd60761ec399b7
1
已修改5个文件
94 ■■■■ 文件已修改
data/db_cx.sql 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/DirController.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/Zip4jHelper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/DirService.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/data/DirMapper.xml 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data/db_cx.sql
@@ -15,6 +15,8 @@
select * from lf.sys_attach where tab != 'bd.b_borehole' order by id desc limit 50; -- 358042
select * from lf.sys_meta where tab is not null order by id desc
select * from bs.m_pipeline where parentid in ('fdac47da-8879-478d-b67c-9624e8b79d6c')
select * from lf.sys_attach where tab='bs.m_pipeline' and tab_guid in (select eventid from bs.m_pipeline where parentid in ('fdac47da-8879-478d-b67c-9624e8b79d6c'))
src/main/java/com/lf/server/controller/data/DirController.java
@@ -5,6 +5,7 @@
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.data.DirEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.data.DirService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
@@ -15,6 +16,7 @@
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@@ -183,4 +185,28 @@
            return fail(ex, null);
        }
    }
    @SysLog()
    @ApiOperation(value = "下载目录结构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "目录ID", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping(value = "/downloadDir")
    public void downloadDir(int id, HttpServletResponse res) {
        try {
            DirEntity entity = dirService.selectDir(id);
            if (null == entity || entity.getPid() > 0) {
                return;
            }
            String zipFile = dirService.createDirs(id);
            if (null == zipFile) {
                return;
            }
            WebHelper.download(zipFile, entity.getName() + ".zip", res);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
}
src/main/java/com/lf/server/helper/Zip4jHelper.java
@@ -84,7 +84,7 @@
    /**
     * 获取ZipParameters
     */
    public static ZipParameters getZipParams(boolean flag) {
    public static ZipParameters getZipParams(boolean hasPwd) {
        // 设置压缩文件参数
        ZipParameters params = new ZipParameters();
        // 压缩方式
@@ -92,7 +92,7 @@
        // 压缩级别
        params.setCompressionLevel(CompressionLevel.MAXIMUM);
        if (flag) {
        if (hasPwd) {
            // 是否设置加密文件
            params.setEncryptFiles(true);
            // 设置AES加密强度:KEY_STRENGTH_256
src/main/java/com/lf/server/service/data/DirService.java
@@ -1,11 +1,17 @@
package com.lf.server.service.data;
import com.lf.server.entity.data.DirEntity;
import com.lf.server.helper.PathHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.Zip4jHelper;
import com.lf.server.mapper.data.DirMapper;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.Date;
import java.util.List;
/**
@@ -16,6 +22,9 @@
@Service
public class DirService implements DirMapper {
    @Autowired
    PathHelper pathHelper;
    @Autowired
    DirMapper dirMapper;
@@ -85,4 +94,37 @@
    public List<DirEntity> selectDirsForPrj() {
        return dirMapper.selectDirsForPrj();
    }
    /**
     * 创建数据目录
     */
    public String createDirs(int id) throws Exception {
        List<DirEntity> list = selectRecursiveById(id);
        if (null == list || list.isEmpty()) {
            return null;
        }
        String tempPath = pathHelper.getTempPath();
        for (DirEntity dir : list) {
            String path = tempPath + File.separator + dir.getFullName();
            File f = new File(path);
            if (f.exists() && f.isDirectory()) {
                continue;
            }
            f.mkdirs();
        }
        File file = new File(tempPath + File.separator + list.get(0).getName());
        if (!file.exists() || !file.isDirectory()) {
            file.mkdirs();
        }
        String zipFile = tempPath + File.separator + list.get(0).getName() + ".zip";
        ZipFile zip = Zip4jHelper.createZipFile(zipFile, null);
        ZipParameters params = Zip4jHelper.getZipParams(false);
        zip.addFolder(file, params);
        return zipFile;
    }
}
src/main/resources/mapper/data/DirMapper.xml
@@ -30,20 +30,20 @@
    <select id="selectDirRecursive" resultType="com.lf.server.entity.data.DirEntity">
        with recursive rs as(
        select a.*, fn_get_fullname(a.code, 2) fullName from lf.sys_dir a where name = #{name}
        union
            select b.*, fn_get_fullname(b.code, 2) fullName from lf.sys_dir b, rs c where b.pid = c.id
        )
        select * from rs order by order_num;
            select a.*, fn_get_fullname(a.code, 2) fullName from lf.sys_dir a where name = #{name}
            union
            select b.*, fn_get_fullname(b.code, 2) fullName from lf.sys_dir b, rs c where b.pid = c.id)
        select * from rs
        order by order_num;
    </select>
    <select id="selectRecursiveById" resultType="com.lf.server.entity.data.DirEntity">
        with recursive rs as(
        select a.*, fn_get_fullname(a.code, 2) fullName from lf.sys_dir a where id = #{id}
        union
            select b.*, fn_get_fullname(b.code, 2) fullName from lf.sys_dir b, rs c where b.pid = c.id
        )
        select * from rs order by order_num;
            select a.*, fn_get_fullname(a.code, 2) fullName from lf.sys_dir a where id = #{id}
            union
            select b.*, fn_get_fullname(b.code, 2) fullName from lf.sys_dir b, rs c where b.pid = c.id)
        select * from rs
        order by code;
    </select>
    <select id="selectDirsForPrj" resultType="com.lf.server.entity.data.DirEntity">