| | |
| | | import com.stylefeng.guns.modular.system.util.RedisUtil; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.GeoResult; |
| | | import org.springframework.data.redis.connection.RedisGeoCommands; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | |
| | | @Override |
| | | public List<Driver> queryDriverLimitTen(Integer type, Double lon, Double lat) { |
| | | List<Driver> drivers = driverMapper.queryIdleDriver(type, null); |
| | | if(CollectionUtils.isEmpty(drivers)){ |
| | | List<GeoResult<RedisGeoCommands.GeoLocation<String>>> driverPosition = redisUtil.getNearGeoSortAscending("DRIVER_POSITION", lon, lat, 5000D); |
| | | if(CollectionUtils.isEmpty(driverPosition)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<RedisGeoCommands.GeoLocation<String>> geoLocations = driverPosition.stream().map(GeoResult::getContent).collect(Collectors.toList()); |
| | | driverPosition.stream().map(GeoResult::getContent).collect(Collectors.toList()); |
| | | List<String> dis = geoLocations.stream().map(RedisGeoCommands.GeoLocation::getName).collect(Collectors.toList()); |
| | | List<Driver> drivers = driverMapper.queryIdleDriverByIds(type, dis); |
| | | Iterator<Driver> iterator = drivers.iterator(); |
| | | while (iterator.hasNext()){ |
| | | Driver driver = iterator.next(); |