| | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto; |
| | | import com.xiaopeng.api.feignClient.automaticPilot.XPUClient; |
| | | import com.xiaopeng.api.vo.automaticPilot.MqttPublishVo; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.*; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.OrderOperation; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.RTTask; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.OrderOperation; |
| | | import com.xiaopeng.common.core.utils.uuid.UUID; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 自动驾驶接口对接文档 |
| | |
| | | @Component |
| | | public class XPUUtil { |
| | | |
| | | /** |
| | | * 接口地址 |
| | | */ |
| | | @Value("${xpu.url}") |
| | | private String xpuUrl; |
| | | @Resource |
| | | private XPUClient xpuClient; |
| | | |
| | | |
| | | /** |
| | |
| | | * @param task |
| | | * @return |
| | | */ |
| | | public ResponseMessage cloudCreateOrder(RTTask task) { |
| | | public MqttPublishDto cloudCreateOrder(RTTask task, String vin) { |
| | | MsgContent msgContent = new MsgContent(); |
| | | // 消息头 |
| | | RtMsgHeader header = new RtMsgHeader(); |
| | |
| | | jsonObject.put("task", task); |
| | | msgContent.setContent_detail(jsonObject); |
| | | log.info("云端-->XPU 创建订单:{}", msgContent); |
| | | HttpRequest post = HttpUtil.createPost(""); |
| | | post.body(JSON.toJSONString(msgContent)); |
| | | HttpResponse execute = post.execute(); |
| | | int status = execute.getStatus(); |
| | | if (200 != status) { |
| | | throw new RuntimeException("XPU 接口异常:" + execute.getStatus()); |
| | | } |
| | | MsgContent resMsgContent = JSON.parseObject(execute.body(), MsgContent.class); |
| | | RtMsgHeader resHeader = resMsgContent.getHeader(); |
| | | int value = resHeader.getType().getValue(); |
| | | //只处理应答消息 |
| | | if (value == MessageType.MESSAGE_TYPE_RESPONSE.getValue()) { |
| | | JSONObject contentDetail = resMsgContent.getContent_detail(); |
| | | return contentDetail.getObject("response", ResponseMessage.class); |
| | | } |
| | | return null; |
| | | |
| | | //组装请求消息体 |
| | | MqttPublishVo vo = new MqttPublishVo(); |
| | | vo.setTopic("topic-prod-xpu-robotaxi-high/" + vin); |
| | | vo.setPayload(JSON.toJSONString(msgContent)); |
| | | return xpuClient.publish(vo); |
| | | } |
| | | |
| | | |
| | |
| | | * @param operation |
| | | * @return |
| | | */ |
| | | public ResponseMessage cloudOrderOperation(OrderOperation operation) { |
| | | public MqttPublishDto cloudOrderOperation(OrderOperation operation, String vin) { |
| | | MsgContent msgContent = new MsgContent(); |
| | | // 消息头 |
| | | RtMsgHeader header = new RtMsgHeader(); |
| | |
| | | jsonObject.put("operation", operation); |
| | | msgContent.setContent_detail(jsonObject); |
| | | log.info("云端-->XPU 操作订单:{}", msgContent); |
| | | HttpRequest post = HttpUtil.createPost(""); |
| | | post.body(JSON.toJSONString(msgContent)); |
| | | HttpResponse execute = post.execute(); |
| | | int status = execute.getStatus(); |
| | | if (200 != status) { |
| | | throw new RuntimeException("XPU 接口异常:" + execute.getStatus()); |
| | | } |
| | | MsgContent resMsgContent = JSON.parseObject(execute.body(), MsgContent.class); |
| | | RtMsgHeader resHeader = resMsgContent.getHeader(); |
| | | int value = resHeader.getType().getValue(); |
| | | //只处理应答消息 |
| | | if (value == MessageType.MESSAGE_TYPE_RESPONSE.getValue()) { |
| | | JSONObject contentDetail = resMsgContent.getContent_detail(); |
| | | return contentDetail.getObject("response", ResponseMessage.class); |
| | | } |
| | | return null; |
| | | //组装请求消息体 |
| | | MqttPublishVo vo = new MqttPublishVo(); |
| | | vo.setTopic("topic-prod-xpu-robotaxi-high/" + vin); |
| | | vo.setPayload(JSON.toJSONString(msgContent)); |
| | | return xpuClient.publish(vo); |
| | | } |
| | | |
| | | |
| | |
| | | * @param responseMessage |
| | | * @return |
| | | */ |
| | | public ResponseMessage responseMessage(ResponseMessage responseMessage) { |
| | | public MqttPublishDto responseMessage(ResponseMessage responseMessage, String vin) { |
| | | MsgContent msgContent = new MsgContent(); |
| | | // 消息头 |
| | | RtMsgHeader header = new RtMsgHeader(); |
| | |
| | | jsonObject.put("resposne", responseMessage); |
| | | msgContent.setContent_detail(jsonObject); |
| | | log.info("云端-->XPU 响应消息:{}", msgContent); |
| | | HttpRequest post = HttpUtil.createPost(""); |
| | | post.body(JSON.toJSONString(msgContent)); |
| | | HttpResponse execute = post.execute(); |
| | | int status = execute.getStatus(); |
| | | if (200 != status) { |
| | | throw new RuntimeException("XPU 接口异常:" + execute.getStatus()); |
| | | } |
| | | return null; |
| | | //组装请求消息体 |
| | | MqttPublishVo vo = new MqttPublishVo(); |
| | | vo.setTopic("topic-prod-xpu-robotaxi-high/" + vin); |
| | | vo.setPayload(JSON.toJSONString(msgContent)); |
| | | return xpuClient.publish(vo); |
| | | } |
| | | |
| | | } |