liujie
8 天以前 086fd5d2392b9028cf1159aec7cd47ddd1eb4d07
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;
@@ -66,6 +63,9 @@
    })
    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());
@@ -140,19 +140,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());