From f891f4e0495819800909910adf1d2d40ba4c514d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Thu, 30 Mar 2023 16:07:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=93=E5=AE=B6=E5=AE=A1=E6=A0=B8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E6=94=B9=E6=94=B9=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/common/helper/RegionCacheHelper.java | 10 +++++++++ .../helper/basic/AbstractRegionCacheHelper.java | 8 +++++-- .../common/helper/impl/RegionsCacheHelperImpl.java | 25 ++++++++++++++++++++++ .../expert/assembler/ExpertUserInfoAssembler.java | 5 +++-- 4 files changed, 44 insertions(+), 4 deletions(-) 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 65bda65..f17195f 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 @@ -99,4 +99,14 @@ public interface RegionCacheHelper { **/ String getDisplayName(String regionCode, Integer regionLevel); + + /** + * 获取用于前端回显示使用的unionList 仅用于返回前端的时候使用 + * + * @param code 区域编码 + * @param level 区域层级 + * @return + */ + String getUnionPathStr(String code, Integer level); + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java index 92f2e63..f23c5dc 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionCacheHelper.java @@ -1,6 +1,5 @@ package com.ningdatech.pmapi.common.helper.basic; -import cn.hutool.core.lang.Assert; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.ningdatech.pmapi.common.model.RegionMapKey; @@ -28,10 +27,12 @@ import java.util.concurrent.TimeUnit; @Slf4j public abstract class AbstractRegionCacheHelper implements InitializingBean { + private static final String PARENT_CODE_ROOT = "-1"; + @Autowired private IRegionService regionService; - private LoadingCache regionsCache; + protected LoadingCache regionsCache; private void initRegionCache() { List allRegions = regionService.all(); @@ -71,4 +72,7 @@ public abstract class AbstractRegionCacheHelper implements InitializingBean { initRegionCache(); } + public String getParentCodeRoot() { + return PARENT_CODE_ROOT; + } } 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 971bb47..7eb2e38 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 @@ -185,4 +185,29 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements .collect(Collectors.toList()); } + + @Override + public String getUnionPathStr(String code, Integer level) { + if (StringUtils.isBlank(code) || Objects.isNull(level)) { + return null; + } + List unionPathStrList = new ArrayList<>(); + buildUnionPathStrList(code, level, unionPathStrList); + Collections.reverse(unionPathStrList); + if (CollectionUtils.isEmpty(unionPathStrList)) { + return null; + } + return String.join("@@", unionPathStrList); + } + + protected void buildUnionPathStrList(String code, Integer level, List unionPathStrList) { + if (level <= 0 || super.getParentCodeRoot().equals(code)) { + return; + } + RegionDTO regionDTO = getByCodeAndLevel(code, level); + unionPathStrList.add(regionDTO.getRegionCode() + "##" + regionDTO.getRegionName() + "##" + regionDTO.getRegionLevel()); + if (!super.getParentCodeRoot().equals(regionDTO.getParentCode())) { + buildUnionPathStrList(regionDTO.getParentCode(), level - 1, unionPathStrList); + } + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertUserInfoAssembler.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertUserInfoAssembler.java index d7b64ac..bb589a1 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertUserInfoAssembler.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/assembler/ExpertUserInfoAssembler.java @@ -4,6 +4,7 @@ package com.ningdatech.pmapi.expert.assembler; import com.alibaba.fastjson.JSONObject; import com.ningdatech.file.entity.vo.result.AttachFileVo; import com.ningdatech.pmapi.common.enumeration.BoolDisplayEnum; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.model.FileBasicInfo; import com.ningdatech.pmapi.expert.constant.ExpertApplyTypeEnum; import com.ningdatech.pmapi.expert.entity.ExpertAvoidCompany; @@ -41,7 +42,7 @@ public class ExpertUserInfoAssembler { private final TagCache tagCache; private final DictionaryCache dictionaryCache; -// private final RegionCache regionCache; + private final RegionCacheHelper regionCacheHelper; public ExpertFullInfoVO buildExpertFullInfoVO(List attachFiles , ExpertFullInfoAllDTO expertUserFullInfoAll) { @@ -83,7 +84,7 @@ public class ExpertUserInfoAssembler { ExpertRegionInfo expertApplyIntentionWorkRegion = new ExpertRegionInfo(); expertApplyIntentionWorkRegion.setRegionLevel(r.getRegionLevel()); expertApplyIntentionWorkRegion.setRegionCode(r.getRegionCode()); -// expertApplyIntentionWorkRegion.setRegionName(regionCache.getUnionPathStr(r.getRegionCode(), r.getRegionLevel())); + expertApplyIntentionWorkRegion.setRegionName(regionCacheHelper.getUnionPathStr(r.getRegionCode(), r.getRegionLevel())); return expertApplyIntentionWorkRegion; }).collect(Collectors.toList());