| | |
| | | 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 { |
| | | return cacheList.stream() |
| | | .filter(item -> item instanceof RegionCascaderVO) |
| | | .map(item -> (RegionCascaderVO) item) |
| | | .collect(Collectors.toList()); |
| | | } 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, |