liujie
2025-08-01 a0a814be1a2cff11a4eea699930b7df4b56ccacb
UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/api/DriverController.java
@@ -14,12 +14,9 @@
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;
@@ -140,19 +137,15 @@
    })
    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());