package com.ruoyi.dataInterchange.server;
|
|
import com.ruoyi.dataInterchange.model.UPPlatformMsg;
|
import com.ruoyi.dataInterchange.model.enu.DataType;
|
import com.ruoyi.dataInterchange.util.jtt809.packet.common.OuterPacket;
|
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.Unpooled;
|
import io.netty.channel.ChannelHandlerContext;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2025/3/4 20:41
|
*/
|
@Slf4j
|
@Component
|
public class PlatformMsgService {
|
|
@Resource
|
private RedisTemplate redisTemplate;
|
|
|
public void up_platform_msg(ChannelHandlerContext ctx, OuterPacket out) {
|
if (!redisTemplate.hasKey("login:" + out.getGnsscenterId())) {
|
log.error("链路还未登录校验,拒绝连接:{}", out.getGnsscenterId());
|
ctx.close();
|
return;
|
}
|
UPPlatformMsg platformMsg = getPlatformMsg(out);
|
DataType dataType = DataType.getDataType(platformMsg.getDataType());
|
switch (dataType) {
|
case UP_PLATFORM_MSG_POST_QUERY_ACK:
|
log.info("平台查岗应答消息({}):{}", DataType.UP_PLATFORM_MSG_POST_QUERY_ACK.getCode(), platformMsg);
|
break;
|
case UP_PLATFORM_MSG_INFO_ACK:
|
log.info("下发平台间报文应答消息({}):{}", DataType.UP_PLATFORM_MSG_INFO_ACK.getCode(), platformMsg);
|
break;
|
default:
|
break;
|
}
|
}
|
|
|
/**
|
* 解析子业务数据
|
*
|
* @param out
|
* @return
|
*/
|
public UPPlatformMsg getPlatformMsg(OuterPacket out) {
|
byte[] body = out.getBody();
|
ByteBuf byteBuf = Unpooled.wrappedBuffer(body);
|
//子业务类型标识
|
int dataType = byteBuf.readShort();
|
//后续数据长度
|
int dataLength = byteBuf.readInt();
|
//子业务数据包
|
byte[] data = new byte[byteBuf.readableBytes()];
|
byteBuf.readBytes(data);
|
UPPlatformMsg platformMsg = new UPPlatformMsg();
|
platformMsg.setDataType(dataType);
|
platformMsg.setDataLength(dataLength);
|
platformMsg.setData(data);
|
return platformMsg;
|
}
|
}
|