|  |  |  | 
|---|
|  |  |  | private RestTemplate restTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询设备是否在线 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Boolean isOnLine4Rtu(String devId) { | 
|---|
|  |  |  | return selectOnOrOffLine4Rtu(devId) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询设备是否在线 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Boolean isOnLine4Mqtt(String devId) { | 
|---|
|  |  |  | return selectOnOrOffLine4Mqtt(devId) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取已经绑定控制器的取水口列表(并标记在线与不在线) | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询RTU在通信中间件中的在线状态 | 
|---|
|  |  |  | * 查询RTU在通信中间件中的状态 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询RTU在线或离线状态 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean selectOnOrOffLine4Rtu(String rtuAddr) { | 
|---|
|  |  |  | //向通信中间件发关命令,查询部分RTU在线情况 | 
|---|
|  |  |  | Command com = this.createInnerCommand(CodeLocal.onPartLineMqtt); | 
|---|
|  |  |  | com.setParam(rtuAddr) ; | 
|---|
|  |  |  | String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ; | 
|---|
|  |  |  | BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ; | 
|---|
|  |  |  | if(res != null){ | 
|---|
|  |  |  | if(res.isSuccess()){ | 
|---|
|  |  |  | Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ; | 
|---|
|  |  |  | CommandBackParam bakParam = JSON.parseObject((reCom== null || reCom.param == null) ? null : JSON.toJSONString(reCom.param), CommandBackParam.class) ; | 
|---|
|  |  |  | if(bakParam != null){ | 
|---|
|  |  |  | if(bakParam.getSuccess().booleanValue()){ | 
|---|
|  |  |  | //通信中间件成功返回命令结果 | 
|---|
|  |  |  | HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class); | 
|---|
|  |  |  | Boolean flag = onLineMap.get(rtuAddr); | 
|---|
|  |  |  | if(flag != null){ | 
|---|
|  |  |  | return flag ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("通信中间件返回内部命令结果中不包含CommandBackParam类型参数"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("通信中间件返回内部命令执行失败" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("通信中间件返回内部命令结果为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询MQTT在线或离线状态 | 
|---|
|  |  |  | * @param devId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean selectOnOrOffLine4Mqtt(String devId) { | 
|---|
|  |  |  | //向通信中间件发关命令,查询部分RTU在线情况 | 
|---|
|  |  |  | Command com = this.createInnerCommand(CodeLocal.onPartLineMqtt); | 
|---|
|  |  |  | com.setParam(devId) ; | 
|---|
|  |  |  | String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ; | 
|---|
|  |  |  | BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ; | 
|---|
|  |  |  | if(res != null){ | 
|---|
|  |  |  | if(res.isSuccess()){ | 
|---|
|  |  |  | Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ; | 
|---|
|  |  |  | CommandBackParam bakParam = JSON.parseObject((reCom== null || reCom.param == null) ? null : JSON.toJSONString(reCom.param), CommandBackParam.class) ; | 
|---|
|  |  |  | if(bakParam != null){ | 
|---|
|  |  |  | if(bakParam.getSuccess().booleanValue()){ | 
|---|
|  |  |  | //通信中间件成功返回命令结果 | 
|---|
|  |  |  | HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class); | 
|---|
|  |  |  | Boolean flag = onLineMap.get(devId); | 
|---|
|  |  |  | if(flag != null){ | 
|---|
|  |  |  | return flag ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("通信中间件返回内部命令结果中不包含CommandBackParam类型参数"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("通信中间件返回内部命令执行失败" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("通信中间件返回内部命令结果为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询取水口,在线或离线状态 | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|