option('check')) { $this->info('开始检查URS关系缓存完整性...'); $result = $logic->checkRelationCacheIntegrity(); if (isset($result['error'])) { $this->error('检查失败: ' . $result['error']); return 1; } $this->info('检查结果:'); $this->table(['项目', '数量'], [ ['总用户数', $result['total_users']], ['有缓存的用户数', $result['users_with_cache']], ['缺失缓存的用户数', $result['missing_users']], ['循环推荐关系数', $result['circular_relations']], ['孤立缓存数', $result['orphaned_caches']] ]); if ($result['missing_users'] > 0 || $result['orphaned_caches'] > 0) { $this->warn('发现问题,建议使用 --fix 参数修复'); return 1; } $this->info('缓存完整性检查通过'); return 0; } // 修复问题 if ($this->option('fix')) { $this->info('开始修复URS关系缓存问题...'); $result = $logic->fixRelationCacheIssues(); if (isset($result['error'])) { $this->error('修复失败: ' . $result['error']); return 1; } $this->info('修复结果:'); $this->table(['项目', '修复数量'], [ ['缺失用户缓存', $result['fixed']['missing_users']], ['孤立缓存清理', $result['fixed']['orphaned_caches']] ]); $this->info('问题修复完成'); return 0; } // 重建所有缓存 $batchSize = (int) $this->option('batch-size'); if (!$this->confirm('确定要重建所有URS用户关系缓存吗?这将清空现有缓存并重新生成。')) { $this->info('操作已取消'); return 0; } $this->info("开始重建URS关系缓存,批处理大小: {$batchSize}"); $progressBar = $this->output->createProgressBar(); $progressBar->start(); $result = $logic->rebuildAllRelationCache($batchSize); $progressBar->finish(); $this->newLine(); if (isset($result['error'])) { $this->error('重建失败: ' . $result['error']); return 1; } $this->info('重建完成:'); $this->table(['项目', '数量'], [ ['总用户数', $result['total']], ['成功数', $result['success']], ['失败数', $result['fail']] ]); if ($result['fail'] > 0) { $this->warn('部分用户缓存生成失败,请检查日志'); return 1; } $this->info('所有URS用户关系缓存重建完成'); return 0; } }