|
|
|
@ -188,8 +188,8 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
lineIds.add(lineId); |
|
|
|
} |
|
|
|
logger.info("---归档--lineIds size: {},lineIds:{}", lineIds.size(), lineIds); |
|
|
|
int analyseNum, collectNum; |
|
|
|
AtomicInteger modifyNum = new AtomicInteger(0); |
|
|
|
// int analyseNum, collectNum; |
|
|
|
// AtomicInteger modifyNum = new AtomicInteger(0); |
|
|
|
// List<PatrolResult> resultList = patrolResultService.selectPatrolResultList(new PatrolResult(mainId)); |
|
|
|
List<PatrolResult> resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds); |
|
|
|
if (resultList.isEmpty()) { |
|
|
|
@ -211,24 +211,24 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
return AjaxResult.error("没有缺陷数据, 无需归档!"); |
|
|
|
} |
|
|
|
// List<PatrolResultAux> patrolResultAuxList = iPatrolResultAuxService.selectPatrolResultAuxListByMainId(new PatrolResultAux(mainId)); |
|
|
|
List<PatrolResultAux> patrolResultAuxList = iPatrolResultAuxService.selectPatrolResultAuxListByMainIds(lineIds); |
|
|
|
for (PatrolResultAux aux : patrolResultAuxList) { |
|
|
|
resultList.forEach((item) -> { |
|
|
|
if (aux.getResultId().equals(String.valueOf(item.getLineId()))) { |
|
|
|
item.setValue(aux.getValue()); |
|
|
|
if (!"1".equals(item.getDataType())) { |
|
|
|
modifyNum.addAndGet(1); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// List<PatrolResultAux> patrolResultAuxList = iPatrolResultAuxService.selectPatrolResultAuxListByMainIds(lineIds); |
|
|
|
// for (PatrolResultAux aux : patrolResultAuxList) { |
|
|
|
// resultList.forEach((item) -> { |
|
|
|
// if (aux.getResultId().equals(String.valueOf(item.getLineId()))) { |
|
|
|
// item.setValue(aux.getValue()); |
|
|
|
// if (!"1".equals(item.getDataType())) { |
|
|
|
// modifyNum.addAndGet(1); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// } |
|
|
|
|
|
|
|
startTime = PrintUtil.useTime("INQUIRY MEND DATA", startTime); |
|
|
|
collectNum = resultList.size(); |
|
|
|
// startTime = PrintUtil.useTime("INQUIRY MEND DATA", startTime); |
|
|
|
// collectNum = resultList.size(); |
|
|
|
// analyseNum = resultAnalysisService.selectResultAnalysisByMainId(lineId); |
|
|
|
analyseNum = resultAnalysisService.selectResultAnalysisByMainIds(lineIds); |
|
|
|
startTime = PrintUtil.useTime("INQUIRY ANALYZE DATA", startTime); |
|
|
|
logger.info("[ARCHIVE] Id: {}, collectNum: {}, analyseNum: {}, modifyNum:{}", mainId, collectNum, analyseNum, modifyNum.get()); |
|
|
|
// analyseNum = resultAnalysisService.selectResultAnalysisByMainIds(lineIds); |
|
|
|
// startTime = PrintUtil.useTime("INQUIRY ANALYZE DATA", startTime); |
|
|
|
// logger.info("[ARCHIVE] Id: {}, collectNum: {}, analyseNum: {}, modifyNum:{}", mainId, collectNum, analyseNum, modifyNum.get()); |
|
|
|
|
|
|
|
// 使用CompletableFuture异步执行saveReport |
|
|
|
int finalAiQxNum = aiQxNum; |
|
|
|
@ -240,7 +240,7 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
logger.error("Report saving failed", ex); |
|
|
|
return Collections.emptyList(); |
|
|
|
}); |
|
|
|
|
|
|
|
PrintUtil.useTime("saveReport", startTime); |
|
|
|
// 当saveReport完成后,再异步处理所有导出任务 |
|
|
|
saveReportFuture.thenAcceptAsync(reportIds -> { |
|
|
|
logger.info("-----------[ARCHIVE] Saved export reportIds: {}", reportIds); |
|
|
|
@ -260,6 +260,7 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
logger.error("Error occurred during saveReport: ", ex); |
|
|
|
return null; |
|
|
|
}); |
|
|
|
PrintUtil.useTime("exportExcelWordAndZip", startTime); |
|
|
|
// logger.info("-----------[ARCHIVE] EndTime: {}, reportIds: {}", DateUtil.now(), reportIds); |
|
|
|
return toAjax(1); |
|
|
|
|
|
|
|
@ -788,7 +789,7 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
images.add(originalImgSrc); |
|
|
|
String pointName = reportData.getPointName(); |
|
|
|
pointName = (pointName != null) ? pointName : "unnamed"; |
|
|
|
PatrolResult patrolResult = patrolResultService.selectPatrolResultByDeviceName(pointName); |
|
|
|
// PatrolResult patrolResult = patrolResultService.selectPatrolResultByDeviceName(pointName); |
|
|
|
// 提取文件扩展名 |
|
|
|
String extension = ""; |
|
|
|
int dotIndex = originalImgSrc.lastIndexOf('.'); |
|
|
|
@ -798,7 +799,7 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
|
|
|
|
// 生成唯一文件名(包含 lineId 防止重复) |
|
|
|
String uniqueFileName = String.format("%s_%s_%s_%d%s", |
|
|
|
(patrolResult != null ? patrolResult.getDeviceId() : ""), |
|
|
|
originalImgSrc.split("_")[2], |
|
|
|
pointName, |
|
|
|
reportData.getLineId(), |
|
|
|
imgIndex, |
|
|
|
@ -811,27 +812,27 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, byte[]> streamHashMap = new HashMap<>(); |
|
|
|
// for (String algorithmBaseImagePath : images) { |
|
|
|
// try { |
|
|
|
// sftpClient.downLoad(algorithmBaseImagePath, (inputStream) -> { |
|
|
|
// byte[] bytes = streamHashMap.get(algorithmBaseImagePath); |
|
|
|
// byte[] byInputStream = getStringByInputStream(inputStream); |
|
|
|
// if (bytes == null) { |
|
|
|
// streamHashMap.put(algorithmBaseImagePath, byInputStream); |
|
|
|
// } |
|
|
|
// |
|
|
|
// }); |
|
|
|
// } catch (Exception e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
images.parallelStream().forEach(imagePath -> { |
|
|
|
byte[] shm = streamHashMap.get(imagePath); |
|
|
|
byte[] bytes = downloadAndCompressImage(imagePath); |
|
|
|
if (shm == null) { |
|
|
|
streamHashMap.put(imagePath, bytes); |
|
|
|
for (String algorithmBaseImagePath : images) { |
|
|
|
try { |
|
|
|
sftpClient.downLoad(algorithmBaseImagePath, (inputStream) -> { |
|
|
|
byte[] bytes = streamHashMap.get(algorithmBaseImagePath); |
|
|
|
byte[] byInputStream = getStringByInputStream(inputStream); |
|
|
|
if (bytes == null) { |
|
|
|
streamHashMap.put(algorithmBaseImagePath, byInputStream); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// images.parallelStream().forEach(imagePath -> { |
|
|
|
// byte[] shm = streamHashMap.get(imagePath); |
|
|
|
// byte[] bytes = downloadAndCompressImage(imagePath); |
|
|
|
// if (shm == null) { |
|
|
|
// streamHashMap.put(imagePath, bytes); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -851,28 +852,37 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
} |
|
|
|
String reportName = namePrefix + inspectionReport.getInspectionTaskName() + "_" + timestamp; |
|
|
|
// 上传媒体包 |
|
|
|
uploadFile(basePath, reportName, ".zip", outputStream -> { |
|
|
|
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(pointFileName); |
|
|
|
zipOut.putNextEntry(zipEntry); |
|
|
|
zipOut.write(imageData); |
|
|
|
zipOut.closeEntry(); |
|
|
|
CompletableFuture<Void> zipUploadFuture = CompletableFuture.runAsync(() -> { |
|
|
|
uploadFile(basePath, reportName, ".zip", outputStream -> { |
|
|
|
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(pointFileName); |
|
|
|
zipOut.putNextEntry(zipEntry); |
|
|
|
zipOut.write(imageData); |
|
|
|
zipOut.closeEntry(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException("生成ZIP文件失败", e); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException("生成ZIP文件失败", e); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, executor); |
|
|
|
// 上传Excel |
|
|
|
uploadFile(basePath, reportName, ".xls", sxssfWorkbook::write); |
|
|
|
CompletableFuture<Void> excelUploadFuture = CompletableFuture.runAsync(() -> { |
|
|
|
uploadFile(basePath, reportName, ".xls", sxssfWorkbook::write); |
|
|
|
}, executor); |
|
|
|
// 上传Word |
|
|
|
uploadFile(basePath, reportName, ".docx", wordDocument::write); |
|
|
|
inspectionReport.setFilePath(basePath + reportName + ".xls"); |
|
|
|
inspectionReportService.updateInspectionReport(inspectionReport); |
|
|
|
CompletableFuture<Void> wordUploadFuture = CompletableFuture.runAsync(() -> { |
|
|
|
uploadFile(basePath, reportName, ".docx", wordDocument::write); |
|
|
|
}, executor); |
|
|
|
CompletableFuture.allOf(zipUploadFuture, excelUploadFuture, wordUploadFuture).whenComplete((v, t) -> { |
|
|
|
inspectionReport.setFilePath(basePath + reportName + ".xls"); |
|
|
|
inspectionReportService.updateInspectionReport(inspectionReport); |
|
|
|
}); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|