|  |  |  | 
|---|
|  |  |  | import java.io.Serializable; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON ; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class Command implements Serializable{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | static { | 
|---|
|  |  |  | serialVersionUID = 201211292156L; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 当命令结果返回的网址是此值时,忽略执行,例如中间件主动下发的命令,就不用返回命令结果 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final String ignoreRtuResultSendWebUrl = "http://0.0.0.0" ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 默认命令ID | 
|---|
|  |  |  | 
|---|
|  |  |  | public String id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 水表协议名称,这个可以为空,因为水表上行数据解析出协议名称,然后系统把协议名称保存在水表数据记录中,从此协议名称就不再空了 | 
|---|
|  |  |  | * RTU协议名称,这个可以为空,因为RTU上行数据解析出协议名称,然后系统把协议名称保存在RTU数据记录中,从此协议名称就不再空了 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String protocol; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * 功能码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String code ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 不返回中间件对命令处理结果(true:不返回处理结果,false或null:返回处理结果) | 
|---|
|  |  |  | * rtu返回命令结果 发向目的地web URL | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Boolean noRtMwDealRes ; | 
|---|
|  |  |  | public String rtuResultSendWebUrl ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 具体参数数据 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 += (rtuResultSendWebUrl == null ? "" : ("回调网址=" + rtuResultSendWebUrl + "\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 ) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return this ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | public static void main(String[] args){ | 
|---|
|  |  |  | String json = "{\"attachment\":null,\"code\":\"03\",\"deviceId\":\"d8c9601f214747d98d47a4736e5\",\"id\":\"999999999\",\"meterNo\":\"23040600377\",\"productId\":16873252,\"param\":\"0002\",\"protocol\":\"HAC_NBhV2_5\",\"rtuAddr\":\"863318060168996\",\"type\":\"outerCommand\"}" ; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Command com = jsonToObject(json) ; | 
|---|
|  |  |  | System.out.println(com.param); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getId() { | 
|---|
|  |  |  | return id; | 
|---|
|  |  |  | 
|---|
|  |  |  | this.rtuAddr = rtuAddr; | 
|---|
|  |  |  | return this ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getRtuResultSendWebUrl() { | 
|---|
|  |  |  | return rtuResultSendWebUrl; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setRtuResultSendWebUrl(String rtuResultSendWebUrl) { | 
|---|
|  |  |  | this.rtuResultSendWebUrl = rtuResultSendWebUrl; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getProtocol() { | 
|---|
|  |  |  | return protocol; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | public Command setCode(String code) { | 
|---|
|  |  |  | this.code = code; | 
|---|
|  |  |  | return this ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | public Boolean getNoRtMwDealRes() { | 
|---|
|  |  |  | return noRtMwDealRes; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | public void setNoRtMwDealRes(Boolean noRtMwDealRes) { | 
|---|
|  |  |  | this.noRtMwDealRes = noRtMwDealRes; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public Object getParam() { | 
|---|
|  |  |  | return param; | 
|---|