xuhy
2026-03-12 4bbbfc8cf87ee90b58d39bdde8a8a6932c38fa0f
车辆运维修改
1个文件已修改
33 ■■■■■ 已修改文件
xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpVehicleServiceImpl.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-vehicle-convoy-boot/src/main/java/com/xiaopeng/vehicleConvoy/service/impl/XpVehicleServiceImpl.java
@@ -54,6 +54,7 @@
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;
@@ -195,18 +196,23 @@
        }
        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);
@@ -246,10 +252,12 @@
            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) {
@@ -258,6 +266,9 @@
            }else {
                throw new ServiceException("距离过远,无法打开", I18nKeyConstant.VEHICLE_DISTANCE_TOO_LONG);
            }
            }else {
                throw new ServiceException("距离过远,无法打开", I18nKeyConstant.VEHICLE_DISTANCE_TOO_LONG);
            }
        }
        // 车门解锁、后备箱解锁
        VehiclesCommandVo vehiclesCommandVo = new VehiclesCommandVo();