|
@@ -985,6 +985,15 @@ def create_talent_tag(tag_data):
|
|
try:
|
|
try:
|
|
from app.services.neo4j_driver import neo4j_driver
|
|
from app.services.neo4j_driver import neo4j_driver
|
|
|
|
|
|
|
|
+ # 验证必要参数存在
|
|
|
|
+ if not tag_data or 'name' not in tag_data or not tag_data['name']:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 400,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': '标签名称为必填项',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
# 准备节点属性
|
|
# 准备节点属性
|
|
tag_properties = {
|
|
tag_properties = {
|
|
'name': tag_data.get('name'),
|
|
'name': tag_data.get('name'),
|
|
@@ -1327,38 +1336,33 @@ def query_neo4j_graph(query_requirement):
|
|
属性: pg_id(PostgreSQL数据库ID), name_zh(中文姓名), name_en(英文姓名),
|
|
属性: pg_id(PostgreSQL数据库ID), name_zh(中文姓名), name_en(英文姓名),
|
|
mobile(手机号码), email(电子邮箱), updated_at(更新时间)
|
|
mobile(手机号码), email(电子邮箱), updated_at(更新时间)
|
|
|
|
|
|
- 2. hotel - 酒店节点
|
|
|
|
- 属性: hotel_zh(酒店中文名称), hotel_en(酒店英文名称), updated_at(更新时间)
|
|
|
|
-
|
|
|
|
- 3. talent_tag - 人才标签节点
|
|
|
|
- 属性: name(标签名称), category(标签分类), en_name(英文名称)
|
|
|
|
-
|
|
|
|
- 4. hotel_tag - 酒店标签节点
|
|
|
|
- 属性: name(标签名称), category(标签分类), en_name(英文名称)
|
|
|
|
-
|
|
|
|
- 5. brand_group - 品牌集团节点
|
|
|
|
- 属性: name(集团名称), en_name(英文名称)
|
|
|
|
-
|
|
|
|
|
|
+ 2. data_label - 人才标签节点
|
|
|
|
+
|
|
### 关系
|
|
### 关系
|
|
- 1. WORKS_FOR - 工作关系,人才在酒店工作
|
|
|
|
- (talent)-[WORKS_FOR]->(hotel)
|
|
|
|
- 属性: title_zh(中文职位), title_en(英文职位), updated_at(更新时间)
|
|
|
|
-
|
|
|
|
- 2. BELONGS_TO - 从属关系
|
|
|
|
- (talent)-[BELONGS_TO]->(talent_tag) - 人才属于某标签
|
|
|
|
- (hotel)-[BELONGS_TO]->(hotel_tag) - 酒店属于某标签
|
|
|
|
- (hotel)-[BELONGS_TO]->(brand_group) - 酒店属于某品牌集团
|
|
|
|
|
|
+ BELONGS_TO - 从属关系
|
|
|
|
+ (talent)-[BELONGS_TO]->(data_label) - 人才属于某标签
|
|
|
|
|
|
## 查询需求
|
|
## 查询需求
|
|
- {query_requirement}
|
|
|
|
|
|
+ {query_requirement}。从查询需求中提取出需要查询的标签。用MATCH和WHERE语句描述。
|
|
|
|
+ 只用一个MATCH语句,描述(t:talent)-[:BELONGS_TO]->(dl:data_label)关系。
|
|
|
|
+ WHERE语句可以包含多个标签,用AND连接。
|
|
|
|
|
|
## 输出要求
|
|
## 输出要求
|
|
1. 只输出有效的Cypher查询语句,不要包含任何解释或注释
|
|
1. 只输出有效的Cypher查询语句,不要包含任何解释或注释
|
|
- 2. 确保查询结果包含有意义的列名
|
|
|
|
- 3. 根据需要使用适当的过滤、排序、聚合和限制
|
|
|
|
- 4. 尽量利用图数据库的特性来优化查询效率
|
|
|
|
|
|
+ 2. 确保return语句中包含talent节点属性
|
|
|
|
+ 3. 尽量利用图数据库的特性来优化查询效率
|
|
|
|
|
|
注意:请直接返回Cypher查询语句,无需任何其他文本。
|
|
注意:请直接返回Cypher查询语句,无需任何其他文本。
|
|
|
|
+
|
|
|
|
+ 例如:
|
|
|
|
+ 查找需求为:查找有新开酒店经验和五星级酒店经验,担任总经理的人。
|
|
|
|
+
|
|
|
|
+ 生成的Cypher查询语句为:
|
|
|
|
+ MATCH (t:talent)-[:BELONGS_TO]->(dl:data_label)
|
|
|
|
+ WHERE dl.name IN ['新开酒店经验', '五星级酒店', '总经理']
|
|
|
|
+ WITH t, COLLECT(DISTINCT dl.name) AS labels
|
|
|
|
+ WHERE size(labels) = 3
|
|
|
|
+ RETURN t.pg_id as pg_id, t.name_zh as name_zh, t.name_en as name_en, t.mobile as mobile, t.email as email, t.updated_at as updated_at
|
|
"""
|
|
"""
|
|
|
|
|
|
# 调用Deepseek API生成Cypher脚本
|
|
# 调用Deepseek API生成Cypher脚本
|
|
@@ -1574,6 +1578,17 @@ def talent_update_tags(data):
|
|
failed_items.append({'talent_pg_id': talent_id, 'tag': tag})
|
|
failed_items.append({'talent_pg_id': talent_id, 'tag': tag})
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
+ # 首先清除所有现有的BELONGS_TO关系
|
|
|
|
+ clear_relations_query = """
|
|
|
|
+ MATCH (t:talent)-[r:BELONGS_TO]->(:data_label)
|
|
|
|
+ WHERE t.pg_id = $talent_id
|
|
|
|
+ DELETE r
|
|
|
|
+ RETURN count(r) as deleted_count
|
|
|
|
+ """
|
|
|
|
+ clear_result = session.run(clear_relations_query, talent_id=int(talent_id))
|
|
|
|
+ deleted_count = clear_result.single()['deleted_count']
|
|
|
|
+ logging.info(f"已删除talent_id={talent_id}的{deleted_count}个已有标签关系")
|
|
|
|
+
|
|
# 处理每个标签
|
|
# 处理每个标签
|
|
for tag_name in tags:
|
|
for tag_name in tags:
|
|
try:
|
|
try:
|
|
@@ -1604,13 +1619,12 @@ def talent_update_tags(data):
|
|
tag_record = tag_result.single()
|
|
tag_record = tag_result.single()
|
|
tag_id = tag_record['tag_id']
|
|
tag_id = tag_record['tag_id']
|
|
|
|
|
|
- # 2. 创建人才与标签的BELONGS_TO关系(如果不存在)
|
|
|
|
|
|
+ # 2. 创建人才与标签的BELONGS_TO关系
|
|
create_relation_query = """
|
|
create_relation_query = """
|
|
MATCH (t:talent), (tag:data_label)
|
|
MATCH (t:talent), (tag:data_label)
|
|
WHERE t.pg_id = $talent_id AND tag.name = $tag_name
|
|
WHERE t.pg_id = $talent_id AND tag.name = $tag_name
|
|
- MERGE (t)-[r:BELONGS_TO]->(tag)
|
|
|
|
- ON CREATE SET r.created_at = $current_time
|
|
|
|
- ON MATCH SET r.updated_at = $current_time
|
|
|
|
|
|
+ CREATE (t)-[r:BELONGS_TO]->(tag)
|
|
|
|
+ SET r.created_at = $current_time
|
|
RETURN r
|
|
RETURN r
|
|
"""
|
|
"""
|
|
|
|
|
|
@@ -1670,6 +1684,47 @@ def talent_update_tags(data):
|
|
error_msg = f"更新人才标签关系失败: {str(e)}"
|
|
error_msg = f"更新人才标签关系失败: {str(e)}"
|
|
logging.error(error_msg, exc_info=True)
|
|
logging.error(error_msg, exc_info=True)
|
|
|
|
|
|
|
|
+ return {
|
|
|
|
+ 'code': 500,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': error_msg,
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+def get_business_card(card_id):
|
|
|
|
+ """
|
|
|
|
+ 根据ID从PostgreSQL数据库中获取名片记录
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ card_id (int): 名片记录ID
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ dict: 包含操作结果和名片信息的字典
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ # 查询指定ID的名片记录
|
|
|
|
+ card = BusinessCard.query.get(card_id)
|
|
|
|
+
|
|
|
|
+ if not card:
|
|
|
|
+ return {
|
|
|
|
+ 'code': 404,
|
|
|
|
+ 'success': False,
|
|
|
|
+ 'message': f'未找到ID为{card_id}的名片记录',
|
|
|
|
+ 'data': None
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 将记录转换为字典格式返回
|
|
|
|
+ return {
|
|
|
|
+ 'code': 200,
|
|
|
|
+ 'success': True,
|
|
|
|
+ 'message': '获取名片记录成功',
|
|
|
|
+ 'data': card.to_dict()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ error_msg = f"获取名片记录失败: {str(e)}"
|
|
|
|
+ logging.error(error_msg, exc_info=True)
|
|
|
|
+
|
|
return {
|
|
return {
|
|
'code': 500,
|
|
'code': 500,
|
|
'success': False,
|
|
'success': False,
|