package com.mortals.xhx.common.pdu;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.queue.DefaultTbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import lombok.Data;

/**
 * @author: zxfei
 * @date: 2022/9/2 10:27
 * @description:
 **/
@Data
public class DefaultQueueMsg {
    /**
     * 消息key
     */
    private String key;
    /**
     * 消息体（base64编码）
     */
    private String data;

    private DefaultQueueMsgHeader headers;

    public static void main(String[] args) {

        TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
        header.put(MessageHeader.MESSAGETYPE, "UPGREAD");
        // header.put(MessageHeader.CLIENTID, "abcd1234");
        //  header.put(MessageHeader.TIMESTAMP, DateUtils.getCurrStrDateTime());
        //header.put(MessageHeader.MESSAGESIGN,"ssdafasdfasdfasfd");
        TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), "eyJmbG93bnVtIjoiQzEwMTEifQ==" , header);

        String ret = JSON.toJSONString(queueMsg);
        System.out.println("pro:"+ret);
//
        DefaultQueueMsg qu = JSON.parseObject(ret, DefaultQueueMsg.class);


        System.out.println("header:"+qu.getHeaders().getData().get(MessageHeader.MESSAGETYPE));
        System.out.println("data:"+qu.getData());

    }
}
