代码调整
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
|
|||||||
* <li>心跳超时处理</li>
|
* <li>心跳超时处理</li>
|
||||||
* <li>异常处理和恢复</li>
|
* <li>异常处理和恢复</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @Description: 设备客户端业务处理器
|
* @Description: 设备客户端业务处理器
|
||||||
* @Author: wr
|
* @Author: wr
|
||||||
* @Date: 2024/12/10 14:16
|
* @Date: 2024/12/10 14:16
|
||||||
@@ -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;
|
||||||
@@ -81,7 +91,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
log.info("客户端通道已建立: {}", ctx.channel().id());
|
log.info("客户端通道已建立: {}", ctx.channel().id());
|
||||||
|
|
||||||
// 检查是否存在同一用户的老连接
|
// 检查是否存在同一用户的老连接
|
||||||
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + CnSocketUtil.DEV_TAG);
|
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + CnSocketUtil.DEV_TAG);
|
||||||
if (Objects.nonNull(channel)) {
|
if (Objects.nonNull(channel)) {
|
||||||
@@ -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);
|
||||||
@@ -130,7 +139,6 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户事件回调方法,主要用于处理心跳超时
|
* 用户事件回调方法,主要用于处理心跳超时
|
||||||
@@ -171,7 +179,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
* 异常捕获处理
|
* 异常捕获处理
|
||||||
* <p>捕获并处理各种类型的异常,执行清理工作</p>
|
* <p>捕获并处理各种类型的异常,执行清理工作</p>
|
||||||
*
|
*
|
||||||
* @param ctx 通道上下文
|
* @param ctx 通道上下文
|
||||||
* @param cause 异常原因
|
* @param cause 异常原因
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +281,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
private boolean isTimeout(SourceIssue sourceIssue) {
|
private boolean isTimeout(SourceIssue sourceIssue) {
|
||||||
long currentTime = SocketManager.clockMap.get(sourceIssue.getIndex());
|
long currentTime = SocketManager.clockMap.get(sourceIssue.getIndex());
|
||||||
String type = sourceIssue.getType();
|
String type = sourceIssue.getType();
|
||||||
|
|
||||||
// 根据不同检测类型使用不同的超时阈值
|
// 根据不同检测类型使用不同的超时阈值
|
||||||
if (DicDataEnum.F.getCode().equals(type)) {
|
if (DicDataEnum.F.getCode().equals(type)) {
|
||||||
// 闪变检测:需要更长时间,20分钟超时
|
// 闪变检测:需要更长时间,20分钟超时
|
||||||
@@ -312,12 +318,12 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
List<DevLineTestResult> devListRes = FormalTestManager.devList.stream()
|
List<DevLineTestResult> devListRes = FormalTestManager.devList.stream()
|
||||||
.map(this::createTimeoutResult)
|
.map(this::createTimeoutResult)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
WebSocketVO<List<DevLineTestResult>> socketVO = new WebSocketVO<>();
|
WebSocketVO<List<DevLineTestResult>> socketVO = new WebSocketVO<>();
|
||||||
socketVO.setRequestId(sourceIssue.getType() + CnSocketUtil.END_TAG);
|
socketVO.setRequestId(sourceIssue.getType() + CnSocketUtil.END_TAG);
|
||||||
socketVO.setOperateCode(sourceIssue.getType());
|
socketVO.setOperateCode(sourceIssue.getType());
|
||||||
socketVO.setData(devListRes);
|
socketVO.setData(devListRes);
|
||||||
|
|
||||||
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketVO));
|
WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,12 +338,12 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
DevLineTestResult devLineTestResult = new DevLineTestResult();
|
DevLineTestResult devLineTestResult = new DevLineTestResult();
|
||||||
devLineTestResult.setDeviceId(dev.getDevId());
|
devLineTestResult.setDeviceId(dev.getDevId());
|
||||||
devLineTestResult.setDeviceName(dev.getDevName());
|
devLineTestResult.setDeviceName(dev.getDevName());
|
||||||
|
|
||||||
Integer[] resultFlags = dev.getMonitorList().stream()
|
Integer[] resultFlags = dev.getMonitorList().stream()
|
||||||
.map(monitor -> DEFAULT_RESULT_FLAG)
|
.map(monitor -> DEFAULT_RESULT_FLAG)
|
||||||
.toArray(Integer[]::new);
|
.toArray(Integer[]::new);
|
||||||
devLineTestResult.setChnResult(resultFlags);
|
devLineTestResult.setChnResult(resultFlags);
|
||||||
|
|
||||||
return devLineTestResult;
|
return devLineTestResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocket会话管理器
|
* WebSocket会话管理器
|
||||||
*
|
*
|
||||||
* <p>负责管理电能质量检测系统中的WebSocket连接会话和检测参数,主要功能包括:</p>
|
* <p>负责管理电能质量检测系统中的WebSocket连接会话和检测参数,主要功能包括:</p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>WebSocket连接会话的添加、删除和管理</li>
|
* <li>WebSocket连接会话的添加、删除和管理</li>
|
||||||
* <li>向指定用户推送实时消息(文本消息和结构化消息)</li>
|
* <li>向指定用户推送实时消息(文本消息和结构化消息)</li>
|
||||||
* <li>全局检测参数的存储和管理</li>
|
* <li>全局检测参数的存储和管理</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <p><b>线程安全性:</b></p>
|
* <p><b>线程安全性:</b></p>
|
||||||
* 使用ConcurrentHashMap确保在高并发环境下的线程安全。
|
* 使用ConcurrentHashMap确保在高并发环境下的线程安全。
|
||||||
*
|
*
|
||||||
* <p><b>使用场景:</b></p>
|
* <p><b>使用场景:</b></p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>检测进度实时推送</li>
|
* <li>检测进度实时推送</li>
|
||||||
@@ -34,20 +34,19 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
* <li>设备状态变更通知</li>
|
* <li>设备状态变更通知</li>
|
||||||
* <li>异常信息推送</li>
|
* <li>异常信息推送</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <p><b>消息推送方式:</b></p>
|
* <p><b>消息推送方式:</b></p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #sendMsg(String, String)} - 发送纯文本消息</li>
|
* <li>{@link #sendMsg(String, String)} - 发送纯文本消息</li>
|
||||||
* <li>{@link #sendMessage(String, WebSocketVO)} - 发送结构化JSON消息</li>
|
* <li>{@link #sendMessage(String, WebSocketVO)} - 发送结构化JSON消息</li>
|
||||||
* </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 {
|
||||||
@@ -67,8 +66,8 @@ public class WebServiceManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加用户WebSocket会话
|
* 添加用户WebSocket会话
|
||||||
*
|
*
|
||||||
* @param userId 用户ID,不能为null
|
* @param userId 用户ID,不能为null
|
||||||
* @param channel WebSocket连接通道,不能为null
|
* @param channel WebSocket连接通道,不能为null
|
||||||
*/
|
*/
|
||||||
public static void addUser(String userId, Channel channel) {
|
public static void addUser(String userId, Channel channel) {
|
||||||
@@ -79,7 +78,7 @@ public class WebServiceManager {
|
|||||||
/**
|
/**
|
||||||
* 根据用户ID移除会话(推荐使用)
|
* 根据用户ID移除会话(推荐使用)
|
||||||
* 时间复杂度:O(1)
|
* 时间复杂度:O(1)
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 被移除的Channel,如果不存在则返回null
|
* @return 被移除的Channel,如果不存在则返回null
|
||||||
*/
|
*/
|
||||||
@@ -90,7 +89,7 @@ public class WebServiceManager {
|
|||||||
/**
|
/**
|
||||||
* 根据channelId移除会话(兼容老版本)
|
* 根据channelId移除会话(兼容老版本)
|
||||||
* 时间复杂度:O(n),建议使用removeByUserId替代
|
* 时间复杂度:O(n),建议使用removeByUserId替代
|
||||||
*
|
*
|
||||||
* @param channelId 通道ID
|
* @param channelId 通道ID
|
||||||
* @deprecated 建议使用 {@link #removeByUserId(String)} 替代
|
* @deprecated 建议使用 {@link #removeByUserId(String)} 替代
|
||||||
*/
|
*/
|
||||||
@@ -110,9 +109,9 @@ public class WebServiceManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送纯文本消息给指定用户
|
* 发送纯文本消息给指定用户
|
||||||
*
|
*
|
||||||
* @param userId 目标用户ID
|
* @param userId 目标用户ID
|
||||||
* @param msg 要发送的文本消息
|
* @param msg 要发送的文本消息
|
||||||
*/
|
*/
|
||||||
public static void sendMsg(String userId, String msg) {
|
public static void sendMsg(String userId, String msg) {
|
||||||
Channel channel = userSessions.get(userId);
|
Channel channel = userSessions.get(userId);
|
||||||
@@ -127,8 +126,8 @@ public class WebServiceManager {
|
|||||||
/**
|
/**
|
||||||
* 发送结构化消息给指定用户
|
* 发送结构化消息给指定用户
|
||||||
* 消息会被序列化为JSON格式后发送
|
* 消息会被序列化为JSON格式后发送
|
||||||
*
|
*
|
||||||
* @param userId 目标用户ID
|
* @param userId 目标用户ID
|
||||||
* @param webSocketVO 要发送的结构化消息对象
|
* @param webSocketVO 要发送的结构化消息对象
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(String userId, WebSocketVO<Object> webSocketVO) {
|
public static void sendMessage(String userId, WebSocketVO<Object> webSocketVO) {
|
||||||
@@ -144,8 +143,8 @@ public class WebServiceManager {
|
|||||||
/**
|
/**
|
||||||
* 存储检测参数(基于用户ID)
|
* 存储检测参数(基于用户ID)
|
||||||
* 支持多用户并发检测,每个用户的检测参数独立存储
|
* 支持多用户并发检测,每个用户的检测参数独立存储
|
||||||
*
|
*
|
||||||
* @param userId 用户ID(登录名)
|
* @param userId 用户ID(登录名)
|
||||||
* @param preDetectionParam 检测参数对象
|
* @param preDetectionParam 检测参数对象
|
||||||
* @throws IllegalArgumentException 当userId或检测参数为空时抛出
|
* @throws IllegalArgumentException 当userId或检测参数为空时抛出
|
||||||
*/
|
*/
|
||||||
@@ -158,22 +157,22 @@ public class WebServiceManager {
|
|||||||
}
|
}
|
||||||
preDetectionParamMap.put(userId, preDetectionParam);
|
preDetectionParamMap.put(userId, preDetectionParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定用户的检测参数
|
* 获取指定用户的检测参数
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 检测参数对象,如果不存在则返回null
|
* @return 检测参数对象,如果不存在则返回null
|
||||||
*/
|
*/
|
||||||
public static PreDetectionParam getPreDetectionParam(String userId) {
|
public static PreDetectionParam getPreDetectionParam(String userId) {
|
||||||
return preDetectionParamMap.get(userId);
|
return preDetectionParamMap.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前检测参数(兼容老版本)
|
* 获取当前检测参数(兼容老版本)
|
||||||
* 注意:该方法已废弃,建议使用 {@link #getPreDetectionParam(String)}
|
* 注意:该方法已废弃,建议使用 {@link #getPreDetectionParam(String)}
|
||||||
*
|
*
|
||||||
* @return 检测参数对象,如果不存在则返回null
|
* @return 检测参数对象,如果不存在则返回null
|
||||||
* @deprecated 多用户并发场景下该方法不安全,请使用 {@link #getPreDetectionParam(String)}
|
* @deprecated 多用户并发场景下该方法不安全,请使用 {@link #getPreDetectionParam(String)}
|
||||||
*/
|
*/
|
||||||
@@ -185,48 +184,48 @@ public class WebServiceManager {
|
|||||||
log.warn("存在多个检测参数,无法确定返回哪个,当前参数数量: {}", preDetectionParamMap.size());
|
log.warn("存在多个检测参数,无法确定返回哪个,当前参数数量: {}", preDetectionParamMap.size());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除指定用户的检测参数
|
* 移除指定用户的检测参数
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 被移除的检测参数,如果不存在则返回null
|
* @return 被移除的检测参数,如果不存在则返回null
|
||||||
*/
|
*/
|
||||||
public static PreDetectionParam removePreDetectionParam(String userId) {
|
public static PreDetectionParam removePreDetectionParam(String userId) {
|
||||||
return preDetectionParamMap.remove(userId);
|
return preDetectionParamMap.remove(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空所有检测参数
|
* 清空所有检测参数
|
||||||
*/
|
*/
|
||||||
public static void removeAllPreDetectionParam() {
|
public static void removeAllPreDetectionParam() {
|
||||||
preDetectionParamMap.clear();
|
preDetectionParamMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空所有检测参数(兼容老版本)
|
* 清空所有检测参数(兼容老版本)
|
||||||
*
|
*
|
||||||
* @deprecated 建议使用 {@link #removeAllPreDetectionParam()} 或 {@link #removePreDetectionParam(String)}
|
* @deprecated 建议使用 {@link #removeAllPreDetectionParam()} 或 {@link #removePreDetectionParam(String)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void removePreDetectionParam() {
|
public static void removePreDetectionParam() {
|
||||||
removeAllPreDetectionParam();
|
removeAllPreDetectionParam();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================ 实用功能方法 ================================
|
// ================================ 实用功能方法 ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前在线用户数量
|
* 获取当前在线用户数量
|
||||||
*
|
*
|
||||||
* @return 在线用户数量
|
* @return 在线用户数量
|
||||||
*/
|
*/
|
||||||
public static int getOnlineUserCount() {
|
public static int getOnlineUserCount() {
|
||||||
return userSessions.size();
|
return userSessions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查指定用户是否在线
|
* 检查指定用户是否在线
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return true如果用户在线且连接活跃,否则返回false
|
* @return true如果用户在线且连接活跃,否则返回false
|
||||||
*/
|
*/
|
||||||
@@ -234,27 +233,27 @@ public class WebServiceManager {
|
|||||||
Channel channel = userSessions.get(userId);
|
Channel channel = userSessions.get(userId);
|
||||||
return Objects.nonNull(channel) && channel.isActive();
|
return Objects.nonNull(channel) && channel.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有在线用户ID集合
|
* 获取所有在线用户ID集合
|
||||||
*
|
*
|
||||||
* @return 在线用户ID集合的快照
|
* @return 在线用户ID集合的快照
|
||||||
*/
|
*/
|
||||||
public static java.util.Set<String> getOnlineUserIds() {
|
public static java.util.Set<String> getOnlineUserIds() {
|
||||||
return new java.util.HashSet<>(userSessions.keySet());
|
return new java.util.HashSet<>(userSessions.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================ 检测消息推送方法 ================================
|
// ================================ 检测消息推送方法 ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送检测相关消息给指定用户
|
* 发送检测相关消息给指定用户
|
||||||
* <p>用于推送检测状态、进度、结果等结构化消息</p>
|
* <p>用于推送检测状态、进度、结果等结构化消息</p>
|
||||||
*
|
*
|
||||||
* @param userId 目标用户ID
|
* @param userId 目标用户ID
|
||||||
* @param requestId 请求ID,用于标识消息类型和流程
|
* @param requestId 请求ID,用于标识消息类型和流程
|
||||||
* @param operateCode 操作代码,标识具体的操作类型
|
* @param operateCode 操作代码,标识具体的操作类型
|
||||||
* @param data 数据载荷,可以是任意类型的数据
|
* @param data 数据载荷,可以是任意类型的数据
|
||||||
* @param desc 描述信息
|
* @param desc 描述信息
|
||||||
* @since v2.3.12 重构版本
|
* @since v2.3.12 重构版本
|
||||||
*/
|
*/
|
||||||
public static void sendDetectionMessage(String userId, String requestId, String operateCode, Object data, String desc) {
|
public static void sendDetectionMessage(String userId, String requestId, String operateCode, Object data, String desc) {
|
||||||
@@ -269,7 +268,7 @@ public class WebServiceManager {
|
|||||||
/**
|
/**
|
||||||
* 发送未知错误消息给指定用户
|
* 发送未知错误消息给指定用户
|
||||||
* <p>用于处理系统无法识别的操作或未知异常情况</p>
|
* <p>用于处理系统无法识别的操作或未知异常情况</p>
|
||||||
*
|
*
|
||||||
* @param userId 目标用户ID
|
* @param userId 目标用户ID
|
||||||
* @since v2.3.12 重构版本
|
* @since v2.3.12 重构版本
|
||||||
*/
|
*/
|
||||||
@@ -280,12 +279,12 @@ public class WebServiceManager {
|
|||||||
webSocketVO.setOperateCode(SourceOperateCodeEnum.UNKNOWN_OPERATE.getMsg());
|
webSocketVO.setOperateCode(SourceOperateCodeEnum.UNKNOWN_OPERATE.getMsg());
|
||||||
sendMessage(userId, webSocketVO);
|
sendMessage(userId, webSocketVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送检测错误消息给指定用户
|
* 发送检测错误消息给指定用户
|
||||||
* <p>用于推送特定类型的检测错误信息</p>
|
* <p>用于推送特定类型的检测错误信息</p>
|
||||||
*
|
*
|
||||||
* @param userId 目标用户ID
|
* @param userId 目标用户ID
|
||||||
* @param errorType 错误类型枚举
|
* @param errorType 错误类型枚举
|
||||||
* @since v2.3.12 重构版本
|
* @since v2.3.12 重构版本
|
||||||
*/
|
*/
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user