CollectUserLogsCommand.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. namespace App\Module\Game\Commands;
  3. use App\Module\Game\Logics\UserLogCollectorManager;
  4. use App\Module\Game\Services\GameConfigService;
  5. use UCore\Command\Command;
  6. /**
  7. * 用户日志收集命令
  8. *
  9. * 定时执行的计划任务,每2秒收集一次用户日志
  10. */
  11. class CollectUserLogsCommand extends Command
  12. {
  13. /**
  14. * 命令名称和参数
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'game:collect-user-logs {--info : 显示收集器信息} {--statistics : 显示收集统计信息} {--detail : 显示详细的处理过程} {--limit=1000 : 单次处理最大记录数} {--force : 强制执行,忽略自动收集配置}';
  19. /**
  20. * 命令描述
  21. *
  22. * @var string
  23. */
  24. protected $description = '收集用户日志,将各模块的原始日志转换为用户友好的日志消息
  25. 选项说明:
  26. --info 显示收集器信息
  27. --statistics 显示收集统计信息
  28. --detail 显示详细的处理过程
  29. --limit 单次处理最大记录数(默认1000)
  30. --force 强制执行,忽略自动收集配置
  31. 进度追踪机制:
  32. - 基于原始日志ID进行进度追踪,确保不遗漏任何记录
  33. - 通过user_logs表中的source_id字段自动维护进度
  34. - 每个收集器独立追踪进度,无需手动重置
  35. - 系统会自动从上次处理的最大ID继续收集';
  36. /**
  37. * 执行命令
  38. */
  39. public function handleRun()
  40. {
  41. // 检查是否允许自动收集日志(除非强制执行)
  42. if (!$this->option('force') && !$this->isAutoCollectEnabled()) {
  43. $this->warn("⚠️ 自动收集日志功能已禁用");
  44. $this->line("💡 如需强制执行,请使用 --force 选项");
  45. return 0;
  46. }
  47. // 显示统计信息
  48. if ($this->option('statistics')) {
  49. $manager = new UserLogCollectorManager();
  50. $collectorsInfo = $manager->getCollectorsInfo();
  51. $this->info("📊 收集器统计信息:");
  52. $this->line("");
  53. $this->line("收集器数量: " . count($collectorsInfo));
  54. // 动态显示所有收集器
  55. foreach ($collectorsInfo as $name => $info) {
  56. $icon = $this->getCollectorIcon($info['source_type']);
  57. $description = $this->getCollectorNameDescription($name);
  58. $this->line("- {$name}: {$icon} {$description}");
  59. }
  60. $this->line("");
  61. // 显示用户日志表统计
  62. try {
  63. $totalUserLogs = \App\Module\Game\Models\UserLog::count();
  64. $this->line("📋 用户日志表统计:");
  65. $this->line(" 📝 总日志数: {$totalUserLogs}");
  66. if ($totalUserLogs > 0) {
  67. $latestLog = \App\Module\Game\Models\UserLog::orderBy('created_at', 'desc')->first();
  68. $oldestLog = \App\Module\Game\Models\UserLog::orderBy('created_at', 'asc')->first();
  69. $this->line(" 🕐 最新日志时间: " . $latestLog->created_at);
  70. $this->line(" 🕐 最旧日志时间: " . $oldestLog->created_at);
  71. // 按类型统计 - 动态获取所有收集器类型
  72. $this->line(" 📊 按类型统计:");
  73. foreach ($collectorsInfo as $name => $info) {
  74. $sourceType = $info['source_type'];
  75. $count = \App\Module\Game\Models\UserLog::where('source_type', $sourceType)->count();
  76. $icon = $this->getCollectorIcon($sourceType);
  77. $description = $this->getCollectorDescription($sourceType);
  78. $this->line(" {$icon} {$description}: {$count}");
  79. }
  80. }
  81. } catch (\Exception $e) {
  82. $this->line(" ⚠️ 无法获取用户日志统计: " . $e->getMessage());
  83. }
  84. $this->line("");
  85. return 0;
  86. }
  87. $manager = new UserLogCollectorManager();
  88. // 显示收集器信息
  89. if ($this->option('info')) {
  90. $this->showCollectorsInfo($manager);
  91. return 0;
  92. }
  93. // 执行日志收集
  94. return $this->executeCollection($manager);
  95. }
  96. /**
  97. * 执行日志收集
  98. *
  99. * @param UserLogCollectorManager $manager
  100. * @return int
  101. */
  102. private function executeCollection(UserLogCollectorManager $manager): int
  103. {
  104. $detail = $this->option('detail');
  105. $limit = (int)$this->option('limit');
  106. $force = $this->option('force');
  107. try {
  108. if ($force) {
  109. $this->info("🚀 强制执行用户日志收集...");
  110. $this->line("⚡ 忽略自动收集配置,强制执行收集任务");
  111. } else {
  112. $this->info("🚀 开始按时间线收集用户日志...");
  113. }
  114. if ($detail) {
  115. $this->showTimelineProgress();
  116. }
  117. $result = $this->executeTimelineCollection($manager, $limit, $detail);
  118. $this->displayTimelineResult($result);
  119. return 0;
  120. } catch (\Exception $e) {
  121. $this->error("❌ 日志收集失败: {$e->getMessage()}");
  122. return 1;
  123. }
  124. }
  125. /**
  126. * 执行单个收集器并显示进度
  127. *
  128. * @param UserLogCollectorManager $manager
  129. * @param string $collectorName
  130. * @param bool $detail
  131. * @param bool $showProgress
  132. * @return array
  133. */
  134. private function executeCollectorWithProgress(UserLogCollectorManager $manager, string $collectorName, bool $detail, bool $showProgress): array
  135. {
  136. if ($detail) {
  137. $this->line("📊 检查收集器状态...");
  138. $this->showCollectorProgress($manager, $collectorName);
  139. }
  140. $startTime = microtime(true);
  141. $result = $manager->collectByName($collectorName);
  142. $endTime = microtime(true);
  143. if ($detail) {
  144. $this->line("⏱️ 执行时间: " . round(($endTime - $startTime) * 1000, 2) . "ms");
  145. }
  146. return $result;
  147. }
  148. /**
  149. * 执行所有收集器并显示进度
  150. *
  151. * @param UserLogCollectorManager $manager
  152. * @param bool $detail
  153. * @param bool $showProgress
  154. * @return array
  155. */
  156. private function executeAllCollectorsWithProgress(UserLogCollectorManager $manager, bool $detail, bool $showProgress): array
  157. {
  158. $collectorsInfo = $manager->getCollectorsInfo();
  159. if ($detail) {
  160. $this->line("📋 收集器总数: " . count($collectorsInfo));
  161. $this->line("");
  162. }
  163. $results = $manager->collectAll();
  164. return $results;
  165. }
  166. /**
  167. * 显示收集器详细信息
  168. *
  169. * @param UserLogCollectorManager $manager
  170. * @param string $collectorName
  171. * @return void
  172. */
  173. private function showCollectorDetails(UserLogCollectorManager $manager, string $collectorName): void
  174. {
  175. $collectorsInfo = $manager->getCollectorsInfo();
  176. if (!isset($collectorsInfo[$collectorName])) {
  177. $this->error("收集器 {$collectorName} 不存在");
  178. return;
  179. }
  180. $info = $collectorsInfo[$collectorName];
  181. $this->line("📝 收集器详情:");
  182. $this->line(" 名称: <comment>{$info['name']}</comment>");
  183. $this->line(" 类名: {$info['class']}");
  184. $this->line(" 源表: <info>{$info['source_table']}</info>");
  185. $this->line(" 类型: <info>{$info['source_type']}</info>");
  186. $this->line("");
  187. }
  188. /**
  189. * 显示收集器进度信息
  190. *
  191. * @param UserLogCollectorManager $manager
  192. * @param string $collectorName
  193. * @return void
  194. */
  195. private function showCollectorProgress(UserLogCollectorManager $manager, string $collectorName): void
  196. {
  197. $collectorsInfo = $manager->getCollectorsInfo();
  198. $info = $collectorsInfo[$collectorName];
  199. // 从user_logs表获取最后处理的记录ID
  200. $lastProcessedId = $this->getLastProcessedIdFromUserLogs($info['source_table'], $info['source_type']);
  201. // 使用收集器获取源表的最大ID
  202. $maxId = $manager->getCollectorSourceTableMaxId($collectorName);
  203. // 计算待处理记录数
  204. $pendingCount = max(0, $maxId - $lastProcessedId);
  205. $this->line("📈 处理进度:");
  206. $this->line(" 最后处理ID: <comment>{$lastProcessedId}</comment>");
  207. $this->line(" 最后处理时间: <comment>" . ($lastProcessedTimestamp > 0 ? date('Y-m-d H:i:s', $lastProcessedTimestamp) : '未开始') . "</comment>");
  208. $this->line(" 源表最大ID: <comment>{$maxId}</comment>");
  209. $this->line(" 待处理记录: <comment>{$pendingCount}</comment>");
  210. $this->line("");
  211. }
  212. /**
  213. * 从user_logs表获取最后处理的ID
  214. *
  215. * @param string $sourceTable
  216. * @param string $sourceType
  217. * @return int
  218. */
  219. private function getLastProcessedIdFromUserLogs(string $sourceTable, string $sourceType): int
  220. {
  221. try {
  222. // 对于农场收集器,需要查询多个表
  223. if ($sourceType === 'farm') {
  224. $lastLog = \App\Module\Game\Models\UserLog::where('source_type', $sourceType)
  225. ->whereIn('source_table', ['farm_harvest_logs', 'farm_upgrade_logs'])
  226. ->orderBy('source_id', 'desc')
  227. ->first();
  228. } elseif ($sourceTable === 'fund_logs') {
  229. // 对于fund_logs表,使用动态source_type,只按source_table查询
  230. // 这与BaseLogCollector的getLastProcessedId方法保持一致
  231. $maxId = \App\Module\Game\Models\UserLog::where('source_table', $sourceTable)
  232. ->max('source_id');
  233. return $maxId ?: 0;
  234. } else {
  235. $lastLog = \App\Module\Game\Models\UserLog::where('source_table', $sourceTable)
  236. ->where('source_type', $sourceType)
  237. ->orderBy('source_id', 'desc')
  238. ->first();
  239. }
  240. return $lastLog ? $lastLog->source_id : 0;
  241. } catch (\Exception $e) {
  242. return 0;
  243. }
  244. }
  245. // 注意:getLastProcessedTimestampFromUserLogs方法已移除
  246. // 当前使用基于ID的进度追踪,不再需要时间戳追踪
  247. /**
  248. * 显示收集器信息
  249. *
  250. * @param UserLogCollectorManager $manager
  251. * @return void
  252. */
  253. private function showCollectorsInfo(UserLogCollectorManager $manager): void
  254. {
  255. $this->info("📋 注册的收集器信息:");
  256. $this->line("");
  257. $collectorsInfo = $manager->getCollectorsInfo();
  258. foreach ($collectorsInfo as $info) {
  259. $this->line("收集器: <comment>{$info['name']}</comment>");
  260. $this->line(" 类名: {$info['class']}");
  261. $this->line(" 源表: <info>{$info['source_table']}</info>");
  262. $this->line(" 类型: <info>{$info['source_type']}</info>");
  263. $this->line("");
  264. }
  265. }
  266. /**
  267. * 显示统计信息
  268. *
  269. * @param UserLogCollectorManager $manager
  270. * @return void
  271. */
  272. private function showStats(UserLogCollectorManager $manager): void
  273. {
  274. $collectorsInfo = $manager->getCollectorsInfo();
  275. $this->line("");
  276. $this->line("收集器数量: " . count($collectorsInfo));
  277. // 动态显示所有收集器
  278. foreach ($collectorsInfo as $name => $info) {
  279. $icon = $this->getCollectorIcon($info['source_type']);
  280. $description = $this->getCollectorNameDescription($name);
  281. $this->line("- {$name}: {$icon} {$description}");
  282. }
  283. $this->line("");
  284. }
  285. /**
  286. * 获取收集器图标
  287. *
  288. * @param string $sourceType
  289. * @return string
  290. */
  291. private function getCollectorIcon(string $sourceType): string
  292. {
  293. $icons = [
  294. 'fund' => '💰',
  295. 'item' => '📦',
  296. 'farm' => '🌾',
  297. 'point' => '⭐',
  298. 'pet' => '🐾',
  299. 'system' => '⚙️',
  300. ];
  301. return $icons[$sourceType] ?? '📄';
  302. }
  303. /**
  304. * 获取收集器描述
  305. *
  306. * @param string $sourceType
  307. * @return string
  308. */
  309. private function getCollectorDescription(string $sourceType): string
  310. {
  311. $descriptions = [
  312. 'fund' => '资金日志收集器',
  313. 'item' => '物品日志收集器',
  314. 'farm' => '农场日志收集器',
  315. 'point' => '积分日志收集器',
  316. 'pet' => '宠物日志收集器',
  317. 'system' => '系统日志收集器',
  318. ];
  319. return $descriptions[$sourceType] ?? '未知类型收集器';
  320. }
  321. /**
  322. * 获取收集器名称描述(基于收集器名称而非源类型)
  323. *
  324. * @param string $collectorName
  325. * @return string
  326. */
  327. private function getCollectorNameDescription(string $collectorName): string
  328. {
  329. $descriptions = [
  330. 'fund' => '资金日志收集器',
  331. 'item' => '物品日志收集器',
  332. 'farm_harvest' => '农场收获日志收集器',
  333. 'farm_upgrade' => '农场升级日志收集器',
  334. 'point' => '积分日志收集器',
  335. 'pet' => '宠物日志收集器',
  336. 'system' => '系统日志收集器',
  337. ];
  338. return $descriptions[$collectorName] ?? '未知收集器';
  339. }
  340. /**
  341. * 获取表的记录总数
  342. *
  343. * @param string $tableName
  344. * @return int
  345. */
  346. private function getTableRecordCount(string $tableName): int
  347. {
  348. try {
  349. // 根据表名使用对应的模型
  350. switch ($tableName) {
  351. case 'fund_logs':
  352. return \App\Module\Fund\Models\FundLogModel::count();
  353. case 'item_transaction_logs':
  354. return \App\Module\GameItems\Models\ItemTransactionLog::count();
  355. case 'farm_harvest_logs':
  356. return \App\Module\Farm\Models\FarmHarvestLog::count();
  357. case 'farm_upgrade_logs':
  358. return \App\Module\Farm\Models\FarmUpgradeLog::count();
  359. case 'point_logs':
  360. return \App\Module\Point\Models\PointLogModel::count();
  361. default:
  362. // 回退到直接查询
  363. return \Illuminate\Support\Facades\DB::table($tableName)->count();
  364. }
  365. } catch (\Exception $e) {
  366. return 0;
  367. }
  368. }
  369. /**
  370. * 显示进度条
  371. *
  372. * @param float $percent
  373. * @return void
  374. */
  375. private function displayProgressBar(float $percent): void
  376. {
  377. $barLength = 20;
  378. $filledLength = (int)round(($percent / 100) * $barLength);
  379. $emptyLength = $barLength - $filledLength;
  380. $bar = str_repeat('█', $filledLength) . str_repeat('░', $emptyLength);
  381. $this->line(" 📊 [{$bar}] {$percent}%");
  382. }
  383. /**
  384. * 执行时间线收集
  385. * 改为让每个收集器独立处理,避免全局时间戳的复杂性
  386. *
  387. * @param UserLogCollectorManager $manager
  388. * @param int $limit
  389. * @param bool $detail
  390. * @return array
  391. */
  392. private function executeTimelineCollection(UserLogCollectorManager $manager, int $limit, bool $detail): array
  393. {
  394. $startTime = microtime(true);
  395. if ($detail) {
  396. $this->line("📊 执行各收集器的日志收集...");
  397. }
  398. // 直接执行所有收集器,传递限制参数
  399. $results = $manager->collectAll($limit);
  400. if ($results['total_processed'] == 0) {
  401. return [
  402. 'processed_count' => 0,
  403. 'execution_time' => round((microtime(true) - $startTime) * 1000, 2),
  404. 'status' => 'success',
  405. 'message' => '没有新记录需要处理',
  406. 'timestamp' => now()->toDateTimeString()
  407. ];
  408. }
  409. if ($detail) {
  410. $this->line("📝 开始处理各收集器...");
  411. foreach ($results['collectors'] as $collectorName => $result) {
  412. $this->line(" {$collectorName}: 处理了 {$result['processed_count']} 条记录");
  413. }
  414. }
  415. $endTime = microtime(true);
  416. return [
  417. 'processed_count' => $results['total_processed'],
  418. 'execution_time' => round(($endTime - $startTime) * 1000, 2),
  419. 'status' => 'success',
  420. 'timestamp' => now()->toDateTimeString(),
  421. 'details' => $results['collectors']
  422. ];
  423. }
  424. // 注意:getAllRecordsByTimeline方法已移除
  425. // 当前使用基于ID的进度追踪,每个收集器独立处理,不再需要全局时间线排序
  426. /**
  427. * 显示收集器进度信息
  428. * 基于ID的进度追踪,显示各收集器的处理状态
  429. *
  430. * @return void
  431. */
  432. private function showTimelineProgress(): void
  433. {
  434. $this->line("📈 收集器进度状态:");
  435. try {
  436. $manager = new \App\Module\Game\Logics\UserLogCollectorManager();
  437. $collectorsInfo = $manager->getCollectorsInfo();
  438. foreach ($collectorsInfo as $name => $info) {
  439. $lastProcessedId = $this->getLastProcessedIdFromUserLogs($info['source_table'], $info['source_type']);
  440. $maxId = $manager->getCollectorSourceTableMaxId($name);
  441. $pendingCount = max(0, $maxId - $lastProcessedId);
  442. $this->line(" 🔧 {$name}: 最后处理ID <comment>{$lastProcessedId}</comment>, 待处理 <info>{$pendingCount}</info> 条");
  443. }
  444. } catch (\Exception $e) {
  445. $this->line(" ⚠️ 无法获取进度信息: " . $e->getMessage());
  446. }
  447. $this->line("");
  448. }
  449. /**
  450. * 显示时间线收集结果
  451. *
  452. * @param array $result
  453. * @return void
  454. */
  455. private function displayTimelineResult(array $result): void
  456. {
  457. $this->line("");
  458. if ($result['status'] === 'success') {
  459. $this->info("✅ 时间线收集完成!");
  460. $this->line("📊 <comment>处理统计</comment>:");
  461. $this->line(" 📝 处理记录数: <info>{$result['processed_count']}</info>");
  462. $this->line(" ⏱️ 执行时间: <info>{$result['execution_time']}ms</info>");
  463. $this->line(" 🕐 完成时间: <info>{$result['timestamp']}</info>");
  464. if (isset($result['last_timestamp'])) {
  465. $this->line(" 🎯 最新的处理时间: <info>" . date('Y-m-d H:i:s', $result['last_timestamp']) . "</info>");
  466. }
  467. if ($result['processed_count'] > 0) {
  468. $avgTime = round($result['execution_time'] / $result['processed_count'], 2);
  469. $this->line(" 📈 平均处理时间: <info>{$avgTime}ms/条</info>");
  470. }
  471. if (isset($result['message'])) {
  472. $this->line(" 💡 <comment>{$result['message']}</comment>");
  473. }
  474. } else {
  475. $this->error("❌ 时间线收集失败!");
  476. if (isset($result['error'])) {
  477. $this->line("🚨 <comment>错误信息</comment>:");
  478. $this->line(" {$result['error']}");
  479. }
  480. }
  481. $this->line("");
  482. }
  483. // 注意:以下时间戳相关方法已移除,因为当前使用基于ID的进度追踪:
  484. // - getGlobalLastProcessedTimestamp(): 全局时间戳追踪已废弃
  485. // - updateGlobalLastProcessedTimestamp(): 手动更新时间戳已废弃
  486. //
  487. // 当前进度追踪机制:
  488. // 1. 每个收集器通过getLastProcessedId()获取最后处理的记录ID
  489. // 2. 进度通过user_logs表中的source_id字段自动维护
  490. // 3. 无需手动重置或更新进度
  491. /**
  492. * 显示用户日志表统计
  493. *
  494. * @return void
  495. */
  496. private function showUserLogStats(): void
  497. {
  498. try {
  499. // 使用模型查询,避免表名前缀问题
  500. $totalUserLogs = \App\Module\Game\Models\UserLog::count();
  501. $todayUserLogs = \App\Module\Game\Models\UserLog::whereDate('created_at', now()->toDateString())->count();
  502. $this->line("📋 <comment>用户日志表统计</comment>:");
  503. $this->line(" 📝 总日志数: <info>{$totalUserLogs}</info>");
  504. $this->line(" 📅 今日新增: <info>{$todayUserLogs}</info>");
  505. // 按来源类型统计
  506. $sourceStats = \App\Module\Game\Models\UserLog::select('source_type', \Illuminate\Support\Facades\DB::raw('count(*) as count'))
  507. ->groupBy('source_type')
  508. ->get();
  509. if ($sourceStats->isNotEmpty()) {
  510. $this->line(" 📊 按来源类型统计:");
  511. foreach ($sourceStats as $stat) {
  512. $this->line(" {$stat->source_type}: <info>{$stat->count}</info>");
  513. }
  514. }
  515. } catch (\Exception $e) {
  516. $this->line(" ⚠️ 无法获取用户日志统计信息: " . $e->getMessage());
  517. }
  518. }
  519. /**
  520. * 显示单个收集器结果
  521. *
  522. * @param array $result
  523. * @return void
  524. */
  525. private function displaySingleResult(array $result): void
  526. {
  527. $this->line("");
  528. if ($result['status'] === 'success') {
  529. $this->info("✅ 收集完成!");
  530. $this->line("📊 <comment>处理统计</comment>:");
  531. $this->line(" 📝 处理记录数: <info>{$result['processed_count']}</info>");
  532. $this->line(" ⏱️ 执行时间: <info>{$result['execution_time']}ms</info>");
  533. $this->line(" 🕐 完成时间: <info>{$result['timestamp']}</info>");
  534. if ($result['processed_count'] > 0) {
  535. $avgTime = round($result['execution_time'] / $result['processed_count'], 2);
  536. $this->line(" 📈 平均处理时间: <info>{$avgTime}ms/条</info>");
  537. }
  538. } else {
  539. $this->error("❌ 收集失败!");
  540. $this->line("🚨 <comment>错误信息</comment>:");
  541. $this->line(" {$result['error']}");
  542. }
  543. $this->line("");
  544. }
  545. /**
  546. * 显示所有收集器结果
  547. *
  548. * @param array $results
  549. * @return void
  550. */
  551. private function displayAllResults(array $results): void
  552. {
  553. $this->line("");
  554. $this->info("🎉 所有收集器执行完成!");
  555. $this->line("");
  556. // 显示总体统计
  557. $this->line("📊 <comment>总体统计</comment>:");
  558. $this->line(" 📝 总处理记录数: <info>{$results['total_processed']}</info>");
  559. $this->line(" ⏱️ 总执行时间: <info>{$results['total_execution_time']}ms</info>");
  560. $this->line(" 🕐 完成时间: <info>{$results['timestamp']}</info>");
  561. if ($results['total_processed'] > 0) {
  562. $avgTime = round($results['total_execution_time'] / $results['total_processed'], 2);
  563. $this->line(" 📈 平均处理时间: <info>{$avgTime}ms/条</info>");
  564. }
  565. $this->line("");
  566. // 显示各收集器详情
  567. $this->line("📋 <comment>各收集器详情</comment>:");
  568. $successCount = 0;
  569. $failureCount = 0;
  570. foreach ($results['collectors'] as $name => $result) {
  571. if ($result['status'] === 'success') {
  572. $status = '<info>✅ 成功</info>';
  573. $successCount++;
  574. } else {
  575. $status = '<error>❌ 失败</error>';
  576. $failureCount++;
  577. }
  578. $this->line(" 🔧 <comment>{$name}</comment>: {$status}");
  579. $this->line(" 📝 处理记录: <info>{$result['processed_count']}</info> 条");
  580. $this->line(" ⏱️ 执行时间: <info>{$result['execution_time']}</info> ms");
  581. if ($result['status'] === 'error') {
  582. $this->line(" 🚨 错误信息: <error>{$result['error']}</error>");
  583. } elseif ($result['processed_count'] > 0) {
  584. $avgTime = round($result['execution_time'] / $result['processed_count'], 2);
  585. $this->line(" 📈 平均时间: <info>{$avgTime}</info> ms/条");
  586. }
  587. $this->line("");
  588. }
  589. // 显示执行摘要
  590. $totalCollectors = $successCount + $failureCount;
  591. $this->line("📈 <comment>执行摘要</comment>:");
  592. $this->line(" 🎯 成功收集器: <info>{$successCount}/{$totalCollectors}</info>");
  593. if ($failureCount > 0) {
  594. $this->line(" ⚠️ 失败收集器: <error>{$failureCount}/{$totalCollectors}</error>");
  595. }
  596. $this->line("");
  597. }
  598. /**
  599. * 检查是否允许自动收集日志
  600. *
  601. * @return bool
  602. */
  603. private function isAutoCollectEnabled(): bool
  604. {
  605. return GameConfigService::isAutoCollectEnabled();
  606. }
  607. }