1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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<JSONObject> feature = (CompletableFuture<JSONObject>) ComResultWait.get(Long.parseLong(data.commandId));
        if(feature != null) {
            feature.complete(job_response);
        }else{
            //超时,feature被清除了
        }
    }
}