feat: 收敛AI资源发布审批生命周期
- 统一工作流、知识库、聊天助手的发布、重新发布、下线与删除链路 - 收敛审批编排、生命周期状态机与展示态,补齐审批管理和快照预览 - 调整审批管理权限模型为单入口页面加内部按钮权限
This commit is contained in:
@@ -15,7 +15,11 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -32,6 +36,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
@Resource
|
||||
private SysAccountRoleService sysAccountRoleService;
|
||||
|
||||
/**
|
||||
* 根据账号查询菜单,并自动补齐已授权节点的父级菜单链。
|
||||
* <p>
|
||||
* 这样当角色只勾选了某个页面下的按钮权限或子能力时,
|
||||
* 其所属的页面菜单仍能正常出现在侧边栏中,避免出现“有子权限但无入口”的问题。
|
||||
*
|
||||
* @param entity 菜单过滤条件
|
||||
* @param accountId 账号 ID
|
||||
* @return 当前账号可访问的菜单集合
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> getMenusByAccountId(SysMenu entity, BigInteger accountId) {
|
||||
// 查询用户对应角色id集合
|
||||
@@ -48,11 +62,53 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
if (CollectionUtil.isEmpty(menuIds)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<BigInteger> fullMenuIds = collectMenuIdsWithParents(menuIds);
|
||||
// 查询当前用户拥有的菜单
|
||||
SqlOperators ops = SqlOperatorsUtil.build(SysMenu.class);
|
||||
QueryWrapper queryWrapper = QueryWrapper.create(entity, ops);
|
||||
queryWrapper.in(SysMenu::getId, menuIds);
|
||||
queryWrapper.in(SysMenu::getId, fullMenuIds);
|
||||
queryWrapper.orderBy("sort_no asc");
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集菜单自身及其所有父级菜单 ID。
|
||||
*
|
||||
* @param menuIds 已授权的菜单 ID 列表
|
||||
* @return 包含父级链路的完整菜单 ID 列表
|
||||
*/
|
||||
private List<BigInteger> collectMenuIdsWithParents(List<BigInteger> menuIds) {
|
||||
List<SysMenu> allMenus = list();
|
||||
if (CollectionUtil.isEmpty(allMenus)) {
|
||||
return menuIds;
|
||||
}
|
||||
Map<BigInteger, SysMenu> menuMap = new HashMap<>();
|
||||
for (SysMenu menu : allMenus) {
|
||||
menuMap.put(menu.getId(), menu);
|
||||
}
|
||||
Set<BigInteger> result = new HashSet<>(menuIds);
|
||||
for (BigInteger menuId : menuIds) {
|
||||
appendParentMenuIds(menuId, menuMap, result);
|
||||
}
|
||||
return new ArrayList<>(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归追加父级菜单 ID,直到根节点或无父节点为止。
|
||||
*
|
||||
* @param menuId 当前菜单 ID
|
||||
* @param menuMap 全量菜单映射
|
||||
* @param result 结果集合
|
||||
*/
|
||||
private void appendParentMenuIds(BigInteger menuId, Map<BigInteger, SysMenu> menuMap, Set<BigInteger> result) {
|
||||
SysMenu current = menuMap.get(menuId);
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
BigInteger parentId = current.getParentId();
|
||||
if (parentId == null || BigInteger.ZERO.equals(parentId) || !result.add(parentId)) {
|
||||
return;
|
||||
}
|
||||
appendParentMenuIds(parentId, menuMap, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user