From 3d07fde0087924371247c16539493bb1f09e89c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Sat, 6 May 2023 16:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=20linkos=20=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E5=9C=9F=E5=A3=A4=E7=9B=91=E6=8E=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=92=8C=E6=B0=94=E8=B1=A1=E7=9B=91=E6=8E=A7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/DeviceLogSyncCommand.php | 7 +++++++ app/Models/Device.php | 5 +++++ app/Services/DeviceLogService.php | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/app/Console/Commands/DeviceLogSyncCommand.php b/app/Console/Commands/DeviceLogSyncCommand.php index d5ea029..8a900ea 100644 --- a/app/Console/Commands/DeviceLogSyncCommand.php +++ b/app/Console/Commands/DeviceLogSyncCommand.php @@ -68,6 +68,13 @@ class DeviceLogSyncCommand extends Command $this->info('=========================================='); $this->info('设备编号: ' . $device->sn); $this->info('设备名称: ' . $device->name); + $this->info('设备类型: ' . match ($device->type) { + Device::TYPE_SOIL => '土壤设备', + Device::TYPE_WATER_QUALITY => '水质设备', + Device::TYPE_METEOROLOGICAL => '气象设备', + Device::TYPE_AIR => '通风设备', + default => '其它', + }); try { $this->deviceLogService->sync($device, $start, $end); diff --git a/app/Models/Device.php b/app/Models/Device.php index cd09d9d..bc21c8b 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -64,4 +64,9 @@ class Device extends Model { return $this->belongsTo(Keyword::class, 'powered_by'); } + + public function isTypeSoil(): bool + { + return $this->type === static::TYPE_SOIL; + } } diff --git a/app/Services/DeviceLogService.php b/app/Services/DeviceLogService.php index eb5b9b7..6c185ca 100644 --- a/app/Services/DeviceLogService.php +++ b/app/Services/DeviceLogService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\Iot\Linkos\HttpClient as LinkosHttpClient; use App\Models\Device; +use Illuminate\Support\Arr; use Illuminate\Support\Carbon; class DeviceLogService @@ -44,6 +45,18 @@ class DeviceLogService } 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'], ], [