From baa4f39d3f60161544a5b629e52ae62cd9b6e4c4 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 7 Mar 2023 15:22:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89=E5=AD=90?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/common/helper/RegionCacheHelper.java | 10 ++++++++++ .../pmapi/common/helper/impl/RegionsCacheHelperImpl.java | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java index adfa0d0..015d376 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionCacheHelper.java @@ -54,6 +54,16 @@ public interface RegionCacheHelper { List listParents(String code, int level); /** + * 根据传入的地区code与level获取所有子区域集合 + * + * @param code 地域编码 + * @param level 地域层级 + * @return 所有子区域(包含自己) + * @author WendyYang + **/ + List listChildren(String code, int level); + + /** * 获取当前区域所有的子区域(包括自己) * * @param code 区域编码 diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java index 90ad7c2..5002a08 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionsCacheHelperImpl.java @@ -170,4 +170,15 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements return result; } + @Override + public List 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()); + } + }