|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
@ -213,6 +214,7 @@ public class AccessConfigServiceImpl implements AccessConfigService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void addOpeAndScopes4Role(String roleKey, String operationKey, List<String> scopeKeys) { |
|
|
|
// 所有客户下该角色的列表
|
|
|
|
Result<List<GovStaffRoleResultDTO>> rolesResult = epmetUserOpenFeignClient.listRolesByRoleKey(roleKey); |
|
|
|
if (!rolesResult.success()) { |
|
|
|
String msg = "调用user服务,根据key查询角色列表失败"; |
|
|
@ -220,39 +222,41 @@ public class AccessConfigServiceImpl implements AccessConfigService { |
|
|
|
RenException.MessageMode.CODE_INTERNAL_EXTERNAL.CODE_INTERNAL_EXTERNAL); |
|
|
|
} |
|
|
|
|
|
|
|
List<GovStaffRoleResultDTO> roles = rolesResult.getData(); |
|
|
|
List<String> roleIds2Add = roles.stream().map(GovStaffRoleResultDTO::getRoleId).collect(Collectors.toList()); |
|
|
|
addOpeAndScopes4Role(roleIds2Add, operationKey, scopeKeys); |
|
|
|
List<GovStaffRoleResultDTO> rolesOfAllCustomer = rolesResult.getData(); |
|
|
|
addOpeAndScopes4Role(rolesOfAllCustomer, operationKey, scopeKeys); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 将默认的角色操作和范围同步给具体的角色 |
|
|
|
* @param rolesOfAllCustomer 所有客户的该角色的列表 |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2020.11.17 17:38 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void addOpeAndScopes4Role(List<String> roleIds, String operationKey, List<String> scopeKeys) { |
|
|
|
for (String roleId : roleIds) { |
|
|
|
public void addOpeAndScopes4Role(List<GovStaffRoleResultDTO> rolesOfAllCustomer, String operationKey, List<String> scopeKeys) { |
|
|
|
for (GovStaffRoleResultDTO role : rolesOfAllCustomer) { |
|
|
|
// 只给没有添加该权限的用户赋予该权限,已经添加了和添加了又取消的不操作
|
|
|
|
RoleOperationEntity roleOpe = roleOperationDao.getRoleOpe(roleId, operationKey); |
|
|
|
RoleOperationEntity roleOpe = roleOperationDao.getRoleOpe(role.getRoleId(), operationKey); |
|
|
|
boolean needRefreshCache = false; |
|
|
|
if (roleOpe == null) { |
|
|
|
// 没有该操作,则添加
|
|
|
|
RoleOperationEntity roleOperation = new RoleOperationEntity(); |
|
|
|
roleOperation.setOperationKey(operationKey); |
|
|
|
roleOperation.setRoleId(roleId); |
|
|
|
roleOperation.setRoleId(role.getRoleId()); |
|
|
|
roleOperation.setCustomerId(role.getCustomerId()); |
|
|
|
roleOperationDao.insert(roleOperation); |
|
|
|
needRefreshCache = true; |
|
|
|
} |
|
|
|
for (String scopeKey : scopeKeys) { |
|
|
|
// 没有的话则添加
|
|
|
|
RoleScopeEntity roleScopeInDb = roleScopeDao.getByRoleIdAndOpeKey(roleId, operationKey, scopeKey); |
|
|
|
RoleScopeEntity roleScopeInDb = roleScopeDao.getByRoleIdAndOpeKey(role.getRoleId(), operationKey, scopeKey); |
|
|
|
if (roleScopeInDb == null) { |
|
|
|
RoleScopeEntity roleScopeEntity = new RoleScopeEntity(); |
|
|
|
roleScopeEntity.setOperationKey(operationKey); |
|
|
|
roleScopeEntity.setRoleId(roleId); |
|
|
|
roleScopeEntity.setRoleId(role.getRoleId()); |
|
|
|
roleScopeEntity.setScopeKey(scopeKey); |
|
|
|
roleScopeEntity.setCustomerId(role.getCustomerId()); |
|
|
|
roleScopeDao.insert(roleScopeEntity); |
|
|
|
needRefreshCache = true; |
|
|
|
} |
|
|
@ -260,7 +264,7 @@ public class AccessConfigServiceImpl implements AccessConfigService { |
|
|
|
|
|
|
|
// 清空角色的权限缓存
|
|
|
|
if (needRefreshCache) { |
|
|
|
roleOpeScopeRedis.delRoleAllOpeScopes(roleId); |
|
|
|
roleOpeScopeRedis.delRoleAllOpeScopes(role.getRoleId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -273,4 +277,24 @@ public class AccessConfigServiceImpl implements AccessConfigService { |
|
|
|
addOpeAndScopes4Role(roleKey, operationKey, scopeKeys); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void addOpeAndScopes4RoleByDefaultConf(String roleKey, String operationKey) { |
|
|
|
// 1.先判断该角色是否已经为该操作配做了默认配置
|
|
|
|
LambdaQueryWrapper<RoleOperationDefaultEntity> rodw = new LambdaQueryWrapper<>(); |
|
|
|
rodw.eq(RoleOperationDefaultEntity::getRoleKey, roleKey); |
|
|
|
rodw.eq(RoleOperationDefaultEntity::getOperationKey, operationKey); |
|
|
|
rodw.eq(RoleOperationDefaultEntity::getDelFlag, 0); |
|
|
|
Integer roleOperationCount = roleOperationDefaultDao.selectCount(rodw); |
|
|
|
List<OperationScopeDefaultEntity> scopes = operationScopeDefaultDao.listOpeDefaultScopesByRoleAndOpeKey(roleKey, operationKey); |
|
|
|
if (roleOperationCount == 0 || CollectionUtils.isEmpty(scopes)) { |
|
|
|
throw new RenException(EpmetErrorCode.ACCESS_CONFIG_ERROR.getCode(), String.format("为所有客户同步%s的%s配置权限默认失败,请先保存默认权限配置再重试", roleKey, operationKey)); |
|
|
|
} |
|
|
|
|
|
|
|
// 2.开始执行同步
|
|
|
|
List<String> scopeKeys = scopes.stream().map(s -> s.getScopeKey()).collect(Collectors.toList()); |
|
|
|
logger.info(String.format("为所有客户同步%s的%s配置权限,范围列表:" + scopeKeys, roleKey, operationKey)); |
|
|
|
addOpeAndScopes4Role(roleKey, operationKey, scopeKeys); |
|
|
|
logger.info("同步完成"); |
|
|
|
} |
|
|
|
} |
|
|
|