cl
17 小时以前 3b41ed73cd464ae2bad44598e6f0b522fc50e886
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.vincent.rsf.openApi.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
import com.vincent.rsf.openApi.entity.params.MissionTaskIssueParam;
import com.vincent.rsf.openApi.entity.params.RCSTaskSubmitRequest;
import com.vincent.rsf.openApi.enums.MissionSystemCodeEnum;
import com.vincent.rsf.openApi.service.WmsWcsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
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 org.springframework.web.client.RestTemplate;
 
@RestController
@Api("任务中转站")
@Slf4j
@RequestMapping("/mission")
public class MissionTransferStationController {
 
    @Autowired
    private WmsWcsService wmsWcsService;
 
    private final RestTemplate restTemplate = new RestTemplate();
 
    @Value("${platform.hk.host}")
    private String hkHost;
    @Value("${platform.hk.port}")
    private String hkPort;
 
    @ApiOperation("任务总控")
    @PostMapping("/task/master/control")
    public CommonResponse missionMasterControl(@RequestBody MissionTaskIssueParam param) {
        try{
            if (Cools.isEmpty(param)){
                return CommonResponse.error("参数为空!!!");
            }
            //判断需要下发系统
            if (param.getSystemCode().equals(MissionSystemCodeEnum.MISSION_SYSTEM_CODE_ENUM_HK_RCS_YZ_5.type)){
                HttpHeaders headers = new HttpHeaders();
                headers.setContentType(MediaType.APPLICATION_JSON);
                String url = hkHost + ":" + hkPort + "/rcs/rtas/api/robot/controller/task/submit";
                RCSTaskSubmitRequest body = new RCSTaskSubmitRequest(param);
                String reqJson = body.toJSONObject();
                try {
                    HttpEntity<RCSTaskSubmitRequest> entity = new HttpEntity<>(body, headers);
                    String resp = restTemplate.postForObject(url, entity, String.class);
                    JSONObject respJson = (resp != null && !resp.isEmpty()) ? JSON.parseObject(resp) : null;
                    log.info("url:{}, 请求参数:{}, 返回:{}", url, reqJson, respJson);
                    /* 海康返回例子:
                     {
 
                        "code": "SUCCESS",
                            "message": "成功",
                            "data": {
                        "robotTaskCode": "13123123123",
                                "extra": null
                    }
                    }*/
                    if (respJson != null && "SUCCESS".equals(respJson.getString("code"))){
                        return CommonResponse.ok(respJson.getJSONObject("data"));
                    }
                    String msg = respJson != null ? respJson.getString("message") : "RCS返回异常";
                    return CommonResponse.error(msg != null ? msg : "RCS返回异常");
                } catch (Exception e) {
                    log.error("RCS任务下发请求异常, url:{}, {}", url, e.getMessage(), e);
                    return CommonResponse.error("RCS服务访问异常: " + e.getMessage());
                }
            } else if (param.getSystemCode().equals(MissionSystemCodeEnum.MISSION_SYSTEM_CODE_ENUM_ZY_WCS_TWO.type)){
                //转wcs下发程序
                R r = wmsWcsService.issueTaskWcs(param);
                if (!r.get("code").equals(200)){
                    return CommonResponse.error(""+r.get("msg"));
                }
            } else if (param.getSystemCode().equals(MissionSystemCodeEnum.MISSION_SYSTEM_CODE_ENUM_WEIGHING_YZ_5.type)){
                //转称重
//                R r = wmsWcsService.issueTaskWcs(param);
//                if (!r.get("code").equals(200)){
//                    return CommonResponse.error(""+r.get("msg"));
//                }
            } else {
                return CommonResponse.error("未知系统类型");
            }
            //判断下发方式
            //返回结果
            return CommonResponse.ok();
        } catch (Exception e){
            return CommonResponse.error(e.getMessage());
        }
    }
 
}