200 lines
7.0 KiB
Python
200 lines
7.0 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import os
|
|||
|
|
import re
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 读取岗位等级数据
|
|||
|
|
def load_job_levels():
|
|||
|
|
with open('网页未导入数据/文旅产业/岗位等级.json', 'r', encoding='utf-8') as f:
|
|||
|
|
data = json.load(f)
|
|||
|
|
|
|||
|
|
# 创建岗位名称到等级的映射
|
|||
|
|
job_levels_map = {}
|
|||
|
|
for item in data:
|
|||
|
|
job_name = item['❌岗位名称']
|
|||
|
|
level = item['前端查询名称']
|
|||
|
|
job_levels_map[job_name] = level
|
|||
|
|
|
|||
|
|
return job_levels_map
|
|||
|
|
|
|||
|
|
# 更新resumeInterviewMock.js文件 - 添加level字段
|
|||
|
|
def update_resume_interview_mock(job_levels_map):
|
|||
|
|
file_path = 'src/mocks/resumeInterviewMock.js'
|
|||
|
|
|
|||
|
|
# 备份文件
|
|||
|
|
backup_path = f'{file_path}.backup_{datetime.now().strftime("%Y%m%d_%H%M%S")}_levels'
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
with open(backup_path, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已备份: {backup_path}")
|
|||
|
|
|
|||
|
|
# 更新内容
|
|||
|
|
updated_count = 0
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
new_lines = []
|
|||
|
|
i = 0
|
|||
|
|
|
|||
|
|
while i < len(lines):
|
|||
|
|
line = lines[i]
|
|||
|
|
new_lines.append(line)
|
|||
|
|
|
|||
|
|
# 查找title字段
|
|||
|
|
if 'title:' in line and 'positions' not in line:
|
|||
|
|
# 提取岗位名称
|
|||
|
|
match = re.search(r'title:\s*["\']([^"\']+)["\']', line)
|
|||
|
|
if match:
|
|||
|
|
position_name = match.group(1)
|
|||
|
|
if position_name in job_levels_map:
|
|||
|
|
level = job_levels_map[position_name]
|
|||
|
|
# 检查下一行是否已经有level字段
|
|||
|
|
has_level = False
|
|||
|
|
for j in range(i+1, min(i+5, len(lines))):
|
|||
|
|
if 'level:' in lines[j]:
|
|||
|
|
has_level = True
|
|||
|
|
# 更新现有的level字段
|
|||
|
|
lines[j] = re.sub(
|
|||
|
|
r'level:\s*["\'][^"\']*["\']',
|
|||
|
|
f'level: "{level}"',
|
|||
|
|
lines[j]
|
|||
|
|
)
|
|||
|
|
updated_count += 1
|
|||
|
|
print(f"更新: {position_name} -> {level}")
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 如果没有level字段,添加一个
|
|||
|
|
if not has_level:
|
|||
|
|
# 在title后面添加level字段
|
|||
|
|
indent = len(line) - len(line.lstrip())
|
|||
|
|
new_level_line = ' ' * indent + f'level: "{level}",'
|
|||
|
|
# 找到合适的位置插入(在title之后)
|
|||
|
|
new_lines.append(new_level_line)
|
|||
|
|
updated_count += 1
|
|||
|
|
print(f"添加: {position_name} -> {level}")
|
|||
|
|
i += 1
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write('\n'.join(new_lines))
|
|||
|
|
|
|||
|
|
print(f"resumeInterviewMock.js 更新完成,共更新 {updated_count} 处")
|
|||
|
|
|
|||
|
|
# 更新companyJobsNew.json文件
|
|||
|
|
def update_company_jobs(job_levels_map):
|
|||
|
|
file_path = 'src/data/companyJobsNew.json'
|
|||
|
|
|
|||
|
|
# 备份文件
|
|||
|
|
backup_path = f'{file_path}.backup_{datetime.now().strftime("%Y%m%d_%H%M%S")}_levels'
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
data = json.load(f)
|
|||
|
|
with open(backup_path, 'w', encoding='utf-8') as f:
|
|||
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|||
|
|
print(f"已备份: {backup_path}")
|
|||
|
|
|
|||
|
|
# 更新数据
|
|||
|
|
updated_count = 0
|
|||
|
|
added_count = 0
|
|||
|
|
|
|||
|
|
for company in data:
|
|||
|
|
if 'jobs' in company:
|
|||
|
|
for job in company['jobs']:
|
|||
|
|
position_name = job.get('positionName', '')
|
|||
|
|
if position_name in job_levels_map:
|
|||
|
|
new_level = job_levels_map[position_name]
|
|||
|
|
if 'jobLevel' in job:
|
|||
|
|
old_level = job['jobLevel']
|
|||
|
|
if old_level != new_level:
|
|||
|
|
job['jobLevel'] = new_level
|
|||
|
|
updated_count += 1
|
|||
|
|
print(f"更新: {position_name}: {old_level} -> {new_level}")
|
|||
|
|
else:
|
|||
|
|
job['jobLevel'] = new_level
|
|||
|
|
added_count += 1
|
|||
|
|
print(f"添加: {position_name} -> {new_level}")
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|||
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|||
|
|
|
|||
|
|
print(f"companyJobsNew.json 更新完成,更新 {updated_count} 处,新增 {added_count} 处")
|
|||
|
|
|
|||
|
|
# 检查mockData.js中的项目库数据
|
|||
|
|
def check_mock_data_projects(job_levels_map):
|
|||
|
|
file_path = 'src/data/mockData.js'
|
|||
|
|
|
|||
|
|
print("检查mockData.js中的项目库数据...")
|
|||
|
|
|
|||
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 查找所有引用的岗位
|
|||
|
|
found_positions = set()
|
|||
|
|
|
|||
|
|
# 查找relatedPositions和targetPositions中的岗位
|
|||
|
|
pattern = r'["\']([^"\']+)["\']'
|
|||
|
|
|
|||
|
|
# 查找包含positions的行
|
|||
|
|
lines = content.split('\n')
|
|||
|
|
for i, line in enumerate(lines):
|
|||
|
|
if 'relatedPositions:' in line or 'targetPositions:' in line:
|
|||
|
|
# 查找数组内容
|
|||
|
|
j = i
|
|||
|
|
bracket_count = 0
|
|||
|
|
in_array = False
|
|||
|
|
while j < len(lines):
|
|||
|
|
if '[' in lines[j]:
|
|||
|
|
in_array = True
|
|||
|
|
bracket_count += lines[j].count('[')
|
|||
|
|
if in_array:
|
|||
|
|
matches = re.findall(pattern, lines[j])
|
|||
|
|
for match in matches:
|
|||
|
|
if match in job_levels_map:
|
|||
|
|
found_positions.add(match)
|
|||
|
|
bracket_count -= lines[j].count(']')
|
|||
|
|
if in_array and bracket_count <= 0:
|
|||
|
|
break
|
|||
|
|
j += 1
|
|||
|
|
|
|||
|
|
print(f"在项目库中找到 {len(found_positions)} 个不同的岗位引用:")
|
|||
|
|
for pos in sorted(found_positions):
|
|||
|
|
print(f" - {pos}: {job_levels_map[pos]}")
|
|||
|
|
|
|||
|
|
# 主函数
|
|||
|
|
def main():
|
|||
|
|
print("=" * 50)
|
|||
|
|
print("开始更新岗位等级数据 V2")
|
|||
|
|
print("=" * 50)
|
|||
|
|
|
|||
|
|
# 加载岗位等级映射
|
|||
|
|
job_levels_map = load_job_levels()
|
|||
|
|
print(f"已加载 {len(job_levels_map)} 个岗位等级映射")
|
|||
|
|
|
|||
|
|
# 显示等级分布
|
|||
|
|
level_counts = {}
|
|||
|
|
for level in job_levels_map.values():
|
|||
|
|
level_counts[level] = level_counts.get(level, 0) + 1
|
|||
|
|
print("\n岗位等级分布:")
|
|||
|
|
for level, count in level_counts.items():
|
|||
|
|
print(f" {level}: {count} 个岗位")
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 50)
|
|||
|
|
|
|||
|
|
# 更新各个文件
|
|||
|
|
print("\n1. 更新简历面试题数据...")
|
|||
|
|
update_resume_interview_mock(job_levels_map)
|
|||
|
|
|
|||
|
|
print("\n2. 更新公司岗位数据...")
|
|||
|
|
update_company_jobs(job_levels_map)
|
|||
|
|
|
|||
|
|
print("\n3. 检查项目库数据...")
|
|||
|
|
check_mock_data_projects(job_levels_map)
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 50)
|
|||
|
|
print("所有更新完成!")
|
|||
|
|
print("=" * 50)
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
main()
|