From a163150feca94c0d9b90941b9cf599800dc50b92 Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Fri, 12 Sep 2025 09:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=9B=91=E6=B5=8B=E7=82=B9?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E3=80=81=E8=AE=BE=E5=A4=87=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SocketContrastResponseService.java | 82 ++++++------ .../handler/SocketDevResponseService.java | 2 +- .../service/impl/DetectionServiceImpl.java | 6 + .../service/impl/PreDetectionServiceImpl.java | 2 +- .../util/socket/cilent/HeartbeatHandler.java | 4 +- .../socket/websocket/WebSocketHandler.java | 2 +- .../gather/device/service/IPqDevService.java | 11 +- .../device/service/impl/PqDevServiceImpl.java | 37 ++++- .../gather/monitor/pojo/po/PqMonitor.java | 31 +++++ .../monitor/service/IPqMonitorService.java | 32 ++++- .../service/impl/PqMonitorServiceImpl.java | 126 ++++++++++++++++++ .../result/controller/ResultController.java | 31 ++++- .../result/pojo/vo/DataSourceResultVO.java | 26 ++++ .../result/pojo/vo/MonitorResultVO.java | 51 +++++++ .../gather/result/service/IResultService.java | 9 +- .../service/impl/ResultServiceImpl.java | 14 +- .../service/DetectionDataDealService.java | 24 +++- .../impl/DetectionDataServiceImpl.java | 42 +++++- 18 files changed, 462 insertions(+), 70 deletions(-) create mode 100644 detection/src/main/java/com/njcn/gather/result/pojo/vo/DataSourceResultVO.java create mode 100644 detection/src/main/java/com/njcn/gather/result/pojo/vo/MonitorResultVO.java diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketContrastResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketContrastResponseService.java index dbb0a0d4..9ea5a405 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketContrastResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketContrastResponseService.java @@ -13,10 +13,7 @@ import com.google.common.collect.HashBiMap; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.gather.detection.pojo.dto.WaveCommandDTO; import com.njcn.gather.detection.pojo.dto.WaveResultDTO; -import com.njcn.gather.detection.pojo.enums.DetectionCodeEnum; -import com.njcn.gather.detection.pojo.enums.DetectionResponseEnum; -import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; -import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; +import com.njcn.gather.detection.pojo.enums.*; import com.njcn.gather.detection.pojo.param.ContrastDetectionParam; import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam; @@ -954,6 +951,7 @@ public class SocketContrastResponseService { webSend.setData(JSON.toJSONString(allResultList)); List adTypes = FormalTestManager.testItemMap.values().stream().collect(Collectors.toList()); + Map result = detectionDataDealService.devResult(true, FormalTestManager.pairsIdMap.keySet().stream().collect(Collectors.toList()), adTypes, code); // 若有不符合的 // if (result.values().stream().anyMatch(r -> r.equals(ResultEnum.NOT_QUALIFIED.getValue()))) { @@ -962,42 +960,42 @@ public class SocketContrastResponseService { webSend.setCode(SourceResponseCodeEnum.REAL_DATA_CHECK_FAIL.getCode());// 实时数据检测失败,最终错误推送 WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSend)); - System.out.println("实时数据校验失败!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始录波》》》》》》》》》》》》》》》》"); // 判断是否启用录波 String datasourceId = FormalTestManager.currentTestPlan.getDatasourceId(); if (datasourceId.contains(DataSourceEnum.WAVE_DATA.getValue())) { + System.out.println("实时数据校验失败!》》》》》》》》》》》》》》》》》》》》》》》》》》》》》开始录波》》》》》》》》》》》》》》》》"); SocketMsg socketMsg = new SocketMsg<>(); socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue()); Map> map = new HashMap<>(1); -// Set delSet = new HashSet<>(); -// for (int i = 0; i < FormalTestManager.devList.size(); i++) { -// PreDetection preDetection = FormalTestManager.devList.get(i); -// List monitorList = preDetection.getMonitorList(); -// for (int j = monitorList.size() - 1; j >= 0; j--) { -// String lineId = monitorList.get(j).getLineId(); -// String[] split = lineId.split(CnSocketUtil.SPLIT_TAG); -// Integer res = result.get(FormalTestManager.devIdMapComm.get(split[1])); -// if (res.equals(ResultEnum.NOT_QUALIFIED.getValue())) { -// monitorList.remove(j); -// delSet.add(lineId); -// FormalTestManager.monitorMap.remove(lineId); -// } -// } -// } -// for (int i = 0; i < FormalTestManager.standardDevList.size(); i++) { -// PreDetection preDetection = FormalTestManager.standardDevList.get(i); -// List monitorList = preDetection.getMonitorList(); -// for (int j = monitorList.size() - 1; j >= 0; j--) { -// String lineId = monitorList.get(j).getLineId(); -// String s1 = FormalTestManager.pairsIpMap.inverse().get(lineId); -// if (delSet.contains(s1)) { -// monitorList.remove(j); -// FormalTestManager.monitorMap.remove(lineId); -// } -// } -// } + Set delSet = new HashSet<>(); + for (int i = 0; i < FormalTestManager.devList.size(); i++) { + PreDetection preDetection = FormalTestManager.devList.get(i); + List monitorList = preDetection.getMonitorList(); + for (int j = monitorList.size() - 1; j >= 0; j--) { + String lineId = monitorList.get(j).getLineId(); + String[] split = lineId.split(CnSocketUtil.SPLIT_TAG); + Integer res = result.get(FormalTestManager.devIdMapComm.get(split[0]) + split[1]); + if (ObjectUtil.isNotNull(res) && res.equals(ResultEnum.NOT_QUALIFIED.getValue())) { + monitorList.remove(j); + delSet.add(lineId); + FormalTestManager.monitorMap.remove(lineId); + } + } + } + for (int i = 0; i < FormalTestManager.standardDevList.size(); i++) { + PreDetection preDetection = FormalTestManager.standardDevList.get(i); + List monitorList = preDetection.getMonitorList(); + for (int j = monitorList.size() - 1; j >= 0; j--) { + String lineId = monitorList.get(j).getLineId(); + String s1 = FormalTestManager.pairsIpMap.inverse().get(lineId); + if (delSet.contains(s1)) { + monitorList.remove(j); + FormalTestManager.monitorMap.remove(lineId); + } + } + } List preDetectionList = new ArrayList<>(); preDetectionList.addAll(FormalTestManager.devList); @@ -1012,9 +1010,11 @@ public class SocketContrastResponseService { // 最终将检测结果推送到前端 webSend.setCode(SourceResponseCodeEnum.ALL_SUCCESS.getCode());//最终成功推送 WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSend)); - // 修改设备状态 - - pqDevService.updateResult(true, param.getDevIds(), adTypes, code, param.getUserId(), param.getTemperature(), param.getHumidity()); + // 修改检测点状态、设备状态 + FormalTestManager.pairsIdMap.forEach((id1, id2) -> { + pqMonitorService.updateMonitorResult(id1, adTypes, DataSourceEnum.REAL_DATA, FormalTestManager.numMap.get(id1), null, code); + pqDevService.updateResult(id1.split(CnSocketUtil.SPLIT_TAG)[0], param.getUserId()); + }); } } } @@ -1190,9 +1190,15 @@ public class SocketContrastResponseService { CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, false); List adTypes = FormalTestManager.testItemMap.values().stream().collect(Collectors.toList()); - // 修改设备状态 - //pqDevService.updateResult(true, param.getDevIds(), adTypes, code, param.getUserId(), param.getTemperature(), param.getHumidity()); - + // 修改检测点状态、设备状态 + FormalTestManager.pairsIpMap.forEach((ip1, ip2) -> { + if (FormalTestManager.monitorMap.containsKey(ip1)) { + String[] split = ip1.split(CnSocketUtil.SPLIT_TAG); + String id = FormalTestManager.devIdMapComm.get(split[0]); + pqMonitorService.updateMonitorResult(id + CnSocketUtil.SPLIT_TAG + split[1], adTypes, DataSourceEnum.WAVE_DATA, FormalTestManager.numMap.get(id + CnSocketUtil.SPLIT_TAG + split[1]), FormalTestManager.waveNum, code); + pqDevService.updateResult(id, param.getUserId()); + } + }); // 最终将检测结果推送到前端 webSend.setCode(SourceResponseCodeEnum.ALL_SUCCESS.getCode()); webSend.setData(JSON.toJSONString(FormalTestManager.preNumTestResultList)); diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java index a2200c6a..64152679 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java @@ -1371,7 +1371,7 @@ public class SocketDevResponseService { checkDataParam.setIsValueTypeName(false); List valueType = iPqScriptCheckDataService.getValueType(checkDataParam); - iPqDevService.updateResult(false, param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); + iPqDevService.updateResult( param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); CnSocketUtil.quitSend(param); } successComm.clear(); diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java index 68b60679..2b642b3a 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/DetectionServiceImpl.java @@ -1741,6 +1741,9 @@ public class DetectionServiceImpl { result.setStdDevMonitorId(devIdMapComm.get(split2[0]) + "_" + split2[1]); result.setAdType(errSysDtls.get(0).getScriptType()); result.setDataType(DataSourceEnum.REAL_DATA.getValue()); + if (ObjectUtil.isNotNull(waveNum)) { + result.setDataType(DataSourceEnum.WAVE_DATA.getValue()); + } if (map.containsKey(TYPE_T)) { List tList = rangeComparisonList(map.get(TYPE_T).get(0), map.get(TYPE_T).get(1), errSysDtls, fData, scale, dataRule); @@ -1852,6 +1855,9 @@ public class DetectionServiceImpl { result.setStdDevMonitorId(devIdMapComm.get(split2[0]) + "_" + split2[1]); result.setAdType(errSysDtls.get(0).getScriptType()); result.setDataType(DataSourceEnum.REAL_DATA.getValue()); + if (ObjectUtil.isNotNull(waveNum)) { + result.setDataType(DataSourceEnum.WAVE_DATA.getValue()); + } List integerBooleanA = harmRangeComparison(devMap.get(TYPE_A).get(0), devMap.get(TYPE_A).get(1), errSysDtls, type, fData, scale, dataRule); List integerBooleanB = harmRangeComparison(devMap.get(TYPE_B).get(0), devMap.get(TYPE_A).get(1), errSysDtls, type, fData, scale, dataRule); diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java index 5a8756d6..56e73009 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java @@ -252,7 +252,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { checkDataParam.setIsValueTypeName(false); List adType = iPqScriptCheckDataService.getValueType(checkDataParam); - iPqDevService.updateResult(false, param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); + iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); CnSocketUtil.quitSend(param); } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java index 210c040f..9e8c3453 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/HeartbeatHandler.java @@ -193,9 +193,9 @@ public class HeartbeatHandler extends SimpleChannelInboundHandler { } else if (CnSocketUtil.SOURCE_TAG.equals(handlerType)) { CnSocketUtil.quitSendSource(param); } else { - if(FormalTestManager.currentStep==SourceOperateCodeEnum.RECORD_WAVE_STEP1 || FormalTestManager.currentStep==SourceOperateCodeEnum.RECORD_WAVE_STEP2){ + if (FormalTestManager.currentStep == SourceOperateCodeEnum.RECORD_WAVE_STEP1 || FormalTestManager.currentStep == SourceOperateCodeEnum.RECORD_WAVE_STEP2) { CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_03, true); - }else{ + } else { CnSocketUtil.contrastSendquit(param.getUserPageId(), SourceOperateCodeEnum.QUIT_INIT_02, true); } } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java index fed0818e..2c7a694d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/websocket/WebSocketHandler.java @@ -378,7 +378,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler { /** * 正式监测完成,修改中断状态 * - * @param isContrast * @param ids * @param adType * @param code @@ -117,7 +116,15 @@ public interface IPqDevService extends IService { * @param humidity * @return */ - boolean updateResult(boolean isContrast, List ids, List adType, String code, String userId, Float temperature, Float humidity); + boolean updateResult(List ids, List adType, String code, String userId, Float temperature, Float humidity); + + /** + * 比对式-修改设备状态 + * + * @param devId + * @param userId + */ + void updateResult(String devId,String userId); void updatePqDevReportState(String devId, int i); diff --git a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java index c0e0327b..11497c2e 100644 --- a/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/device/service/impl/PqDevServiceImpl.java @@ -434,11 +434,11 @@ public class PqDevServiceImpl extends ServiceImpl implements @Override - public boolean updateResult(boolean isContrast, List ids, List adType, String code, String userId, Float temperature, Float humidity) { + public boolean updateResult(List ids, List adType, String code, String userId, Float temperature, Float humidity) { if (CollUtil.isNotEmpty(ids)) { SysTestConfig config = sysTestConfigService.getOneConfig(); - Map result = detectionDataDealService.devResult(isContrast, ids, adType, code); + Map result = detectionDataDealService.devResult(false, ids, adType, code); List list = new ArrayList<>(); if (CollUtil.isNotEmpty(ids)) { list.addAll(this.baseMapper.listByDevIds(ids)); @@ -508,6 +508,39 @@ public class PqDevServiceImpl extends ServiceImpl implements return true; } + @Override + public void updateResult(String devId, String userId) { + PqDev dev = this.getById(devId); + Integer checkState = pqMonitorService.getDevCheckState(devId); + Integer checkResult = pqMonitorService.getDevCheckResult(devId); + + pqDevSubService.lambdaUpdate() + .set(PqDevSub::getCheckState, checkState) + .set(PqDevSub::getCheckResult, checkResult) + .eq(PqDevSub::getDevId, devId).update(); + + PqDevParam.QueryParam param = new PqDevParam.QueryParam(); + String planId = dev.getPlanId(); + param.setPlanIdList(Arrays.asList(planId)); + List pqDevVOList = this.baseMapper.selectByQueryParam(param); + + if (CollUtil.isNotEmpty(pqDevVOList)) { + Set set = pqDevVOList.stream().map(PqDevVO::getCheckResult).collect(Collectors.toSet()); + if (set.contains(CheckResultEnum.NOT_ACCORD.getValue())) { + this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.NOT_ACCORD.getValue()); + } else if (set.contains(CheckResultEnum.UNCHECKED.getValue())) { + this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.UNCHECKED.getValue()); + } else { + this.baseMapper.updatePlanCheckResult(planId, CheckResultEnum.ACCORD.getValue()); + } + + set = pqDevVOList.stream().map(PqDevVO::getCheckState).collect(Collectors.toSet()); + if (set.contains(CheckStateEnum.UNCHECKED.getValue())) { + this.baseMapper.updatePlanTestState(planId, CheckStateEnum.CHECKING.getValue()); + } + } + } + @Override public void updatePqDevReportState(String devId, int reportState) { LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); diff --git a/detection/src/main/java/com/njcn/gather/monitor/pojo/po/PqMonitor.java b/detection/src/main/java/com/njcn/gather/monitor/pojo/po/PqMonitor.java index e028d684..70d401a1 100644 --- a/detection/src/main/java/com/njcn/gather/monitor/pojo/po/PqMonitor.java +++ b/detection/src/main/java/com/njcn/gather/monitor/pojo/po/PqMonitor.java @@ -1,5 +1,7 @@ package com.njcn.gather.monitor.pojo.po; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @@ -66,16 +68,45 @@ public class PqMonitor implements Serializable { /** * 实时数据结果 0:不合格,1:合格,2:未检 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private Integer realtimeResult; /** * 统计数据结果 0:不合格,1:合格,2:未检 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private Integer statisticsResult; /** * 录波数据结果 0:不合格,1:合格,2:未检 */ + @TableField(updateStrategy = FieldStrategy.IGNORED) private Integer recordedResult; + + /** + * 实时数据使用哪一次的检测数据来表示结论 + */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String realtimeNum; + + /** + * 统计数据使用哪一次的检测数据来表示结论 + */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String statisticsNum; + + /** + * 录波数据使用哪一次、哪一组的检测数据来表示结论 例如 3_2,第三次检测第二组 + */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String recordedNum; + + /** + * 整个通道的结果使用那种数据。real、wave_data、statistics + */ + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String resultType; + + private Integer qualifiedNum; // 合格次数 } diff --git a/detection/src/main/java/com/njcn/gather/monitor/service/IPqMonitorService.java b/detection/src/main/java/com/njcn/gather/monitor/service/IPqMonitorService.java index f997dfb2..b7056340 100644 --- a/detection/src/main/java/com/njcn/gather/monitor/service/IPqMonitorService.java +++ b/detection/src/main/java/com/njcn/gather/monitor/service/IPqMonitorService.java @@ -3,8 +3,10 @@ package com.njcn.gather.monitor.service; import com.baomidou.mybatisplus.extension.service.IService; import com.njcn.gather.monitor.pojo.param.PqMonitorParam; import com.njcn.gather.monitor.pojo.po.PqMonitor; +import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import java.util.List; +import java.util.Map; /** * @author caozehui @@ -13,14 +15,13 @@ import java.util.List; public interface IPqMonitorService extends IService { - /** * 根据设备id获取所有监测点信息 * * @param devIds 被检设备id列表 * @return 监测点信息列表 */ - List listPqMonitorByDevIds(List devId); + List listPqMonitorByDevIds(List devIds); /** * 根据设备id批量新增监测点信息 @@ -72,6 +73,7 @@ public interface IPqMonitorService extends IService { /** * 根据被检设备id获取额定电流 + * * @param devMonitorId 被检设备监测点id * @return 额定电流 */ @@ -79,8 +81,34 @@ public interface IPqMonitorService extends IService { /** * 根据被检设备id获取额定电压 + * * @param devMonitorId 被检设备监测点id * @return 额定电压 */ Double getRatedVoltage(String devMonitorId); + + /** + * @param monitorId 监测点id + * @param adTypes 检测项指标id列表 + * @param dataSourceEnum 那种数据源 + * @param code 结果表后缀 + * @return + */ + boolean updateMonitorResult(String monitorId, List adTypes, DataSourceEnum dataSourceEnum, Integer num, Integer waveNum, String code); + + /** + * 查询设备的检测状态 + * + * @param devId + * @return + */ + Integer getDevCheckState(String devId); + + /** + * 查询设备的检测结果 + * + * @param devId + * @return + */ + Integer getDevCheckResult(String devId); } diff --git a/detection/src/main/java/com/njcn/gather/monitor/service/impl/PqMonitorServiceImpl.java b/detection/src/main/java/com/njcn/gather/monitor/service/impl/PqMonitorServiceImpl.java index 062877e4..552259a3 100644 --- a/detection/src/main/java/com/njcn/gather/monitor/service/impl/PqMonitorServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/monitor/service/impl/PqMonitorServiceImpl.java @@ -7,11 +7,17 @@ import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.gather.detection.util.socket.CnSocketUtil; +import com.njcn.gather.device.pojo.enums.CheckResultEnum; +import com.njcn.gather.device.pojo.enums.CheckStateEnum; import com.njcn.gather.monitor.mapper.PqMonitorMapper; import com.njcn.gather.monitor.pojo.param.PqMonitorParam; import com.njcn.gather.monitor.pojo.po.PqMonitor; import com.njcn.gather.monitor.service.IPqMonitorService; +import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import com.njcn.gather.pojo.enums.DetectionResponseEnum; +import com.njcn.gather.storage.service.DetectionDataDealService; +import com.njcn.gather.storage.service.impl.DetectionDataServiceImpl; import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.service.IDictDataService; import lombok.RequiredArgsConstructor; @@ -19,7 +25,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * @author caozehui @@ -31,6 +39,7 @@ import java.util.List; public class PqMonitorServiceImpl extends ServiceImpl implements IPqMonitorService { private final IDictDataService dictDataService; + private final DetectionDataDealService detectionDataDealService; @Override public List listPqMonitorByDevIds(List devIds) { @@ -121,4 +130,121 @@ public class PqMonitorServiceImpl extends ServiceImpl adTypes, DataSourceEnum dataSourceEnum, Integer num, Integer waveNum, String code) { + Integer newMonitorResult = detectionDataDealService.getMonitorResult(monitorId, adTypes, dataSourceEnum.getValue(), num, waveNum, code); + String[] split = monitorId.split(CnSocketUtil.SPLIT_TAG); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("pq_monitor.Dev_Id", split[0]) + .eq("pq_monitor.Num", split[1]) + .last("LIMIT 1"); + PqMonitor monitor = this.getOne(wrapper); + String resultType = monitor.getResultType(); + Integer qualifiedNum = monitor.getQualifiedNum(); + boolean updateFlag = false; + + if (StrUtil.isBlank(resultType)) { + updateFlag = true; + if (CheckResultEnum.ACCORD.getValue().equals(newMonitorResult)) { + qualifiedNum += 1; + } + } else { + Integer oldMonitorResult = null; + if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) { + oldMonitorResult = monitor.getRealtimeResult(); + } else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) { + oldMonitorResult = monitor.getRecordedResult(); + } else { + oldMonitorResult = monitor.getStatisticsResult(); + } + + if (CheckResultEnum.ACCORD.getValue().equals(oldMonitorResult)) { + if (CheckResultEnum.ACCORD.getValue().equals(newMonitorResult)) { + qualifiedNum += 1; + updateFlag = true; + } + } else { + updateFlag = true; + if (CheckResultEnum.ACCORD.getValue().equals(newMonitorResult)) { + qualifiedNum += 1; + } + } + } + + if (updateFlag) { + monitor.setResultType(dataSourceEnum.getValue()); + + if (DataSourceEnum.REAL_DATA.getValue().equals(dataSourceEnum.getValue())) { + monitor.setRealtimeResult(newMonitorResult); + monitor.setRealtimeNum(String.valueOf(num)); + } else if (DataSourceEnum.WAVE_DATA.getValue().equals(dataSourceEnum.getValue())) { + monitor.setRecordedResult(newMonitorResult); + monitor.setRecordedNum(num + CnSocketUtil.SPLIT_TAG + waveNum); + } else { + monitor.setStatisticsResult(newMonitorResult); + monitor.setStatisticsNum(String.valueOf(num)); + } + + if (StrUtil.isNotBlank(resultType) && !resultType.equals(dataSourceEnum.getValue())) { + if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) { + monitor.setRealtimeResult(null); + monitor.setRealtimeNum(null); + } else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) { + monitor.setRecordedResult(null); + monitor.setRecordedNum(null); + } else { + monitor.setStatisticsResult(null); + monitor.setStatisticsNum(null); + } + } + monitor.setQualifiedNum(qualifiedNum); + } + + return this.updateById(monitor); + } + + + @Override + public Integer getDevCheckState(String devId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("pq_monitor.Dev_Id", devId); + List monitorList = this.list(wrapper); + if (CollUtil.isNotEmpty(monitorList)) { + List allNumList = monitorList.stream().map(PqMonitor::getNum).collect(Collectors.toList()); + List checkedNumList = monitorList.stream().filter(obj -> ObjectUtil.isNotNull(obj.getResultType())).map(PqMonitor::getNum).collect(Collectors.toList()); + + if (checkedNumList.containsAll(allNumList)) { + return CheckStateEnum.CHECKED.getValue(); + } else { + if (checkedNumList.size() > 0) { + return CheckStateEnum.CHECKING.getValue(); + } + } + } + return CheckStateEnum.UNCHECKED.getValue(); + } + + @Override + public Integer getDevCheckResult(String devId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("pq_monitor.Dev_Id", devId); + List monitorList = this.list(wrapper); + + List allResultFlags = new ArrayList<>(); + for (PqMonitor monitor : monitorList) { + String resultType = monitor.getResultType(); + if (StrUtil.isNotBlank(resultType)) { + if (DataSourceEnum.REAL_DATA.getValue().equals(resultType)) { + allResultFlags.add(monitor.getRealtimeResult()); + } else if (DataSourceEnum.WAVE_DATA.getValue().equals(resultType)) { + allResultFlags.add(monitor.getRecordedResult()); + } else { + allResultFlags.add(monitor.getStatisticsResult()); + } + } + } + + return DetectionDataServiceImpl.isResultFlag(allResultFlags); + } } diff --git a/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java b/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java index e7e14714..ea2e1dcf 100644 --- a/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java +++ b/detection/src/main/java/com/njcn/gather/result/controller/ResultController.java @@ -7,13 +7,10 @@ import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.LogUtil; -import com.njcn.gather.result.pojo.vo.ContrastResultVO; import com.njcn.gather.detection.service.IAdPariService; import com.njcn.gather.detection.util.socket.CnSocketUtil; import com.njcn.gather.result.pojo.param.ResultParam; -import com.njcn.gather.result.pojo.vo.FormContentVO; -import com.njcn.gather.result.pojo.vo.ResultVO; -import com.njcn.gather.result.pojo.vo.TreeDataVO; +import com.njcn.gather.result.pojo.vo.*; import com.njcn.gather.result.service.IResultService; import com.njcn.web.controller.BaseController; import com.njcn.web.utils.HttpResultUtil; @@ -26,6 +23,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; /** * @author caozehui @@ -151,4 +149,29 @@ public class ResultController extends BaseController { ContrastResultVO result = resultService.getContrastResult(queryParam); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/getMonitorResult") + @ApiOperation("获取监测点的检测结果") + @ApiImplicitParam(name = "param", value = "查询参数", required = true) + public HttpResult getMonitorResult(@RequestParam("devId") String devId) { + String methodDescribe = getMethodDescribe("getMonitorResult"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, devId); + + MonitorResultVO result = resultService.getMonitorResult(devId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @GetMapping("/getMonitorDataSourceResult") + @ApiOperation("获取监测点的检测结果下拉框") + @ApiImplicitParam(name = "param", value = "查询参数", required = true) + public HttpResult> getMonitorDataSourceResult(@RequestParam("monitorId") String monitorId) { + String methodDescribe = getMethodDescribe("getMonitorDataSourceResult"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, monitorId); + + Map result = resultService.getMonitorDataSourceResult(monitorId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } } diff --git a/detection/src/main/java/com/njcn/gather/result/pojo/vo/DataSourceResultVO.java b/detection/src/main/java/com/njcn/gather/result/pojo/vo/DataSourceResultVO.java new file mode 100644 index 00000000..02a3b7c8 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/result/pojo/vo/DataSourceResultVO.java @@ -0,0 +1,26 @@ +package com.njcn.gather.result.pojo.vo; + +import lombok.Data; + +/** + * @author caozehui + * @data 2025-09-12 + */ +@Data +public class DataSourceResultVO { + + /** + * 通道所使用的数据源名称 + */ + private String dataSourceName; + + /** + * 通道所使用的数据源code + */ + private String dataSourceCode; + + /** + * 通道检测结果 + */ + private Integer checkResult; +} diff --git a/detection/src/main/java/com/njcn/gather/result/pojo/vo/MonitorResultVO.java b/detection/src/main/java/com/njcn/gather/result/pojo/vo/MonitorResultVO.java new file mode 100644 index 00000000..ece85455 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/result/pojo/vo/MonitorResultVO.java @@ -0,0 +1,51 @@ +package com.njcn.gather.result.pojo.vo; + +import lombok.Data; + +/** + * @author caozehui + * @data 2025-09-10 + */ +@Data +public class MonitorResultVO { + + /** + * 监测点id + */ + private Integer monitorId; + + /** + * 监测点序号 + */ + private Integer monitorNum; + + /** + * 总检测次数 + */ + private Integer totalNum; + + /** + * 合格检测次数 + */ + private Integer qualifiedNum; + + /** + * 不合格检测次数 + */ + private Integer unQualifiedNum; + + /** + * 误差体系名称 + */ + private String errorSysName; + + /** + * 检测结果 + */ + private Integer checkResult; + + /** + * 结论来源 + */ + private String resultOrigin; +} diff --git a/detection/src/main/java/com/njcn/gather/result/service/IResultService.java b/detection/src/main/java/com/njcn/gather/result/service/IResultService.java index 96a68dc0..d8761cba 100644 --- a/detection/src/main/java/com/njcn/gather/result/service/IResultService.java +++ b/detection/src/main/java/com/njcn/gather/result/service/IResultService.java @@ -2,10 +2,7 @@ package com.njcn.gather.result.service; import com.njcn.gather.report.pojo.result.SingleTestResult; import com.njcn.gather.result.pojo.param.ResultParam; -import com.njcn.gather.result.pojo.vo.ContrastResultVO; -import com.njcn.gather.result.pojo.vo.FormContentVO; -import com.njcn.gather.result.pojo.vo.ResultVO; -import com.njcn.gather.result.pojo.vo.TreeDataVO; +import com.njcn.gather.result.pojo.vo.*; import com.njcn.gather.script.pojo.vo.PqScriptDtlDataVO; import java.util.List; @@ -116,4 +113,8 @@ public interface IResultService { */ ContrastResultVO getContrastResult(ResultParam.QueryParam queryParam); + + MonitorResultVO getMonitorResult(String devId); + + Map getMonitorDataSourceResult(String monitorId); } diff --git a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java index e26ef8c6..7b8c8469 100644 --- a/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/result/service/impl/ResultServiceImpl.java @@ -1636,6 +1636,18 @@ public class ResultServiceImpl implements IResultService { return contrastResultVO; } + + @Override + public MonitorResultVO getMonitorResult(String devId) { + + return null; + } + + @Override + public Map getMonitorDataSourceResult(String monitorId) { + return null; + } + private Map> getResultMap(DictTree dictTree, List adTypeList, String monitorId, String unit, Integer num, Integer waveNum, Boolean isWave, String code) { Map> resultMap = new LinkedHashMap<>(); @@ -1999,7 +2011,7 @@ public class ResultServiceImpl implements IResultService { checkDataParam.setIsValueTypeName(false); List valueType = iPqScriptCheckDataService.getValueType(checkDataParam); - iPqDevService.updateResult(false, param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); + iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity()); } /** diff --git a/storage/src/main/java/com/njcn/gather/storage/service/DetectionDataDealService.java b/storage/src/main/java/com/njcn/gather/storage/service/DetectionDataDealService.java index 44b85a5d..dce89ce5 100644 --- a/storage/src/main/java/com/njcn/gather/storage/service/DetectionDataDealService.java +++ b/storage/src/main/java/com/njcn/gather/storage/service/DetectionDataDealService.java @@ -2,9 +2,7 @@ package com.njcn.gather.storage.service; import com.njcn.db.mybatisplus.service.IReplenishMybatisService; import com.njcn.gather.storage.pojo.po.BaseResult; -import com.njcn.gather.storage.pojo.po.ContrastNonHarmonicResult; import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult; -import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult; import java.util.List; import java.util.Map; @@ -12,14 +10,13 @@ import java.util.Map; public interface DetectionDataDealService extends IReplenishMybatisService { + Boolean acceptNonHarmonic(List nonHarmonicResultList, String code); - Boolean acceptNonHarmonic(List nonHarmonicResultList,String code); - - Boolean acceptHarmonic(List harmonicResultList,String code); + Boolean acceptHarmonic(List harmonicResultList, String code); Boolean acceptNonHarmonicResult(List nonHarmonicResultList, String code); - Boolean acceptHarmonicResult(List SimAndDigHarmonicResultList,String code); + Boolean acceptHarmonicResult(List SimAndDigHarmonicResultList, String code); /** * 根据终端id查询终端所有监测项目是否合格 @@ -30,5 +27,18 @@ public interface DetectionDataDealService extends IReplenishMybatisService devResult(boolean isContrast,List ids,List adType,String code); + Map devResult(boolean isContrast, List ids, List adType, String code); + + /** + * 获取检测点的检测结果 + * + * @param monitorId + * @param adTypes + * @param dataSource + * @param num + * @param waveNum + * @param code + * @return + */ + Integer getMonitorResult(String monitorId, List adTypes, String dataSource, Integer num, Integer waveNum, String code); } diff --git a/storage/src/main/java/com/njcn/gather/storage/service/impl/DetectionDataServiceImpl.java b/storage/src/main/java/com/njcn/gather/storage/service/impl/DetectionDataServiceImpl.java index 743824ab..c920496a 100644 --- a/storage/src/main/java/com/njcn/gather/storage/service/impl/DetectionDataServiceImpl.java +++ b/storage/src/main/java/com/njcn/gather/storage/service/impl/DetectionDataServiceImpl.java @@ -2,6 +2,7 @@ package com.njcn.gather.storage.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.db.mybatisplus.handler.DynamicTableNameHandler; import com.njcn.db.mybatisplus.service.impl.ReplenishMybatisServiceImpl; @@ -206,19 +207,50 @@ public class DetectionDataServiceImpl extends ReplenishMybatisServiceImpl> harmMap = harm.stream().collect(Collectors.groupingBy(x -> x.getDevMonitorId().split("_")[0], Collectors.mapping(BaseResult::getResultFlag, Collectors.toList()))); for (String id : ids) { + String s = id.split("_")[0]; List resultFlags = new ArrayList<>(); - if (noHarmMap.containsKey(id)) { - resultFlags.addAll(noHarmMap.get(id)); + if (noHarmMap.containsKey(s)) { + resultFlags.addAll(noHarmMap.get(s)); } - if (harmMap.containsKey(id)) { - resultFlags.addAll(harmMap.get(id)); + if (harmMap.containsKey(s)) { + resultFlags.addAll(harmMap.get(s)); } map.put(id, isResultFlag(resultFlags)); } return map; } - private static Integer isResultFlag(List resultFlags) { + @Override + public Integer getMonitorResult(String monitorId, List adTypes, String dataSource, Integer num, Integer waveNum, String code) { + DynamicTableNameHandler.setTableName("ad_non_harmonic_result_" + code); + LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper() + .like(ContrastNonHarmonicResult::getDevMonitorId, monitorId) + .in(CollUtil.isNotEmpty(adTypes), ContrastNonHarmonicResult::getAdType, adTypes) + .eq(ContrastNonHarmonicResult::getDataType, dataSource) + .eq(ContrastNonHarmonicResult::getNum, num) + .eq(ObjectUtil.isNotEmpty(waveNum), ContrastNonHarmonicResult::getWaveNum, waveNum); + + List nonHarmonicResultList = contrastNonHarmonicService.list(wrapper1); + DynamicTableNameHandler.remove(); + + DynamicTableNameHandler.setTableName("ad_harmonic_result_" + code); + LambdaQueryWrapper wrapper2 = new LambdaQueryWrapper() + .like(ContrastHarmonicResult::getDevMonitorId, monitorId) + .in(CollUtil.isNotEmpty(adTypes), ContrastHarmonicResult::getAdType, adTypes) + .eq(ContrastHarmonicResult::getDataType, dataSource) + .eq(ContrastHarmonicResult::getNum, num) + .eq(ObjectUtil.isNotEmpty(waveNum), ContrastHarmonicResult::getWaveNum, waveNum); + + List harmonicResultList = contrastHarmonicService.list(wrapper2); + DynamicTableNameHandler.remove(); + + List resultFlagList = nonHarmonicResultList.stream().map(ContrastNonHarmonicResult::getResultFlag).collect(Collectors.toList()); + resultFlagList.addAll(harmonicResultList.stream().map(ContrastHarmonicResult::getResultFlag).collect(Collectors.toList())); + + return isResultFlag(resultFlagList); + } + + public static Integer isResultFlag(List resultFlags) { // 检测结果(0:不符合 1:符合 2:/[未检测无结果]) //脚本结果是 1.符合 2.不符合 4.未检测无结果 5.不参与误差比较 resultFlags = resultFlags.stream().filter(x -> 4 != x && 5 != x).distinct().collect(Collectors.toList());