| | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto; |
| | | import com.xiaopeng.api.dto.automaticPilot.PushOrderDto; |
| | | import com.xiaopeng.api.dto.automaticPilot.VehicleEventDTO; |
| | | import com.xiaopeng.api.dto.map.OrderRouteAndFareDto; |
| | | import com.xiaopeng.api.dto.operation.LonLatDto; |
| | | import com.xiaopeng.api.dto.order.PopOrderDto; |
| | | import com.xiaopeng.api.dto.pushMessage.PushOrderRouteDTO; |
| | | import com.xiaopeng.api.dto.pushMessage.SendMessageDTO; |
| | | import com.xiaopeng.api.dto.vehicleConvoy.UpdateVehicleStateDto; |
| | | import com.xiaopeng.api.feignClient.automaticPilot.VehicleBuriedPointClient; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.feignClient.pushMessage.XpPushMessageClient; |
| | |
| | | import com.xiaopeng.api.vo.order.OrderTrajectoryVo; |
| | | import com.xiaopeng.automaticPilot.util.XPUUtil; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.enums.CancelOrderSceneEnum; |
| | | import com.xiaopeng.common.core.enums.OrderStatusEnum; |
| | | import com.xiaopeng.common.core.enums.PushMessageTypeEnum; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | |
| | | private RedisService redisService; |
| | | @Resource |
| | | private XpVehicleClient xpVehicleClient; |
| | | @Resource |
| | | private VehicleBuriedPointClient vehicleBuriedPointClient; |
| | | @Resource(name = "hutoolSnowflake") |
| | | private Snowflake snowflake; |
| | | |
| | |
| | | taskBuilder.setSequence(1); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_CRUISE); |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | }else{ |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.USER_ORDER)){ |
| | | //乘客单 |
| | | for (int i = 1; i < 3; i++) { |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_ORDER)){ |
| | | //测试单 |
| | | for (int i = 1; i < 3; i++) { |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); |
| | | if(i == 1){ |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(dto.getVin())), VehiclePosition.class); |
| | | //构建车辆当前位置数据 |
| | | 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(vehiclePosition.getPoint().getY()); |
| | | geoPointBuilder.setLongitude(vehiclePosition.getPoint().getX()); |
| | | 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(i); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_PICKUP); |
| | | }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.getStartLatitude()); |
| | | geoPointBuilder.setLongitude(dto.getStartLongitude()); |
| | | 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.getEndLongitude()); |
| | | pointBuilderEnd.setPoint(geoPointBuilder.build()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(i); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_CRUISE_ORDER)){ |
| | | //测试单巡游单 |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_CRUISE); |
| | | //构建起点坐标数据 |
| | | 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()); |
| | | 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.getEndLongitude()); |
| | | pointBuilderEnd.setPoint(geoPointBuilder.build()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(1); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_CRUISE); |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | |
| | | long sequence = snowflake.nextId(); |
| | | MqttPublishDto mqttPublishDto = xpuUtil.cloudCreateOrder(taskListBuilder.build(), dto.getVin(),sequence); |
| | | //先将车辆修改状态,防止在异步通知之前被其他订单选中 |
| | | if (!dto.getOrderId().contains("XU") && mqttPublishDto.getCode()== 200) { |
| | | if(!dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.CRUISE_ORDER) && |
| | | !dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_CRUISE_ORDER) |
| | | && 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("orderType", dto.getOrderType()); |
| | | jsonObject.put("orderId", dto.getOrderId()); |
| | | jsonObject.put("vin", dto.getVin()); |
| | | redisService.setCacheObject("CREATE_ORDER:" + dto.getOrderId().toString(), jsonObject.toJSONString(),30L, TimeUnit.MINUTES); |
| | |
| | | |
| | | @PostMapping("/inner/cancelOrder") |
| | | R<Boolean> cancelOrder(@RequestBody PushOrderDto dto) { |
| | | String taskId = StringUtils.isNotEmpty(dto.getTaskId()) ? dto.getTaskId() : snowflake.nextId() + ""; |
| | | OrderOperation.Builder operationBuilder = OrderOperation.newBuilder(); |
| | | operationBuilder.setOrderId(dto.getOrderId().toString()); |
| | | operationBuilder.setTaskId(snowflake.nextId() + ""); |
| | | operationBuilder.setTaskId(taskId); |
| | | if (dto.getOperation_type() != null) { |
| | | operationBuilder.setOperationType(OrderOperationType.forNumber(dto.getOperation_type().getNumber())); |
| | | } |
| | |
| | | |
| | | if (mqttPublishDto.getCode() == 200) { |
| | | if(!dto.getOrderId().contains("XU")){ |
| | | // 正常订单处理 |
| | | redisService.setCacheObject(String.valueOf(sequence), "cancelOrder_" + dto.getOrderId() + "_" + dto.getVin(), 30l, TimeUnit.MINUTES); |
| | | Map<String, Object> cancelContext = new HashMap<>(); |
| | | cancelContext.put("orderId", dto.getOrderId()); |
| | | cancelContext.put("vin", dto.getVin()); |
| | | cancelContext.put("cancelScene", StringUtils.isNotEmpty(dto.getCancelScene()) |
| | | ? dto.getCancelScene() |
| | | : CancelOrderSceneEnum.NORMAL_CANCEL.getCode()); |
| | | redisService.setCacheObject("CANCEL_ORDER_CONTEXT:" + taskId, |
| | | JSONObject.toJSONString(cancelContext), 30L, TimeUnit.MINUTES); |
| | | log.info("记录取消订单上下文成功,orderId: {}, vin: {}, taskId: {}, cancelScene: {}", |
| | | dto.getOrderId(), dto.getVin(), taskId, cancelContext.get("cancelScene")); |
| | | } |
| | | return R.ok(true); |
| | | } |
| | |
| | | Long appUserId = xpOrder.getAppUserId(); |
| | | Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId()); |
| | | RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | log.info("开始实施推送车辆位置和剩余导航线路 {} {}", xpOrder.getOrderNumber(), JSON.toJSONString(routeVo)); |
| | | |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000)); |
| | | Long finalOrderId = orderId; |
| | |
| | | |
| | | //5秒钟循环一次 |
| | | try { |
| | | Thread.sleep(500); |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |