diff --git a/app/Console/Commands/DeviceLogSyncCommand.php b/app/Console/Commands/DeviceLogSyncCommand.php index e727132..d5ea029 100644 --- a/app/Console/Commands/DeviceLogSyncCommand.php +++ b/app/Console/Commands/DeviceLogSyncCommand.php @@ -38,29 +38,31 @@ class DeviceLogSyncCommand extends Command { $this->deviceLogService = $deviceLogService; + $factory = $this->argument('factory'); + $sleep = (int) value(fn ($sleep) => is_numeric($sleep) ? $sleep : 60, $this->option('sleep')); while (true) { - $end = now(); - $start = $end->copy()->subHours(1); - - $this->info('------------------------------------------'); - $this->info('开始时间: '. $start); - $this->info('结束时间: '. $end); - - $this->performSync($start, $end); - - $this->info('------------------------------------------'); - $this->newLine(); + $this->runSync($factory); sleep($sleep); }; } - protected function performSync(Carbon $start, Carbon $end): void + /** + * 执行同步 + */ + protected function runSync(string $factory): void { + $end = now(); + $start = $end->copy()->subHours(1); + + $this->info('------------------------------------------'); + $this->info('开始时间: '. $start); + $this->info('结束时间: '. $end); + /** @var \Illuminate\Database\Eloquent\Collection */ - $devices = Device::with(['factory'])->poweredBy($this->argument('factory'))->get(); + $devices = Device::with(['factory'])->poweredBy($factory)->get(); foreach ($devices as $device) { $this->info('=========================================='); @@ -79,5 +81,8 @@ class DeviceLogSyncCommand extends Command $this->info('=========================================='); } + + $this->info('------------------------------------------'); + $this->newLine(); } }