代码优化

master
liuqingkun 3 years ago
parent 20bd8e9383
commit bf12bf1aad
  1. 18
      jtt808-server/src/main/java/io/github/yezhihao/netmc/websocket/WsChannelInboundHandler.java

@ -1,5 +1,6 @@
package io.github.yezhihao.netmc.websocket;
import io.github.yezhihao.netmc.session.SessionManager;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
@ -10,6 +11,7 @@ import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.internal.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.yzh.commons.constant.BusinessConstant;
import org.yzh.commons.util.BusinessCacheUtil;
import org.yzh.web.util.SendCommandUtil;
@ -24,6 +26,9 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
private static final Logger log = LoggerFactory.getLogger(WsChannelInboundHandler.class);
@Autowired
private SessionManager sessionManager;
/**
* 用于记录和管理所有客户端的channle
*/
@ -54,6 +59,9 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
content = content.replace("jtt1078:", "");
String curPush = BusinessCacheUtil.getCurrentPushDevice();
int curPushChannel = BusinessCacheUtil.getCurrentPushChannel();
if (content.contains("-")) {
// 由于1078传过来的信息为(0+clientId+'-'+channelNo), 故此处需要解析
// 接收jt1078通过websocket传输的数据
@ -63,10 +71,7 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
BusinessCacheUtil.set1078PushDevice(clientId);
// 重置1078推送为空的次数
BusinessCacheUtil.setPushEmptyTimes(0);
String curPush = BusinessCacheUtil.getCurrentPushDevice();
int curPushChannel = BusinessCacheUtil.getCurrentPushChannel();
// BusinessCacheUtil.setPushEmptyTimes(0);
log.debug(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 1078推流设备 = {} - {} ", clientId, channelNo);
// 如果1078推送的正在推流的设备 != 808记录的当前推流的设备, 调用接口通知慢直播服务, 当前推流车辆及推流状态信息
@ -78,10 +83,9 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
}
} else {
// 若接收到1078推送的当前推流设备为空, 更新808的缓存
String curPush = BusinessCacheUtil.getCurrentPushDevice();
if (!StringUtil.isNullOrEmpty(curPush)) {
if (SendCommandUtil.getService() != null) {
log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 更新为1078正在推流设备 = {} - {} ", curPush, "null");
log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 原推流设备 = {} - {} : 更新为1078正在推流设备 = null ", curPush, curPushChannel);
SendCommandUtil.getService().noticeCarStatus(null, BusinessConstant.DEFAULT_CHANNEL_NO, BusinessConstant.LIVE_STATUS_OFFLINE);
}
}
@ -91,7 +95,7 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
// // 若持续30s收到的消息都为空, 调用推流方法
// if (emptyTimes == 30) {
// log.warn(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 持续30s收到的消息都为空, 调用推流方法 ");
if (SendCommandUtil.getService() != null) {
if (SendCommandUtil.getService() != null && sessionManager != null && sessionManager.all() != null && sessionManager.all().size() > 0) {
SendCommandUtil.getService().sendToDevice(null, null);
}
// emptyTimes = 0;

Loading…
Cancel
Save