| | |
| | | import com.xiaopeng.api.dto.map.RouteAndFareDto; |
| | | import com.xiaopeng.api.dto.operation.LonLatDto; |
| | | import com.xiaopeng.api.dto.operation.VehiclePositionByVinDto; |
| | | import com.xiaopeng.api.dto.pushMessage.SendMessageDTO; |
| | | import com.xiaopeng.api.dto.vehicleConvoy.BaseVehicleUserDto; |
| | | import com.xiaopeng.api.feignClient.automaticPilot.OrderMissionClient; |
| | | import com.xiaopeng.api.feignClient.map.XpMapClient; |
| | | 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.operation.XpElectronicFence; |
| | |
| | | private OrderMissionClient orderMissionClient; |
| | | |
| | | @Resource |
| | | private XpPushMessageClient xpPushMessageClient; |
| | | |
| | | @Resource |
| | | private XpElectronicFenceMapper xpElectronicFenceMapper; |
| | | |
| | | |
| | |
| | | //每次查找车辆推单后的等待秒数 |
| | | int sleepTime = 3; |
| | | Integer onePushTime = xpTradingStrategy.getOnePushTime(); |
| | | Double onePushDistance = xpTradingStrategy.getOnePushDistance(); |
| | | int count = onePushTime / sleepTime; |
| | | // 第一轮推单 |
| | | log.info("开始第一轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, onePushDistance, distance, duration, planRule); |
| | | |
| | | // 第二轮推单 |
| | | Integer twoPushTime = xpTradingStrategy.getTwoPushTime(); |
| | | Double twoPushDistance = xpTradingStrategy.getTwoPushDistance(); |
| | | count = twoPushTime / sleepTime; |
| | | log.info("开始第二轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, twoPushDistance, distance, duration, planRule); |
| | | |
| | | // 第三轮推单 |
| | | Integer threePushTime = xpTradingStrategy.getThreePushTime(); |
| | | Double threePushDistance = xpTradingStrategy.getThreePushDistance(); |
| | | count = threePushTime / sleepTime; |
| | | log.info("开始第三轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, threePushDistance, distance, duration, planRule); |
| | | |
| | | // 第四轮推单 |
| | | Integer fourPushTime = xpTradingStrategy.getFourPushTime(); |
| | | Double fourPushDistance = xpTradingStrategy.getFourPushDistance(); |
| | | count = fourPushTime / sleepTime; |
| | | log.info("开始第四轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, fourPushDistance, distance, duration, planRule); |
| | | |
| | | // 第五轮推单 |
| | | Integer fivePushTime = xpTradingStrategy.getFivePushTime(); |
| | | Double fivePushDistance = xpTradingStrategy.getFivePushDistance(); |
| | | count = fivePushTime / sleepTime; |
| | | log.info("开始第五轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, fivePushDistance, distance, duration, planRule); |
| | | |
| | | // 取消订单 |
| | | R<XpOrder> xpOrderR = xpOrderClient.queryOrderById(Long.valueOf(orderId)); |
| | | if (xpOrderR.getCode() == 200) { |
| | | if (xpOrderR.getData().getStatus() == 1) { |
| | | XpOrder xpOrder = xpOrderR.getData(); |
| | | if (xpOrder.getStatus() == 1) { |
| | | log.info("五轮推单结束,无车辆接单,执行取消订单 {}", orderNo); |
| | | xpOrderClient.cancelOrder(orderId); |
| | | //推送订单状态给乘客 |
| | | SendMessageDTO dto = new SendMessageDTO(); |
| | | dto.setAppUserId(xpOrder.getAppUserId().toString()); |
| | | dto.setMessage("{\"type\":\"ORDER_STATUS\",\"content\":\"{\\\"orderId\\\":\\\"" + orderId + "\\\",\\\"status\\\":0}\",\"timestamp\":\"" + System.currentTimeMillis() + "\"}"); |
| | | xpPushMessageClient.sendStatus(dto); |
| | | //将订单从队列中移除 |
| | | log.info("五轮推单结束,无车辆接单,执行队列移除订单 {}", orderNo); |
| | | redisService.popFirstElement(quoteName); |
| | |
| | | * @param xpTradingStrategy 规则 |
| | | */ |
| | | @SneakyThrows |
| | | private void processPushOrder(String quoteName, int count, int sleepTime, String uid, String[] split, String orderNo, XpTradingStrategy xpTradingStrategy, String distance, String duration, String planRule) { |
| | | System.out.println("进入推单环节"); |
| | | private void processPushOrder(String quoteName, int count, int sleepTime, String uid, String[] split, String orderNo, XpTradingStrategy xpTradingStrategy, Double pushDistance, String distance, String duration, String planRule) { |
| | | log.info("进入推单环节 单号 {}", orderNo); |
| | | if (count == 0) { |
| | | count = 1; |
| | | } |
| | |
| | | |
| | | for (int i = 0; i < count; i++) { |
| | | //等到sleepTime秒钟 |
| | | Thread.sleep(sleepTime); |
| | | System.out.println("进入找车环节"); |
| | | Thread.sleep(sleepTime * 1000); |
| | | log.info("进入找车环节 单号 {} 第{}轮", orderNo, count++); |
| | | // 根据距离找车 |
| | | // 车多则根据配置找具体车数量 根据距离最近 |
| | | // 更改 暂不限制数量 |
| | | |
| | | List<VehiclePosition> positionList = vehiclePositionService.findAvailableVehiclesNearby(Double.parseDouble(split[0]), Double.parseDouble(split[1]), xpTradingStrategy.getOnePushDistance(), xpTradingStrategy.getSimultaneouslyOrderCount()); |
| | | log.info("根据距离找车 距离 {}KM 经度 {} 维度 {} 查找结果 {}", xpTradingStrategy.getOnePushDistance(), split[0], split[1], positionList); |
| | | List<VehiclePosition> positionList = vehiclePositionService.findAvailableVehiclesNearby(Double.parseDouble(split[0]), Double.parseDouble(split[1]), pushDistance, xpTradingStrategy.getSimultaneouslyOrderCount()); |
| | | log.info("根据距离找车 {} 距离 {}KM 经度 {} 维度 {} 查找结果 {} 单号 {}", orderNo, pushDistance, split[0], split[1], positionList, orderNo); |
| | | // 获取车辆的区域信息 |
| | | if (positionList.isEmpty()) { |
| | | continue; |
| | |
| | | |
| | | // 获取车辆的信息 筛选出可用车辆 |
| | | R<List<String>> vehiclePositionVos = xpVehicleClient.queryVehiclePositionByVin(new VehiclePositionByVinDto(xpElectronicFence.getId(), vinList, xpTradingStrategy.getSimultaneouslyOrderCount())); |
| | | log.info("筛选可用车辆结果 {}", JSON.toJSONString(vehiclePositionVos)); |
| | | log.info("筛选可用车辆结果 {} 单号 {}", JSON.toJSONString(vehiclePositionVos), orderNo); |
| | | if (vehiclePositionVos.getCode() != 200) { |
| | | continue; |
| | | } |
| | |
| | | |
| | | if (!availableVehiclesNearby.isEmpty()) { |
| | | if (availableVehiclesNearby.size() > 1) { |
| | | log.info("附近有 {} 辆车,进入权重判断流程", availableVehiclesNearby.size()); |
| | | log.info("附近有 {} 辆车,进入权重判断流程 单号 {}", availableVehiclesNearby.size(), orderNo); |
| | | // 走权重 |
| | | |
| | | // 订单价值 |
| | |
| | | |
| | | RLock lock = redissonClient.getLock("FIND_CAR_" + vehiclePositionVo.getVin()); |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | System.err.println("队列:" + quoteName + " 车辆:" + vehiclePositionVo.getVin() + "订单" + orderNo); |
| | | log.info("队列 {} 车辆 {} 单号 {}", quoteName, vehiclePositionVo.getVin(), orderNo); |
| | | try { |
| | | // VehiclePosition vehiclePosition = vehiclePositionService.findByVehicleId(vehiclePositionVo.getVehicle_id()); |
| | | R<XpVehicle> vehiclePositionR = xpVehicleClient.findByVehicleVin(vehiclePositionVo.getVin()); |
| | |
| | | continue; |
| | | } |
| | | XpVehicle vehiclePosition = vehiclePositionR.getData(); |
| | | log.info("符合条件的车辆 {} ,直接推单XPU", vehiclePosition.getPlateNumber()); |
| | | log.info("当前车辆状态 {}", vehiclePosition.getStatus()); |
| | | log.info("符合条件的车辆 {} ,直接推单XPU。单号 {}", vehiclePosition.getPlateNumber(), orderNo); |
| | | log.info("当前车辆状态 {} 单号 {}", vehiclePosition.getStatus(), orderNo); |
| | | if (vehiclePosition.getStatus() != 1 || vehiclePosition.getState() != 0 || vehiclePosition.getVehicleType()==1) { |
| | | continue; |
| | | } |
| | | // 关闭巡游单子 |
| | | R<String> stringR = xpCruiseOrderClient.updateCruiseOrder(vehiclePosition.getVehicleVin()); |
| | | if(stringR ==null || stringR.getData()==null){ |
| | | log.info("关闭巡游单子失败"); |
| | | if(stringR ==null || stringR.getCode() != 200){ |
| | | log.info("关闭巡游单子失败 车牌号 {}", vehiclePosition.getPlateNumber()); |
| | | continue; |
| | | } |
| | | |
| | |
| | | pushOrderDto.setOrderType(OrderType.USER_ORDER); |
| | | pushOrderDto.setStage(1); |
| | | // 调用推送服务 orderId + carVin |
| | | // orderMissionClient.pushOrder(pushOrderDto); |
| | | log.info("开始推送 {} 订单到XPU", xpOrder.getOrderNumber()); |
| | | orderMissionClient.pushOrder(pushOrderDto); |
| | | log.info("开始推送 {} 订单到XPU。单号 {}", xpOrder.getOrderNumber(), orderNo); |
| | | |
| | | redisService.popFirstElement(quoteName); |
| | | log.info("将订单 {} 从队列 {} 弹出去", xpOrder.getOrderNumber(), quoteName); |
| | | log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName); |
| | | return; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | continue; |
| | | } |
| | | XpVehicle vehicleId1 = vehicleR.getData(); |
| | | log.info("附近只有一个车辆 {} ,直接推单XPU", vehicleId1.getPlateNumber()); |
| | | log.info("当前车辆状态 {} 运营状态 {}", vehicleId1.getOperatingStatus(), vehicleId1.getState()); |
| | | log.info("附近只有一个车辆 {} ,直接推单XPU。单号 {}", vehicleId1.getPlateNumber(), orderNo); |
| | | log.info("当前车辆状态 {} 运营状态 {} 单号 {}", vehicleId1.getOperatingStatus(), vehicleId1.getState(), orderNo); |
| | | if (vehicleId1.getOperatingStatus() != 1 || vehicleId1.getState() != 0 || vehicleId1.getVehicleType()==1) { |
| | | continue; |
| | | } |
| | | // 关闭巡游单子 |
| | | R<String> stringR = xpCruiseOrderClient.updateCruiseOrder(vehicleId1.getVehicleVin()); |
| | | if(stringR ==null || stringR.getData()==null){ |
| | | log.info("关闭巡游单子失败"); |
| | | if(stringR ==null || stringR.getCode() != 200){ |
| | | log.info("关闭巡游单子失败 车牌号 {}", vehicleId1.getPlateNumber()); |
| | | continue; |
| | | } |
| | | |
| | |
| | | pushOrderDto.setOrderType(OrderType.USER_ORDER); |
| | | pushOrderDto.setStage(1); |
| | | // 调用推送服务 orderId + carVin |
| | | // orderMissionClient.pushOrder(pushOrderDto); |
| | | orderMissionClient.pushOrder(pushOrderDto); |
| | | log.info("开始推送 {} 订单到XPU", xpOrder.getOrderNumber()); |
| | | redisService.popFirstElement(quoteName); |
| | | log.info("将订单 {} 从队列 {} 弹出去", xpOrder.getOrderNumber(), quoteName); |
| | | log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName); |
| | | return; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |