59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\DeviceType;
|
|
use App\Models\Device;
|
|
use App\Models\LinkosDeviceLog;
|
|
use App\Services\LinkosDeviceLogService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class LinkosDeviceLogArchiveCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'linkos:device-log-archive';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'LinkOS 设备流水归档';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @param \App\Services\LinkosDeviceLogService $linkosDeviceLogService
|
|
* @return int
|
|
*/
|
|
public function handle(LinkosDeviceLogService $linkosDeviceLogService)
|
|
{
|
|
$devices = Device::whereIn('type', [DeviceType::Meteorological, DeviceType::Soil, DeviceType::WaterQuality])->get();
|
|
|
|
// 物联平台目前只有水质监测设备和气象监测设备
|
|
LinkosDeviceLog::orderBy('reported_at', 'asc')->lazy()->each(function ($log) use ($devices, $linkosDeviceLogService) {
|
|
if (empty($log->data)) {
|
|
return;
|
|
}
|
|
|
|
foreach ($devices as $device) {
|
|
if ($device->sn !== $log->device_id) {
|
|
continue;
|
|
}
|
|
|
|
match ($device->type) {
|
|
DeviceType::Soil => $linkosDeviceLogService->handleSoilMonitoringLog($device, $log->data, $log->reported_at),
|
|
DeviceType::Meteorological => $linkosDeviceLogService->handleMeteorologicalMonitoringLog($device, $log->data, $log->reported_at),
|
|
DeviceType::WaterQuality => $linkosDeviceLogService->handleWaterQualityMonitoringLog($device, $log->data, $log->reported_at),
|
|
};
|
|
}
|
|
});
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|