diff --git a/src/main/java/com/glxp/api/controller/auth/SysRoleController.java b/src/main/java/com/glxp/api/controller/auth/SysRoleController.java index 5081f90e..71d5af50 100644 --- a/src/main/java/com/glxp/api/controller/auth/SysRoleController.java +++ b/src/main/java/com/glxp/api/controller/auth/SysRoleController.java @@ -88,6 +88,13 @@ public class SysRoleController extends BaseController { @PutMapping @Log(title = "用户管理", businessType = BusinessType.UPDATE) public BaseResponse edit(@Validated @RequestBody SysRole role) { + //把角色改成禁用的时候 如果存在关联 不能禁用 + if("1".equals(role.getStatus())){ + List sysUserRoles = roleService.selectUserRoleList(role.getRoleId()); + if( !sysUserRoles.isEmpty()){ + return ResultVOUtils.error(500, "角色已关联用户,不能禁用!"); + } + } roleService.checkRoleAllowed(role); roleService.checkRoleDataScope(role.getRoleId()); if (Constant.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role))) { diff --git a/src/main/java/com/glxp/api/dao/auth/SysUserRoleMapper.java b/src/main/java/com/glxp/api/dao/auth/SysUserRoleMapper.java index 691f8fe5..58eba9a3 100644 --- a/src/main/java/com/glxp/api/dao/auth/SysUserRoleMapper.java +++ b/src/main/java/com/glxp/api/dao/auth/SysUserRoleMapper.java @@ -19,4 +19,6 @@ public interface SysUserRoleMapper { SysUserRole selectByAuthId(Long id); + List selectUserRoleList(Long roleId); + } diff --git a/src/main/java/com/glxp/api/service/auth/ISysRoleService.java b/src/main/java/com/glxp/api/service/auth/ISysRoleService.java index 45878d16..6a2bfb81 100644 --- a/src/main/java/com/glxp/api/service/auth/ISysRoleService.java +++ b/src/main/java/com/glxp/api/service/auth/ISysRoleService.java @@ -85,6 +85,8 @@ public interface ISysRoleService { */ void checkRoleAllowed(SysRole role); + List selectUserRoleList(Long roleId); + /** * 校验角色是否有数据权限 * diff --git a/src/main/java/com/glxp/api/service/auth/impl/SysRoleServiceImpl.java b/src/main/java/com/glxp/api/service/auth/impl/SysRoleServiceImpl.java index b023f610..6bfcea09 100644 --- a/src/main/java/com/glxp/api/service/auth/impl/SysRoleServiceImpl.java +++ b/src/main/java/com/glxp/api/service/auth/impl/SysRoleServiceImpl.java @@ -187,6 +187,11 @@ public class SysRoleServiceImpl implements ISysRoleService { } } + @Override + public List selectUserRoleList(Long roleId) { + return sysUserRoleMapper.selectUserRoleList(roleId); + } + /** * 校验角色是否有数据权限 * diff --git a/src/main/resources/mybatis/mapper/auth/SysUserRoleMapper.xml b/src/main/resources/mybatis/mapper/auth/SysUserRoleMapper.xml index 58bf6871..f66af6b7 100644 --- a/src/main/resources/mybatis/mapper/auth/SysUserRoleMapper.xml +++ b/src/main/resources/mybatis/mapper/auth/SysUserRoleMapper.xml @@ -20,6 +20,13 @@ where user_id=#{id} + + DELETE