Commit 4d46f4c1b5600c71bec9c08181b412acf9d13895
1 parent
a941c1b4
删除用户和角色解绑关联
Showing
5 changed files
with
34 additions
and
3 deletions
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java
| ... | ... | @@ -27,6 +27,14 @@ public interface SysRoleMenuMapper |
| 27 | 27 | public int deleteRoleMenuByRoleId(Long roleId); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | + * 批量删除角色菜单关联信息 | |
| 31 | + * | |
| 32 | + * @param ids 需要删除的数据ID | |
| 33 | + * @return 结果 | |
| 34 | + */ | |
| 35 | + public int deleteRoleMenu(Long[] ids); | |
| 36 | + | |
| 37 | + /** | |
| 30 | 38 | * 批量新增角色菜单信息 |
| 31 | 39 | * |
| 32 | 40 | * @param roleMenuList 角色菜单列表 | ... | ... |
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
| ... | ... | @@ -290,8 +290,13 @@ public class SysRoleServiceImpl implements ISysRoleService |
| 290 | 290 | * @return 结果 |
| 291 | 291 | */ |
| 292 | 292 | @Override |
| 293 | + @Transactional | |
| 293 | 294 | public int deleteRoleById(Long roleId) |
| 294 | 295 | { |
| 296 | + // 删除角色与菜单关联 | |
| 297 | + roleMenuMapper.deleteRoleMenuByRoleId(roleId); | |
| 298 | + // 删除角色与部门关联 | |
| 299 | + roleDeptMapper.deleteRoleDeptByRoleId(roleId); | |
| 295 | 300 | return roleMapper.deleteRoleById(roleId); |
| 296 | 301 | } |
| 297 | 302 | |
| ... | ... | @@ -302,6 +307,7 @@ public class SysRoleServiceImpl implements ISysRoleService |
| 302 | 307 | * @return 结果 |
| 303 | 308 | */ |
| 304 | 309 | @Override |
| 310 | + @Transactional | |
| 305 | 311 | public int deleteRoleByIds(Long[] roleIds) |
| 306 | 312 | { |
| 307 | 313 | for (Long roleId : roleIds) |
| ... | ... | @@ -313,6 +319,10 @@ public class SysRoleServiceImpl implements ISysRoleService |
| 313 | 319 | throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName())); |
| 314 | 320 | } |
| 315 | 321 | } |
| 322 | + // 删除角色与菜单关联 | |
| 323 | + roleMenuMapper.deleteRoleMenu(roleIds); | |
| 324 | + // 删除角色与部门关联 | |
| 325 | + roleDeptMapper.deleteRoleDept(roleIds); | |
| 316 | 326 | return roleMapper.deleteRoleByIds(roleIds); |
| 317 | 327 | } |
| 318 | 328 | } | ... | ... |
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java
| ... | ... | @@ -363,6 +363,7 @@ public class SysUserServiceImpl implements ISysUserService |
| 363 | 363 | * @return 结果 |
| 364 | 364 | */ |
| 365 | 365 | @Override |
| 366 | + @Transactional | |
| 366 | 367 | public int deleteUserById(Long userId) |
| 367 | 368 | { |
| 368 | 369 | // 删除用户与角色关联 |
| ... | ... | @@ -379,12 +380,17 @@ public class SysUserServiceImpl implements ISysUserService |
| 379 | 380 | * @return 结果 |
| 380 | 381 | */ |
| 381 | 382 | @Override |
| 383 | + @Transactional | |
| 382 | 384 | public int deleteUserByIds(Long[] userIds) |
| 383 | 385 | { |
| 384 | 386 | for (Long userId : userIds) |
| 385 | 387 | { |
| 386 | 388 | checkUserAllowed(new SysUser(userId)); |
| 387 | 389 | } |
| 390 | + // 删除用户与角色关联 | |
| 391 | + userRoleMapper.deleteUserRole(userIds); | |
| 392 | + // 删除用户与岗位关联 | |
| 393 | + userPostMapper.deleteUserPost(userIds); | |
| 388 | 394 | return userMapper.deleteUserByIds(userIds); |
| 389 | 395 | } |
| 390 | 396 | ... | ... |
ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml
| ... | ... | @@ -17,6 +17,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| 17 | 17 | delete from sys_role_menu where role_id=#{roleId} |
| 18 | 18 | </delete> |
| 19 | 19 | |
| 20 | + <delete id="deleteRoleMenu" parameterType="Long"> | |
| 21 | + delete from sys_role_menu where role_id in | |
| 22 | + <foreach collection="array" item="roleId" open="(" separator="," close=")"> | |
| 23 | + #{roleId} | |
| 24 | + </foreach> | |
| 25 | + </delete> | |
| 26 | + | |
| 20 | 27 | <insert id="batchRoleMenu"> |
| 21 | 28 | insert into sys_role_menu(role_id, menu_id) values |
| 22 | 29 | <foreach item="item" index="index" collection="list" separator=","> | ... | ... |
ruoyi-ui/src/assets/styles/ruoyi.scss