修复--修改角色菜单不生效
This commit is contained in:
@@ -18,10 +18,12 @@ import com.agileboot.system.user.dto.UserInfo;
|
||||
import com.agileboot.system.user.entity.SysUser;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -29,10 +31,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -95,6 +94,29 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
super.baseMapper.deleteAbsoluteByIds(collect);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void updateRole(UpdateRoleDTO updateDTO) {
|
||||
// LambdaQueryWrapper<SysRole> roleLqw = new LambdaQueryWrapper<>();
|
||||
// roleLqw.eq(SysRole::getRoleId, updateDTO.getRoleId());
|
||||
// roleLqw.eq(SysRole::getStatus, StatusEnum.ENABLE.getValue());
|
||||
// SysRole sysRole = getOne(roleLqw);
|
||||
// Preconditions.checkArgument(Objects.nonNull(sysRole), "角色不存在");
|
||||
// LambdaQueryWrapper<SysRoleMenu> roleMenuLqw = new LambdaQueryWrapper<>();
|
||||
// roleMenuLqw.eq(SysRoleMenu::getRoleId, updateDTO.getRoleId());
|
||||
// //角色对应的菜单
|
||||
// LambdaUpdateWrapper<SysRoleMenu> roleMenuLuw = new LambdaUpdateWrapper<>();
|
||||
// roleMenuLuw.eq(SysRoleMenu::getRoleId, updateDTO.getRoleId());
|
||||
// roleMenuService.cleanOldMenus(List.of(updateDTO.getRoleId()));//清空之前的角色菜单关联
|
||||
// List<Long> menuIds = updateDTO.getMenuIds();//新的菜单列表
|
||||
// if (!CollectionUtils.isEmpty(menuIds)) {
|
||||
// roleMenuService.saveMenus(updateDTO.getRoleId(), menuIds);
|
||||
// }
|
||||
// BeanUtils.copyProperties(updateDTO, sysRole, "roleId");
|
||||
// updateById(sysRole);
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateRole(UpdateRoleDTO updateDTO) {
|
||||
@@ -102,8 +124,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
if (byId == null) {
|
||||
throw new BizException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, updateDTO.getRoleId(), "角色");
|
||||
}
|
||||
List<SysRoleMenu> roleMenus = roleMenuService.listById(updateDTO.getRoleId());
|
||||
List<Long> menuIds = roleMenus.stream().map(SysRoleMenu::getMenuId).toList();
|
||||
// List<SysRoleMenu> roleMenus = roleMenuService.listById(updateDTO.getRoleId());
|
||||
List<Long> menuIds = updateDTO.getMenuIds();
|
||||
// List<Long> menuIds = roleMenus.stream().map(SysRoleMenu::getMenuId).toList();
|
||||
|
||||
// List<Long> deptIds = StrUtil.split(byId.getDeptIdSet(), ",").stream().map(Convert::toLong).toList();
|
||||
|
||||
@@ -112,7 +135,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
this.checkRoleNameUnique(byId.getRoleId(), byId.getRoleName());
|
||||
// 清空之前的角色菜单关联
|
||||
roleMenuService.cleanOldMenus(List.of(byId.getRoleId()));
|
||||
if (!roleMenuService.saveMenus(byId.getRoleId(), menuIds)) {
|
||||
boolean b = roleMenuService.saveMenus(byId.getRoleId(), menuIds);
|
||||
if (!b) {
|
||||
throw new BizException("修改角色失败");
|
||||
}
|
||||
super.updateById(byId);
|
||||
|
||||
Reference in New Issue
Block a user