Explorar o código

refactor(Game): 移除日志收集命令中的冗余代码- 删除了 CollectUserLogsCommand 类中多个未使用的私有方法- 清理了冗余的代码结构,简化了命令逻辑- 保留了核心的日志收集功能,提高了代码的可读性和维护性

notfff hai 6 meses
pai
achega
6dd762af1e
Modificáronse 1 ficheiros con 1 adicións e 157 borrados
  1. 1 157
      app/Module/Game/Commands/CollectUserLogsCommand.php

+ 1 - 157
app/Module/Game/Commands/CollectUserLogsCommand.php

@@ -5,6 +5,7 @@ namespace App\Module\Game\Commands;
 use App\Module\Game\Logics\UserLogCollectorManager;
 use App\Module\Game\Services\GameConfigService;
 use UCore\Command\Command;
+use UCore\Exception\LogicException;
 
 /**
  * 用户日志收集命令
@@ -143,170 +144,13 @@ class CollectUserLogsCommand extends Command
         }
     }
 
-    /**
-     * 执行单个收集器并显示进度
-     *
-     * @param UserLogCollectorManager $manager
-     * @param string $collectorName
-     * @param bool $detail
-     * @param bool $showProgress
-     * @return array
-     */
-    private function executeCollectorWithProgress(UserLogCollectorManager $manager, string $collectorName, bool $detail, bool $showProgress): array
-    {
-        if ($detail) {
-            $this->line("📊 检查收集器状态...");
-            $this->showCollectorProgress($manager, $collectorName);
-        }
-
-        $startTime = microtime(true);
-        $result = $manager->collectByName($collectorName);
-        $endTime = microtime(true);
-
-        if ($detail) {
-            $this->line("⏱️  执行时间: " . round(($endTime - $startTime) * 1000, 2) . "ms");
-        }
-
-        return $result;
-    }
-
-    /**
-     * 执行所有收集器并显示进度
-     *
-     * @param UserLogCollectorManager $manager
-     * @param bool $detail
-     * @param bool $showProgress
-     * @return array
-     */
-    private function executeAllCollectorsWithProgress(UserLogCollectorManager $manager, bool $detail, bool $showProgress): array
-    {
-        $collectorsInfo = $manager->getCollectorsInfo();
-
-        if ($detail) {
-            $this->line("📋 收集器总数: " . count($collectorsInfo));
-            $this->line("");
-        }
 
-        $results = $manager->collectAll();
 
-        return $results;
-    }
 
-    /**
-     * 显示收集器详细信息
-     *
-     * @param UserLogCollectorManager $manager
-     * @param string $collectorName
-     * @return void
-     */
-    private function showCollectorDetails(UserLogCollectorManager $manager, string $collectorName): void
-    {
-        $collectorsInfo = $manager->getCollectorsInfo();
 
-        if (!isset($collectorsInfo[$collectorName])) {
-            $this->error("收集器 {$collectorName} 不存在");
-            return;
-        }
 
-        $info = $collectorsInfo[$collectorName];
 
-        $this->line("📝 收集器详情:");
-        $this->line("  名称: <comment>{$info['name']}</comment>");
-        $this->line("  类名: {$info['class']}");
-        $this->line("  源表: <info>{$info['source_table']}</info>");
-        $this->line("  类型: <info>{$info['source_type']}</info>");
-        $this->line("");
-    }
 
-    /**
-     * 显示收集器进度信息
-     *
-     * @param UserLogCollectorManager $manager
-     * @param string $collectorName
-     * @return void
-     */
-    private function showCollectorProgress(UserLogCollectorManager $manager, string $collectorName): void
-    {
-        $collectorsInfo = $manager->getCollectorsInfo();
-        $info = $collectorsInfo[$collectorName];
-
-        // 从user_logs表获取最后处理的记录
-        $lastProcessedId = $this->getLastProcessedIdFromUserLogs($info['source_table'], $info['source_type']);
-        $lastProcessedTimestamp = $this->getLastProcessedTimestampFromUserLogs($info['source_table'], $info['source_type']);
-
-        // 获取源表的最大ID
-        $maxId = $this->getTableMaxId($info['source_table']);
-
-        // 计算待处理记录数
-        $pendingCount = max(0, $maxId - $lastProcessedId);
-
-        $this->line("📈 处理进度:");
-        $this->line("  最后处理ID: <comment>{$lastProcessedId}</comment>");
-        $this->line("  最后处理时间: <comment>" . ($lastProcessedTimestamp > 0 ? date('Y-m-d H:i:s', $lastProcessedTimestamp) : '未开始') . "</comment>");
-        $this->line("  源表最大ID: <comment>{$maxId}</comment>");
-        $this->line("  待处理记录: <comment>{$pendingCount}</comment>");
-        $this->line("");
-    }
-
-    /**
-     * 获取表的最大ID
-     *
-     * @param string $tableName
-     * @return int
-     */
-    private function getTableMaxId(string $tableName): int
-    {
-        try {
-            // 根据表名使用对应的模型
-            switch ($tableName) {
-                case 'fund_logs':
-                    return \App\Module\Fund\Models\FundLogModel::max('id') ?: 0;
-                case 'item_transaction_logs':
-                    return \App\Module\GameItems\Models\ItemTransactionLog::max('id') ?: 0;
-                case 'farm_harvest_logs':
-                    return \App\Module\Farm\Models\FarmHarvestLog::max('id') ?: 0;
-                case 'farm_upgrade_logs':
-                    return \App\Module\Farm\Models\FarmUpgradeLog::max('id') ?: 0;
-                case 'point_logs':
-                    return \App\Module\Point\Models\PointLogModel::max('id') ?: 0;
-                default:
-                    // 回退到直接查询
-                    $result = \Illuminate\Support\Facades\DB::table($tableName)->max('id');
-                    return $result ? (int)$result : 0;
-            }
-        } catch (\Exception $e) {
-            return 0;
-        }
-    }
-
-    /**
-     * 从user_logs表获取最后处理的ID
-     *
-     * @param string $sourceTable
-     * @param string $sourceType
-     * @return int
-     */
-    private function getLastProcessedIdFromUserLogs(string $sourceTable, string $sourceType): int
-    {
-        try {
-            // 对于农场收集器,需要查询多个表
-            if ($sourceType === 'farm') {
-                $lastLog = \App\Module\Game\Models\UserLog::where('source_type', $sourceType)
-                    ->whereIn('source_table', ['farm_harvest_logs', 'farm_upgrade_logs'])
-                    ->orderBy('source_id', 'desc')
-                    ->first();
-            } else {
-                $lastLog = \App\Module\Game\Models\UserLog::where('source_table', $sourceTable)
-                    ->where('source_type', $sourceType)
-                    ->orderBy('source_id', 'desc')
-                    ->first();
-            }
-
-            return $lastLog ? $lastLog->source_id : 0;
-        } catch (\Exception $e) {
-            return 0;
-        }
-    }
 
     /**
      * 从user_logs表获取最后处理的时间戳