|  |  | 
 |  |  | import java.io.Serializable; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSON ; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  |  | 
 |  |  | public class Command implements Serializable{ | 
 |  |  |  | 
 |  |  | 
 |  |  |    public Boolean noRtMwDealRes ; | 
 |  |  |  | 
 |  |  |    /** | 
 |  |  |     * rtu返回命令结果 发向目的地web URL | 
 |  |  |     */ | 
 |  |  |    public String rtuResultSendWebUrl ; | 
 |  |  |  | 
 |  |  |    /** | 
 |  |  |     * 具体参数数据 | 
 |  |  |     */ | 
 |  |  |    public Object param ; | 
 |  |  | 
 |  |  |       String s = "命令id=" + id + "\n" ; | 
 |  |  |       s += (protocol == null ? "" : ("协议=" + protocol + "\n")); | 
 |  |  |       s += (rtuAddr == null ? "" : ("Rtu地址=" + rtuAddr + "\n")); | 
 |  |  |       s += "命令类型=" + (type.equals(CommandType.innerCommand)?"内部命令":"终端命令") + "\n" ; | 
 |  |  |       s += "命令类型=" + (type.equals(CommandType.innerCommand)?"内部命令":"RTU命令") + "\n" ; | 
 |  |  |       s += (code == null ? "" : ("功能码=" + code + "\n")) ; | 
 |  |  |       s += "返回中间件对命令处理结果=" + (noRtMwDealRes == null?"返回":(noRtMwDealRes?"不返回":"返回") + "\n") ; | 
 |  |  |       s += "是否返回中间件对命令处理结果=" + (noRtMwDealRes == null?"是":(noRtMwDealRes?"是":"否") + "\n") ; | 
 |  |  |       if(param != null){ | 
 |  |  |          s += "参数:" + param  ; | 
 |  |  |       } | 
 |  |  | 
 |  |  |    @SuppressWarnings("unused") | 
 |  |  |    public String toJson()throws Exception{ | 
 |  |  |       try{ | 
 |  |  |          return JSON.toJSONString(this) ; | 
 |  |  |          String json = JSON.toJSONString(this) ; | 
 |  |  |          return json ; | 
 |  |  |       }catch(Exception e){ | 
 |  |  |          throw new Exception(e.getMessage() , e ) ; | 
 |  |  |       } | 
 |  |  | 
 |  |  |    @SuppressWarnings("unused") | 
 |  |  |    public static Command jsonToObject(String json)throws Exception{ | 
 |  |  |       try{ | 
 |  |  |          return JSON.parseObject(json, Command.class) ; | 
 |  |  |          JSONObject jsonObject = JSON.parseObject(json); | 
 |  |  |          Command command = jsonObject.to(Command.class) ; | 
 |  |  |          //command.param = jsonObject.getObject("param", class); | 
 |  |  |          return command ; | 
 |  |  |       }catch(Exception e){ | 
 |  |  |          throw new Exception(e.getMessage() , e ) ; | 
 |  |  |       } | 
 |  |  | 
 |  |  |       this.rtuAddr = rtuAddr; | 
 |  |  |       return this ; | 
 |  |  |    } | 
 |  |  | 	 | 
 |  |  |  | 
 |  |  |    public String getRtuResultSendWebUrl() { | 
 |  |  |       return rtuResultSendWebUrl; | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |    public void setRtuResultSendWebUrl(String rtuResultSendWebUrl) { | 
 |  |  |       this.rtuResultSendWebUrl = rtuResultSendWebUrl; | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |    public String getProtocol() { | 
 |  |  |       return protocol; | 
 |  |  |    } |