1
0
Fork 0

同步 linkos 设备历史数据时,区分土壤监控数据和气象监控数据

develop
李静 2023-05-06 16:16:21 +08:00
parent 3fcbe33ddc
commit 3d07fde008
3 changed files with 25 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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'],
], [