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