#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json import re def fix_position_levels(): """ 修复项目详情数据中的岗位等级标签,使其与能源岗位简历.json中的等级数据保持一致 """ # 读取能源岗位简历数据,建立岗位名称到等级的映射 with open("网页未导入数据/能源产业/能源岗位简历.json", 'r', encoding='utf-8') as f: resume_data = json.load(f) # 建立岗位名称到等级的映射字典 position_level_mapping = {} for item in resume_data: position_name = item.get("岗位名称", "") position_level = item.get("岗位等级标签", "技术骨干岗") # 默认为技术骨干岗 if position_name: position_level_mapping[position_name] = position_level print("🔍 岗位等级映射表:") for level in ["技术骨干岗", "储备干部岗", "普通岗"]: positions = [pos for pos, lv in position_level_mapping.items() if lv == level] print(f" {level}: {len(positions)}个岗位") for pos in positions[:3]: print(f" - {pos}") if len(positions) > 3: print(f" ... 还有{len(positions)-3}个岗位") print() # 读取当前的Mock数据 with open("src/mocks/projectLibraryMock.js", 'r', encoding='utf-8') as f: content = f.read() # 找到getMockProjectDetail函数中的projects数组 pattern = r'(export const getMockProjectDetail = \(id\) => \{\s*// 直接根据ID返回对应项目的详情\s*const projects = )\[[\s\S]*?\];' match = re.search(pattern, content) if not match: print("❌ 未找到projects数组") return # 提取项目数组部分 projects_start = match.start(1) + len(match.group(1)) projects_end = match.end() projects_section = content[projects_start:projects_end] # 逐个修复项目中的position级别 def fix_position_level(match_obj): level = match_obj.group(1) position = match_obj.group(2) # 查找正确的等级 correct_level = position_level_mapping.get(position, "技术骨干岗") return f'{{"level": "{correct_level}", "position": "{position}"}}' # 替换所有的position对象 position_pattern = r'\{\s*"level": "([^"]*)",\s*"position": "([^"]*)"\s*\}' fixed_projects_section = re.sub(position_pattern, fix_position_level, projects_section) # 重新构建完整的文件内容 updated_content = content[:projects_start] + fixed_projects_section # 写入更新后的内容 with open("src/mocks/projectLibraryMock.js", 'w', encoding='utf-8') as f: f.write(updated_content) # 统计修复结果 updated_matches = re.findall(position_pattern, fixed_projects_section) level_stats = {} for level, position in updated_matches: if level not in level_stats: level_stats[level] = [] level_stats[level].append(position) print("✅ 修复完成!更新后的等级标签统计:") for level, positions in level_stats.items(): print(f" {level}: {len(positions)}个岗位") for pos in positions[:3]: print(f" - {pos}") if len(positions) > 3: print(f" ... 还有{len(positions)-3}个岗位") print() print(f"📝 总计: {len(updated_matches)}个岗位的等级标签已更新") if __name__ == "__main__": fix_position_levels()