From 3f06b9de8009c1f0c16ee1996a4a8d03483fcd5b Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 20 六月 2023 16:59:05 +0800 Subject: [PATCH] 修改反馈bug --- management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TOrderServiceImpl.java | 286 ++++++++++++++++++++++++++++++++------------------------- 1 files changed, 161 insertions(+), 125 deletions(-) diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TOrderServiceImpl.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TOrderServiceImpl.java index 2d71020..fd21548 100644 --- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TOrderServiceImpl.java +++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TOrderServiceImpl.java @@ -732,153 +732,189 @@ * 合适司:积分 > 评分 > 距离 * 3.司机没有接单直接将订单置入大厅 */ - TSystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<TSystemConfig>().eq("type", 1)); - if(null == systemConfig){ - return; - } - JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); - Double num3 = jsonObject.getDouble("num3");//推单最大范围 - Integer num4 = jsonObject.getInteger("num4");//接单时间 - String startLat = order.getStartLat(); - String startLng = order.getStartLng(); - - //1 - //找到中心点 - GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat)); - Double num = num3 / 1000;//范围公里 - //构造半径 - 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()); - Integer driver = null; - TYouTuiDriver youTuiDriver1 = null; - if(driverIds.size() > 0){ - List<TYouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<TYouTuiDriver>().in("driverId", driverIds) - .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime")); - Double d = null; - for (TYouTuiDriver youTuiDriver : youTuiDrivers) { - String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId()); - if(ToolUtil.isEmpty(value)){ - continue; - } - TDriver driver1 = driverService.selectById(youTuiDriver.getDriverId()); - if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){ - continue; - } - TDriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<TDriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); - if(null == driverWork){ - continue; - } - Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); - Double wgs84 = distance.get("WGS84"); - if(d == null || d.compareTo(wgs84) > 0){ - d = wgs84; - driver = youTuiDriver.getDriverId(); - youTuiDriver1 = youTuiDriver; + 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++; + } } } - } + if(!lock){ + redisUtil.unlock(); + order.setHallOrder(1); + this.updateById(order); + ExtraPushOrder(order); + return; + } + TSystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<TSystemConfig>().eq("type", 1)); + if(null == systemConfig){ + redisUtil.unlock(); + return; + } + JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); + Double num3 = jsonObject.getDouble("num3");//推单最大范围 + Integer num4 = jsonObject.getInteger("num4");//接单时间 + String startLat = order.getStartLat(); + String startLng = order.getStartLng(); - if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){ - youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1); - youTuiDriverService.updateById(youTuiDriver1); - } - - //开始范围查找 - if(null == driver){ - for (int i = 1; i < 4; i++) { - if(null != driver){ - break; - } - num = jsonObject.getDouble("num" + i) / 1000;//范围公里 - //构造半径 - distanceR = new Distance(num, Metrics.KILOMETERS); - //画圆 - circle = new Circle(geoJsonPoint, distanceR); - // 构造query对象 - query = Query.query(Criteria.where("location").withinSphere(circle)); - locations = mongoTemplate.find(query, Location.class); - - driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); - if(driverIds.size() > 0){ - List<TDriver> drivers = driverService.selectList(new EntityWrapper<TDriver>().eq("approvalStatus", 2) - .eq("serverStatus", 1).eq("openOrderQRCode", 0).eq("status", 1).in("id", driverIds)); - if(drivers.size() == 0){ + //1 + //找到中心点 + GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat)); + Double num = num3 / 1000;//范围公里 + //构造半径 + 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()); + Integer driver = null; + TYouTuiDriver youTuiDriver1 = null; + if(driverIds.size() > 0){ + List<TYouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<TYouTuiDriver>().in("driverId", driverIds) + .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime")); + Double d = null; + for (TYouTuiDriver youTuiDriver : youTuiDrivers) { + String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId()); + if(ToolUtil.isEmpty(value)){ continue; } + TDriver driver1 = driverService.selectById(youTuiDriver.getDriverId()); + if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){ + continue; + } + TDriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<TDriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); + if(null == driverWork){ + continue; + } + Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); + Double wgs84 = distance.get("WGS84"); + if(d == null || d.compareTo(wgs84) > 0){ + d = wgs84; + driver = youTuiDriver.getDriverId(); + youTuiDriver1 = youTuiDriver; + } + } + } - Integer integral = null; - Double score = null; - Double d = null; - for (TDriver driver1 : drivers) { - String value = redisUtil.getValue("DRIVER" + driver1.getId()); - if(ToolUtil.isEmpty(value)){ - continue; - } - TDriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<TDriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); - if(null == driverWork){ + if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){ + youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1); + youTuiDriverService.updateById(youTuiDriver1); + } + + //开始范围查找 + if(null == driver){ + for (int i = 1; i < 4; i++) { + if(null != driver){ + break; + } + num = jsonObject.getDouble("num" + i) / 1000;//范围公里 + //构造半径 + distanceR = new Distance(num, Metrics.KILOMETERS); + //画圆 + circle = new Circle(geoJsonPoint, distanceR); + // 构造query对象 + query = Query.query(Criteria.where("location").withinSphere(circle)); + locations = mongoTemplate.find(query, Location.class); + + driverIds = locations.stream().map(Location::getDriverId).collect(Collectors.toList()); + if(driverIds.size() > 0){ + List<TDriver> drivers = driverService.selectList(new EntityWrapper<TDriver>().eq("approvalStatus", 2) + .eq("serverStatus", 1).eq("openOrderQRCode", 0).eq("status", 1).in("id", driverIds)); + if(drivers.size() == 0){ continue; } - if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大 - integral = driver1.getIntegral(); - score = driver1.getScore(); - driver = driver1.getId(); - Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); - Double wgs84 = distance.get("WGS84"); - d = wgs84; - continue; - } - if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分 - integral = driver1.getIntegral(); - score = driver1.getScore(); - driver = driver1.getId(); - Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); - Double wgs84 = distance.get("WGS84"); - d = wgs84; - continue; - } - if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离 - Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); - Double wgs84 = distance.get("WGS84"); - if(d.compareTo(wgs84) > 0){ - d = wgs84; + Integer integral = null; + Double score = null; + Double d = null; + for (TDriver driver1 : drivers) { + String value = redisUtil.getValue("DRIVER" + driver1.getId()); + if(ToolUtil.isEmpty(value)){ + continue; + } + TDriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<TDriverWork>().eq("driverId", driver1.getId()).eq("status", 1)); + if(null == driverWork){ + continue; + } + + if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大 integral = driver1.getIntegral(); score = driver1.getScore(); driver = driver1.getId(); + Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); + Double wgs84 = distance.get("WGS84"); + d = wgs84; continue; } + if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分 + integral = driver1.getIntegral(); + score = driver1.getScore(); + driver = driver1.getId(); + Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); + Double wgs84 = distance.get("WGS84"); + d = wgs84; + continue; + } + if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离 + Map<String, Double> distance = GeodesyUtil.getDistance(value, order.getStartLng() + "," + order.getStartLat()); + Double wgs84 = distance.get("WGS84"); + if(d.compareTo(wgs84) > 0){ + d = wgs84; + integral = driver1.getIntegral(); + score = driver1.getScore(); + driver = driver1.getId(); + continue; + } + } } - } + } } } - } - if(null != driver){ - pushUtil.pushGrabOrder(driver, 2, order.getId(), num4); - //创建定时任务处理订单到大厅 - new Timer().schedule(new TimerTask() { - @Override - public void run() { - TOrder order1 = TOrderServiceImpl.this.selectById(order.getId()); - if(order1.getState() == 101 || order1.getState() == 201){ - order1.setHallOrder(1); - TOrderServiceImpl.this.updateById(order1); + if(null != driver){ + TDriver tDriver = driverService.selectById(driver); + tDriver.setServerStatus(2); + driverService.updateById(tDriver); - ExtraPushOrder(order1); + pushUtil.pushGrabOrder(driver, 2, order.getId(), num4); + //创建定时任务处理订单到大厅 + new Timer().schedule(new TimerTask() { + @Override + public void run() { + TOrder order1 = TOrderServiceImpl.this.selectById(order.getId()); + if(order1.getState() == 101 || order1.getState() == 201){ + tDriver.setServerStatus(1); + driverService.updateById(tDriver); + + order1.setHallOrder(1); + TOrderServiceImpl.this.updateById(order1); + + ExtraPushOrder(order1); + } } - } - }, num4 * 1000); - }else{ - order.setHallOrder(1); - this.updateById(order); - 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(TOrder order){ -- Gitblit v1.7.1