#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json import re import os import datetime import shutil def parse_interview_questions(content): """解析面试题内容""" questions = [] lines = content.split('\n') current_question = None current_answer = [] question_id = 1 in_answer = False for line in lines: line = line.strip() question_match = re.match(r'^(\d+)\.[\s ]+(.+)$', line) if question_match: if current_question and current_answer: answer_text = '\n'.join(current_answer).strip() if answer_text: current_question['answer'] = answer_text questions.append(current_question) current_answer = [] question_text = question_match.group(2).rstrip('??') current_question = { 'id': f'q{question_id}', 'question': question_text, 'answer': '' } question_id += 1 in_answer = False elif '示例答案' in line or '答案:' in line or '答案:' in line: in_answer = True answer_in_line = re.sub(r'^.*?(示例答案|答案)[::]?\s*', '', line).strip() if answer_in_line: current_answer.append(answer_in_line) elif in_answer and current_question and line: if not line.startswith('#'): current_answer.append(line) elif line.startswith('#') and current_question and current_answer: answer_text = '\n'.join(current_answer).strip() if answer_text: current_question['answer'] = answer_text questions.append(current_question) current_question = None current_answer = [] in_answer = False if current_question and current_answer: answer_text = '\n'.join(current_answer).strip() if answer_text: current_question['answer'] = answer_text questions.append(current_question) return questions def read_modified_resumes(): """读取所有修改版简历""" modified_resumes = {} folder_path = "网页未导入数据/能源产业/能源修改版简历" if os.path.exists(folder_path): for filename in os.listdir(folder_path): if filename.endswith('.md'): position_name = filename.replace('.md', '') file_path = os.path.join(folder_path, filename) with open(file_path, 'r', encoding='utf-8') as f: modified_resumes[position_name] = f.read() return modified_resumes def generate_complete_energy_data(): """生成包含修改版的完整能源数据""" # 读取能源岗位简历数据 with open("网页未导入数据/能源产业/能源岗位简历.json", 'r', encoding='utf-8') as f: energy_jobs = json.load(f) # 读取修改版简历 modified_resumes = read_modified_resumes() print(f"📚 找到 {len(modified_resumes)} 个修改版简历") # 岗位级别映射 level_mapping = { "高级": "技术骨干岗", "中级": "技术骨干岗", "普通": "普通岗", "": "普通岗" } # 默认头像 default_avatars = [ "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYv4rBd.jpeg", "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYvF54F.jpeg", "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/butler_position_avatar/recuPFYfYvumAH.jpeg" ] # 按岗位群分组 groups = {} for job in energy_jobs: group_name = job.get("简历岗位群", "") if group_name: if group_name not in groups: groups[group_name] = { "positions": [], "questions": None, "templates": [] } position_name = job.get("岗位名称", "") # 添加岗位信息 position = { "id": f"energy_{len(groups)}_{len(groups[group_name]['positions'])+1}", "title": position_name, "level": level_mapping.get(job.get("岗位等级标签", ""), "普通岗"), "avatar": job.get("简历头像url") or default_avatars[len(groups[group_name]['positions']) % 3], "department": group_name, "type": "全职", "experience": "1-3年", "education": "大专", "salary": "8-15K", "location": "北京", "updateTime": "2024-01-20", "description": f"负责{position_name}相关工作", "requirements": [] } groups[group_name]["positions"].append(position) # 准备简历模板内容 original_content = job.get("简历内容", "") modified_content = "" # 查找对应的修改版 if position_name in modified_resumes: modified_content = modified_resumes[position_name] print(f" ✅ 找到修改版: {position_name}") elif position_name.replace('PACK', 'pack') in modified_resumes: modified_content = modified_resumes[position_name.replace('PACK', 'pack')] print(f" ✅ 找到修改版: {position_name} (大小写)") elif position_name.replace('pack', 'PACK') in modified_resumes: modified_content = modified_resumes[position_name.replace('pack', 'PACK')] print(f" ✅ 找到修改版: {position_name} (大小写)") # 添加简历模板 template = { "position": position_name, "level": level_mapping.get(job.get("岗位等级标签", ""), "普通岗"), "avatar": job.get("简历头像url") or default_avatars[0], "content": { "original": original_content, "modified": modified_content }, "studentInfo": { "project_experience": { "project_name": "", "position": "", "time_period": "XXXXXX", "company": "XXXXXX", "description": "" }, "core_skills": [], "compound_skills": [], "personal_summary": "" } } groups[group_name]["templates"].append(template) # 提取面试题 if not groups[group_name]["questions"] and "面试题内容" in job: questions = parse_interview_questions(job["面试题内容"]) groups[group_name]["questions"] = questions # 生成industries数组和resumeTemplates industries = [] resumeTemplates = {} group_id = 1 for group_name, data in groups.items(): industry = { "id": f"energy_{group_id}", "name": group_name, "positions": data["positions"], "questions": [ { "id": f"group_q{group_id}", "question": f"# {group_name}面试题", "subQuestions": data["questions"] if data["questions"] else [] } ] } industries.append(industry) resumeTemplates[group_name] = data["templates"] group_id += 1 return industries, resumeTemplates def update_mock_file(): """更新mock文件""" mock_file = "src/mocks/resumeInterviewMock.js" # 备份 backup_path = f"{mock_file}.backup_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}" shutil.copy(mock_file, backup_path) print(f"✅ 已备份文件到:{backup_path}") # 生成新数据 industries, resumeTemplates = generate_complete_energy_data() # 生成完整内容 content = '''// 简历与面试题Mock数据 // 岗位群列表 const industries = %s; // 简历模板数据 const resumeTemplates = %s; // 我的简历数据 const myResume = { personalInfo: { name: "王强", phone: "138****8888", email: "wangqiang@example.com", age: 22, education: "苏州健雄职业技术学院 2020.9-2023.6", experience: "应届毕业生", location: "苏州" }, workExperience: [ { company: "苏州某智能制造企业", position: "模具设计与制造实习生", duration: "2023.03-2023.06", description: "负责模具设计与制造相关工作" } ], skills: ["模具设计", "机械制图", "CAD/CAM", "数控编程"], projects: [] }; export const resumeInterviewService = { getIndustries: async () => { // 模拟API调用延迟 await new Promise((resolve) => setTimeout(resolve, 500)); return industries; }, }; // 导出合并的数据 export const resumeInterviewMockData = { industries, resumeTemplates, myResume }; export function getMockPageData() { return resumeInterviewMockData; } export { myResume }; ''' % (json.dumps(industries, ensure_ascii=False, indent=2), json.dumps(resumeTemplates, ensure_ascii=False, indent=2)) # 写入文件 with open(mock_file, 'w', encoding='utf-8') as f: f.write(content) print("✅ 成功生成包含修改版的能源产业数据") # 统计 modified_count = 0 for group_templates in resumeTemplates.values(): for template in group_templates: if template["content"]["modified"]: modified_count += 1 print(f"\n📊 数据统计:") print(f" - 岗位群: {len(industries)}") print(f" - 总岗位: {sum(len(ind['positions']) for ind in industries)}") print(f" - 简历模板: {sum(len(templates) for templates in resumeTemplates.values())}") print(f" - 包含修改版: {modified_count}") print(f" - 面试题: {sum(len(ind['questions'][0]['subQuestions']) for ind in industries if ind['questions'])}") if __name__ == "__main__": update_mock_file()