删除用户和角色解绑关联

master
RuoYi 2020-12-09 10:14:10 +08:00
parent fb480530c8
commit ded17a552d
8 changed files with 24 additions and 22 deletions

View File

@ -170,16 +170,9 @@ public class SysRoleController extends BaseController
@PostMapping("/remove") @PostMapping("/remove")
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids)
{
try
{ {
return toAjax(roleService.deleteRoleByIds(ids)); return toAjax(roleService.deleteRoleByIds(ids));
} }
catch (Exception e)
{
return error(e.getMessage());
}
}
/** /**
* *

View File

@ -239,16 +239,9 @@ public class SysUserController extends BaseController
@PostMapping("/remove") @PostMapping("/remove")
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) public AjaxResult remove(String ids)
{
try
{ {
return toAjax(userService.deleteUserByIds(ids)); return toAjax(userService.deleteUserByIds(ids));
} }
catch (Exception e)
{
return error(e.getMessage());
}
}
/** /**
* *

View File

@ -308,7 +308,7 @@
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script> <script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ruoyi/js/ry-ui.js?v=4.5.1}"></script> <script th:src="@{/ruoyi/js/ry-ui.js?v=4.5.1}"></script>
<script th:src="@{/ruoyi/js/common.js?v=4.5.1}"></script> <script th:src="@{/ruoyi/js/common.js?v=4.5.1}"></script>
<script th:src="@{/ruoyi/index.js?v=20200902}"></script> <script th:src="@{/ruoyi/index.js?v=20201208}"></script>
<script th:src="@{/ajax/libs/fullscreen/jquery.fullscreen.js}"></script> <script th:src="@{/ajax/libs/fullscreen/jquery.fullscreen.js}"></script>
<script th:src="@{/js/resize-tabs.js}"></script> <script th:src="@{/js/resize-tabs.js}"></script>
<script th:inline="javascript"> <script th:inline="javascript">

View File

@ -258,7 +258,7 @@
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script> <script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ruoyi/js/ry-ui.js?v=4.5.1}"></script> <script th:src="@{/ruoyi/js/ry-ui.js?v=4.5.1}"></script>
<script th:src="@{/ruoyi/js/common.js?v=4.5.1}"></script> <script th:src="@{/ruoyi/js/common.js?v=4.5.1}"></script>
<script th:src="@{/ruoyi/index.js}"></script> <script th:src="@{/ruoyi/index.js?v=20201208}"></script>
<script th:src="@{/ajax/libs/fullscreen/jquery.fullscreen.js}"></script> <script th:src="@{/ajax/libs/fullscreen/jquery.fullscreen.js}"></script>
<script th:inline="javascript"> <script th:inline="javascript">
window.history.forward(1); window.history.forward(1);

View File

@ -66,7 +66,7 @@ public interface ISysRoleService
* @return * @return
* @throws Exception * @throws Exception
*/ */
public int deleteRoleByIds(String ids) throws Exception; public int deleteRoleByIds(String ids);
/** /**
* *

View File

@ -90,7 +90,7 @@ public interface ISysUserService
* @return * @return
* @throws Exception * @throws Exception
*/ */
public int deleteUserByIds(String ids) throws Exception; public int deleteUserByIds(String ids);
/** /**
* *

View File

@ -133,8 +133,13 @@ public class SysRoleServiceImpl implements ISysRoleService
* @return * @return
*/ */
@Override @Override
@Transactional
public boolean deleteRoleById(Long roleId) public boolean deleteRoleById(Long roleId)
{ {
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenuByRoleId(roleId);
// 删除角色与部门关联
roleDeptMapper.deleteRoleDeptByRoleId(roleId);
return roleMapper.deleteRoleById(roleId) > 0 ? true : false; return roleMapper.deleteRoleById(roleId) > 0 ? true : false;
} }
@ -145,7 +150,8 @@ public class SysRoleServiceImpl implements ISysRoleService
* @throws Exception * @throws Exception
*/ */
@Override @Override
public int deleteRoleByIds(String ids) throws BusinessException @Transactional
public int deleteRoleByIds(String ids)
{ {
Long[] roleIds = Convert.toLongArray(ids); Long[] roleIds = Convert.toLongArray(ids);
for (Long roleId : roleIds) for (Long roleId : roleIds)
@ -157,6 +163,10 @@ public class SysRoleServiceImpl implements ISysRoleService
throw new BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName())); throw new BusinessException(String.format("%1$s已分配,不能删除", role.getRoleName()));
} }
} }
// 删除角色与菜单关联
roleMenuMapper.deleteRoleMenu(roleIds);
// 删除角色与部门关联
roleDeptMapper.deleteRoleDept(roleIds);
return roleMapper.deleteRoleByIds(roleIds); return roleMapper.deleteRoleByIds(roleIds);
} }

View File

@ -160,6 +160,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return * @return
*/ */
@Override @Override
@Transactional
public int deleteUserById(Long userId) public int deleteUserById(Long userId)
{ {
// 删除用户与角色关联 // 删除用户与角色关联
@ -176,13 +177,18 @@ public class SysUserServiceImpl implements ISysUserService
* @return * @return
*/ */
@Override @Override
public int deleteUserByIds(String ids) throws BusinessException @Transactional
public int deleteUserByIds(String ids)
{ {
Long[] userIds = Convert.toLongArray(ids); Long[] userIds = Convert.toLongArray(ids);
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);
} }