diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/IPatrolResultService.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/IPatrolResultService.java index b7e592a..80b6de7 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/IPatrolResultService.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/IPatrolResultService.java @@ -86,7 +86,7 @@ public interface IPatrolResultService { List saveReportLingzhou_v2(PatrolTaskResultMain resultMain, List lineIds, Long currentLineId, List resultList); - List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, Long currentLineId, List resultList, int aiQxNum, int csQxNum); + List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, Long currentLineId, List resultList); List saveReportV2(PatrolTaskResultMain patrolTaskResultMain, List patrolResultList); 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 862e09c..083aafb 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 @@ -6,7 +6,6 @@ import com.alibaba.fastjson.JSONObject; import com.inspect.analysis.domain.AlgValue; import com.inspect.analysis.domain.AnalyseResPoint; import com.inspect.analysis.domain.ResultAnalysis; -import com.inspect.analysis.domain.resultList; import com.inspect.analysis.mapper.ResultAnalysisMapper; import com.inspect.base.core.constant.AlgConstants; import com.inspect.base.core.exception.ServiceException; @@ -30,7 +29,6 @@ import com.inspect.patrolresultdefault.mapper.PatrolResultDefaultValueMapper; import com.inspect.resultmain.domain.PatrolTaskResultMain; import com.inspect.resultmain.mapper.PatrolTaskResultMainMapper; import com.inspect.system.base.openDomain.BasedataEqpBookMoMain; -import com.inspect.system.base.openDomain.PatrolTaskDomain; import com.inspect.task.domain.PatrolData; import com.inspect.task.domain.PatrolTask; import com.inspect.task.mapper.PatrolTaskMapper; @@ -503,23 +501,20 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } @Transactional - public List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, Long currentLineId, List resultList, int aiQxNum, int csQxNum) { + public List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, Long currentLineId, List resultList) { long startTime = System.currentTimeMillis(); List reportIds = new ArrayList<>(); -// String mainId = String.valueOf(resultMain.getLineId()); for (Long lineId : lineIds) { resultMain.setLineId(lineId); resultMain.setCheckTime(new Date()); resultMain.setFileStatus("1"); this.patrolTaskResultMainMapper.updatePatrolTaskResultMain(resultMain); this.patrolResultMapper.updatePatrolResultByMainId(String.valueOf(lineId)); - reportIds.addAll(saveReportDataShaoxing(resultList, resultMain, lineIds, aiQxNum, csQxNum)); + reportIds.addAll(saveReportDataShaoxing(resultList, resultMain, lineIds)); } PrintUtil.useTime("获取所有报告id", startTime); return reportIds; -// resultMain.setLineId(currentLineId); -// return saveReportData(resultList, resultMain, lineIds); } @Transactional @@ -617,15 +612,9 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } } - public List saveReportDataShaoxing(List resultList, PatrolTaskResultMain resultMain, List lineIds, int aiQxNum, int csQxNum) { + public List saveReportDataShaoxing(List resultList, PatrolTaskResultMain resultMain, List lineIds) { long startTime = System.currentTimeMillis(); String mainId = String.valueOf(resultMain.getLineId()); -// String analyseNum = statisticsAnalyseNum(lineIds, resultList.size()); -// String filterNum = statisticsAnalyseNumLingZhou(lineIds, "1"); - String AiNum = statisticsAnalyseNumShaoxing(lineIds); -// String[] nums = new String[]{AiNum, filterNum}; - String[] nums = new String[]{AiNum}; - startTime = PrintUtil.useTime("STATISTICS ANALYZE DATA", startTime); if (resultList.isEmpty()) { throw new ServiceException("LACK INSPECT RESULT: " + mainId); } else { @@ -651,15 +640,6 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } else { List reportIds = new ArrayList<>(); PatrolTask task = list.get(0); -// List reports = inspectionReportMapper.selectInspectionReportList(new InspectionReport(mainId)); -// startTime = PrintUtil.useTime("INQUIRY TASK REPORT", startTime); -// InspectionReport report; -// if (!reports.isEmpty()) { -// report = reports.get(0); -// resetReport(report, analyseNum, mainId, task, taskStatus); -// inspectionReportMapper.updateInspectionReport(report); -// PrintUtil.useTime("MODIFY TASK REPORT", startTime); -// } else { Map stationMap = patrolResultMapper.selectBasedataStation(); String stationName = stationMap.get("station_name"); String stationType = stationMap.get("station_type"); @@ -676,44 +656,184 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } envoList.add(typeName + ":" + valueUnit); } - for (int i = 0; i < nums.length; i++) { - if ("0".equals(exportReportFlag) && aiQxNum == 0 && csQxNum == 0) { - continue; + + List patrolResultRefs = patrolResultMapper.selectResultRefByLineIds(lineIds, null); + Map> groupKeyListMap; + if ("0".equals(exportReportFlag)) { + List resultRefs = new ArrayList<>(); + // 只导出缺陷 + patrolResultRefs = patrolResultRefs.stream().filter((item) -> "0".equals(item.getResultType())).collect(Collectors.toList()); + // 分组,按点位ID和算法类型进行分组 + groupKeyListMap = patrolResultRefs.stream().collect(Collectors.groupingBy(item -> new GroupKey(item.getDeviceId(), item.getAlgType(), item.getTaskPatrolledId()))); + groupKeyListMap.forEach((key, value) -> { + PatrolResultRef patrolResultRef = new PatrolResultRef(); + patrolResultRef.setDeviceId(key.objectId); + patrolResultRef.setAlgType(key.algType); + patrolResultRef.setDescription(value.stream().sorted(Comparator.comparing(PatrolResultRef::getFilter).reversed()).map(PatrolResultRef::getDescription).collect(Collectors.joining(","))); + patrolResultRef.setValue(value.stream().sorted(Comparator.comparing(PatrolResultRef::getFilter).reversed()).map(PatrolResultRef::getValue).collect(Collectors.joining(","))); + for (PatrolResultRef resultRef : value) { + // 初筛有缺陷,展示初筛结果 + if ("1".equals(resultRef.getFilter()) && StringUtils.isEmpty(patrolResultRef.getResultContent())) { + patrolResultRef.setResultContent(resultRef.getResultContent()); + } + if ("1".equals(resultRef.getFilter()) && StringUtils.isEmpty(patrolResultRef.getFilePath())) { + patrolResultRef.setFilePath(resultRef.getFilePath()); + } + // 大模型有缺陷,展示大模型结果 + if ("0".equals(resultRef.getFilter())) { + patrolResultRef.setResultContent(resultRef.getResultContent()); + patrolResultRef.setFilePath(resultRef.getFilePath()); + } + } + patrolResultRef.setDevType(value.stream().map(item -> item.getDevType() != null ? item.getDevType() : "").distinct().findFirst().orElse("")); + patrolResultRef.setDeviceSource(value.stream().map(item -> item.getDeviceSource() != null ? item.getDeviceSource() : "").distinct().findFirst().orElse("")); + patrolResultRef.setTime(value.stream().map(item -> item.getTime() != null ? item.getTime() : "").distinct().findFirst().orElse("")); + patrolResultRef.setThreshold(value.stream().map(item -> item.getThreshold() != null ? item.getThreshold() : "").distinct().findFirst().orElse("")); + patrolResultRef.setAlgName(value.get(0).getAlgName()); + patrolResultRef.setResultType("0"); + resultRefs.add(patrolResultRef); + }); + patrolResultRefs = resultRefs; + } else { + groupKeyListMap = patrolResultRefs.stream().collect(Collectors.groupingBy(item -> new GroupKey(item.getDeviceId(), item.getAlgType(), item.getTaskPatrolledId()))); + List processedRefs = new ArrayList<>(); + for (Map.Entry> entry : groupKeyListMap.entrySet()) { + List value = entry.getValue(); + GroupKey key = entry.getKey(); + String algType = key.algType; + List filterResults = value.stream().filter(item -> "1".equals(item.getFilter())).collect(Collectors.toList()); + List AIResults = value.stream().filter(item -> "0".equals(item.getFilter())).collect(Collectors.toList()); + PatrolResultRef filterResult = filterResults.isEmpty() ? null : filterResults.get(0); + PatrolResultRef AIResult = AIResults.isEmpty() ? null : AIResults.get(0); + + if (AlgConstants.METER.equalsIgnoreCase(algType)) { + // 表计处理 + if (filterResult != null && AIResult != null) { + String filterResultType = filterResult.getResultType(); + String AIResultType = AIResult.getResultType(); + if ("1".equals(filterResultType)) { // 初筛正常 + // 只归档大模型 + processedRefs.add(AIResult); + } else if ("0".equals(filterResultType)) { // 初筛缺陷 + if ("1".equals(AIResultType)) { + // 分开:初筛缺陷,大模型正常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("0".equals(AIResultType)) { + // 合并:初筛缺陷,大模型缺陷 + PatrolResultRef merged = mergePatrolResultRef(filterResult, AIResult, "0"); + processedRefs.add(merged); + } else if ("2".equals(AIResultType)) { + // 分开:初筛缺陷,大模型异常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else if ("2".equals(filterResultType)) { // 初筛异常 + if ("1".equals(AIResultType)) { + // 分开:初筛异常,大模型正常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("0".equals(AIResultType)) { + // 分开:初筛异常,大模型缺陷 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("2".equals(AIResultType)) { + // 合并:初筛异常,大模型异常 + PatrolResultRef merged = mergePatrolResultRef(filterResult, AIResult, "2"); + processedRefs.add(merged); + } + } else { + // 未知类型,都添加 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else if (filterResult != null) { + processedRefs.add(filterResult); + } else if (AIResult != null) { + processedRefs.add(AIResult); + } + } else { + // 外观处理 + if (filterResult != null && AIResult != null) { + String filterResultType = filterResult.getResultType(); + String AIResultType = AIResult.getResultType(); + if ("0".equals(filterResultType)) { // 初筛缺陷 + if ("1".equals(AIResultType)) { + // 分开:初筛缺陷,大模型正常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("0".equals(AIResultType)) { + // 合并:初筛缺陷,大模型缺陷 + PatrolResultRef merged = mergePatrolResultRef(filterResult, AIResult, "0"); + processedRefs.add(merged); + } else if ("2".equals(AIResultType)) { + // 分开:初筛缺陷,大模型异常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else { + // 未知,都添加 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else { + // 初筛不是缺陷但有大模型(理论上不应出现),为保数据完整都添加 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else if (filterResult != null) { + processedRefs.add(filterResult); + } else if (AIResult != null) { + processedRefs.add(AIResult); + } + } } -// Map keyPatrolResultRef = new HashMap<>(); - List patrolResultRefs = patrolResultMapper.selectResultRefByLineIds(lineIds, null); -// for (PatrolResultRef AIRef : patrolResultRefs) { -// keyPatrolResultRef.put(AIRef.getDeviceId() + "_" + AIRef.getAlgType(), AIRef); -// } -// for (PatrolResultRef filterRef : patrolResultRefsFilter) { -// keyPatrolResultRef.putIfAbsent(filterRef.getDeviceId() + "_" + filterRef.getAlgType(), filterRef); -// } -// patrolResultRefs = new ArrayList<>(keyPatrolResultRef.values()); - if (patrolResultRefs.isEmpty()) { + patrolResultRefs = processedRefs; + } + long okNum = 0L; + long failNum = 0L; + long defectNum = 0L; + for (PatrolResultRef patrolResultRef : patrolResultRefs) { + String resultType = patrolResultRef.getResultType(); + if(resultType == null) { continue; + } else if (resultType.equals("0")) { + // 缺陷编号 + ++defectNum; + } else if (resultType.equals("1")) { + // 正常编号 + ++okNum; + } else { + // 异常编号 + ++failNum; } - InspectionReport report = new InspectionReport(); - resetReport(report, nums[i], mainId, task, taskStatus); - report.setTaskId(String.valueOf(task.getTaskId())); - report.setEnvInfo(StringUtils.join(envoList,",")); - report.setTaskPatrolledId(taskPatrolId); - report.setInspectionTaskName(taskName); - report.setDescription(resultMain.getTaskResult()); - report.setCheckPerson(resultMain.getCheckPerson()); - report.setCheckTime(resultMain.getCheckTime()); - report.setStationName(stationName); - report.setVoltLevel(StringUtils.isEmpty(voltLevel) ? voltage : voltLevel); - report.setFilter(String.valueOf(i)); - report.setStationType(stationType); - inspectionReportMapper.insertInspectionReport(report); - PrintUtil.useTime("NEW TASK REPORT", startTime); - batchInsertReportData(String.valueOf(report.getLineId()), lineIds, String.valueOf(i), patrolResultRefs); - PrintUtil.useTime("BATCH INSERT DETAIL", startTime); - log.info("[ARCHIVE] reportId: {}", report.getLineId()); - Long lineId = report.getLineId(); - reportIds.add(lineId); } -// } + String patrolStatistics; + if ("0".equals(exportReportFlag)) { + patrolStatistics = String.format(messageUtils.get("缺陷数量:%d个。"), defectNum); + } else { + patrolStatistics = String.format(messageUtils.get("本次任务巡视总结果数量:%d个,正常结果数量:%d个,异常结果数量:%d个,缺陷结果数量:%d个。"), patrolResultRefs.size(), okNum, failNum, defectNum); + } + InspectionReport report = new InspectionReport(); + resetReport(report, patrolStatistics, mainId, task, taskStatus); + report.setTaskId(String.valueOf(task.getTaskId())); + report.setEnvInfo(StringUtils.join(envoList,",")); + report.setTaskPatrolledId(taskPatrolId); + report.setInspectionTaskName(taskName); + report.setDescription(resultMain.getTaskResult()); + report.setCheckPerson(resultMain.getCheckPerson()); + report.setCheckTime(resultMain.getCheckTime()); + report.setStationName(stationName); + report.setVoltLevel(StringUtils.isEmpty(voltLevel) ? voltage : voltLevel); + report.setFilter("0"); + report.setStationType(stationType); + inspectionReportMapper.insertInspectionReport(report); + PrintUtil.useTime("NEW TASK REPORT", startTime); + batchInsertReportData_shaoxing(String.valueOf(report.getLineId()), lineIds, "0", patrolResultRefs); + PrintUtil.useTime("BATCH INSERT DETAIL", startTime); + log.info("[ARCHIVE] reportId: {}", report.getLineId()); + Long lineId = report.getLineId(); + reportIds.add(lineId); + return reportIds; } } @@ -1108,6 +1228,124 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } } + public void batchInsertReportData_shaoxing(String reportId, List mainIds, String filter, List patrolResultRefs) { + log.info("batchInsertReportData reportId:" + reportId + ", mainIds:" + mainIds + ", filter:" + filter); + long startTime = System.currentTimeMillis(); + + List basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(mainIds); + log.info("REPORTS SIZE: {}", patrolResultRefs.size()); + List reportDatas = new ArrayList<>(); + List reportImages = new ArrayList<>(); + + long okNum = 0L; + long failNum = 0L; + long defectNum = 0L; + int index; + for (index = 0; index < patrolResultRefs.size(); ++index) { + PatrolResultRef patrolResultRef = patrolResultRefs.get(index); + String devType = patrolResultRef.getDevType(); + BasePointAreaInfo basePointAreaInfo; + try { + basePointAreaInfo = basePointAreaInfoList.stream().filter((item) -> item != null && patrolResultRef.getDeviceId().equals(item.getDeviceId())).findFirst().get(); + } catch (Exception e) { + log.error("[REPORT DETAIL] The point lacking belonging area: {}", patrolResultRef.getDeviceId()); + basePointAreaInfo = new BasePointAreaInfo(); + } + + InspectionReportData reportData = new InspectionReportData(); + reportData.setReportId(reportId); + reportData.setArea(basePointAreaInfo.getAreaName()); + reportData.setTimeInterval(basePointAreaInfo.getJgName()); + reportData.setEqName(basePointAreaInfo.getMainName()); + reportData.setParts(basePointAreaInfo.getDeviceName()); + reportData.setPointName(basePointAreaInfo.getPatrolPointName()); + reportData.setDataSources(patrolResultRef.getDeviceSource()); + reportData.setAcquisitionTime(DateUtils.parse(DateUtils.yyyyMMddHHmmss2, patrolResultRef.getTime())); + if ("1".equals(patrolResultRef.getResultType()) && validAlgTypes.contains(patrolResultRef.getAlgType())) { + reportData.setInspectionResults(patrolResultRef.getValue()); + } else { + reportData.setInspectionResults(patrolResultRef.getDescription()); + } + reportData.setAlgName(patrolResultRef.getAlgName()); + String threshold = patrolResultRef.getThreshold(); + if(StringUtils.isBlank(threshold)) { + threshold = ""; + } + if ("1".equals(patrolResultRef.getResultType()) && threshold.contains("sub_53")) { + reportData.setInspectionResults(patrolResultRef.getValue()); + } + + if ("1".equals(patrolResultRef.getResultType()) && (threshold.contains("sub_52") || threshold.contains("sub_53")) + && !"0".equals(patrolResultRef.getValue()) + && !"1".equals(patrolResultRef.getValue()) + && !"-1".equals(patrolResultRef.getValue()) + && !"check image".equals(patrolResultRef.getValue())) { + reportData.setInspectionResults(patrolResultRef.getValue()); + } + + String pointStatus = patrolResultRef.getPointStatus(); + String resultType = patrolResultRef.getResultType(); + log.info("[RESULT] resultType: {}, patrolResultRef: {}", resultType, patrolResultRef); + if(resultType == null) { + continue; + } else if (resultType.equals("0")) { + reportData.setPointStatus(messageUtils.get("缺陷")); + // 缺陷编号 + ++defectNum; + reportData.setCode(defectNum); + } else if (resultType.equals("1")) { + reportData.setPointStatus(messageUtils.get("正常")); + ++okNum; + reportData.setCode(okNum); + } else { + reportData.setPointStatus(messageUtils.get("异常")); + // 异常编号 + ++failNum; + reportData.setCode(failNum); + } + + final String reportDataId = reportId + "_" + (100000 + index); + reportData.setLineId(reportDataId); + reportDatas.add(reportData); + log.info("batchInsertReportData reportData:" + reportData); + String resultContent = patrolResultRef.getResultContent(); + //List results = JSONObject.parseObject(resultContent).getJSONArray("resultList").toJavaList(resultList.class); + //String imgUrl = results.get(0).getResults().get(0).getResImageUrl(); + AnalyseResPoint analyseResPoint = JSONObject.parseObject(resultContent, AnalyseResPoint.class); + String imgUrl = analyseResPoint.getResImageUrl(); + + if (StringUtils.isEmpty(imgUrl)) { + imgUrl = patrolResultRef.getFilePath().split(StringUtils.COMMA)[0]; + } + + InspectionReportImg reportImg = new InspectionReportImg(); + reportImg.setReportInfoId(reportDataId); + reportImg.setImg(imgUrl); + reportImg.setImgSrc(imgUrl); + reportImg.setImgType("0"); + reportImg.setCreatTime(new Date()); + reportImages.add(reportImg); + log.info("batchInsertReportData reportImg:" + reportImg); + } + + index = reportDatas.size() / 50; + if (reportDatas.size() % 50 > 0) { + ++index; + } + + log.info("[REPORT] BATCH INSERT PROGRESS: reportDatas size: {}", reportDatas.size()); + for (int j = 0; j < reportDatas.size(); j += 50) { + log.info("[REPORT] BATCH INSERT PROGRESS: {}/{}", j / 50 + 1, j % 50 + 1); + int end = j + 50; + if (end > reportDatas.size() - 1) { + end = reportDatas.size(); + } + + inspectionReportDataMapper.batchInsertInspectionReportData(reportDatas.subList(j, end)); + inspectionReportImgMapper.batchInsertInspectionReportImg(reportImages.subList(j, end)); + } + } + public void batchInsertReportData_Lingzhou(String reportId, List basePointAreaInfoList, String filter, List patrolResultRefs) { long startTime = System.currentTimeMillis(); if ("0".equals(exportReportFlag)) { @@ -1601,7 +1839,7 @@ public class PatrolResultServiceImpl implements IPatrolResultService { public InspectionReport getInspectionReport(List lineIds, PatrolTaskResultMain patrolTaskResultMain) { List taskPatrolledIds = patrolTaskResultMain.getTaskPatrolledIds(); // 巡视统计描述 - String patrolStatistics = statisticsAnalyseNumShaoxing(lineIds); + String patrolStatistics = ""; // 查询任务状态信息 List patrolTaskStatuses = patrolTaskStatusMapper.selectPatrolTaskStatusListByTaskPatrolledIds(taskPatrolledIds); List startTimes = patrolTaskStatuses.stream().map(PatrolTaskStatus::getStartTime).sorted().collect(Collectors.toList()); @@ -1630,8 +1868,6 @@ public class PatrolResultServiceImpl implements IPatrolResultService { InspectionReport report = new InspectionReport(); report.setInspectionDate(new Date()); -// report.setTaskResultId(mainId); - report.setPatrolStatistics(patrolStatistics); report.setInspectionStartTime(startTimes.get(0)); report.setInspectionEndTime(DateUtils.parseDate(endTimes.get(endTimes.size() - 1))); // report.setTaskId(String.valueOf(task.getTaskId())); @@ -1645,13 +1881,13 @@ public class PatrolResultServiceImpl implements IPatrolResultService { report.setVoltLevel(StringUtils.isEmpty(voltLevel) ? voltage : voltLevel); // report.setFilter(String.valueOf(i)); report.setStationType(stationType); - + Map> groupKeyListMap; if ("0".equals(exportReportFlag)) { List resultRefs = new ArrayList<>(); // 只导出缺陷 patrolResultRefs = patrolResultRefs.stream().filter((item) -> "0".equals(item.getResultType())).collect(Collectors.toList()); // 分组,按点位ID和算法类型进行分组 - Map> groupKeyListMap = patrolResultRefs.stream().collect(Collectors.groupingBy(item -> new GroupKey(item.getDeviceId(), item.getAlgType(), item.getTaskPatrolledId()))); + groupKeyListMap = patrolResultRefs.stream().collect(Collectors.groupingBy(item -> new GroupKey(item.getDeviceId(), item.getAlgType(), item.getTaskPatrolledId()))); groupKeyListMap.forEach((key, value) -> { PatrolResultRef patrolResultRef = new PatrolResultRef(); patrolResultRef.setDeviceId(key.objectId); @@ -1681,6 +1917,100 @@ public class PatrolResultServiceImpl implements IPatrolResultService { resultRefs.add(patrolResultRef); }); patrolResultRefs = resultRefs; + } else { + groupKeyListMap = patrolResultRefs.stream().collect(Collectors.groupingBy(item -> new GroupKey(item.getDeviceId(), item.getAlgType(), item.getTaskPatrolledId()))); + List processedRefs = new ArrayList<>(); + for (Map.Entry> entry : groupKeyListMap.entrySet()) { + List value = entry.getValue(); + GroupKey key = entry.getKey(); + String algType = key.algType; + List filterResults = value.stream().filter(item -> "1".equals(item.getFilter())).collect(Collectors.toList()); + List AIResults = value.stream().filter(item -> "0".equals(item.getFilter())).collect(Collectors.toList()); + PatrolResultRef filterResult = filterResults.isEmpty() ? null : filterResults.get(0); + PatrolResultRef AIResult = AIResults.isEmpty() ? null : AIResults.get(0); + + if ("meter".equalsIgnoreCase(algType)) { + // 表计处理 + if (filterResult != null && AIResult != null) { + String filterResultType = filterResult.getResultType(); + String AIResultType = AIResult.getResultType(); + if ("1".equals(filterResultType)) { // 初筛正常 + // 只归档大模型 + processedRefs.add(AIResult); + } else if ("0".equals(filterResultType)) { // 初筛缺陷 + if ("1".equals(AIResultType)) { + // 分开:初筛缺陷,大模型正常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("0".equals(AIResultType)) { + // 合并:初筛缺陷,大模型缺陷 + PatrolResultRef merged = mergePatrolResultRef(filterResult, AIResult, "0"); + processedRefs.add(merged); + } else if ("2".equals(AIResultType)) { + // 分开:初筛缺陷,大模型异常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else if ("2".equals(filterResultType)) { // 初筛异常 + if ("1".equals(AIResultType)) { + // 分开:初筛异常,大模型正常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("0".equals(AIResultType)) { + // 分开:初筛异常,大模型缺陷 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("2".equals(AIResultType)) { + // 合并:初筛异常,大模型异常 + PatrolResultRef merged = mergePatrolResultRef(filterResult, AIResult, "2"); + processedRefs.add(merged); + } + } else { + // 未知类型,都添加 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else if (filterResult != null) { + processedRefs.add(filterResult); + } else if (AIResult != null) { + processedRefs.add(AIResult); + } + } else { + // 外观处理 + if (filterResult != null && AIResult != null) { + String filterResultType = filterResult.getResultType(); + String AIResultType = AIResult.getResultType(); + if ("0".equals(filterResultType)) { // 初筛缺陷 + if ("1".equals(AIResultType)) { + // 分开:初筛缺陷,大模型正常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else if ("0".equals(AIResultType)) { + // 合并:初筛缺陷,大模型缺陷 + PatrolResultRef merged = mergePatrolResultRef(filterResult, AIResult, "0"); + processedRefs.add(merged); + } else if ("2".equals(AIResultType)) { + // 分开:初筛缺陷,大模型异常 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } else { + // 未知,都添加 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else { + // 初筛不是缺陷但有大模型(理论上不应出现),为保数据完整都添加 + processedRefs.add(filterResult); + processedRefs.add(AIResult); + } + } else if (filterResult != null) { + processedRefs.add(filterResult); + } else if (AIResult != null) { + processedRefs.add(AIResult); + } + } + } + patrolResultRefs = processedRefs; } List basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(lineIds); @@ -1688,9 +2018,9 @@ public class PatrolResultServiceImpl implements IPatrolResultService { log.info("REPORTS SIZE: {}", patrolResultRefs.size()); List reportDatas = new ArrayList<>(); - long okNum = 1L; - long failNum = 1L; - long defectNum = 1L; + long okNum = 0L; + long failNum = 0L; + long defectNum = 0L; int index; for (index = 0; index < patrolResultRefs.size(); ++index) { PatrolResultRef patrolResultRef = patrolResultRefs.get(index); @@ -1740,19 +2070,18 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } else if (resultType.equals("0")) { reportData.setPointStatus(messageUtils.get("缺陷")); // 缺陷编号 - reportData.setCode(defectNum); ++defectNum; + reportData.setCode(defectNum); } else if (resultType.equals("1")) { reportData.setPointStatus(messageUtils.get("正常")); - reportData.setCode(okNum); ++okNum; + reportData.setCode(okNum); } else { reportData.setPointStatus(messageUtils.get("异常")); // 异常编号 - reportData.setCode(failNum); ++failNum; + reportData.setCode(failNum); } - String resultContent = patrolResultRef.getResultContent(); AnalyseResPoint analyseResPoint = JSONObject.parseObject(resultContent, AnalyseResPoint.class); String imgUrl = analyseResPoint.getResImageUrl(); @@ -1770,10 +2099,37 @@ public class PatrolResultServiceImpl implements IPatrolResultService { reportData.setReportImgList(reportImages); reportDatas.add(reportData); } + if ("0".equals(exportReportFlag)) { + patrolStatistics = String.format(messageUtils.get("缺陷数量:%d个。"), defectNum); + } else { + patrolStatistics = String.format(messageUtils.get("本次任务巡视总结果数量:%d个,正常结果数量:%d个,异常结果数量:%d个,缺陷结果数量:%d个。"), patrolResultRefs.size(), okNum, failNum, defectNum); + } + report.setPatrolStatistics(patrolStatistics); report.setReportDatalist(reportDatas); return report; } + private PatrolResultRef mergePatrolResultRef(PatrolResultRef filterResult, PatrolResultRef AIResult, String resultType) { + PatrolResultRef merged = new PatrolResultRef(); + merged.setDeviceId(filterResult.getDeviceId()); + merged.setAlgType(filterResult.getAlgType()); + merged.setTaskPatrolledId(filterResult.getTaskPatrolledId()); + // 描述和值拼接 + merged.setDescription(filterResult.getDescription() + "," + AIResult.getDescription()); + merged.setValue(filterResult.getValue() + "," + AIResult.getValue()); + // 合并时使用大模型的结果内容和文件路径(因为图片要显示大模型分析后的图) + merged.setResultContent(AIResult.getResultContent()); + merged.setFilePath(AIResult.getFilePath()); + // 其他字段取 filterResult + merged.setDevType(filterResult.getDevType()); + merged.setDeviceSource(filterResult.getDeviceSource()); + merged.setTime(filterResult.getTime()); + merged.setThreshold(filterResult.getThreshold()); + merged.setAlgName(filterResult.getAlgName()); + merged.setResultType(resultType); + return merged; + } + private static class GroupKey { private final String objectId; private final String algType; 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 cc6178e..95b33a6 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 @@ -281,44 +281,22 @@ public class PatrolTaskResultMainController extends BaseController { lineIds.addAll(longs); } lineIds = lineIds.stream().distinct().collect(Collectors.toList()); - PrintUtil.useTime("收集需归档的lineIds", startTime); logger.info("---归档--lineIds size: {},lineIds:{}", lineIds.size(), lineIds); List resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds); if (resultList.isEmpty()) { logger.error("[归档]失败, 数据采集中..."); return AjaxResult.error("数据采集中请稍后...."); } - startTime = System.currentTimeMillis(); - ResultAnalysis resultAnalysis = new ResultAnalysis(); - int csQxNum = 0, aiQxNum = 0; - List taskPatrolledIds = resultList.stream().map(PatrolResult::getTaskPatrolledId).distinct().collect(Collectors.toList()); - for (String taskPatrolledId : taskPatrolledIds) { - resultAnalysis.setTaskPatrolledId(taskPatrolledId); - ResultAnalysis ras = patrolResultService.selectTaskAbnormalData(resultAnalysis); - csQxNum += ras.getCsQxNum(); - aiQxNum += ras.getAiQxNum(); - } - - if ("0".equals(exportReportFlag) && 0 == aiQxNum && 0 == csQxNum) { - logger.error("[归档]没有缺陷数据, 无需归档!"); - return AjaxResult.error("没有缺陷数据, 无需归档!"); - } - - PrintUtil.useTime("查询统计缺陷数据", startTime); - startTime = System.currentTimeMillis(); - // 使用CompletableFuture异步执行saveReport - int finalAiQxNum = aiQxNum; - int finalCsQxNum = csQxNum; List finalLineIds = lineIds; + startTime = PrintUtil.useTime("查询统计数据", startTime); CompletableFuture> saveReportFuture = CompletableFuture.supplyAsync(() -> { logger.info("[ARCHIVE] Start saving reports"); - return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, lineId, resultList, finalAiQxNum, finalCsQxNum); + return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, lineId, resultList); }, executor).exceptionally(ex -> { logger.error("Report saving failed", ex); return Collections.emptyList(); }); - PrintUtil.useTime("保存报告数据", startTime); - startTime = System.currentTimeMillis(); + startTime = PrintUtil.useTime("保存报告数据", startTime); // 当saveReport完成后,再异步处理所有导出任务 saveReportFuture.thenAcceptAsync(reportIds -> { logger.info("-----------[ARCHIVE] Saved export reportIds: {}", reportIds); @@ -607,7 +585,7 @@ public class PatrolTaskResultMainController extends BaseController { // 点位汇总 - List statusList = Arrays.asList(MessageUtils.get("异常"), MessageUtils.get("缺陷"), MessageUtils.get("正常")); + List statusList = Arrays.asList(MessageUtils.get("缺陷"), MessageUtils.get("异常"), MessageUtils.get("正常")); // List statusList = Collections.singletonList(MessageUtils.get("缺陷")); for (String status : statusList) { addStatusSectionLingzhou(doc, report, status, images); @@ -2861,18 +2839,18 @@ public class PatrolTaskResultMainController extends BaseController { // } // } - InspectionReportData inspection = new InspectionReportData(); + List list = new ArrayList(); + InspectionReportData inspectionReportData = new InspectionReportData(); + inspectionReportData.setPointStatus(MessageUtils.get("缺陷")); + list.add(inspectionReportData); + InspectionReportData inspection = new InspectionReportData(); inspection.setPointStatus(MessageUtils.get("异常")); list.add(inspection); - InspectionReportData inspectionReportData = new InspectionReportData(); -// inspection.setPointStatus(MessageUtils.get("待人工确认")); -// list.add(inspection); InspectionReportData inection = new InspectionReportData(); inection.setPointStatus(MessageUtils.get("正常")); list.add(inection); - inspectionReportData.setPointStatus(MessageUtils.get("缺陷")); - list.add(inspectionReportData); + int total = 0; label186: @@ -3158,11 +3136,11 @@ public class PatrolTaskResultMainController extends BaseController { CellRangeAddress callRangeAddress33 = new CellRangeAddress(3, 3, 8, 11); CellRangeAddress callRangeAddress34 = new CellRangeAddress(3, 3, 12, 14); CellRangeAddress callRangeAddress41 = new CellRangeAddress(4, 4, 0, 3); - CellRangeAddress callRangeAddress42 = new CellRangeAddress(4, 4, 4, 7); - CellRangeAddress callRangeAddress43 = new CellRangeAddress(4, 4, 8, 11); - CellRangeAddress callRangeAddress44 = new CellRangeAddress(4, 4, 12, 14); + CellRangeAddress callRangeAddress42 = new CellRangeAddress(4, 4, 4, 14); CellRangeAddress callRangeAddress51 = new CellRangeAddress(5, 5, 0, 3); CellRangeAddress callRangeAddress52 = new CellRangeAddress(5, 5, 4, 14); + CellRangeAddress callRangeAddress61 = new CellRangeAddress(6, 6, 0, 3); + CellRangeAddress callRangeAddress62 = new CellRangeAddress(6, 6, 4, 14); sheet.addMergedRegion(callRangeAddress01); sheet.addMergedRegion(callRangeAddress02); sheet.addMergedRegion(callRangeAddress03); @@ -3178,10 +3156,10 @@ public class PatrolTaskResultMainController extends BaseController { sheet.addMergedRegion(callRangeAddress34); sheet.addMergedRegion(callRangeAddress41); sheet.addMergedRegion(callRangeAddress42); - sheet.addMergedRegion(callRangeAddress43); - sheet.addMergedRegion(callRangeAddress44); sheet.addMergedRegion(callRangeAddress51); sheet.addMergedRegion(callRangeAddress52); + sheet.addMergedRegion(callRangeAddress61); + sheet.addMergedRegion(callRangeAddress62); Row row0 = sheet.createRow(0); row0.setHeight((short) 600); Cell cell0 = row0.createCell(0); @@ -3273,16 +3251,16 @@ public class PatrolTaskResultMainController extends BaseController { cell62.setCellValue(inspectionReport.getInspectionTaskName()); cell62.setCellStyle(colStyle2); autoFitRowHeight(sheet, 4, 4, colStyle2); - Cell cell63 = row6.createCell(8); - cell63.setCellValue(MessageUtils.get("巡视统计")); - cell63.setCellStyle(colStyle2); - Cell cell64 = row6.createCell(12); - cell64.setCellValue(inspectionReport.getPatrolStatistics()); - cell64.setCellStyle(colStyle2); - autoFitRowHeight(sheet, 4, 12, colStyle2); +// Cell cell63 = row6.createCell(8); +// cell63.setCellValue(MessageUtils.get("巡视统计")); +// cell63.setCellStyle(colStyle2); +// Cell cell64 = row6.createCell(12); +// cell64.setCellValue(inspectionReport.getPatrolStatistics()); +// cell64.setCellStyle(colStyle2); +// autoFitRowHeight(sheet, 4, 12, colStyle2); for (int i = 0; i < 15; ++i) { - if (i != 0 && i != 4 && i != 8 && i != 12) { + if (i != 0 && i != 4) { cell14 = row6.createCell(i); cell14.setCellStyle(colStyle2); } @@ -3291,10 +3269,10 @@ public class PatrolTaskResultMainController extends BaseController { Row row7 = sheet.createRow(5); row7.setHeight((short) 1000); Cell cell71 = row7.createCell(0); - cell71.setCellValue(MessageUtils.get("巡视结论")); + cell71.setCellValue(MessageUtils.get("巡视统计")); cell71.setCellStyle(colStyle2); Cell cell72 = row7.createCell(4); - cell72.setCellValue(inspectionReport.getDescription()); + cell72.setCellValue(inspectionReport.getPatrolStatistics()); cell72.setCellStyle(colStyle2); //qinyl @@ -3304,26 +3282,43 @@ public class PatrolTaskResultMainController extends BaseController { cell14.setCellStyle(colStyle2); } } + + Row row8 = sheet.createRow(6); + row8.setHeight((short) 1000); + Cell cell81 = row8.createCell(0); + cell81.setCellValue(MessageUtils.get("巡视结论")); + cell81.setCellStyle(colStyle2); + Cell cell82 = row8.createCell(4); + cell82.setCellValue(inspectionReport.getDescription()); + cell82.setCellStyle(colStyle2); + + //qinyl + for (int j = 0; j < 15; ++j) { + if (j != 0 && j != 4) { + cell14 = row8.createCell(j); + cell14.setCellStyle(colStyle2); + } + } List list = new ArrayList<>(); InspectionReportData inspectionReportQxData = new InspectionReportData(); inspectionReportQxData.setPointStatus(MessageUtils.get("缺陷")); list.add(inspectionReportQxData); if ("1".equals(exportReportFlag)) { - InspectionReportData inspectionReportZcData = new InspectionReportData(); - inspectionReportZcData.setPointStatus(MessageUtils.get("正常")); - list.add(inspectionReportZcData); InspectionReportData inspectionReportYcData = new InspectionReportData(); inspectionReportYcData.setPointStatus(MessageUtils.get("异常")); list.add(inspectionReportYcData); + InspectionReportData inspectionReportZcData = new InspectionReportData(); + inspectionReportZcData.setPointStatus(MessageUtils.get("正常")); + list.add(inspectionReportZcData); } int total = 0; label186: for (Iterator var74 = list.iterator(); var74.hasNext(); total += 2) { InspectionReportData arr = (InspectionReportData) var74.next(); SXSSFDrawing patriarch = sheet.createDrawingPatriarch(); - CellRangeAddress callRangeAddressa1 = new CellRangeAddress(6 + total, 6 + total, 0, 14); + CellRangeAddress callRangeAddressa1 = new CellRangeAddress(7 + total, 7 + total, 0, 14); sheet.addMergedRegion(callRangeAddressa1); - Row rowa1 = sheet.createRow(6 + total); + Row rowa1 = sheet.createRow(7 + total); Cell cella1 = rowa1.createCell(0); cella1.setCellValue(arr.getPointStatus() + MessageUtils.get("点位汇总")); CellStyle styleab = wb.createCellStyle(); @@ -3342,12 +3337,12 @@ public class PatrolTaskResultMainController extends BaseController { } } - CellRangeAddress callRangeAddressa12 = new CellRangeAddress(7 + total, 7 + total, 12, 14); + CellRangeAddress callRangeAddressa12 = new CellRangeAddress(8 + total, 8 + total, 12, 14); sheet.addMergedRegion(callRangeAddressa12); - rowa1 = sheet.createRow(7 + total); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total, 2, 4)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total, 5, 6)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total, 9, 10)); + rowa1 = sheet.createRow(8 + total); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total, 2, 4)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total, 5, 6)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total, 9, 10)); cella1 = rowa1.createCell(0); cella1.setCellValue(MessageUtils.get("编号")); cella1.setCellStyle(colStyle2); @@ -3422,9 +3417,9 @@ public class PatrolTaskResultMainController extends BaseController { imgList = brr.getReportImgList(); } - CellRangeAddress callRangeAddressa4 = new CellRangeAddress(7 + total, 7 + total, 12, 14); + CellRangeAddress callRangeAddressa4 = new CellRangeAddress(8 + total, 8 + total, 12, 14); sheet.addMergedRegion(callRangeAddressa4); - Row rowb1 = sheet.createRow(7 + total); + Row rowb1 = sheet.createRow(8 + total); if (((List) imgList).size() > 0) { rowb1.setHeight((short) 1000); } @@ -3481,22 +3476,22 @@ public class PatrolTaskResultMainController extends BaseController { cella1 = rowb1.createCell(14); cella1.setCellStyle(colStyle); if (((List) imgList).size() > 0) { - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 0, 0)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 1, 1)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 2, 4)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 5, 6)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 7, 7)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 8, 8)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 9, 10)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total + ((List) imgList).size(), 11, 11)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 0, 0)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 1, 1)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 2, 4)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 5, 6)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 7, 7)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 8, 8)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 9, 10)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total + ((List) imgList).size(), 11, 11)); Iterator var93 = ((List) imgList).iterator(); while (var93.hasNext()) { InspectionReportImg crr = (InspectionReportImg) var93.next(); ++total; - CellRangeAddress callRangeAddressb4 = new CellRangeAddress(7 + total, 7 + total, 12, 14); + CellRangeAddress callRangeAddressb4 = new CellRangeAddress(8 + total, 8 + total, 12, 14); sheet.addMergedRegion(callRangeAddressb4); - rowb1 = sheet.createRow(7 + total); + rowb1 = sheet.createRow(8 + total); rowb1.setHeight((short) 1000); cella1 = rowb1.createCell(0); cella1.setCellStyle(colStyle2); @@ -3525,7 +3520,7 @@ public class PatrolTaskResultMainController extends BaseController { cella1 = rowb1.createCell(12); if (crr.getImgType().equals("0")) { try { - insertImage(wb, patriarch, this.images(crr.getImg(), inputStreamMap), 7 + total, 0, 2); + insertImage(wb, patriarch, this.images(crr.getImg(), inputStreamMap), 8 + total, 0, 2); } catch (Exception var97) { var97.printStackTrace(); } @@ -3541,9 +3536,9 @@ public class PatrolTaskResultMainController extends BaseController { cella1.setCellStyle(colStyle); } } else { - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total, 2, 4)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total, 5, 6)); - sheet.addMergedRegion(new CellRangeAddress(7 + total, 7 + total, 9, 10)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total, 2, 4)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total, 5, 6)); + sheet.addMergedRegion(new CellRangeAddress(8 + total, 8 + total, 9, 10)); } } }