|
@@ -625,7 +625,7 @@ def get_minio_client():
|
|
|
|
|
|
def get_business_cards():
|
|
|
"""
|
|
|
- 获取所有名片记录
|
|
|
+ 获取所有名片记录,并为每个记录添加tag_count字段
|
|
|
|
|
|
Returns:
|
|
|
dict: 包含名片记录列表的字典
|
|
@@ -637,6 +637,40 @@ def get_business_cards():
|
|
|
# 转换为字典格式
|
|
|
cards_data = [card.to_dict() for card in cards]
|
|
|
|
|
|
+ # 从Neo4j图数据库获取每个名片对应的关系数量
|
|
|
+ try:
|
|
|
+ from app.services.neo4j_driver import neo4j_driver
|
|
|
+
|
|
|
+ # 构建批量查询的Cypher语句,获取所有Talent节点的关系数量
|
|
|
+ cypher_query = """
|
|
|
+ MATCH (t:Talent)-[r]-()
|
|
|
+ WHERE t.pg_id IS NOT NULL
|
|
|
+ RETURN t.pg_id as pg_id, count(r) as relation_count
|
|
|
+ """
|
|
|
+
|
|
|
+ # 执行查询获取关系数量映射
|
|
|
+ relation_counts = {}
|
|
|
+ with neo4j_driver.get_session() as session:
|
|
|
+ result = session.run(cypher_query)
|
|
|
+ for record in result:
|
|
|
+ pg_id = record['pg_id']
|
|
|
+ relation_count = record['relation_count']
|
|
|
+ relation_counts[pg_id] = relation_count
|
|
|
+
|
|
|
+ # 为每个名片记录添加tag_count字段
|
|
|
+ for card_data in cards_data:
|
|
|
+ card_id = card_data.get('id')
|
|
|
+ if card_id and card_id in relation_counts:
|
|
|
+ card_data['tag_count'] = relation_counts[card_id]
|
|
|
+ else:
|
|
|
+ card_data['tag_count'] = 0
|
|
|
+
|
|
|
+ except Exception as neo4j_error:
|
|
|
+ logging.warning(f"从Neo4j获取关系数量失败: {str(neo4j_error)}")
|
|
|
+ # 如果Neo4j查询失败,为所有记录设置tag_count为0
|
|
|
+ for card_data in cards_data:
|
|
|
+ card_data['tag_count'] = 0
|
|
|
+
|
|
|
return {
|
|
|
'code': 200,
|
|
|
'success': True,
|