From 2f7828173ab5b06409d1992f8e448cc31fa8cc32 Mon Sep 17 00:00:00 2001 From: WangGuangYuan Date: Fri, 15 Aug 2025 17:43:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=8D=E5=85=B4bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PatrolResultServiceImpl.java | 4 +- .../PatrolTaskResultMainController.java | 130 ++++++++++-------- .../task/controller/PatrolTaskController.java | 41 +++--- 3 files changed, 93 insertions(+), 82 deletions(-) diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/impl/PatrolResultServiceImpl.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/impl/PatrolResultServiceImpl.java index b2115d7..5a2afa6 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/impl/PatrolResultServiceImpl.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/impl/PatrolResultServiceImpl.java @@ -541,11 +541,11 @@ public class PatrolResultServiceImpl implements IPatrolResultService { patrolResultRefs = patrolResultRefs.stream().filter((item) -> "0".equals(item.getResultType())).collect(Collectors.toList()); } - log.info("batchInsertReportData patrolResultRefs:" + patrolResultRefs); +// log.info("batchInsertReportData patrolResultRefs:" + patrolResultRefs); startTime = PrintUtil.useTime("SELECT RESULT", startTime); // List basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainId(mainId); List basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(mainIds); - log.info("batchInsertReportData basePointAreaInfoList:" + basePointAreaInfoList); +// log.info("batchInsertReportData basePointAreaInfoList:" + basePointAreaInfoList); PrintUtil.useTime("AREA INQUERY", startTime); log.info("REPORTS SIZE: {}", patrolResultRefs.size()); List reportDatas = new ArrayList<>(); diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/resultmain/controller/PatrolTaskResultMainController.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/resultmain/controller/PatrolTaskResultMainController.java index a493ede..6b9253a 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/resultmain/controller/PatrolTaskResultMainController.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/resultmain/controller/PatrolTaskResultMainController.java @@ -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 resultList = patrolResultService.selectPatrolResultList(new PatrolResult(mainId)); List resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds); if (resultList.isEmpty()) { @@ -211,24 +211,24 @@ public class PatrolTaskResultMainController extends BaseController { return AjaxResult.error("没有缺陷数据, 无需归档!"); } // List patrolResultAuxList = iPatrolResultAuxService.selectPatrolResultAuxListByMainId(new PatrolResultAux(mainId)); - List 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 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 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 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 zipUploadFuture = CompletableFuture.runAsync(() -> { + uploadFile(basePath, reportName, ".zip", outputStream -> { + try (ZipOutputStream zipOut = new ZipOutputStream(outputStream)) { + for (Map.Entry 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 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 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(); } diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java index bc020d2..3054074 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/task/controller/PatrolTaskController.java @@ -132,20 +132,20 @@ public class PatrolTaskController extends BaseController { } else { task.setFileStatus("0"); } - String areaIdS = task.getAreaIdS(); - AjaxResult ajaxResult = FeignBasedataAreaService.list((new JSONObject()).fluentPut("areaIdS", areaIdS)); - JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(ajaxResult)); - // 检查响应是否成功 - if ("200".equals(ajaxResult.get("code").toString())) { - JSONArray data = jsonObject.getJSONArray("data"); - if (data != null && !data.isEmpty()) { - List areaNames = data.stream() - .filter(item -> "station_in".equals(((JSONObject) item).getString("areaType"))) - .map(item -> ((JSONObject) item).getString("areaName")) - .collect(Collectors.toList()); - task.setAreaName(StringUtils.join(areaNames, StringUtils.COMMA)); - } - } +// String areaIdS = task.getAreaIdS(); +// AjaxResult ajaxResult = FeignBasedataAreaService.list((new JSONObject()).fluentPut("areaIdS", areaIdS)); +// JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(ajaxResult)); +// // 检查响应是否成功 +// if ("200".equals(ajaxResult.get("code").toString())) { +// JSONArray data = jsonObject.getJSONArray("data"); +// if (data != null && !data.isEmpty()) { +// List areaNames = data.stream() +// .filter(item -> "station_in".equals(((JSONObject) item).getString("areaType"))) +// .map(item -> ((JSONObject) item).getString("areaName")) +// .collect(Collectors.toList()); +// task.setAreaName(StringUtils.join(areaNames, StringUtils.COMMA)); +// } +// } } if (StringUtils.isNotEmpty(patrolTask.getAreaName())) { @@ -543,6 +543,7 @@ public class PatrolTaskController extends BaseController { jsonText = message; try { patrolTaskList = JSONArray.parseArray("[" + message + "]", PatrolTask.class); + patrolTaskList = toPatrolTaskList(parseObject, flag); //eqList = JSONArray.parseArray(message + "", PatrolTask.class); } catch (Exception e) { logger.warn("2 Exception: {}", e.getMessage()); @@ -1725,12 +1726,12 @@ public class PatrolTaskController extends BaseController { } } - if (jsonObject.get("areaName") != null) { - jsonObjectString = jsonObject.get("areaName").toString(); - if (StringUtils.isNotEmpty(jsonObjectString)) { - patrolTask.setAreaName(jsonObjectString); - } - } +// if (jsonObject.get("areaName") != null) { +// jsonObjectString = jsonObject.get("areaName").toString(); +// if (StringUtils.isNotEmpty(jsonObjectString)) { +// patrolTask.setAreaName(jsonObjectString); +// } +// } if (jsonObject.get("stationCode") != null) { jsonObjectString = jsonObject.get("stationCode").toString();