@@ -1,10 +1,11 @@ | |||
package com.hz.pm.api.datascope.provider; | |||
import cn.hutool.core.collection.CollUtil; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.ningdatech.basic.exception.BizException; | |||
import com.ningdatech.basic.util.SpringUtils; | |||
import lombok.RequiredArgsConstructor; | |||
import java.io.Serializable; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Optional; | |||
@@ -16,21 +17,29 @@ import java.util.Optional; | |||
* @author WendyYang | |||
* @since 2022/1/9 23:28 | |||
*/ | |||
@RequiredArgsConstructor | |||
public class DataScopeContext implements Serializable { | |||
public class DataScopeContext { | |||
private static final String WARN_MSG = "请先创建数据权限[%s]的实现类"; | |||
private DataScopeContext() { | |||
} | |||
private static final String WARN_MSG = "请先创建数据权限 [%s] 的实现类"; | |||
private static final Map<String, DataScopeProvider> DSP_MAP; | |||
static { | |||
DSP_MAP = SpringUtils.getBeansOfType(DataScopeProvider.class); | |||
DSP_MAP = new HashMap<>(16); | |||
Map<String, DataScopeProvider> beansMap = SpringUtils.getBeansOfType(DataScopeProvider.class); | |||
if (CollUtil.isNotEmpty(beansMap)) { | |||
for (DataScopeProvider value : beansMap.values()) { | |||
DSP_MAP.put(value.findRole().name(), value); | |||
} | |||
} | |||
} | |||
public static Optional<DataScopeDTO> getDataScope(String roleCode) { | |||
DataScopeProvider dataScopeProvider = DSP_MAP.get(roleCode); | |||
if (dataScopeProvider == null) { | |||
throw new IllegalArgumentException(String.format(WARN_MSG, roleCode)); | |||
throw BizException.wrap(WARN_MSG, roleCode); | |||
} | |||
return dataScopeProvider.findDataFieldProperty(); | |||
} | |||
@@ -38,8 +47,9 @@ public class DataScopeContext implements Serializable { | |||
public static Optional<DataScopeDTO> getDataScopeHasUserId(String roleCode, Long userId) { | |||
DataScopeProvider dataScopeProvider = DSP_MAP.get(roleCode); | |||
if (dataScopeProvider == null) { | |||
throw new IllegalArgumentException(String.format(WARN_MSG, roleCode)); | |||
throw BizException.wrap(WARN_MSG, roleCode); | |||
} | |||
return dataScopeProvider.findDataFieldProperty(userId); | |||
} | |||
} |
@@ -2,6 +2,7 @@ package com.hz.pm.api.datascope.provider; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import java.util.Optional; | |||
@@ -15,6 +16,8 @@ import java.util.Optional; | |||
*/ | |||
public interface DataScopeProvider { | |||
RoleEnum findRole(); | |||
/** | |||
* 获取登录人的数据权限 | |||
* | |||
@@ -1,10 +1,8 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -21,27 +19,29 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("DASHBOARD") | |||
public class DashboardUserDataScopeProviderImpl implements DataScopeProvider { | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.DASHBOARD; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(user.getUserId()); | |||
ds.setUserId(LoginUserUtil.getUserId()); | |||
ds.setRole(RoleEnum.DASHBOARD); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(userId); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(user.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.DASHBOARD); | |||
return Optional.of(ds); | |||
} | |||
} |
@@ -1,10 +1,8 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.security.model.UserInfoDetails; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
@@ -20,11 +18,14 @@ import java.util.Optional; | |||
* @author WendyYang | |||
* @since 10:39 2023/12/11 | |||
*/ | |||
@Component("EXPERT_ADMIN") | |||
@Component | |||
@RequiredArgsConstructor | |||
public class ExpertAdminDataScopeProviderImpl implements DataScopeProvider { | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.EXPERT_ADMIN; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
@@ -38,7 +39,7 @@ public class ExpertAdminDataScopeProviderImpl implements DataScopeProvider { | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO user = userInfoHelper.getUserFullInfo(userId); | |||
UserInfoDetails user = LoginUserUtil.loginUserDetail(); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setRole(RoleEnum.EXPERT_ADMIN); | |||
ds.setUserId(user.getUserId()); | |||
@@ -1,6 +1,5 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.RegionCacheHelper; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
@@ -22,28 +21,28 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("EXPERT") | |||
public class ExpertDataScopeProviderImpl implements DataScopeProvider { | |||
private final RegionCacheHelper regionCacheHelper; | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.EXPERT; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(LoginUserUtil.getUserId()); | |||
ds.setRole(RoleEnum.EXPERT); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.EXPERT); | |||
return Optional.of(ds); | |||
} | |||
@@ -1,10 +1,8 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -21,30 +19,30 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("HIGH_MEMBER") | |||
public class HigherUserDataScopeProviderImpl implements DataScopeProvider { | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.HIGH_MEMBER; | |||
} | |||
//和区域管理员一样 | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(LoginUserUtil.getUserId()); | |||
ds.setRole(RoleEnum.REGION_MANAGER); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
//借由 丽水市的code 来映射市本级的regionCode | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.REGION_MANAGER); | |||
return Optional.of(ds); | |||
} | |||
} |
@@ -1,10 +1,8 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -21,26 +19,27 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("NORMAL_MEMBER") | |||
public class OrdinaryUserDataScopeProviderImpl implements DataScopeProvider { | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.NORMAL_MEMBER; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(LoginUserUtil.getUserId()); | |||
ds.setRole(RoleEnum.NORMAL_MEMBER); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.NORMAL_MEMBER); | |||
return Optional.of(ds); | |||
} | |||
@@ -1,10 +1,9 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.security.model.UserInfoDetails; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -22,28 +21,32 @@ import java.util.Optional; | |||
*/ | |||
@Slf4j | |||
@RequiredArgsConstructor | |||
@Component("COMPANY_MANAGER") | |||
@Component | |||
public class OrgAdminDataScopeProviderImpl implements DataScopeProvider { | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.COMPANY_MANAGER; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
UserInfoDetails user = LoginUserUtil.loginUserDetail(); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setOrgCode(String.valueOf(userFullInfo.getMhUnitId())); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setOrgCode(user.getMhUnitIdStr()); | |||
ds.setUserId(user.getUserId()); | |||
ds.setRole(RoleEnum.COMPANY_MANAGER); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
UserInfoDetails user = LoginUserUtil.loginUserDetail(); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setOrgCode(String.valueOf(userFullInfo.getMhUnitId())); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setOrgCode(user.getMhUnitIdStr()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.COMPANY_MANAGER); | |||
return Optional.of(ds); | |||
} | |||
} |
@@ -1,11 +1,8 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.RegionCacheHelper; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -22,28 +19,30 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("REGION_MANAGER") | |||
public class RegionAdminDataScopeProviderImpl implements DataScopeProvider { | |||
private final RegionCacheHelper regionCacheHelper; | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.REGION_MANAGER; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
Long userId = LoginUserUtil.getUserId(); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.REGION_MANAGER); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.REGION_MANAGER); | |||
return Optional.of(ds); | |||
} | |||
} |
@@ -1,11 +1,8 @@ | |||
package com.hz.pm.api.datascope.provider.impl; | |||
import com.hz.pm.api.common.helper.RegionCacheHelper; | |||
import com.hz.pm.api.common.helper.UserInfoHelper; | |||
import com.hz.pm.api.datascope.model.DataScopeDTO; | |||
import com.hz.pm.api.datascope.provider.DataScopeProvider; | |||
import com.hz.pm.api.user.model.enumeration.RoleEnum; | |||
import com.hz.pm.api.user.security.model.UserFullInfoDTO; | |||
import com.hz.pm.api.user.util.LoginUserUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -22,30 +19,31 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("SUPER_ADMIN") | |||
public class SuperAdminDataScopeProviderImpl implements DataScopeProvider { | |||
private final RegionCacheHelper regionCacheHelper; | |||
private final UserInfoHelper userInfoHelper; | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.SUPER_ADMIN; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); | |||
Long userId = LoginUserUtil.getUserId(); | |||
//所有 丽水市的code | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.SUPER_ADMIN); | |||
return Optional.of(ds); | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty(Long userId) { | |||
UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId); | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setUserId(userFullInfo.getUserId()); | |||
ds.setUserId(userId); | |||
ds.setRole(RoleEnum.SUPER_ADMIN); | |||
return Optional.of(ds); | |||
} | |||
} |
@@ -18,11 +18,16 @@ import java.util.Optional; | |||
* @since 2023/3/27 23:29 | |||
*/ | |||
@Slf4j | |||
@Component | |||
@RequiredArgsConstructor | |||
@Component("VISITOR") | |||
public class VisitorDataScopeProviderImpl implements DataScopeProvider { | |||
@Override | |||
public RoleEnum findRole() { | |||
return RoleEnum.VISITOR; | |||
} | |||
@Override | |||
public Optional<DataScopeDTO> findDataFieldProperty() { | |||
DataScopeDTO ds = new DataScopeDTO(); | |||
ds.setRole(RoleEnum.SUPER_ADMIN); | |||