|
|
|
@ -5,6 +5,7 @@ import java.util.Arrays; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
@ -46,8 +47,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 角色数据集合信息 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<SysRole> selectRoleList(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public List<SysRole> selectRoleList(SysRole role) { |
|
|
|
|
return roleMapper.selectRoleList(role); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -58,16 +58,12 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 角色列表 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<SysRole> selectRolesByUserId(Long userId) |
|
|
|
|
{ |
|
|
|
|
public List<SysRole> selectRolesByUserId(Long userId) { |
|
|
|
|
List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId); |
|
|
|
|
List<SysRole> roles = selectRoleAll(); |
|
|
|
|
for (SysRole role : roles) |
|
|
|
|
{ |
|
|
|
|
for (SysRole userRole : userRoles) |
|
|
|
|
{ |
|
|
|
|
if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) |
|
|
|
|
{ |
|
|
|
|
for (SysRole role : roles) { |
|
|
|
|
for (SysRole userRole : userRoles) { |
|
|
|
|
if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) { |
|
|
|
|
role.setFlag(true); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -83,14 +79,11 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 权限列表 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Set<String> selectRolePermissionByUserId(Long userId) |
|
|
|
|
{ |
|
|
|
|
public Set<String> selectRolePermissionByUserId(Long userId) { |
|
|
|
|
List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId); |
|
|
|
|
Set<String> permsSet = new HashSet<>(); |
|
|
|
|
for (SysRole perm : perms) |
|
|
|
|
{ |
|
|
|
|
if (StringUtils.isNotNull(perm)) |
|
|
|
|
{ |
|
|
|
|
for (SysRole perm : perms) { |
|
|
|
|
if (StringUtils.isNotNull(perm)) { |
|
|
|
|
permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -103,8 +96,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 角色列表 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<SysRole> selectRoleAll() |
|
|
|
|
{ |
|
|
|
|
public List<SysRole> selectRoleAll() { |
|
|
|
|
return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -115,8 +107,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 选中角色ID列表 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<Long> selectRoleListByUserId(Long userId) |
|
|
|
|
{ |
|
|
|
|
public List<Long> selectRoleListByUserId(Long userId) { |
|
|
|
|
return roleMapper.selectRoleListByUserId(userId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -127,8 +118,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 角色对象信息 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public SysRole selectRoleById(Long roleId) |
|
|
|
|
{ |
|
|
|
|
public SysRole selectRoleById(Long roleId) { |
|
|
|
|
return roleMapper.selectRoleById(roleId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -139,12 +129,10 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean checkRoleNameUnique(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public boolean checkRoleNameUnique(SysRole role) { |
|
|
|
|
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
|
|
|
|
SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); |
|
|
|
|
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
|
|
|
|
{ |
|
|
|
|
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { |
|
|
|
|
return UserConstants.NOT_UNIQUE; |
|
|
|
|
} |
|
|
|
|
return UserConstants.UNIQUE; |
|
|
|
@ -157,12 +145,10 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean checkRoleKeyUnique(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public boolean checkRoleKeyUnique(SysRole role) { |
|
|
|
|
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); |
|
|
|
|
SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); |
|
|
|
|
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) |
|
|
|
|
{ |
|
|
|
|
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) { |
|
|
|
|
return UserConstants.NOT_UNIQUE; |
|
|
|
|
} |
|
|
|
|
return UserConstants.UNIQUE; |
|
|
|
@ -174,10 +160,8 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @param role 角色信息 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void checkRoleAllowed(SysRole role) |
|
|
|
|
{ |
|
|
|
|
if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) |
|
|
|
|
{ |
|
|
|
|
public void checkRoleAllowed(SysRole role) { |
|
|
|
|
if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) { |
|
|
|
|
throw new ServiceException("不允许操作超级管理员角色"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -188,15 +172,12 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @param roleId 角色id |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void checkRoleDataScope(Long roleId) |
|
|
|
|
{ |
|
|
|
|
if (!SysUser.isAdmin(SecurityUtils.getUserId())) |
|
|
|
|
{ |
|
|
|
|
public void checkRoleDataScope(Long roleId) { |
|
|
|
|
if (!SysUser.isAdmin(SecurityUtils.getUserId())) { |
|
|
|
|
SysRole role = new SysRole(); |
|
|
|
|
role.setRoleId(roleId); |
|
|
|
|
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); |
|
|
|
|
if (StringUtils.isEmpty(roles)) |
|
|
|
|
{ |
|
|
|
|
if (StringUtils.isEmpty(roles)) { |
|
|
|
|
throw new ServiceException("没有权限访问角色数据!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -209,8 +190,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int countUserRoleByRoleId(Long roleId) |
|
|
|
|
{ |
|
|
|
|
public int countUserRoleByRoleId(Long roleId) { |
|
|
|
|
return userRoleMapper.countUserRoleByRoleId(roleId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -222,8 +202,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public int insertRole(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public int insertRole(SysRole role) { |
|
|
|
|
// 新增角色信息
|
|
|
|
|
roleMapper.insertRole(role); |
|
|
|
|
return insertRoleMenu(role); |
|
|
|
@ -237,8 +216,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public int updateRole(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public int updateRole(SysRole role) { |
|
|
|
|
// 修改角色信息
|
|
|
|
|
roleMapper.updateRole(role); |
|
|
|
|
// 删除角色与菜单关联
|
|
|
|
@ -253,8 +231,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int updateRoleStatus(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public int updateRoleStatus(SysRole role) { |
|
|
|
|
return roleMapper.updateRole(role); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -266,8 +243,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public int authDataScope(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public int authDataScope(SysRole role) { |
|
|
|
|
// 修改角色信息
|
|
|
|
|
return roleMapper.updateRole(role); |
|
|
|
|
} |
|
|
|
@ -277,20 +253,17 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* |
|
|
|
|
* @param role 角色对象 |
|
|
|
|
*/ |
|
|
|
|
public int insertRoleMenu(SysRole role) |
|
|
|
|
{ |
|
|
|
|
public int insertRoleMenu(SysRole role) { |
|
|
|
|
int rows = 1; |
|
|
|
|
// 新增用户与角色管理
|
|
|
|
|
List<SysRoleMenu> list = new ArrayList<SysRoleMenu>(); |
|
|
|
|
for (Long menuId : role.getMenuIds()) |
|
|
|
|
{ |
|
|
|
|
for (Long menuId : role.getMenuIds()) { |
|
|
|
|
SysRoleMenu rm = new SysRoleMenu(); |
|
|
|
|
rm.setRoleId(role.getRoleId()); |
|
|
|
|
rm.setMenuId(menuId); |
|
|
|
|
list.add(rm); |
|
|
|
|
} |
|
|
|
|
if (list.size() > 0) |
|
|
|
|
{ |
|
|
|
|
if (list.size() > 0) { |
|
|
|
|
rows = roleMenuMapper.batchRoleMenu(list); |
|
|
|
|
} |
|
|
|
|
return rows; |
|
|
|
@ -305,8 +278,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public int deleteRoleById(Long roleId) |
|
|
|
|
{ |
|
|
|
|
public int deleteRoleById(Long roleId) { |
|
|
|
|
// 删除角色与菜单关联
|
|
|
|
|
roleMenuMapper.deleteRoleMenuByRoleId(roleId); |
|
|
|
|
return roleMapper.deleteRoleById(roleId); |
|
|
|
@ -320,15 +292,12 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
@Transactional |
|
|
|
|
public int deleteRoleByIds(Long[] roleIds) |
|
|
|
|
{ |
|
|
|
|
for (Long roleId : roleIds) |
|
|
|
|
{ |
|
|
|
|
public int deleteRoleByIds(Long[] roleIds) { |
|
|
|
|
for (Long roleId : roleIds) { |
|
|
|
|
checkRoleAllowed(new SysRole(roleId)); |
|
|
|
|
checkRoleDataScope(roleId); |
|
|
|
|
SysRole role = selectRoleById(roleId); |
|
|
|
|
if (countUserRoleByRoleId(roleId) > 0) |
|
|
|
|
{ |
|
|
|
|
if (countUserRoleByRoleId(roleId) > 0) { |
|
|
|
|
throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -345,8 +314,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int deleteAuthUser(SysUserRole userRole) |
|
|
|
|
{ |
|
|
|
|
public int deleteAuthUser(SysUserRole userRole) { |
|
|
|
|
return userRoleMapper.deleteUserRoleInfo(userRole); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -358,8 +326,7 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int deleteAuthUsers(Long roleId, Long[] userIds) |
|
|
|
|
{ |
|
|
|
|
public int deleteAuthUsers(Long roleId, Long[] userIds) { |
|
|
|
|
return userRoleMapper.deleteUserRoleInfos(roleId, userIds); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -371,12 +338,10 @@ public class SysRoleServiceImpl implements ISysRoleService { |
|
|
|
|
* @return 结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public int insertAuthUsers(Long roleId, Long[] userIds) |
|
|
|
|
{ |
|
|
|
|
public int insertAuthUsers(Long roleId, Long[] userIds) { |
|
|
|
|
// 新增用户与角色管理
|
|
|
|
|
List<SysUserRole> list = new ArrayList<SysUserRole>(); |
|
|
|
|
for (Long userId : userIds) |
|
|
|
|
{ |
|
|
|
|
for (Long userId : userIds) { |
|
|
|
|
SysUserRole ur = new SysUserRole(); |
|
|
|
|
ur.setUserId(userId); |
|
|
|
|
ur.setRoleId(roleId); |
|
|
|
|