| | |
| | | |
| | | @Autowired |
| | | private IRegionService regionService; |
| | | |
| | | @Autowired |
| | | private ITSysPushTypeService tSysPushTypeService; |
| | | |
| | | public static List<Integer> orderIds = new ArrayList<>(); |
| | | |
| | |
| | | } |
| | | |
| | | OpenCity openCity = openCityService.openCity1(orderTaxi.getStartLon().toString(), orderTaxi.getStartLat().toString()); |
| | | List<PushOrder> querys = pushOrderService.querys(null, 2, openCity.getId());//获取需要推送的次数 |
| | | //整轮派单结束,若无司机接单,系统自动增加派单5轮,若增加5轮后任无司机接单,则系统结束派单,乘客端显示无司机接单、是否再次打车 |
| | | int num = 0; |
| | | for (int j = 0; j < 6; j++) { |
| | | Boolean push = false; |
| | | for (int i = 1; i <= querys.size(); i++) { |
| | | num++; |
| | | int finalI = i; |
| | | PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); |
| | | System.out.println("pushOrder:" + pushOrder); |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | //随机排序 |
| | | Collections.shuffle(list); |
| | | if (list.size() > 0) { |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for (Driver driver : list) {//开始进行推送 |
| | | //查询是否在限制推单范围内 |
| | | boolean bo = false; |
| | | for (Integer integer : integers) { |
| | | if (integer.compareTo(driver.getId()) == 0) { |
| | | bo = true; |
| | | break; |
| | | |
| | | // 判断是否为派单模式 |
| | | TSysPushType sysPushType = tSysPushTypeService.selectOne(new EntityWrapper<TSysPushType>().eq("openCityId", openCity.getId())); |
| | | if(sysPushType!=null && sysPushType.getPushType()==2){ |
| | | OrderTaxi orderTaxi1 = orderTaxiMapper.selectById(orderTaxi.getId()); |
| | | if (null == orderTaxi1 && orderTaxi1.getState() == 1) { |
| | | // 固定5公里进行派单 |
| | | List<Driver> listDriver = driverService.queryIdleDriver(2, orderTaxi1.getStartLon(), orderTaxi1.getStartLat(), 5.0, null);//所有附近空闲司机 |
| | | if (listDriver.size() > 0) { |
| | | Driver driver1 = listDriver.stream().sorted(Comparator.comparingDouble(Driver::getDistance).reversed()).findFirst().get(); |
| | | |
| | | orderTaxi1.setDriverId(driver1.getId()); |
| | | orderTaxi1.setCarId(driver1.getCarId()); |
| | | orderTaxi1.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : ( |
| | | driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1)); |
| | | orderTaxi1.setState(2); |
| | | orderTaxi1.setSnatchOrderTime(new Date()); |
| | | |
| | | // 是否推广订单 |
| | | Integer promotion = isPromotion(orderTaxi1.getUserId(), driver1.getPlaceOfEmployment()); |
| | | if(promotion!=null){ |
| | | orderTaxi1.setPromotion(2); |
| | | orderTaxi1.setPromotionUser(driver1.getName()); |
| | | orderTaxi1.setPromotionPhone(driver1.getPhone()); |
| | | orderTaxi1.setPromotionDriverId(promotion); |
| | | }else{ |
| | | orderTaxi1.setPromotion(1); |
| | | } |
| | | orderTaxiMapper.updateById(orderTaxi1); |
| | | |
| | | |
| | | if(orderTaxi.getType() == 2){ |
| | | List<OrderTaxi> list = orderTaxiMapper.selectList( |
| | | new EntityWrapper<OrderTaxi>() |
| | | .eq("type", 2) |
| | | .eq("userId", orderTaxi.getUserId()) |
| | | .ne("state", 1) |
| | | .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) |
| | | .eq("place", orderTaxi.getPlace()).ne("id", orderTaxi.getId()) |
| | | ); |
| | | List<OrderPrivateCar> list1 = orderPrivateCarService.selectList( |
| | | new EntityWrapper<OrderPrivateCar>() |
| | | .eq("type", 2) |
| | | .eq("userId", orderTaxi.getUserId()) |
| | | .ne("state", 1) |
| | | .eq("crossCityOrderId", orderTaxi.getCrossCityOrderId()) |
| | | .eq("place", orderTaxi.getPlace()) |
| | | ); |
| | | for(OrderTaxi orderTaxi2 : list){ |
| | | orderTaxi2.setState(10); |
| | | orderTaxiMapper.updateById(orderTaxi2); |
| | | } |
| | | for(OrderPrivateCar orderPrivateCar : list1){ |
| | | orderPrivateCar.setState(10); |
| | | orderPrivateCarService.updateById(orderPrivateCar); |
| | | } |
| | | } |
| | | |
| | | |
| | | //如果是预约单,则不修改司机为服务中 |
| | | if(orderTaxi1.getOrderType() != 2 || (orderTaxi1.getOrderType() == 2 && orderTaxi1.getTravelTime().getTime() < System.currentTimeMillis() + 600000)){ |
| | | //修改司机为服务中 |
| | | driver1.setState(3); |
| | | driverService.updateById(driver1); |
| | | } |
| | | |
| | | //推送相关代码------------------start---------------- |
| | | OrderTaxi finalOrderTaxi = orderTaxi1; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState(),0); |
| | | pushUtil.pushOrderState(2, finalOrderTaxi.getDriverId(), finalOrderTaxi.getId(), 2, finalOrderTaxi.getState(),0); |
| | | if(finalOrderTaxi.getType() == 2){ |
| | | pushUtil.pushFerryOrderState(1, finalOrderTaxi.getUserId(), finalOrderTaxi.getId(), 2, 2); |
| | | System.err.println("----------------------------------推送摆渡订单-----------------------------"); |
| | | } |
| | | |
| | | } |
| | | }).start(); |
| | | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | pushUtil.pushDriverPosition(finalOrderTaxi.getId(), 2); |
| | | } |
| | | }).start(); |
| | | |
| | | systemNoticeService.addSystemNotice(2, "以为您派得出租车订单,请及时联系客户!", orderTaxi.getDriverId(), 1); |
| | | systemNoticeService.addSystemNotice(1, "您的订单已指派给" + driver1.getName().substring(0, 1) + "师傅,请保持电话畅通!", orderTaxi.getUserId(), 1); |
| | | |
| | | |
| | | }else { |
| | | // 没找到车辆 |
| | | OrderTaxi orderTaxi2 = orderTaxiMapper.selectById(orderTaxi.getId()); |
| | | orderTaxi2.setState(10); |
| | | orderTaxiMapper.updateById(orderTaxi2); |
| | | pushUtil.pushEndPush(1, orderTaxi2.getUserId(), orderTaxi2.getId(), 2, 1); |
| | | |
| | | // TODO 退款 |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | }else { |
| | | |
| | | List<PushOrder> querys = pushOrderService.querys(null, 2, openCity.getId());//获取需要推送的次数 |
| | | //整轮派单结束,若无司机接单,系统自动增加派单5轮,若增加5轮后任无司机接单,则系统结束派单,乘客端显示无司机接单、是否再次打车 |
| | | int num = 0; |
| | | for (int j = 0; j < 6; j++) { |
| | | Boolean push = false; |
| | | for (int i = 1; i <= querys.size(); i++) { |
| | | num++; |
| | | int finalI = i; |
| | | PushOrder pushOrder = querys.stream().filter(s -> s.getType() == (finalI <= 3 ? finalI : 3)).findFirst().orElse(null); |
| | | System.out.println("pushOrder:" + pushOrder); |
| | | //获取空闲司机 |
| | | List<Driver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机 |
| | | //随机排序 |
| | | Collections.shuffle(list); |
| | | if (list.size() > 0) { |
| | | double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数 |
| | | int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取) |
| | | lastIndex = lastIndex == 0 ? list.size() : lastIndex; |
| | | list = list.subList(0, lastIndex);//获取空闲司机中占比数据 |
| | | for (Driver driver : list) {//开始进行推送 |
| | | //查询是否在限制推单范围内 |
| | | boolean bo = false; |
| | | for (Integer integer : integers) { |
| | | if (integer.compareTo(driver.getId()) == 0) { |
| | | bo = true; |
| | | break; |
| | | } |
| | | } |
| | | if (bo) { |
| | | continue; |
| | | } |
| | | pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime()); |
| | | } |
| | | if (bo) { |
| | | continue; |
| | | } |
| | | pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime()); |
| | | } |
| | | Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间 |
| | | OrderPrivateCar orderTaxi1 = orderPrivateCarService.selectById(orderTaxi.getId()); |
| | | if(null == orderTaxi1){ |
| | | break; |
| | | } |
| | | Integer state = orderTaxi1.getState(); |
| | | if (state != 1) { |
| | | push = true; |
| | | break; |
| | | } |
| | | if (num == 18 && state == 1) { |
| | | orderTaxi1.setState(10); |
| | | orderPrivateCarService.updateById(orderTaxi1); |
| | | pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 1); |
| | | orderIds.remove(orderTaxi.getId()); |
| | | } |
| | | } |
| | | Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间 |
| | | OrderPrivateCar orderTaxi1 = orderPrivateCarService.selectById(orderTaxi.getId()); |
| | | if(null == orderTaxi1){ |
| | | if(push){ |
| | | break; |
| | | } |
| | | Integer state = orderTaxi1.getState(); |
| | | if (state != 1) { |
| | | push = true; |
| | | break; |
| | | } |
| | | if (num == 18 && state == 1) { |
| | | orderTaxi1.setState(10); |
| | | orderPrivateCarService.updateById(orderTaxi1); |
| | | pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2, 1); |
| | | orderIds.remove(orderTaxi.getId()); |
| | | } |
| | | } |
| | | if(push){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | |
| | | |
| | | private Integer isPromotion(Integer userId, String code){ |
| | | UserInfo userInfo = userInfoService.selectById(userId); |
| | | if(userInfo.getBindDriverId()!=null && userInfo.getBindExpireDate().getTime()>=System.currentTimeMillis()){ |
| | | TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", code) |
| | | .eq("state",1).le("startTime", new Date()).ge("endTime", new Date()).last("AND FIND_IN_SET(" + 1 + ", bizType) limit 1")); |
| | | if(tDriverPromotionActivity!=null){ |
| | | return userInfo.getBindDriverId(); |
| | | } |
| | | } |
| | | return null; |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized String getOrderNum() throws Exception { |