174 lines
5.8 KiB
Python
174 lines
5.8 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
import json
|
|||
|
|
import os
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 读取视觉设计项目案例数据
|
|||
|
|
print("正在读取视觉设计项目案例数据...")
|
|||
|
|
with open('网页未导入数据/视觉设计产业/视觉设计项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
visual_design_data = json.load(f)
|
|||
|
|
|
|||
|
|
print(f"找到 {len(visual_design_data)} 个视觉设计项目案例")
|
|||
|
|
|
|||
|
|
# 读取mock文件
|
|||
|
|
mock_file = 'src/mocks/projectLibraryMock.js'
|
|||
|
|
print(f"\n正在读取文件:{mock_file}")
|
|||
|
|
|
|||
|
|
with open(mock_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 创建备份
|
|||
|
|
backup_file = f"{mock_file}.backup_fix_positions_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
|||
|
|
with open(backup_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print(f"已创建备份:{backup_file}")
|
|||
|
|
|
|||
|
|
# 找到 getMockProjectDetail 函数
|
|||
|
|
detail_func_start = content.find('export const getMockProjectDetail = (id) => {')
|
|||
|
|
if detail_func_start == -1:
|
|||
|
|
print("❌ 未找到 getMockProjectDetail 函数")
|
|||
|
|
exit(1)
|
|||
|
|
|
|||
|
|
# 为每个项目更新positions和units
|
|||
|
|
for i, case in enumerate(visual_design_data, 1):
|
|||
|
|
print(f"\n更新项目 {i}: {case.get('案例名称', '未知')}")
|
|||
|
|
|
|||
|
|
# 提取原始数据
|
|||
|
|
name = case.get('案例名称', '未知项目')
|
|||
|
|
positions_str = case.get('对应个人简历名称', '')
|
|||
|
|
unit_compound = case.get('对应单元名称(复合能力课)', '')
|
|||
|
|
unit_vertical = case.get('对应单元名称(垂直能力课)', '')
|
|||
|
|
direction = case.get('所属垂直方向', '')
|
|||
|
|
|
|||
|
|
# 查找项目在mock文件中的位置
|
|||
|
|
search_pattern = f'"id": {i},'
|
|||
|
|
id_pos = content.find(search_pattern, detail_func_start)
|
|||
|
|
if id_pos == -1:
|
|||
|
|
print(f" ✗ 未找到项目ID {i}")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 找到该项目的positions数组
|
|||
|
|
positions_start = content.find('"positions":', id_pos)
|
|||
|
|
if positions_start == -1:
|
|||
|
|
print(f" ✗ 未找到positions字段")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 找到positions数组的开始和结束
|
|||
|
|
array_start = content.find('[', positions_start)
|
|||
|
|
if array_start == -1:
|
|||
|
|
print(f" ✗ 未找到positions数组开始")
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# 找到positions数组的结束
|
|||
|
|
bracket_count = 0
|
|||
|
|
in_string = False
|
|||
|
|
escape_next = False
|
|||
|
|
array_end = array_start
|
|||
|
|
|
|||
|
|
for j in range(array_start, len(content)):
|
|||
|
|
char = content[j]
|
|||
|
|
if escape_next:
|
|||
|
|
escape_next = False
|
|||
|
|
continue
|
|||
|
|
if char == '\\':
|
|||
|
|
escape_next = True
|
|||
|
|
continue
|
|||
|
|
if char == '"' and not in_string:
|
|||
|
|
in_string = True
|
|||
|
|
elif char == '"' and in_string:
|
|||
|
|
in_string = False
|
|||
|
|
elif not in_string:
|
|||
|
|
if char == '[':
|
|||
|
|
bracket_count += 1
|
|||
|
|
elif char == ']':
|
|||
|
|
bracket_count -= 1
|
|||
|
|
if bracket_count == 0:
|
|||
|
|
array_end = j
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 解析岗位列表
|
|||
|
|
positions_list = []
|
|||
|
|
if positions_str:
|
|||
|
|
# 使用逗号分割岗位
|
|||
|
|
if ',' in positions_str:
|
|||
|
|
pos_list = positions_str.split(',')
|
|||
|
|
elif '、' in positions_str:
|
|||
|
|
pos_list = positions_str.split('、')
|
|||
|
|
else:
|
|||
|
|
pos_list = [positions_str]
|
|||
|
|
|
|||
|
|
for pos in pos_list[:4]: # 最多取4个岗位
|
|||
|
|
pos_clean = pos.strip()
|
|||
|
|
if pos_clean:
|
|||
|
|
# 根据岗位名称判断级别
|
|||
|
|
if '助理' in pos_clean or '实习' in pos_clean:
|
|||
|
|
level = "普通岗"
|
|||
|
|
elif '总监' in pos_clean or '经理' in pos_clean or '主管' in pos_clean:
|
|||
|
|
level = "储备干部岗"
|
|||
|
|
else:
|
|||
|
|
level = "技术骨干岗"
|
|||
|
|
|
|||
|
|
positions_list.append({
|
|||
|
|
"level": level,
|
|||
|
|
"position": pos_clean
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
# 如果没有岗位,使用默认值
|
|||
|
|
if not positions_list:
|
|||
|
|
positions_list = [{
|
|||
|
|
"level": "技术骨干岗",
|
|||
|
|
"position": "视觉设计师"
|
|||
|
|
}]
|
|||
|
|
|
|||
|
|
# 生成新的positions JSON
|
|||
|
|
new_positions = json.dumps(positions_list, ensure_ascii=False, indent=8)
|
|||
|
|
# 调整缩进
|
|||
|
|
lines = new_positions.split('\n')
|
|||
|
|
adjusted_lines = []
|
|||
|
|
for line in lines:
|
|||
|
|
if line.strip():
|
|||
|
|
adjusted_lines.append(' ' + line) # 6个空格缩进
|
|||
|
|
new_positions = '\n'.join(adjusted_lines).strip()
|
|||
|
|
|
|||
|
|
# 替换positions数组
|
|||
|
|
content = content[:array_start] + new_positions + content[array_end+1:]
|
|||
|
|
|
|||
|
|
# 更新unit字段 - 找到unit字段
|
|||
|
|
unit_pos = content.find('"unit":', id_pos)
|
|||
|
|
if unit_pos != -1:
|
|||
|
|
# 找到unit值的开始和结束
|
|||
|
|
quote_start = content.find('"', unit_pos + 7)
|
|||
|
|
quote_end = content.find('"', quote_start + 1)
|
|||
|
|
|
|||
|
|
# 构建新的unit值(包含复合能力课和垂直能力课)
|
|||
|
|
if unit_vertical:
|
|||
|
|
new_unit = f"{unit_compound} / {unit_vertical}"
|
|||
|
|
else:
|
|||
|
|
new_unit = unit_compound if unit_compound else "视觉设计基础"
|
|||
|
|
|
|||
|
|
# 替换unit值
|
|||
|
|
content = content[:quote_start+1] + new_unit + content[quote_end:]
|
|||
|
|
print(f" ✓ 更新了{len(positions_list)}个岗位,单元:{new_unit}")
|
|||
|
|
else:
|
|||
|
|
print(f" ✗ 未找到unit字段")
|
|||
|
|
|
|||
|
|
# 写入文件
|
|||
|
|
print("\n正在写入更新后的内容...")
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
# 验证语法
|
|||
|
|
print("\n验证语法...")
|
|||
|
|
result = os.popen(f'node -c {mock_file} 2>&1').read()
|
|||
|
|
if result:
|
|||
|
|
print(f"❌ 语法错误:{result}")
|
|||
|
|
print("恢复备份...")
|
|||
|
|
with open(backup_file, 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
with open(mock_file, 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
print("已恢复备份")
|
|||
|
|
else:
|
|||
|
|
print("✓ 语法验证通过")
|
|||
|
|
print("✓ 成功更新所有项目的岗位和单元信息!")
|