fix(system): 修复更新账号时岗位为空时发生的空指针异常

This commit is contained in:
oc 2023-11-25 18:25:03 +08:00
parent 522ab17902
commit fb479d7d79
2 changed files with 7 additions and 5 deletions

View File

@ -138,8 +138,9 @@ public class PermissionServiceImpl implements PermissionService {
// 获得角色拥有菜单编号 // 获得角色拥有菜单编号
Set<Long> dbMenuIds = convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId); Set<Long> dbMenuIds = convertSet(roleMenuMapper.selectListByRoleId(roleId), RoleMenuDO::getMenuId);
// 计算新增和删除的菜单编号 // 计算新增和删除的菜单编号
Collection<Long> createMenuIds = CollUtil.subtract(menuIds, dbMenuIds); Set<Long> menuIdList = CollUtil.emptyIfNull(menuIds);
Collection<Long> deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIds); Collection<Long> createMenuIds = CollUtil.subtract(menuIdList, dbMenuIds);
Collection<Long> deleteMenuIds = CollUtil.subtract(dbMenuIds, menuIdList);
// 执行新增和删除对于已经授权的菜单不用做任何处理 // 执行新增和删除对于已经授权的菜单不用做任何处理
if (CollUtil.isNotEmpty(createMenuIds)) { if (CollUtil.isNotEmpty(createMenuIds)) {
roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, menuId -> { roleMenuMapper.insertBatch(CollectionUtils.convertList(createMenuIds, menuId -> {
@ -205,8 +206,9 @@ public class PermissionServiceImpl implements PermissionService {
Set<Long> dbRoleIds = convertSet(userRoleMapper.selectListByUserId(userId), Set<Long> dbRoleIds = convertSet(userRoleMapper.selectListByUserId(userId),
UserRoleDO::getRoleId); UserRoleDO::getRoleId);
// 计算新增和删除的角色编号 // 计算新增和删除的角色编号
Collection<Long> createRoleIds = CollUtil.subtract(roleIds, dbRoleIds); Set<Long> roleIdList = CollUtil.emptyIfNull(roleIds);
Collection<Long> deleteMenuIds = CollUtil.subtract(dbRoleIds, roleIds); Collection<Long> createRoleIds = CollUtil.subtract(roleIdList, dbRoleIds);
Collection<Long> deleteMenuIds = CollUtil.subtract(dbRoleIds, roleIdList);
// 执行新增和删除对于已经授权的角色不用做任何处理 // 执行新增和删除对于已经授权的角色不用做任何处理
if (!CollectionUtil.isEmpty(createRoleIds)) { if (!CollectionUtil.isEmpty(createRoleIds)) {
userRoleMapper.insertBatch(CollectionUtils.convertList(createRoleIds, roleId -> { userRoleMapper.insertBatch(CollectionUtils.convertList(createRoleIds, roleId -> {

View File

@ -117,7 +117,7 @@ public class AdminUserServiceImpl implements AdminUserService {
Long userId = reqVO.getId(); Long userId = reqVO.getId();
Set<Long> dbPostIds = convertSet(userPostMapper.selectListByUserId(userId), UserPostDO::getPostId); Set<Long> dbPostIds = convertSet(userPostMapper.selectListByUserId(userId), UserPostDO::getPostId);
// 计算新增和删除的岗位编号 // 计算新增和删除的岗位编号
Set<Long> postIds = updateObj.getPostIds(); Set<Long> postIds = CollUtil.emptyIfNull(updateObj.getPostIds());
Collection<Long> createPostIds = CollUtil.subtract(postIds, dbPostIds); Collection<Long> createPostIds = CollUtil.subtract(postIds, dbPostIds);
Collection<Long> deletePostIds = CollUtil.subtract(dbPostIds, postIds); Collection<Long> deletePostIds = CollUtil.subtract(dbPostIds, postIds);
// 执行新增和删除对于已经授权的菜单不用做任何处理 // 执行新增和删除对于已经授权的菜单不用做任何处理