|  |  | 
 |  |  | package com.dy.common.mw.protocol4Mqtt; | 
 |  |  |  | 
 |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.upVos.ManureVo; | 
 |  |  | import com.dy.common.util.Callback; | 
 |  |  | import lombok.Data; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @Author: liurunyu | 
 |  |  |  * @Date: 2025/6/5 11:44 | 
 |  |  |  * @Description | 
 |  |  |  */ | 
 |  |  |  | 
 |  |  | public abstract class MqttSubMsg { | 
 |  |  | @Data | 
 |  |  | public class MqttSubMsg { | 
 |  |  |     public String commandId ;//命令ID | 
 |  |  |     public String mqttResultSendWebUrl ;//Mtt返回命令结果 发向目的地web URL | 
 |  |  |  | 
 |  |  |     public String deviceId ;//设备ID | 
 |  |  |     public String protocol;//协议 | 
 |  |  |  | 
 |  |  |     public String topic ;//消息主题 | 
 |  |  |     public String msg ;//消息 | 
 |  |  |     public MqttTopic topic ;//消息主题 | 
 |  |  |     public String metaData;//MQTT推送来的元数据 | 
 |  |  |  | 
 |  |  |     public abstract boolean valid(); | 
 |  |  |     public Vo4Up vo4Up;//订阅的消息数据值对象 | 
 |  |  |     public MqttSubMsg() { | 
 |  |  |     } | 
 |  |  |     public MqttSubMsg(MqttTopic subTopic, String msg) { | 
 |  |  |         this.deviceId = subTopic.devId ; | 
 |  |  |         this.protocol = subTopic.protocol ; | 
 |  |  |         this.topic = subTopic ; | 
 |  |  |         this.metaData = msg ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public abstract boolean subMsgMatchPubMsg(MqttPubMsg pubMsg); | 
 |  |  |     public boolean valid() { | 
 |  |  |         if (topic == null || topic.isEmpty()) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         if (metaData == null || metaData.isEmpty()) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         return true; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public abstract void action(Callback callback); | 
 |  |  |     public boolean subMsgMatchPubMsg(MqttPubMsg pubMsg){ | 
 |  |  |         if(this.vo4Up != null && this.vo4Up instanceof ManureVo){ | 
 |  |  |             //只要上报的是状态数据,说明设备响应了命令 | 
 |  |  |             return true ; | 
 |  |  |         } | 
 |  |  |         return false ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void action(Callback callback){ | 
 |  |  |         callback.call(this) ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     public String toString(){ | 
 |  |  |         StringBuilder sb = new StringBuilder(); | 
 |  |  |         if(commandId != null){ | 
 |  |  |             sb.append("commandId:") | 
 |  |  |                     .append(commandId) | 
 |  |  |                     .append("\n") ; | 
 |  |  |         } | 
 |  |  |         sb.append("主题:") | 
 |  |  |                 .append(topic.longName()) | 
 |  |  |                 .append("\n") ; | 
 |  |  |         if(vo4Up != null){ | 
 |  |  |             sb.append("数据:") | 
 |  |  |                     .append(vo4Up.toString()) | 
 |  |  |                     .append("\n") ; | 
 |  |  |         }else{ | 
 |  |  |             sb.append("元数据:") | 
 |  |  |                     .append(metaData) | 
 |  |  |                     .append("\n") ; | 
 |  |  |         } | 
 |  |  |         return sb.toString() ; | 
 |  |  |     } | 
 |  |  | } |