|
|
|
@ -2,14 +2,17 @@ package com.ruoyi.jjh.declaration.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
|
|
|
import com.ruoyi.jjh.declaration.entity.BmsDeclarationRecords;
|
|
|
|
|
import com.ruoyi.jjh.declaration.entity.dto.ApprovalDeclarationRecordsQueryDto;
|
|
|
|
|
import com.ruoyi.jjh.declaration.entity.dto.BmsApprovalInfoUpdateDto;
|
|
|
|
@ -20,26 +23,21 @@ import com.ruoyi.jjh.declaration.mapper.BmsDeclarationRecordsMapper;
|
|
|
|
|
import com.ruoyi.jjh.declaration.service.IBmsDeclarationRecordsService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -58,15 +56,17 @@ public class BmsDeclarationRecordsController extends BaseController {
|
|
|
|
|
@Value("${ruoyi.profile}")
|
|
|
|
|
private String fileAddress;
|
|
|
|
|
|
|
|
|
|
@Value("${server.port}")
|
|
|
|
|
private String port;
|
|
|
|
|
|
|
|
|
|
@Value("${server.servlet.context-path}")
|
|
|
|
|
private String path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private BmsDeclarationRecordsMapper bmsDeclarationRecordsMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ServerConfig serverConfig;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 审核列表
|
|
|
|
|
*/
|
|
|
|
@ -118,43 +118,47 @@ public class BmsDeclarationRecordsController extends BaseController {
|
|
|
|
|
// @RequiresPermissions("system:declarationRecords:list")
|
|
|
|
|
@GetMapping("/fileList")
|
|
|
|
|
@ApiOperation("根据列表id集合压缩所有文件")
|
|
|
|
|
public ResponseEntity<byte[]> fileList(@RequestParam(name = "list") List<Long> list) throws FileNotFoundException, UnsupportedEncodingException {
|
|
|
|
|
public void fileList(@RequestParam(name = "list") List<Long> list, HttpServletResponse response) throws IOException {
|
|
|
|
|
List<BmsDeclarationRecordsQueryVo> rd = bmsDeclarationRecordsMapper.selectDeclarationRecordsToIdList(list);
|
|
|
|
|
// 创建父文件目录
|
|
|
|
|
String fatherFile = fileAddress + "/" + "项目压缩文件";
|
|
|
|
|
String fatherFile = fileAddress + "/项目压缩文件";
|
|
|
|
|
FileUtil.mkdir(fatherFile);
|
|
|
|
|
for (BmsDeclarationRecordsQueryVo item : rd) {
|
|
|
|
|
String itemsFileName = fatherFile + "/" +item.getEnterpriseName()+ item.getProjectName();
|
|
|
|
|
FileUtil.mkdir(itemsFileName);
|
|
|
|
|
List<String> splitList = bmsDeclarationRecordsService.getAllFile(item.getTemplateJson());
|
|
|
|
|
for (String s : splitList) {
|
|
|
|
|
// 下载文件
|
|
|
|
|
try {
|
|
|
|
|
HttpUtil.downloadFile("http://localhost:" + port + s, itemsFileName);
|
|
|
|
|
String urls = RuoYiConfig.getProfile() + StringUtils.substringAfter(s, Constants.RESOURCE_PREFIX);
|
|
|
|
|
Path sourcePath = Paths.get(urls);
|
|
|
|
|
String itemsFileName = fatherFile + "/" + item.getEnterpriseName() + item.getProjectName() + "/" + sourcePath.getFileName();
|
|
|
|
|
FileUtil.touch(itemsFileName);
|
|
|
|
|
// 目标文件路径
|
|
|
|
|
Path targetPath = Paths.get(itemsFileName);
|
|
|
|
|
try {
|
|
|
|
|
Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
|
System.out.println("文件成功复制到新的位置!");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("暂无该文件!");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(itemsFileName + "某文件下载失败");
|
|
|
|
|
throw new RuntimeException("文件下载失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 压缩后的文件路径
|
|
|
|
|
String zipFilePath = fatherFile + ".zip";
|
|
|
|
|
// 使用Hutool压缩文件夹
|
|
|
|
|
ZipUtil.zip(fatherFile, zipFilePath);
|
|
|
|
|
// 从本地读取压缩文件
|
|
|
|
|
File zipFile = FileUtil.file(zipFilePath);
|
|
|
|
|
// FileSystemResource resource = new FileSystemResource(zipFile);
|
|
|
|
|
// 读取本地压缩文件并转为字节数组
|
|
|
|
|
byte[] bytes = FileUtil.readBytes(zipFile);
|
|
|
|
|
// 设置响应头
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
|
|
headers.setContentDispositionFormData("attachment", URLEncoder.encode("项目压缩文件.zip", "UTF-8"));
|
|
|
|
|
// 删除压缩之前的文件夹
|
|
|
|
|
File file = new File(zipFilePath);// 创建File对象
|
|
|
|
|
response.setContentType("application/zip");// 设置内容类型为ZIP文件
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=\"file.zip\"");//设置文件名
|
|
|
|
|
try (FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
|
|
OutputStream outputStream = response.getOutputStream()) {
|
|
|
|
|
byte[] buffer = new byte[4096];
|
|
|
|
|
int by;
|
|
|
|
|
while ((by = fileInputStream.read(buffer)) != -1) {
|
|
|
|
|
outputStream.write(buffer, 0, by);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FileUtil.del(zipFilePath);
|
|
|
|
|
// 删除压缩包
|
|
|
|
|
FileUtil.del(fatherFile);
|
|
|
|
|
// 创建响应实体
|
|
|
|
|
return new ResponseEntity<>(bytes, headers, HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|