 package com.yunfeiyun.agmp.common.framework.mq;

import com.alibaba.fastjson2.JSON;
import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
import com.yunfeiyun.agmp.common.utils.uuid.Uuids;

import java.io.Serializable;

 public class MqMsg implements Serializable
 {
   private static final long serialVersionUID = -4842953318898603188L;
   private String seqId;
   private String msgType;
   private String cmd;
   private Object data;
   private String src;
   private Integer water;
   private Integer timeOut;

   public MqMsg(String msgType, String cmd, String src) {
     this.seqId = getId();
     this.msgType = msgType;
     this.cmd = cmd;
     this.src = src;
   }

   public <T> T getData(Class<T> clazz) {
     return (this.data == null) ? null : (T)JSON.parseObject(this.data.toString(), clazz);
   }

   public String getSeqId() {
     return this.seqId;
   }
   public void setSeqId(String seqId) {
     this.seqId = seqId;
   }

   public String getMsgType() {
     return this.msgType;
   }
   public void setMsgType(String msgType) {
     this.msgType = msgType;
   }

   public String getCmd() {
     return this.cmd;
   }
   public void setCmd(String cmd) {
     this.cmd = cmd;
   }
   public Object getData() {
     return this.data;
   }
   public void setData(Object data) {
     this.data = data;
   }

   public String getSrc() {
     return this.src;
   }
   public void setSrc(String src) {
     this.src = src;
   }


   public String getId()
   {
     try {
       return (Uuids.create().toString());
     }catch(Exception e){
       return IdUtils.fastUUID();
     }
   }

   @Override
   public String toString() {
     return "MqMsg{" +
             "seqId='" + seqId + '\'' +
             ", msgType='" + msgType + '\'' +
             ", cmd='" + cmd + '\'' +
             ", data=" + data +
             ", src='" + src + '\'' +
             ", water=" + water +
             ", timeOut=" + timeOut +
             '}';
   }

 }

