puzhibing
2026-03-14 a6d4e647711dc2131cd7477d4e817cd7c4509eed
xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/service/impl/XpRegionServiceImpl.java
@@ -120,6 +120,61 @@
        redisService.setCacheList(CacheConstants.XP_REGION_CASCADER, result);
        return result;
    }
    @Override
    public List<RegionCascaderVO> getRegionCascaderNoArea() {
        List<Object> cacheList = redisService.getCacheList(CacheConstants.XP_REGION_CASCADER);
        if (cacheList != null && !cacheList.isEmpty()) {
            try {
                List<RegionCascaderVO> collect = cacheList.stream()
                        .filter(item -> item instanceof RegionCascaderVO)
                        .map(item -> (RegionCascaderVO) item)
                        .collect(Collectors.toList());
                for (RegionCascaderVO regionCascaderVO : collect) {
                    List<RegionCascaderVO> children = regionCascaderVO.getChildren();
                    for (RegionCascaderVO children1 : children) {
                        children1.setChildren(null);
                    }
                }
                return collect;
            } catch (ClassCastException e) {
                redisService.deleteObject(CacheConstants.XP_REGION_CASCADER);
            }
        }
        List<XpRegion> regionList = this.baseMapper.selectList(Wrappers.lambdaQuery(XpRegion.class));
        if (regionList == null || regionList.isEmpty()) {
            return Collections.emptyList();
        }
        List<XpOpenCity> openCityList = openCityService.list(Wrappers.lambdaQuery(XpOpenCity.class)
                .eq(XpOpenCity::getStatus, 1));
        Set<String> openCityCodeSet = openCityList.stream()
                .map(XpOpenCity::getCityCode)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toCollection(HashSet::new));
        Set<String> openDistrictCodeSet = openCityList.stream()
                .map(XpOpenCity::getDistrictCode)
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toCollection(HashSet::new));
        Map<Long, List<XpRegion>> childrenMap = regionList.stream()
                .collect(Collectors.groupingBy(region -> region.getParentId() == null ? 0L : region.getParentId()));
        List<XpRegion> provinceList = childrenMap.getOrDefault(0L, Collections.emptyList()).stream()
                .sorted(REGION_COMPARATOR)
                .collect(Collectors.toList());
        List<RegionCascaderVO> result = provinceList.stream()
                .map(region -> buildRegionNode(region, childrenMap, openCityCodeSet, openDistrictCodeSet))
                .collect(Collectors.toList());
        for (RegionCascaderVO regionCascaderVO : result) {
            List<RegionCascaderVO> children = regionCascaderVO.getChildren();
            for (RegionCascaderVO children1 : children) {
                children1.setChildren(null);
            }
        }
        redisService.setCacheList(CacheConstants.XP_REGION_CASCADER, result);
        return result;
    }
    private RegionCascaderVO buildRegionNode(XpRegion current,
                                             Map<Long, List<XpRegion>> childrenMap,