From db0aaa2033a43c016ca165513faaee993117ecf8 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 22 八月 2025 12:14:14 +0800 Subject: [PATCH] 修改bug --- user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java | 76 +++++++++++++++++--------------------- 1 files changed, 34 insertions(+), 42 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java index b7090e1..d658f5c 100644 --- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java @@ -15,10 +15,8 @@ import com.supersavedriving.user.modular.system.util.MallBook.model.*; import com.supersavedriving.user.modular.system.util.MallBook.util.Transfer; import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest; -import com.supersavedriving.user.modular.system.util.juhe.WeatherUtil; import com.supersavedriving.user.modular.system.util.mongodb.model.Location; import com.supersavedriving.user.modular.system.warpper.*; -import io.swagger.models.auth.In; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.slf4j.Logger; @@ -37,9 +35,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; -import java.math.MathContext; import java.math.RoundingMode; -import java.net.InetAddress; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.*; @@ -440,7 +436,7 @@ @Override public ResultUtil travelOrder(Integer uid, TravelOrder travelOrder) throws Exception { RLock lock1 = redissonClient.getLock("travelOrder:" + uid); - boolean lock2 = lock1.tryLock(5, TimeUnit.SECONDS); + boolean lock2 = lock1.tryLock(5, 10, TimeUnit.SECONDS); if(!lock2){ return ResultUtil.error("系统繁忙,请稍后重试"); } @@ -530,27 +526,34 @@ appUserService.updateById(appUser); } + List<Order> orderList = new ArrayList<>(); for (Integer i = 0; i < travelOrder.getDriverNum(); i++) { order.setId(null); order.setCode(UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(5)); boolean insert = this.insert(order); if(insert){ - //推送状态 - pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState()); - if(null != order.getDriverId()){ - PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); - pushOrderInfoWarpper.setId(order.getId()); - pushOrderInfoWarpper.setState(order.getState()); - pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); - }else{ - //推单 - Order finalOrder = order; - new Thread(()->{ - pushOrder(finalOrder.getId()); - }).start(); - } + orderList.add(order); } } + new Thread(new Runnable() { + @Override + public void run() { + orderList.forEach(order -> { + //推送状态 + pushUtil.pushOrderStatus(uid, 1, order.getId(), order.getState()); + if(null != order.getDriverId()){ + PushOrderInfoWarpper pushOrderInfoWarpper = new PushOrderInfoWarpper(); + pushOrderInfoWarpper.setId(order.getId()); + pushOrderInfoWarpper.setState(order.getState()); + pushUtil.pushOrderInfo(order.getDriverId(), 2, pushOrderInfoWarpper); + }else{ + //推单 + pushOrder(order.getId(), uid); + } + }); + } + }).start(); + redisUtil.setStrValue("newOrder", "true"); return ResultUtil.success(order.getId()); }catch (Exception e){ @@ -567,7 +570,9 @@ /** * 订单推送逻辑 */ - public void pushOrder(Long orderId){ + public void pushOrder(Long orderId, Integer uid){ + System.err.println("开始推单:" + orderId); +// RLock lock1 = redissonClient.getLock("pushOrder:" + uid); try { Order order = this.selectById(orderId); /** @@ -577,28 +582,14 @@ * 合适司:积分 > 评分 > 距离 * 3.司机没有接单直接将订单置入大厅 */ - 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){ - order.setHallOrder(1); - this.updateById(order); - ExtraPushOrder(order); - redisUtil.unlock(); - } +// boolean lock2 = lock1.tryLock(5, 10, TimeUnit.SECONDS); +// if(!lock2){ +// order.setHallOrder(1); +// this.updateById(order); +// ExtraPushOrder(order); +// } SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1)); if(null == systemConfig){ - redisUtil.unlock(); return; } JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); @@ -745,6 +736,7 @@ } if(null != driver){ + System.err.println("完成司机查找:" + driver); //防止多笔订单推给一个司机 Driver driver1 = driverService.selectById(driver); driver1.setServerStatus(2); @@ -786,10 +778,10 @@ ExtraPushOrder(order); redisUtil.setStrValue("lobbyOrder", "true"); } - redisUtil.unlock(); }catch (Exception e){ e.printStackTrace(); - redisUtil.unlock(); + }finally { +// lock1.unlock(); } } -- Gitblit v1.7.1