Pu Zhibing
2025-03-07 297512bc22b179b7038d96a1ff033eceaed38c4b
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
package com.ruoyi.dataInterchange.server;
 
import com.ruoyi.dataInterchange.model.UPExgMsg;
import com.ruoyi.dataInterchange.model.UPPlatformMsg;
import com.ruoyi.dataInterchange.model.UPPlatformMsgInfoAck;
import com.ruoyi.dataInterchange.model.enu.DataType;
import com.ruoyi.dataInterchange.util.jtt809.common.Jtt809Util;
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.stereotype.Component;
 
/**
 * @author zhibing.pu
 * @Date 2025/3/4 20:41
 */
@Slf4j
@Component
public class PlatformMsgService {
    
    public void up_platform_msg(ChannelHandlerContext ctx, OuterPacket out){
        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;
            case UP_PLATFORM_MSG_RETRAN_REQ:
                log.info("上传平台间消息补传请求({}):{}", DataType.UP_PLATFORM_MSG_RETRAN_REQ.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;
    }
}