| | |
| | | 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("任务中转站") |
| | |
| | | @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) { |
| | |
| | | } |
| | | //判断需要下发系统 |
| | | if (param.getSystemCode().equals(MissionSystemCodeEnum.MISSION_SYSTEM_CODE_ENUM_HK_RCS_YZ_5.type)){ |
| | | //转海康下发程序 |
| | | // R r = wmsWcsService.issueTaskWcs(param); |
| | | // if (!r.get("code").equals(200)){ |
| | | // return CommonResponse.error(""+r.get("msg")); |
| | | // } |
| | | 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); |
| | |
| | | return CommonResponse.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |