xp-robotaxi-api/src/main/java/com/xiaopeng/api/vo/SystemEventType.java
@@ -8,5 +8,10 @@ /** * 推送导航 */ String CREATE_ORDER = "create_order"; /** * 推送导航 */ String PUSH_NAVIGATION = "push_navigation"; } xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java
@@ -17,6 +17,7 @@ import com.xiaopeng.api.feignClient.pushMessage.XpPushMessageClient; import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; import com.xiaopeng.api.model.order.XpOrder;import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; import com.xiaopeng.api.vo.SystemEventType; import com.xiaopeng.api.vo.automaticPilot.VehiclePosition; import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.RTTask; import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.TaskStatus; @@ -65,7 +66,7 @@ @PostMapping("/inner/pushOrder") public R<Boolean> pushOrder(@RequestBody PushOrderDto dto) { RtTask.Builder taskBuilder = RtTask.newBuilder(); //TODO 设置目标地点信息 taskBuilder.setOrderId(dto.getOrderId().toString()); taskBuilder.setTaskId("MISSION_"+ IdUtil.fastUUID()); @@ -75,44 +76,82 @@ taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); } //构建点位信息 Waypoint.Builder pointBuilder = Waypoint.newBuilder(); Waypoint.Builder pointBuilderStart = Waypoint.newBuilder(); Waypoint.Builder pointBuilderEnd = Waypoint.newBuilder(); //巡游订单 if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.CRUISE_ORDER)){ pointBuilder.setPointType(PointType.CRUISE_END_POINT); pointBuilder.setSequence(1); //构建终点坐标 GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getEndLatitude()); geoPointBuilder.setLongitude(dto.getEndLatitude()); // geoPointBuilder.setPoiName("Start Point"); // GeoPoint might not have poi_name pointBuilder.setPoint(geoPointBuilder.build()); }else{ //用户订单 if(dto.getStage() == 1){ //开往上车点 pointBuilder.setPointType(PointType.START_POINT); pointBuilder.setActionType(ActionType.PICK_UP); pointBuilder.setSequence(1); //构建起点坐标 //构建起点坐标数据 pointBuilderStart.setWaypointId(dto.getOrderId() + "-001"); pointBuilderStart.setPointType(PointType.START_POINT); pointBuilderStart.setSequence(1); pointBuilderStart.setActionType(ActionType.ACTION_UNSPECIFIED); GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getStartLatitude()); geoPointBuilder.setLongitude(dto.getStartLongitude()); // geoPointBuilder.setPoiName("Start Point"); // GeoPoint might not have poi_name pointBuilder.setPoint(geoPointBuilder.build()); pointBuilderStart.setPoint(geoPointBuilder.build()); taskBuilder.addPoints(pointBuilderStart); //构建终点数据 pointBuilderEnd.setWaypointId(dto.getOrderId() + "-002"); pointBuilderEnd.setPointType(PointType.CRUISE_END_POINT); pointBuilderEnd.setSequence(2); pointBuilderEnd.setActionType(ActionType.DRIVE_THROUGH); geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getEndLatitude()); geoPointBuilder.setLongitude(dto.getEndLatitude()); pointBuilderEnd.setPoint(geoPointBuilder.build()); taskBuilder.addPoints(pointBuilderEnd); taskBuilder.setSequence(1); }else{ //开往终点 pointBuilder.setPointType(PointType.END_POINT); pointBuilder.setActionType(ActionType.PICK_UP); pointBuilder.setSequence(1); //构建起点坐标 //用户订单 if(dto.getStage() == 1){ //构建车辆当前位置数据 pointBuilderStart.setWaypointId(dto.getOrderId() + "-JJ-001"); pointBuilderStart.setPointType(PointType.START_POINT); pointBuilderStart.setActionType(ActionType.ACTION_UNSPECIFIED); pointBuilderStart.setSequence(1); GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getStartLatitude()); geoPointBuilder.setLongitude(dto.getStartLongitude()); pointBuilderStart.setPoint(geoPointBuilder.build()); taskBuilder.addPoints(pointBuilderStart); //构建上车点位置信息 pointBuilderEnd.setWaypointId(dto.getOrderId() + "-JJ-002"); pointBuilderEnd.setPointType(PointType.PICK_UP_POINT); pointBuilderEnd.setActionType(ActionType.PICK_UP); pointBuilderEnd.setSequence(2); geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getStartLatitude()); geoPointBuilder.setLongitude(dto.getStartLongitude()); pointBuilderEnd.setPoint(geoPointBuilder.build()); taskBuilder.addPoints(pointBuilderEnd); taskBuilder.setSequence(1); }else{ //构建上车点位置信息 pointBuilderStart.setWaypointId(dto.getOrderId() + "-SD-001"); pointBuilderStart.setPointType(PointType.PICK_UP_POINT); pointBuilderStart.setActionType(ActionType.PICK_UP); pointBuilderStart.setSequence(1); GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getEndLatitude()); geoPointBuilder.setLongitude(dto.getEndLatitude()); // geoPointBuilder.setPoiName("Start Point"); // GeoPoint might not have poi_name pointBuilder.setPoint(geoPointBuilder.build()); pointBuilderStart.setPoint(geoPointBuilder.build()); taskBuilder.addPoints(pointBuilderStart); //构建下车点位置信息 pointBuilderEnd.setWaypointId(dto.getOrderId() + "-SD-002"); pointBuilderEnd.setPointType(PointType.END_POINT); pointBuilderEnd.setActionType(ActionType.DROP_OFF); pointBuilderEnd.setSequence(2); geoPointBuilder = GeoPoint.newBuilder(); geoPointBuilder.setLatitude(dto.getEndLatitude()); geoPointBuilder.setLongitude(dto.getEndLatitude()); pointBuilderEnd.setPoint(geoPointBuilder.build()); taskBuilder.addPoints(pointBuilderEnd); taskBuilder.setSequence(2); } } taskBuilder.addPoints(pointBuilder); RtTaskList.Builder taskListBuilder = RtTaskList.newBuilder(); taskListBuilder.addTasks(taskBuilder.build()); @@ -120,11 +159,13 @@ snowFlake.withStartTimestamp(1420041600000L); long sequence = snowFlake.nextId(); MqttPublishDto mqttPublishDto = xpuUtil.cloudCreateOrder(taskListBuilder.build(), dto.getVin(),sequence); // 正常单子才修改 巡游单子不修改状态 if (!dto.getOrderId().contains("XU") && mqttPublishDto.getCode()== 200) { // 修改车子为接单状态 xpVehicleClient.updateVehicleStatus(new UpdateVehicleStateDto(dto.getVin(),1)); if(null != mqttPublishDto && mqttPublishDto.getCode() == 200){ JSONObject jsonObject = new JSONObject(); jsonObject.put("event", SystemEventType.CREATE_ORDER); jsonObject.put("orderType", dto.getOrderId().contains("XU") ? com.xiaopeng.api.vo.OrderType.CRUISE_ORDER : com.xiaopeng.api.vo.OrderType.USER_ORDER); jsonObject.put("orderId", dto.getOrderId()); jsonObject.put("vin", dto.getVin()); redisTemplate.opsForValue().set("CREATE_ORDER:" + dto.getOrderId().toString(), jsonObject.toJSONString(),30, TimeUnit.MINUTES); return R.ok(true); } return R.ok(false); @@ -136,7 +177,7 @@ operationBuilder.setOrderId(dto.getOrderId().toString()); operationBuilder.setTaskId("CANCEL_MISSION_" + IdUtil.fastUUID()); if (dto.getOperation_type() != null) { operationBuilder.setOperationType(OrderOperationType.forNumber(dto.getOperation_type().getValue())); operationBuilder.setOperationType(OrderOperationType.forNumber(dto.getOperation_type().getNumber())); } SnowFlake snowFlake = new SnowFlake(0, 0); xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/service/KafkaConsumerService.java
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.util.JsonFormat; import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto; import com.xiaopeng.api.dto.map.OrderRouteAndFareDto; import com.xiaopeng.api.dto.operation.CruisePointDto; import com.xiaopeng.api.dto.operation.LonLatDto; @@ -242,40 +243,30 @@ log.warn("Unknown cmd value: {}", cmdValue); return; } //云端下发订单的响应报文 if (cmd == RTCmdType.CLOUD_SEND_RT_TASK) { RtTaskListResponse response = msgContent.getRtTaskListResponse(); try { log.info("云端下发订单操作的响应消息 (XPU→云端):{}", jsonPrinter.print(response)); Object sequence = redisTemplate.opsForValue().get("CREATE_ORDER:" + response.getResults().getOrderId()); if(sequence!=null){ JSONObject jsonObject = JSON.parseObject(sequence.toString()); String orderId = jsonObject.getString("orderId"); String vin = jsonObject.getString("vin"); String orderType = jsonObject.getString("orderType"); PopOrderDto dto = new PopOrderDto(); dto.setOrderId(Long.valueOf(orderId)); dto.setXpVehicleVin(vin); dto.setOrderType(orderType); xpOrderClient.popOrder(dto); log.info("订单状态更新:{}", response.getResults().getOrderId()); } } catch (InvalidProtocolBufferException e) { log.error("Failed to print RtTaskListResponse: {}", response, e); } } else { log.info("响应消息不在处理范围内,忽略:{}", message); } // ResponseMessage response = msgContent.getResponse(); // StatusCode code = response.getCode(); // long requestSeq = response.getRequestSeq(); // if(code == StatusCode.OK){ // log.info("收到XPU消息的响应,code: {}, message: {}", code.getNumber(), message); // Object sequence = redisTemplate.opsForValue().get(requestSeq); // if(sequence!=null){ // log.info("收到XPU消息的响应,sequence: {}", sequence); // JSONObject jsonObject = JSON.parseObject(sequence.toString()); // String event = jsonObject.getString("event"); // //推送导航的响应消息 // if(SystemEventType.PUSH_NAVIGATION.equals(event)){ // log.info("推送导航的响应消息,{}", jsonObject.toJSONString()); // String orderId = jsonObject.getString("orderId"); // String vin = jsonObject.getString("vin"); // String orderType = jsonObject.getString("orderType"); // PopOrderDto dto = new PopOrderDto(); // dto.setOrderId(Long.valueOf(orderId)); // dto.setXpVehicleVin(vin); // dto.setOrderType(orderType); // xpOrderClient.popOrder(dto); // } // } // } } } @@ -557,16 +548,17 @@ vehicleId = xpOrder.getVehicleId(); } if(StringUtils.isNotEmpty(routeID)){ XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); R<String> stringR = xpMapClient.queryRouted(routeID); if (200 != stringR.getCode()) { throw new RuntimeException("根据导航ID获取车端需要的导航数据失败"); } //TODO 这里的逻辑不太对,收到导航偏航事件之后 //构建导航下发请求对象 cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId()); } // TODO 在请求导航哪里返回导航数据 // if(StringUtils.isNotEmpty(routeID)){ // XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); // R<String> stringR = xpMapClient.queryRouted(routeID); // if (200 != stringR.getCode()) { // throw new RuntimeException("根据导航ID获取车端需要的导航数据失败"); // } // //TODO 这里的逻辑不太对,收到导航偏航事件之后 // //构建响应导航数据给车端 // cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId()); // } // } } @@ -586,12 +578,9 @@ Long vehicleId = null; String orderType = ""; if (orderId.contains("XU")) { orderType = OrderType.CRUISE_ORDER; //巡游单 if (orderPhase.equals(OrderPhase.ROUTE_TO_CRUISE)) { //先响应消息 responseMessage(sequence, ""); /* 构建导航数据给到车端 */ R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(orderId); XpCruiseOrder xpCruiseOrder = cruiseOrder.getData(); @@ -624,8 +613,6 @@ } XpOrder xpOrder = xpOrderR.getData(); XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData(); //先响应消息 responseMessage(sequence, xpVehicle.getVehicleVin()); //驶往上车点的行程 if (orderPhase.equals(OrderPhase.ROUTE_TO_PICKUP)) { //查询车辆位置 @@ -1047,7 +1034,8 @@ jsonObject.put("orderId", orderId); jsonObject.put("vin", vin); redisTemplate.opsForValue().set(sequence, jsonObject.toJSONString(),30, TimeUnit.MINUTES); xpuUtil.cloudPushNavigation(navigationDataBuilder.build(), xpuId, sequence); MqttPublishDto mqttPublishDto = xpuUtil.cloudPushNavigation(navigationDataBuilder.build(), xpuId, sequence); log.info("推送导航的响应消息,{}", JSON.toJSONString(mqttPublishDto)); } } xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java
@@ -143,7 +143,6 @@ headerBuilder.setType(MessageType.MESSAGE_TYPE_RESPONSE); headerBuilder.setSource(SourceType.CLOUD); msgContentBuilder.setHeader(headerBuilder.build()); msgContentBuilder.setRestoreNavigationData(navigationData); MqttPublishVo vo = new MqttPublishVo(); vo.setTopic(buildTopicByXpuId(xpuId)); xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/utils/TaskOrderUtil.java
@@ -246,7 +246,6 @@ // 根据距离找车 // 车多则根据配置找具体车数量 根据距离最近 // 更改 暂不限制数量 List<VehiclePosition> positionList = vehiclePositionService.findAvailableVehiclesNearby(Double.parseDouble(split[0]), Double.parseDouble(split[1]), pushDistance, xpTradingStrategy.getSimultaneouslyOrderCount()); log.info("根据距离找车 {} 距离 {}KM 经度 {} 维度 {} 查找结果 {} 单号 {}", orderNo, pushDistance, split[0], split[1], positionList, orderNo); // 获取车辆的区域信息 @@ -769,7 +768,7 @@ } // 关闭巡游单子 R<String> stringR = xpCruiseOrderClient.updateCruiseOrder(vehiclePosition.getVehicleVin()); if(stringR ==null || stringR.getData()==null){ if(stringR ==null || stringR.getCode() != 200){ log.info("关闭巡游单子失败 车牌号 {}", vehiclePosition.getPlateNumber()); continue; } @@ -785,7 +784,7 @@ pushOrderDto.setOrderType(OrderType.USER_ORDER); pushOrderDto.setStage(1); // 调用推送服务 orderId + carVin // orderMissionClient.pushOrder(pushOrderDto); orderMissionClient.pushOrder(pushOrderDto); log.info("开始推送 {} 订单到XPU。单号 {}", xpOrder.getOrderNumber(), orderNo); redisService.popFirstElement(quoteName); @@ -818,7 +817,7 @@ } // 关闭巡游单子 R<String> stringR = xpCruiseOrderClient.updateCruiseOrder(vehicleId1.getVehicleVin()); if(stringR ==null || stringR.getData()==null){ if(stringR ==null || stringR.getCode() != 200){ log.info("关闭巡游单子失败 车牌号 {}", vehicleId1.getPlateNumber()); continue; } @@ -833,8 +832,8 @@ pushOrderDto.setOrderType(OrderType.USER_ORDER); pushOrderDto.setStage(1); // 调用推送服务 orderId + carVin // orderMissionClient.pushOrder(pushOrderDto); log.info("开始推送 {} 订单到XPU。单号 {}", xpOrder.getOrderNumber(), orderNo); orderMissionClient.pushOrder(pushOrderDto); log.info("开始推送 {} 订单到XPU", xpOrder.getOrderNumber()); redisService.popFirstElement(quoteName); log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName); return;