| | |
| | | import org.springframework.context.i18n.LocaleContextHolder; |
| | | import org.springframework.data.geo.Point; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.geo.GeoJsonPoint; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | } |
| | | |
| | | for (XpVehicleVO xpVehicleVO : list) { |
| | | List<Point> positionList = redisTemplate.opsForGeo().position("vehiclePosition:" + xpVehicleVO.getVehicleVin(), xpVehicleVO.getVehicleVin()); |
| | | if (!CollectionUtils.isEmpty(positionList)) { |
| | | Point geoJsonPoint = positionList.get(0); |
| | | // 获取经纬度 |
| | | xpVehicleVO.setLongitude(geoJsonPoint.getX()); |
| | | xpVehicleVO.setLatitude(geoJsonPoint.getY()); |
| | | } |
| | | // List<Point> positionList = redisTemplate.opsForGeo().position("vehiclePosition:" + xpVehicleVO.getVehicleVin(), xpVehicleVO.getVehicleVin()); |
| | | // if (!CollectionUtils.isEmpty(positionList)) { |
| | | // Point geoJsonPoint = positionList.get(0); |
| | | // // 获取经纬度 |
| | | // xpVehicleVO.setLongitude(geoJsonPoint.getX()); |
| | | // xpVehicleVO.setLatitude(geoJsonPoint.getY()); |
| | | // } |
| | | // 查询车辆的续航里程 |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicleVO.getVehicleVin())), VehiclePosition.class); |
| | | if (Objects.nonNull(vehiclePosition)) { |
| | | xpVehicleVO.setMileageRange(vehiclePosition.getMileageRange()); |
| | | xpVehicleVO.setCurrentElectricity(vehiclePosition.getCurrentElectricity()); |
| | | GeoJsonPoint point = vehiclePosition.getPoint(); |
| | | if(Objects.nonNull(point)){ |
| | | xpVehicleVO.setLongitude(point.getX()); |
| | | xpVehicleVO.setLatitude(point.getY()); |
| | | } |
| | | } else { |
| | | xpVehicleVO.setMileageRange(0F); |
| | | xpVehicleVO.setCurrentElectricity(0); |
| | |
| | | throw new ServiceException("未查询到有效车辆信息", I18nKeyConstant.VEHICLE_NOT_EXISTS); |
| | | } |
| | | // 判断距离是否在范围之内 4米 |
| | | List<Point> positionList = redisTemplate.opsForGeo().position("vehiclePosition:" + xpVehicle.getVehicleVin(), xpVehicle.getVehicleVin()); |
| | | if (CollUtil.isNotEmpty(positionList)) { |
| | | Point geoJsonPoint = positionList.get(0); |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(dto.getLongitude()+ "," + dto.getLatitude(), geoJsonPoint.getX()+","+geoJsonPoint.getY()); |
| | | // List<Point> positionList = redisTemplate.opsForGeo().position("vehiclePosition:" + xpVehicle.getVehicleVin(), xpVehicle.getVehicleVin()); |
| | | VehiclePosition vehiclePosition = mongoTemplate.findOne(new Query(Criteria.where("vin").is(xpVehicle.getVehicleVin())), VehiclePosition.class); |
| | | if (Objects.nonNull(vehiclePosition)) { |
| | | GeoJsonPoint point = vehiclePosition.getPoint(); |
| | | if(Objects.nonNull(point)){ |
| | | Map<String, Double> distance = GeodesyUtil.getDistance(dto.getLongitude()+ "," + dto.getLatitude(), point.getX()+","+point.getY()); |
| | | if (null != distance) { |
| | | Double distance1 = distance.get("WGS84"); |
| | | if (distance1 > 4) { |
| | |
| | | }else { |
| | | throw new ServiceException("距离过远,无法打开", I18nKeyConstant.VEHICLE_DISTANCE_TOO_LONG); |
| | | } |
| | | }else { |
| | | throw new ServiceException("距离过远,无法打开", I18nKeyConstant.VEHICLE_DISTANCE_TOO_LONG); |
| | | } |
| | | } |
| | | // 车门解锁、后备箱解锁 |
| | | VehiclesCommandVo vehiclesCommandVo = new VehiclesCommandVo(); |