puzhibing
2023-06-13 44c2d6a14afc95239f19c41c311abb5df7d89e0e
修改bug
7个文件已修改
719 ■■■■■ 已修改文件
driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java 326 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PushUtil.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
management/guns-admin/src/main/webapp/WEB-INF/view/system/tAgent/enterprisePage.html 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java 294 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
user/guns-admin/src/main/resources/application.yml 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
user/guns-admin/src/main/resources/redis.properties 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/service/impl/OrderServiceImpl.java
@@ -428,27 +428,187 @@
     * @param order
     */
    public void pushOrder(Order order){
        /**
         * 1.先找最大推单范围内的优推司机 -》 距离最近
         * 没有1 - 》
         *      2.按照后台推送配置在范围内查找合适司机
         *        合适司:积分 > 评分 > 距离
         *      3.司机没有接单直接将订单置入大厅
         */
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 1));
        if(null == systemConfig){
            return;
        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 - 》
             *      2.按照后台推送配置在范围内查找合适司机
             *        合适司:积分 > 评分 > 距离
             *      3.司机没有接单直接将订单置入大厅
             */
            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().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();
            //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;
            YouTuiDriver youTuiDriver1 = null;
            if(driverIds.size() > 0){
                List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
                        .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
                Double d = null;
                for (YouTuiDriver youTuiDriver : youTuiDrivers) {
                    String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
                    if(ToolUtil.isEmpty(value)){
                        continue;
                    }
                    DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", youTuiDriver.getDriverId()).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;
                    }
                }
            }
            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<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("serverStatus", 1).eq("status", 1).in("id", driverIds));
                        if(drivers.size() == 0){
                            continue;
                        }
                        Integer integral = null;
                        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;
                            }
                            if(integral == null || integral.compareTo(driver1.getIntegral()) < 0){//积分大
                                integral = driver1.getIntegral();
                                score = driver1.getScore();
                                driver = driver1.getId();
                                continue;
                            }
                            if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分
                                integral = driver1.getIntegral();
                                score = driver1.getScore();
                                driver = driver1.getId();
                                continue;
                            }
                            if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
                                String value1 = redisUtil.getValue("DRIVER" + driver1.getId());
                                if(ToolUtil.isEmpty(value1)){
                                    continue;
                                }
                                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;
                                    driver = driver1.getId();
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            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() {
                    @Override
                    public void run() {
                        Order order1 = OrderServiceImpl.this.selectById(order.getId());
                        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();
        }
        JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
        Double num3 = jsonObject.getDouble("num3");//推单最大范围
        Integer num4 = jsonObject.getInteger("num4");//接单时间
    }
    public void ExtraPushOrder(Order order){
        String startLat = order.getStartLat();
        String startLng = order.getStartLng();
        //1
        //找到中心点
        GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.valueOf(startLng), Double.valueOf(startLat));
        Double num = num3 / 1000;//范围公里
        Double num = 5D;//范围公里
        //构造半径
        Distance distanceR = new Distance(num, Metrics.KILOMETERS);
        //画圆
@@ -457,115 +617,26 @@
        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;
        YouTuiDriver youTuiDriver1 = null;
        if(driverIds.size() > 0){
            List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
                    .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
            Double d = null;
            for (YouTuiDriver youTuiDriver : youTuiDrivers) {
                String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
                if(ToolUtil.isEmpty(value)){
                    continue;
                }
                DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().eq("driverId", youTuiDriver.getDriverId()).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;
                }
        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;
            }
        }
        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<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().eq("approvalStatus", 2).eq("serverStatus", 1).eq("status", 1).in("id", driverIds));
                    if(drivers.size() == 0){
                        continue;
                    }
                    Integer integral = null;
                    Double score = null;
                    Double d = null;
                    for (Driver driver1 : drivers) {
                        DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().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();
                            continue;
                        }
                        if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) < 0){//积分相同对比评分
                            integral = driver1.getIntegral();
                            score = driver1.getScore();
                            driver = driver1.getId();
                            continue;
                        }
                        if(integral.compareTo(driver1.getIntegral()) == 0 && score.compareTo(driver1.getScore()) == 0){//积分相同/评分相同对比距离
                            String value = redisUtil.getValue("DRIVER" + driver1.getId());
                            if(ToolUtil.isEmpty(value)){
                                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 = driver1.getId();
                                continue;
                            }
                        }
                    }
                }
            }
        }
        if(null != driver){
            pushUtil.pushGrabOrder(driver, 2, order.getId(), num4);
            //创建定时任务处理订单到大厅
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    Order order1 = OrderServiceImpl.this.selectById(order.getId());
                    if(order1.getState() == 101 || order1.getState() == 201){
                        order1.setHallOrder(1);
                        OrderServiceImpl.this.updateById(order1);
                    }
                }
            }, num4 * 1000);
        }else{
            order.setHallOrder(1);
            this.updateById(order);
            pushUtil.pushGrabOrderExtras(driver1.getId(), 2);
        }
    }
@@ -668,9 +739,18 @@
            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();
driver/guns-admin/src/main/java/com/supersavedriving/driver/modular/system/util/PushUtil.java
@@ -164,6 +164,43 @@
    }
    /**
     * 系统推单推送 附加(防止 用户推单后,范围内的司机20s 内接不到单的补充方法)
     * @param id            接受对象id
     * @param type          接受对象类型(1=用户,2=司机)
     */
    public void pushGrabOrderExtras(Integer id, Integer type){
        JSONObject msg = new JSONObject();
        msg.put("code", 200);
        msg.put("msg", "SUCCESS");
        msg.put("method", "PUSH_ORDER");
        Map<String, Object> map = new HashMap<>();
        msg.put("data", map);
        //调用推送
        HttpHeaders headers = new HttpHeaders();
        // 以表单的方式提交
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        //将请求头部和参数合成一个请求
        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        params.add("msg", msg.toJSONString());
        params.add("id", id.toString());
        params.add("type", type.toString());
        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
        if(jsonObject1.getIntValue("code") != 200){
            logger.debug(jsonObject1.getString("msg"));
            System.err.println(jsonObject1.getString("msg"));
        }
    }
    /**
     * 推送订单数据
     * @param id
management/guns-admin/src/main/webapp/WEB-INF/view/system/tAgent/enterprisePage.html
@@ -71,7 +71,7 @@
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">*公司名称:</label>
                        <label class="col-sm-3 control-label">*姓名:</label>
                        <div class="col-sm-9">
                            <input class="form-control" id="merchantName" name="merchantName" value="${item.merchantName}" type="text" maxlength="20" placeholder="请输入">
                        </div>
@@ -140,8 +140,8 @@
                            <input class="form-control" id="legalPerson" name="legalPerson" value="${item.legalPerson}" type="text" maxlength="20" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group qy">
                        <label class="col-sm-3 control-label">*法人身份证号:</label>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">*身份证号:</label>
                        <div class="col-sm-9">
                            <input class="form-control" id="merchantIDCode" name="merchantIDCode" value="${item.merchantIDCode}" type="text" maxlength="20" placeholder="请输入">
                        </div>
@@ -294,12 +294,16 @@
        if(userType == 0){
            $('.qy').hide();
            $('#bankAcctType').html('<option value="2">对私</option>')
            $('#merchantIDCode').parent('div').siblings('label').text('*身份证号')
            $('#merchantName').parent('div').siblings('label').text('*姓名')
        }else{
            $('.qy').show();
            $('#bankAcctType').html('<option value="1">对公</option>')
            $('#merchantIDCode').parent('div').siblings('label').text('*法人身份证号')
            $('#merchantName').parent('div').siblings('label').text('*公司名称')
        }
    })
    $('#userType').click();
    function initCity(id) {
        let city = "";
@@ -439,6 +443,8 @@
        $('#provCodeEnterprise').val($('#provCodeEnterprise1').val());
        initArea($('#provCodeEnterprise'), 'areaCodeEnterprise');
        $('#areaCodeEnterprise').val($('#areaCodeEnterprise1').val());
        $('#userType').change();
    })
</script>
@}
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java
@@ -191,12 +191,22 @@
                appUser.setInviterType(signInToRegister.getInviterType());
                this.insert(appUser);
                //发送优惠券
                boolean lock = redisUtil.lock();
                if(lock){
                    List<CouponWarpper> list = pushCoupon(appUser.getId());
                    redisUtil.unlock();
                    warpper.setCoupons(list);
                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++;
                        }
                    }
                }
                List<CouponWarpper> list = pushCoupon(appUser.getId());
                redisUtil.unlock();
                warpper.setCoupons(list);
            }
            if(appUser.getStatus() == 2){
                return ResultUtil.error("账号被冻结");
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/OrderServiceImpl.java
@@ -499,159 +499,187 @@
     * 订单推送逻辑
     */
    public void pushOrder(Long orderId){
        Order order = this.selectById(orderId);
        /**
         * 1.先找最大推单范围内的优推司机 -》 距离最近
         * 没有1 - 》
         *      2.按照后台推送配置在范围内查找合适司机
         *        合适司:积分 > 评分 > 距离
         *      3.司机没有接单直接将订单置入大厅
         */
        SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().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;
        YouTuiDriver youTuiDriver1 = null;
        if(driverIds.size() > 0){
            List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
                    .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
            Double d = null;
            for (YouTuiDriver youTuiDriver : youTuiDrivers) {
                String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
                if(ToolUtil.isEmpty(value)){
                    continue;
                }
                Driver driver1 = driverService.selectById(youTuiDriver.getDriverId());
                if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){
                    continue;
                }
                DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().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(null != youTuiDriver1 && youTuiDriver1.getType() == 1){
            youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1);
            youTuiDriverService.updateById(youTuiDriver1);
        }
            Order order = this.selectById(orderId);
            /**
             * 1.先找最大推单范围内的优推司机 -》 距离最近
             * 没有1 - 》
             *      2.按照后台推送配置在范围内查找合适司机
             *        合适司:积分 > 评分 > 距离
             *      3.司机没有接单直接将订单置入大厅
             */
            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().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 == 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<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){
            //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;
            YouTuiDriver youTuiDriver1 = null;
            if(driverIds.size() > 0){
                List<YouTuiDriver> youTuiDrivers = youTuiDriverService.selectList(new EntityWrapper<YouTuiDriver>().in("driverId", driverIds)
                        .eq("state", 2).last(" and (surplusQuantity > 0 or now() < endTime) and now() < failureTime"));
                Double d = null;
                for (YouTuiDriver youTuiDriver : youTuiDrivers) {
                    String value = redisUtil.getValue("DRIVER" + youTuiDriver.getDriverId());
                    if(ToolUtil.isEmpty(value)){
                        continue;
                    }
                    Driver driver1 = driverService.selectById(youTuiDriver.getDriverId());
                    if(driver1.getServerStatus() == 2 || driver1.getOpenOrderQRCode() == 1){
                        continue;
                    }
                    DriverWork driverWork = driverWorkService.selectOne(new EntityWrapper<DriverWork>().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;
                    }
                }
            }
            if(null != youTuiDriver1 && youTuiDriver1.getType() == 1){
                youTuiDriver1.setSurplusQuantity(youTuiDriver1.getSurplusQuantity() - 1);
                youTuiDriverService.updateById(youTuiDriver1);
            }
                    Integer integral = null;//积分
                    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){
            //开始范围查找
            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<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){
                            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 (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;
                            }
                            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){
                //防止多笔订单推给一个司机
                Driver driver1 = driverService.selectById(driver);
                driver1.setServerStatus(2);
                driverService.updateById(driver1);
                pushUtil.pushGrabOrder(driver, 2, order.getId(), num4);
                //创建定时任务处理订单到大厅
                new Timer().schedule(new TimerTask() {
                    @Override
                    public void run() {
                        Order order1 = OrderServiceImpl.this.selectById(order.getId());
                        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){
            e.printStackTrace();
            redisUtil.unlock();
        }
        if(null != driver){
            pushUtil.pushGrabOrder(driver, 2, order.getId(), num4);
            //创建定时任务处理订单到大厅
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    Order order1 = OrderServiceImpl.this.selectById(order.getId());
                    if(order1.getState() == 101 || order1.getState() == 201){
                        order1.setHallOrder(1);
                        OrderServiceImpl.this.updateById(order1);
                        ExtraPushOrder(order);
                    }
                }
            }, num4 * 1000);
        }else{
            order.setHallOrder(1);
            this.updateById(order);
            ExtraPushOrder(order);
        }
    }
user/guns-admin/src/main/resources/application.yml
@@ -13,8 +13,8 @@
  application:
    name: user-server
  profiles:
    active: dev
#    active: produce
#    active: dev
    active: produce
  mvc:
    static-path-pattern: /static/**
    view:
@@ -53,7 +53,7 @@
spring:
  datasource:
    url: jdbc:mysql://121.37.15.157:3306/super_save_driving?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=Asia/Shanghai
    url: jdbc:mysql://127.0.0.1:3306/super_save_driving?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: f4OfRjqoN3jSiNGiUoiNsQdOBtCOKYRj
#    password: 123456
@@ -130,8 +130,8 @@
spring:
  data:
    mongodb:
#      uri: mongodb://root:CEtyLdKjPk0yeHNo@127.0.0.1:27017/admin
      uri: mongodb://127.0.0.1:27017/admin
      uri: mongodb://root:CEtyLdKjPk0yeHNo@127.0.0.1:27017/admin
#      uri: mongodb://127.0.0.1:27017/admin
#  mallbook 调起接口参数配置
user/guns-admin/src/main/resources/redis.properties
@@ -2,19 +2,19 @@
# RedisÊý¾Ý¿âË÷Òý£¨Ä¬ÈÏΪ0£©
spring.redis.database=0
## Redis·þÎñÆ÷µØÖ·
#spring.redis.host=127.0.0.1
## Redis·þÎñÆ÷Á¬½Ó¶Ë¿Ú
#spring.redis.port=16379
## Redis·þÎñÆ÷Á¬½ÓÃÜÂ루ĬÈÏΪ¿Õ£©
#spring.redis.password=cKsEeyffDXG5PzNg8CIbrWxFluXrCprZ
# Redis·þÎñÆ÷µØÖ·
spring.redis.host=127.0.0.1
# Redis·þÎñÆ÷Á¬½Ó¶Ë¿Ú
spring.redis.port=6379
spring.redis.port=16379
# Redis·þÎñÆ÷Á¬½ÓÃÜÂ루ĬÈÏΪ¿Õ£©
spring.redis.password=123456
spring.redis.password=cKsEeyffDXG5PzNg8CIbrWxFluXrCprZ
## Redis·þÎñÆ÷µØÖ·
#spring.redis.host=127.0.0.1
## Redis·þÎñÆ÷Á¬½Ó¶Ë¿Ú
#spring.redis.port=6379
## Redis·þÎñÆ÷Á¬½ÓÃÜÂ루ĬÈÏΪ¿Õ£©
#spring.redis.password=123456
# Á¬½Ó³Ø×î´óÁ¬½ÓÊý£¨Ê¹ÓøºÖµ±íʾûÓÐÏÞÖÆ£©
spring.redis.jedis.pool.max-active=1024