|  |  | 
 |  |  | package com.dy.pipIrrRemote.common; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSON; | 
 |  |  | import com.alibaba.fastjson2.JSONArray; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.dy.common.mw.protocol.Data; | 
 |  |  | import com.dy.common.webUtil.BaseResponse; | 
 |  |  | import com.dy.common.webUtil.BaseResponseUtils; | 
 |  |  | import com.dy.pipIrrGlobal.command.ComResultWait; | 
 |  |  | import com.dy.pipIrrGlobal.command.ComSupport; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.springframework.http.MediaType; | 
 |  |  | 
 |  |  | @RequestMapping(path="comRes") | 
 |  |  | public class CommandResultCtrl extends ComSupport { | 
 |  |  |     @PostMapping(path = "receive", consumes = MediaType.APPLICATION_JSON_VALUE) | 
 |  |  |     public BaseResponse<String> receive(@RequestBody Data data) { | 
 |  |  |         Long comId = 0L; | 
 |  |  |         if(data.getCommandId() != null) { | 
 |  |  |             comId = Long.parseLong(data.getCommandId()); | 
 |  |  |     public void receive(@RequestBody Data data) { | 
 |  |  |         JSONObject protocolData = data == null ? null : (JSONObject)data.subData ; //协议数据 | 
 |  |  |         Object codeDataObj = protocolData == null ? null : protocolData.get("subData") ; | 
 |  |  |         JSONObject codeData = null ; | 
 |  |  |         JSONArray codeArrayData = null ; | 
 |  |  |         if(codeDataObj != null){ | 
 |  |  |             if(codeDataObj instanceof JSONObject){ | 
 |  |  |                 codeData = protocolData == null ? null : (protocolData.getJSONObject("subData")) ; //协议功能码数据 | 
 |  |  |             }else if(codeDataObj instanceof JSONArray){ | 
 |  |  |                 codeArrayData = protocolData == null ? null : (protocolData.getJSONArray("subData")) ; //协议功能码数据 | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         JSONObject job_response = new JSONObject(); | 
 |  |  |         job_response.put("data", codeData!=null?codeData:(codeArrayData!=null?codeArrayData:null)); | 
 |  |  |         job_response.put("commandCode", data.code); | 
 |  |  |         job_response.put("commandId", data.commandId); | 
 |  |  |  | 
 |  |  |         CompletableFuture<Data> feature = (CompletableFuture<Data>) features.get(comId); | 
 |  |  |         CompletableFuture<JSONObject> feature = (CompletableFuture<JSONObject>) ComResultWait.get(Long.parseLong(data.commandId)); | 
 |  |  |         if(feature != null) { | 
 |  |  |             feature.complete(data); | 
 |  |  |             feature.complete(job_response); | 
 |  |  |         }else{ | 
 |  |  |             log.error("feature is null"); | 
 |  |  |             //超时,feature被清除了 | 
 |  |  |         } | 
 |  |  |         return BaseResponseUtils.buildSuccess("ok"); | 
 |  |  |     } | 
 |  |  | } |