liujie
2026-04-24 9e02dfdb98980ab1e6371592481afc396e3b9e47
xp-robotaxi-account-boot/src/main/java/com/xiaopeng/account/service/impl/XpAppUserCollectAddrServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.alibaba.fastjson2.JSON;
import com.xiaopeng.account.mapper.XpAppUserCollectAddrMapper;
import com.xiaopeng.account.model.dto.CollectAddrDTO;
import com.xiaopeng.account.model.query.XpUserCollectAddrListQuery;
@@ -15,14 +16,21 @@
import com.xiaopeng.api.model.account.XpAppUserCollectAddr;
import com.xiaopeng.api.model.operation.XpPoint;
import com.xiaopeng.api.model.operation.XpStation;
import com.xiaopeng.api.vo.order.XpPointsListVo;
import com.xiaopeng.common.core.domain.R;
import com.xiaopeng.common.core.exception.ServiceException;
import com.xiaopeng.common.core.web.page.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -111,21 +119,23 @@
    public Page<XpAppUserCollectAddrVO> userCollectAddrList(XpUserCollectAddrListQuery query, String uid) {
        Page<XpAppUserCollectAddrVO> page = new Page<>(query.getPageNum(), query.getPageSize());
        Page<XpAppUserCollectAddrVO> pageData = this.baseMapper.userCollectAddrPageList(page, query, Long.parseLong(uid));
        Set<Long> collectedPointIds = new HashSet<>(getPointIdsByUserId(Long.parseLong(uid)));
        pageData.getRecords().forEach(xpAppUserCollectAddrVO -> {
            if(xpAppUserCollectAddrVO.getItemType() == 1){
                XpPointExportExcelQuery xpPointExportExcelQuery = new XpPointExportExcelQuery();
                xpPointExportExcelQuery.setPointIds(Arrays.asList(xpAppUserCollectAddrVO.getPointId()));
                List<XpPoint> data = xpPointClient.getByIds(xpPointExportExcelQuery).getData();
                if(null != data && data.size() > 0){
                    xpAppUserCollectAddrVO.setPointName(data.get(0).getPointName());
                    xpAppUserCollectAddrVO.setPointAddress(data.get(0).getPointAddress());
                    fillPointInfo(xpAppUserCollectAddrVO, data.get(0), query);
                }
            }
            if(xpAppUserCollectAddrVO.getItemType() == 2){
                fillCollectPointInfo(xpAppUserCollectAddrVO, query);
                XpStation data = xpStationClient.getXpStationById(xpAppUserCollectAddrVO.getStationId()).getData();
                if(null != data){
                    xpAppUserCollectAddrVO.setPointName(data.getStationName());
                }
                xpAppUserCollectAddrVO.setChildren(buildStationChildren(xpAppUserCollectAddrVO.getStationId(), query, collectedPointIds));
            }
        });
@@ -135,6 +145,92 @@
        return page;
    }
    private List<XpPointsListVo> buildStationChildren(Long stationId, XpUserCollectAddrListQuery query, Set<Long> collectedPointIds) {
        if (stationId == null) {
            return Collections.emptyList();
        }
        R<List<XpPointsListVo>> result = xpPointClient.getStationChildren(stationId);
        List<XpPointsListVo> children = result == null ? Collections.emptyList() : result.getData();
        if (children == null || children.isEmpty()) {
            return Collections.emptyList();
        }
        return children.stream()
                .peek(child -> fillChildInfo(child, query, collectedPointIds))
                .collect(Collectors.toList());
    }
    private void fillChildInfo(XpPointsListVo child, XpUserCollectAddrListQuery query, Set<Long> collectedPointIds) {
        fillChildDistance(child, query);
        if (collectedPointIds.contains(child.getId())) {
            child.setIsCollect(1);
        }
    }
    private void fillChildDistance(XpPointsListVo child, XpUserCollectAddrListQuery query) {
        if (query.getLatitude() == null || query.getLongitude() == null || child.getLatitude() == null || child.getLongitude() == null) {
            return;
        }
        double distance = distanceFast(query.getLatitude(), query.getLongitude(), child.getLatitude(), child.getLongitude());
        child.setDistance(BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_UP).doubleValue());
    }
    private void fillCollectPointInfo(XpAppUserCollectAddrVO collectAddrVO, XpUserCollectAddrListQuery query) {
        XpPointExportExcelQuery xpPointExportExcelQuery = new XpPointExportExcelQuery();
        xpPointExportExcelQuery.setPointIds(Arrays.asList(collectAddrVO.getPointId()));
        List<XpPoint> data = xpPointClient.getByIds(xpPointExportExcelQuery).getData();
        if (data == null || data.isEmpty()) {
            return;
        }
        fillPointInfo(collectAddrVO, data.get(0), query);
    }
    private void fillPointInfo(XpAppUserCollectAddrVO collectAddrVO, XpPoint point, XpUserCollectAddrListQuery query) {
        collectAddrVO.setPointName(point.getPointName());
        collectAddrVO.setPointAddress(point.getPointAddress());
        collectAddrVO.setElectronicAreaId(point.getElectronicAreaId());
        collectAddrVO.setTime(point.getParkingTimeLimit());
        fillEffectiveTime(collectAddrVO, point.getEffectiveTimePeriod());
        fillDistance(collectAddrVO, point, query);
    }
    private void fillEffectiveTime(XpAppUserCollectAddrVO collectAddrVO, String effectiveTimePeriod) {
        if (effectiveTimePeriod == null || effectiveTimePeriod.isEmpty()) {
            return;
        }
        List<String> timeRanges;
        try {
            timeRanges = JSON.parseArray(effectiveTimePeriod, String.class);
        } catch (Exception e) {
            return;
        }
        if (timeRanges == null || timeRanges.isEmpty()) {
            return;
        }
        String[] timeRange = timeRanges.get(0).split("-");
        if (timeRange.length != 2) {
            return;
        }
        collectAddrVO.setStartTime(timeRange[0].trim());
        collectAddrVO.setEndTime(timeRange[1].trim());
    }
    private void fillDistance(XpAppUserCollectAddrVO collectAddrVO, XpPoint point, XpUserCollectAddrListQuery query) {
        if (query.getLatitude() == null || query.getLongitude() == null || point.getPointLat() == null || point.getPointLon() == null) {
            return;
        }
        double distance = distanceFast(query.getLatitude(), query.getLongitude(), point.getPointLat(), point.getPointLon());
        collectAddrVO.setDistance(BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_UP).doubleValue());
    }
    private double distanceFast(double lat1, double lon1, double lat2, double lon2) {
        double latDistance = Math.toRadians(lat2 - lat1);
        double lonDistance = Math.toRadians(lon2 - lon1);
        double value = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
                + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
                * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
        return 6371000 * 2 * Math.atan2(Math.sqrt(value), Math.sqrt(1 - value));
    }
    @Override
    public List<Long> getPointIdsByUserId(Long uid) {
        return this.list(buildUserCollectQuery(uid)