is_numeric($seconds) ? $seconds : 300, $this->option('sleep')); while (true) { try { /** @var \Illuminate\Database\Eloquent\Collection */ $devices = Device::supplierBy('device-supplier-yunfei')->get(); foreach ($devices as $device) { $this->createReport($device); } } catch (Throwable $e) { report($e); } sleep($seconds); }; } /** * 创建比昂设备报告 */ protected function createReport(Device $device): void { $lastReportedAt = match ($device->type) { DeviceType::InsecticidalLamp => InsecticidalLampReport::where('device_id', $device->id)->latest('reported_at')->value('reported_at'), default => null, }; if (is_null($lastReportedAt ??= DeviceLog::where('device_id', $device->id)->oldest('reported_at')->value('reported_at'))) { return; } if (is_null($latestReportedAt = DeviceLog::where('device_id', $device->id)->latest('reported_at')->value('reported_at'))) { return; } $service = new YunFeiDeviceService(); /** @var \Carbon\Carbon */ $startAt = $lastReportedAt->copy()->startOfHour(); do { $service->createReport($device, $startAt->copy()); $startAt->addHour(); } while ($latestReportedAt->gte($startAt)); } }