fix: type_groups动态收集,空大类从根上不产生节点
This commit is contained in:
@@ -282,20 +282,20 @@ class KnowledgeService:
|
||||
|
||||
total_count = len(items)
|
||||
|
||||
# 按 source_type 分组,初始化所有已知类别
|
||||
type_groups: dict = {st: [] for st in self.SOURCE_TYPE_ORDER}
|
||||
# 按 source_type 分组:仅收集有数据的类别,再按固定顺序排列
|
||||
type_groups: dict = {}
|
||||
for item in items:
|
||||
st = item.source_type or "manual"
|
||||
if st not in type_groups:
|
||||
type_groups[st] = []
|
||||
type_groups[st].append(item)
|
||||
|
||||
# 只遍历有数据的类别,按 SOURCE_TYPE_ORDER 顺序
|
||||
children = []
|
||||
for st in self.SOURCE_TYPE_ORDER:
|
||||
st_items = type_groups.get(st, [])
|
||||
# 空类别(0条)不渲染
|
||||
if not st_items:
|
||||
if st not in type_groups:
|
||||
continue
|
||||
st_items = type_groups[st]
|
||||
|
||||
secondary_field = self.SECONDARY_GROUP_FIELD.get(st)
|
||||
grandchildren = []
|
||||
|
||||
Reference in New Issue
Block a user