From b419690525cbf660da4d4c85caa8b3a2813e5e7b Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 11 Dec 2023 14:11:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=93=E5=AE=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ExpertAdminDataScopeProviderImpl.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/ExpertAdminDataScopeProviderImpl.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/ExpertAdminDataScopeProviderImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/ExpertAdminDataScopeProviderImpl.java new file mode 100644 index 0000000..591e72b --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/datascope/provider/impl/ExpertAdminDataScopeProviderImpl.java @@ -0,0 +1,74 @@ +package com.ningdatech.pmapi.datascope.provider.impl; + +import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.common.helper.RegionCacheHelper; +import com.ningdatech.pmapi.common.helper.UserInfoHelper; +import com.ningdatech.pmapi.datascope.model.DataScopeDTO; +import com.ningdatech.pmapi.datascope.provider.DataScopeProvider; +import com.ningdatech.pmapi.sys.model.dto.RegionDTO; +import com.ningdatech.pmapi.user.entity.enumeration.RoleEnum; +import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; +import com.ningdatech.pmapi.user.util.LoginUserUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + *

+ * ExpertAdminDataScopeProviderImpl + *

+ * + * @author WendyYang + * @since 10:39 2023/12/11 + */ +@Component("EXPERT_ADMIN") +@RequiredArgsConstructor +public class ExpertAdminDataScopeProviderImpl implements DataScopeProvider { + + private final RegionCacheHelper regionCacheHelper; + private final UserInfoHelper userInfoHelper; + + @Override + public Optional findDataFieldProperty() { + UserInfoDetails user = LoginUserUtil.loginUserDetail(); + DataScopeDTO ds = new DataScopeDTO(); + if (Objects.isNull(user.getRegionLevel())) { + ds.setRegionIds(Collections.emptyList()); + ds.setRegionCodes(Collections.emptyList()); + } else { + List regions = regionCacheHelper.listChildren(user.getRegionCode(), user.getRegionLevel()); + ds.setRegionCodes(CollUtils.fieldList(regions, RegionDTO::getRegionCode)); + ds.setRegionIds(CollUtils.fieldList(regions, RegionDTO::getId)); + } + ds.setRole(RoleEnum.EXPERT_ADMIN); + ds.setUserId(user.getUserId()); + ds.setEmployeeCode(user.getEmployeeCode()); + ds.setOrgCode(user.getOrganizationCode()); + return Optional.of(ds); + } + + @Override + public Optional findDataFieldProperty(Long userId) { + UserFullInfoDTO user = userInfoHelper.getUserFullInfo(userId); + DataScopeDTO ds = new DataScopeDTO(); + if (Objects.isNull(user.getRegionLevel())) { + ds.setRegionIds(Collections.emptyList()); + ds.setRegionCodes(Collections.emptyList()); + } else { + List regions = regionCacheHelper.listChildren(user.getRegionCode(), user.getRegionLevel()); + ds.setRegionCodes(CollUtils.fieldList(regions, RegionDTO::getRegionCode)); + ds.setRegionIds(CollUtils.fieldList(regions, RegionDTO::getId)); + } + ds.setRole(RoleEnum.EXPERT_ADMIN); + ds.setUserId(user.getUserId()); + ds.setEmployeeCode(user.getEmployeeCode()); + ds.setOrgCode(user.getOrganizationCode()); + return Optional.of(ds); + } + +}