| | |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.geo.GeoResult; |
| | | import org.springframework.data.geo.GeoResults; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.NearQuery; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | }) |
| | | public ResultUtil<BaseWarpper> queryIdleDriver(Integer type, Double lon, Double lat){ |
| | | try { |
| | | if(type==2){ |
| | | type=null; |
| | | } |
| | | List<Driver> list = driverService.queryIdleDriver(type, lon, lat, 5D, null); |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setNumber(list.size()); |
| | |
| | | }) |
| | | public ResultUtil<List<Map<String, Object>>> queryNearbyCar(String lon, String lat){ |
| | | //mongodb查询附近5公里范围内的坐标 |
| | | NearQuery query = NearQuery.near(new Point(Double.parseDouble(lon), Double.parseDouble(lat))); |
| | | query.query(Query.query(Criteria.where("point"))); |
| | | query.maxDistance(5000); |
| | | GeoResults<DriverPosition> results = mongoTemplate.geoNear(query, DriverPosition.class); |
| | | Query query = Query.query(Criteria.where("point").nearSphere(new Point(Double.parseDouble(lon), Double.parseDouble(lat))).maxDistance(5000)); |
| | | List<DriverPosition> driverPositions = mongoTemplate.find(query, DriverPosition.class); |
| | | List<Map<String, Object>> collect = new ArrayList<>(); |
| | | if(collect.size() > 0){ |
| | | List<GeoResult<DriverPosition>> content1 = results.getContent(); |
| | | List<DriverPosition> positionList = content1.stream().map(GeoResult::getContent).collect(Collectors.toList()); |
| | | List<Integer> driverIds = positionList.stream().map(DriverPosition::getDriverId).collect(Collectors.toList()); |
| | | List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().in("driverId", driverIds) |
| | | if(driverPositions.size() > 0){ |
| | | List<Integer> driverIds = driverPositions.stream().map(DriverPosition::getDriverId).collect(Collectors.toList()); |
| | | List<Driver> drivers = driverService.selectList(new EntityWrapper<Driver>().in("id", driverIds) |
| | | .eq("authState", 2).eq("state", 2)); |
| | | collect = drivers.stream().map(driver -> { |
| | | Optional<DriverPosition> driverPosition = positionList.stream().filter(position -> position.getDriverId().equals(driver.getId())).findFirst(); |
| | | Optional<DriverPosition> driverPosition = driverPositions.stream().filter(position -> position.getDriverId().equals(driver.getId())).findFirst(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("driverId", driver.getId()); |
| | | map.put("name", driver.getName()); |