feature:新增关系图谱显示功能,支持查看组织、角色、职业的所有关系连接。
This commit is contained in:
@@ -108,14 +108,14 @@ async def get_relationship_graph(
|
||||
for c in characters
|
||||
]
|
||||
|
||||
# 获取所有关系(边)
|
||||
# 获取所有角色关系(边)
|
||||
rels_result = await db.execute(
|
||||
select(CharacterRelationship).where(
|
||||
CharacterRelationship.project_id == project_id
|
||||
)
|
||||
)
|
||||
relationships = rels_result.scalars().all()
|
||||
|
||||
|
||||
links = [
|
||||
RelationshipGraphLink(
|
||||
source=r.character_from_id,
|
||||
@@ -126,8 +126,34 @@ async def get_relationship_graph(
|
||||
)
|
||||
for r in relationships
|
||||
]
|
||||
|
||||
logger.info(f"获取项目 {project_id} 的关系图谱:{len(nodes)} 个节点,{len(links)} 条关系")
|
||||
|
||||
# 获取组织成员关系(组织 -> 成员)并追加到图谱边
|
||||
# source 使用组织对应的角色ID(Organization.character_id),确保与节点ID一致
|
||||
members_result = await db.execute(
|
||||
select(OrganizationMember, Organization).join(
|
||||
Organization,
|
||||
OrganizationMember.organization_id == Organization.id
|
||||
).where(Organization.project_id == project_id)
|
||||
)
|
||||
org_members = members_result.all()
|
||||
|
||||
member_links = [
|
||||
RelationshipGraphLink(
|
||||
source=org.character_id,
|
||||
target=member.character_id,
|
||||
relationship=f"组织成员·{member.position}",
|
||||
intimacy=member.loyalty,
|
||||
status=member.status
|
||||
)
|
||||
for member, org in org_members
|
||||
]
|
||||
|
||||
links.extend(member_links)
|
||||
|
||||
logger.info(
|
||||
f"获取项目 {project_id} 的关系图谱:{len(nodes)} 个节点,"
|
||||
f"{len(relationships)} 条角色关系,{len(member_links)} 条组织成员关系"
|
||||
)
|
||||
return RelationshipGraphData(nodes=nodes, links=links)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user