liujie
2023-08-10 aa241a47c90ed776062adf0b8daccf288a21836f
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/DriverServiceImpl.java
@@ -65,19 +65,27 @@
        // 构造query对象
        Query query = Query.query(Criteria.where("location").withinSphere(circle));
        List<Location> locations = mongoTemplate.find(query, Location.class);
//        System.err.println("附近空闲司机" + JSON.toJSONString(locations));
        List<Integer> collect = locations.stream().map(Location::getDriverId).collect(Collectors.toList());
        if(collect.size() == 0){
            return list;
        }
        List<Driver> drivers = this.selectList(new EntityWrapper<Driver>().in("id", collect).eq("approvalStatus", 2).eq("serverStatus", 1).eq("status", 1));
        collect = drivers.stream().map(Driver::getId).collect(Collectors.toList());
        if(collect.size() == 0){
            return list;
        }
        List<DriverWork> driverWorks = driverWorkService.selectList(new EntityWrapper<DriverWork>().in("driverId", collect).eq("status", 1));
        for (DriverWork driverWork : driverWorks) {
            String value = redisUtil.getValue("DRIVER" + driverWork.getDriverId());
            if(ToolUtil.isNotEmpty(value)){
                NearbyDriverWarpper nearbyDriverWarpper = new NearbyDriverWarpper();
                nearbyDriverWarpper.setLonLat(value);
                Map<String, Double> distance = GeodesyUtil.getDistance(value, lon + "," + lat);
                nearbyDriverWarpper.setDistance(distance.get("WGS84") / 1000);
                nearbyDriverWarpper.setDriverId(driverWork.getDriverId());
                list.add(nearbyDriverWarpper);
            if(ToolUtil.isEmpty(value)){
                continue;
            }
            NearbyDriverWarpper nearbyDriverWarpper = new NearbyDriverWarpper();
            nearbyDriverWarpper.setLonLat(value);
            Map<String, Double> distance = GeodesyUtil.getDistance(value, lon + "," + lat);
            nearbyDriverWarpper.setDistance(distance.get("WGS84") / 1000);
            nearbyDriverWarpper.setDriverId(driverWork.getDriverId());
            list.add(nearbyDriverWarpper);
        }
        return list;
    }