diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionLimitHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionLimitHelper.java index 08cf986..4428076 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionLimitHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/RegionLimitHelper.java @@ -39,4 +39,14 @@ public interface RegionLimitHelper { */ RegionContainsBO getContainsRegionBo(Integer regionLevel, String regionCode); + + + /** + * 根据专家管理员用户id 获取专家管理员管辖区域列表 + * + * @param expertAdminUserId 专家管理员用户id + * @return + */ + List getExpertAdminContainsRegion(Long expertAdminUserId); + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionLimitHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionLimitHelper.java index 2142393..67dcad9 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionLimitHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/basic/AbstractRegionLimitHelper.java @@ -5,6 +5,8 @@ import com.ningdatech.pmapi.common.helper.RegionLimitHelper; import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo; import com.ningdatech.pmapi.expert.service.IExpertUserFullInfoService; import com.ningdatech.pmapi.meta.model.ExpertRegionInfo; +import com.ningdatech.pmapi.sys.service.IRegionService; +import com.ningdatech.pmapi.user.service.IUserInfoService; import lombok.AllArgsConstructor; import java.util.Objects; @@ -22,6 +24,8 @@ public abstract class AbstractRegionLimitHelper implements RegionLimitHelper { protected final RegionCacheHelper regionCache; protected final IExpertUserFullInfoService expertUserFullInfoService; + protected final IUserInfoService iUserInfoService; + protected final IRegionService regionService; /** diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionLimitHelperImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionLimitHelperImpl.java index 9834280..29401d3 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionLimitHelperImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/helper/impl/RegionLimitHelperImpl.java @@ -1,9 +1,16 @@ package com.ningdatech.pmapi.common.helper.impl; +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.helper.basic.AbstractRegionLimitHelper; import com.ningdatech.pmapi.expert.service.IExpertUserFullInfoService; import com.ningdatech.pmapi.meta.model.bo.RegionContainsBO; +import com.ningdatech.pmapi.sys.model.entity.Region; +import com.ningdatech.pmapi.sys.service.IRegionService; +import com.ningdatech.pmapi.user.entity.UserInfo; +import com.ningdatech.pmapi.user.service.IUserInfoService; import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,8 +31,9 @@ public class RegionLimitHelperImpl extends AbstractRegionLimitHelper { private static final Logger logger = LoggerFactory.getLogger(RegionLimitHelperImpl.class); - public RegionLimitHelperImpl(RegionCacheHelper regionCache, IExpertUserFullInfoService expertUserFullInfoService) { - super(regionCache, expertUserFullInfoService); + public RegionLimitHelperImpl(RegionCacheHelper regionCache, IExpertUserFullInfoService expertUserFullInfoService + , IUserInfoService iUserInfoService, IRegionService regionService) { + super(regionCache, expertUserFullInfoService, iUserInfoService, regionService); } public static Boolean contains(Integer adminRegionLevel, List adminAllContainsRegionCodes @@ -89,4 +97,36 @@ public class RegionLimitHelperImpl extends AbstractRegionLimitHelper { } + @Override + public List getExpertAdminContainsRegion(Long expertAdminUserId) { + if (Objects.isNull(expertAdminUserId)) { + logger.error("getExpertAdminContainsRegion expertAdminUserId is null"); + return new ArrayList<>(); + } + + UserInfo userInfo = iUserInfoService.getById(expertAdminUserId); + + if (Objects.isNull(userInfo) || StringUtils.isBlank(userInfo.getRegionCode())) { + logger.error("getExpertAdminContainsRegion userInfo is null Or regionCode is null"); + return new ArrayList<>(); + } + + String regionCode = userInfo.getRegionCode(); + List regionList = regionService.list(Wrappers.lambdaQuery(Region.class) + .eq(Region::getRegionCode, regionCode) + .orderByDesc(Region::getRegionLevel)); + + Region region = regionList.get(0); + Collection regionCodes = regionCache + .listChildRegionCodeList(region.getRegionCode(), region.getRegionLevel()); + RegionContainsBO regionContainsBO = new RegionContainsBO(); + regionContainsBO.setContainsRegionCodeList(new ArrayList<>(regionCodes)); + regionContainsBO.setParentRegionTreeLevel(region.getRegionLevel()); + + ArrayList regionContainsBOS = CollectionUtil.toList(regionContainsBO); + + return regionContainsBOS; + } + + } 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 5500fce..bbfbcd6 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 @@ -40,7 +40,7 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements @Override public String getRegionName(String code, int level) { RegionDTO dto = getByCodeAndLevel(code, level); - if(Objects.nonNull(dto)){ + if (Objects.nonNull(dto)) { return dto.getRegionName(); } return StringUtils.EMPTY; @@ -54,7 +54,7 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements @Override public Collection listChildRegionCodeList(String regionCode, int regionLevel) { RegionDTO currRegion = getByCodeAndLevel(regionCode, regionLevel); - if(Objects.isNull(currRegion)){ + if (Objects.isNull(currRegion)) { return Collections.emptyList(); } if (currRegion.getParentCode().equals(regionCode)) { @@ -217,4 +217,5 @@ public class RegionsCacheHelperImpl extends AbstractRegionCacheHelper implements buildUnionPathStrList(regionDTO.getParentCode(), level - 1, unionPathStrList); } } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ExpertAdminManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ExpertAdminManage.java index 0b298ec..4e683ec 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ExpertAdminManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ExpertAdminManage.java @@ -152,6 +152,10 @@ public class ExpertAdminManage { } List expertAdminContainsRegionList = new ArrayList<>(); + // 如果为超级管理员,可以查看所有的专家,包括没有层级的专家 + if (!permissionCheckHelper.isSuperAdmin()) { + expertAdminContainsRegionList = regionLimitHelper.getExpertAdminContainsRegion(userId); + } List containsRegion = new ArrayList<>(); if (Objects.nonNull(query.getExpertRegionInfo())) {