同步 linkos 设备历史数据时,区分土壤监控数据和气象监控数据
parent
3fcbe33ddc
commit
3d07fde008
|
|
@ -68,6 +68,13 @@ class DeviceLogSyncCommand extends Command
|
||||||
$this->info('==========================================');
|
$this->info('==========================================');
|
||||||
$this->info('设备编号: ' . $device->sn);
|
$this->info('设备编号: ' . $device->sn);
|
||||||
$this->info('设备名称: ' . $device->name);
|
$this->info('设备名称: ' . $device->name);
|
||||||
|
$this->info('设备类型: ' . match ($device->type) {
|
||||||
|
Device::TYPE_SOIL => '土壤设备',
|
||||||
|
Device::TYPE_WATER_QUALITY => '水质设备',
|
||||||
|
Device::TYPE_METEOROLOGICAL => '气象设备',
|
||||||
|
Device::TYPE_AIR => '通风设备',
|
||||||
|
default => '其它',
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->deviceLogService->sync($device, $start, $end);
|
$this->deviceLogService->sync($device, $start, $end);
|
||||||
|
|
|
||||||
|
|
@ -64,4 +64,9 @@ class Device extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Keyword::class, 'powered_by');
|
return $this->belongsTo(Keyword::class, 'powered_by');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isTypeSoil(): bool
|
||||||
|
{
|
||||||
|
return $this->type === static::TYPE_SOIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Services;
|
||||||
|
|
||||||
use App\Iot\Linkos\HttpClient as LinkosHttpClient;
|
use App\Iot\Linkos\HttpClient as LinkosHttpClient;
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class DeviceLogService
|
class DeviceLogService
|
||||||
|
|
@ -44,6 +45,18 @@ class DeviceLogService
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data['content'] as $item) {
|
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([
|
$device->logs()->firstOrCreate([
|
||||||
'reported_at' => $item['createTime'],
|
'reported_at' => $item['createTime'],
|
||||||
], [
|
], [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue