| | |
| | | log.info("没有找到空闲车辆 {},尝试连环派单给即将服务结束的车辆", orderNo); |
| | | // 查询状态为1的车辆vin |
| | | R<List<String>> servingVehicles = xpVehicleClient.queryVehiclePositionByVin(new VehiclePositionByVinDto(xpElectronicFence.getId(), vinList, xpTradingStrategy.getSimultaneouslyOrderCount(),1)); |
| | | if (vehiclePositionVos.getCode() != 200) { |
| | | if (servingVehicles.getCode() != 200) { |
| | | continue; |
| | | } |
| | | |
| | | LonLatDto current = new LonLatDto(Double.parseDouble(split[0]), Double.parseDouble(split[1]));//当前点位 |
| | | LonLatDto userPostion = new LonLatDto(Double.parseDouble(split[0]), Double.parseDouble(split[1])); |
| | | |
| | | XpTradingStrategyDetailVO strategyDetailVO = tradingStrategyClient.queryById().getData(); |
| | | |
| | |
| | | .map(R::getData) |
| | | .filter(o -> { |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(o.getVehicleId()).getData(); |
| | | |
| | | Object cacheObject = redisService.getCacheObject(CacheConstants.navigationEnd(o.getAppUserId().toString())); |
| | | RouteVo routeRemain = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | if (routeRemain.getDuration() / 60 > timeRegardAsEnding) { |
| | | return false; |
| | | } |
| | | RouteAndFareDto remain = new RouteAndFareDto(); |
| | | remain.setOrigin(current); |
| | | LonLatDto ll = new LonLatDto(o.getStartLon(), o.getStartLat()); |
| | | remain.setDestination(ll); |
| | | RouteVo r = xpMapClient.getDistanceAndDuration(remain).getData(); |
| | | if (r.getDistance() > distanceRegardAsEnding) { |
| | | if (routeRemain.getDistance() > distanceRegardAsEnding) { |
| | | return false; |
| | | } |
| | | if (r.getDuration() / 60 > timeRegardAsEnding) { |
| | | if (routeRemain.getDuration() / 60 > timeRegardAsEnding) { |
| | | return false; |
| | | } |
| | | RouteAndFareDto next = new RouteAndFareDto(); |
| | |
| | | RouteVo route = xpMapClient.getDistanceAndDuration(next).getData(); |
| | | if (route.getDistance() > backupPower + xpVehicle.getMileageRange()) |
| | | return false; |
| | | return r.getDistance() < destToPassenger |
| | | return routeRemain.getDistance() < destToPassenger |
| | | || now.plusSeconds(routeRemain.getDuration()) |
| | | .plusMinutes(endingTimeToUseTime) |
| | | .isBefore(rideTime); |
| | |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(luckyOder.getVehicleId()).getData(); |
| | | // 设置路线信息 |
| | | RouteAndFareDto routeAndFareDto = new RouteAndFareDto(); |
| | | routeAndFareDto.setDestination(current); |
| | | routeAndFareDto.setDestination(userPostion); |
| | | routeAndFareDto.setOrigin(new LonLatDto(luckyOder.getEndLon(),luckyOder.getEndLat())); |
| | | RouteVo routeToOrigin = xpMapClient.getDistanceAndDuration(routeAndFareDto).getData(); |
| | | Object cacheObject = redisService.getCacheObject(CacheConstants.navigationEnd(luckyOder.getAppUserId().toString())); |
| | |
| | | redisService.setCacheObject(CacheConstants.navigationStart(xpOrder.getAppUserId().toString()), routeToOrigin); |
| | | redisService.removeByPattern(quoteName,xpOrder.getOrderNumber()); |
| | | log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName); |
| | | break; |
| | | } |
| | | } |
| | | return false; |
| | |
| | | |
| | | // 获取车辆的区域信息 |
| | | if (positionList.isEmpty()) { |
| | | continue; |
| | | log.info("没有找到空闲车辆 {},尝试连环派单给即将服务结束的车辆", orderNo); |
| | | // 查询状态为1的车辆vin |
| | | Set<String> vinList = positionList.stream().map(VehiclePosition::getVin).collect(Collectors.toSet()); |
| | | R<List<String>> servingVehicles = xpVehicleClient.queryVehiclePositionByVin(new VehiclePositionByVinDto(data.getFleetId(), vinList, xpTradingStrategy.getSimultaneouslyOrderCount(),1)); |
| | | if (servingVehicles.getCode() != 200) { |
| | | continue; |
| | | } |
| | | |
| | | LonLatDto userPosition = new LonLatDto(data.getStartLon(), data.getStartLat());//人的位置 |
| | | |
| | | XpTradingStrategyDetailVO strategyDetailVO = tradingStrategyClient.queryById().getData(); |
| | | |
| | | Integer distanceRegardAsEnding = strategyDetailVO.getDistanceRegardAsEnding(); |
| | | Integer timeRegardAsEnding = strategyDetailVO.getTimeRegardAsEnding(); |
| | | |
| | | Integer backupPower = strategyDetailVO.getBackupPower(); |
| | | Integer destToPassenger = strategyDetailVO.getDestToPassenger(); |
| | | Integer endingTimeToUseTime = strategyDetailVO.getEndingTimeToUseTime(); |
| | | LocalDateTime rideTime = data.getRideTime(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | Optional<XpOrder> luckyOrderOpt = servingVehicles.getData().stream() |
| | | //获取位置 |
| | | .map(vin -> mongoTemplate.findOne(new Query(Criteria.where("vin").is(vin)), VehiclePosition.class)) |
| | | .map(VehiclePosition::getOrderId) |
| | | .map(xpOrderClient::queryOrderById) |
| | | .filter(R::isSuccess) |
| | | .map(R::getData) |
| | | .filter(o -> { |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(o.getVehicleId()).getData(); |
| | | Object cacheObject = redisService.getCacheObject(CacheConstants.navigationEnd(o.getAppUserId().toString())); |
| | | RouteVo routeRemain = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | if (routeRemain.getDuration() / 60 > timeRegardAsEnding) { |
| | | return false; |
| | | } |
| | | if (routeRemain.getDistance() > distanceRegardAsEnding) { |
| | | return false; |
| | | } |
| | | if (routeRemain.getDuration() / 60 > timeRegardAsEnding) { |
| | | return false; |
| | | } |
| | | RouteAndFareDto next = new RouteAndFareDto(); |
| | | next.setOrigin(new LonLatDto(o.getStartLon(),o.getStartLat())); |
| | | next.setDestination(new LonLatDto(o.getEndLon(),o.getEndLat())); |
| | | RouteVo route = xpMapClient.getDistanceAndDuration(next).getData(); |
| | | if (route.getDistance() > backupPower + xpVehicle.getMileageRange()) |
| | | return false; |
| | | return routeRemain.getDistance() < destToPassenger |
| | | || now.plusSeconds(routeRemain.getDuration()) |
| | | .plusMinutes(endingTimeToUseTime) |
| | | .isBefore(rideTime); |
| | | }) |
| | | .findAny(); |
| | | |
| | | if (luckyOrderOpt.isPresent()) { |
| | | XpOrder luckyOder = luckyOrderOpt.get(); |
| | | log.info("有空闲车辆 {} 订单 {}", luckyOder.getOrderNumber(), orderNo); |
| | | XpVehicle xpVehicle = xpVehicleClient.queryById(luckyOder.getVehicleId()).getData(); |
| | | // 设置路线信息 |
| | | RouteAndFareDto pickUpRoute = new RouteAndFareDto(); |
| | | pickUpRoute.setDestination(userPosition); |
| | | pickUpRoute.setOrigin(new LonLatDto(luckyOder.getEndLon(),luckyOder.getEndLat())); |
| | | RouteVo routeToOrigin = xpMapClient.getDistanceAndDuration(pickUpRoute).getData(); |
| | | Object cacheObject = redisService.getCacheObject(CacheConstants.navigationEnd(luckyOder.getAppUserId().toString())); |
| | | RouteVo routeRemain = JSON.parseObject(cacheObject.toString(), RouteVo.class); |
| | | routeToOrigin.getPolyline().addAll(0, routeRemain.getPolyline()); |
| | | routeToOrigin.setDuration(routeToOrigin.getDuration() + routeRemain.getDuration()); |
| | | routeToOrigin.setDistance(routeToOrigin.getDistance() + routeRemain.getDistance()); |
| | | PushOrderDto pushOrderDto = buildPushOrderDto(data); |
| | | pushOrderDto.setVin(xpVehicle.getVehicleVin()); |
| | | // 订单流转 |
| | | orderMissionClient.pushOrder(pushOrderDto); |
| | | redisService.setCacheObject(CacheConstants.nextOrder(luckyOder.getId().toString()), data.getId()); |
| | | redisService.setCacheObject(CacheConstants.navigationStart(data.getAppUserId().toString()), routeToOrigin); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 直接派单 定义一个锁来锁定车辆 |