|  |  | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.dy.common.mw.protocol.Command; | 
 |  |  | import com.dy.common.mw.protocol4Mqtt.MqttSubMsg; | 
 |  |  | import com.dy.common.util.Callback; | 
 |  |  | import com.dy.common.util.IDLongGenerator; | 
 |  |  | import com.dy.common.webUtil.BaseResponse; | 
 |  |  | 
 |  |  |     @Value("${mw.waitMwRtnResultTimeout}") | 
 |  |  |     protected int waitMwRtnResultTimeout ; | 
 |  |  |  | 
 |  |  |     @Value("${mw.rtuCallbackUrl_rm}") | 
 |  |  |     protected String rtuResultSendWebUrl; | 
 |  |  |     @Value("${mw.mqttCallbackUrl_rm}") | 
 |  |  |     protected String mqttResultSendWebUrl; | 
 |  |  |  | 
 |  |  |     //水肥机对象 | 
 |  |  |     protected PrStManure ctrlPo ; | 
 |  |  |     //异步等待器 | 
 |  |  |     protected CompletableFuture<JSONObject> feature; | 
 |  |  |     protected CompletableFuture<MqttSubMsg> feature; | 
 |  |  |     //命令名称 | 
 |  |  |     protected String comName ; | 
 |  |  |     //命令日志id | 
 |  |  | 
 |  |  |     public BaseResponse<Object> after(String comCode, Callback callback) { | 
 |  |  |         try{ | 
 |  |  |             //等待通信中间件通知水肥机执行命令上行数据(命令结果) | 
 |  |  |             JSONObject resultData = feature.get(waitMwRtnResultTimeout, TimeUnit.SECONDS); | 
 |  |  |             return BaseResponseUtils.buildSuccess(this.dealComResult(comCode, resultData, callback)); | 
 |  |  |             MqttSubMsg subMsg = feature.get(waitMwRtnResultTimeout, TimeUnit.SECONDS); | 
 |  |  |             return BaseResponseUtils.buildSuccess(this.dealComResult(comCode, subMsg, callback)); | 
 |  |  |         }catch (Exception e){ | 
 |  |  |             return BaseResponseUtils.buildFail("等待通信中间件通知命令结果超时"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |     /** | 
 |  |  |      * 生成命令返回信息 | 
 |  |  |      */ | 
 |  |  |     protected abstract String dealComResult(String code, JSONObject resultData, Callback callback); | 
 |  |  |     protected abstract String dealComResult(String code, MqttSubMsg subMsg, Callback callback); | 
 |  |  | } |