|
|
|
@ -1,18 +1,15 @@ |
|
|
|
package com.mh.user.netty.handle; |
|
|
|
package com.mh.user.netty.handle; |
|
|
|
|
|
|
|
|
|
|
|
import com.github.benmanes.caffeine.cache.Cache; |
|
|
|
import com.mh.common.utils.StringUtils; |
|
|
|
import com.mh.user.constants.FourthGEnum; |
|
|
|
|
|
|
|
import com.mh.user.entity.GatewayManageEntity; |
|
|
|
import com.mh.user.entity.GatewayManageEntity; |
|
|
|
import com.mh.user.netty.session.ServerSession; |
|
|
|
import com.mh.user.netty.session.ServerSession; |
|
|
|
import com.mh.user.netty.session.SessionMap; |
|
|
|
import com.mh.user.netty.session.SessionMap; |
|
|
|
import com.mh.user.utils.CacheUtil; |
|
|
|
import com.mh.user.utils.CacheUtil; |
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
|
|
import com.mh.user.utils.NettyTools; |
|
|
|
import com.mh.user.utils.NettyTools; |
|
|
|
import com.mh.user.utils.SpringBeanUtil; |
|
|
|
|
|
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter; |
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@ -22,26 +19,31 @@ public class DataUploadServerHandler extends ChannelInboundHandlerAdapter { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { |
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { |
|
|
|
//将接收到的数据转为字符串,此字符串就是客户端发送的字符串
|
|
|
|
//将接收到的数据转为字符串,此字符串就是客户端发送的字符串
|
|
|
|
String receiveStr = ExchangeStringUtil.bytesToHexString((byte[]) msg); |
|
|
|
String receiveStr = ExchangeStringUtil.bytesToHexString(msg); |
|
|
|
// 判断当前报文是否是上报数据报文
|
|
|
|
// 判断当前报文是否是上报数据报文
|
|
|
|
if (receiveStr != null) { |
|
|
|
if (receiveStr != null) { |
|
|
|
// 判断属于哪一个DTU网关上报的数据
|
|
|
|
// 判断属于哪一个DTU网关上报的数据
|
|
|
|
CacheUtil instance = CacheUtil.getInstance(); |
|
|
|
CacheUtil instance = CacheUtil.getInstance(); |
|
|
|
List<GatewayManageEntity> gwList = instance.getGatewayInfo(); |
|
|
|
List<GatewayManageEntity> gwList = instance.getGatewayInfo(); |
|
|
|
|
|
|
|
String deviceCode = ""; |
|
|
|
|
|
|
|
log.info("接收数据报文>>>>>>>>>>>>>>{}", receiveStr); |
|
|
|
if (gwList != null && !gwList.isEmpty()) { |
|
|
|
if (gwList != null && !gwList.isEmpty()) { |
|
|
|
for (GatewayManageEntity gw : gwList) { |
|
|
|
for (GatewayManageEntity gw : gwList) { |
|
|
|
if (receiveStr.startsWith(ExchangeStringUtil.str2HexStr(gw.getSn()))) { |
|
|
|
if (!StringUtils.isBlank(gw.getSn())) { |
|
|
|
|
|
|
|
String snHexStr = ExchangeStringUtil.str2HexStr(gw.getSn()); |
|
|
|
|
|
|
|
if (receiveStr.startsWith(snHexStr)) { |
|
|
|
// 直接设置对应值
|
|
|
|
// 直接设置对应值
|
|
|
|
NettyTools.setReceiveMsg(gw.getHeartBeat(), receiveStr.substring(gw.getSn().length())); |
|
|
|
deviceCode = gw.getHeartBeat(); |
|
|
|
} else { |
|
|
|
NettyTools.setReceiveMsg(gw.getHeartBeat(), receiveStr.substring(snHexStr.length())); |
|
|
|
// 判断是否登录,没有登录立马断开
|
|
|
|
break; |
|
|
|
String deviceCode = gw.getHeartBeat(); |
|
|
|
} |
|
|
|
if (!SessionMap.inst().hasLogin(deviceCode+ctx.channel().remoteAddress())) { |
|
|
|
|
|
|
|
ServerSession.closeSession(ctx); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 判断是否登录,没有登录立马断开
|
|
|
|
|
|
|
|
if (!SessionMap.inst().hasLogin(deviceCode + ctx.channel().remoteAddress())) { |
|
|
|
|
|
|
|
ServerSession.closeSession(ctx); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
super.channelRead(ctx, msg); |
|
|
|
super.channelRead(ctx, msg); |
|
|
|
|