|
|
@@ -17,7 +17,7 @@ class CollectUserLogsCommand extends Command
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $signature = 'game:collect-user-logs {--reset : 重置处理进度,从头开始收集} {--info : 显示收集器信息} {--statistics : 显示收集统计信息} {--detail : 显示详细的处理过程} {--limit=1000 : 单次处理最大记录数}';
|
|
|
+ protected $signature = 'game:collect-user-logs {--info : 显示收集器信息} {--statistics : 显示收集统计信息} {--detail : 显示详细的处理过程} {--limit=1000 : 单次处理最大记录数}';
|
|
|
|
|
|
/**
|
|
|
* 命令描述
|
|
|
@@ -27,11 +27,12 @@ class CollectUserLogsCommand extends Command
|
|
|
protected $description = '收集用户日志,将各模块的原始日志转换为用户友好的日志消息
|
|
|
|
|
|
选项说明:
|
|
|
- --reset 重置处理进度,从头开始收集
|
|
|
--info 显示收集器信息
|
|
|
--statistics 显示收集统计信息
|
|
|
--detail 显示详细的处理过程
|
|
|
- --limit 单次处理最大记录数(默认1000)';
|
|
|
+ --limit 单次处理最大记录数(默认1000)
|
|
|
+
|
|
|
+注意:进度追踪基于user_logs表中的已处理记录,系统会自动从上次处理位置继续收集';
|
|
|
|
|
|
/**
|
|
|
* 执行命令
|
|
|
@@ -41,12 +42,18 @@ class CollectUserLogsCommand extends Command
|
|
|
|
|
|
// 显示统计信息
|
|
|
if ($this->option('statistics')) {
|
|
|
+ $manager = new UserLogCollectorManager();
|
|
|
+ $collectorsInfo = $manager->getCollectorsInfo();
|
|
|
+
|
|
|
$this->info("📊 收集器统计信息:");
|
|
|
$this->line("");
|
|
|
- $this->line("收集器数量: 3");
|
|
|
- $this->line("- fund: 资金日志收集器");
|
|
|
- $this->line("- item: 物品日志收集器");
|
|
|
- $this->line("- farm: 农场日志收集器");
|
|
|
+ $this->line("收集器数量: " . count($collectorsInfo));
|
|
|
+
|
|
|
+ // 动态显示所有收集器
|
|
|
+ foreach ($collectorsInfo as $name => $info) {
|
|
|
+ $icon = $this->getCollectorIcon($info['source_type']);
|
|
|
+ $this->line("- {$name}: {$icon} {$this->getCollectorDescription($info['source_type'])}");
|
|
|
+ }
|
|
|
$this->line("");
|
|
|
|
|
|
// 显示用户日志表统计
|
|
|
@@ -62,17 +69,15 @@ class CollectUserLogsCommand extends Command
|
|
|
$this->line(" 🕐 最新日志时间: " . $latestLog->created_at);
|
|
|
$this->line(" 🕐 最旧日志时间: " . $oldestLog->created_at);
|
|
|
|
|
|
- // 按类型统计
|
|
|
- $fundCount = \App\Module\Game\Models\UserLog::where('source_type', 'fund')->count();
|
|
|
- $itemCount = \App\Module\Game\Models\UserLog::where('source_type', 'item')->count();
|
|
|
- $farmCount = \App\Module\Game\Models\UserLog::where('source_type', 'farm')->count();
|
|
|
- $pointCount = \App\Module\Game\Models\UserLog::where('source_type', 'point')->count();
|
|
|
-
|
|
|
+ // 按类型统计 - 动态获取所有收集器类型
|
|
|
$this->line(" 📊 按类型统计:");
|
|
|
- $this->line(" 💰 资金日志: {$fundCount}");
|
|
|
- $this->line(" 📦 物品日志: {$itemCount}");
|
|
|
- $this->line(" 🌾 农场日志: {$farmCount}");
|
|
|
- $this->line(" ⭐ 积分日志: {$pointCount}");
|
|
|
+ foreach ($collectorsInfo as $name => $info) {
|
|
|
+ $sourceType = $info['source_type'];
|
|
|
+ $count = \App\Module\Game\Models\UserLog::where('source_type', $sourceType)->count();
|
|
|
+ $icon = $this->getCollectorIcon($sourceType);
|
|
|
+ $description = $this->getCollectorDescription($sourceType);
|
|
|
+ $this->line(" {$icon} {$description}: {$count}");
|
|
|
+ }
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
$this->line(" ⚠️ 无法获取用户日志统计: " . $e->getMessage());
|
|
|
@@ -90,12 +95,6 @@ class CollectUserLogsCommand extends Command
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- // 重置收集器进度
|
|
|
- if ($this->option('reset')) {
|
|
|
- $this->resetCollectors($manager);
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
// 执行日志收集
|
|
|
return $this->executeCollection($manager);
|
|
|
}
|
|
|
@@ -342,47 +341,67 @@ class CollectUserLogsCommand extends Command
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 重置收集器进度
|
|
|
+ * 显示统计信息
|
|
|
*
|
|
|
* @param UserLogCollectorManager $manager
|
|
|
* @return void
|
|
|
*/
|
|
|
- private function resetCollectors(UserLogCollectorManager $manager): void
|
|
|
+ private function showStats(UserLogCollectorManager $manager): void
|
|
|
{
|
|
|
- if ($this->confirm('确定要重置处理进度吗?这将清空所有用户日志并从头开始收集。')) {
|
|
|
- try {
|
|
|
- // 清空用户日志表
|
|
|
- \App\Module\Game\Models\UserLog::truncate();
|
|
|
-
|
|
|
- // 重置全局时间戳(兼容性)
|
|
|
- \Illuminate\Support\Facades\Cache::forget('user_log_collector:global_last_timestamp');
|
|
|
+ $collectorsInfo = $manager->getCollectorsInfo();
|
|
|
|
|
|
- // 重置各收集器的进度(兼容性)
|
|
|
- $manager->resetAllCollectors();
|
|
|
+ $this->line("");
|
|
|
+ $this->line("收集器数量: " . count($collectorsInfo));
|
|
|
|
|
|
- $this->info("✅ 已重置处理进度,清空了所有用户日志");
|
|
|
- } catch (\Exception $e) {
|
|
|
- $this->error("❌ 重置失败: {$e->getMessage()}");
|
|
|
- }
|
|
|
+ // 动态显示所有收集器
|
|
|
+ foreach ($collectorsInfo as $name => $info) {
|
|
|
+ $icon = $this->getCollectorIcon($info['source_type']);
|
|
|
+ $this->line("- {$name}: {$icon} {$this->getCollectorDescription($info['source_type'])}");
|
|
|
}
|
|
|
+ $this->line("");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 显示统计信息
|
|
|
+ * 获取收集器图标
|
|
|
*
|
|
|
- * @param UserLogCollectorManager $manager
|
|
|
- * @return void
|
|
|
+ * @param string $sourceType
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- private function showStats(UserLogCollectorManager $manager): void
|
|
|
+ private function getCollectorIcon(string $sourceType): string
|
|
|
{
|
|
|
- $this->line("");
|
|
|
- $this->line("收集器数量: 4");
|
|
|
- $this->line("- fund: 资金日志收集器");
|
|
|
- $this->line("- item: 物品日志收集器");
|
|
|
- $this->line("- farm: 农场日志收集器");
|
|
|
- $this->line("- point: 积分日志收集器");
|
|
|
- $this->line("");
|
|
|
+ $icons = [
|
|
|
+ 'fund' => '💰',
|
|
|
+ 'item' => '📦',
|
|
|
+ 'farm' => '🌾',
|
|
|
+ 'point' => '⭐',
|
|
|
+ 'pet' => '🐾',
|
|
|
+ 'system' => '⚙️',
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $icons[$sourceType] ?? '📄';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取收集器描述
|
|
|
+ *
|
|
|
+ * @param string $sourceType
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ private function getCollectorDescription(string $sourceType): string
|
|
|
+ {
|
|
|
+ $descriptions = [
|
|
|
+ 'fund' => '资金日志收集器',
|
|
|
+ 'item' => '物品日志收集器',
|
|
|
+ 'farm' => '农场日志收集器',
|
|
|
+ 'point' => '积分日志收集器',
|
|
|
+ 'pet' => '宠物日志收集器',
|
|
|
+ 'system' => '系统日志收集器',
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $descriptions[$sourceType] ?? '未知类型收集器';
|
|
|
}
|
|
|
|
|
|
/**
|