|
|
@ -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); |
|
|
|