import json import re # 读取食品项目案例数据 with open('网页未导入数据/食品产业/食品项目案例.json', 'r', encoding='utf-8') as f: food_cases = json.load(f) print(f"总共找到 {len(food_cases)} 个食品项目案例") # 分析附件数据结构 def analyze_attachments(): projects_with_attachments = [] attachment_types = set() for case in food_cases: case_name = case.get('案例名称', '') attachments_str = case.get('附件', '') if attachments_str and attachments_str.strip(): # 解析附件字符串 attachments = [] for attachment in attachments_str.split(','): attachment = attachment.strip() if attachment: # 提取文件扩展名 ext_match = re.search(r'\.([a-zA-Z0-9]+)$', attachment) file_type = ext_match.group(1).lower() if ext_match else 'unknown' attachment_types.add(file_type) attachments.append({ "id": f"attach_{len(attachments) + 1}", "name": attachment, "type": file_type, "size": "2.5MB", # 模拟文件大小 "url": f"https://example.com/files/{attachment}" }) projects_with_attachments.append({ "caseName": case_name, "unitName": case.get('对应单元名称(复合能力课)', ''), "attachments": attachments, "originalData": case }) return projects_with_attachments, attachment_types projects_with_attachments, attachment_types = analyze_attachments() print(f"\n找到 {len(projects_with_attachments)} 个有附件的项目") print(f"附件类型: {sorted(attachment_types)}") print("\n有附件的项目列表:") for i, project in enumerate(projects_with_attachments, 1): print(f"{i}. {project['caseName']} ({project['unitName']})") for att in project['attachments']: print(f" - {att['name']} ({att['type']})") # 为我的项目库生成附件数据 def generate_my_projects_with_attachments(): # 读取当前的我的项目数据 with open('my_projects_data_food_only.js', 'r', encoding='utf-8') as f: content = f.read() # 提取项目名称 my_projects = [] # 为项目分配附件 project_attachments_mapping = {} # 根据关键词匹配为项目分配合适的附件 for project in projects_with_attachments: case_name = project['caseName'] attachments = project['attachments'] # 餐饮相关 if any(keyword in case_name for keyword in ['餐厅', '餐饮', '轻食']): if any(keyword in case_name for keyword in ['管理', '运营']): project_attachments_mapping['轻食店外卖包装与用户体验优化'] = attachments project_attachments_mapping['社区咖啡馆日常运营成本控制分析'] = attachments # 酿造工艺相关 if any(keyword in case_name for keyword in ['酿造', '工艺', '红曲酒']): project_attachments_mapping['传统中式菜肴标准化工艺流程制定'] = attachments # 包装设计相关 if any(keyword in case_name for keyword in ['包装', '设计']): project_attachments_mapping['地方特色食品抖音短视频营销方案'] = attachments # 仓储管理相关 if any(keyword in case_name for keyword in ['仓储', '管理', '保鲜']): project_attachments_mapping['临期食品仓储管理系统数据库设计'] = attachments # 供应链相关 if any(keyword in case_name for keyword in ['供应链', '优化']): project_attachments_mapping['节庆食品季节性供需波动与库存管理'] = attachments return project_attachments_mapping # 生成附件映射 attachment_mapping = generate_my_projects_with_attachments() print(f"\n为我的项目库分配了 {len(attachment_mapping)} 个项目的附件:") for project_name, attachments in attachment_mapping.items(): print(f"- {project_name}: {len(attachments)} 个附件") for att in attachments: print(f" * {att['name']}") # 生成JavaScript代码 js_content = '''// 项目附件数据映射 const projectAttachmentsData = { ''' for project_name, attachments in attachment_mapping.items(): js_content += f' "{project_name}": [\n' for att in attachments: js_content += f' {{\n' js_content += f' "id": "{att["id"]}",\n' js_content += f' "name": "{att["name"]}",\n' js_content += f' "type": "{att["type"]}",\n' js_content += f' "size": "{att["size"]}",\n' js_content += f' "url": "{att["url"]}"\n' js_content += f' }},\n' js_content = js_content.rstrip(',\n') + '\n' js_content += f' ],\n' js_content = js_content.rstrip(',\n') + '\n' js_content += '''}; export default projectAttachmentsData; ''' print(f"\n生成的JavaScript代码:") print(js_content) # 保存到文件 with open('project_attachments_data.js', 'w', encoding='utf-8') as f: f.write(js_content) print(f"\n已保存到 project_attachments_data.js") print(f"\n统计信息:") print(f" 有附件的案例总数: {len(projects_with_attachments)}") print(f" 分配附件的我的项目数: {len(attachment_mapping)}") print(f" 支持的文件类型: {sorted(attachment_types)}")