| | |
| | | * @param order |
| | | */ |
| | | public void pushOrder(Order order){ |
| | | try { |
| | | boolean lock = redisUtil.lock(5); |
| | | if(!lock){ |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock(5); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 1.先找最大推单范围内的优推司机 -》 距离最近 |
| | | * 没有1 - 》 |
| | |
| | | */ |
| | | SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1)); |
| | | if(null == systemConfig){ |
| | | redisUtil.unlock(); |
| | | return; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); |
| | |
| | | Double score = null; |
| | | Double d = null; |
| | | for (Driver driver1 : drivers) { |
| | | String value = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | continue; |
| | | } |
| | | DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); |
| | | if(null == driverWork){ |
| | | continue; |
| | |
| | | continue; |
| | | } |
| | | if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离 |
| | | String value = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | | if(ToolUtil.isEmpty(value)){ |
| | | String value1 = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | | if(ToolUtil.isEmpty(value1)){ |
| | | continue; |
| | | } |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(value1, order.getStartLng() + "," + order.getStartLat()); |
| | | Double wgs84 = distance.get("WGS84"); |
| | | if(d == null || d.compareTo(wgs84) > 0){ |
| | | d = wgs84; |
| | |
| | | } |
| | | |
| | | if(null != driver){ |
| | | //防止多笔订单推给一个司机 |
| | | Driver driver1 = driverService.selectById(driver); |
| | | driver1.setServerStatus(2); |
| | | driverService.updateById(driver1); |
| | | pushUtil.pushGrabOrder(driver, 2, order.getId(), num4); |
| | | //创建定时任务处理订单到大厅 |
| | | new Timer().schedule(new TimerTask() { |
| | |
| | | if(order1.getState() == 101 || order1.getState() == 201){ |
| | | order1.setHallOrder(1); |
| | | OrderServiceImpl.this.updateById(order1); |
| | | |
| | | driver1.setServerStatus(1); |
| | | driverService.updateById(driver1); |
| | | ExtraPushOrder(order); |
| | | } |
| | | } |
| | | }, num4 * 1000); |
| | | }else{ |
| | | order.setHallOrder(1); |
| | | this.updateById(order); |
| | | ExtraPushOrder(order); |
| | | } |
| | | redisUtil.unlock(); |
| | | }catch (Exception e){ |
| | | redisUtil.unlock(); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void ExtraPushOrder(Order order){ |
| | | String startLat = order.getStartLat(); |
| | | String startLng = order.getStartLng(); |
| | | |
| | | //找到中心点 |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat)); |
| | | Double num = 5D;//范围公里 |
| | | //构造半径 |
| | | Distance distanceR = new Distance(num, Metrics.KILOMETERS); |
| | | //画圆 |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | // 构造query对象 |
| | | Query query = Query.query(Criteria.where("location").withinSphere(circle)); |
| | | List<Location> locations = mongoTemplate.find(query, Location.class); |
| | | List<Integer> driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); |
| | | if(driverIds.size() == 0){ |
| | | return; |
| | | } |
| | | List<DriverWork> tDriverWorks = driverWorkService.selectList(new EntityWrapper<DriverWork>().in("driverId", driverIds).eq("status", 1)); |
| | | driverIds = tDriverWorks.stream().map(DriverWork::getDriverId).collect(Collectors.toList()); |
| | | List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2) |
| | | .eq("serverStatus", 1).eq("openOrderQRCode", 0).eq("status", 1).in("id", driverIds)); |
| | | if(drivers.size() == 0){ |
| | | return; |
| | | } |
| | | for (Driver driver1 : drivers) { |
| | | String value = redisUtil.getValue("DRIVER" + driver1.getId()); |
| | | if (ToolUtil.isEmpty(value)) { |
| | | return; |
| | | } |
| | | pushUtil.pushGrabOrderExtras(driver1.getId(), 2); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | if(count > 0){ |
| | | return ResultUtil.error("还有未完成的订单"); |
| | | } |
| | | boolean lock = redisUtil.lock(); |
| | | boolean lock = redisUtil.lock(5); |
| | | if(!lock){ |
| | | return ResultUtil.error("请重试"); |
| | | int num1 = 1; |
| | | while (num1 <= 10){ |
| | | Thread.sleep(3000);//等待3秒 |
| | | lock = redisUtil.lock(5); |
| | | if(lock){ |
| | | break; |
| | | }else{ |
| | | num1++; |
| | | } |
| | | } |
| | | } |
| | | Order order = this.selectById(orderId); |
| | | Integer state = order.getState(); |