删除用户和角色解绑关联

This commit is contained in:
RuoYi 2020-12-09 10:32:53 +08:00
parent a941c1b488
commit 4d46f4c1b5
5 changed files with 34 additions and 3 deletions

View File

@ -26,6 +26,14 @@ public interface SysRoleMenuMapper
*/ */
public int deleteRoleMenuByRoleId(Long roleId); public int deleteRoleMenuByRoleId(Long roleId);
/**
* 批量删除角色菜单关联信息
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteRoleMenu(Long[] ids);
/** /**
* 批量新增角色菜单信息 * 批量新增角色菜单信息
* *

View File

@ -290,8 +290,13 @@ public class SysRoleServiceImpl implements ISysRoleService
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional
public int deleteRoleById(Long roleId) public int deleteRoleById(Long roleId)
{ {
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenuByRoleId(roleId);
// 删除角色与部门关联
roleDeptMapper.deleteRoleDeptByRoleId(roleId);
return roleMapper.deleteRoleById(roleId); return roleMapper.deleteRoleById(roleId);
} }
@ -302,6 +307,7 @@ public class SysRoleServiceImpl implements ISysRoleService
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional
public int deleteRoleByIds(Long[] roleIds) public int deleteRoleByIds(Long[] roleIds)
{ {
for (Long roleId : roleIds) for (Long roleId : roleIds)
@ -313,6 +319,10 @@ public class SysRoleServiceImpl implements ISysRoleService
throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName())); throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));
} }
} }
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenu(roleIds);
// 删除角色与部门关联
roleDeptMapper.deleteRoleDept(roleIds);
return roleMapper.deleteRoleByIds(roleIds); return roleMapper.deleteRoleByIds(roleIds);
} }
} }

View File

@ -363,6 +363,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional
public int deleteUserById(Long userId) public int deleteUserById(Long userId)
{ {
// 删除用户与角色关联 // 删除用户与角色关联
@ -379,12 +380,17 @@ public class SysUserServiceImpl implements ISysUserService
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional
public int deleteUserByIds(Long[] userIds) public int deleteUserByIds(Long[] userIds)
{ {
for (Long userId : userIds) for (Long userId : userIds)
{ {
checkUserAllowed(new SysUser(userId)); checkUserAllowed(new SysUser(userId));
} }
// 删除用户与角色关联
userRoleMapper.deleteUserRole(userIds);
// 删除用户与岗位关联
userPostMapper.deleteUserPost(userIds);
return userMapper.deleteUserByIds(userIds); return userMapper.deleteUserByIds(userIds);
} }

View File

@ -17,6 +17,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from sys_role_menu where role_id=#{roleId} delete from sys_role_menu where role_id=#{roleId}
</delete> </delete>
<delete id="deleteRoleMenu" parameterType="Long">
delete from sys_role_menu where role_id in
<foreach collection="array" item="roleId" open="(" separator="," close=")">
#{roleId}
</foreach>
</delete>
<insert id="batchRoleMenu"> <insert id="batchRoleMenu">
insert into sys_role_menu(role_id, menu_id) values insert into sys_role_menu(role_id, menu_id) values
<foreach item="item" index="index" collection="list" separator=","> <foreach item="item" index="index" collection="list" separator=",">

View File

@ -238,7 +238,7 @@
position: relative; position: relative;
float: right; float: right;
} }
/* XY 代码生成预览左右滑动 */ /* el-tabs提供滚动机制 */
.el-tabs__content{ .el-tabs__content {
overflow-x: scroll; overflow-x: scroll;
} }