import json # 读取食品岗位简历数据,建立岗位等级映射 with open('网页未导入数据/食品产业/食品岗位简历.json', 'r', encoding='utf-8') as f: resumes = json.load(f) # 创建岗位名称到等级的映射 position_level_map = {} for resume in resumes: position_name = resume.get('岗位名称', '') level = resume.get('等级', '技术骨干岗') # 默认为技术骨干岗 if position_name: position_level_map[position_name] = level print(f"共找到 {len(position_level_map)} 个岗位等级映射") print("\n岗位等级分布:") level_counts = {} for pos, level in position_level_map.items(): level_counts[level] = level_counts.get(level, 0) + 1 for level, count in sorted(level_counts.items()): print(f" {level}: {count} 个岗位") # 读取项目库mock数据 with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f: mock_content = f.read() # 读取转换后的食品项目数据 with open('food_projects_converted.json', 'r', encoding='utf-8') as f: converted_data = json.load(f) # 更新项目详情中的岗位等级 updated_details = {} for project_id, detail in converted_data['projects_details'].items(): updated_positions = [] for pos_info in detail.get('positions', []): position_name = pos_info.get('position', '') # 查找对应的等级 if position_name in position_level_map: level = position_level_map[position_name] else: # 如果找不到精确匹配,保持原有等级 level = pos_info.get('level', '技术骨干岗') print(f"警告:岗位 '{position_name}' 未在简历数据中找到,使用默认等级: {level}") updated_positions.append({ "position": position_name, "level": level }) detail['positions'] = updated_positions updated_details[project_id] = detail # 同时更新列表数据中的岗位信息 updated_list = [] for item in converted_data['projects_list']: # 从详情中获取对应的岗位等级信息 detail = updated_details.get(str(item['id']), {}) positions_with_levels = detail.get('positions', []) # 更新列表项 updated_item = item.copy() updated_item['positionsWithLevels'] = positions_with_levels updated_list.append(updated_item) # 保存更新后的数据 updated_output = { "projects_list": updated_list, "projects_details": updated_details } with open('food_projects_with_levels.json', 'w', encoding='utf-8') as f: json.dump(updated_output, f, ensure_ascii=False, indent=2) print(f"\n已生成更新后的项目数据文件: food_projects_with_levels.json") # 显示几个示例 print("\n示例项目岗位等级更新:") for i, (pid, detail) in enumerate(list(updated_details.items())[:3]): print(f"\n项目 {pid}: {detail['name']}") for pos in detail['positions'][:3]: print(f" - {pos['position']}: {pos['level']}")