package com.dy.pipIrrRemote.common; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.dy.common.mw.protocol.Data; import com.dy.pipIrrGlobal.command.ComResultWait; import com.dy.pipIrrGlobal.command.ComSupport; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.CompletableFuture; /** * @author ZhuBaoMin * @date 2024-05-23 8:19 * @LastEditTime 2024-05-23 8:19 * @Description */ @Slf4j @RestController @RequestMapping(path="comRes") public class CommandResultCtrl extends ComSupport { @PostMapping(path = "receive", consumes = MediaType.APPLICATION_JSON_VALUE) public void receive(@RequestBody Data data) { JSONObject protocolData = data == null ? null : (JSONObject)data.subData ; //协议数据 JSONObject codeData = protocolData == null ? null : (protocolData.getJSONObject("subData")) ; //协议功能码数据 JSONObject job_response = new JSONObject(); job_response.put("data", codeData==null?protocolData:codeData); job_response.put("commandCode", data.code); job_response.put("commandId", data.commandId); CompletableFuture feature = (CompletableFuture) ComResultWait.get(Long.parseLong(data.commandId)); if(feature != null) { feature.complete(job_response); }else{ //超时,feature被清除了 } } }