Browse Source

获取所有子区域

tags/24080901
WendyYang 1 year ago
parent
commit
baa4f39d3f
2 changed files with 21 additions and 0 deletions
  1. +10
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java
  2. +11
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java

+ 10
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java View File

@@ -54,6 +54,16 @@ public interface RegionCacheHelper {
List<RegionDTO> listParents(String code, int level);

/**
* 根据传入的地区code与level获取所有子区域集合
*
* @param code 地域编码
* @param level 地域层级
* @return 所有子区域(包含自己)
* @author WendyYang
**/
List<RegionDTO> listChildren(String code, int level);

/**
* 获取当前区域所有的子区域(包括自己)
*
* @param code 区域编码


+ 11
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java View File

@@ -170,4 +170,15 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements
return result;
}

@Override
public List<RegionDTO> listChildren(String code, int level) {
RegionDTO curr = getByCodeAndLevel(code, level);
if (curr.getParentCode().equals(curr.getRegionCode())) {
return Collections.singletonList(curr);
}
return all().stream()
.filter(w -> StrUtils.split(w.getRegionCodePath()).contains(code))
.collect(Collectors.toList());
}

}

Loading…
Cancel
Save