157 lines
5.6 KiB
Python
157 lines
5.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 fix_project_detail_positions():
|
|||
|
|
"""修复项目详情中的岗位列表"""
|
|||
|
|
|
|||
|
|
# 获取正确的岗位数据
|
|||
|
|
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}
|
|||
|
|
]'''
|
|||
|
|
|
|||
|
|
# 在getMockProjectDetail函数中查找并替换
|
|||
|
|
# 查找模式:在getMockProjectDetail函数中,项目ID后的positions数组
|
|||
|
|
# 先找到getMockProjectDetail函数的位置
|
|||
|
|
detail_func_match = re.search(r'export const getMockProjectDetail.*?const projects = \[', content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if detail_func_match:
|
|||
|
|
# 获取函数开始位置
|
|||
|
|
func_start = detail_func_match.end()
|
|||
|
|
|
|||
|
|
# 找到该项目的详情定义
|
|||
|
|
# 模式:项目ID后到下一个项目或数组结束
|
|||
|
|
pattern = rf'({{[\s\S]*?"id":\s*{project_id},[^{{]*?)("positions":\s*\[[^\]]*?\]|[\s]*"positions":\s*\[[^\]]*?\])'
|
|||
|
|
|
|||
|
|
# 在函数内容中查找
|
|||
|
|
func_content = content[func_start:]
|
|||
|
|
match = re.search(pattern, func_content, re.DOTALL)
|
|||
|
|
|
|||
|
|
if match:
|
|||
|
|
# 计算替换位置
|
|||
|
|
start_pos = func_start + match.start(2)
|
|||
|
|
end_pos = func_start + match.end(2)
|
|||
|
|
|
|||
|
|
# 执行替换
|
|||
|
|
new_content = content[:start_pos] + new_positions_block + content[end_pos:]
|
|||
|
|
|
|||
|
|
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" ⚠️ 未能修复")
|
|||
|
|
else:
|
|||
|
|
print(f" ⚠️ 未找到项目 {project_id} 的详情定义")
|
|||
|
|
else:
|
|||
|
|
print(" ❌ 未找到getMockProjectDetail函数")
|
|||
|
|
|
|||
|
|
# 保存更新后的文件
|
|||
|
|
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}")
|
|||
|
|
|
|||
|
|
# 执行修复
|
|||
|
|
fix_project_detail_positions()
|