|
|
|
@ -2,6 +2,7 @@ package com.inspect.partrolresult.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.inspect.analysis.domain.AlgValue; |
|
|
|
import com.inspect.analysis.domain.AnalyseResPoint; |
|
|
|
import com.inspect.analysis.domain.ResultAnalysis; |
|
|
|
import com.inspect.analysis.domain.resultList; |
|
|
|
@ -31,11 +32,8 @@ import com.inspect.task.mapper.PatrolTaskMapper; |
|
|
|
import com.inspect.taskstatus.domain.PatrolTaskStatus; |
|
|
|
import com.inspect.taskstatus.mapper.PatrolTaskStatusMapper; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@ -94,6 +92,10 @@ public class PatrolResultServiceImpl implements IPatrolResultService { |
|
|
|
return patrolResultMapper.selectPatrolResultList(patrolResult); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultAnalysis selectTaskAbnormalData(ResultAnalysis patrolResult) { |
|
|
|
return resultAnalysisMapper.selectTaskAbnormalData(patrolResult); |
|
|
|
} |
|
|
|
|
|
|
|
public List<PatrolResult> selectPatrolResultListOrderBy(PatrolResult patrolResult) { |
|
|
|
return patrolResultMapper.selectPatrolResultListOrderBy(patrolResult); |
|
|
|
} |
|
|
|
@ -318,6 +320,19 @@ public class PatrolResultServiceImpl implements IPatrolResultService { |
|
|
|
return saveReportData(resultList, resultMain, lineIds); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
public List saveReportV2(PatrolTaskResultMain resultMain, List<PatrolResult> resultList) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
String mainId = String.valueOf(resultMain.getLineId()); |
|
|
|
resultMain.setCheckTime(new Date()); |
|
|
|
resultMain.setFileStatus("1"); |
|
|
|
patrolTaskResultMainMapper.updatePatrolTaskResultMain(resultMain); |
|
|
|
patrolResultMapper.updatePatrolResultByMainId(mainId); |
|
|
|
PrintUtil.useTime("修正数据", startTime); |
|
|
|
List reportIds = saveReportDataV2(resultList, resultMain); |
|
|
|
return reportIds; |
|
|
|
} |
|
|
|
|
|
|
|
public Long saveReportData(List<PatrolResult> resultList, PatrolTaskResultMain resultMain, List<Long> lineIds) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
String mainId = String.valueOf(resultMain.getLineId()); |
|
|
|
@ -381,6 +396,96 @@ public class PatrolResultServiceImpl implements IPatrolResultService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public List saveReportDataV2(List<PatrolResult> resultList, PatrolTaskResultMain resultMain) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
String mainId = String.valueOf(resultMain.getLineId()); |
|
|
|
String filterNum = statisticsAnalyseNumV2(mainId, "1"); |
|
|
|
String AiNum = statisticsAnalyseNumV2(mainId, "0"); |
|
|
|
String[] nums = new String[]{AiNum, filterNum}; |
|
|
|
startTime = PrintUtil.useTime("统计分析数据", startTime); |
|
|
|
if(resultList.isEmpty()) { |
|
|
|
throw new ServiceException("缺少巡检结果:" + mainId); |
|
|
|
} else { |
|
|
|
PatrolResult patrolResult = resultList.get(0); |
|
|
|
String taskCode = patrolResult.getTaskCode(); |
|
|
|
String taskPatrolId = patrolResult.getTaskPatrolledId(); |
|
|
|
if(StringUtils.isEmpty(taskPatrolId)) { |
|
|
|
throw new ServiceException("缺少执行ID:" + mainId); |
|
|
|
} else { |
|
|
|
List<PatrolTaskStatus> taskStatuses = this.patrolTaskStatusMapper.selectPatrolTaskStatusList(new PatrolTaskStatus(taskPatrolId)); |
|
|
|
startTime = PrintUtil.useTime("查询状态数据", startTime); |
|
|
|
if(taskStatuses.isEmpty()) { |
|
|
|
throw new ServiceException("缺少状态数据:" + mainId); |
|
|
|
} else { |
|
|
|
PatrolTaskStatus taskStatus = taskStatuses.get(0); |
|
|
|
PatrolTask patrolTask = new PatrolTask(); |
|
|
|
patrolTask.setTaskCode(taskCode); |
|
|
|
List<PatrolTask> list = this.patrolTaskMapper.selectPatrolTaskList(patrolTask); |
|
|
|
startTime = PrintUtil.useTime("查询任务计划", startTime); |
|
|
|
if(list.isEmpty()) { |
|
|
|
throw new ServiceException("任务计划丢失:" + taskCode); |
|
|
|
} else { |
|
|
|
PatrolTask task = list.get(0); |
|
|
|
startTime = PrintUtil.useTime("查询任务报告", startTime); |
|
|
|
Map<String, String> stationMap = patrolResultMapper.selectBasedataStation(); |
|
|
|
String stationName = stationMap.get("station_name"); |
|
|
|
String stationType = stationMap.get("station_type"); |
|
|
|
ResultAnalysis resultAnalysis = new ResultAnalysis(); |
|
|
|
resultAnalysis.setTaskPatrolledId(resultList.get(0).getTaskPatrolledId()); |
|
|
|
ResultAnalysis ras = resultAnalysisMapper.selectTaskAbnormalData(resultAnalysis); |
|
|
|
int ii = 0; |
|
|
|
int iii = 0; |
|
|
|
if(0 == ras.getCsQxNum()) { |
|
|
|
ras.setFilter("0"); |
|
|
|
ii = 0; |
|
|
|
iii = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 == ras.getAiQxNum()) { |
|
|
|
ras.setFilter("1"); |
|
|
|
ii = 0; |
|
|
|
iii = 1; |
|
|
|
} |
|
|
|
|
|
|
|
if(0 != ras.getCsQxNum() && 0 != ras.getAiQxNum()) { |
|
|
|
ras.setFilter("2"); |
|
|
|
ii = 2; |
|
|
|
} |
|
|
|
Long[] ids = new Long[ii]; |
|
|
|
List list1 = new ArrayList<>(); |
|
|
|
|
|
|
|
for(int i = 0; i < 2; ++i) { |
|
|
|
if(0 != ras.getCsQxNum() && 0 != ras.getAiQxNum()) { |
|
|
|
iii = i; |
|
|
|
} |
|
|
|
|
|
|
|
if(i != Integer.parseInt(ras.getFilter())) { |
|
|
|
InspectionReport report = new InspectionReport(); |
|
|
|
resetReport(report, nums[iii], mainId, task, taskStatus); |
|
|
|
report.setFilter(iii + ""); |
|
|
|
report.setTaskId(String.valueOf(task.getTaskId())); |
|
|
|
report.setTaskPatrolledId(taskPatrolId); |
|
|
|
report.setInspectionTaskName(task.getTaskName()); |
|
|
|
report.setDescription(resultMain.getTaskResult()); |
|
|
|
report.setCheckPerson(resultMain.getCheckPerson()); |
|
|
|
report.setCheckTime(resultMain.getCheckTime()); |
|
|
|
report.setStationName(stationName); |
|
|
|
report.setVoltLevel(this.voltage); |
|
|
|
report.setStationType(stationType); |
|
|
|
inspectionReportMapper.insertInspectionReport(report); |
|
|
|
PrintUtil.useTime("新增任务报告", startTime); |
|
|
|
batchInsertReportDataV2(String.valueOf(report.getLineId()), mainId, iii + ""); |
|
|
|
list1.add(report.getLineId()); |
|
|
|
PrintUtil.useTime("批量插入明细", startTime); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return list1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
private void resetReport(InspectionReport report, String analyseNum, String mainId, PatrolTask task, PatrolTaskStatus taskStatus) { |
|
|
|
report.setPatrolStatistics(analyseNum); |
|
|
|
//report.setInspectionDate(task.getCreateTime()); |
|
|
|
@ -506,6 +611,138 @@ public class PatrolResultServiceImpl implements IPatrolResultService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void batchInsertReportDataV2(String reportId, String mainId, String filter) { |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
long okNum = 1L; |
|
|
|
long failNum = 1L; |
|
|
|
long confirmNum = 1L; |
|
|
|
List<PatrolResultRef> patrolResultRefs = patrolResultMapper.selectResultRefByLineId(mainId); |
|
|
|
patrolResultRefs = patrolResultRefs.stream().filter((item) -> { |
|
|
|
return filter.equals(item.getFilter()); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
startTime = PrintUtil.useTime("查询结果关联信息", startTime); |
|
|
|
List<BasePointAreaInfo> areas = patrolResultMapper.selectBaseInfoByMainIdByReport(mainId); |
|
|
|
List<AlgInfo> algInfos = patrolResultMapper.selectAlgInfo(new PatrolResult()); |
|
|
|
PrintUtil.useTime("查询地区", startTime); |
|
|
|
log.info("[报告点位数量]: {}", patrolResultRefs.size()); |
|
|
|
List<InspectionReportData> reportDatas = new ArrayList<>(); |
|
|
|
List<InspectionReportImg> reportImages = new ArrayList<>(); |
|
|
|
|
|
|
|
int i; |
|
|
|
for(i = 0; i < patrolResultRefs.size(); ++i) { |
|
|
|
PatrolResultRef ref = patrolResultRefs.get(i); |
|
|
|
ref.setAlgName(algInfos.stream().filter((alg) -> { |
|
|
|
return alg.getAlgSubtypeCode().equals(ref.getAlgType()); |
|
|
|
}).findFirst().get().getAlgSubtypeName()); |
|
|
|
String type = ref.getDevType(); |
|
|
|
|
|
|
|
BasePointAreaInfo area; |
|
|
|
try { |
|
|
|
area = areas.stream().filter((item) -> { |
|
|
|
return item != null && ref.getDeviceId().equals(item.getPatrolPointId()); |
|
|
|
}).findFirst().get(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("[整理报告明细] 该点位没有所属区域: {}", ref.getDeviceId()); |
|
|
|
area = new BasePointAreaInfo(); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> map = null; |
|
|
|
BasePointAreaInfo basePointAreaInfo; |
|
|
|
if(StringUtils.isNotNull(area.getEqpBookId())) { |
|
|
|
basePointAreaInfo = new BasePointAreaInfo(); |
|
|
|
basePointAreaInfo.setEqpBookId(area.getEqpBookId()); |
|
|
|
map = patrolResultMapper.selectDeviceNameById(basePointAreaInfo); |
|
|
|
} |
|
|
|
|
|
|
|
if(StringUtils.isNotNull(area.getChannelId())) { |
|
|
|
basePointAreaInfo = new BasePointAreaInfo(); |
|
|
|
basePointAreaInfo.setChannelId(area.getChannelId()); |
|
|
|
map = patrolResultMapper.selectDeviceNameById(basePointAreaInfo); |
|
|
|
} |
|
|
|
|
|
|
|
InspectionReportData reportData = new InspectionReportData(); |
|
|
|
reportData.setReportId(reportId); |
|
|
|
reportData.setArea(area.getAreaName()); |
|
|
|
reportData.setTimeInterval(area.getJgName()); |
|
|
|
reportData.setEqName(area.getMainName()); |
|
|
|
reportData.setParts(area.getDeviceName()); |
|
|
|
reportData.setPointName(area.getPatrolPointName()); |
|
|
|
reportData.setAlgName(ref.getAlgName()); |
|
|
|
if(type.equals("0") || type.equals("1")) { |
|
|
|
reportData.setDataSources(map.get("device_source") + "/" + map.get("patrol_device_name")); |
|
|
|
} else { |
|
|
|
reportData.setDataSources(map.get("device_source") + "/" + map.get("channel_name")); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
reportData.setAcquisitionTime(DateUtil.parseDateTime(ref.getTime())); |
|
|
|
} catch (Exception e) { |
|
|
|
reportData.setAcquisitionTime(new Date()); |
|
|
|
} |
|
|
|
|
|
|
|
String desc = ref.getResDesc(); |
|
|
|
String resultContent; |
|
|
|
if("meter".equals(ref.getAlgType()) || "infrared".equals(ref.getAlgType())) { |
|
|
|
desc = ref.getResValue(); |
|
|
|
AlgValue algValue = new AlgValue(); |
|
|
|
resultContent = algValue.formatValue(desc); |
|
|
|
if(resultContent.equals("1")) { |
|
|
|
desc = "采集图片为空"; |
|
|
|
} else if(resultContent.equals("-1")) { |
|
|
|
desc = "与样本有差异"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reportData.setInspectionResults(desc); |
|
|
|
if("meter".equals(ref.getAlgType())) { |
|
|
|
if("0".equals(ref.getPointStatus())) { |
|
|
|
reportData.setPointStatus(ref.getDescription() + "(" + ref.getResValue() + ")"); |
|
|
|
} else { |
|
|
|
reportData.setPointStatus(ref.getResValue()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
reportData.setPointStatus(ref.getDescription()); |
|
|
|
} |
|
|
|
|
|
|
|
reportData.setPointStatus("异常"); |
|
|
|
reportData.setCode(failNum); |
|
|
|
++failNum; |
|
|
|
String reportDataId = reportId + "_" + (100000 + i); |
|
|
|
reportData.setLineId(reportDataId); |
|
|
|
reportDatas.add(reportData); |
|
|
|
resultContent = ref.getResultContent(); |
|
|
|
AnalyseResPoint resPoint = JSONObject.parseObject(resultContent, AnalyseResPoint.class); |
|
|
|
String imgUrl = resPoint.getResImageUrl(); |
|
|
|
if(StringUtils.isEmpty(imgUrl)) { |
|
|
|
imgUrl = ref.getFilePath().split(StringUtils.COMMA)[0]; |
|
|
|
} |
|
|
|
|
|
|
|
InspectionReportImg reportImg = new InspectionReportImg(); |
|
|
|
reportImg.setReportInfoId(reportDataId); |
|
|
|
reportImg.setImg(ref.getResImgUrl()); |
|
|
|
reportImg.setImgSrc(ref.getResImgUrl()); |
|
|
|
reportImg.setImgType("0"); |
|
|
|
reportImg.setCreatTime(new Date()); |
|
|
|
reportImages.add(reportImg); |
|
|
|
} |
|
|
|
|
|
|
|
i = reportDatas.size() / 50; |
|
|
|
if(reportDatas.size() % 50 > 0) { |
|
|
|
++i; |
|
|
|
} |
|
|
|
|
|
|
|
for(int j = 0; j < reportDatas.size(); j += 50) { |
|
|
|
log.info("[批量插入报告明细] 进度: {}/{}", j / 50 + 1, j); |
|
|
|
int end = j + 50; |
|
|
|
if(end > reportDatas.size()) { |
|
|
|
end = reportDatas.size(); |
|
|
|
} |
|
|
|
|
|
|
|
inspectionReportDataMapper.batchInsertInspectionReportData(reportDatas.subList(j, end)); |
|
|
|
inspectionReportImgMapper.batchInsertInspectionReportImg(reportImages.subList(j, end)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public String statisticsAnalyseNum(List<Long> lineIds, int totalNum) { |
|
|
|
int okNum = 0; |
|
|
|
int failNum = 0; |
|
|
|
@ -535,6 +772,58 @@ public class PatrolResultServiceImpl implements IPatrolResultService { |
|
|
|
return String.format(messageUtils.get("总点位:%d个,已检点位:%d个,未检点位:0个,正常点位:%d个,异常点位:%d个,待人工确认点位:%d个。"), totalNum, totalNum, okNum, failNum, confirmNum); |
|
|
|
} |
|
|
|
|
|
|
|
public String statisticsAnalyseNumV2(String mainId, String filter) { |
|
|
|
int okNum = 0; |
|
|
|
int failNum = 0; |
|
|
|
int confirmNum = 0; |
|
|
|
ResultAnalysis resultAnalysis = new ResultAnalysis(mainId); |
|
|
|
resultAnalysis.setFilter(filter); |
|
|
|
List<ResultAnalysis> analyses = resultAnalysisMapper.selectResultAnalysisListByMainIdNew(resultAnalysis); |
|
|
|
|
|
|
|
for (ResultAnalysis analyse : analyses) { |
|
|
|
String var10 = analyse.getResStatus(); |
|
|
|
byte var11 = -1; |
|
|
|
switch (var10.hashCode()) { |
|
|
|
case 49: |
|
|
|
if (var10.equals("1")) { |
|
|
|
var11 = 0; |
|
|
|
} |
|
|
|
break; |
|
|
|
case 50: |
|
|
|
if (var10.equals("2")) { |
|
|
|
var11 = 1; |
|
|
|
} |
|
|
|
break; |
|
|
|
case 51: |
|
|
|
if (var10.equals("3")) { |
|
|
|
var11 = 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch (var11) { |
|
|
|
case 0: |
|
|
|
++failNum; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
++okNum; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
++confirmNum; |
|
|
|
break; |
|
|
|
default: |
|
|
|
log.error("【归档-统计分析数量】异常分析类型:{}", analyse.getPointStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int totalNum = analyses.size(); |
|
|
|
int lastNum = totalNum - failNum - confirmNum; |
|
|
|
if(lastNum != okNum) { |
|
|
|
; |
|
|
|
} |
|
|
|
|
|
|
|
return String.format("缺陷总数:%d个", totalNum); |
|
|
|
} |
|
|
|
|
|
|
|
public List<PatrolResultRef> selectResultRefByLineId(String mainId) { |
|
|
|
return this.patrolResultMapper.selectResultRefByLineId(mainId); |
|
|
|
} |
|
|
|
|