is_numeric($sleep) ? $sleep : 60, $this->option('sleep')); while (true) { $this->runSync(); sleep($sleep); }; } /** * 执行同步 */ protected function runSync(): void { $now = now(); $this->info('------------------------------------------'); $this->info('同步时间: '. $now); /** @var \Illuminate\Database\Eloquent\Collection */ $devices = Device::with(['project']) ->supplierBy("device-supplier-biang") ->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline]) ->get(); /** @var \App\Models\Device */ foreach ($devices as $device) { if (! in_array($device->type, [ DeviceType::Soil, DeviceType::Meteorological, DeviceType::InsecticidalLamp, ])) { continue; } $this->info('=========================================='); $this->info('设备编号: ' . $device->sn); $this->info('设备名称: ' . $device->name); $this->info('设备类型: ' . match ($device->type) { DeviceType::Soil => '土壤设备', DeviceType::Meteorological => '气象设备', DeviceType::InsecticidalLamp => '杀虫灯设备', }); try { (new BiAngDeviceLogService())->sync($device, $now->copy()); $this->info('同步成功!'); } catch (Throwable $e) { report($e); $this->error('同步失败: '. $e->getMessage()); } $this->info('=========================================='); } $this->info('------------------------------------------'); $this->newLine(); } }