| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | |
| | | // 自定义线程池 |
| | | private static final ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); |
| | | |
| | | ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(20); |
| | | |
| | | static { |
| | | threadPoolTaskExecutor.setCorePoolSize(20); |
| | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | log.info("没有找到空闲车辆 {},尝试连环派单给即将服务结束的车辆", orderNo); |
| | | // 查询状态为1的车辆vin |
| | | R<List<String>> servingVehicles = xpVehicleClient.queryVehiclePositionByVin(new VehiclePositionByVinDto(xpElectronicFence.getId(), vinList, xpTradingStrategy.getSimultaneouslyOrderCount(),1)); |
| | | if (vehiclePositionVos.getCode() != 200) { |
| | | continue; |
| | | } |
| | | LonLatDto lonLatDto = new LonLatDto(Double.parseDouble(split[0]), Double.parseDouble(split[1])); |
| | | RouteAndFareDto routeAndFareDto = new RouteAndFareDto(); |
| | | routeAndFareDto.setDestination(lonLatDto); |
| | | |
| | | Optional<XpOrder> lucyOrderOpt = 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 -> isClose(o, routeAndFareDto)) |
| | | .findAny(); |
| | | |
| | | if (lucyOrderOpt.isPresent()) { |
| | | XpOrder lucyOder = lucyOrderOpt.get(); |
| | | routeAndFareDto.setOrigin(new LonLatDto(lucyOder.getEndLon(),lucyOder.getEndLat())); |
| | | routeAndFareDto.setOrigin(lonLatDto); |
| | | |
| | | RouteAndFareDto routeAndFare = null;//TODO 获取导航路线 |
| | | if (null == routeAndFare) { //轨迹不在运营区 |
| | | continue; |
| | | } |
| | | // 当轨迹是否在运营区内,存储 |
| | | xpOrder.setStatus(1); |
| | | xpOrderClient.updateOrder(xpOrder); |
| | | scheduler.scheduleWithFixedDelay(this::pushProgress, 0, 5, TimeUnit.SECONDS); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private void pushProgress() { |
| | | //TODO 调用push message 服务 |
| | | PushOrderDto pushOrderDto = new PushOrderDto(); |
| | | // pushOrderDto.setVin(lucyOrder.get().getVin()); |
| | | // pushOrderDto.setOrderId(xpOrder.getId().toString()); |
| | | // pushOrderDto.setStartLatitude(xpOrder.getStartLat()); |
| | | // pushOrderDto.setStartLongitude(xpOrder.getStartLon()); |
| | | // pushOrderDto.setEndLatitude(xpOrder.getEndLat()); |
| | | // pushOrderDto.setEndLongitude(xpOrder.getEndLon()); |
| | | // pushOrderDto.setOrderType(OrderType.USER_ORDER); |
| | | } |
| | | |
| | | private boolean isClose(XpOrder xpOrder,RouteAndFareDto routeAndFareDto) { |
| | | LonLatDto lonLatDto = new LonLatDto(xpOrder.getStartLon(), xpOrder.getStartLat()); |
| | | routeAndFareDto.setOrigin(lonLatDto); |
| | | return xpMapClient.getDistanceAndDuration(routeAndFareDto).getData().getDistance() < 800; |
| | | } |
| | | |
| | | @Resource |
| | | private MongoTemplate mongoTemplate; |
| | | boolean isClose(Long orderId) { |
| | | // yong id 去查目的地坐标,判断是否小于800 |
| | | return false; |
| | | } |
| | | /** |
| | | * 订单处理 |
| | | * @param count 轮数 |