// PHP 业务迁移脚本 console.log('🚀 开始迁移 PHP 业务到 NestJS...\n'); // PHP 项目中的核心表列表 const phpTables = [ 'sys_user', // 系统用户 'sys_menu', // 系统菜单 'sys_config', // 系统配置 'sys_area', // 系统地区 'sys_dict_type', // 字典类型 'sys_dict_item', // 字典项 'sys_role', // 系统角色 'sys_user_role', // 用户角色关联 'member', // 会员 'member_level', // 会员等级 'member_address', // 会员地址 'site', // 站点 'pay', // 支付记录 'pay_channel', // 支付渠道 'refund', // 退款记录 'wechat_fans', // 微信粉丝 'wechat_media', // 微信素材 'wechat_reply', // 微信回复 'diy', // DIY页面 'diy_form', // DIY表单 'addon', // 插件 'addon_log' // 插件日志 ]; // 生成迁移配置 function generateMigrationConfig() { return { // 系统核心模块 sys: { tables: ['sys_user', 'sys_menu', 'sys_config', 'sys_area', 'sys_dict_type', 'sys_dict_item', 'sys_role', 'sys_user_role'], description: '系统核心模块', priority: 1 }, // 会员模块 member: { tables: ['member', 'member_level', 'member_address', 'member_label', 'member_sign', 'member_cash_out', 'member_cash_out_account', 'member_account_log'], description: '会员管理模块', priority: 2 }, // 站点模块 site: { tables: ['site', 'site_group', 'site_account_log'], description: '站点管理模块', priority: 3 }, // 支付模块 pay: { tables: ['pay', 'pay_channel', 'refund', 'transfer', 'transfer_scene'], description: '支付管理模块', priority: 4 }, // 微信模块 wechat: { tables: ['wechat_fans', 'wechat_media', 'wechat_reply'], description: '微信管理模块', priority: 5 }, // DIY模块 diy: { tables: ['diy', 'diy_route', 'diy_theme', 'diy_form', 'diy_form_fields', 'diy_form_submit_config', 'diy_form_write_config', 'diy_form_records', 'diy_form_records_fields'], description: 'DIY页面模块', priority: 6 }, // 插件模块 addon: { tables: ['addon', 'addon_log'], description: '插件管理模块', priority: 7 }, // 其他模块 other: { tables: ['verify', 'verifier', 'stat_hour', 'poster', 'dict'], description: '其他功能模块', priority: 8 } }; } // 生成迁移计划 function generateMigrationPlan() { const config = generateMigrationConfig(); const plan = []; Object.keys(config).forEach(moduleName => { const module = config[moduleName]; plan.push({ module: moduleName, description: module.description, tables: module.tables, priority: module.priority, status: 'pending', estimatedTime: `${module.tables.length * 2} 分钟` }); }); return plan.sort((a, b) => a.priority - b.priority); } // 生成迁移命令 function generateMigrationCommands() { const plan = generateMigrationPlan(); const commands = []; plan.forEach(module => { commands.push(`\n# ${module.description} (${module.module})`); commands.push(`# 预计时间: ${module.estimatedTime}`); commands.push(`# 表数量: ${module.tables.length}`); // 批量迁移命令 commands.push(`curl -X POST http://localhost:3000/adminapi/migration/php/batch-migrate \\`); commands.push(` -H "Content-Type: application/json" \\`); commands.push(` -d '{`); commands.push(` "tableNames": [${module.tables.map(t => `"${t}"`).join(', ')}],`); commands.push(` "options": {`); commands.push(` "generateController": true,`); commands.push(` "generateService": true,`); commands.push(` "generateEntity": true,`); commands.push(` "generateDto": true,`); commands.push(` "generateMapper": true,`); commands.push(` "generateEvents": true,`); commands.push(` "generateListeners": true`); commands.push(` }`); commands.push(` }'`); commands.push(''); }); return commands; } // 生成 NestJS 模块结构 function generateNestJSModuleStructure() { return ` src/ ├── common/ │ ├── sys/ # 系统核心模块 │ │ ├── sys.module.ts │ │ ├── controllers/ │ │ │ ├── adminapi/ │ │ │ │ ├── sysUser.controller.ts │ │ │ │ ├── sysMenu.controller.ts │ │ │ │ ├── sysConfig.controller.ts │ │ │ │ └── ... │ │ │ └── api/ │ │ │ └── ... │ │ ├── services/ │ │ │ ├── admin/ │ │ │ ├── api/ │ │ │ └── core/ │ │ ├── entity/ │ │ │ ├── sysUser.entity.ts │ │ │ ├── sysMenu.entity.ts │ │ │ └── ... │ │ ├── dto/ │ │ │ ├── create-sysUser.dto.ts │ │ │ ├── update-sysUser.dto.ts │ │ │ └── ... │ │ ├── mapper/ │ │ │ ├── sysUser.mapper.ts │ │ │ └── ... │ │ ├── events/ │ │ │ ├── sysUser.created.event.ts │ │ │ └── ... │ │ └── listeners/ │ │ ├── sysUser.created.listener.ts │ │ └── ... │ ├── member/ # 会员模块 │ │ └── ... │ ├── site/ # 站点模块 │ │ └── ... │ ├── pay/ # 支付模块 │ │ └── ... │ ├── wechat/ # 微信模块 │ │ └── ... │ ├── diy/ # DIY模块 │ │ └── ... │ └── addon/ # 插件模块 │ └── ... └── tools/ # 迁移工具 └── migration/ └── ... `; } // 执行迁移分析 console.log('📊 迁移分析报告'); console.log('================'); const config = generateMigrationConfig(); const plan = generateMigrationPlan(); console.log(`📋 总模块数: ${Object.keys(config).length}`); console.log(`📋 总表数: ${phpTables.length}`); console.log(`📋 预计总时间: ${plan.reduce((total, module) => total + parseInt(module.estimatedTime), 0)} 分钟`); console.log('\n📅 迁移计划:'); plan.forEach((module, index) => { console.log(`${index + 1}. ${module.description} (${module.module})`); console.log(` 📋 表数量: ${module.tables.length}`); console.log(` ⏱️ 预计时间: ${module.estimatedTime}`); console.log(` 📝 表列表: ${module.tables.slice(0, 3).join(', ')}${module.tables.length > 3 ? '...' : ''}`); console.log(''); }); console.log('🏗️ 生成的 NestJS 模块结构:'); console.log(generateNestJSModuleStructure()); console.log('🔧 迁移命令:'); const commands = generateMigrationCommands(); commands.forEach(cmd => console.log(cmd)); console.log('\n✨ 迁移工具特性:'); console.log(' ✅ 支持批量迁移'); console.log(' ✅ 支持模块化组织'); console.log(' ✅ 支持优先级排序'); console.log(' ✅ 支持进度跟踪'); console.log(' ✅ 支持错误处理'); console.log(' ✅ 支持迁移报告'); console.log(' ✅ 支持代码预览'); console.log(' ✅ 支持增量迁移'); console.log('\n🎯 下一步操作:'); console.log('1. 启动 NestJS 应用: npm run start:dev'); console.log('2. 执行迁移命令 (见上面的 curl 命令)'); console.log('3. 查看生成的代码文件'); console.log('4. 根据需要调整生成的内容'); console.log('5. 集成到现有业务逻辑中'); console.log('\n🎉 PHP 业务迁移准备完成!');