| | |
| | | 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.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.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.common.redis.service.RedisService; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | |
| | | @Api(tags = "订单任务Api") |
| | | public class OrderMissionController { |
| | | |
| | | private static final String TEST_PLAN_DEMO_ORDER_PREFIX = "TPD"; |
| | | private static final String REASSIGN_CANCEL_CONTEXT_PREFIX = "REASSIGN_CANCEL_CONTEXT:"; |
| | | private static final String CANCEL_ORDER_CONTEXT_PREFIX = "CANCEL_ORDER_CONTEXT:"; |
| | | private static final long CANCEL_CONTEXT_TTL_MINUTES = 30L; |
| | | |
| | | /** |
| | | * 共享线程池,用于推送司机位置轨迹,避免每次请求创建新线程池导致资源泄漏 |
| | | */ |
| | | private static final ThreadPoolExecutor DRIVER_LOCATION_EXECUTOR = new ThreadPoolExecutor( |
| | | 2, 4, 60L, TimeUnit.SECONDS, |
| | | new LinkedBlockingQueue<>(500), |
| | | r -> { |
| | | Thread t = new Thread(r, "driver-location-push"); |
| | | t.setDaemon(true); |
| | | return t; |
| | | }, |
| | | new ThreadPoolExecutor.CallerRunsPolicy() |
| | | ); |
| | | |
| | | @Resource |
| | | private XPUUtil xpuUtil; |
| | | @Resource |
| | |
| | | @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); |
| | |
| | | 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.getActions()){ |
| | | for (com.xiaopeng.api.dto.automaticPilot.TaskAction action : dto.getActions()) { |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(action.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(action.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(action.getTaskActionType()); |
| | | taskBuilder.addPreActions(taskActionBuilder.build()); |
| | | } |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.USER_ORDER)){ |
| | | //乘客单 |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.USER_ORDER) |
| | | || (dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_PLAN_DEMO_ORDER) |
| | | && !isTestPlanDemoSingleSegment(dto))){ |
| | | //乘客单 / TPD 需接驾单(含全排列不停车单):两段式 接驾+送驾,是否停车单独由 stopFlag 控制 |
| | | for (int i = 1; i < 3; i++) { |
| | | if(i == 1){ |
| | | RtTask.Builder taskBuilder = RtTask.newBuilder(); |
| | | taskBuilder.setOrderId(dto.getOrderId().toString()); |
| | | taskBuilder.setTaskId(snowflake.nextId() + ""); |
| | | taskBuilder.setTaskId(StringUtils.isNotEmpty(dto.getStartTaskId()) ? dto.getStartTaskId() : 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); |
| | | if (vehiclePosition == null) { |
| | | log.error("pushOrder USER_ORDER: 车辆位置不存在, vin={}", dto.getVin()); |
| | | return R.fail("车辆位置数据不存在,请确认车辆已上报位置"); |
| | | } |
| | | //构建车辆当前位置数据 |
| | | 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); |
| | | if (StringUtils.isNotEmpty(dto.getStartPoiName())) { |
| | | pointBuilderEnd.setPoiName(dto.getStartPoiName()); |
| | | } |
| | | 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); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_PICKUP); |
| | | |
| | | //构建下车点位置信息 |
| | | 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); |
| | | //不停车替换原有任务 |
| | | if(null != dto.getActions()){ |
| | | for (com.xiaopeng.api.dto.automaticPilot.TaskAction action : dto.getActions()) { |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(action.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(action.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(action.getTaskActionType()); |
| | | taskBuilder.addPreActions(taskActionBuilder.build()); |
| | | } |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_ORDER)){ |
| | | //测试单 |
| | | for (int i = 1; i < 3; i++) { |
| | | }else{ |
| | | 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_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.setWaypointId(dto.getStartWaypointId() + ""); |
| | | pointBuilderStart.setPointType(PointType.PICK_UP_POINT); |
| | | pointBuilderStart.setActionType(ActionType.PICK_UP); |
| | | pointBuilderStart.setSequence(1); |
| | | if (StringUtils.isNotEmpty(dto.getStartPoiName())) { |
| | | pointBuilderStart.setPoiName(dto.getStartPoiName()); |
| | | } |
| | | GeoPoint.Builder geoPointBuilder = GeoPoint.newBuilder(); |
| | | geoPointBuilder.setLatitude(dto.getStartLatitude()); |
| | | geoPointBuilder.setLongitude(dto.getStartLongitude()); |
| | |
| | | taskBuilder.addPoints(pointBuilderStart); |
| | | |
| | | //构建下车点位置信息 |
| | | pointBuilderEnd.setWaypointId(dto.getOrderId() + "-SD-002"); |
| | | pointBuilderEnd.setWaypointId(dto.getEndWaypointId() + ""); |
| | | pointBuilderEnd.setPointType(PointType.END_POINT); |
| | | pointBuilderEnd.setActionType(ActionType.DROP_OFF); |
| | | pointBuilderEnd.setActionType(resolveUserOrderEndActionType(dto)); |
| | | 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.addOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getActions()){ |
| | | for (com.xiaopeng.api.dto.automaticPilot.TaskAction action : dto.getActions()) { |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(action.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(action.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(action.getTaskActionType()); |
| | | taskBuilder.addPreActions(taskActionBuilder.build()); |
| | | } |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | } |
| | | }else if(dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_ORDER) |
| | | || (dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_PLAN_DEMO_ORDER) |
| | | && isTestPlanDemoSingleSegment(dto))){ |
| | | //测试单 / TPD 免接驾单段单(仅串烧已串接段)- 直接下发单段送驾任务(终点动作由 stopFlag 决定) |
| | | boolean skipStopAction = shouldSkipTestOrderStopAction(dto); |
| | | 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(skipStopAction ? ActionType.ACTION_UNSPECIFIED : ActionType.PICK_UP); |
| | | pointBuilderStart.setSequence(1); |
| | | if (StringUtils.isNotEmpty(dto.getStartPoiName())) { |
| | | pointBuilderStart.setPoiName(dto.getStartPoiName()); |
| | | } |
| | | 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); |
| | | // stopFlag=0 表示不停车直接接下一单(批量测试中间段),其余情况按原有"下车"语义 |
| | | pointBuilderEnd.setActionType( |
| | | Integer.valueOf(0).equals(dto.getStopFlag()) |
| | | ? ActionType.DRIVE_THROUGH |
| | | : 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(1); |
| | | taskBuilder.setOrderPhase(OrderPhase.ROUTE_TO_DESTINATION); |
| | | |
| | | //不停车替换原有任务 |
| | | if(null != dto.getActions()){ |
| | | for (com.xiaopeng.api.dto.automaticPilot.TaskAction action : dto.getActions()) { |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(action.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(action.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(action.getTaskActionType()); |
| | | taskBuilder.addPreActions(taskActionBuilder.build()); |
| | | } |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | if (skipStopAction) { |
| | | log.info("测试订单跳过上下客动作 orderId={}, needStop={}", dto.getOrderId(), dto.getNeedStop()); |
| | | } |
| | | }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.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); |
| | |
| | | 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.getActions()){ |
| | | for (com.xiaopeng.api.dto.automaticPilot.TaskAction action : dto.getActions()) { |
| | | TaskAction.Builder taskActionBuilder = TaskAction.newBuilder(); |
| | | taskActionBuilder.setOrderId(action.getLastOrderId()); |
| | | taskActionBuilder.setTaskId(action.getLastXpuTaskId()); |
| | | taskActionBuilder.setActionType(action.getTaskActionType()); |
| | | taskBuilder.addPreActions(taskActionBuilder.build()); |
| | | } |
| | | } |
| | | taskListBuilder.addTasks(taskBuilder.build()); |
| | | } |
| | | |
| | | long sequence = snowflake.nextId(); |
| | | MqttPublishDto mqttPublishDto = xpuUtil.cloudCreateOrder(taskListBuilder.build(), dto.getVin(),sequence); |
| | | RtTaskList rtTaskList = taskListBuilder.build(); |
| | | MqttPublishDto mqttPublishDto = xpuUtil.cloudCreateOrder(rtTaskList, dto.getVin(),sequence); |
| | | if(null != mqttPublishDto && mqttPublishDto.getCode() == 200){ |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("event", SystemEventType.CREATE_ORDER); |
| | | jsonObject.put("orderType", dto.getOrderType()); |
| | | jsonObject.put("orderId", dto.getOrderId()); |
| | | jsonObject.put("vin", dto.getVin()); |
| | | // 记录本次下发的 taskId 列表,供 CLOUD_SEND_RT_TASK 响应校验合法性 |
| | | List<String> taskIds = rtTaskList.getTasksList().stream() |
| | | .map(RtTask::getTaskId) |
| | | .collect(Collectors.toList()); |
| | | jsonObject.put("taskIds", taskIds); |
| | | redisService.setCacheObject("CREATE_ORDER:" + dto.getOrderId().toString(), jsonObject.toJSONString(),30L, TimeUnit.MINUTES); |
| | | } |
| | | //先将车辆修改状态,防止在异步通知之前被其他订单选中 |
| | | if(!dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.CRUISE_ORDER) && |
| | | !dto.getOrderType().equals(com.xiaopeng.api.vo.OrderType.TEST_CRUISE_ORDER) |
| | |
| | | // 修改车子为接单状态 |
| | | 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.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(true); |
| | | } |
| | | return R.ok(false); |
| | | |
| | | private boolean shouldSkipTestOrderStopAction(PushOrderDto dto) { |
| | | if (Integer.valueOf(0).equals(dto.getNeedStop())) { |
| | | return true; |
| | | } |
| | | // TPD 不停车单:连续驶过,起点不下发上车动作 |
| | | return isTestPlanDemoNoStop(dto); |
| | | } |
| | | |
| | | @PostMapping("/inner/cancelOrder") |
| | | R<Boolean> cancelOrder(@RequestBody PushOrderDto dto) { |
| | | String taskId = StringUtils.isNotEmpty(dto.getTaskId()) ? dto.getTaskId() : snowflake.nextId() + ""; |
| | | /** |
| | | * 是否为 TPD 不停车单:orderId 为 TPD 前缀且 stopFlag=0(由计划级 isStopAtDropoff 换算而来)。 |
| | | * 不停车单走与测试单一致的单段送驾结构,终点动作为 DRIVE_THROUGH。 |
| | | */ |
| | | private boolean isTestPlanDemoNoStop(PushOrderDto dto) { |
| | | return StringUtils.isNotEmpty(dto.getOrderId()) |
| | | && dto.getOrderId().startsWith(TEST_PLAN_DEMO_ORDER_PREFIX) |
| | | && Integer.valueOf(0).equals(dto.getStopFlag()); |
| | | } |
| | | |
| | | /** |
| | | * 是否为 TPD 免接驾的单段送驾单:仅当明确不需要接驾(needPickup=false)时成立。 |
| | | * 是否接驾只看订单串接关系/生成模式(由 operation-boot 计算并透传 needPickup),与是否停车(stopFlag)完全无关; |
| | | * needPickup 为 null/true 时一律走两段式接驾,作为保守回退。 |
| | | */ |
| | | private boolean isTestPlanDemoSingleSegment(PushOrderDto dto) { |
| | | return StringUtils.isNotEmpty(dto.getOrderId()) |
| | | && dto.getOrderId().startsWith(TEST_PLAN_DEMO_ORDER_PREFIX) |
| | | && Boolean.FALSE.equals(dto.getNeedPickup()); |
| | | } |
| | | |
| | | private ActionType resolveUserOrderEndActionType(PushOrderDto dto) { |
| | | // TPD 测试单:stopFlag 源自计划级 isStopAtDropoff(operation-boot 派单时换算并通过 PushOrderDto 透传) |
| | | // stopFlag=0 -> 不停车驶过;stopFlag=1/null -> 停车下客 |
| | | if (StringUtils.isNotEmpty(dto.getOrderId()) |
| | | && dto.getOrderId().startsWith(TEST_PLAN_DEMO_ORDER_PREFIX) |
| | | && Integer.valueOf(0).equals(dto.getStopFlag())) { |
| | | return ActionType.DRIVE_THROUGH; |
| | | } |
| | | return ActionType.DROP_OFF; |
| | | } |
| | | |
| | | @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(taskId); |
| | |
| | | operationBuilder.setOperationType(OrderOperationType.forNumber(dto.getOperation_type().getNumber())); |
| | | } |
| | | |
| | | long sequence = snowflake.nextId(); |
| | | MqttPublishDto mqttPublishDto = xpuUtil.cloudOrderOperation(operationBuilder.build(), dto.getVin(), sequence); |
| | | |
| | | if (mqttPublishDto.getCode() == 200) { |
| | | if (!dto.getOrderId().contains("XU")) { |
| | | recordCancelOrderContext(dto, taskId); |
| | | } |
| | | return R.ok(true); |
| | | } |
| | | |
| | | return R.ok(false); |
| | | |
| | | |
| | | } |
| | | |
| | | private void recordCancelOrderContext(PushOrderDto dto, String taskId) { |
| | | Map<String, Object> cancelContext = new HashMap<>(); |
| | | cancelContext.put("orderId", dto.getOrderId()); |
| | | cancelContext.put("vin", dto.getVin()); |
| | | String cancelScene = StringUtils.isNotEmpty(dto.getCancelScene()) |
| | | ? dto.getCancelScene() |
| | | : CancelOrderSceneEnum.NORMAL_CANCEL.getCode(); |
| | | cancelContext.put("cancelScene", cancelScene); |
| | | String contextJson = JSONObject.toJSONString(cancelContext); |
| | | redisService.setCacheObject(CANCEL_ORDER_CONTEXT_PREFIX + taskId, |
| | | contextJson, CANCEL_CONTEXT_TTL_MINUTES, TimeUnit.MINUTES); |
| | | if (CancelOrderSceneEnum.REASSIGN_OLD_VEHICLE == CancelOrderSceneEnum.fromCode(cancelScene)) { |
| | | redisService.setCacheObject(REASSIGN_CANCEL_CONTEXT_PREFIX + dto.getOrderId(), |
| | | contextJson, CANCEL_CONTEXT_TTL_MINUTES, TimeUnit.MINUTES); |
| | | } |
| | | log.info("记录取消订单上下文成功,orderId: {}, vin: {}, taskId: {}, cancelScene: {}", |
| | | dto.getOrderId(), dto.getVin(), taskId, cancelScene); |
| | | } |
| | | |
| | | |
| | | |
| | | @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.getEndWaypointId() + ""); |
| | | 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); |
| | | |
| | |
| | | : CancelOrderSceneEnum.NORMAL_CANCEL.getCode()); |
| | | redisService.setCacheObject("CANCEL_ORDER_CONTEXT:" + taskId, |
| | | JSONObject.toJSONString(cancelContext), 30L, TimeUnit.MINUTES); |
| | | log.info("记录取消订单上下文成功,orderId: {}, vin: {}, taskId: {}, cancelScene: {}", |
| | | log.info("记录修改目的地订单上下文成功,orderId: {}, vin: {}, taskId: {}, cancelScene: {}", |
| | | dto.getOrderId(), dto.getVin(), taskId, cancelContext.get("cancelScene")); |
| | | } |
| | | return R.ok(true); |
| | | } |
| | | |
| | | return R.ok(false); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | @GetMapping("/base/v1/order/acceptingOrder") |
| | | public R acceptingOrder(Long orderId, String code, Long vehicleId, Double startLon, Double startLat){ |
| | | log.info("【模拟接单】开始,orderId={}, code={}, vehicleId={}, startLon={}, startLat={}", orderId, code, vehicleId, startLon, startLat); |
| | | if(null == vehicleId){ |
| | | vehicleId = 11L;//默认使用造的测试车辆 |
| | | log.info("【模拟接单】vehicleId为空,使用默认测试车辆 vehicleId={}", vehicleId); |
| | | } |
| | | if(null == startLat || null == startLon){ |
| | | startLat = 30.583407D; |
| | | startLon = 104.040251D; |
| | | startLat = 23.146815D; |
| | | startLon = 113.459765D; |
| | | log.info("【模拟接单】起点坐标为空,使用默认坐标 startLon={}, startLat={}", startLon, startLat); |
| | | } |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); |
| | | log.info("【模拟接单】查询车辆信息,vehicleId={}, vin={}", vehicleId, xpVehicle != null ? xpVehicle.getVehicleVin() : "null"); |
| | | XpOrder xpOrder = null; |
| | | if(null != orderId){ |
| | | xpOrder = xpOrderClient.queryOrderById(orderId).getData(); |
| | | log.info("【模拟接单】按orderId查询订单,orderId={}, orderNo={}", orderId, xpOrder != null ? xpOrder.getOrderNumber() : "null"); |
| | | } |
| | | if(StringUtils.isNotEmpty(code)){ |
| | | xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData(); |
| | | log.info("【模拟接单】按orderNo查询订单,code={}, orderId={}", code, xpOrder != null ? xpOrder.getId() : "null"); |
| | | } |
| | | |
| | | orderId = xpOrder.getId(); |
| | | log.info("【模拟接单】订单信息,orderId={}, appUserId={}, startLon={}, startLat={}", orderId, xpOrder.getAppUserId(), xpOrder.getStartLon(), xpOrder.getStartLat()); |
| | | OrderRouteAndFareDto dto = new OrderRouteAndFareDto(); |
| | | dto.setOrderId(orderId); |
| | | LonLatDto origin = new LonLatDto(); |
| | | origin.setLongitude(startLon); |
| | | origin.setLatitude(startLat); |
| | | dto.setOrigin(origin); |
| | | |
| | | //保存车辆实时位置到redis |
| | | String vin = xpVehicle.getVehicleVin(); |
| | | redisService.setCacheObject("VEHICLE_POSITION:" + vin, startLon + "," + startLat); |
| | | log.info("【模拟接单】保存车辆位置到Redis,vin={}, lon={}, lat={}", vin, startLon, startLat); |
| | | |
| | | //保存车辆实时信息到mongodb |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class); |
| | | if (null == vehiclePosition) { |
| | | log.info("【模拟接单】MongoDB无车辆位置记录,新建,vin={}", vin); |
| | | vehiclePosition = new VehiclePosition(); |
| | | vehiclePosition.setVin(vin); |
| | | 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={}", vin); |
| | | 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(vin)), update, VehiclePosition.class); |
| | | } |
| | | |
| | | LonLatDto destination = new LonLatDto(); |
| | | destination.setLongitude(xpOrder.getStartLon()); |
| | | destination.setLatitude(xpOrder.getStartLat()); |
| | | dto.setDestination(destination); |
| | | dto.setRouteType(1); |
| | | dto.setVehicleId(xpOrder.getVehicleId()); |
| | | log.info("【模拟接单】请求规划接驾路线,origin=[{},{}], destination=[{},{}]", startLon, startLat, xpOrder.getStartLon(), xpOrder.getStartLat()); |
| | | R<RouteVo> routeVoR = xpMapClient.getOrderDistanceAndDuration(dto); |
| | | if (200 != routeVoR.getCode()) { |
| | | log.error("【模拟接单】获取订单线路和运费失败,orderId={}, code={}, msg={}", orderId, routeVoR.getCode(), routeVoR.getMsg()); |
| | | throw new RuntimeException("获取订单线路和运费失败"); |
| | | } |
| | | RouteVo routeVo = routeVoR.getData(); |
| | | log.info("【模拟接单】获取接驾路线成功,orderId={}, distance={}, duration={}, polylineSize={}", orderId, routeVo.getDistance(), routeVo.getDuration(), routeVo.getPolyline() != null ? routeVo.getPolyline().size() : 0); |
| | | //缓存数据,用于后续推给乘客导航线路 |
| | | redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getAppUserId(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | redisService.setCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getId(), JSON.toJSONString(routeVo), 24L, TimeUnit.HOURS); |
| | | log.info("【模拟接单】缓存接驾导航数据成功,key=ORDER_NAVIGATION_START_DATA:{}", xpOrder.getId()); |
| | | |
| | | PopOrderDto dto1 = new PopOrderDto(); |
| | | dto1.setOrderId(Long.valueOf(orderId)); |
| | | dto1.setXpVehicleVin(xpVehicle.getVehicleVin()); |
| | | dto1.setXpVehicleVin(vin); |
| | | dto1.setOrderType(com.xiaopeng.api.vo.OrderType.USER_ORDER); |
| | | log.info("【模拟接单】调用popOrder,orderId={}, vin={}", orderId, vin); |
| | | R<?> r = xpOrderClient.popOrder(dto1); |
| | | log.info("【模拟接单】popOrder结果,orderId={}, code={}", orderId, r.getCode()); |
| | | |
| | | //构建推送消息 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | Map<String, Object> content = new HashMap<>(); |
| | | content.put("orderId", orderId.toString()); |
| | | content.put("status", 3); |
| | | content.put("hasPreviousOrder", redisService.hasPreviousOrder(orderId.toString())); |
| | | params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc()); |
| | | params.put("content", JSONObject.toJSONString(content)); |
| | | params.put("timestamp", System.currentTimeMillis() + ""); |
| | |
| | | SendMessageDTO dto2 = new SendMessageDTO(); |
| | | dto2.setAppUserId(appUserId + ""); |
| | | dto2.setMessage(message); |
| | | log.info("【模拟接单】推送订单状态(status=3)给用户,appUserId={}, orderId={}", appUserId, orderId); |
| | | R<String> stringR = xpPushMessageClient.sendStatus(dto2); |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | log.error("【模拟接单】推送消息失败,appUserId={}, orderId={}, msg={}", appUserId, orderId, stringR.getMsg()); |
| | | } |
| | | log.info("【模拟接单】更新订单状态为PICK_UP,orderId={}", orderId); |
| | | xpOrderClient.updateOrderStatus(orderId, OrderStatusEnum.PICK_UP.getCode()); |
| | | log.info("【模拟接单】流程完成,orderId={}", orderId); |
| | | |
| | | // PushOrderRouteDTO dto3 = new PushOrderRouteDTO(); |
| | | // dto3.setOrderId(orderId); |
| | |
| | | */ |
| | | @GetMapping("/base/v1/order/pushStartDriverLocation") |
| | | private void pushStartDriverLocation(Long vehicleId, Long orderId, String code){ |
| | | log.info("【推送接驾轨迹】开始,vehicleId={}, orderId={}, code={}", vehicleId, orderId, code); |
| | | if(null == vehicleId){ |
| | | vehicleId = 1L; |
| | | log.info("【推送接驾轨迹】vehicleId为空,使用默认 vehicleId={}", vehicleId); |
| | | } |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); |
| | | XpOrder xpOrder = null; |
| | |
| | | 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); |
| | | log.info("【推送接驾轨迹】订单信息,orderId={}, orderNo={}, vin={}, appUserId={}", orderId, xpOrder.getOrderNumber(), vin, appUserId); |
| | | Object cacheObject = redisService.getCacheObject("ORDER_NAVIGATION_START_DATA:" + xpOrder.getId()); |
| | | RouteVo routeVo = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | log.info("【推送接驾轨迹】获取接驾导航缓存数据,orderId={}, polylineSize={}", orderId, routeVo.getPolyline() != null ? routeVo.getPolyline().size() : 0); |
| | | |
| | | |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000)); |
| | | Long finalOrderId = orderId; |
| | | Long finalOrderId1 = orderId; |
| | | threadPoolExecutor.execute(() -> { |
| | | //等待10秒后开始执行车子位移 |
| | | DRIVER_LOCATION_EXECUTOR.execute(() -> { |
| | | //等待1秒后开始执行车子位移 |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | Thread.currentThread().interrupt(); |
| | | log.error("pushStartDriverLocation 线程被中断", e); |
| | | return; |
| | | } |
| | | List<LonLatDto> polyline = routeVo.getPolyline(); |
| | | log.info("【推送接驾轨迹】开始逐点推送位置,orderId={}, 总点数={}", finalOrderId, polyline.size()); |
| | | int idx = 0; |
| | | for (LonLatDto lonLatDto : polyline) { |
| | | Double latitude = lonLatDto.getLatitude(); |
| | | Double longitude = lonLatDto.getLongitude(); |
| | | log.info("【推送接驾轨迹】推送第{}/{}个点,orderId={}, lon={}, lat={}", ++idx, polyline.size(), finalOrderId, longitude, latitude); |
| | | |
| | | //保存车辆实时位置到redis |
| | | redisTemplate.opsForGeo().add("vehiclePosition:" + vin, new Point(longitude, latitude), vin); |
| | | redisService.setCacheObject("VEHICLE_POSITION:" + vin, longitude + "," + latitude); |
| | | |
| | | //保存车辆实时信息到mongodb |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class); |
| | |
| | | vehiclePosition.setMileageRange(300f); |
| | | vehiclePosition.setHasOrder(0); |
| | | vehiclePosition.setOrderId(finalOrderId1); |
| | | vehiclePosition.setTotalOdometer(10000L); |
| | | vehiclePosition.setAddTime(System.currentTimeMillis()); |
| | | mongoTemplate.save(vehiclePosition); |
| | | }else{ |
| | | vehiclePosition.setOrderId(finalOrderId1); |
| | |
| | | .set("currentElectricity", 80) |
| | | .set("mileageRange", 300f) |
| | | .set("hasOrder", 0) |
| | | .set("orderId", finalOrderId1); |
| | | .set("orderId", finalOrderId1) |
| | | .set("totalOdometer", 10000L) |
| | | .set("addTime", System.currentTimeMillis());; |
| | | mongoTemplate.updateFirst(new Query(Criteria.where("vin").is(vin)), update, VehiclePosition.class); |
| | | } |
| | | //调用推送服务接口 |
| | |
| | | dto.setRouteType(1); |
| | | dto.setLongitude(longitude); |
| | | dto.setLatitude(latitude); |
| | | dto.setDuration(10); |
| | | dto.setDistance(2); |
| | | dto.setDuration(10.0); |
| | | dto.setDistance(2.0); |
| | | dto.setDirection(60); |
| | | dto.setMessageType(PushMessageTypeEnum.ORDER_ROUTE.getDesc()); |
| | | xpPushMessageClient.pushOrderRoute(dto); |
| | | } |
| | | |
| | |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | Thread.currentThread().interrupt(); |
| | | log.error("pushStartDriverLocation 循环线程被中断", e); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | log.info("【推送接驾轨迹】所有点推送完毕,推送status=4给用户,orderId={}, appUserId={}", finalOrderId, appUserId); |
| | | //构建推送消息 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | Map<String, Object> content = new HashMap<>(); |
| | | content.put("orderId", finalOrderId.toString()); |
| | | content.put("status", 4); |
| | | content.put("hasPreviousOrder", redisService.hasPreviousOrder(finalOrderId.toString())); |
| | | params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc()); |
| | | params.put("content", JSONObject.toJSONString(content)); |
| | | params.put("timestamp", System.currentTimeMillis() + ""); |
| | |
| | | dto2.setMessage(message); |
| | | R<String> stringR = xpPushMessageClient.sendStatus(dto2); |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | log.error("【推送接驾轨迹】推送消息失败,appUserId={}, orderId={}, msg={}", appUserId, finalOrderId, stringR.getMsg()); |
| | | } |
| | | log.info("【推送接驾轨迹】更新订单状态为PICK_UP_GUESTS,orderId={}", finalOrderId); |
| | | xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.PICK_UP_GUESTS.getCode()); |
| | | log.info("【推送接驾轨迹】流程完成,orderId={}", finalOrderId); |
| | | }); |
| | | |
| | | } |
| | |
| | | */ |
| | | @GetMapping("/base/v1/order/updateOrderStatus") |
| | | public R updateOrderStatus(Long orderId, String code, Integer status) { |
| | | log.info("【模拟修改订单状态】开始,orderId={}, code={}, status={}", orderId, code, status); |
| | | XpOrder xpOrder = null; |
| | | if(null != orderId){ |
| | | xpOrder = xpOrderClient.queryOrderById(orderId).getData(); |
| | |
| | | xpOrder = xpOrderClient.queryOrderByOrderNo(code).getData(); |
| | | } |
| | | orderId = xpOrder.getId(); |
| | | log.info("【模拟修改订单状态】订单信息,orderId={}, orderNo={}, appUserId={}", orderId, xpOrder.getOrderNumber(), xpOrder.getAppUserId()); |
| | | //构建推送消息 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | Map<String, Object> content = new HashMap<>(); |
| | | content.put("orderId", orderId.toString()); |
| | | content.put("status", status); |
| | | content.put("hasPreviousOrder", redisService.hasPreviousOrder(orderId.toString())); |
| | | params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc()); |
| | | params.put("content", JSONObject.toJSONString(content)); |
| | | params.put("timestamp", System.currentTimeMillis() + ""); |
| | |
| | | SendMessageDTO dto2 = new SendMessageDTO(); |
| | | dto2.setAppUserId(xpOrder.getAppUserId() + ""); |
| | | dto2.setMessage(message); |
| | | log.info("【模拟修改订单状态】推送状态消息给用户,appUserId={}, orderId={}, status={}", xpOrder.getAppUserId(), orderId, status); |
| | | R<String> stringR = xpPushMessageClient.sendStatus(dto2); |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | log.error("【模拟修改订单状态】推送消息失败,appUserId={}, orderId={}, msg={}", xpOrder.getAppUserId(), orderId, stringR.getMsg()); |
| | | } |
| | | log.info("【模拟修改订单状态】更新订单状态,orderId={}, status={}", orderId, status); |
| | | xpOrderClient.updateOrderStatus(orderId, status); |
| | | if(5 == status){ |
| | | log.info("【模拟修改订单状态】status=5,主动推送全程轨迹,orderId={}", orderId); |
| | | //主动推一次全程轨迹 |
| | | 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(); |
| | | log.info("【模拟修改订单状态】获取送驾导航缓存,orderId={}, polylineSize={}", orderId, routeVo.getPolyline() != null ? routeVo.getPolyline().size() : 0); |
| | | 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; |
| | |
| | | SendMessageDTO messageDTO = new SendMessageDTO(); |
| | | messageDTO.setAppUserId(xpOrder.getAppUserId().toString()); |
| | | messageDTO.setMessage(jsonObject.toJSONString()); |
| | | log.info("【模拟修改订单状态】推送全程轨迹,appUserId={}, orderId={}", xpOrder.getAppUserId(), orderId); |
| | | xpPushMessageClient.sendRoute(messageDTO); |
| | | } |
| | | log.info("【模拟修改订单状态】完成,orderId={}, status={}", orderId, status); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 推送司机接驾轨迹和实时位置 |
| | | * 推送司机送驾轨迹和实时位置 |
| | | * @param orderId |
| | | */ |
| | | @GetMapping("/base/v1/order/pushEndDriverLocation") |
| | | private void pushEndDriverLocation(Long vehicleId, Long orderId, String code){ |
| | | log.info("【推送送驾轨迹】开始,vehicleId={}, orderId={}, code={}", vehicleId, orderId, code); |
| | | if(null == vehicleId){ |
| | | vehicleId = 1L; |
| | | log.info("【推送送驾轨迹】vehicleId为空,使用默认 vehicleId={}", vehicleId); |
| | | } |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(vehicleId).getData(); |
| | | XpOrder xpOrder = null; |
| | |
| | | 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)); |
| | | log.info("【推送送驾轨迹】获取送驾导航缓存,orderId={}, vin={}, appUserId={}, polylineSize={}", orderId, vin, appUserId, routeVo.getPolyline() != null ? routeVo.getPolyline().size() : 0); |
| | | |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1000)); |
| | | Long finalOrderId = orderId; |
| | | Long finalOrderId1 = orderId; |
| | | threadPoolExecutor.execute(() -> { |
| | | //等待10秒后开始执行车子位移 |
| | | DRIVER_LOCATION_EXECUTOR.execute(() -> { |
| | | //等待1秒后开始执行车子位移 |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | Thread.currentThread().interrupt(); |
| | | log.error("pushEndDriverLocation 线程被中断", e); |
| | | return; |
| | | } |
| | | |
| | | List<LonLatDto> polyline = routeVo.getPolyline(); |
| | | log.info("【推送送驾轨迹】开始逐点推送位置,orderId={}, 总点数={}", finalOrderId, polyline.size()); |
| | | int idx = 0; |
| | | for (LonLatDto lonLatDto : polyline) { |
| | | Double latitude = lonLatDto.getLatitude(); |
| | | Double longitude = lonLatDto.getLongitude(); |
| | | log.info("【推送送驾轨迹】推送第{}/{}个点,orderId={}, lon={}, lat={}", ++idx, polyline.size(), finalOrderId, longitude, latitude); |
| | | |
| | | //保存车辆实时位置到redis |
| | | redisTemplate.opsForGeo().add("vehiclePosition:" + vin, new Point(longitude, latitude), vin); |
| | | redisService.setCacheObject("VEHICLE_POSITION:" + vin, longitude + "," + latitude); |
| | | |
| | | //保存车辆实时信息到mongodb |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class); |
| | |
| | | vehiclePosition.setMileageRange(300f); |
| | | vehiclePosition.setHasOrder(0); |
| | | vehiclePosition.setOrderId(finalOrderId1); |
| | | vehiclePosition.setTotalOdometer(10000L); |
| | | vehiclePosition.setAddTime(System.currentTimeMillis()); |
| | | mongoTemplate.save(vehiclePosition); |
| | | }else{ |
| | | vehiclePosition.setOrderId(finalOrderId1); |
| | |
| | | .set("currentElectricity", 80) |
| | | .set("mileageRange", 300f) |
| | | .set("hasOrder", 0) |
| | | .set("orderId", finalOrderId1); |
| | | .set("orderId", finalOrderId1) |
| | | .set("totalOdometer", 10000L) |
| | | .set("addTime", System.currentTimeMillis());; |
| | | mongoTemplate.updateFirst(new Query(Criteria.where("vin").is(vin)), update, VehiclePosition.class); |
| | | } |
| | | //调用推送服务接口 |
| | |
| | | dto.setRouteType(1); |
| | | dto.setLongitude(longitude); |
| | | dto.setLatitude(latitude); |
| | | dto.setDuration(20); |
| | | dto.setDistance(10); |
| | | dto.setDuration(20.0); |
| | | dto.setDistance(10.0); |
| | | dto.setDirection(60); |
| | | xpPushMessageClient.pushOrderRoute(dto); |
| | | dto.setMessageType(PushMessageTypeEnum.ORDER_ROUTE.getDesc()); |
| | | R<String> stringR = xpPushMessageClient.pushOrderRoute(dto); |
| | | |
| | | //存储历史轨迹 |
| | | OrderTrajectoryVo orderTrajectory = new OrderTrajectoryVo(); |
| | |
| | | xpOrderClient.saveVehicleLocation(orderTrajectory); |
| | | } |
| | | |
| | | //5秒钟循环一次 |
| | | //1秒钟循环一次 |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | Thread.currentThread().interrupt(); |
| | | log.error("pushEndDriverLocation 循环线程被中断", e); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | log.info("【推送送驾轨迹】所有点推送完毕,推送status=7给用户,orderId={}, appUserId={}", finalOrderId, appUserId); |
| | | //构建推送消息 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | Map<String, Object> content = new HashMap<>(); |
| | | content.put("orderId", finalOrderId.toString()); |
| | | content.put("status", 7); |
| | | content.put("hasPreviousOrder", redisService.hasPreviousOrder(finalOrderId.toString())); |
| | | params.put("type", PushMessageTypeEnum.ORDER_STATUS.getDesc()); |
| | | params.put("content", JSONObject.toJSONString(content)); |
| | | params.put("timestamp", System.currentTimeMillis() + ""); |
| | |
| | | dto2.setMessage(message); |
| | | R<String> stringR = xpPushMessageClient.sendStatus(dto2); |
| | | if (R.isError(stringR)) { |
| | | log.error("推送消息失败:{}", stringR.getMsg()); |
| | | log.error("【推送送驾轨迹】推送消息失败,appUserId={}, orderId={}, msg={}", appUserId, finalOrderId, stringR.getMsg()); |
| | | } |
| | | log.info("【推送送驾轨迹】更新订单状态为SEE_OFF_GUESTS,orderId={}", finalOrderId); |
| | | xpOrderClient.updateOrderStatus(finalOrderId, OrderStatusEnum.SEE_OFF_GUESTS.getCode()); |
| | | log.info("【推送送驾轨迹】流程完成,orderId={}", finalOrderId); |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |