|
@@ -220,7 +220,7 @@ def _handle_recruitment_task(created_by, data=None):
|
|
|
|
|
|
Args:
|
|
|
created_by (str): 创建者
|
|
|
- data (str): 招聘数据内容
|
|
|
+ data (str or list): 招聘数据内容,可以是JSON字符串或已解析的列表
|
|
|
|
|
|
Returns:
|
|
|
dict: 处理结果
|
|
@@ -239,7 +239,40 @@ def _handle_recruitment_task(created_by, data=None):
|
|
|
|
|
|
# 将传入的data参数写入task_source字段
|
|
|
if data:
|
|
|
- task_source['data'] = data
|
|
|
+ # 如果data是字符串,尝试解析为JSON
|
|
|
+ if isinstance(data, str):
|
|
|
+ try:
|
|
|
+ data_list = json.loads(data)
|
|
|
+ except json.JSONDecodeError:
|
|
|
+ # 如果不是有效的JSON,将其作为单个元素处理
|
|
|
+ data_list = [data]
|
|
|
+ elif isinstance(data, list):
|
|
|
+ data_list = data
|
|
|
+ else:
|
|
|
+ # 其他类型转换为列表
|
|
|
+ data_list = [data]
|
|
|
+
|
|
|
+ # 为每个数组元素添加指定字段
|
|
|
+ processed_data = []
|
|
|
+ for index, item in enumerate(data_list):
|
|
|
+ # 确保item是字典类型
|
|
|
+ if not isinstance(item, dict):
|
|
|
+ item = {"original_data": item}
|
|
|
+
|
|
|
+ # 添加指定字段
|
|
|
+ item.update({
|
|
|
+ "error": None,
|
|
|
+ "filename": "",
|
|
|
+ "index": index,
|
|
|
+ "message": "",
|
|
|
+ "minio_path": "",
|
|
|
+ "object_key": "",
|
|
|
+ "success": True
|
|
|
+ })
|
|
|
+
|
|
|
+ processed_data.append(item)
|
|
|
+
|
|
|
+ task_source['data'] = processed_data
|
|
|
|
|
|
# 创建解析任务记录
|
|
|
parse_task = ParseTaskRepository(
|
|
@@ -257,7 +290,7 @@ def _handle_recruitment_task(created_by, data=None):
|
|
|
db.session.add(parse_task)
|
|
|
db.session.commit()
|
|
|
|
|
|
- logging.info(f"成功创建招聘任务记录: {task_name}, 包含data参数: {'是' if data else '否'}")
|
|
|
+ logging.info(f"成功创建招聘任务记录: {task_name}, 处理了 {len(task_source.get('data', []))} 个数据项")
|
|
|
|
|
|
return {
|
|
|
'code': 200,
|
|
@@ -268,7 +301,8 @@ def _handle_recruitment_task(created_by, data=None):
|
|
|
'task_summary': {
|
|
|
'task_type': '招聘',
|
|
|
'description': '数据库记录处理任务',
|
|
|
- 'requires_files': False
|
|
|
+ 'requires_files': False,
|
|
|
+ 'processed_items': len(task_source.get('data', []))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -592,6 +626,49 @@ def add_parse_task(files, task_type, created_by='system', data=None, publish_tim
|
|
|
}
|
|
|
|
|
|
|
|
|
+def _update_origin_source_with_minio_path(existing_origin_source, minio_path):
|
|
|
+ """
|
|
|
+ 更新origin_source字段,将minio_path添加到JSON数组中
|
|
|
+
|
|
|
+ Args:
|
|
|
+ existing_origin_source: 现有的origin_source内容
|
|
|
+ minio_path: 要添加的minio_path
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ str: 更新后的origin_source JSON字符串
|
|
|
+ """
|
|
|
+ import json
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 如果minio_path为空,直接返回现有的origin_source
|
|
|
+ if not minio_path:
|
|
|
+ return existing_origin_source
|
|
|
+
|
|
|
+ # 解析现有的origin_source
|
|
|
+ if existing_origin_source:
|
|
|
+ try:
|
|
|
+ origin_list = json.loads(existing_origin_source)
|
|
|
+ if not isinstance(origin_list, list):
|
|
|
+ origin_list = [origin_list]
|
|
|
+ except (json.JSONDecodeError, TypeError):
|
|
|
+ # 如果解析失败,将现有内容作为单个元素
|
|
|
+ origin_list = [existing_origin_source] if existing_origin_source else []
|
|
|
+ else:
|
|
|
+ origin_list = []
|
|
|
+
|
|
|
+ # 添加新的minio_path(如果不存在)
|
|
|
+ if minio_path not in origin_list:
|
|
|
+ origin_list.append(minio_path)
|
|
|
+
|
|
|
+ # 返回JSON字符串
|
|
|
+ return json.dumps(origin_list, ensure_ascii=False)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ logging.error(f"更新origin_source失败: {str(e)}")
|
|
|
+ # 如果处理失败,返回原始的origin_source
|
|
|
+ return existing_origin_source
|
|
|
+
|
|
|
+
|
|
|
def add_single_talent(talent_data):
|
|
|
"""
|
|
|
添加单个人才记录(基于add_business_card逻辑,去除MinIO图片上传)
|
|
@@ -690,7 +767,9 @@ def add_single_talent(talent_data):
|
|
|
existing_card.brand_group = talent_data.get('brand_group', existing_card.brand_group)
|
|
|
# 更新image_path字段,从talent_data中获取
|
|
|
existing_card.image_path = talent_data.get('image_path', existing_card.image_path)
|
|
|
- existing_card.origin_source = talent_data.get('origin_source', existing_card.origin_source)
|
|
|
+ # 更新origin_source字段,将minio_path添加到JSON数组中
|
|
|
+ minio_path = talent_data.get('minio_path', '')
|
|
|
+ existing_card.origin_source = _update_origin_source_with_minio_path(existing_card.origin_source, minio_path)
|
|
|
existing_card.talent_profile = talent_data.get('talent_profile', existing_card.talent_profile)
|
|
|
existing_card.updated_by = 'talent_system'
|
|
|
|
|
@@ -703,6 +782,29 @@ def add_single_talent(talent_data):
|
|
|
|
|
|
logging.info(f"已更新现有人才记录,ID: {existing_card.id}")
|
|
|
|
|
|
+ # 在Neo4j图数据库中更新Talent节点
|
|
|
+ try:
|
|
|
+ from app.core.graph.graph_operations import create_or_get_node
|
|
|
+ from datetime import datetime
|
|
|
+
|
|
|
+ # 创建Talent节点属性
|
|
|
+ talent_properties = {
|
|
|
+ 'name_zh': existing_card.name_zh,
|
|
|
+ 'name_en': existing_card.name_en,
|
|
|
+ 'mobile': existing_card.mobile,
|
|
|
+ 'email': existing_card.email,
|
|
|
+ 'pg_id': existing_card.id, # PostgreSQL主记录的ID
|
|
|
+ 'updated_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ }
|
|
|
+
|
|
|
+ # 在Neo4j中更新或创建Talent节点
|
|
|
+ neo4j_node_id = create_or_get_node('Talent', **talent_properties)
|
|
|
+ logging.info(f"成功在Neo4j中更新Talent节点,Neo4j ID: {neo4j_node_id}, PostgreSQL ID: {existing_card.id}")
|
|
|
+
|
|
|
+ except Exception as neo4j_error:
|
|
|
+ logging.error(f"在Neo4j中更新Talent节点失败: {str(neo4j_error)}")
|
|
|
+ # Neo4j操作失败不影响主流程,继续返回成功结果
|
|
|
+
|
|
|
return {
|
|
|
'code': 200,
|
|
|
'success': True,
|
|
@@ -720,6 +822,34 @@ def add_single_talent(talent_data):
|
|
|
duplicate_check['reason']
|
|
|
)
|
|
|
|
|
|
+ # 更新origin_source字段,将minio_path添加到JSON数组中
|
|
|
+ minio_path = talent_data.get('minio_path', '')
|
|
|
+ main_card.origin_source = _update_origin_source_with_minio_path(main_card.origin_source, minio_path)
|
|
|
+ db.session.commit() # 提交origin_source的更新
|
|
|
+
|
|
|
+ # 在Neo4j图数据库中创建Talent节点
|
|
|
+ try:
|
|
|
+ from app.core.graph.graph_operations import create_or_get_node
|
|
|
+ from datetime import datetime
|
|
|
+
|
|
|
+ # 创建Talent节点属性
|
|
|
+ talent_properties = {
|
|
|
+ 'name_zh': main_card.name_zh,
|
|
|
+ 'name_en': main_card.name_en,
|
|
|
+ 'mobile': main_card.mobile,
|
|
|
+ 'email': main_card.email,
|
|
|
+ 'pg_id': main_card.id, # PostgreSQL主记录的ID
|
|
|
+ 'updated_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ }
|
|
|
+
|
|
|
+ # 在Neo4j中创建Talent节点
|
|
|
+ neo4j_node_id = create_or_get_node('Talent', **talent_properties)
|
|
|
+ logging.info(f"成功在Neo4j中创建Talent节点,Neo4j ID: {neo4j_node_id}, PostgreSQL ID: {main_card.id}")
|
|
|
+
|
|
|
+ except Exception as neo4j_error:
|
|
|
+ logging.error(f"在Neo4j中创建Talent节点失败: {str(neo4j_error)}")
|
|
|
+ # Neo4j操作失败不影响主流程,继续返回成功结果
|
|
|
+
|
|
|
return {
|
|
|
'code': 202, # Accepted,表示已接受但需要进一步处理
|
|
|
'success': True,
|
|
@@ -787,7 +917,7 @@ def add_single_talent(talent_data):
|
|
|
image_path=image_path, # 从talent_data获取图片路径
|
|
|
career_path=initial_career_path,
|
|
|
brand_group=talent_data.get('brand_group', ''),
|
|
|
- origin_source=talent_data.get('origin_source'),
|
|
|
+ origin_source=json.dumps([talent_data.get('minio_path', '')], ensure_ascii=False) if talent_data.get('minio_path') else None,
|
|
|
talent_profile=talent_data.get('talent_profile', ''),
|
|
|
status='active',
|
|
|
updated_by='talent_system'
|
|
@@ -798,6 +928,29 @@ def add_single_talent(talent_data):
|
|
|
|
|
|
logging.info(f"人才信息已保存到数据库,ID: {business_card.id}")
|
|
|
|
|
|
+ # 在Neo4j图数据库中创建Talent节点
|
|
|
+ try:
|
|
|
+ from app.core.graph.graph_operations import create_or_get_node
|
|
|
+ from datetime import datetime
|
|
|
+
|
|
|
+ # 创建Talent节点属性
|
|
|
+ talent_properties = {
|
|
|
+ 'name_zh': business_card.name_zh,
|
|
|
+ 'name_en': business_card.name_en,
|
|
|
+ 'mobile': business_card.mobile,
|
|
|
+ 'email': business_card.email,
|
|
|
+ 'pg_id': business_card.id, # PostgreSQL主记录的ID
|
|
|
+ 'updated_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ }
|
|
|
+
|
|
|
+ # 在Neo4j中创建Talent节点
|
|
|
+ neo4j_node_id = create_or_get_node('Talent', **talent_properties)
|
|
|
+ logging.info(f"成功在Neo4j中创建Talent节点,Neo4j ID: {neo4j_node_id}, PostgreSQL ID: {business_card.id}")
|
|
|
+
|
|
|
+ except Exception as neo4j_error:
|
|
|
+ logging.error(f"在Neo4j中创建Talent节点失败: {str(neo4j_error)}")
|
|
|
+ # Neo4j操作失败不影响主流程,继续返回成功结果
|
|
|
+
|
|
|
return {
|
|
|
'code': 200,
|
|
|
'success': True,
|