添加日志, websocket接收逻辑修改

master
liuqingkun 3 years ago
parent 537a440756
commit aeecbea7af
  1. 20
      jtt808-server/src/main/java/io/github/yezhihao/netmc/websocket/WsChannelInboundHandler.java
  2. 5
      jtt808-server/src/main/java/org/yzh/web/endpoint/JT808Endpoint.java

@ -7,6 +7,7 @@ import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.internal.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yzh.commons.constant.BusinessConstant;
@ -14,6 +15,7 @@ import org.yzh.commons.util.BusinessCacheUtil;
import org.yzh.web.util.SendCommandUtil;
import java.time.LocalDateTime;
import java.time.LocalTime;
/**
* 处理消息的handler
@ -37,6 +39,12 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
// 获取客户端传输过来的消息
String content = msg.text();
// 每分钟的0s, 打印当前推流通道
LocalTime localTime = LocalTime.now();
if (localTime.getSecond() == 0) {
log.info(BusinessConstant.LOGGER_PREFIX + " : jt1078推送信息 : content = {}", content);
}
if (content.contains("-")) {
// 由于1078传过来的信息为(0+clientId+'-'+channelNo), 故此处需要解析
// 接收jt1078通过websocket传输的数据
@ -55,7 +63,17 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
SendCommandUtil.getService().noticeCarStatus(clientId, Integer.parseInt(channelNo), BusinessConstant.LIVE_STATUS_ONLINE);
}
}
} else {
// 若接收到1078推送的当前推流设备为空, 更新808的缓存
String curPush = BusinessCacheUtil.getCurrentPushDevice();
if (!StringUtil.isNullOrEmpty(curPush)) {
if (SendCommandUtil.getService() != null) {
log.info(BusinessConstant.LOGGER_PREFIX + " : websocket接收 : 更新为1078正在推流设备 = {} - {} ", curPush, "null");
SendCommandUtil.getService().noticeCarStatus(null, BusinessConstant.DEFAULT_CHANNEL_NO, BusinessConstant.LIVE_STATUS_OFFLINE);
}
}
}
currentChannel.writeAndFlush(new TextWebSocketFrame("服务器时间" + LocalDateTime.now() + " : " + content));
}
@ -68,7 +86,7 @@ public class WsChannelInboundHandler extends SimpleChannelInboundHandler<TextWeb
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
users.add(ctx.channel());
log.info("netty 获得连接..... ");
log.info(BusinessConstant.LOGGER_PREFIX + " : websocket连接 : 客户端上线 : channelId = {} ", ctx.channel().id().asShortText());
log.info(BusinessConstant.LOGGER_PREFIX + " : websocket连接 : 客户端上线 : channelId = {} ", ctx.channel().id().asShortText());
ctx.channel().writeAndFlush(new TextWebSocketFrame("服务器时间" + LocalDateTime.now() + " qw12312"));

@ -5,6 +5,7 @@ import io.github.yezhihao.netmc.core.annotation.AsyncBatch;
import io.github.yezhihao.netmc.core.annotation.Endpoint;
import io.github.yezhihao.netmc.core.annotation.Mapping;
import io.github.yezhihao.netmc.session.Session;
import io.netty.util.internal.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -75,7 +76,7 @@ public class JT808Endpoint {
// 若无正在推流的设备, 调用推流方法
SendCommandUtil.setService(sendCommandService);
if (BusinessCacheUtil.getCurrentPushDevice() == null || BusinessCacheUtil.getCurrentPushDevice() == message.getClientId()) {
if (StringUtil.isNullOrEmpty(BusinessCacheUtil.getCurrentPushDevice()) || BusinessCacheUtil.getCurrentPushDevice().equals(message.getClientId())) {
log.info(BusinessConstant.LOGGER_PREFIX + " : 终端鉴权触发 - 发送推流命令 : 当前指定推流设备 = {} -> 将要推流设备 = {} ", BusinessCacheUtil.getCurrentPushDevice(), message.getClientId());
sendCommandService.sendToDevice(message.getClientId(), null);
} else {
@ -103,7 +104,7 @@ public class JT808Endpoint {
// 若无正在推流的设备, 调用推流方法
SendCommandUtil.setService(sendCommandService);
if (BusinessCacheUtil.getCurrentPushDevice() == null || BusinessCacheUtil.getCurrentPushDevice() == message.getClientId()) {
if (StringUtil.isNullOrEmpty(BusinessCacheUtil.getCurrentPushDevice()) || BusinessCacheUtil.getCurrentPushDevice().equals(message.getClientId())) {
log.info(BusinessConstant.LOGGER_PREFIX + " : 终端鉴权触发 - 发送推流命令 : 当前指定推流设备 = {} -> 将要推流设备 = {} ", BusinessCacheUtil.getCurrentPushDevice(), message.getClientId());
sendCommandService.sendToDevice(message.getClientId(), null);
} else {

Loading…
Cancel
Save