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 a2da2567..9bdc2074 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 @@ -439,6 +439,7 @@ public class SocketDevResponseService { //告诉前端当前项开始了 WebSocketVO webSocketVO = new WebSocketVO<>(); + FormalTestManager.currentIssue = sourceIssues.get(0); String type = sourceIssues.get(0).getType(); if (ResultUnitEnum.P.getCode().equals(type)) { sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode()); @@ -953,6 +954,7 @@ public class SocketDevResponseService { } else { webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG); } + FormalTestManager.currentIssue = sourceIssues.get(0); socketMsg.setData(JSON.toJSONString(sourceIssues.get(0))); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); @@ -1210,6 +1212,7 @@ public class SocketDevResponseService { } else { webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG); } + FormalTestManager.currentIssue = sourceIssues.get(0); socketMsg.setData(JSON.toJSONString(sourceIssues.get(0))); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); @@ -1782,6 +1785,7 @@ public class SocketDevResponseService { } else { dataRule = DictDataEnum.SECTION_VALUE; } + FormalTestManager.currentTestPlan = plan; String code = dictDataService.getDictDataById(plan.getPattern()).getCode(); FormalTestManager.patternEnum = PatternEnum.getEnum(code); diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java index c46e3b49..15eb0853 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java @@ -2,6 +2,7 @@ package com.njcn.gather.detection.handler; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam; @@ -14,7 +15,12 @@ import com.njcn.gather.detection.util.socket.*; import com.njcn.gather.detection.util.socket.websocket.WebServiceManager; import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.service.IPqDevService; +import com.njcn.gather.plan.pojo.po.AdPlanSource; +import com.njcn.gather.plan.service.IAdPlanSourceService; +import com.njcn.gather.result.pojo.enums.ResultUnitEnum; import com.njcn.gather.script.pojo.po.SourceIssue; +import com.njcn.gather.source.pojo.po.SourceInitialize; +import com.njcn.gather.source.service.IPqSourceService; import com.njcn.gather.system.pojo.enums.DicDataEnum; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -56,6 +62,8 @@ public class SocketSourceResponseService { * 设备信息服务,提供设备基础信息查询功能 */ private final IPqDevService iPqDevService; + private final IAdPlanSourceService adPlanSourceService; + private final IPqSourceService pqSourceService; /** * Socket连接管理器,负责管理设备和源的Socket连接 @@ -363,18 +371,32 @@ public class SocketSourceResponseService { SocketMsg socketMsg = new SocketMsg<>(); switch (dictDataEnumByCode) { case SUCCESS: - //todo 前端推送收到的消息暂未处理好 - sendWebSocketMessage(param.getUserPageId(), socketDataMsg); - //开始设备通讯检测(发送设备初始化) - Map> map = new HashMap<>(1); - map.put("deviceList", FormalTestManager.devList); - String jsonString = JSON.toJSONString(map); - socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); - socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); - socketMsg.setData(jsonString); - String json = JSON.toJSONString(socketMsg); - // 使用智能发送工具类,自动管理设备连接 - socketManager.smartSendToDevice(param, json); + if (FormalTestManager.unknownError) { + FormalTestManager.unknownError = false; + + //重新下发脚本 + String type = FormalTestManager.currentIssue.getType(); + if (ResultUnitEnum.P.getCode().equals(type)) { + FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode()); + } + socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); + socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue)); + socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); + SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg)); + } else { + //todo 前端推送收到的消息暂未处理好 + sendWebSocketMessage(param.getUserPageId(), socketDataMsg); + //开始设备通讯检测(发送设备初始化) + Map> map = new HashMap<>(1); + map.put("deviceList", FormalTestManager.devList); + String jsonString = JSON.toJSONString(map); + socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); + socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); + socketMsg.setData(jsonString); + String json = JSON.toJSONString(socketMsg); + // 使用智能发送工具类,自动管理设备连接 + socketManager.smartSendToDevice(param, json); + } break; case UNPROCESSED_BUSINESS: sendWebSocketMessage(param.getUserPageId(), socketDataMsg); @@ -570,6 +592,10 @@ public class SocketSourceResponseService { case UNPROCESSED_BUSINESS: sendWebSocketMessage(param.getUserPageId(), socketDataMsg); break; + case UNKNOWN_ERROR: //-1源未知异常 + CnSocketUtil.quitSendSource(param); + FormalTestManager.unknownError = true; + break; default: sendErrorAndQuit(param, socketDataMsg, dictDataEnumByCode); break; @@ -601,9 +627,23 @@ public class SocketSourceResponseService { SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); switch (Objects.requireNonNull(dictDataEnumByCode)) { case SUCCESS: - //通讯校验成功 - SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG); - sendWebSocketMessage(param.getUserPageId(), socketDataMsg); + if (FormalTestManager.unknownError) { + //获取源初始化参数 + AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper().eq(AdPlanSource::getPlanId, param.getPlanId())); + SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId()); + if (ObjectUtil.isNotNull(sourceParam)) { + SocketMsg socketMsg1 = new SocketMsg<>(); + socketMsg1.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); + socketMsg1.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue()); + socketMsg1.setData(JSON.toJSONString(sourceParam)); + //使用智能发送工具类,自动管理与源控程序的socket连接 + socketManager.smartSendToSource(param, JSON.toJSONString(socketMsg1)); + } + } else { + //通讯校验成功 + SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG); + sendWebSocketMessage(param.getUserPageId(), socketDataMsg); + } break; case UNPROCESSED_BUSINESS: break; @@ -653,6 +693,8 @@ public class SocketSourceResponseService { // 同步更新系数管理器中的设备列表 XiNumberManager.xiDevList = devList; + FormalTestManager.unknownError = false; + FormalTestManager.currentIssue = null; } } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java index 6d87f2e2..21d09e6f 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/FormalTestManager.java @@ -10,6 +10,7 @@ import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.plan.pojo.enums.DataSourceEnum; import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlanTestConfig; +import com.njcn.gather.script.pojo.po.SourceIssue; import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum; import java.util.ArrayList; @@ -195,4 +196,11 @@ public class FormalTestManager { public static boolean statisticsProtocol; public static boolean voltageProtocol; + + public static boolean unknownError; + + /** + * 当前下发的脚本 + */ + public static SourceIssue currentIssue; }