处理源未知异常

This commit is contained in:
caozehui
2025-11-10 14:45:23 +08:00
parent f10debe2f2
commit 6b7e38fef6
3 changed files with 69 additions and 15 deletions

View File

@@ -439,6 +439,7 @@ public class SocketDevResponseService {
//告诉前端当前项开始了 //告诉前端当前项开始了
WebSocketVO<Object> webSocketVO = new WebSocketVO<>(); WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
FormalTestManager.currentIssue = sourceIssues.get(0);
String type = sourceIssues.get(0).getType(); String type = sourceIssues.get(0).getType();
if (ResultUnitEnum.P.getCode().equals(type)) { if (ResultUnitEnum.P.getCode().equals(type)) {
sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode()); sourceIssues.get(0).setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
@@ -953,6 +954,7 @@ public class SocketDevResponseService {
} else { } else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG); webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
} }
FormalTestManager.currentIssue = sourceIssues.get(0);
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0))); socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
@@ -1210,6 +1212,7 @@ public class SocketDevResponseService {
} else { } else {
webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG); webSocketVO.setRequestId(sourceIssues.get(0).getType() + CnSocketUtil.START_TAG);
} }
FormalTestManager.currentIssue = sourceIssues.get(0);
socketMsg.setData(JSON.toJSONString(sourceIssues.get(0))); socketMsg.setData(JSON.toJSONString(sourceIssues.get(0)));
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type); socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
@@ -1782,6 +1785,7 @@ public class SocketDevResponseService {
} else { } else {
dataRule = DictDataEnum.SECTION_VALUE; dataRule = DictDataEnum.SECTION_VALUE;
} }
FormalTestManager.currentTestPlan = plan;
String code = dictDataService.getDictDataById(plan.getPattern()).getCode(); String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
FormalTestManager.patternEnum = PatternEnum.getEnum(code); FormalTestManager.patternEnum = PatternEnum.getEnum(code);

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.detection.handler;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON; 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.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam; 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.detection.util.socket.websocket.WebServiceManager;
import com.njcn.gather.device.pojo.vo.PreDetection; import com.njcn.gather.device.pojo.vo.PreDetection;
import com.njcn.gather.device.service.IPqDevService; 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.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 com.njcn.gather.system.pojo.enums.DicDataEnum;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -56,6 +62,8 @@ public class SocketSourceResponseService {
* 设备信息服务,提供设备基础信息查询功能 * 设备信息服务,提供设备基础信息查询功能
*/ */
private final IPqDevService iPqDevService; private final IPqDevService iPqDevService;
private final IAdPlanSourceService adPlanSourceService;
private final IPqSourceService pqSourceService;
/** /**
* Socket连接管理器负责管理设备和源的Socket连接 * Socket连接管理器负责管理设备和源的Socket连接
@@ -363,18 +371,32 @@ public class SocketSourceResponseService {
SocketMsg<String> socketMsg = new SocketMsg<>(); SocketMsg<String> socketMsg = new SocketMsg<>();
switch (dictDataEnumByCode) { switch (dictDataEnumByCode) {
case SUCCESS: case SUCCESS:
//todo 前端推送收到的消息暂未处理好 if (FormalTestManager.unknownError) {
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); FormalTestManager.unknownError = false;
//开始设备通讯检测(发送设备初始化)
Map<String, List<PreDetection>> map = new HashMap<>(1); //重新下发脚本
map.put("deviceList", FormalTestManager.devList); String type = FormalTestManager.currentIssue.getType();
String jsonString = JSON.toJSONString(map); if (ResultUnitEnum.P.getCode().equals(type)) {
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue()); FormalTestManager.currentIssue.setType(ResultUnitEnum.V_ABSOLUTELY.getCode());
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue()); }
socketMsg.setData(jsonString); socketMsg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue());
String json = JSON.toJSONString(socketMsg); socketMsg.setData(JSON.toJSONString(FormalTestManager.currentIssue));
// 使用智能发送工具类,自动管理设备连接 socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + CnSocketUtil.STEP_TAG + type);
socketManager.smartSendToDevice(param, json); SocketManager.sendMsg(param.getUserPageId() + CnSocketUtil.SOURCE_TAG, JSON.toJSONString(socketMsg));
} else {
//todo 前端推送收到的消息暂未处理好
sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
//开始设备通讯检测(发送设备初始化)
Map<String, List<PreDetection>> 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; break;
case UNPROCESSED_BUSINESS: case UNPROCESSED_BUSINESS:
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
@@ -570,6 +592,10 @@ public class SocketSourceResponseService {
case UNPROCESSED_BUSINESS: case UNPROCESSED_BUSINESS:
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); sendWebSocketMessage(param.getUserPageId(), socketDataMsg);
break; break;
case UNKNOWN_ERROR: //-1源未知异常
CnSocketUtil.quitSendSource(param);
FormalTestManager.unknownError = true;
break;
default: default:
sendErrorAndQuit(param, socketDataMsg, dictDataEnumByCode); sendErrorAndQuit(param, socketDataMsg, dictDataEnumByCode);
break; break;
@@ -601,9 +627,23 @@ public class SocketSourceResponseService {
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
switch (Objects.requireNonNull(dictDataEnumByCode)) { switch (Objects.requireNonNull(dictDataEnumByCode)) {
case SUCCESS: case SUCCESS:
//通讯校验成功 if (FormalTestManager.unknownError) {
SocketManager.removeUser(param.getUserPageId() + CnSocketUtil.SOURCE_TAG); //获取源初始化参数
sendWebSocketMessage(param.getUserPageId(), socketDataMsg); AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper<AdPlanSource>().eq(AdPlanSource::getPlanId, param.getPlanId()));
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
if (ObjectUtil.isNotNull(sourceParam)) {
SocketMsg<String> 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; break;
case UNPROCESSED_BUSINESS: case UNPROCESSED_BUSINESS:
break; break;
@@ -653,6 +693,8 @@ public class SocketSourceResponseService {
// 同步更新系数管理器中的设备列表 // 同步更新系数管理器中的设备列表
XiNumberManager.xiDevList = devList; XiNumberManager.xiDevList = devList;
FormalTestManager.unknownError = false;
FormalTestManager.currentIssue = null;
} }
} }

View File

@@ -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.enums.DataSourceEnum;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanTestConfig; 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 com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import java.util.ArrayList; import java.util.ArrayList;
@@ -195,4 +196,11 @@ public class FormalTestManager {
public static boolean statisticsProtocol; public static boolean statisticsProtocol;
public static boolean voltageProtocol; public static boolean voltageProtocol;
public static boolean unknownError;
/**
* 当前下发的脚本
*/
public static SourceIssue currentIssue;
} }