| | |
| | | package com.stylefeng.guns.modular.api; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.modular.system.model.Driver; |
| | | import com.stylefeng.guns.modular.system.service.IDriverService; |
| | | import com.stylefeng.guns.modular.system.service.IOrderEvaluateService; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.stylefeng.guns.modular.system.warpper.BaseWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.DriverInfoWarpper; |
| | | import com.stylefeng.guns.modular.system.warpper.DriverPosition; |
| | | import com.stylefeng.guns.modular.system.warpper.OrderEvaluateWarpper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | 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; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 司机控制器 |
| | |
| | | |
| | | @Autowired |
| | | private IOrderEvaluateService orderEvaluateService; |
| | | |
| | | @Autowired |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | |
| | | |
| | |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @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){ |
| | | //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); |
| | | 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) |
| | | .eq("authState", 2).eq("state", 2)); |
| | | collect = drivers.stream().map(driver -> { |
| | | Optional<DriverPosition> driverPosition = positionList.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; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | return ResultUtil.success(collect); |
| | | } |
| | | } |