|
|
|
@ -208,7 +208,7 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
(new Thread(() -> { |
|
|
|
long beginTime = (new Date()).getTime(); |
|
|
|
logger.info("[EXPORT REPORTS] StartTime: {}, reportId: {}", DateUtil.now(), reportId); |
|
|
|
exportExcelAndWord(String.valueOf(reportId)); |
|
|
|
exportExcelWordAndZip(String.valueOf(reportId)); |
|
|
|
PrintUtil.useTime("EXPORT REPORTS END", beginTime); |
|
|
|
})).start(); |
|
|
|
return toAjax(1); |
|
|
|
@ -672,8 +672,9 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void exportExcelAndWord(String lineId) { |
|
|
|
public void exportExcelWordAndZip(String lineId) { |
|
|
|
List<String> images = new ArrayList<>(); |
|
|
|
Map<String, String> imgSrcToFileNameMap = new HashMap<>(); |
|
|
|
InspectionReport inspectionReport = |
|
|
|
inspectionReportService.selectInspectionReportByLineId(Long.valueOf(lineId)); |
|
|
|
InspectionReportData inspectionReportData = new InspectionReportData(); |
|
|
|
@ -690,9 +691,31 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
List<InspectionReportImg> reportImgList = |
|
|
|
inspectionReportImgService.selectInspectionReportImgList(inspectionReportImg); |
|
|
|
reportData.setReportImgList(reportImgList); |
|
|
|
|
|
|
|
int imgIndex = 1; // 每个报告数据项下的图片索引 |
|
|
|
for (InspectionReportImg reportImg : reportImgList) { |
|
|
|
if (StringUtils.isNotEmpty(reportImg.getImgSrc()) && reportImg.getImgType().equals("0")) { |
|
|
|
images.add(reportImg.getImgSrc()); |
|
|
|
String originalImgSrc = reportImg.getImgSrc(); |
|
|
|
images.add(originalImgSrc); |
|
|
|
String pointName = reportData.getPointName(); |
|
|
|
pointName = (pointName != null) ? pointName : "unnamed"; |
|
|
|
|
|
|
|
// 提取文件扩展名 |
|
|
|
String extension = ""; |
|
|
|
int dotIndex = originalImgSrc.lastIndexOf('.'); |
|
|
|
if (dotIndex > 0) { |
|
|
|
extension = originalImgSrc.substring(dotIndex); |
|
|
|
} |
|
|
|
|
|
|
|
// 生成唯一文件名(包含 lineId 防止重复) |
|
|
|
String uniqueFileName = String.format("%s_%s_%d%s", |
|
|
|
pointName, |
|
|
|
reportData.getLineId(), |
|
|
|
imgIndex, |
|
|
|
extension); |
|
|
|
|
|
|
|
imgSrcToFileNameMap.put(originalImgSrc, uniqueFileName); |
|
|
|
imgIndex++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -728,10 +751,10 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
try (ZipOutputStream zipOut = new ZipOutputStream(outputStream)) { |
|
|
|
for (Map.Entry<String, byte[]> entry : streamHashMap.entrySet()) { |
|
|
|
String imagePath = entry.getKey(); |
|
|
|
String pointFileName = imgSrcToFileNameMap.getOrDefault(imagePath, "unnamed"); |
|
|
|
byte[] imageData = entry.getValue(); |
|
|
|
// 提取文件名并处理路径问题 |
|
|
|
String fileName = new File(imagePath).getName(); |
|
|
|
ZipEntry zipEntry = new ZipEntry(fileName); |
|
|
|
// String fileName = new File(imagePath).getName(); |
|
|
|
ZipEntry zipEntry = new ZipEntry(pointFileName); |
|
|
|
zipOut.putNextEntry(zipEntry); |
|
|
|
zipOut.write(imageData); |
|
|
|
zipOut.closeEntry(); |
|
|
|
|