warn('⚠️ 此命令已废弃,建议使用 cleanup:scan-models 命令'); $this->info('开始扫描Model类(通过兼容模式)...'); $this->newLine(); $forceRefresh = $this->option('force'); $showDetails = $this->option('show-details'); if ($forceRefresh) { $this->warn('强制刷新模式:将重新生成所有Model的配置'); } try { // 执行扫描 $result = CleanupService::scanTables($forceRefresh); // 显示扫描结果 $this->displayScanResults($result, $showDetails); $this->newLine(); $this->info('✅ 数据表扫描完成!'); return Command::SUCCESS; } catch (\Exception $e) { $this->error('❌ 扫描失败: ' . $e->getMessage()); $this->error('详细错误: ' . $e->getTraceAsString()); return Command::FAILURE; } } /** * 显示扫描结果 * * @param array $result 扫描结果 * @param bool $showDetails 是否显示详细信息 */ private function displayScanResults(array $result, bool $showDetails): void { // 显示统计信息 $this->info("📊 扫描统计:"); $this->table( ['项目', '数量'], [ ['总表数', $result['total_tables']], ['已扫描', $result['scanned_tables']], ['新增配置', $result['new_tables']], ['更新配置', $result['updated_tables']], ['扫描耗时', $result['scan_time'] . ' 秒'], ] ); if (!$showDetails) { return; } $this->newLine(); $this->info("📋 表详细信息:"); // 按数据分类分组显示 $tablesByCategory = []; foreach ($result['tables'] as $table) { $category = $table['data_category_name']; if (!isset($tablesByCategory[$category])) { $tablesByCategory[$category] = []; } $tablesByCategory[$category][] = $table; } foreach ($tablesByCategory as $category => $tables) { $this->newLine(); $tableCount = count($tables); $this->line("📁 {$category} ({$tableCount} 个表)"); $tableData = []; foreach ($tables as $table) { $status = []; if ($table['is_new']) { $status[] = '新增'; } if ($table['is_updated']) { $status[] = '更新'; } $tableData[] = [ $table['table_name'], $table['module_name'], number_format($table['record_count']), $table['table_size_mb'] . ' MB', $table['has_time_field'] ? '✅' : '❌', $table['has_user_field'] ? '✅' : '❌', implode(' ', $status) ?: '-', ]; } $this->table( ['表名', '模块', '记录数', '大小', '时间字段', '用户字段', '状态'], $tableData ); } // 显示字段分析 $this->newLine(); $this->info("🔍 字段分析:"); $timeFieldTables = array_filter($result['tables'], fn($t) => $t['has_time_field']); $userFieldTables = array_filter($result['tables'], fn($t) => $t['has_user_field']); $this->table( ['分析项', '数量', '百分比'], [ ['包含时间字段的表', count($timeFieldTables), round(count($timeFieldTables) / $result['total_tables'] * 100, 1) . '%'], ['包含用户字段的表', count($userFieldTables), round(count($userFieldTables) / $result['total_tables'] * 100, 1) . '%'], ] ); // 显示推荐的清理计划 $this->newLine(); $this->info("💡 推荐的清理计划:"); $recommendations = CleanupService::getRecommendedPlans(); if (empty($recommendations)) { $this->line('暂无推荐的清理计划'); } else { foreach ($recommendations as $recommendation) { $this->line("• {$recommendation['title']} - {$recommendation['description']} (预计 {$recommendation['estimated_tables']} 个表)"); } } } }