| | |
| | | private static final ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); |
| | | |
| | | static { |
| | | threadPoolTaskExecutor.setCorePoolSize(50); |
| | | threadPoolTaskExecutor.setCorePoolSize(20); |
| | | threadPoolTaskExecutor.setMaxPoolSize(100); |
| | | threadPoolTaskExecutor.setQueueCapacity(20); |
| | | threadPoolTaskExecutor.setKeepAliveSeconds(60); |
| | |
| | | // 后台配置的规则 |
| | | String planRule = firstElement.split("_")[7]; |
| | | |
| | | |
| | | // 经纬度 |
| | | String[] split = lonLat.split(","); |
| | | |
| | | // 5轮找车辆 |
| | | //每次查找车辆推单后的等待秒数 |
| | | int sleepTime = 3; |
| | | Integer onePushTime = xpTradingStrategy.getOnePushTime(); |
| | | int count = onePushTime / 3; |
| | | int count = onePushTime / sleepTime; |
| | | // 第一轮推单 |
| | | processPushOrder(quoteName, count, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | // |
| | | // for (int i = 0; i < count; i++) { |
| | | // // 根据距离找车 |
| | | // // 车多则根据配置找具体车数量 根据距离最近 |
| | | // List<VehiclePosition> availableVehiclesNearby = vehiclePositionService.findAvailableVehiclesNearby(Double.parseDouble(split[0]), Double.parseDouble(split[1]), one.getOnePushDistance(), one.getSimultaneouslyOrderCount()); |
| | | // if (!availableVehiclesNearby.isEmpty()) { |
| | | // if (availableVehiclesNearby.size() > 1) { |
| | | // // 走权重 |
| | | // } else { |
| | | // // 直接派单 定义一个锁来锁定车辆 |
| | | // VehiclePosition vehiclePosition = availableVehiclesNearby.get(0); |
| | | // Long vehicleId = vehiclePosition.getVehicle_id(); |
| | | // // 查询车辆状态 |
| | | // VehiclePosition vehicleId1 = vehiclePositionService.findByVehicleId(vehicleId); |
| | | // if (vehicleId1.getStatus() != 1 || vehicleId1.getState() != 0) { |
| | | // continue; |
| | | // } |
| | | // if (vehiclePosition.getHasOrder() == 1) { |
| | | // // 关闭巡游单子 TODO |
| | | // } |
| | | // |
| | | // AddTaxiPassengerVo addTaxiPassengerVo = new AddTaxiPassengerVo(); |
| | | // addTaxiPassengerVo.setVin(vehiclePosition.getVin()); |
| | | // addTaxiPassengerVo.setUid(uid); |
| | | // addTaxiPassengerVo.setOrderNo(orderNo); |
| | | // // TODO |
| | | // addTaxiPassengerVo.setAppId(""); |
| | | // BaseVehicleUserDto baseVehicleUserDto = userVehicleClient.addTaxiPassenger(addTaxiPassengerVo); |
| | | // if (baseVehicleUserDto.getCode() == 200) { |
| | | // redisService.popFirstElement(quoteName); |
| | | // |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // } |
| | | log.info("开始第一轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | // 第二轮推单 |
| | | Integer twoPushTime = xpTradingStrategy.getTwoPushTime(); |
| | | count = twoPushTime / 3; |
| | | processPushOrder(quoteName, count, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | count = twoPushTime / sleepTime; |
| | | log.info("开始第二轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | // 第三轮推单 |
| | | Integer threePushTime = xpTradingStrategy.getThreePushTime(); |
| | | count = threePushTime / 3; |
| | | processPushOrder(quoteName, count, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | count = threePushTime / sleepTime; |
| | | log.info("开始第三轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | // 第四轮推单 |
| | | Integer fourPushTime = xpTradingStrategy.getFourPushTime(); |
| | | count = fourPushTime / 3; |
| | | processPushOrder(quoteName, count, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | count = fourPushTime / sleepTime; |
| | | log.info("开始第四轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | // 第五轮推单 |
| | | Integer fivePushTime = xpTradingStrategy.getFivePushTime(); |
| | | count = fivePushTime / 3; |
| | | processPushOrder(quoteName, count, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | count = fivePushTime / sleepTime; |
| | | log.info("开始第五轮推单 {}", orderNo); |
| | | processPushOrder(quoteName, count, sleepTime, uid, split, orderNo, xpTradingStrategy, distance, duration, planRule); |
| | | |
| | | // 取消订单 |
| | | R<XpOrder> xpOrderR = xpOrderClient.queryOrderById(Long.valueOf(orderId)); |
| | | if (xpOrderR.getCode() == 200) { |
| | | if (xpOrderR.getData().getStatus() == 1) { |
| | | log.info("五轮推单结束,无车辆接单,执行取消订单 {}", orderNo); |
| | | xpOrderClient.cancelOrder(orderId); |
| | | |
| | | // 最终没找到车 |
| | | //将订单从队列中移除 |
| | | log.info("五轮推单结束,无车辆接单,执行队列移除订单 {}", orderNo); |
| | | redisService.popFirstElement(quoteName); |
| | | } |
| | | } |
| | |
| | | * @param xpTradingStrategy 规则 |
| | | */ |
| | | @SneakyThrows |
| | | private void processPushOrder(String quoteName, int count, String uid, String[] split, String orderNo, XpTradingStrategy xpTradingStrategy, String distance, String duration, String planRule) { |
| | | // 卡住3秒 |
| | | Thread.sleep(3000); |
| | | System.out.println("进入推单环环节"); |
| | | 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("进入推单环节"); |
| | | if (count == 0) { |
| | | count = 1; |
| | | } |
| | |
| | | XpElectronicFence xpElectronicFence = xpElectronicFenceMapper.selectById(electronicId); |
| | | |
| | | for (int i = 0; i < count; i++) { |
| | | //等到sleepTime秒钟 |
| | | Thread.sleep(sleepTime); |
| | | System.out.println("进入找车环节"); |
| | | // 根据距离找车 |
| | | // 车多则根据配置找具体车数量 根据距离最近 |
| | |
| | | log.info("附近只有一个车辆 {} ,直接推单XPU", vehicleId1.getPlateNumber()); |
| | | log.info("当前车辆状态 {} 运营状态 {}", vehicleId1.getOperatingStatus(), vehicleId1.getState()); |
| | | if (vehicleId1.getOperatingStatus() != 1 || vehicleId1.getState() != 0 || vehicleId1.getVehicleType()==1) { |
| | | lock.unlock(); |
| | | continue; |
| | | } |
| | | // 关闭巡游单子 |
| | |
| | | log.info("关闭巡游单子失败"); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | PushOrderDto pushOrderDto = new PushOrderDto(); |
| | | pushOrderDto.setVin(vehiclePosition.getVin()); |
| | |
| | | redisService.popFirstElement(quoteName); |
| | | log.info("将订单 {} 从队列 {} 弹出去", xpOrder.getOrderNumber(), quoteName); |
| | | return; |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |