|
|
@@ -119,6 +119,7 @@ public class ConvergeServiceImpl implements ConvergeService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void downConvergeFile(HttpServletResponse response, String ywh) {
|
|
|
try {
|
|
|
@@ -142,7 +143,7 @@ public class ConvergeServiceImpl implements ConvergeService {
|
|
|
response.setContentType("application/zip");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
String fileName = downName + ".zip";
|
|
|
-
|
|
|
+
|
|
|
// 对文件名进行 URL 编码,解决中文乱码导致的 Header 非法字符异常
|
|
|
String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName);
|
|
|
@@ -161,6 +162,59 @@ public class ConvergeServiceImpl implements ConvergeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downConvergeMultiFile(HttpServletResponse response, List<String> idList) {
|
|
|
+ try {
|
|
|
+ if(CollectionUtils.isEmpty(idList)){
|
|
|
+ throw new ServiceException("汇交任务ID列表为空");
|
|
|
+ }
|
|
|
+ List<Converge> convergeList = convergeMapper.getByIds(idList);
|
|
|
+ if(CollectionUtils.isEmpty(convergeList)){
|
|
|
+ throw new ServiceException("获取不到当前任务:"+idList);
|
|
|
+ }
|
|
|
+
|
|
|
+ File[] zipFiles = new File[convergeList.size()];
|
|
|
+ int idx = 0;
|
|
|
+ String zipDirPath = convergedir;
|
|
|
+ for (Converge converge : convergeList) {
|
|
|
+ String path = converge.getFilePath();
|
|
|
+ Path dirPath = Paths.get(path);
|
|
|
+ if (!Files.exists(dirPath)) {
|
|
|
+ throw new ServiceException("找不到汇交文件生成目录:"+converge.getId());
|
|
|
+ }
|
|
|
+ zipFiles[idx++] = dirPath.toFile();
|
|
|
+ }
|
|
|
+
|
|
|
+ String uuidStr = IdUtils.fastSimpleUUID();
|
|
|
+ File zipFile = new File(zipDirPath + uuidStr +".zip");
|
|
|
+ if(zipFiles.length>0){
|
|
|
+ ServiceFileUtil.zipByDir(zipFiles,null, zipFile);
|
|
|
+ }
|
|
|
+ // 4. 设置响应头并下载
|
|
|
+ String downName = uuidStr;
|
|
|
+ response.setContentType("application/zip");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = downName + ".zip";
|
|
|
+ // 对文件名进行 URL 编码,解决中文乱码导致的 Header 非法字符异常
|
|
|
+ String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName);
|
|
|
+ try (FileInputStream fis = new FileInputStream(zipFile)) {
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int len;
|
|
|
+ while ((len = fis.read(buffer)) > 0) {
|
|
|
+ response.getOutputStream().write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("zip文件下载失败", e);
|
|
|
+ throw new RuntimeException("zip文件下载失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
* 不动产汇交数据生成主逻辑
|