factory?->key) { case 'link-os': $this->syncLinkosDeviceLogs($device, $start, $end); break; } } /** * 同步 Linkos 设备历史流水 */ protected function syncLinkosDeviceLogs(Device $device, Carbon $start, Carbon $end): void { /** @var \App\Iot\Linkos\HttpClient */ $httpClient = app(LinkosHttpClient::class); $page = 1; $perPage = 50; do { $data = $httpClient->getDeviceFlowList( $device->sn, $start, $end, $page, $perPage ); $countResults = count($data['content']); if ($countResults === 0) { break; } foreach ($data['content'] as $item) { $isSoilMonitoring = Arr::hasAny($item['data'], [ 'soil_humidity', 'soil_temperature', 'nitrogen_content', 'potassium_content', 'phosphorus_content', ]); if (($device->isTypeSoil() && ! $isSoilMonitoring) || (! $device->isTypeSoil() && $isSoilMonitoring)) { continue; } $device->logs()->firstOrCreate([ 'reported_at' => $item['createTime'], ], [ 'data' => empty($item['data']) ? (new \stdClass) : $item['data'], ]); } unset($data); $page++; } while ($countResults === $perPage); } }