|
@@ -598,14 +598,13 @@ 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, task_type=None):
|
|
|
|
|
|
+def _update_origin_source_with_minio_path(existing_origin_source, talent_data=None):
|
|
"""
|
|
"""
|
|
- 更新origin_source字段,将minio_path和task_type组成的JSON对象添加到JSON数组中
|
|
|
|
|
|
+ 更新origin_source字段,将talent_data提供的origin_source与现有的origin_source进行合并
|
|
|
|
|
|
Args:
|
|
Args:
|
|
existing_origin_source: 现有的origin_source内容
|
|
existing_origin_source: 现有的origin_source内容
|
|
- minio_path: 要添加的minio_path
|
|
|
|
- task_type: 任务类型
|
|
|
|
|
|
+ talent_data: 人才数据,包含origin_source字段
|
|
|
|
|
|
Returns:
|
|
Returns:
|
|
str: 更新后的origin_source JSON字符串
|
|
str: 更新后的origin_source JSON字符串
|
|
@@ -625,25 +624,27 @@ def _update_origin_source_with_minio_path(existing_origin_source, minio_path, ta
|
|
else:
|
|
else:
|
|
origin_list = []
|
|
origin_list = []
|
|
|
|
|
|
- # 如果minio_path不为空,则创建新的JSON对象并添加到列表中
|
|
|
|
- if minio_path:
|
|
|
|
- # 创建新的JSON对象,格式为 {task_type: "任务类型", minio_path: "路径", source_date: "时间"}
|
|
|
|
- from datetime import datetime
|
|
|
|
- new_entry = {
|
|
|
|
- "task_type": task_type if task_type else "",
|
|
|
|
- "minio_path": minio_path,
|
|
|
|
- "source_date": datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- # 检查是否已存在相同的条目
|
|
|
|
- entry_exists = False
|
|
|
|
- for existing_entry in origin_list:
|
|
|
|
- if isinstance(existing_entry, dict) and existing_entry.get('minio_path') == minio_path:
|
|
|
|
- entry_exists = True
|
|
|
|
- break
|
|
|
|
-
|
|
|
|
- if not entry_exists:
|
|
|
|
- origin_list.append(new_entry)
|
|
|
|
|
|
+ # 处理talent_data提供的origin_source
|
|
|
|
+ if talent_data and talent_data.get('origin_source'):
|
|
|
|
+ talent_origin_source = talent_data.get('origin_source')
|
|
|
|
+ if isinstance(talent_origin_source, list):
|
|
|
|
+ # 如果是列表,直接合并
|
|
|
|
+ for entry in talent_origin_source:
|
|
|
|
+ if isinstance(entry, dict) and entry not in origin_list:
|
|
|
|
+ origin_list.append(entry)
|
|
|
|
+ elif isinstance(talent_origin_source, str):
|
|
|
|
+ # 如果是字符串,尝试解析为JSON
|
|
|
|
+ try:
|
|
|
|
+ parsed_talent_origin = json.loads(talent_origin_source)
|
|
|
|
+ if isinstance(parsed_talent_origin, list):
|
|
|
|
+ for entry in parsed_talent_origin:
|
|
|
|
+ if isinstance(entry, dict) and entry not in origin_list:
|
|
|
|
+ origin_list.append(entry)
|
|
|
|
+ elif isinstance(parsed_talent_origin, dict) and parsed_talent_origin not in origin_list:
|
|
|
|
+ origin_list.append(parsed_talent_origin)
|
|
|
|
+ except (json.JSONDecodeError, TypeError):
|
|
|
|
+ # 如果解析失败,忽略talent_data的origin_source
|
|
|
|
+ pass
|
|
|
|
|
|
# 返回JSON字符串
|
|
# 返回JSON字符串
|
|
return json.dumps(origin_list, ensure_ascii=False)
|
|
return json.dumps(origin_list, ensure_ascii=False)
|
|
@@ -754,17 +755,15 @@ def add_single_talent(talent_data, minio_path=None, task_type=None):
|
|
existing_card.brand_group = talent_data.get('brand_group', existing_card.brand_group)
|
|
existing_card.brand_group = talent_data.get('brand_group', existing_card.brand_group)
|
|
# 更新image_path字段,从talent_data中获取
|
|
# 更新image_path字段,从talent_data中获取
|
|
existing_card.image_path = talent_data.get('image_path', existing_card.image_path)
|
|
existing_card.image_path = talent_data.get('image_path', existing_card.image_path)
|
|
- # 更新origin_source字段,将minio_path添加到JSON数组中
|
|
|
|
- # 只有当minio_path不为空时才更新origin_source
|
|
|
|
- if minio_path:
|
|
|
|
- existing_card.origin_source = _update_origin_source_with_minio_path(existing_card.origin_source, minio_path, task_type)
|
|
|
|
|
|
+ # 更新origin_source字段,将talent_data提供的origin_source与现有的origin_source进行合并
|
|
|
|
+ existing_card.origin_source = _update_origin_source_with_minio_path(existing_card.origin_source, talent_data)
|
|
existing_card.talent_profile = talent_data.get('talent_profile', existing_card.talent_profile)
|
|
existing_card.talent_profile = talent_data.get('talent_profile', existing_card.talent_profile)
|
|
existing_card.updated_by = 'talent_system'
|
|
existing_card.updated_by = 'talent_system'
|
|
|
|
|
|
# 更新职业轨迹,传递从talent_data获取的图片路径
|
|
# 更新职业轨迹,传递从talent_data获取的图片路径
|
|
from app.core.data_parse.parse_system import update_career_path
|
|
from app.core.data_parse.parse_system import update_career_path
|
|
image_path = talent_data.get('image_path', '')
|
|
image_path = talent_data.get('image_path', '')
|
|
- existing_card.career_path = update_career_path(existing_card, talent_data, image_path)
|
|
|
|
|
|
+ existing_card.career_path = update_career_path(existing_card, talent_data)
|
|
|
|
|
|
db.session.commit()
|
|
db.session.commit()
|
|
|
|
|
|
@@ -822,10 +821,8 @@ def add_single_talent(talent_data, minio_path=None, task_type=None):
|
|
duplicate_check['reason']
|
|
duplicate_check['reason']
|
|
)
|
|
)
|
|
|
|
|
|
- # 更新origin_source字段,将minio_path添加到JSON数组中
|
|
|
|
- # 只有当minio_path不为空时才更新origin_source
|
|
|
|
- if minio_path:
|
|
|
|
- main_card.origin_source = _update_origin_source_with_minio_path(main_card.origin_source, minio_path, task_type)
|
|
|
|
|
|
+ # 更新origin_source字段,将talent_data提供的origin_source与现有的origin_source进行合并
|
|
|
|
+ main_card.origin_source = _update_origin_source_with_minio_path(main_card.origin_source, talent_data)
|
|
db.session.commit() # 提交origin_source的更新
|
|
db.session.commit() # 提交origin_source的更新
|
|
|
|
|
|
# 在Neo4j图数据库中创建Talent节点
|
|
# 在Neo4j图数据库中创建Talent节点
|
|
@@ -879,18 +876,11 @@ def add_single_talent(talent_data, minio_path=None, task_type=None):
|
|
|
|
|
|
else:
|
|
else:
|
|
# 创建新记录
|
|
# 创建新记录
|
|
- # 准备初始职业轨迹,包含从talent_data获取的图片路径
|
|
|
|
|
|
+ # 直接使用上传的请求参数talent_data中的career_path记录
|
|
|
|
+ career_path = talent_data.get('career_path', [])
|
|
|
|
+
|
|
|
|
+ # 获取图片路径
|
|
image_path = talent_data.get('image_path', '')
|
|
image_path = talent_data.get('image_path', '')
|
|
- initial_entry = {
|
|
|
|
- 'date': datetime.now().strftime('%Y-%m-%d'),
|
|
|
|
- 'hotel_zh': talent_data.get('hotel_zh', ''),
|
|
|
|
- 'hotel_en': talent_data.get('hotel_en', ''),
|
|
|
|
- 'title_zh': talent_data.get('title_zh', ''),
|
|
|
|
- 'title_en': talent_data.get('title_en', ''),
|
|
|
|
- 'image_path': image_path, # 从talent_data获取图片路径
|
|
|
|
- 'source': 'talent_data_creation'
|
|
|
|
- }
|
|
|
|
- initial_career_path = [initial_entry]
|
|
|
|
|
|
|
|
# 导入手机号码处理函数和BusinessCard模型
|
|
# 导入手机号码处理函数和BusinessCard模型
|
|
from app.core.data_parse.parse_system import normalize_mobile_numbers, BusinessCard
|
|
from app.core.data_parse.parse_system import normalize_mobile_numbers, BusinessCard
|
|
@@ -928,9 +918,9 @@ def add_single_talent(talent_data, minio_path=None, task_type=None):
|
|
native_place=talent_data.get('native_place', ''),
|
|
native_place=talent_data.get('native_place', ''),
|
|
residence=talent_data.get('residence', ''),
|
|
residence=talent_data.get('residence', ''),
|
|
image_path=image_path, # 从talent_data获取图片路径
|
|
image_path=image_path, # 从talent_data获取图片路径
|
|
- career_path=initial_career_path,
|
|
|
|
|
|
+ career_path=career_path, # 直接使用talent_data中的career_path
|
|
brand_group=talent_data.get('brand_group', ''),
|
|
brand_group=talent_data.get('brand_group', ''),
|
|
- origin_source=_update_origin_source_with_minio_path(None, minio_path, task_type) if minio_path else None,
|
|
|
|
|
|
+ origin_source=_update_origin_source_with_minio_path(None, talent_data),
|
|
talent_profile=talent_data.get('talent_profile', ''),
|
|
talent_profile=talent_data.get('talent_profile', ''),
|
|
status='active',
|
|
status='active',
|
|
updated_by='talent_system'
|
|
updated_by='talent_system'
|
|
@@ -1102,6 +1092,24 @@ def add_parsed_talents(api_response_data):
|
|
try:
|
|
try:
|
|
talent_result = add_single_talent(talent_data, minio_path, task_type)
|
|
talent_result = add_single_talent(talent_data, minio_path, task_type)
|
|
if talent_result.get('success', False):
|
|
if talent_result.get('success', False):
|
|
|
|
+ # 成功处理后,更新parsed_talents表中对应记录的status为"已入库"
|
|
|
|
+ talent_id = talent_data.get('id')
|
|
|
|
+ if talent_id:
|
|
|
|
+ try:
|
|
|
|
+ from app.core.data_parse.parse_system import ParsedTalent, db
|
|
|
|
+ # 查询并更新parsed_talents表中的记录
|
|
|
|
+ parsed_record = ParsedTalent.query.get(talent_id)
|
|
|
|
+ if parsed_record:
|
|
|
|
+ parsed_record.status = '已入库'
|
|
|
|
+ parsed_record.updated_at = datetime.now()
|
|
|
|
+ parsed_record.updated_by = 'system'
|
|
|
|
+ db.session.commit()
|
|
|
|
+ logging.info(f"已更新parsed_talents表记录状态: id={talent_id}, status=已入库")
|
|
|
|
+ else:
|
|
|
|
+ logging.warning(f"未找到ID为{talent_id}的parsed_talents记录")
|
|
|
|
+ except Exception as update_error:
|
|
|
|
+ logging.error(f"更新parsed_talents记录状态失败: {str(update_error)}")
|
|
|
|
+
|
|
success_count += 1
|
|
success_count += 1
|
|
processed_results.append({
|
|
processed_results.append({
|
|
'index': i,
|
|
'index': i,
|