|
|
@ -123,33 +123,34 @@ public class MenuServiceImpl implements MenuService { |
|
|
|
} |
|
|
|
if(roleVo.getMenuIds() == null||roleVo.getMenuIds().isEmpty()) { |
|
|
|
return Result.error("角色权限为空"); |
|
|
|
}else |
|
|
|
{ |
|
|
|
List<Integer> menuIds = new ArrayList<>(roleVo.getMenuIds()); // 创建副本避免修改原始列表 |
|
|
|
Set<Integer> processedIds = new HashSet<>(menuIds); // 使用Set快速检查存在性 |
|
|
|
|
|
|
|
// 处理每个菜单ID及其所有父菜单 |
|
|
|
for (int i = 0; i < menuIds.size(); i++) { |
|
|
|
Integer currentId = menuIds.get(i); |
|
|
|
|
|
|
|
// ID为1不处理 |
|
|
|
if (currentId == 1) continue; |
|
|
|
|
|
|
|
// 获取父菜单ID |
|
|
|
Integer fatherId = menuMapper.selectFatherId(currentId); |
|
|
|
|
|
|
|
// 递归添加所有父菜单 |
|
|
|
while (fatherId != null) { |
|
|
|
if (!processedIds.contains(fatherId)) { |
|
|
|
menuIds.add(fatherId); |
|
|
|
processedIds.add(fatherId); |
|
|
|
} |
|
|
|
// 继续向上查找父菜单的父菜单 |
|
|
|
fatherId = menuMapper.selectFatherId(fatherId); |
|
|
|
} |
|
|
|
} |
|
|
|
roleVo.setMenuIds(menuIds); |
|
|
|
} |
|
|
|
// else |
|
|
|
// { |
|
|
|
// List<Integer> menuIds = new ArrayList<>(roleVo.getMenuIds()); // 创建副本避免修改原始列表 |
|
|
|
// Set<Integer> processedIds = new HashSet<>(menuIds); // 使用Set快速检查存在性 |
|
|
|
// |
|
|
|
// // 处理每个菜单ID及其所有父菜单 |
|
|
|
// for (int i = 0; i < menuIds.size(); i++) { |
|
|
|
// Integer currentId = menuIds.get(i); |
|
|
|
// |
|
|
|
// // ID为1不处理 |
|
|
|
// if (currentId == 1) continue; |
|
|
|
// |
|
|
|
// // 获取父菜单ID |
|
|
|
// Integer fatherId = menuMapper.selectFatherId(currentId); |
|
|
|
// |
|
|
|
// // 递归添加所有父菜单 |
|
|
|
// while (fatherId != null) { |
|
|
|
// if (!processedIds.contains(fatherId)) { |
|
|
|
// menuIds.add(fatherId); |
|
|
|
// processedIds.add(fatherId); |
|
|
|
// } |
|
|
|
// // 继续向上查找父菜单的父菜单 |
|
|
|
// fatherId = menuMapper.selectFatherId(fatherId); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// roleVo.setMenuIds(menuIds); |
|
|
|
// } |
|
|
|
if(roleMapper.selectByRoleId(roleVo.getId())==null){ |
|
|
|
return Result.error("角色不存在"); |
|
|
|
} |
|
|
|