Pu Zhibing
7 天以前 db0aaa2033a43c016ca165513faaee993117ecf8
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -526,24 +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{
                        //推单
                        pushOrder(order.getId());
                    }
                    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){
@@ -560,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);
            /**
@@ -571,12 +582,12 @@
             *        合适司:积分 > 评分 > 距离
             *      3.司机没有接单直接将订单置入大厅
             */
            boolean lock2 = lock1.tryLock(5, 10, TimeUnit.SECONDS);
            if(!lock2){
                order.setHallOrder(1);
                this.updateById(order);
                ExtraPushOrder(order);
            }
//            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){
                return;
@@ -725,6 +736,7 @@
            }
            if(null != driver){
                System.err.println("完成司机查找:" + driver);
                //防止多笔订单推给一个司机
                Driver driver1 = driverService.selectById(driver);
                driver1.setServerStatus(2);
@@ -769,7 +781,7 @@
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            lock1.unlock();
//            lock1.unlock();
        }
    }