代码调整

This commit is contained in:
2025-08-11 16:31:26 +08:00
parent 09d2911c4c
commit fe5040c7af
4 changed files with 94 additions and 71 deletions

View File

@@ -857,7 +857,7 @@ public class SocketDevResponseService {
webSocketVO.setData(JSON.toJSONString(map)); webSocketVO.setData(JSON.toJSONString(map));
webSocketVO.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue()); webSocketVO.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
webSocketVO.setOperateCode(SourceOperateCodeEnum.VERIFY_MAPPING$01.getValue()); webSocketVO.setOperateCode(SourceOperateCodeEnum.VERIFY_MAPPING$01.getValue());
webSocketVO.setCode(SourceResponseCodeEnum.SUCCESS.getCode()); webSocketVO.setCode(SourceResponseCodeEnum.FAIL.getCode());
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO)); WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(webSocketVO));
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
break; break;

View File

@@ -236,8 +236,9 @@ public class PreDetectionServiceImpl implements PreDetectionService {
xuMsg.setData(JSON.toJSONString(sourceIssues)); xuMsg.setData(JSON.toJSONString(sourceIssues));
xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType()); xuMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue() + "&&" + sourceIssues.getType());
SocketManager.sendMsg(param.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg)); SocketManager.sendMsg(param.getUserPageId() + DetectionCommunicateConstant.SOURCE, JSON.toJSONString(xuMsg));
// Resume_Success
} else { } else {
//TODO 是否最终检测完成需要推送给用户 //TODO 是否最终检测完成需要推送给用户 检测完成
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam(); PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
checkDataParam.setScriptId(param.getScriptId()); checkDataParam.setScriptId(param.getScriptId());
checkDataParam.setIsValueTypeName(false); checkDataParam.setIsValueTypeName(false);

View File

@@ -51,19 +51,29 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> { public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
/** 闪变检测超时时间20分钟1300秒 */ /**
* 闪变检测超时时间20分钟1300秒
*/
private static final long FLICKER_TIMEOUT = 1300L; private static final long FLICKER_TIMEOUT = 1300L;
/** 统计数据检测超时时间3分钟180秒 */ /**
* 统计数据检测超时时间3分钟180秒
*/
private static final long STATISTICS_TIMEOUT = 180L; private static final long STATISTICS_TIMEOUT = 180L;
/** 实时数据检测超时时间1分钟60秒 */ /**
* 实时数据检测超时时间1分钟60秒
*/
private static final long REALTIME_TIMEOUT = 60L; private static final long REALTIME_TIMEOUT = 60L;
/** 暂停操作超时时间10分钟600秒 */ /**
* 暂停操作超时时间10分钟600秒
*/
private static final long STOP_TIMEOUT = 600L; private static final long STOP_TIMEOUT = 600L;
/** 超时时默认结果标志3表示超时失败 */ /**
* 超时时默认结果标志3表示超时失败
*/
private static final int DEFAULT_RESULT_FLAG = 3; private static final int DEFAULT_RESULT_FLAG = 3;
private final PreDetectionParam param; private final PreDetectionParam param;
@@ -117,10 +127,9 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
* *
* @param ctx 通道上下文 * @param ctx 通道上下文
* @param msg 接收到的消息 * @param msg 接收到的消息
* @throws InterruptedException 线程中断异常
*/ */
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException { protected void channelRead0(ChannelHandlerContext ctx, String msg) {
log.info("devhandler接收server端数据: {}", msg); log.info("devhandler接收server端数据: {}", msg);
try { try {
socketResponseService.deal(param, msg); socketResponseService.deal(param, msg);
@@ -131,7 +140,6 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
} }
/** /**
* 用户事件回调方法,主要用于处理心跳超时 * 用户事件回调方法,主要用于处理心跳超时
* <p>当触发READER_IDLE事件时根据当前状态进行超时处理</p> * <p>当触发READER_IDLE事件时根据当前状态进行超时处理</p>
@@ -208,8 +216,6 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
} }
/** /**
* 处理读取超时事件 * 处理读取超时事件
* <p>检查源列表,更新超时计数器,判断是否超时并处理</p> * <p>检查源列表,更新超时计数器,判断是否超时并处理</p>
@@ -241,7 +247,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
log.warn("当前进入暂停操作超时函数,停止时间: {}", FormalTestManager.stopTime); log.warn("当前进入暂停操作超时函数,停止时间: {}", FormalTestManager.stopTime);
if (FormalTestManager.stopTime > STOP_TIMEOUT) { if (FormalTestManager.stopTime > STOP_TIMEOUT) {
CnSocketUtil.quitSend(param); CnSocketUtil.quitSend(param);
WebServiceManager.sendDetectionErrorMessage(param.getUserPageId(), SourceOperateCodeEnum.STOP_TIMEOUT); WebServiceManager.sendDetectionErrorMessage(param.getUserPageId(),SourceOperateCodeEnum.FORMAL_REAL.getValue(), SourceOperateCodeEnum.STOP_TIMEOUT);
} }
} }

View File

@@ -42,12 +42,11 @@ import java.util.concurrent.ConcurrentHashMap;
* </ul> * </ul>
* *
* @author wr * @author wr
* @date 2024/12/11 13:04
* @version 1.0 * @version 1.0
* @since 检测系统 v2.3.12 * @date 2024/12/11 13:04
*
* @see com.njcn.gather.detection.util.socket.websocket.WebSocketHandler WebSocket处理器 * @see com.njcn.gather.detection.util.socket.websocket.WebSocketHandler WebSocket处理器
* @see com.njcn.gather.detection.pojo.vo.WebSocketVO WebSocket消息对象 * @see com.njcn.gather.detection.pojo.vo.WebSocketVO WebSocket消息对象
* @since 检测系统 v2.3.12
*/ */
@Slf4j @Slf4j
public class WebServiceManager { public class WebServiceManager {
@@ -296,5 +295,22 @@ public class WebServiceManager {
webSocketVO.setOperateCode(errorType.getValue()); webSocketVO.setOperateCode(errorType.getValue());
sendMessage(userId, webSocketVO); sendMessage(userId, webSocketVO);
} }
/**
* 发送检测错误消息给指定用户
* <p>用于推送特定类型的检测错误信息</p>
*
* @param userId 目标用户ID
* @param requestId 请求ID
* @param errorType 错误类型枚举
* @since v2.3.12 重构版本
*/
public static void sendDetectionErrorMessage(String userId, String requestId, SourceOperateCodeEnum errorType) {
WebSocketVO<Object> webSocketVO = new WebSocketVO<>();
webSocketVO.setRequestId(requestId);
webSocketVO.setData(errorType.getMsg());
webSocketVO.setOperateCode(errorType.getValue());
sendMessage(userId, webSocketVO);
}
} }