137 lines
4.6 KiB
Python
137 lines
4.6 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
import datetime
|
|||
|
|
import shutil
|
|||
|
|
|
|||
|
|
def get_correct_positions_from_json():
|
|||
|
|
"""从化工项目案例.json获取每个项目的正确岗位列表"""
|
|||
|
|
|
|||
|
|
# 读取化工项目案例数据
|
|||
|
|
with open('网页未导入数据/化工产业/化工项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
data = json.load(f)
|
|||
|
|
|
|||
|
|
# 读取化工岗位简历数据获取等级映射
|
|||
|
|
with open('网页未导入数据/化工产业/化工岗位简历.json', 'r', encoding='utf-8') as f:
|
|||
|
|
resume_data = json.load(f)
|
|||
|
|
|
|||
|
|
position_levels = {}
|
|||
|
|
for item in resume_data:
|
|||
|
|
position = item.get('岗位名称', '').strip()
|
|||
|
|
level = item.get('岗位等级标签', '').strip()
|
|||
|
|
if position and level:
|
|||
|
|
position_levels[position] = level
|
|||
|
|
|
|||
|
|
project_positions = {}
|
|||
|
|
|
|||
|
|
for i, project in enumerate(data, 1):
|
|||
|
|
positions_str = project.get('适用岗位', '')
|
|||
|
|
|
|||
|
|
# 将岗位字符串分割成列表
|
|||
|
|
if positions_str:
|
|||
|
|
positions = [p.strip() for p in positions_str.replace(',', ',').split(',') if p.strip()]
|
|||
|
|
else:
|
|||
|
|
positions = []
|
|||
|
|
|
|||
|
|
# 为每个岗位添加等级
|
|||
|
|
positions_with_level = []
|
|||
|
|
for pos in positions:
|
|||
|
|
# 查找岗位等级
|
|||
|
|
if pos in position_levels:
|
|||
|
|
level = position_levels[pos]
|
|||
|
|
else:
|
|||
|
|
# 根据岗位名称推测等级
|
|||
|
|
if '工程师' in pos:
|
|||
|
|
level = '技术骨干岗'
|
|||
|
|
elif '技术员' in pos or '操作员' in pos or '实验员' in pos or '化验员' in pos or '质检员' in pos:
|
|||
|
|
level = '普通岗'
|
|||
|
|
elif '助理' in pos or '储备' in pos:
|
|||
|
|
level = '储备干部岗'
|
|||
|
|
elif '调色师' in pos or '调香师' in pos:
|
|||
|
|
level = '技术骨干岗'
|
|||
|
|
else:
|
|||
|
|
level = '技术骨干岗' # 默认
|
|||
|
|
|
|||
|
|
positions_with_level.append({
|
|||
|
|
'position': pos,
|
|||
|
|
'level': level
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
project_positions[i] = positions_with_level
|
|||
|
|
|
|||
|
|
return project_positions
|
|||
|
|
|
|||
|
|
def update_project_positions_in_mock():
|
|||
|
|
"""更新mock文件中每个项目的岗位列表"""
|
|||
|
|
|
|||
|
|
# 获取正确的岗位数据
|
|||
|
|
correct_positions = get_correct_positions_from_json()
|
|||
|
|
|
|||
|
|
# 读取mock文件
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 统计更新
|
|||
|
|
updates_made = 0
|
|||
|
|
|
|||
|
|
# 逐个项目更新岗位列表
|
|||
|
|
for project_id, positions in correct_positions.items():
|
|||
|
|
print(f"\n更新项目 {project_id} 的岗位列表:")
|
|||
|
|
|
|||
|
|
# 构建新的positions数组
|
|||
|
|
positions_array = []
|
|||
|
|
for pos in positions:
|
|||
|
|
positions_array.append(f''' {{
|
|||
|
|
"level": "{pos['level']}",
|
|||
|
|
"position": "{pos['position']}"
|
|||
|
|
}}''')
|
|||
|
|
|
|||
|
|
new_positions_str = ',\n'.join(positions_array)
|
|||
|
|
new_positions_block = f''' "positions": [
|
|||
|
|
{new_positions_str}
|
|||
|
|
]'''
|
|||
|
|
|
|||
|
|
# 使用正则表达式替换项目的positions数组
|
|||
|
|
# 查找模式:项目ID后的positions数组
|
|||
|
|
pattern = rf'("id":\s*{project_id},.*?"name":[^,]+,\s*)"positions":\s*\[[^\]]*\]'
|
|||
|
|
|
|||
|
|
# 替换为新的positions数组
|
|||
|
|
replacement = rf'\1{new_positions_block}'
|
|||
|
|
|
|||
|
|
new_content = re.sub(pattern, replacement, content, flags=re.DOTALL)
|
|||
|
|
|
|||
|
|
if new_content != content:
|
|||
|
|
content = new_content
|
|||
|
|
updates_made += 1
|
|||
|
|
print(f" ✅ 已更新 {len(positions)} 个岗位")
|
|||
|
|
for pos in positions:
|
|||
|
|
print(f" - {pos['position']} [{pos['level']}]")
|
|||
|
|
else:
|
|||
|
|
print(f" ⚠️ 未能更新")
|
|||
|
|
|
|||
|
|
# 保存更新后的文件
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print(f"\n{'=' * 60}")
|
|||
|
|
print(f"✅ 共更新了 {updates_made} 个项目的岗位列表")
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
import subprocess
|
|||
|
|
result = subprocess.run(['node', '-c', 'src/mocks/projectLibraryMock.js'],
|
|||
|
|
capture_output=True, text=True)
|
|||
|
|
if result.returncode == 0:
|
|||
|
|
print("✅ JavaScript语法检查通过")
|
|||
|
|
else:
|
|||
|
|
print(f"❌ JavaScript语法错误: {result.stderr}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
# 备份原文件
|
|||
|
|
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
|||
|
|
backup_file = f"src/mocks/projectLibraryMock.js.backup_{timestamp}"
|
|||
|
|
shutil.copy('src/mocks/projectLibraryMock.js', backup_file)
|
|||
|
|
print(f"✅ 已备份到: {backup_file}")
|
|||
|
|
|
|||
|
|
# 执行更新
|
|||
|
|
update_project_positions_in_mock()
|