From dde34bfbce11139c78bfad19f59481a4b828fe1f Mon Sep 17 00:00:00 2001 From: Jing Li Date: Mon, 23 Oct 2023 11:48:21 +0800 Subject: [PATCH] Update --- .../Commands/BiAng/DeviceLogSyncCommand.php | 11 ++++++++++- app/Iot/BiAng/HttpClient.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/BiAng/DeviceLogSyncCommand.php b/app/Console/Commands/BiAng/DeviceLogSyncCommand.php index 643457d..4cd1222 100644 --- a/app/Console/Commands/BiAng/DeviceLogSyncCommand.php +++ b/app/Console/Commands/BiAng/DeviceLogSyncCommand.php @@ -10,7 +10,6 @@ use App\Models\DeviceLog; use App\Models\WormPhoto; use Illuminate\Console\Command; use Illuminate\Support\Arr; -use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Storage; use RuntimeException; use Throwable; @@ -65,6 +64,7 @@ class DeviceLogSyncCommand extends Command /** @var \App\Models\Device */ foreach ($devices as $device) { if (! in_array($device->type, [ + DeviceType::Monitor, DeviceType::Soil, DeviceType::Meteorological, DeviceType::Worm, @@ -78,6 +78,7 @@ class DeviceLogSyncCommand extends Command $this->info('设备编号: ' . $device->sn); $this->info('设备名称: ' . $device->name); $this->info('设备类型: ' . match ($device->type) { + DeviceType::Monitor => '苗情设备', DeviceType::Soil => '土壤设备', DeviceType::Meteorological => '气象设备', DeviceType::Worm => '虫情设备', @@ -89,6 +90,14 @@ class DeviceLogSyncCommand extends Command $httpClient = $this->buildHttpClient($device); switch ($device->type) { + case DeviceType::Monitor: + $data = $httpClient->getMonitorPalyAddress($device->sn); + + $device->update([ + 'status' => $data ? DeviceStatus::Online : DeviceStatus::Offline, + ]); + + break; case DeviceType::Soil: $data = $httpClient->getLatestSoilReport($device->sn); diff --git a/app/Iot/BiAng/HttpClient.php b/app/Iot/BiAng/HttpClient.php index 46e855a..1c9b158 100644 --- a/app/Iot/BiAng/HttpClient.php +++ b/app/Iot/BiAng/HttpClient.php @@ -95,6 +95,21 @@ class HttpClient return $result['data'] ?? []; } + /** + * 苗情设备 - 直播地址 + */ + public function getMonitorPalyAddress(string $deviceId) + { + $result = $this->get( + $this->apiUrl('/api/open-api/open/getSeedingLive'), + [ + 'equipmentCode' => $deviceId, + ] + ); + + return $result['data'] ?? ""; + } + public function get(string $url, array $query = []): array { return $this->request('GET', $url, [