| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.geo.Circle; |
| | | import org.springframework.data.geo.Distance; |
| | | import org.springframework.data.geo.Metrics; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/driver/queryNearbyCar") |
| | | @ApiOperation(value = "首页查询5公里范围内的车辆位置", tags = {"司机端-首页"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "String"), |
| | | @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "String") |
| | | }) |
| | | public ResultUtil<List<Map<String, Object>>> queryNearbyCar(String lon, String lat){ |
| | | GeoJsonPoint geoJsonPoint = new GeoJsonPoint(Double.parseDouble(lon), Double.parseDouble(lat)); |
| | | Distance distanceR = new Distance(5, Metrics.KILOMETERS); |
| | | Circle circle = new Circle(geoJsonPoint, distanceR); |
| | | Query query = Query.query(Criteria.where("point").withinSphere(circle)); |
| | | List<DriverPosition> driverPositions = mongoTemplate.find(query, DriverPosition.class); |
| | | |
| | | List<Map<String, Object>> collect = new ArrayList<>(); |
| | | 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 -> { |
| | | String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + driver.getId()); |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | 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()); |
| | | map.put("lot", driverPosition.isPresent() ? driverPosition.get().getPoint().getX() : ""); |
| | | map.put("lat", driverPosition.isPresent() ? driverPosition.get().getPoint().getY() : ""); |
| | | return map; |
| | | } |
| | | return null; |
| | | }).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | } |
| | | return ResultUtil.success(collect); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/driver/queryOrderDataFromDriver") |