#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json import re from datetime import datetime # 备份当前文件 print("创建备份...") backup_time = datetime.now().strftime('%Y%m%d_%H%M%S') with open('src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f: content = f.read() with open(f'src/mocks/resumeInterviewMock.js.backup_plc_fix_{backup_time}', 'w', encoding='utf-8') as backup: backup.write(content) # PLC完整面试题数据(手动构建) plc_questions = ''' "questions": [ { "id": "group_q1", "question": "# 一、知识点问答题", "subQuestions": [ { "id": "q1_1", "question": "简述PLC的基本组成部分", "answer": "中央处理器(CPU)、输入/输出模块(I/O)、电源模块、编程设备(如电脑+软件)、通信模块。" }, { "id": "q1_2", "question": "说明梯形图(Ladder Diagram)中常开触点(NO)和常闭触点(NC)的区别", "answer": "常开触点(NO):未通电时断开,通电后闭合(符号:| |);常闭触点(NC):未通电时闭合,通电后断开(符号:|/|)" }, { "id": "q1_3", "question": "什么是传感器?列举两种常见类型", "answer": "检测物理量(如位置、温度)并转换为电信号的装置。例如:接近开关(检测金属)、光电传感器(检测物体有无)。" }, { "id": "q1_4", "question": "PLC程序中\\"自锁电路\\"的作用是什么?", "answer": "保持输出状态持续通电(如启动按钮松开后电机仍运行),直到停止信号触发。" } ] }, { "id": "group_q2", "question": "# 二、场景问答题", "subQuestions": [ { "id": "q2_1", "question": "设备运行时,某个气缸不动作,你会如何逐步排查?", "answer": "第1步:检查气源压力是否正常;第2步:确认PLC是否有输出信号(看输出指示灯);第3步:测试电磁阀是否通电(用万用表测电压);第4步:手动触发电磁阀检查气缸是否卡死" }, { "id": "q2_2", "question": "操作工按下启动按钮,但设备无反应,可能有哪些原因?", "answer": "急停按钮未复位;安全门未关闭;启动按钮接线松动;PLC未处于运行模式" }, { "id": "q2_3", "question": "发现PLC程序需要修改,你应该遵守什么操作流程?", "answer": "停机并挂\\"禁止操作\\"警示牌;备份原始程序;修改后模拟测试;经主管批准后下载到PLC;记录修改内容" } ] }, { "id": "group_q3", "question": "# 三、选择题", "subQuestions": [ { "id": "q3_1", "question": "PLC的输入信号通常来自( )", "answer": "B" }, { "id": "q3_2", "question": "以下哪种情况会导致PLC输出点烧坏?( )", "answer": "B" }, { "id": "q3_3", "question": "急停按钮的接线应采用( )", "answer": "B" }, { "id": "q3_4", "question": "表示\\"电机过载\\"的PLC输入信号一般由( )提供", "answer": "B" }, { "id": "q3_5", "question": "梯形图中( )符号代表( )", "answer": "A" }, { "id": "q3_6", "question": "PLC通信中,RS485接口的特点是( )", "answer": "B" }, { "id": "q3_7", "question": "发现现场导线破损露铜,正确处理是( )", "answer": "B" }, { "id": "q3_8", "question": "编写PLC程序时,注释的作用是( )", "answer": "B" }, { "id": "q3_9", "question": "设备维护后首次上电,应( )", "answer": "B" } ] } ]''' # 替换PLC的questions部分 print("正在替换PLC面试题...") pattern = r'("name": "PLC".*?"questions": \[.*?\]\s*)(?=\s*\})' replacement = lambda m: m.group(0).split('"questions": [')[0] + plc_questions new_content = re.sub(pattern, replacement, content, flags=re.DOTALL) # 保存文件 with open('src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f: f.write(new_content) print("✅ PLC面试题更新完成!") # 验证语法 import subprocess result = subprocess.run(['node', '-c', 'src/mocks/resumeInterviewMock.js'], capture_output=True, text=True) if result.returncode == 0: print("✅ 语法检查通过!") print("PLC现在有3个章节,16道题") else: print("❌ 语法错误:") print(result.stderr)