|
|
@ -213,6 +213,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 +221,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 +263,7 @@ public class AccessConfigServiceImpl implements AccessConfigService { |
|
|
|
|
|
|
|
// 清空角色的权限缓存
|
|
|
|
if (needRefreshCache) { |
|
|
|
roleOpeScopeRedis.delRoleAllOpeScopes(roleId); |
|
|
|
roleOpeScopeRedis.delRoleAllOpeScopes(role.getRoleId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|