| | |
| | | package com.xiaopeng.automaticPilot.controller; |
| | | |
| | | 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.automaticPilot.MqttPublishDto; |
| | |
| | | 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.feignClient.vehicleConvoy.XpVehicleClient; |
| | | import com.xiaopeng.api.model.order.XpOrder;import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | | 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.protobuf.*; |
| | |
| | | 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; |
| | |
| | | @Resource |
| | | private XpVehicleClient xpVehicleClient; |
| | | @Resource |
| | | private VehicleBuriedPointClient vehicleBuriedPointClient; |
| | | @Resource(name = "hutoolSnowflake") |
| | | private Snowflake snowflake; |
| | | |
| | | @PostMapping("/inner/pushOrder") |
| | | @PostMapping("/logan/inner/pushOrder") |
| | | public R<Boolean> pushOrder(@RequestBody PushOrderDto dto) { |
| | | log.info("创建订单,推送XPU报文:{}", JSON.toJSONString(dto)); |
| | | //构建点位信息 |
| | | Waypoint.Builder pointBuilderStart = Waypoint.newBuilder(); |
| | | Waypoint.Builder pointBuilderEnd = Waypoint.newBuilder(); |
| | |
| | | if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.CRUISE_ORDER)){ |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskId(StringUtils.isNotEmpty(dto.getEndTaskId()) ? dto.getEndTaskId() : snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_CRUISE); |
| | | //构建起点坐标数据 |
| | | pointBuilderStart.setWaypointId(dto.getOrderId() + "-001"); |
| | | pointBuilderStart.setWaypointId(dto.getStartWaypointId() + ""); |
| | | pointBuilderStart.setPointType(PointType.START_POINT); |
| | | pointBuilderStart.setSequence(1); |
| | | pointBuilderStart.setActionType(ActionType.ACTION_UNSPECIFIED); |
| | |
| | | taskBuilder.addPoints(pointBuilderStart); |
| | | |
| | | //构建终点数据 |
| | | pointBuilderEnd.setWaypointId(dto.getOrderId() + "-002"); |
| | | pointBuilderEnd.setWaypointId(dto.getEndWaypointId() + ""); |
| | | 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()); |
| | | geoPointBuilder.setLongitude(dto.getEndLongitude()); |
| | | pointBuilderEnd.setPoint(geoPointBuilder.build()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(1); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_CRUISE); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_CRUISE); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getLastOrderId()){ |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(dto.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(dto.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(dto.getTaskActionType()); |
| | | taskBuilder.setPreActions(0, taskActionBuilder); |
| | | } |
| | | 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()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); |
| | | if(i == 1){ |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(StringUtils.isNotEmpty(dto.getStartTaskId()) ? dto.getStartTaskId() : snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); |
| | | 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); |
| | |
| | | taskBuilder.addPoints(pointBuilderStart); |
| | | |
| | | //构建上车点位置信息 |
| | | pointBuilderEnd.setWaypointId(dto.getOrderId() + "-JJ-002"); |
| | | pointBuilderEnd.setWaypointId(dto.getStartWaypointId() + ""); |
| | | pointBuilderEnd.setPointType(PointType.PICK_UP_POINT); |
| | | pointBuilderEnd.setActionType(ActionType.PICK_UP); |
| | | pointBuilderEnd.setSequence(2); |
| | |
| | | pointBuilderEnd.setPoint(geoPointBuilder.build()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(i); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_PICKUP); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_PICKUP); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getLastOrderId()){ |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(dto.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(dto.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(dto.getTaskActionType()); |
| | | taskBuilder.setPreActions(0, taskActionBuilder); |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | }else{ |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(StringUtils.isNotEmpty(dto.getEndTaskId()) ? dto.getEndTaskId() : snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); |
| | | //构建上车点位置信息 |
| | | pointBuilderStart.setWaypointId(dto.getOrderId() + "-SD-001"); |
| | | pointBuilderStart.setWaypointId(dto.getStartWaypointId() + ""); |
| | | pointBuilderStart.setPointType(PointType.PICK_UP_POINT); |
| | | pointBuilderStart.setActionType(ActionType.PICK_UP); |
| | | pointBuilderStart.setSequence(1); |
| | |
| | | taskBuilder.addPoints(pointBuilderStart); |
| | | |
| | | //构建下车点位置信息 |
| | | pointBuilderEnd.setWaypointId(dto.getOrderId() + "-SD-002"); |
| | | pointBuilderEnd.setWaypointId(dto.getEndWaypointId() + ""); |
| | | pointBuilderEnd.setPointType(PointType.END_POINT); |
| | | pointBuilderEnd.setActionType(ActionType.DROP_OFF); |
| | | pointBuilderEnd.setSequence(2); |
| | | pointBuilderEnd.setPoiName(dto.getEndPoiName()); |
| | | geoPointBuilder = GeoPoint.newBuilder(); |
| | | geoPointBuilder.setLatitude(dto.getEndLatitude()); |
| | | geoPointBuilder.setLongitude(dto.getEndLongitude()); |
| | | pointBuilderEnd.setPoint(geoPointBuilder.build()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(i); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getLastOrderId()){ |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(dto.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(dto.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(dto.getTaskActionType()); |
| | | taskBuilder.setPreActions(0, taskActionBuilder); |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | } |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_ORDER)){ |
| | | //测试单 |
| | | for (int i = 1; i < 3; i++) { |
| | | if(i == 1){ |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(StringUtils.isNotEmpty(dto.getStartTaskId()) ? dto.getStartTaskId() : snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(dto.getVin())), VehiclePosition.class); |
| | | //构建车辆当前位置数据 |
| | | 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.getStartWaypointId() + ""); |
| | | 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()); |
| | | pointBuilderEnd.setPoiName(dto.getEndPoiName()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(i); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_PICKUP); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getLastOrderId()){ |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(dto.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(dto.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(dto.getTaskActionType()); |
| | | taskBuilder.setPreActions(0, taskActionBuilder); |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | }else{ |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(StringUtils.isNotEmpty(dto.getEndTaskId()) ? dto.getEndTaskId() : snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_ROBOTAXI); |
| | | //构建上车点位置信息 |
| | | pointBuilderStart.setWaypointId(dto.getStartWaypointId() + ""); |
| | | 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.getEndWaypointId() + ""); |
| | | pointBuilderEnd.setPointType(PointType.END_POINT); |
| | | pointBuilderEnd.setActionType(ActionType.DROP_OFF); |
| | | pointBuilderEnd.setSequence(2); |
| | | geoPointBuilder = GeoPoint.newBuilder(); |
| | | geoPointBuilder.setLatitude(dto.getEndLatitude()); |
| | | geoPointBuilder.setLongitude(dto.getEndLatitude()); |
| | | geoPointBuilder.setLongitude(dto.getEndLongitude()); |
| | | pointBuilderEnd.setPoint(geoPointBuilder.build()); |
| | | taskBuilder.addPoints(pointBuilderEnd); |
| | | taskBuilder.setSequence(i); |
| | | taskBuilder.addOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getLastOrderId()){ |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(dto.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(dto.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(dto.getTaskActionType()); |
| | | taskBuilder.setPreActions(0, taskActionBuilder); |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | 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(StringUtils.isNotEmpty(dto.getEndTaskId()) ? dto.getEndTaskId() : snowflake.nextId() + ""); |
| | | taskBuilder.setTaskType(OrderType.ORDER_TYPE_CRUISE); |
| | | //构建起点坐标数据 |
| | | pointBuilderStart.setWaypointId(dto.getStartWaypointId() + ""); |
| | | 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.getEndWaypointId() + ""); |
| | | 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.setOrderPhase(OrderPhase.ROUTE_TO_CRUISE); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getLastOrderId()){ |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(dto.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(dto.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(dto.getTaskActionType()); |
| | | taskBuilder.setPreActions(0, taskActionBuilder); |
| | | } |
| | | 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); |
| | |
| | | return R.ok(false); |
| | | } |
| | | |
| | | @PostMapping("/inner/cancelOrder") |
| | | R<Boolean> cancelOrder(@RequestBody PushOrderDto dto) { |
| | | @PostMapping("/logan/inner/cancelOrder") |
| | | public R<Boolean> cancelOrder(@RequestBody PushOrderDto dto) { |
| | | log.info("取消订单,推送XPU报文:{}", JSON.toJSONString(dto)); |
| | | String taskId = StringUtils.isNotEmpty(dto.getEndTaskId()) ? dto.getEndTaskId() : 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); |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | @PostMapping("/logan/inner/updateEndAddress") |
| | | public R<Boolean> updateEndAddress(@RequestBody PushOrderDto dto){ |
| | | log.info("修改目的地,推送XPU报文:{}", JSON.toJSONString(dto)); |
| | | String taskId = StringUtils.isNotEmpty(dto.getEndTaskId()) ? dto.getEndTaskId() : snowflake.nextId() + ""; |
| | | OrderOperation.Builder operationBuilder = OrderOperation.newBuilder(); |
| | | operationBuilder.setOrderId(dto.getOrderId().toString()); |
| | | operationBuilder.setTaskId(taskId); |
| | | if (dto.getOperation_type() != null) { |
| | | operationBuilder.setOperationType(OrderOperationType.forNumber(dto.getOperation_type().getNumber())); |
| | | } |
| | | Waypoint.Builder waypointBuilder = Waypoint.newBuilder(); |
| | | waypointBuilder.setWaypointId(dto.getOrderId() + "-002"); |
| | | waypointBuilder.setPointType(PointType.END_POINT); |
| | | waypointBuilder.setActionType(ActionType.DROP_OFF); |
| | | waypointBuilder.setSequence(2); |
| | | GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); |
| | | geoPointBuilder.setLatitude(dto.getEndLatitude()); |
| | | geoPointBuilder.setLongitude(dto.getEndLongitude()); |
| | | waypointBuilder.setPoint(geoPointBuilder.build()); |
| | | waypointBuilder.setPoiName(dto.getEndPoiName()); |
| | | operationBuilder.setTargetPoint(waypointBuilder); |
| | | long sequence = snowflake.nextId(); |
| | | MqttPublishDto mqttPublishDto = xpuUtil.cloudOrderOperation(operationBuilder.build(), dto.getVin(), sequence); |
| | | |
| | | if (mqttPublishDto.getCode() == 200) { |
| | | if(!dto.getOrderId().contains("XU")){ |
| | | 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); |
| | | } |
| | | |
| | | return R.ok(false); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | vehicleId = 11L;//默认使用造的测试车辆 |
| | | } |
| | | if(null == startLat || null == startLon){ |
| | | startLat = 30.583407D; |
| | | startLon = 104.040251D; |
| | | startLat = 23.146815D; |
| | | startLon = 113.459765D; |
| | | } |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); |
| | | XpOrder xpOrder = null; |
| | |
| | | if(StringUtils.isNotEmpty(code)){ |
| | | xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData(); |
| | | } |
| | | |
| | | //保存车辆实时信息到mongodb |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class); |
| | | if (null == vehiclePosition) { |
| | | log.info("【模拟接单】MongoDB无车辆位置记录,新建,vin={}", xpVehicle.getVehicleVin()); |
| | | vehiclePosition = new VehiclePosition(); |
| | | vehiclePosition.setVin(xpVehicle.getVehicleVin()); |
| | | vehiclePosition.setPoint(new GeoJsonPoint(startLon, startLat)); |
| | | vehiclePosition.setCourse(60D); |
| | | vehiclePosition.setAlt(100F); |
| | | vehiclePosition.setSpeed(50F); |
| | | vehiclePosition.setCurrentElectricity(80); |
| | | vehiclePosition.setMileageRange(300f); |
| | | vehiclePosition.setHasOrder(0); |
| | | vehiclePosition.setOrderId(orderId); |
| | | vehiclePosition.setTotalOdometer(10000L); |
| | | vehiclePosition.setAddTime(System.currentTimeMillis()); |
| | | mongoTemplate.save(vehiclePosition); |
| | | }else{ |
| | | log.info("【模拟接单】更新MongoDB车辆位置记录,vin={}", xpVehicle.getVehicleVin()); |
| | | vehiclePosition.setOrderId(orderId); |
| | | Update update = new Update() |
| | | .set("point", new GeoJsonPoint(startLon, startLat)) |
| | | .set("course", 60D) |
| | | .set("alt", 100F) |
| | | .set("speed", 50F) |
| | | .set("currentElectricity", 80) |
| | | .set("mileageRange", 300f) |
| | | .set("hasOrder", 0) |
| | | .set("orderId", orderId) |
| | | .set("totalOdometer", 10000L) |
| | | .set("addTime", System.currentTimeMillis()); |
| | | mongoTemplate.updateFirst(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), update, VehiclePosition.class); |
| | | } |
| | | |
| | | orderId = xpOrder.getId(); |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(orderId); |
| | |
| | | destination.setLatitude(xpOrder.getStartLat()); |
| | | dto.setDestination(destination); |
| | | dto.setRouteType(1); |
| | | dto.setVehicleId(xpOrder.getVehicleId()); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | } |
| | | xpOrderClient.updateOrderStatus(orderId, OrderStatusEnum.PICK_UP.getCode()); |
| | | xpOrderClient.updateOrderStatus(orderId, OrderStatusEnum.PICK_UP.getCode(), false); |
| | | |
| | | // PushOrderRouteDTO dto3 = new PushOrderRouteDTO(); |
| | | // dto3.setOrderId(orderId); |
| | |
| | | orderId = xpOrder.getId(); |
| | | String vin = xpVehicle.getVehicleVin(); |
| | | Long appUserId = xpOrder.getAppUserId(); |
| | | // Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId()); |
| | | // RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | RouteVo routeVo =new RouteVo(); |
| | | ArrayList<LonLatDto> lonLatDtos = new ArrayList<>(); |
| | | LonLatDto lonLatDto1 = new LonLatDto(); |
| | | lonLatDto1.setLatitude(30.575685); |
| | | lonLatDto1.setLongitude(104.001118); |
| | | lonLatDtos.add(lonLatDto1); |
| | | routeVo.setPolyline(lonLatDtos); |
| | | Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId()); |
| | | RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | // RouteVo routeVo =new RouteVo(); |
| | | // ArrayList<LonLatDto> lonLatDtos = new ArrayList<>(); |
| | | // LonLatDto lonLatDto1 = new LonLatDto(); |
| | | // lonLatDto1.setLatitude(30.575685); |
| | | // lonLatDto1.setLongitude(104.001118); |
| | | // lonLatDtos.add(lonLatDto1); |
| | | // routeVo.setPolyline(lonLatDtos); |
| | | |
| | | |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000)); |
| | |
| | | dto.setRouteType(1); |
| | | dto.setLongitude(longitude); |
| | | dto.setLatitude(latitude); |
| | | dto.setDuration(10); |
| | | dto.setDistance(2); |
| | | dto.setDuration(10.0); |
| | | dto.setDistance(2.0); |
| | | dto.setSpeed(2.0f); |
| | | dto.setDirection(60); |
| | | dto.setMessageType(PushMessageTypeEnum.ORDER_ROUTE.getDesc()); |
| | | xpPushMessageClient.pushOrderRoute(dto); |
| | | } |
| | | |
| | |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | } |
| | | xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.PICK_UP_GUESTS.getCode()); |
| | | xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.PICK_UP_GUESTS.getCode(), false); |
| | | }); |
| | | |
| | | } |
| | |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | } |
| | | xpOrderClient.updateOrderStatus(orderId, status); |
| | | xpOrderClient.updateOrderStatus(orderId, status, false); |
| | | if(5 == status){ |
| | | //主动推一次全程轨迹 |
| | | Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_END_DATA:" + xpOrder.getAppUserId()); |
| | | RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("type", "ORDER_ROUTE"); |
| | | jsonObject.put("timestamp", System.currentTimeMillis()); |
| | | com.alibaba.fastjson2.JSONObject content1 = new com.alibaba.fastjson2.JSONObject(); |
| | | JSONObject content1 = new JSONObject(); |
| | | content1.put("orderId", orderId.toString()); |
| | | content1.put("routeType", 1); |
| | | com.alibaba.fastjson2.JSONObject route = new com.alibaba.fastjson2.JSONObject(); |
| | | JSONObject route = new JSONObject(); |
| | | route.put("distance", routeVo.getDistance()); |
| | | route.put("duration", routeVo.getDuration()); |
| | | route.put("routeID", routeVo.getRouteID()); |
| | | |
| | | List<com.alibaba.fastjson2.JSONObject> collect = routeVo.getPolyline().stream().map(item -> { |
| | | com.alibaba.fastjson2.JSONObject point = new com.alibaba.fastjson2.JSONObject(); |
| | | List<JSONObject> collect = routeVo.getPolyline().stream().map(item -> { |
| | | JSONObject point = new JSONObject(); |
| | | point.put("latitude", item.getLatitude()); |
| | | point.put("longitude", item.getLongitude()); |
| | | return point; |
| | |
| | | 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; |
| | |
| | | dto.setRouteType(1); |
| | | dto.setLongitude(longitude); |
| | | dto.setLatitude(latitude); |
| | | dto.setDuration(20); |
| | | dto.setDistance(10); |
| | | dto.setDuration(20.0); |
| | | dto.setDistance(10.0); |
| | | dto.setSpeed(10.0f); |
| | | dto.setDirection(60); |
| | | xpPushMessageClient.pushOrderRoute(dto); |
| | | dto.setMessageType(PushMessageTypeEnum.ORDER_ROUTE.getDesc()); |
| | | R<String> stringR = xpPushMessageClient.pushOrderRoute(dto); |
| | | |
| | | //存储历史轨迹 |
| | | OrderTrajectoryVo orderTrajectory = new OrderTrajectoryVo(); |
| | |
| | | |
| | | //5秒钟循环一次 |
| | | try { |
| | | Thread.sleep(500); |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | } |
| | | xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.SEE_OFF_GUESTS.getCode()); |
| | | xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.SEE_OFF_GUESTS.getCode(), false); |
| | | }); |
| | | } |
| | | |