Browse Source

数据权限修改

tags/24080901
WendyYang 8 months ago
parent
commit
ba25e9b45c
11 changed files with 94 additions and 79 deletions
  1. +18
    -8
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/DataScopeContext.java
  2. +3
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/DataScopeProvider.java
  3. +8
    -8
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/DashboardUserDataScopeProviderImpl.java
  4. +6
    -5
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/ExpertAdminDataScopeProviderImpl.java
  5. +7
    -8
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/ExpertDataScopeProviderImpl.java
  6. +8
    -10
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/HigherUserDataScopeProviderImpl.java
  7. +7
    -8
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java
  8. +13
    -10
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java
  9. +9
    -10
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java
  10. +9
    -11
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java
  11. +6
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/VisitorDataScopeProviderImpl.java

+ 18
- 8
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/DataScopeContext.java View File

@@ -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);
}

}

+ 3
- 0
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/DataScopeProvider.java View File

@@ -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();

/**
* 获取登录人的数据权限
*


+ 8
- 8
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/DashboardUserDataScopeProviderImpl.java View File

@@ -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);
}

}

+ 6
- 5
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/ExpertAdminDataScopeProviderImpl.java View File

@@ -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());


+ 7
- 8
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/ExpertDataScopeProviderImpl.java View File

@@ -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);
}


+ 8
- 10
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/HigherUserDataScopeProviderImpl.java View File

@@ -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);
}

}

+ 7
- 8
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/OrdinaryUserDataScopeProviderImpl.java View File

@@ -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);
}


+ 13
- 10
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/OrgAdminDataScopeProviderImpl.java View File

@@ -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);
}

}

+ 9
- 10
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/RegionAdminDataScopeProviderImpl.java View File

@@ -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);
}

}

+ 9
- 11
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/SuperAdminDataScopeProviderImpl.java View File

@@ -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);
}

}

+ 6
- 1
hz-pm-api/src/main/java/com/hz/pm/api/datascope/provider/impl/VisitorDataScopeProviderImpl.java View File

@@ -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);


Loading…
Cancel
Save