Pu Zhibing
2025-03-14 3c66b754ee314ae87d0f2eda2fa86a30ea2304e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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("链路还未登录校验,拒绝连接");
            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;
    }
}