| | |
| | | package com.xiaopeng.automaticPilot.service; |
| | | |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.dto.map.OrderRouteAndFareDto; |
| | |
| | | import com.xiaopeng.api.dto.pushMessage.SendMessageDTO; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | import com.xiaopeng.api.feignClient.operation.ReassignOrderClient; |
| | | import com.xiaopeng.api.feignClient.order.XpCruiseOrderClient; |
| | | 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.XpVehicleClient; |
| | | import com.xiaopeng.api.model.order.XpCruiseOrder; |
| | | import com.xiaopeng.api.model.order.XpOrder; |
| | | 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.proto.down.GeoPoint; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.ResponseMessage; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.StatusCode; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.RTTask; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.TaskStatus; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.TaskType; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.*; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudPushNavigation.RestoreNavigationData; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.ActionType; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.GeoPoint; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.OrderOperation; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.OrderOperationType; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.PointType; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.ResponseMessage; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.RestoreNavigationData; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.StatusCode; |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.Waypoint; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.up.MessageType; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.up.MsgContent; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.up.RTCmdType; |
| | |
| | | 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.Autowired; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | private UserVehicleClient userVehicleClient; |
| | | |
| | | @Resource |
| | | private XpCruiseOrderClient xpCruiseOrderClient; |
| | | |
| | | @Resource |
| | | private Snowflake snowflake; |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | |
| | | /** |
| | |
| | | if(code == com.xiaopeng.api.vo.automaticPilot.proto.up.StatusCode.OK){ |
| | | Object sequence = redisTemplate.opsForValue().get(requestSeq); |
| | | if(sequence!=null){ |
| | | JSONObject jsonObject = JSON.parseObject(sequence.toString()); |
| | | String event = jsonObject.getString("event"); |
| | | //推送导航的响应消息 |
| | | if(SystemEventType.PUSH_NAVIGATION.equals(event)){ |
| | | String orderId = jsonObject.getString("orderId"); |
| | | String vin = jsonObject.getString("vin"); |
| | | String orderType = jsonObject.getString("orderType"); |
| | | String[] split = sequence.toString().split("_"); |
| | | if(split[0].equals("pushOrder")){ |
| | | PopOrderDto dto = new PopOrderDto(); |
| | | dto.setOrderId(Long.valueOf(orderId)); |
| | | dto.setXpVehicleVin(vin); |
| | | dto.setOrderType(orderType); |
| | | dto.setOrderId(Long.valueOf(split[1])); |
| | | dto.setXpVehicleVin(split[2]); |
| | | xpOrderClient.popOrder(dto); |
| | | } |
| | | } |
| | |
| | | //车辆动态信息 |
| | | VehicleDynamicStatus dynamicStatus = vehicleStatus.getDynamic_status(); |
| | | dynamicStatus.setSpeed(dynamicStatus.getSpeed()); |
| | | vehiclePosition.setCurrentElectricity(dynamicStatus.getBms_soc_disp()); |
| | | vehiclePosition.setMileageRange(dynamicStatus.getDst_bat_disp()); |
| | | vehiclePosition.setCurrentElectricity(dynamicStatus.getBattery_level()); |
| | | //订单信息 |
| | | OrderStatusInfo runningOrderStatusInfo = systemRuntimeStatus.getRunning_order_status_info(); |
| | | Long orderId = null; |
| | |
| | | //开始处理消息对应的业务逻辑 |
| | | NavigationDeviationEvent deviationEvent = msgContent.getContent_detail().getObject("deviationEvent", NavigationDeviationEvent.class); |
| | | String requestId = deviationEvent.getRequest_id(); |
| | | //导航id |
| | | String routeID = ""; |
| | | Long vehicleId = null; |
| | | String orderType = ""; |
| | | //偏航事件类型 1:请求导航,2:取消导航 |
| | | if (deviationEvent.getEvent_type().equals(RtEventType.RT_EVENT_TYPE_REQUEST)) { |
| | | NavigationDeviationMessage navigationDeviationMessage = deviationEvent.getNavigation_deviation_message(); |
| | |
| | | LonLatDto destination = new LonLatDto(); |
| | | LonLatDto origin = new LonLatDto(); |
| | | if (orderId.contains("XU")) { |
| | | orderType = OrderType.CRUISE_ORDER; |
| | | // todo 下发巡游单的导航数据 |
| | | //先响应消息 |
| | | responseMessage(sequence, ""); |
| | | //构建导航数据给到车端 |
| | | origin.setLongitude(116.40528); |
| | | origin.setLatitude(39.90498); |
| | | //巡游单 |
| | | origin.setLongitude(longitude); |
| | | origin.setLatitude(latitude); |
| | | destination.setLongitude(116.40528); |
| | | destination.setLatitude(39.90498); |
| | | |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | routeID = routeVo.getRouteID(); |
| | | |
| | | |
| | | // vehicleId = xpOrder.getVehicleId(); |
| | | //响应消息 |
| | | responseMessage(sequence, ""); |
| | | } else { |
| | | orderType = OrderType.USER_ORDER; |
| | | //正常单 |
| | | R<XpOrder> xpOrderR = xpOrderClient.queryOrderById(Long.parseLong(orderId)); |
| | | if (200 != xpOrderR.getCode()) { |
| | |
| | | origin.setLatitude(latitude); |
| | | destination.setLongitude(xpOrder.getStartLon()); |
| | | destination.setLatitude(xpOrder.getStartLat()); |
| | | |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | routeID = routeVo.getRouteID(); |
| | | //缓存数据,用于后续推给乘客导航线路 |
| | | redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | } |
| | | //驶往下车点的行程 |
| | | if (Arrays.asList(6).contains(xpOrder.getStatus())) { |
| | | //查询起点到终点的线路 |
| | | origin.setLongitude(longitude); |
| | | origin.setLatitude(latitude); |
| | | destination.setLongitude(xpOrder.getEndLon()); |
| | | destination.setLatitude(xpOrder.getEndLat()); |
| | | |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | routeID = routeVo.getRouteID(); |
| | | //缓存导航数据,用于后面的逻辑中给乘客端推送导航数据 |
| | | redisService.setCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | } |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(routeID)){ |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); |
| | | R<String> stringR = xpMapClient.queryRouted(routeID); |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | R<String> stringR = xpMapClient.queryRouted(routeVo.getRouteID()); |
| | | if (200 != stringR.getCode()) { |
| | | throw new RuntimeException("根据导航ID获取车端需要的导航数据失败"); |
| | | } |
| | | |
| | | //构建导航下发请求对象 |
| | | cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId()); |
| | | cloudPushNavigationInfo(requestId, routeVo.getRouteID(), stringR.getData(), orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | //订单类型 1:乘客订单,2=巡游订单 |
| | | LonLatDto destination = new LonLatDto(); |
| | | LonLatDto origin = new LonLatDto(); |
| | | //导航id |
| | | String routeID = ""; |
| | | Long vehicleId = null; |
| | | String orderType = ""; |
| | | if (orderId.contains("XU")) { |
| | | // todo 下发巡游单的导航数据 |
| | | orderType = OrderType.CRUISE_ORDER; |
| | | //巡游单 |
| | | if (orderPhase.equals(OrderPhase.ROUTE_TO_CRUISE)) { |
| | | origin.setLongitude(116.40528); |
| | | origin.setLatitude(39.90498); |
| | | destination.setLongitude(116.40528); |
| | | destination.setLatitude(39.90498); |
| | | |
| | | //先响应消息 |
| | | responseMessage(sequence, ""); |
| | | /* 构建导航数据给到车端 */ |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(orderId); |
| | | XpCruiseOrder xpCruiseOrder = cruiseOrder.getData(); |
| | | |
| | | origin.setLongitude(xpCruiseOrder.getStartLon()); |
| | | origin.setLatitude(xpCruiseOrder.getStartLat()); |
| | | destination.setLongitude(xpCruiseOrder.getEndLon()); |
| | | destination.setLatitude(xpCruiseOrder.getEndLat()); |
| | | |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | routeID = routeVo.getRouteID(); |
| | | |
| | | |
| | | // vehicleId = xpOrder.getVehicleId(); |
| | | } |
| | | } else { |
| | | orderType = OrderType.USER_ORDER; |
| | | //正常单 |
| | | R<XpOrder> xpOrderR = xpOrderClient.queryOrderById(Long.parseLong(orderId)); |
| | | if (200 != xpOrderR.getCode()) { |
| | | throw new RuntimeException("订单不存在"); |
| | | } |
| | | XpOrder xpOrder = xpOrderR.getData(); |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData(); |
| | | //先响应消息 |
| | | responseMessage(sequence, xpVehicle.getVehicleVin()); |
| | | //驶往上车点的行程 |
| | | if (orderPhase.equals(OrderPhase.ROUTE_TO_PICKUP)) { |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData(); |
| | | //先响应消息 |
| | | responseMessage(sequence, xpVehicle.getVehicleVin()); |
| | | //查询车辆位置 |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class); |
| | | if (Objects.isNull(vehiclePosition)) { |
| | |
| | | origin.setLatitude(vehiclePosition.getPoint().getY()); |
| | | destination.setLongitude(xpOrder.getStartLon()); |
| | | destination.setLatitude(xpOrder.getStartLat()); |
| | | |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | routeID = routeVo.getRouteID(); |
| | | //缓存数据,用于后续推给乘客导航线路 |
| | | redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | } |
| | | //驶往下车点的行程 |
| | | if (orderPhase.equals(OrderPhase.ROUTE_TO_DESTINATION)) { |
| | | //直接取缓存中的导航数据推送给车端和乘客 |
| | | Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_DATA:" + xpOrder.getAppUserId()); |
| | | if(null == cacheObject){ |
| | | //没有缓存数据,重新规划线路 |
| | | //查询起点到终点的线路 |
| | | origin.setLongitude(xpOrder.getStartLon()); |
| | | origin.setLatitude(xpOrder.getStartLat()); |
| | | destination.setLongitude(xpOrder.getEndLon()); |
| | | destination.setLatitude(xpOrder.getEndLat()); |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | routeID = routeVo.getRouteID(); |
| | | //缓存导航数据,用于后面的逻辑中给乘客端推送导航数据 |
| | | redisService.setCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId(), com.alibaba.fastjson.JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | }else{ |
| | | RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | routeID = routeVo.getRouteID(); |
| | | } |
| | | //查询起点到终点的线路 |
| | | origin.setLongitude(xpOrder.getStartLon()); |
| | | origin.setLatitude(xpOrder.getStartLat()); |
| | | destination.setLongitude(xpOrder.getEndLon()); |
| | | destination.setLatitude(xpOrder.getEndLat()); |
| | | } |
| | | vehicleId = xpOrder.getVehicleId(); |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(routeID)){ |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); |
| | | R<String> stringR = xpMapClient.queryRouted(routeID); |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(Long.parseLong(orderId)); |
| | | dto.setOrigin(origin); |
| | | dto.setDestination(destination); |
| | | //TODO 这里的routeID不应该每次都重新生成,应该有一个缓存,调用的接口有做缓存但是没有读取缓存 |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(xpOrder.getVehicleId()).getData(); |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | R<String> stringR = xpMapClient.queryRouted(routeVo.getRouteID()); |
| | | if (200 != stringR.getCode()) { |
| | | throw new RuntimeException("根据导航ID获取车端需要的导航数据失败"); |
| | | } |
| | | //构建导航下发请求对象 |
| | | cloudPushNavigationInfo(requestId, routeID, stringR.getData(), orderType, orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId()); |
| | | cloudPushNavigationInfo(requestId, routeVo.getRouteID(), stringR.getData(), orderId, xpVehicle.getVehicleVin(), xpVehicle.getXpuId()); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | public void cloudOrderOperation(Integer orderType, String orderId, String taskId, RouteVo routeVo, String vin) { |
| | | //构建消息体 |
| | | OrderOperation orderOperation = new OrderOperation(); |
| | | orderOperation.setOrder_id(orderId); |
| | | orderOperation.setTask_id(taskId); |
| | | orderOperation.setOperation_type(OrderOperationType.CLOUD_UPDATE_WAYPOINTS); |
| | | OrderOperation.Builder orderOperationBuilder = OrderOperation.newBuilder(); |
| | | orderOperationBuilder.setOrderId(orderId); |
| | | orderOperationBuilder.setTaskId(taskId); |
| | | orderOperationBuilder.setOperationType(OrderOperationType.CLOUD_UPDATE_WAYPOINTS); |
| | | |
| | | //构建航点 |
| | | List<Waypoint> waypoints = new ArrayList<>(); |
| | | List<LonLatDto> polyline = routeVo.getPolyline(); |
| | | for (int i = 0; i < polyline.size(); i++) { |
| | | LonLatDto lonLatDto = polyline.get(i); |
| | | Waypoint waypoint = new Waypoint(); |
| | | waypoint.setWaypoint_id(UUID.randomUUID().toString()); |
| | | Waypoint.Builder waypointBuilder = Waypoint.newBuilder(); |
| | | waypointBuilder.setWaypointId(UUID.randomUUID().toString()); |
| | | if (0 == i) { |
| | | waypoint.setPoint_type(PointType.START_POINT); |
| | | waypointBuilder.setPointType(PointType.START_POINT); |
| | | //订单类型不同,点位的动作类型不同 |
| | | waypoint.setAction_type(1 == orderType ? ActionType.PICK_UP : ActionType.ACTION_UNSPECIFIED); |
| | | waypointBuilder.setActionType(1 == orderType ? ActionType.PICK_UP : ActionType.ACTION_UNSPECIFIED); |
| | | } else if (polyline.size() - 1 == i) { |
| | | waypoint.setPoint_type(PointType.END_POINT); |
| | | waypoint.setAction_type(1 == orderType ? ActionType.DROP_OFF : ActionType.ACTION_UNSPECIFIED); |
| | | waypointBuilder.setPointType(PointType.END_POINT); |
| | | waypointBuilder.setActionType(1 == orderType ? ActionType.DROP_OFF : ActionType.ACTION_UNSPECIFIED); |
| | | } else { |
| | | waypoint.setPoint_type(PointType.WAY_POINT); |
| | | waypointBuilder.setPointType(PointType.WAY_POINT); |
| | | //订单类型不同,点位的动作类型不同 |
| | | waypoint.setAction_type(ActionType.ACTION_UNSPECIFIED); |
| | | waypointBuilder.setActionType(ActionType.ACTION_UNSPECIFIED); |
| | | } |
| | | //构建经纬度 |
| | | GeoPoint geoPoint = new GeoPoint(); |
| | | geoPoint.setLongitude(lonLatDto.getLongitude()); |
| | | geoPoint.setLatitude(lonLatDto.getLatitude()); |
| | | waypoint.setPoint(geoPoint); |
| | | waypoint.setSequence(i + 1); |
| | | waypoints.add(waypoint); |
| | | GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); |
| | | geoPointBuilder.setLongitude(lonLatDto.getLongitude()); |
| | | geoPointBuilder.setLatitude(lonLatDto.getLatitude()); |
| | | waypointBuilder.setPoint(geoPointBuilder.build()); |
| | | waypointBuilder.setSequence(i + 1); |
| | | waypoints.add(waypointBuilder.build()); |
| | | } |
| | | orderOperation.setWaypoints(waypoints); |
| | | orderOperationBuilder.addAllWaypoints(waypoints); |
| | | long sequence = snowflake.nextId(); |
| | | // 处理数据 |
| | | redisTemplate.opsForValue().set(sequence,"pushOrder_"+orderId+"_"+vin,30, TimeUnit.MINUTES); |
| | | //开发发送请求到XPU |
| | | xpuUtil.cloudOrderOperation(orderOperation, vin,sequence); |
| | | xpuUtil.cloudOrderOperation(orderOperationBuilder.build(), vin,sequence); |
| | | } |
| | | |
| | | |
| | |
| | | * 构建响应消息 |
| | | */ |
| | | public void responseMessage(Long request_seq, String vin) { |
| | | ResponseMessage responseMessage = new ResponseMessage(); |
| | | responseMessage.setRequest_seq(request_seq); |
| | | responseMessage.setCode(StatusCode.OK); |
| | | responseMessage.setTimestamp(System.currentTimeMillis()); |
| | | xpuUtil.responseMessage(responseMessage, vin); |
| | | ResponseMessage.Builder responseMessageBuilder = ResponseMessage.newBuilder(); |
| | | responseMessageBuilder.setRequestSeq(request_seq); |
| | | responseMessageBuilder.setCode(StatusCode.OK); |
| | | responseMessageBuilder.setTimestamp(System.currentTimeMillis()); |
| | | xpuUtil.responseMessage(responseMessageBuilder.build(), vin); |
| | | } |
| | | |
| | | |
| | |
| | | if(orderId.contains("XU")){ |
| | | //巡游单 |
| | | //响应消息 |
| | | // TODO 1.处理结束当前巡游订单 2.创建新的巡游订单 返航 3.调用xpu车机接口 (判断是返航还是正常 返航需要存储之前的订单id) |
| | | responseMessage(sequence, ""); |
| | | //前往目的地 |
| | | if(OrderStatusEnum.IN_SERVICE.equals(status)){ |
| | |
| | | //到达目的地 |
| | | if(OrderStatusEnum.COMPLETED.equals(status)){ |
| | | |
| | | // 返程找到目前的订单 -》之前的订单 查询生成一个 正常巡游 找到下一个点位 若到达最后点位 则反向找点位 每次判断是否收车状态 是则不进行处理了 |
| | | // 找到这个订单 |
| | | R<XpCruiseOrder> cruiseOrder = xpCruiseOrderClient.getCruiseOrder(orderId); |
| | | if(cruiseOrder!=null){ |
| | | XpCruiseOrder xpCruiseOrder = cruiseOrder.getData(); |
| | | Long vehicleId = xpCruiseOrder.getVehicleId(); |
| | | |
| | | // 关闭当前巡游单子 已完成 |
| | | xpCruiseOrderClient.closeCruiseOrder(xpCruiseOrder.getVehicleVin()); |
| | | R<XpVehicle> xpVehicleR = xpVehicleClient.queryById(vehicleId); |
| | | XpVehicle xpVehicle = xpVehicleR.getData(); |
| | | // 运营中 继续执行 |
| | | if(xpVehicle.getOperatingStatus()==1 && xpVehicle.getState()==0){ |
| | | // 创建新的巡游单子 判断是否为返程单子 |
| | | if(xpCruiseOrder.getOrderType()==2){ |
| | | R<XpCruiseOrder> lastOrder = xpCruiseOrderClient.getCruiseOrder(xpCruiseOrder.getLastOrderId()); |
| | | XpCruiseOrder lastXpCruiseOrder = lastOrder.getData(); |
| | | |
| | | // 修改一下id 加一个一样的巡游单子 |
| | | lastXpCruiseOrder.setId("XU"+ IdUtil.fastUUID()); |
| | | lastXpCruiseOrder.setStatus(1); |
| | | xpCruiseOrderClient.addCruiseOrder(lastXpCruiseOrder); |
| | | |
| | | |
| | | RTTask task = new RTTask(); |
| | | task.setOrder_id(lastXpCruiseOrder.getId()); |
| | | task.setTask_id("MISSION_"+ IdUtil.fastUUID()); |
| | | task.setTask_type(TaskType.CRUISE); |
| | | task.setStatus(TaskStatus.PENDING); |
| | | SnowFlake snowFlake = new SnowFlake(0, 0); |
| | | snowFlake.withStartTimestamp(1420041600000L); |
| | | long sequence1 = snowFlake.nextId(); |
| | | xpuUtil.cloudCreateOrder(task, xpVehicle.getVehicleVin(),sequence1); |
| | | }else if(xpCruiseOrder.getOrderType()==1){ |
| | | // 正常巡游 找到下一个点位 若到达最后点位 则反向找点位 TODO v |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | }else{ |
| | | //普通单 |
| | |
| | | * @param vin 车辆VIN |
| | | * @param xpuId XPU设备id |
| | | */ |
| | | public void cloudPushNavigationInfo(String requestId, String routeId, String routeDataContent, String orderType, String orderId, String vin, String xpuId) { |
| | | public void cloudPushNavigationInfo(String requestId, String routeId, String routeDataContent, String orderId, String vin, String xpuId) { |
| | | //组装报文,将routeDateContent信息推送到XPU |
| | | RestoreNavigationData navigationData = new RestoreNavigationData(); |
| | | navigationData.setRoute_id(routeId); |
| | | navigationData.setRequest_id(requestId); |
| | | navigationData.setContent(routeDataContent); |
| | | navigationData.setTimestamp(System.currentTimeMillis()); |
| | | RestoreNavigationData.Builder navigationDataBuilder = RestoreNavigationData.newBuilder(); |
| | | navigationDataBuilder.setRouteId(routeId); |
| | | navigationDataBuilder.setRequestId(requestId); |
| | | navigationDataBuilder.setContent(routeDataContent); |
| | | navigationDataBuilder.setTimestamp(System.currentTimeMillis()); |
| | | long sequence = snowflake.nextId(); |
| | | // 处理数据 |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("event", SystemEventType.PUSH_NAVIGATION); |
| | | jsonObject.put("orderType", orderType); |
| | | jsonObject.put("orderId", orderId); |
| | | jsonObject.put("vin", vin); |
| | | redisTemplate.opsForValue().set(sequence, jsonObject.toJSONString(),30, TimeUnit.MINUTES); |
| | | xpuUtil.cloudPushNavigation(navigationData, xpuId, sequence); |
| | | redisTemplate.opsForValue().set(sequence,"pushOrder_"+orderId+"_"+vin,30, TimeUnit.MINUTES); |
| | | xpuUtil.cloudPushNavigation(navigationDataBuilder.build(), xpuId, sequence); |
| | | } |
| | | |
| | | } |