| | |
| | | package com.xiaopeng.automaticPilot.service; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.google.protobuf.InvalidProtocolBufferException; |
| | |
| | | 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.feignClient.account.XpOperationUserClient; |
| | | import com.xiaopeng.api.feignClient.account.XpOperationUserNotificationClient; |
| | | import com.xiaopeng.api.feignClient.maintenance.XpTaskClient; |
| | | import com.xiaopeng.api.feignClient.maintenance.XpTaskRuleClient; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | import com.xiaopeng.api.feignClient.operation.ReassignOrderClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpCruisePlanClient; |
| | |
| | | import com.xiaopeng.api.feignClient.order.XpOrderClient; |
| | | import com.xiaopeng.api.feignClient.pushMessage.XpPushMessageClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.UserVehicleClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetOperationsClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetVehicleClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpVehicleClient; |
| | | import com.xiaopeng.api.model.order.XpCruiseOrder; |
| | | import com.xiaopeng.api.model.order.XpOrder; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleet; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | | import com.xiaopeng.api.vo.OrderType; |
| | | import com.xiaopeng.api.vo.SystemEventType; |
| | | import com.xiaopeng.api.vo.automaticPilot.VehiclePosition; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.*; |
| | | import com.xiaopeng.api.vo.operation.RouteVo; |
| | |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.enums.OrderStatusEnum; |
| | | import com.xiaopeng.common.core.enums.PushMessageTypeEnum; |
| | | import com.xiaopeng.common.core.utils.SnowFlake; |
| | | import com.xiaopeng.common.core.utils.StringUtils; |
| | | import com.xiaopeng.common.core.utils.uuid.UUID; |
| | | import com.xiaopeng.common.redis.service.RedisService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.data.mongodb.core.query.UpdateDefinition; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private XpCruisePlanClient xpCruisePlanClient; |
| | | |
| | | @Resource |
| | | private Snowflake snowflake; |
| | | |
| | | @Value("${robotaxi.appId:xp_robotaxi_api}") |
| | | private String appid; |
| | | |
| | | @Resource |
| | | private XpTaskClient xpTaskClient; |
| | | |
| | | private static final com.google.protobuf.util.JsonFormat.Printer jsonPrinter = com.google.protobuf.util.JsonFormat.printer() |
| | | .printingEnumsAsInts() |
| | |
| | | int value = gearLevel.getNumber(); |
| | | redisService.setCacheObject(CacheConstants.GEAR_LEVEL + systemRuntimeStatus.getVehicleStatus().getStaticInfo().getXpuId(), value); |
| | | // 判断是否为故障状态 |
| | | XpVehicle vehicle = null; |
| | | if (abnormalReason == AbnormalReason.FAULT) { |
| | | log.info("车辆故障,开始处理故障"); |
| | | // TODO 添加异常任务 |
| | | // 解绑用户与车辆关系 |
| | | CancelTaxiPassengerVo cancelTaxiPassengerVo = new CancelTaxiPassengerVo(); |
| | | String orderId = systemRuntimeStatus.getRunningOrderStatusInfo().getOrderId(); |
| | | XpOrder xpOrder = xpOrderClient.queryOrderById(Long.parseLong(orderId)).getData(); |
| | | XpVehicle vehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData(); |
| | | if(!orderId.contains("XU")){ |
| | | //巡游订单,需要关闭订单 |
| | | xpCruiseOrderClient.updateCruiseOrderId(Long.parseLong(orderId.substring(2))); |
| | | XpCruiseOrder cruiseOrder = xpCruiseOrderClient.getCruiseOrder(Long.parseLong(orderId.substring(2))).getData(); |
| | | vehicle = xpVehicleClient.queryById(cruiseOrder.getVehicleId()).getData(); |
| | | if (vehicle != null) { |
| | | // 修改车辆状态 |
| | | vehicle.setOperatingStatus(4); |
| | | xpVehicleClient.updateVehicleById(vehicle); |
| | | } |
| | | }else{ |
| | | //正常订单 |
| | | XpOrder xpOrder = xpOrderClient.queryOrderById(Long.parseLong(orderId)).getData(); |
| | | vehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData(); |
| | | if (vehicle != null) { |
| | | // 修改车辆状态 |
| | | vehicle.setState(0); |
| | | vehicle.setOperatingStatus(4); |
| | | xpVehicleClient.updateVehicleById(vehicle); |
| | | // 解绑用户与车辆关系 |
| | | CancelTaxiPassengerVo cancelTaxiPassengerVo = new CancelTaxiPassengerVo(); |
| | | cancelTaxiPassengerVo.setVin(vehicle.getVehicleVin()); |
| | | cancelTaxiPassengerVo.setUid(xpOrder.getAppUserId().toString()); |
| | | cancelTaxiPassengerVo.setOrderNo(xpOrder.getOrderNumber()); |
| | | cancelTaxiPassengerVo.setAppId(appid); |
| | | userVehicleClient.cancelTaxiPassenger(cancelTaxiPassengerVo); |
| | | } |
| | | // TODO 重新派单 |
| | |
| | | reassignOrderDTO.setLongitude(longitude); |
| | | reassignOrderDTO.setLatitude(latitude); |
| | | reassignOrderClient.reassignOrder(reassignOrderDTO); |
| | | } |
| | | //添加车辆异常任务和发送消息 |
| | | xpTaskClient.saveVehicleAccidentError(vehicle.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | if (orderId.contains("XU")) { |
| | | // orderType = OrderType.CRUISE_ORDER; |
| | | |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(orderId); |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(Long.parseLong(orderId.substring(2))); |
| | | XpCruiseOrder xpCruiseOrder = cruiseOrder.getData(); |
| | | |
| | | //先响应消息 |
| | |
| | | //巡游单 |
| | | if (orderPhase.equals(OrderPhase.ROUTE_TO_CRUISE)) { |
| | | /* 构建导航数据给到车端 */ |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(orderId); |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(Long.parseLong(orderId.substring(2))); |
| | | XpCruiseOrder xpCruiseOrder = cruiseOrder.getData(); |
| | | |
| | | origin.setLongitude(xpCruiseOrder.getStartLon()); |
| | |
| | | |
| | | } |
| | | orderOperationBuilder.addAllWaypoints(waypoints); |
| | | SnowFlake snowFlake = new SnowFlake(0, 0); |
| | | snowFlake.withStartTimestamp(1420041600000L); |
| | | long sequence = snowFlake.nextId(); |
| | | long sequence = snowflake.nextId(); |
| | | // 处理数据 |
| | | redisService.setCacheObject(sequence + "","pushOrder_"+orderId+"_"+vin,30L, TimeUnit.MINUTES); |
| | | //开发发送请求到XPU |
| | |
| | | |
| | | // 返程找到目前的订单 -》之前的订单 查询生成一个 正常巡游 找到下一个点位 若到达最后点位 则反向找点位 每次判断是否收车状态 是则不进行处理了 |
| | | // 找到这个订单 |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(orderId); |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(Long.parseLong(orderId.substring(2))); |
| | | if(cruiseOrder!=null){ |
| | | XpCruiseOrder xpCruiseOrder = cruiseOrder.getData(); |
| | | Long vehicleId = xpCruiseOrder.getVehicleId(); |
| | |
| | | XpCruiseOrder lastXpCruiseOrder = lastOrder.getData(); |
| | | |
| | | // 修改一下id 加一个一样的巡游单子 |
| | | lastXpCruiseOrder.setId("XU"+ IdUtil.fastUUID()); |
| | | lastXpCruiseOrder.setId(null); |
| | | lastXpCruiseOrder.setStatus(1); |
| | | xpCruiseOrderClient.addCruiseOrder(lastXpCruiseOrder); |
| | | //构建下发XPU订单报文数据 |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(lastXpCruiseOrder.getId()); |
| | | taskBuilder.setTaskId("MISSION_"+ IdUtil.fastUUID()); |
| | | taskBuilder.setOrderId("XU" + lastXpCruiseOrder.getId()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(com.xiaopeng.api.vo.automaticPilot.protobuf.OrderType.ORDER_TYPE_CRUISE); |
| | | //构建点位信息 |
| | | Waypoint.Builder pointBuilder = Waypoint.newBuilder(); |
| | |
| | | RtTask task = taskBuilder.build(); |
| | | RtTaskList taskList = RtTaskList.newBuilder().addTasks(task).build(); |
| | | |
| | | SnowFlake snowFlake = new SnowFlake(0, 0); |
| | | snowFlake.withStartTimestamp(1420041600000L); |
| | | long sequence1 = snowFlake.nextId(); |
| | | long sequence1 = snowflake.nextId(); |
| | | xpuUtil.cloudCreateOrder(taskList, xpVehicle.getVehicleVin(),sequence1); |
| | | }else if(xpCruiseOrder.getOrderType()==1){ |
| | | // 正常巡游 找到下一个点位 若到达最后点位 则反向找点位 |
| | |
| | | Double endLon = xpCruiseOrder.getEndLon(); |
| | | Double endLat = xpCruiseOrder.getEndLat(); |
| | | XpCruiseOrder newXpCruiseOrder = new XpCruiseOrder(); |
| | | newXpCruiseOrder.setId("XU"+ IdUtil.fastUUID()); |
| | | newXpCruiseOrder.setVehicleId(xpCruiseOrder.getVehicleId()); |
| | | newXpCruiseOrder.setVehicleVin(xpCruiseOrder.getVehicleVin()); |
| | | newXpCruiseOrder.setFleetId(xpCruiseOrder.getFleetId()); |
| | |
| | | xpCruiseOrderClient.addCruiseOrder(cruisePoint.getData()); |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | |
| | | taskBuilder.setOrderId(newXpCruiseOrder.getId()); |
| | | taskBuilder.setTaskId("MISSION_"+ IdUtil.fastUUID()); |
| | | taskBuilder.setOrderId("XU" + newXpCruiseOrder.getId()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(com.xiaopeng.api.vo.automaticPilot.protobuf.OrderType.ORDER_TYPE_CRUISE); |
| | | |
| | | //构建点位信息 |
| | |
| | | RtTaskList.Builder taskListBuilder = RtTaskList.newBuilder(); |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | |
| | | SnowFlake snowFlake = new SnowFlake(0, 0); |
| | | snowFlake.withStartTimestamp(1420041600000L); |
| | | long sequence1 = snowFlake.nextId(); |
| | | long sequence1 = snowflake.nextId(); |
| | | xpuUtil.cloudCreateOrder(taskListBuilder.build(), xpVehicle.getVehicleVin(),sequence1); |
| | | } |
| | | } |
| | |
| | | navigationDataBuilder.setRequestId(requestId); |
| | | navigationDataBuilder.setContent(routeDataContent); |
| | | navigationDataBuilder.setTimestamp(System.currentTimeMillis()); |
| | | SnowFlake snowFlake = new SnowFlake(0, 0); |
| | | snowFlake.withStartTimestamp(1420041600000L); |
| | | long sequence = snowFlake.nextId(); |
| | | long sequence = snowflake.nextId(); |
| | | log.info("开始推送导航数据 {}", orderId); |
| | | MqttPublishDto mqttPublishDto = xpuUtil.cloudPushNavigation(navigationDataBuilder.build(), xpuId, sequence); |
| | | log.info("推送导航的响应消息,{}", JSON.toJSONString(mqttPublishDto)); |