liujie
2026-03-25 d597b03477f904bc87bc9c3a984f9bfa485a906d
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/service/serviceimpl/XpTestPointServiceImpl.java
File was renamed from xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpTestPointServiceImpl.java
@@ -1,4 +1,4 @@
package com.xiaopeng.operation.service.impl;
package com.xiaopeng.map.service.serviceimpl;
import cn.hutool.core.collection.CollUtil;
@@ -7,29 +7,29 @@
import com.xiaopeng.api.dto.operation.PointMapQuery;
import com.xiaopeng.api.dto.order.HistoryEndPointsDto;
import com.xiaopeng.api.dto.order.HistoryStartPointsDto;
import com.xiaopeng.api.model.operation.*;
import com.xiaopeng.api.model.map.XpTestPoint;
import com.xiaopeng.api.model.operation.XpElectronicFence;
import com.xiaopeng.api.model.operation.XpElectronicFenceArea;
import com.xiaopeng.api.model.operation.XpSystemSetting;
import com.xiaopeng.api.query.operation.PointListQuery;
import com.xiaopeng.api.query.operation.PointPageListListQuery;
import com.xiaopeng.api.vo.order.XpHistoryEndPointsVo;
import com.xiaopeng.api.vo.order.XpHistoryStartPointsVo;
import com.xiaopeng.api.vo.order.XpPointsListVo;
import com.xiaopeng.api.vo.order.XpPointsSearchVo;
import com.xiaopeng.common.core.constant.CacheConstants;
import com.xiaopeng.common.core.web.page.PageInfo;
import com.xiaopeng.common.redis.service.RedisService;
import com.xiaopeng.operation.dto.NearestDto;
import com.xiaopeng.operation.mapper.XpSystemSettingMapper;
import com.xiaopeng.operation.mapper.XpTestPointMapper;
import com.xiaopeng.operation.query.PointByNameQuery;
import com.xiaopeng.operation.service.IXpElectronicFenceAreaService;
import com.xiaopeng.operation.service.IXpElectronicFenceService;
import com.xiaopeng.operation.service.XpTestPointService;
import com.xiaopeng.operation.utils.TimeRangeChecker;
import com.xiaopeng.operation.utils.holiday.HolidayUtil;
import com.xiaopeng.operation.utils.map.FastDistanceCalculator;
import com.xiaopeng.operation.vo.NearestNextVo;
import com.xiaopeng.operation.vo.NearestVo;
import com.xiaopeng.operation.vo.OrderDistanceVo;
import com.xiaopeng.map.dto.NearestDto;
import com.xiaopeng.map.mapper.XpSystemSettingMapper;
import com.xiaopeng.map.mapper.XpTestPointMapper;
import com.xiaopeng.map.service.XpElectronicFenceAreaService;
import com.xiaopeng.map.service.XpElectronicFenceService;
import com.xiaopeng.map.service.XpTestPointService;
import com.xiaopeng.map.utils.TimeRangeChecker;
import com.xiaopeng.map.utils.holiday.HolidayUtil;
import com.xiaopeng.map.utils.map.map.FastDistanceCalculator;
import com.xiaopeng.map.vo.NearestNextVo;
import com.xiaopeng.map.vo.NearestVo;
import com.xiaopeng.map.vo.OrderDistanceVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -65,112 +65,10 @@
    private HolidayUtil holidayUtil;
    @Resource
    private IXpElectronicFenceAreaService xpElectronicFenceAreaService;
    private XpElectronicFenceAreaService xpElectronicFenceAreaService;
    @Resource
    private IXpElectronicFenceService xpElectronicFenceService;
    @Override
    public NearestVo nearest(NearestDto dto) {
        // 走缓存
        Object orderDistanceObj = redisService.getCacheObject(CacheConstants.NEAR_POINT_DISTANCE);
        Integer orderDistance;
        if (orderDistanceObj != null) {
            orderDistance = Integer.valueOf(orderDistanceObj.toString());
        } else {
            XpSystemSetting xpSystemSetting = xpSystemSettingMapper.selectOne(null);
            orderDistance = xpSystemSetting.getNearPointDistance();
        }
        List<XpTestPoint> list1 = list(new LambdaQueryWrapper<XpTestPoint>().eq(XpTestPoint::getOperationStatus, 2).eq(XpTestPoint::getPointType,1).isNotNull(XpTestPoint::getElectronicAreaId));
        if(list1.size()<2){
            return new NearestVo();
        }
        // 获取所有的站点信息
        List<XpTestPoint> list = list(new LambdaQueryWrapper<XpTestPoint>().eq(XpTestPoint::getOperationStatus, 2).eq(XpTestPoint::getPointType,1).isNotNull(XpTestPoint::getElectronicAreaId)
                // 添加距离计算字段
                .apply("ST_Distance_Sphere(point({0}, {1}), point(point_lon, point_lat)) <= {2}",
                        dto.getLongitude(), dto.getLatitude(), orderDistance));
        list = list.stream().filter(e->e.getElectronicAreaId().equals(dto.getElectronicAreaId())).collect(Collectors.toList());
        NearestVo nearestVo = new NearestVo();
        if(list.isEmpty()){
            nearestVo.setPoints(new ArrayList<>());
            nearestVo.setTotal(0);
            return nearestVo;
        }
        List<NearestNextVo> nearestNextVos = new ArrayList<>();
        LocalTime now = LocalTime.now();
        List<Long> areaIds = list.stream().map(XpTestPoint::getElectronicAreaId).collect(Collectors.toList());
        List<XpElectronicFenceArea> xpElectronicFenceAreas = xpElectronicFenceAreaService.listByIds(areaIds);
        List<Long> fenceIds = xpElectronicFenceAreas.stream().map(XpElectronicFenceArea::getElectronicId).collect(Collectors.toList());
        List<XpElectronicFence> xpElectronicFences = new ArrayList<>();
        if (CollUtil.isNotEmpty(fenceIds)) {
            xpElectronicFences = xpElectronicFenceService.listByIds(fenceIds);
        }
        //判断当前点位是否在运营时间范围内
        for (XpTestPoint xpPoint : list) {
            Integer operationType = xpPoint.getOperationType();
            if(1 == operationType){
                //与运营区同步
                XpElectronicFenceArea xpElectronicFenceArea = xpElectronicFenceAreas.stream().filter(s -> s.getId().equals(xpPoint.getElectronicAreaId())).findFirst().orElse(null);
                if(null == xpElectronicFenceArea){
                    continue;
                }
                XpElectronicFence xpElectronicFence = xpElectronicFences.stream().filter(s -> s.getId().equals(xpElectronicFenceArea.getElectronicId())).findFirst().orElse(null);
                if(null == xpElectronicFence){
                    continue;
                }
                //失效类型 1=永不失效 2=定时失效
                Integer failureType = xpElectronicFence.getFailureType();
                //永不失效,但是还未到开始时间
                if(1 == failureType && LocalDateTime.now().isBefore(xpElectronicFence.getEffectTime())){
                    continue;
                }else if(2 == failureType && (LocalDateTime.now().isBefore(xpElectronicFence.getEffectTime()) || LocalDateTime.now().isAfter(xpElectronicFence.getFailureTime()))){
                    //定时失效,但是当前时间不在时间范围内
                    continue;
                }
            }else{
                //自定义时间段
                // 判断是否在时间段内
                boolean intime = getInTime(now, xpPoint.getEffectivePeriod(), xpPoint.getEffectiveTimePeriod());
                if (!intime) {
                    continue;
                }
            }
            // 计算距离 小于的站点
            double v = FastDistanceCalculator.distanceFast(dto.getLatitude(), dto.getLongitude(), xpPoint.getPointLat(), xpPoint.getPointLon());
            // m做判断
            if ((v) < orderDistance) {
                NearestNextVo nearestNextVo = new NearestNextVo();
                nearestNextVo.setId(xpPoint.getId());
                nearestNextVo.setName(xpPoint.getPointName());
                nearestNextVo.setLatitude(xpPoint.getPointLat());
                nearestNextVo.setLongitude(xpPoint.getPointLon());
                nearestNextVo.setDistance(new BigDecimal(v).setScale(2, RoundingMode.HALF_UP).doubleValue());
                nearestNextVo.setAddress(xpPoint.getPointAddress());
                nearestNextVo.setTime(xpPoint.getParkingTimeLimit());
                nearestNextVo.setElectronicAreaId(xpPoint.getElectronicAreaId());
                nearestNextVos.add(nearestNextVo);
            }
        }
        if (!nearestNextVos.isEmpty()) {
            nearestNextVos = nearestNextVos.stream().sorted(Comparator.comparing(NearestNextVo::getDistance)).collect(Collectors.toList());
        }
        nearestVo.setPoints(nearestNextVos);
        nearestVo.setTotal(nearestNextVos.size());
        return nearestVo;
    }
    private XpElectronicFenceService xpElectronicFenceService;