Commit d6725234 authored by huyuchen's avatar huyuchen

huych-电子档案批量导入第五次提交

parent 997f4abc
...@@ -240,7 +240,20 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic ...@@ -240,7 +240,20 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic
} }
} }
// 2. 设置响应头 // 2. 校验文件总大小是否超过500MB
long totalSize = calculateTotalFileSize(downloadMap);
long maxSize = 500 * 1024 * 1024L; // 500MB
if (totalSize > maxSize) {
log.warn("批量下载文件总大小超过限制,总大小:{}MB,限制:500MB", totalSize / 1024 / 1024);
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
String errorMsg = String.format("{\"code\":1,\"msg\":\"下载文件总大小超过限制,当前总大小:%.2fMB,最大允许:500MB\"}",
totalSize / 1024.0 / 1024.0);
response.getWriter().write(errorMsg);
return;
}
// 3. 设置响应头
String fileName = "电子档案批量下载_" + String fileName = "电子档案批量下载_" +
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".zip"; LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".zip";
response.setContentType("application/zip"); response.setContentType("application/zip");
...@@ -248,10 +261,10 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic ...@@ -248,10 +261,10 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic
response.setHeader(CommonConstants.CONTENT_DISPOSITION, response.setHeader(CommonConstants.CONTENT_DISPOSITION,
"attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
// 3. 创建ZIP输出流 // 4. 创建ZIP输出流
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) { try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
// 4. 下载并打包档案文件 // 5. 下载并打包档案文件
for (Map.Entry<String, ArchiveDownloadInfo> entry : downloadMap.entrySet()) { for (Map.Entry<String, ArchiveDownloadInfo> entry : downloadMap.entrySet()) {
String folderName = entry.getKey(); String folderName = entry.getKey();
ArchiveDownloadInfo downloadInfo = entry.getValue(); ArchiveDownloadInfo downloadInfo = entry.getValue();
...@@ -284,7 +297,7 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic ...@@ -284,7 +297,7 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic
} }
} }
// 5. 生成并添加反馈Excel表 // 6. 生成并添加反馈Excel表
addFeedbackExcel(zipOut, feedbackList); addFeedbackExcel(zipOut, feedbackList);
zipOut.finish(); zipOut.finish();
...@@ -803,6 +816,19 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic ...@@ -803,6 +816,19 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic
return; return;
} }
// 2. 校验文件总大小是否超过500MB
long totalSize = calculateTotalFileSize(downloadMap);
long maxSize = 500 * 1024 * 1024L; // 500MB
if (totalSize > maxSize) {
log.warn("批量下载文件总大小超过限制,总大小:{}MB,限制:500MB", totalSize / 1024 / 1024);
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
String errorMsg = String.format("{\"code\":1,\"msg\":\"下载文件总大小超过限制,当前总大小:%.2fMB,最大允许:500MB\"}",
totalSize / 1024.0 / 1024.0);
response.getWriter().write(errorMsg);
return;
}
// 3. 设置响应头 // 3. 设置响应头
String fileName = "电子档案勾选导出_" + String fileName = "电子档案勾选导出_" +
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".zip"; LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".zip";
...@@ -1131,6 +1157,19 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic ...@@ -1131,6 +1157,19 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic
return; return;
} }
// 2. 校验文件总大小是否超过500MB
long totalSize = calculateTotalFileSize(downloadMap);
long maxSize = 500 * 1024 * 1024L; // 500MB
if (totalSize > maxSize) {
log.warn("批量下载文件总大小超过限制,总大小:{}MB,限制:500MB", totalSize / 1024 / 1024);
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
String errorMsg = String.format("{\"code\":1,\"msg\":\"下载文件总大小超过限制,当前总大小:%.2fMB,最大允许:500MB\"}",
totalSize / 1024.0 / 1024.0);
response.getWriter().write(errorMsg);
return;
}
// 5. 设置响应头 // 5. 设置响应头
String fileName = "电子档案条件导出_" + String fileName = "电子档案条件导出_" +
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".zip"; LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + ".zip";
...@@ -1388,4 +1427,35 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic ...@@ -1388,4 +1427,35 @@ public class TElectronicArchiveDetailServiceImpl extends ServiceImpl<TElectronic
return R.failed("删除失败:" + e.getMessage()); return R.failed("删除失败:" + e.getMessage());
} }
} }
/**
* 计算下载文件总大小
*
* @param downloadMap 下载信息Map
* @return 文件总大小(字节)
*/
private long calculateTotalFileSize(Map<String, ArchiveDownloadInfo> downloadMap) {
long totalSize = 0L;
for (Map.Entry<String, ArchiveDownloadInfo> entry : downloadMap.entrySet()) {
ArchiveDownloadInfo downloadInfo = entry.getValue();
Map<String, List<TAttaInfo>> materialTypeAttaMap = downloadInfo.getMaterialTypeAttaMap();
if (materialTypeAttaMap != null) {
for (Map.Entry<String, List<TAttaInfo>> attaEntry : materialTypeAttaMap.entrySet()) {
List<TAttaInfo> attaList = attaEntry.getValue();
if (CollUtil.isNotEmpty(attaList)) {
for (TAttaInfo atta : attaList) {
if (atta.getAttaSize() != null) {
totalSize += atta.getAttaSize();
}
}
}
}
}
}
log.info("批量下载文件总大小:{}字节({}MB)", totalSize, totalSize / 1024.0 / 1024.0);
return totalSize;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment