Browse Source

feat:当天巡视归档后的报告合并成一个报告,任务名称取当天日期 年-月-日 - 巡视报告

master
WangGuangYuan 5 hours ago
parent
commit
1e35ac4c9c
8 changed files with 410 additions and 264 deletions
  1. +93
    -0
      inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/controller/InspectionReportController.java
  2. +3
    -0
      inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/domain/InspectionReport.java
  3. +7
    -0
      inspect-main/inspect-main-task/src/main/java/com/inspect/insreportdata/domain/InspectionReportData.java
  4. +1
    -1
      inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/IPatrolResultService.java
  5. +290
    -250
      inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/impl/PatrolResultServiceImpl.java
  6. +7
    -10
      inspect-main/inspect-main-task/src/main/java/com/inspect/resultmain/controller/PatrolTaskResultMainController.java
  7. +7
    -3
      inspect-main/inspect-main-task/src/main/resources/mapper/task/InspectionReportDataMapper.xml
  8. +2
    -0
      inspect-main/inspect-main-task/src/main/resources/mapper/task/PatrolResultMapper.xml

+ 93
- 0
inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/controller/InspectionReportController.java View File

@ -186,6 +186,99 @@ public class InspectionReportController extends BaseController {
return AjaxResult.success(inspectionReport); 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<InspectionReport> 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<InspectionReportData> inspectionReportDataList =
inspectionReportDataService.selectInspectionReportDataList(inspectionReportData);
// 收集所有需要查询的lineId
List<String> lineIds = inspectionReportDataList.stream()
.map(InspectionReportData::getLineId)
.filter(StringUtils::isNotBlank)
.distinct()
.collect(Collectors.toList());
// 批量查询图片数据
Map<String, String> imageMap = Collections.emptyMap();
if (!lineIds.isEmpty()) {
// 批量查询
List<InspectionReportImg> 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<String, List<Map<String, List<InspectionReportData>>>> resultTaskInfoMap = new HashMap<>();
// pointStatus 分组再按 taskPatrolledId_taskName 分组
// key: pointStatusvalue: {taskPatrolledId_taskName -> List<InspectionReportData>}
Map<String, Map<String, List<InspectionReportData>>> detailGrouped =
inspectionReportDataList.stream()
.collect(Collectors.groupingBy(
item -> item.getPointStatus() == null ? "unknown" : item.getPointStatus(),
Collectors.groupingBy(item -> item.getTaskPatrolledId() + "_" + item.getTaskName())
));
// 将分组结果转换为所需的格式
for (Map.Entry<String, Map<String, List<InspectionReportData>>> stringMapEntry : detailGrouped.entrySet()) {
// keytaskPatrolledId_taskName -> valueList<InspectionReportData>
Map<String, List<InspectionReportData>> value = stringMapEntry.getValue();
List<Map<String, List<InspectionReportData>>> collect = value.entrySet().stream().map(entry -> {
Map<String, List<InspectionReportData>> 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( @Log(
title = "巡视报告头数据", title = "巡视报告头数据",
businessType = BizType.INSERT businessType = BizType.INSERT


+ 3
- 0
inspect-main/inspect-main-task/src/main/java/com/inspect/insreport/domain/InspectionReport.java View File

@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import lombok.Getter; import lombok.Getter;
@ -102,6 +103,8 @@ public class InspectionReport extends BaseEntity {
List<InspectionReportData> ReportDatalist; List<InspectionReportData> ReportDatalist;
private List<InspectionReportData> info; private List<InspectionReportData> info;
private Map<String, List<Map<String, List<InspectionReportData>>>> detail;
public InspectionReport(String taskResultId) { public InspectionReport(String taskResultId) {
this.taskResultId = taskResultId; this.taskResultId = taskResultId;
} }


+ 7
- 0
inspect-main/inspect-main-task/src/main/java/com/inspect/insreportdata/domain/InspectionReportData.java View File

@ -70,6 +70,10 @@ public class InspectionReportData extends BaseEntity {
List<InspectionReportImg> reportImgList; List<InspectionReportImg> reportImgList;
private String algName; private String algName;
private String taskName;
private String taskPatrolledId;
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (this == object) return true; if (this == object) return true;
@ -100,6 +104,9 @@ public class InspectionReportData extends BaseEntity {
", inspectionImg='" + inspectionImg + '\'' + ", inspectionImg='" + inspectionImg + '\'' +
", reportId='" + reportId + '\'' + ", reportId='" + reportId + '\'' +
", reportImgList=" + reportImgList + ", reportImgList=" + reportImgList +
", algName='" + algName + '\'' +
", taskName='" + taskName + '\'' +
", taskPatrolledId='" + taskPatrolledId + '\'' +
'}'; '}';
} }
} }

+ 1
- 1
inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/IPatrolResultService.java View File

@ -86,7 +86,7 @@ public interface IPatrolResultService {
List<Long> saveReportLingzhou_v2(PatrolTaskResultMain resultMain, List<Long> lineIds, Long currentLineId, List<PatrolResult> resultList); List<Long> saveReportLingzhou_v2(PatrolTaskResultMain resultMain, List<Long> lineIds, Long currentLineId, List<PatrolResult> resultList);
List<Long> saveReportShaoxing(PatrolTaskResultMain resultMain, List<Long> lineIds, Long currentLineId, List<PatrolResult> resultList);
List<Long> saveReportShaoxing(PatrolTaskResultMain resultMain, List<Long> lineIds, List<PatrolResult> resultList);
List saveReportV2(PatrolTaskResultMain patrolTaskResultMain, List<PatrolResult> patrolResultList); List saveReportV2(PatrolTaskResultMain patrolTaskResultMain, List<PatrolResult> patrolResultList);


+ 290
- 250
inspect-main/inspect-main-task/src/main/java/com/inspect/partrolresult/service/impl/PatrolResultServiceImpl.java View File

@ -35,9 +35,11 @@ import com.inspect.task.mapper.PatrolTaskMapper;
import com.inspect.taskstatus.domain.PatrolTaskStatus; import com.inspect.taskstatus.domain.PatrolTaskStatus;
import com.inspect.taskstatus.mapper.PatrolTaskStatusMapper; import com.inspect.taskstatus.mapper.PatrolTaskStatusMapper;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import io.seata.common.util.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -501,19 +503,260 @@ public class PatrolResultServiceImpl implements IPatrolResultService {
} }
@Transactional @Transactional
public List<Long> saveReportShaoxing(PatrolTaskResultMain resultMain, List<Long> lineIds, Long currentLineId, List<PatrolResult> resultList) {
public List<Long> saveReportShaoxing(PatrolTaskResultMain resultMain, List<Long> lineIds, List<PatrolResult> resultList) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
List<Long> reportIds = new ArrayList<>(); List<Long> reportIds = new ArrayList<>();
// 获取站信息
Map<String, String> 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<JSONObject> jsonObjects = JSONObject.parseArray(JSON.toJSONString(ajaxResult.get("data")), JSONObject.class);
List<String> 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<String> taskPatrolledIds = resultList.stream().map(PatrolResult::getTaskPatrolledId).distinct().collect(Collectors.toList());
List<PatrolTaskStatus> patrolTaskStatuses = patrolTaskStatusMapper.selectPatrolTaskStatusListByTaskPatrolledIds(taskPatrolledIds);
List<Date> startTimes = patrolTaskStatuses.stream().map(PatrolTaskStatus::getStartTime).sorted().collect(Collectors.toList());
List<String> endTimes = patrolTaskStatuses.stream().map(PatrolTaskStatus::getEndTime).sorted().collect(Collectors.toList());
startTime = PrintUtil.useTime("导出报告:获取任务进度信息", startTime);
List<String> 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<BasePointAreaInfo> basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(lineIds);
startTime = PrintUtil.useTime("导出报告:获取区域,生产,部件信息", startTime);
List<PatrolResultRef> patrolResultRefs = patrolResultMapper.selectResultRefByLineIds(lineIds, null);
startTime = PrintUtil.useTime("导出报告:获取巡视分析结果数据", startTime);
Map<GroupKey, List<PatrolResultRef>> groupKeyListMap;
if ("0".equals(exportReportFlag)) {
List<PatrolResultRef> 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<PatrolResultRef> processedRefs = new ArrayList<>();
for (Map.Entry<GroupKey, List<PatrolResultRef>> entry : groupKeyListMap.entrySet()) {
List<PatrolResultRef> value = entry.getValue();
GroupKey key = entry.getKey();
String algType = key.algType;
List<PatrolResultRef> filterResults = value.stream().filter(item -> "1".equals(item.getFilter())).collect(Collectors.toList());
List<PatrolResultRef> 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) { for (Long lineId : lineIds) {
resultMain.setLineId(lineId); resultMain.setLineId(lineId);
resultMain.setCheckTime(new Date()); resultMain.setCheckTime(new Date());
resultMain.setFileStatus("1"); 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<PatrolTaskStatus> taskStatuses = this.patrolTaskStatusMapper.selectPatrolTaskStatusList(PatrolTaskStatus.builder().taskPatrolledId(taskPatrolId).build());
if (taskStatuses.isEmpty()) {
throw new ServiceException("LACKING STATUS: " + mainId);
} else {
List<PatrolTask> 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.patrolTaskResultMainMapper.updatePatrolTaskResultMain(resultMain);
this.patrolResultMapper.updatePatrolResultByMainId(String.valueOf(lineId)); this.patrolResultMapper.updatePatrolResultByMainId(String.valueOf(lineId));
reportIds.addAll(saveReportDataShaoxing(resultList, resultMain, lineIds));
} }
PrintUtil.useTime("获取所有报告id", startTime);
return reportIds; return reportIds;
} }
@ -612,240 +855,6 @@ public class PatrolResultServiceImpl implements IPatrolResultService {
} }
} }
public List<Long> saveReportDataShaoxing(List<PatrolResult> resultList, PatrolTaskResultMain resultMain, List<Long> 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<String> 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<PatrolTaskStatus> 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<PatrolTask> list = patrolTaskMapper.selectPatrolTaskList(PatrolTask.builder().taskCode(taskCode).build());
startTime = PrintUtil.useTime("INQUIRY TASK PLAN", startTime);
List<Long> reportIds = new ArrayList<>();
PatrolTask task = new PatrolTask();
if (list.isEmpty()) {
log.error("TASK PLAN LOST: " + taskCode);
} else {
task = list.get(0);
}
Map<String, String> 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<JSONObject> jsonObjects = JSONObject.parseArray(JSON.toJSONString(ajaxResult.get("data")), JSONObject.class);
log.info("EVN LIST: " + jsonObjects);
List<String> 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<PatrolResultRef> patrolResultRefs = patrolResultMapper.selectResultRefByLineIds(lineIds, null);
Map<GroupKey, List<PatrolResultRef>> groupKeyListMap;
if ("0".equals(exportReportFlag)) {
List <PatrolResultRef> 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<PatrolResultRef> processedRefs = new ArrayList<>();
for (Map.Entry<GroupKey, List<PatrolResultRef>> entry : groupKeyListMap.entrySet()) {
List<PatrolResultRef> value = entry.getValue();
GroupKey key = entry.getKey();
String algType = key.algType;
List<PatrolResultRef> filterResults = value.stream().filter(item -> "1".equals(item.getFilter())).collect(Collectors.toList());
List<PatrolResultRef> 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<Long> saveReportDataLingzhou_v1(List<PatrolResult> resultList, PatrolTaskResultMain resultMain, List<Long> lineIds, int aiQxNum, int csQxNum) { public List<Long> saveReportDataLingzhou_v1(List<PatrolResult> resultList, PatrolTaskResultMain resultMain, List<Long> lineIds, int aiQxNum, int csQxNum) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
String mainId = String.valueOf(resultMain.getLineId()); String mainId = String.valueOf(resultMain.getLineId());
@ -1233,11 +1242,18 @@ public class PatrolResultServiceImpl implements IPatrolResultService {
} }
} }
public void batchInsertReportData_shaoxing(String reportId, List<Long> mainIds, String filter, List<PatrolResultRef> patrolResultRefs) {
log.info("batchInsertReportData reportId:" + reportId + ", mainIds:" + mainIds + ", filter:" + filter);
long startTime = System.currentTimeMillis();
public void batchInsertReportData_shaoxing(String reportId, List<PatrolResultRef> patrolResultRefs, List<BasePointAreaInfo> basePointAreaInfoList, List<String> taskPatrolledIds) {
Map<String, Map<String, Long>> taskCounterMap = new HashMap<>();
// 为每个任务初始化计数器
for (String item : taskPatrolledIds) {
Map<String, Long> counter = new HashMap<>();
counter.put("defect", 0L);
counter.put("ok", 0L);
counter.put("fail", 0L);
taskCounterMap.put(item, counter);
}
List<BasePointAreaInfo> basePointAreaInfoList = patrolResultMapper.selectBaseInfoByMainIds(mainIds);
log.info("REPORTS SIZE: {}", patrolResultRefs.size()); log.info("REPORTS SIZE: {}", patrolResultRefs.size());
List<InspectionReportData> reportDatas = new ArrayList<>(); List<InspectionReportData> reportDatas = new ArrayList<>();
List<InspectionReportImg> reportImages = new ArrayList<>(); List<InspectionReportImg> reportImages = new ArrayList<>();
@ -1249,6 +1265,9 @@ public class PatrolResultServiceImpl implements IPatrolResultService {
for (index = 0; index < patrolResultRefs.size(); ++index) { for (index = 0; index < patrolResultRefs.size(); ++index) {
PatrolResultRef patrolResultRef = patrolResultRefs.get(index); PatrolResultRef patrolResultRef = patrolResultRefs.get(index);
String devType = patrolResultRef.getDevType(); String devType = patrolResultRef.getDevType();
// 获取该结果所属的任务名
String resultTaskName = patrolResultRef.getTaskName();
String taskPatrolledId = patrolResultRef.getTaskPatrolledId();
BasePointAreaInfo basePointAreaInfo; BasePointAreaInfo basePointAreaInfo;
try { try {
basePointAreaInfo = basePointAreaInfoList.stream().filter((item) -> item != null && patrolResultRef.getDeviceId().equals(item.getDeviceId())).findFirst().get(); 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.setPointName(basePointAreaInfo.getPatrolPointName());
reportData.setDataSources(patrolResultRef.getDeviceSource()); reportData.setDataSources(patrolResultRef.getDeviceSource());
reportData.setAcquisitionTime(DateUtils.parse(DateUtils.yyyyMMddHHmmss2, patrolResultRef.getTime())); reportData.setAcquisitionTime(DateUtils.parse(DateUtils.yyyyMMddHHmmss2, patrolResultRef.getTime()));
reportData.setTaskName(resultTaskName);
reportData.setTaskPatrolledId(taskPatrolledId);
if ("1".equals(patrolResultRef.getResultType()) && validAlgTypes.contains(patrolResultRef.getAlgType())) { if ("1".equals(patrolResultRef.getResultType()) && validAlgTypes.contains(patrolResultRef.getAlgType())) {
reportData.setInspectionResults(patrolResultRef.getValue()); reportData.setInspectionResults(patrolResultRef.getValue());
} else { } else {
@ -1295,18 +1316,37 @@ public class PatrolResultServiceImpl implements IPatrolResultService {
continue; continue;
} else if (resultType.equals("0")) { } else if (resultType.equals("0")) {
reportData.setPointStatus(messageUtils.get("缺陷")); reportData.setPointStatus(messageUtils.get("缺陷"));
// 缺陷编号
++defectNum;
reportData.setCode(defectNum);
// 按任务统计异常编号
Map<String, Long> 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")) { } else if (resultType.equals("1")) {
reportData.setPointStatus(messageUtils.get("正常")); reportData.setPointStatus(messageUtils.get("正常"));
++okNum;
reportData.setCode(okNum);
// 按任务统计异常编号
Map<String, Long> 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 { } else {
reportData.setPointStatus(messageUtils.get("异常")); reportData.setPointStatus(messageUtils.get("异常"));
// 异常编号
++failNum;
reportData.setCode(failNum);
// 按任务统计异常编号
Map<String, Long> 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); final String reportDataId = reportId + "_" + (100000 + index);


+ 7
- 10
inspect-main/inspect-main-task/src/main/java/com/inspect/resultmain/controller/PatrolTaskResultMainController.java View File

@ -265,23 +265,20 @@ public class PatrolTaskResultMainController extends BaseController {
public AjaxResult updateInfo_shaoxing( public AjaxResult updateInfo_shaoxing(
@RequestBody PatrolTaskResultMain resultMain) { @RequestBody PatrolTaskResultMain resultMain) {
long startTime = System.currentTimeMillis(); 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<String> taskPatrolledIds = resultMain.getTaskPatrolledIds();
logger.info("-----------patrolTaskResultMains taskPatrolledIds: {}", taskPatrolledIds);
List<PatrolTaskResultMain> patrolTaskResultMains = patrolTaskResultMainService.selectPatrolTaskResultMainByTaskPatrolledIds(taskPatrolledIds);
logger.info("-----------patrolTaskResultMains: {}", patrolTaskResultMains);
if (patrolTaskResultMains.size() == 0) {
logger.error("[归档]失败, 数据采集中..."); logger.error("[归档]失败, 数据采集中...");
return AjaxResult.error("数据采集中请稍后...."); return AjaxResult.error("数据采集中请稍后....");
} }
Long lineId = patrolTaskResultMain.getLineId();
List<Long> lineIds = new ArrayList<>();
lineIds.add(lineId);
List<Long> lineIds = patrolTaskResultMains.stream().map(PatrolTaskResultMain::getLineId).collect(Collectors.toList());
List<Long> longs = patrolTaskResultMainService.selectLineIdsByList(lineIds); List<Long> longs = patrolTaskResultMainService.selectLineIdsByList(lineIds);
if (longs != null && longs.size() > 0) { if (longs != null && longs.size() > 0) {
lineIds.addAll(longs); lineIds.addAll(longs);
} }
lineIds = lineIds.stream().distinct().collect(Collectors.toList()); lineIds = lineIds.stream().distinct().collect(Collectors.toList());
logger.info("---归档--lineIds size: {},lineIds:{}", lineIds.size(), lineIds);
List<PatrolResult> resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds); List<PatrolResult> resultList = patrolResultService.selectPatrolResultListByMainIds(lineIds);
if (resultList.isEmpty()) { if (resultList.isEmpty()) {
logger.error("[归档]失败, 数据采集中..."); logger.error("[归档]失败, 数据采集中...");
@ -291,7 +288,7 @@ public class PatrolTaskResultMainController extends BaseController {
startTime = PrintUtil.useTime("查询统计数据", startTime); startTime = PrintUtil.useTime("查询统计数据", startTime);
CompletableFuture<List<Long>> saveReportFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<Long>> saveReportFuture = CompletableFuture.supplyAsync(() -> {
logger.info("[ARCHIVE] Start saving reports"); logger.info("[ARCHIVE] Start saving reports");
return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, lineId, resultList);
return patrolResultService.saveReportShaoxing(resultMain, finalLineIds, resultList);
}, executor).exceptionally(ex -> { }, executor).exceptionally(ex -> {
logger.error("Report saving failed", ex); logger.error("Report saving failed", ex);
return Collections.emptyList(); return Collections.emptyList();


+ 7
- 3
inspect-main/inspect-main-task/src/main/resources/mapper/task/InspectionReportDataMapper.xml View File

@ -19,6 +19,8 @@
<result property="inspectionImg" column="inspection_img"/> <result property="inspectionImg" column="inspection_img"/>
<result property="reportId" column="report_id"/> <result property="reportId" column="report_id"/>
<result property="algName" column="alg_name"/> <result property="algName" column="alg_name"/>
<result property="taskName" column="task_name"/>
<result property="taskPatrolledId" column="task_patrolled_id"/>
</resultMap> </resultMap>
<sql id="selectInspectionReportDataVo"> <sql id="selectInspectionReportDataVo">
@ -35,7 +37,9 @@
inspection_results, inspection_results,
point_status, point_status,
inspection_img, inspection_img,
alg_name
alg_name,
task_name,
task_patrolled_id
from inspection_report_data from inspection_report_data
</sql> </sql>
@ -158,11 +162,11 @@
</delete> </delete>
<insert id="batchInsertInspectionReportData" parameterType="java.util.List"> <insert id="batchInsertInspectionReportData" parameterType="java.util.List">
insert into inspection_report_data 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 values
<foreach collection="list" item="t" index="index" separator=","> <foreach collection="list" item="t" index="index" separator=",">
(#{t.lineId}, #{t.code}, #{t.reportId}, #{t.area}, #{t.timeInterval}, #{t.eqName}, #{t.parts}, (#{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})
</foreach> </foreach>
</insert> </insert>
</mapper> </mapper>

+ 2
- 0
inspect-main/inspect-main-task/src/main/resources/mapper/task/PatrolResultMapper.xml View File

@ -603,6 +603,7 @@
<resultMap type="PatrolResultRef" id="PatrolResultRef"> <resultMap type="PatrolResultRef" id="PatrolResultRef">
<result property="lineId" column="line_id"/> <result property="lineId" column="line_id"/>
<result property="deviceId" column="device_id"/> <result property="deviceId" column="device_id"/>
<result property="taskName" column="task_name"/>
<result property="devType" column="dev_type"/> <result property="devType" column="dev_type"/>
<result property="deviceSource" column="device_source"/> <result property="deviceSource" column="device_source"/>
<result property="time" column="time"/> <result property="time" column="time"/>
@ -642,6 +643,7 @@
<select id="selectResultRefByLineIds" resultMap="PatrolResultRef"> <select id="selectResultRefByLineIds" resultMap="PatrolResultRef">
select a.line_id, select a.line_id,
a.device_id, a.device_id,
a.task_name,
c.dev_type, c.dev_type,
COALESCE(e.device_source, h.device_source) as device_source, COALESCE(e.device_source, h.device_source) as device_source,
a.time, a.time,


Loading…
Cancel
Save