deviceLogService = $deviceLogService; $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(); sleep($sleep); }; } protected function performSync(Carbon $start, Carbon $end): void { /** @var \Illuminate\Database\Eloquent\Collection */ $devices = Device::with(['factory'])->poweredBy($this->argument('factory'))->get(); foreach ($devices as $device) { $this->info('=========================================='); $this->info('设备编号: ' . $device->sn); $this->info('设备名称: ' . $device->name); try { $this->deviceLogService->sync($device, $start, $end); $this->info('同步成功!'); } catch (Throwable $e) { report($e); $this->error('同步失败: '. $e->getMessage()); } $this->info('=========================================='); } } }