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 | 61 ++++++++++++++++-------------- 1 files changed, 32 insertions(+), 29 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 5e418be..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.*; @@ -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,8 +570,9 @@ /** * 订单推送逻辑 */ - public void pushOrder(Long orderId){ - RLock lock1 = redissonClient.getLock("pushOrder:" + orderId); + public void pushOrder(Long orderId, Integer uid){ + System.err.println("开始推单:" + orderId); +// RLock lock1 = redissonClient.getLock("pushOrder:" + uid); try { Order order = this.selectById(orderId); /** @@ -578,16 +582,14 @@ * 合适司:积分 > 评分 > 距离 * 3.司机没有接单直接将订单置入大厅 */ - boolean lock2 = lock1.tryLock(5, 10, TimeUnit.SECONDS); - if(!lock2){ - 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()); @@ -734,6 +736,7 @@ } if(null != driver){ + System.err.println("完成司机查找:" + driver); //防止多笔订单推给一个司机 Driver driver1 = driverService.selectById(driver); driver1.setServerStatus(2); @@ -778,7 +781,7 @@ }catch (Exception e){ e.printStackTrace(); }finally { - lock1.unlock(); +// lock1.unlock(); } } -- Gitblit v1.7.1