From dd4cf1eedea98923cc8b0e4e580238df9aa801ac Mon Sep 17 00:00:00 2001 From: chendaofei <857448963@qq.com> Date: Tue, 14 Jan 2025 16:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/SocketDevResponseService.java | 60 +++++++++++--- .../detection/pojo/dto/DevXiNumData.java | 3 + .../detection/pojo/vo/CoefficientVO.java | 7 ++ .../service/impl/PreDetectionServiceImpl.java | 16 +++- .../socket/cilent/NettyDevClientHandler.java | 82 +++++++++---------- 5 files changed, 112 insertions(+), 56 deletions(-) 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 f98f3126..1a39f596 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 @@ -5,6 +5,7 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.njcn.gather.detection.pojo.dto.DevXiNumData; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; @@ -15,6 +16,7 @@ import com.njcn.gather.detection.pojo.vo.*; import com.njcn.gather.detection.service.impl.DetectionServiceImpl; import com.njcn.gather.detection.util.socket.*; import com.njcn.gather.detection.util.socket.web.WebSocketHandler; +import com.njcn.gather.device.device.pojo.po.PqDev; import com.njcn.gather.device.device.pojo.vo.PreDetection; import com.njcn.gather.device.device.service.IPqDevService; import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam; @@ -46,6 +48,7 @@ import java.time.format.DateTimeParseException; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -250,6 +253,8 @@ public class SocketDevResponseService { //获取数据流程结束,先把所有数据存到内存中 Map> realDataXiMap = realDataXiList.stream().collect(Collectors.groupingBy(it -> it.getId().split(splitTag)[0])); realDataXiMap.forEach((devIp, dataList) -> { + AtomicBoolean xiFlag = new AtomicBoolean(true); + XiNumberManager.devXiList.add(devIp); Map> monitorMap = dataList.stream().collect(Collectors.groupingBy(DevData::getId)); @@ -274,6 +279,9 @@ public class SocketDevResponseService { coefficientVO.setDesc((XiNumberManager.stepNumber == 0 || XiNumberManager.stepNumber == 1) ? "系数下装" : "系数校准"); assemblyEntity(list, F, coefficientVO, devParameter); + if(Objects.nonNull(coefficientVO.getResultFlag()) && coefficientVO.getResultFlag() == 0){ + xiFlag.set(false); + } DevXiNumData.GF gfItem = new DevXiNumData.GF(); gfItem.setUMonitorPoint(Integer.parseInt(splitStr[1]) - 1); @@ -291,10 +299,15 @@ public class SocketDevResponseService { devXiNumData.setChnNum(0); devXiNumData.setDevIP(devIp); devXiNumData.setGf(gf); + if(xiFlag.get()){ + devXiNumData.setResultFlag(1); + }else { + devXiNumData.setResultFlag(0); + } - if (XiNumberManager.stepNumber == 0) { + if (XiNumberManager.stepNumber == 0||XiNumberManager.stepNumber == 2) { XiNumberManager.devXiNumDataMap.put(devIp, devXiNumData); - } else if (XiNumberManager.stepNumber == 1) { + } else if (XiNumberManager.stepNumber == 1||XiNumberManager.stepNumber == 3) { XiNumberManager.smallDevXiNumDataMap.put(devIp, devXiNumData); } }); @@ -330,8 +343,6 @@ public class SocketDevResponseService { } else { - - System.out.println(devIp); flag = false; //继续下发一轮 if (!ia) { @@ -399,6 +410,19 @@ public class SocketDevResponseService { sendWebSocket(param.getUserPageId(), SourceOperateCodeEnum.Coefficient_Check.getValue(), SourceOperateCodeEnum.small_comp_end.getValue(), XiNumberManager.devParameterList.get(1)); System.out.println("-------------------------已经全部结束----------------------"); CnSocketUtil.quitSend(param); + //修改设备表Factor_Check_Result字段 + XiNumberManager.devXiNumDataMap.forEach((key,val)->{ + DevXiNumData small = XiNumberManager.smallDevXiNumDataMap.get(key); + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(PqDev::getId,FormalTestManager.devIdMapComm.get(key)); + if(val.getResultFlag() == 0 || small.getResultFlag() == 0){ + updateWrapper.set(PqDev::getFactorCheckResult,0); + }else { + updateWrapper.set(PqDev::getFactorCheckResult,1); + } + iPqDevService.update(updateWrapper); + updateWrapper.clear(); + }); } } @@ -441,6 +465,7 @@ public class SocketDevResponseService { } + private void assemblyEntity(List deList, DevXiNumData.F F, CoefficientVO coefficientVO, CoefficientVO.DevParameter devParameter) { //表示接收完成,必须保证10个数 if (deList.size() >= 10) { @@ -498,6 +523,11 @@ public class SocketDevResponseService { coefficientVO.setAIeXi(isWithinTenPercent(optionalIA, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格"); coefficientVO.setBIeXi(isWithinTenPercent(optionalIB, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格"); coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格"); + if("不合格".equals(coefficientVO.getAVuXi()) ||"不合格".equals(coefficientVO.getBVuXi()) ||"不合格".equals(coefficientVO.getCVuXi()) ||"不合格".equals(coefficientVO.getAIeXi()) ||"不合格".equals(coefficientVO.getBIeXi()) ||"不合格".equals(coefficientVO.getCIeXi())){ + coefficientVO.setResultFlag(0); + }else { + coefficientVO.setResultFlag(1); + } } } } @@ -523,18 +553,23 @@ public class SocketDevResponseService { case SUCCESS: String result = socketDataMsg.getData(); //通讯校验成功 - webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, FormalTestManager.devNameMapComm, 1)); + + if(!param.getOperateType().equals(SourceOperateCodeEnum.TEST_TEM_START.getValue())) { + webSocketHandler.sendMsgToUser(param.getUserPageId(), MsgUtil.msgToWebData(socketDataMsg, FormalTestManager.devNameMapComm, 1)); + } successDevComm.add(result.split(splitTag)[0]); successComm.add(result); - System.out.println("设备通讯校验全部成功!" + successComm.size() + "=====" + FormalTestManager.monitorIdListComm.size()); + System.out.println("设备通讯校验!" + successComm.size() + "=====" + FormalTestManager.monitorIdListComm.size()); if (successComm.size() == FormalTestManager.monitorIdListComm.size()) { - SocketDataMsg temMsg = new SocketDataMsg(); - temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode()); - temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); - temMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); - webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(temMsg)); + if(!param.getOperateType().equals(SourceOperateCodeEnum.TEST_TEM_START.getValue())) { + SocketDataMsg temMsg = new SocketDataMsg(); + temMsg.setCode(SourceResponseCodeEnum.DEV_COMM_ALL_SUCCESS.getCode()); + temMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); + temMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); + webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(temMsg)); + } //开始进行协议校验 successComm.clear(); @@ -932,10 +967,11 @@ public class SocketDevResponseService { SocketManager.delSource(sourceIssue.getIndex()); //在这一步判断是否已经触发暂停按钮 if (FormalTestManager.stopFlag) { - CnSocketUtil.quitSend(param); + // CnSocketUtil.quitSend(param); successComm.clear(); realDataXiList.clear(); sendWebSocket(param.getUserPageId(), "preStopTest", "stop", null); + return; } //开始进行下一项检测 diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/dto/DevXiNumData.java b/detection/src/main/java/com/njcn/gather/detection/pojo/dto/DevXiNumData.java index 10d082cc..12e29a00 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/dto/DevXiNumData.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/dto/DevXiNumData.java @@ -19,6 +19,9 @@ public class DevXiNumData { private List gf; + private Integer resultFlag; + + @Data public static class GF{ diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/CoefficientVO.java b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/CoefficientVO.java index 190ef7a2..5db4bb7b 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/CoefficientVO.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/CoefficientVO.java @@ -64,6 +64,13 @@ public class CoefficientVO { + /** + * 标识校验不合格的为 0 合格项为 1 + */ + private Integer resultFlag; + + + @Data public static class DevParameter{ 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 75a16468..a17830af 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 @@ -181,7 +181,7 @@ public class PreDetectionServiceImpl implements PreDetectionService { @Override public boolean restartTemTest(PreDetectionParam param) { FormalTestManager.stopFlag = false; - specialDeal(param); + /* specialDeal(param); AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper().eq(AdPlanSource::getPlanId, param.getPlanId())); if (ObjectUtil.isNotNull(planSource)) { SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId()); @@ -203,7 +203,21 @@ public class PreDetectionServiceImpl implements PreDetectionService { } } else { throw new BusinessException(DetectionResponseEnum.PLAN_AND_SOURCE_NOT); + }*/ + List sourceIssueList = SocketManager.getSourceList(); + if (CollUtil.isNotEmpty(sourceIssueList)) { + SourceIssue sourceIssues = SocketManager.getSourceList().get(0); + SocketMsg xuMsg = new SocketMsg<>(); + xuMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); + xuMsg.setData(JSON.toJSONString(sourceIssues)); + xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType()); + SocketManager.sendMsg(param.getUserPageId() + source, JSON.toJSONString(xuMsg)); + } else { + //TODO 是否最终检测完成需要推送给用户 + iPqDevService.updateResult(param.getDevIds(), param.getCode()); + CnSocketUtil.quitSend(param); } + return true; } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java index 390c7375..863a921d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java @@ -87,14 +87,6 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler { @Override public void channelInactive(ChannelHandlerContext ctx) { System.out.println("设备通讯客户端断线"); - Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + dev); - if (Objects.nonNull(channel)) { - try { - channel.close().sync(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } SocketManager.removeUser(param.getUserPageId() + dev); } @@ -108,44 +100,46 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (evt instanceof IdleStateEvent) { if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) { - if (CollUtil.isNotEmpty(SocketManager.getSourceList())) { - SourceIssue sourceIssue = SocketManager.getSourceList().get(0); - if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) { - SocketManager.clockMap.put(sourceIssue.getIndex(), SocketManager.clockMap.get(sourceIssue.getIndex()) + 60L); + if(!FormalTestManager.stopFlag) { + if (CollUtil.isNotEmpty(SocketManager.getSourceList())) { + SourceIssue sourceIssue = SocketManager.getSourceList().get(0); + if (SocketManager.clockMap.containsKey(sourceIssue.getIndex())) { + SocketManager.clockMap.put(sourceIssue.getIndex(), SocketManager.clockMap.get(sourceIssue.getIndex()) + 60L); + } else { + SocketManager.clockMap.put(sourceIssue.getIndex(), 60L); + } + + System.out.println("超时函数进入-----》" + sourceIssue.getType() + "----:" + SocketManager.clockMap.get(sourceIssue.getIndex()) + "S"); + + if (sourceIssue.getType().equals(DicDataEnum.F.getCode())) { + //闪变,正常抛一轮最大等待20分钟超时 + if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 1300) { + System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭"); + CnSocketUtil.quitSend(param); + timeoutSend(sourceIssue); + } + } else if (sourceIssue.getType().equals(DicDataEnum.VOLTAGE.getCode()) || sourceIssue.getType().equals(DicDataEnum.HP.getCode())) { + //统计数据项,正常抛一轮数据,超时 + if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 180) { + CnSocketUtil.quitSend(param); + System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭"); + timeoutSend(sourceIssue); + } + + } else { + //实时数据 + if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 60) { + CnSocketUtil.quitSend(param); + System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭"); + timeoutSend(sourceIssue); + } + } } else { - SocketManager.clockMap.put(sourceIssue.getIndex(), 60L); + //为空则认为是常规步骤,设定一分钟超时 + CnSocketUtil.quitSend(param); } - - System.out.println("超时函数进入-----》" + sourceIssue.getType() + "----:" + SocketManager.clockMap.get(sourceIssue.getIndex()) + "S"); - - if (sourceIssue.getType().equals(DicDataEnum.F.getCode())) { - //闪变,正常抛一轮最大等待20分钟超时 - if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 1300) { - System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭"); - CnSocketUtil.quitSend(param); - timeoutSend(sourceIssue); - } - } else if (sourceIssue.getType().equals(DicDataEnum.VOLTAGE.getCode()) || sourceIssue.getType().equals(DicDataEnum.HP.getCode())) { - //统计数据项,正常抛一轮数据,超时 - if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 180) { - CnSocketUtil.quitSend(param); - System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭"); - timeoutSend(sourceIssue); - } - - } else { - //实时数据 - if (SocketManager.clockMap.get(sourceIssue.getIndex()) > 60) { - CnSocketUtil.quitSend(param); - System.out.println("超时处理-----》" + sourceIssue.getType() + "已超时----------------关闭"); - timeoutSend(sourceIssue); - } - } - } else { - //为空则认为是常规步骤,设定一分钟超时 - CnSocketUtil.quitSend(param); + System.out.println("已经等了一分钟了。。。。。。。。。。。。"); } - System.out.println("已经等了一分钟了。。。。。。。。。。。。"); } } @@ -188,6 +182,8 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler { // 可以记录未知异常信息 } ctx.close(); + + }