Commit 5d8137ef authored by 施翔轲's avatar 施翔轲

修改角色管理-取消授权中判断"角色下是否有账号与账号下是否有角色"的顺序

parent c76cb448
...@@ -406,15 +406,15 @@ public class SysRoleServiceImpl implements ISysRoleService { ...@@ -406,15 +406,15 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public int deleteAuthUser(SysUserRole userRole) { public int deleteAuthUser(SysUserRole userRole) {
//校验企业管理员角色下是否至少有一个账号
checkAdminHasUsers(userRole.getRoleId());
//若该账号仅有一个角色,则不允许取消授权 //若该账号仅有一个角色,则不允许取消授权
SysUser sysUser = userMapper.selectUserById(userRole.getUserId()); SysUser sysUser = userMapper.selectUserById(userRole.getUserId());
if (sysUser.getRoles().size() == 1) { if (sysUser.getRoles().size() == 1) {
throw new ServiceException("至少保留一个角色在该账号下"); throw new ServiceException("至少保留一个角色在该账号下");
} }
//校验企业管理员角色下是否至少有一个账号
checkAdminHasUsers(userRole.getRoleId());
int rows = userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>() int rows = userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>()
.eq(SysUserRole::getRoleId, userRole.getRoleId()) .eq(SysUserRole::getRoleId, userRole.getRoleId())
.eq(SysUserRole::getUserId, userRole.getUserId())); .eq(SysUserRole::getUserId, userRole.getUserId()));
...@@ -433,6 +433,9 @@ public class SysRoleServiceImpl implements ISysRoleService { ...@@ -433,6 +433,9 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/ */
@Override @Override
public int deleteAuthUsers(Long roleId, Long[] userIds) { public int deleteAuthUsers(Long roleId, Long[] userIds) {
//校验企业管理员角色下是否至少有一个账号
Integer users = checkAdminHasUsers(roleId);
//若该账号仅有一个角色,则不允许取消授权 //若该账号仅有一个角色,则不允许取消授权
StringBuilder lackRoleAccount = new StringBuilder(); StringBuilder lackRoleAccount = new StringBuilder();
for (Long userId : userIds) { for (Long userId : userIds) {
...@@ -441,13 +444,12 @@ public class SysRoleServiceImpl implements ISysRoleService { ...@@ -441,13 +444,12 @@ public class SysRoleServiceImpl implements ISysRoleService {
lackRoleAccount.append(sysUser.getUserName()).append(","); lackRoleAccount.append(sysUser.getUserName()).append(",");
} }
} }
//将缺少角色的账号返回给前端 //将缺少角色的账号返回给前端
if (lackRoleAccount.toString().contains(",")) { if (lackRoleAccount.toString().contains(",")) {
throw new ServiceException(lackRoleAccount.substring(0, lackRoleAccount.length()-1)); throw new ServiceException(lackRoleAccount.substring(0, lackRoleAccount.length()-1));
} }
//校验企业管理员角色下是否至少有一个账号
Integer users = checkAdminHasUsers(roleId);
//如果取消授权企业管理员角色下所有账号,则抛异常 //如果取消授权企业管理员角色下所有账号,则抛异常
if (users != null && userIds.length == users) { if (users != null && userIds.length == users) {
throw new ServiceException("至少要保留一个账号在企业管理员角色下!"); throw new ServiceException("至少要保留一个账号在企业管理员角色下!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment