diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/controller/InspectionReportController.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/controller/InspectionReportController.java index 42486a8..ff3d09e1 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/controller/InspectionReportController.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/controller/InspectionReportController.java @@ -186,6 +186,99 @@ public class InspectionReportController extends BaseController { return AjaxResult.success(inspectionReport); } + @GetMapping({"/shaoxing/{lineId}/{filter}"}) + public AjaxResult getInfo_shaoxing(@PathVariable("lineId") Long lineId, @PathVariable(value = "filter",required = false) String filter) { + InspectionReport inspectionReport = inspectionReportService.selectInspectionReportByLineId(lineId); + if(inspectionReport == null) { + // 暂时这么处理(进度条报告入口,lineId传的是patrolTaskStatus的lineId) + PatrolTaskStatus patrolTaskStatus = patrolTaskStatusService.selectPatrolTaskStatusByLineId(lineId); + String taskPatrolledId = patrolTaskStatus.getTaskPatrolledId(); + inspectionReport = new InspectionReport(); + inspectionReport.setTaskPatrolledId(taskPatrolledId); + inspectionReport.setFilter(filter); + logger.info("进度条报告查看,filter:{},taskPatrolledId:{}", filter, taskPatrolledId); + List inspectionReports = inspectionReportService.selectInspectionReportList(inspectionReport); + if (inspectionReports.size() > 0) { + inspectionReport = inspectionReports.get(0); + lineId = inspectionReport.getLineId(); + } else { + return AjaxResult.error("报告不存在: " + lineId); + } + } + InspectionReportData inspectionReportData = new InspectionReportData(); + inspectionReportData.setReportId(String.valueOf(lineId)); + List inspectionReportDataList = + inspectionReportDataService.selectInspectionReportDataList(inspectionReportData); + // 收集所有需要查询的lineId + List lineIds = inspectionReportDataList.stream() + .map(InspectionReportData::getLineId) + .filter(StringUtils::isNotBlank) + .distinct() + .collect(Collectors.toList()); + + // 批量查询图片数据 + Map imageMap = Collections.emptyMap(); + if (!lineIds.isEmpty()) { + // 批量查询 + List allImages = inspectionReportImgService.selectByReportInfoIds(lineIds); + + // 按reportInfoId分组,拼接图片URL + imageMap = allImages.stream() + .filter(img -> StringUtils.isNotBlank(img.getReportInfoId())) + .filter(img -> StringUtils.isNotBlank(img.getImg())) + .collect(Collectors.groupingBy( + InspectionReportImg::getReportInfoId, + Collectors.mapping( + InspectionReportImg::getImg, + Collectors.joining(StringUtils.COMMA) + ) + )); + } + + // 设置图片数据 + for (InspectionReportData reportData : inspectionReportDataList) { + // 记录日志(根据实际情况调整日志级别,避免生产环境过多日志) + logger.debug("reportData: {}", reportData); + + // 从缓存中获取图片URL + String imgUrls = imageMap.get(reportData.getLineId()); + if (StringUtils.isNotBlank(imgUrls)) { + reportData.setInspectionImg(imgUrls); + } + } + + +// inspectionReport.setInfo(inspectionReportDataList); + Map>>> resultTaskInfoMap = new HashMap<>(); + // 按 pointStatus 分组,再按 taskPatrolledId_taskName 分组 + // key: pointStatus,value: {taskPatrolledId_taskName -> List} + Map>> detailGrouped = + inspectionReportDataList.stream() + .collect(Collectors.groupingBy( + item -> item.getPointStatus() == null ? "unknown" : item.getPointStatus(), + Collectors.groupingBy(item -> item.getTaskPatrolledId() + "_" + item.getTaskName()) + )); + // 将分组结果转换为所需的格式 + for (Map.Entry>> stringMapEntry : detailGrouped.entrySet()) { + // key:taskPatrolledId_taskName -> value:List + Map> value = stringMapEntry.getValue(); + + List>> collect = value.entrySet().stream().map(entry -> { + Map> resultHashMap = new HashMap<>(); + // 从分组中的任意一个元素获取 taskName(因为同一分组内 taskName 相同) + String taskName = entry.getValue().get(0).getTaskName(); + resultHashMap.put(taskName, entry.getValue()); + return resultHashMap; + }).collect(Collectors.toList()); + resultTaskInfoMap.put(stringMapEntry.getKey(), collect); + } + + inspectionReport.setDetail(resultTaskInfoMap); + + + return AjaxResult.success(inspectionReport); + } + @Log( title = "巡视报告头数据", businessType = BizType.INSERT diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/domain/InspectionReport.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/domain/InspectionReport.java index c0236b6..89f78ca 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/domain/InspectionReport.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/domain/InspectionReport.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Objects; import lombok.Getter; @@ -102,6 +103,8 @@ public class InspectionReport extends BaseEntity { List ReportDatalist; private List info; + private Map>>> detail; + public InspectionReport(String taskResultId) { this.taskResultId = taskResultId; } diff --git a/inspect-main/inspect-main-task/src/main/java/com/inspect/insreportdata/domain/InspectionReportData.java b/inspect-main/inspect-main-task/src/main/java/com/inspect/insreportdata/domain/InspectionReportData.java index 6d53347..94f6b22 100644 --- a/inspect-main/inspect-main-task/src/main/java/com/inspect/insreportdata/domain/InspectionReportData.java +++ b/inspect-main/inspect-main-task/src/main/java/com/inspect/insreportdata/domain/InspectionReportData.java @@ -70,6 +70,10 @@ public class InspectionReportData extends BaseEntity { List reportImgList; private String algName; + private String taskName; + + private String taskPatrolledId; + @Override public boolean equals(Object object) { if (this == object) return true; @@ -100,6 +104,9 @@ public class InspectionReportData extends BaseEntity { ", inspectionImg='" + inspectionImg + '\'' + ", reportId='" + reportId + '\'' + ", reportImgList=" + reportImgList + + ", algName='" + algName + '\'' + + ", taskName='" + taskName + '\'' + + ", taskPatrolledId='" + taskPatrolledId + '\'' + '}'; } } 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 80b6de7..7f0be7c 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); + List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, 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 3a6f990..1845b7a 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 @@ -35,9 +35,11 @@ import com.inspect.task.mapper.PatrolTaskMapper; import com.inspect.taskstatus.domain.PatrolTaskStatus; import com.inspect.taskstatus.mapper.PatrolTaskStatusMapper; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; +import io.seata.common.util.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -501,19 +503,260 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } @Transactional - public List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, Long currentLineId, List resultList) { + public List saveReportShaoxing(PatrolTaskResultMain resultMain, List lineIds, List resultList) { long startTime = System.currentTimeMillis(); List reportIds = new ArrayList<>(); + // 获取站信息 + Map stationMap = patrolResultMapper.selectBasedataStation(); + String stationName = stationMap.get("station_name"); + String stationType = stationMap.get("station_type"); + String voltLevel = stationMap.get("volt_level"); + startTime = PrintUtil.useTime("导出报告:查询站点信息", startTime); + + AjaxResult ajaxResult = feignBasedataAreaService.evnList(); + List jsonObjects = JSONObject.parseArray(JSON.toJSONString(ajaxResult.get("data")), JSONObject.class); + List envoList = new ArrayList<>(); + for (JSONObject jsonObject : jsonObjects) { + String typeName = jsonObject.getString("typeName"); + String valueUnit = jsonObject.getString("valueUnit"); + if (StringUtils.isEmpty(valueUnit) || StringUtils.isEmpty(typeName)) { + continue; + } + envoList.add(typeName + ":" + valueUnit); + } + startTime = PrintUtil.useTime("导出报告:获取气象数据", startTime); + + // 查询任务状态信息 + List taskPatrolledIds = resultList.stream().map(PatrolResult::getTaskPatrolledId).distinct().collect(Collectors.toList()); + List patrolTaskStatuses = patrolTaskStatusMapper.selectPatrolTaskStatusListByTaskPatrolledIds(taskPatrolledIds); + List startTimes = patrolTaskStatuses.stream().map(PatrolTaskStatus::getStartTime).sorted().collect(Collectors.toList()); + List endTimes = patrolTaskStatuses.stream().map(PatrolTaskStatus::getEndTime).sorted().collect(Collectors.toList()); + startTime = PrintUtil.useTime("导出报告:获取任务进度信息", startTime); + + List taskNames = resultList.stream().map(PatrolResult::getTaskName).distinct().collect(Collectors.toList()); + String taskName = StringUtils.join(taskNames, ","); + boolean isMultipleTasks = CollectionUtils.isNotEmpty(taskPatrolledIds) && taskPatrolledIds.size() > 1; + if (isMultipleTasks) { + // 说明多个任务合并,任务名称修改为巡视日期-巡视报告 例如:2026年3月23日-巡视报告 + Date date = CollectionUtils.isNotEmpty(startTimes) ? startTimes.get(0) : new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日"); + taskName = sdf.format(date) + "-" + messageUtils.get("巡视报告"); + } + startTime = PrintUtil.useTime("导出报告:获取任务名信息", startTime); + + List basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(lineIds); + startTime = PrintUtil.useTime("导出报告:获取区域,生产,部件信息", startTime); + + List patrolResultRefs = patrolResultMapper.selectResultRefByLineIds(lineIds, null); + startTime = PrintUtil.useTime("导出报告:获取巡视分析结果数据", startTime); + + 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; + startTime = PrintUtil.useTime("导出报告:筛选缺陷数据", startTime); + } 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.BIG_MODEL_ALG_LIST.contains(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; + startTime = PrintUtil.useTime("导出报告:全部数据处理", startTime); + } + 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; + } + } + long total = okNum + defectNum; + String patrolStatistics; + if ("0".equals(exportReportFlag)) { + patrolStatistics = String.format(messageUtils.get("缺陷数量:%d个。"), defectNum); + } else { + patrolStatistics = String.format(messageUtils.get("本次任务巡视总结果数量:%d个,正常结果数量:%d个,缺陷结果数量:%d个"), total, okNum, defectNum); + } for (Long lineId : lineIds) { resultMain.setLineId(lineId); resultMain.setCheckTime(new Date()); resultMain.setFileStatus("1"); + String mainId = String.valueOf(resultMain.getLineId()); + // 查询当前的结果信息 + PatrolResult patrolResult = resultList.stream().filter(item -> mainId.equals(item.getMainId())).findFirst().orElse(null); + assert patrolResult != null; + String taskCode = patrolResult.getTaskCode(); + String taskPatrolId = patrolResult.getTaskPatrolledId(); + if (StringUtils.isEmpty(taskPatrolId)) { + throw new ServiceException("LACK PLAN ID: " + mainId); + } else { + List taskStatuses = this.patrolTaskStatusMapper.selectPatrolTaskStatusList(PatrolTaskStatus.builder().taskPatrolledId(taskPatrolId).build()); + if (taskStatuses.isEmpty()) { + throw new ServiceException("LACKING STATUS: " + mainId); + } else { + List list = patrolTaskMapper.selectPatrolTaskList(PatrolTask.builder().taskCode(taskCode).build()); + PatrolTask task = new PatrolTask(); + if (list.isEmpty()) { + log.error("TASK PLAN LOST: " + taskCode); + } else { + task = list.get(0); + } + InspectionReport report = new InspectionReport(); + report.setPatrolStatistics(patrolStatistics); + report.setInspectionDate(new Date()); + report.setTaskResultId(mainId); + report.setInspectionStartTime(startTimes.get(0)); + report.setInspectionEndTime(DateUtils.parseDate(endTimes.get(endTimes.size() - 1))); + report.setTaskId(task.getTaskId() == null ? "" : 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); + batchInsertReportData_shaoxing(String.valueOf(report.getLineId()), patrolResultRefs, basePointAreaInfoList, taskPatrolledIds); + reportIds.add(report.getLineId()); + } + } this.patrolTaskResultMainMapper.updatePatrolTaskResultMain(resultMain); this.patrolResultMapper.updatePatrolResultByMainId(String.valueOf(lineId)); - reportIds.addAll(saveReportDataShaoxing(resultList, resultMain, lineIds)); } - - PrintUtil.useTime("获取所有报告id", startTime); return reportIds; } @@ -612,240 +855,6 @@ public class PatrolResultServiceImpl implements IPatrolResultService { } } - public List saveReportDataShaoxing(List resultList, PatrolTaskResultMain resultMain, List lineIds) { - long startTime = System.currentTimeMillis(); - String mainId = String.valueOf(resultMain.getLineId()); - if (resultList.isEmpty()) { - throw new ServiceException("LACK INSPECT RESULT: " + mainId); - } else { - PatrolResult patrolResult = resultList.stream().filter(item -> mainId.equals(item.getMainId())).findFirst().orElse(null); - assert patrolResult != null; - String taskCode = patrolResult.getTaskCode(); - String taskPatrolId = patrolResult.getTaskPatrolledId(); - List taskNames = resultList.stream().map(PatrolResult::getTaskName).distinct().collect(Collectors.toList()); - String taskName = StringUtils.join(taskNames, ","); - if (StringUtils.isEmpty(taskPatrolId)) { - throw new ServiceException("LACK PLAN ID: " + mainId); - } else { - List taskStatuses = this.patrolTaskStatusMapper.selectPatrolTaskStatusList(PatrolTaskStatus.builder().taskPatrolledId(taskPatrolId).build()); - startTime = PrintUtil.useTime("INQUIRY STATUS", startTime); - if (taskStatuses.isEmpty()) { - throw new ServiceException("LACKING STATUS: " + mainId); - } else { - PatrolTaskStatus taskStatus = taskStatuses.get(0); - List list = patrolTaskMapper.selectPatrolTaskList(PatrolTask.builder().taskCode(taskCode).build()); - startTime = PrintUtil.useTime("INQUIRY TASK PLAN", startTime); - - List reportIds = new ArrayList<>(); - PatrolTask task = new PatrolTask(); - if (list.isEmpty()) { - log.error("TASK PLAN LOST: " + taskCode); - } else { - task = list.get(0); - } - - Map stationMap = patrolResultMapper.selectBasedataStation(); - String stationName = stationMap.get("station_name"); - String stationType = stationMap.get("station_type"); - String voltLevel = stationMap.get("volt_level"); - AjaxResult ajaxResult = feignBasedataAreaService.evnList(); - List jsonObjects = JSONObject.parseArray(JSON.toJSONString(ajaxResult.get("data")), JSONObject.class); - log.info("EVN LIST: " + jsonObjects); - List envoList = new ArrayList<>(); - for (JSONObject jsonObject : jsonObjects) { - String typeName = jsonObject.getString("typeName"); - String valueUnit = jsonObject.getString("valueUnit"); - if (StringUtils.isEmpty(valueUnit) || StringUtils.isEmpty(typeName)) { - continue; - } - envoList.add(typeName + ":" + valueUnit); - } - - 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.BIG_MODEL_ALG_LIST.contains(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; - } - 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; - } - } - long total = okNum + defectNum; - String patrolStatistics; - if ("0".equals(exportReportFlag)) { - patrolStatistics = String.format(messageUtils.get("缺陷数量:%d个。"), defectNum); - } else { - patrolStatistics = String.format(messageUtils.get("本次任务巡视总结果数量:%d个,正常结果数量:%d个,缺陷结果数量:%d个"), total, okNum, defectNum); - } - InspectionReport report = new InspectionReport(); - resetReport(report, patrolStatistics, mainId, task, taskStatus); - report.setTaskId(task.getTaskId() == null ? "" : 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; - - } - } - } - } - public List saveReportDataLingzhou_v1(List resultList, PatrolTaskResultMain resultMain, List lineIds, int aiQxNum, int csQxNum) { long startTime = System.currentTimeMillis(); String mainId = String.valueOf(resultMain.getLineId()); @@ -1233,11 +1242,18 @@ 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(); + public void batchInsertReportData_shaoxing(String reportId, List patrolResultRefs, List basePointAreaInfoList, List taskPatrolledIds) { + Map> taskCounterMap = new HashMap<>(); + + // 为每个任务初始化计数器 + for (String item : taskPatrolledIds) { + Map counter = new HashMap<>(); + counter.put("defect", 0L); + counter.put("ok", 0L); + counter.put("fail", 0L); + taskCounterMap.put(item, counter); + } - List basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(mainIds); log.info("REPORTS SIZE: {}", patrolResultRefs.size()); List reportDatas = new ArrayList<>(); List reportImages = new ArrayList<>(); @@ -1249,6 +1265,9 @@ public class PatrolResultServiceImpl implements IPatrolResultService { for (index = 0; index < patrolResultRefs.size(); ++index) { PatrolResultRef patrolResultRef = patrolResultRefs.get(index); String devType = patrolResultRef.getDevType(); + // 获取该结果所属的任务名 + String resultTaskName = patrolResultRef.getTaskName(); + String taskPatrolledId = patrolResultRef.getTaskPatrolledId(); BasePointAreaInfo basePointAreaInfo; try { basePointAreaInfo = basePointAreaInfoList.stream().filter((item) -> item != null && patrolResultRef.getDeviceId().equals(item.getDeviceId())).findFirst().get(); @@ -1266,6 +1285,8 @@ public class PatrolResultServiceImpl implements IPatrolResultService { reportData.setPointName(basePointAreaInfo.getPatrolPointName()); reportData.setDataSources(patrolResultRef.getDeviceSource()); reportData.setAcquisitionTime(DateUtils.parse(DateUtils.yyyyMMddHHmmss2, patrolResultRef.getTime())); + reportData.setTaskName(resultTaskName); + reportData.setTaskPatrolledId(taskPatrolledId); if ("1".equals(patrolResultRef.getResultType()) && validAlgTypes.contains(patrolResultRef.getAlgType())) { reportData.setInspectionResults(patrolResultRef.getValue()); } else { @@ -1295,18 +1316,37 @@ public class PatrolResultServiceImpl implements IPatrolResultService { continue; } else if (resultType.equals("0")) { reportData.setPointStatus(messageUtils.get("缺陷")); - // 缺陷编号 - ++defectNum; - reportData.setCode(defectNum); + // 按任务统计异常编号 + Map counter = taskCounterMap.get(taskPatrolledId); + if (counter != null) { + counter.put("defect", counter.get("defect") + 1); + reportData.setCode(counter.get("defect")); + defectNum++; + } else { + reportData.setCode(++defectNum); + } } else if (resultType.equals("1")) { reportData.setPointStatus(messageUtils.get("正常")); - ++okNum; - reportData.setCode(okNum); + // 按任务统计异常编号 + Map counter = taskCounterMap.get(taskPatrolledId); + if (counter != null) { + counter.put("ok", counter.get("ok") + 1); + reportData.setCode(counter.get("ok")); + okNum++; + } else { + reportData.setCode(++okNum); + } } else { reportData.setPointStatus(messageUtils.get("异常")); - // 异常编号 - ++failNum; - reportData.setCode(failNum); + // 按任务统计异常编号 + Map counter = taskCounterMap.get(taskPatrolledId); + if (counter != null) { + counter.put("fail", counter.get("fail") + 1); + reportData.setCode(counter.get("fail")); + failNum++; + } else { + reportData.setCode(++failNum); + } } final String reportDataId = reportId + "_" + (100000 + index); 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 cb43c55..7c3f2bb 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 @@ -265,23 +265,20 @@ public class PatrolTaskResultMainController extends BaseController { public AjaxResult updateInfo_shaoxing( @RequestBody PatrolTaskResultMain resultMain) { long startTime = System.currentTimeMillis(); - logger.info("[ARCHIVE] Starting, resultMain: {}", resultMain); - logger.info("-----------resultMain getTaskPatrolledId: {}", resultMain.getTaskPatrolledId()); - PatrolTaskResultMain patrolTaskResultMain = patrolTaskResultMainService.selectPatrolTaskResultMainByTaskPatrolledId(resultMain.getTaskPatrolledId()); - logger.info("-----------patrolTaskResultMain: {}", patrolTaskResultMain); - if (patrolTaskResultMain == null) { + List taskPatrolledIds = resultMain.getTaskPatrolledIds(); + logger.info("-----------patrolTaskResultMains taskPatrolledIds: {}", taskPatrolledIds); + List patrolTaskResultMains = patrolTaskResultMainService.selectPatrolTaskResultMainByTaskPatrolledIds(taskPatrolledIds); + logger.info("-----------patrolTaskResultMains: {}", patrolTaskResultMains); + if (patrolTaskResultMains.size() == 0) { logger.error("[归档]失败, 数据采集中..."); return AjaxResult.error("数据采集中请稍后...."); } - Long lineId = patrolTaskResultMain.getLineId(); - List lineIds = new ArrayList<>(); - lineIds.add(lineId); + List lineIds = patrolTaskResultMains.stream().map(PatrolTaskResultMain::getLineId).collect(Collectors.toList()); List longs = patrolTaskResultMainService.selectLineIdsByList(lineIds); if (longs != null && longs.size() > 0) { lineIds.addAll(longs); } lineIds = lineIds.stream().distinct().collect(Collectors.toList()); - logger.info("---归档--lineIds size: {},lineIds:{}", lineIds.size(), lineIds); List resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds); if (resultList.isEmpty()) { logger.error("[归档]失败, 数据采集中..."); @@ -291,7 +288,7 @@ public class PatrolTaskResultMainController extends BaseController { startTime = PrintUtil.useTime("查询统计数据", startTime); CompletableFuture> saveReportFuture = CompletableFuture.supplyAsync(() -> { logger.info("[ARCHIVE] Start saving reports"); - return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, lineId, resultList); + return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, resultList); }, executor).exceptionally(ex -> { logger.error("Report saving failed", ex); return Collections.emptyList(); diff --git a/inspect-main/inspect-main-task/src/main/resources/mapper/task/InspectionReportDataMapper.xml b/inspect-main/inspect-main-task/src/main/resources/mapper/task/InspectionReportDataMapper.xml index 96a08bb..91259ad 100644 --- a/inspect-main/inspect-main-task/src/main/resources/mapper/task/InspectionReportDataMapper.xml +++ b/inspect-main/inspect-main-task/src/main/resources/mapper/task/InspectionReportDataMapper.xml @@ -19,6 +19,8 @@ + + @@ -35,7 +37,9 @@ inspection_results, point_status, inspection_img, - alg_name + alg_name, + task_name, + task_patrolled_id from inspection_report_data @@ -158,11 +162,11 @@ insert into inspection_report_data - (line_id,code,report_id,area,time_interval,eq_name,parts,point_name,data_sources,acquisition_time,inspection_results,point_status,inspection_img,alg_name) + (line_id,code,report_id,area,time_interval,eq_name,parts,point_name,data_sources,acquisition_time,inspection_results,point_status,inspection_img,alg_name,task_name,task_patrolled_id) values (#{t.lineId}, #{t.code}, #{t.reportId}, #{t.area}, #{t.timeInterval}, #{t.eqName}, #{t.parts}, - #{t.pointName},#{t.dataSources},#{t.acquisitionTime},#{t.inspectionResults},#{t.pointStatus},#{t.inspectionImg},#{t.algName}) + #{t.pointName},#{t.dataSources},#{t.acquisitionTime},#{t.inspectionResults},#{t.pointStatus},#{t.inspectionImg},#{t.algName},#{t.taskName},#{t.taskPatrolledId}) diff --git a/inspect-main/inspect-main-task/src/main/resources/mapper/task/PatrolResultMapper.xml b/inspect-main/inspect-main-task/src/main/resources/mapper/task/PatrolResultMapper.xml index b102f53..321eba8 100644 --- a/inspect-main/inspect-main-task/src/main/resources/mapper/task/PatrolResultMapper.xml +++ b/inspect-main/inspect-main-task/src/main/resources/mapper/task/PatrolResultMapper.xml @@ -603,6 +603,7 @@ + @@ -642,6 +643,7 @@