同步比昂水质设备数据
parent
7daf2e52f3
commit
40df91fcc6
|
|
@ -70,6 +70,7 @@ class DeviceLogSyncCommand extends Command
|
|||
if (! in_array($device->type, [
|
||||
DeviceType::Monitor,
|
||||
DeviceType::Soil,
|
||||
DeviceType::WaterQuality,
|
||||
DeviceType::Meteorological,
|
||||
DeviceType::Worm,
|
||||
DeviceType::InsectSexLure,
|
||||
|
|
@ -84,6 +85,7 @@ class DeviceLogSyncCommand extends Command
|
|||
$this->info('设备类型: ' . match ($device->type) {
|
||||
DeviceType::Monitor => '苗情设备',
|
||||
DeviceType::Soil => '土壤设备',
|
||||
DeviceType::WaterQuality => '水质设备',
|
||||
DeviceType::Meteorological => '气象设备',
|
||||
DeviceType::Worm => '虫情设备',
|
||||
DeviceType::InsectSexLure => '昆虫性诱设备',
|
||||
|
|
@ -102,61 +104,26 @@ class DeviceLogSyncCommand extends Command
|
|||
]);
|
||||
|
||||
break;
|
||||
|
||||
case DeviceType::Soil:
|
||||
$data = $httpClient->getLatestSoilReport($device->sn);
|
||||
|
||||
if (empty($data)) {
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Offline,
|
||||
]);
|
||||
$this->warn('设备数据为空');
|
||||
break;
|
||||
}
|
||||
|
||||
$log = DeviceLog::firstOrCreate([
|
||||
'device_id' => $device->id,
|
||||
'reported_at' => $data['time'],
|
||||
], [
|
||||
'data' => Arr::except($data, ['deviceId', 'time']),
|
||||
]);
|
||||
|
||||
$device->update([
|
||||
'status' => $now->copy()->subMinutes(60)->lt($log->reported_at) ? DeviceStatus::Online : DeviceStatus::Offline,
|
||||
]);
|
||||
break;
|
||||
|
||||
case DeviceType::WaterQuality:
|
||||
case DeviceType::Meteorological:
|
||||
$data = $httpClient->getLatestMeteorologicalReport($device->sn);
|
||||
|
||||
if (empty($data)) {
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Offline,
|
||||
]);
|
||||
$this->warn('设备数据为空');
|
||||
break;
|
||||
}
|
||||
|
||||
$log = DeviceLog::firstOrCreate([
|
||||
'device_id' => $device->id,
|
||||
'reported_at' => $data['time'],
|
||||
], [
|
||||
'data' => Arr::except($data, ['deviceId', 'time']),
|
||||
]);
|
||||
|
||||
$device->update([
|
||||
'status' => $now->copy()->subMinutes(60)->lt($log->reported_at) ? DeviceStatus::Online : DeviceStatus::Offline,
|
||||
]);
|
||||
break;
|
||||
|
||||
case DeviceType::InsecticidalLamp:
|
||||
$data = $httpClient->getLatestLampReport($device->sn);
|
||||
$data = match ($device->type) {
|
||||
DeviceType::Soil => $httpClient->getLatestSoilReport($device->sn),
|
||||
DeviceType::WaterQuality => $httpClient->getLatestWaterDeviceReport($device->sn),
|
||||
DeviceType::Meteorological => $httpClient->getLatestMeteorologicalReport($device->sn),
|
||||
DeviceType::InsecticidalLamp => $httpClient->getLatestLampReport($device->sn),
|
||||
};
|
||||
|
||||
if (empty($data)) {
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Offline,
|
||||
]);
|
||||
$this->warn('设备数据为空');
|
||||
$this->warn('设备数据: 无');
|
||||
break;
|
||||
} else {
|
||||
$this->info('设备数据: '.json_encode($data));
|
||||
}
|
||||
|
||||
$log = DeviceLog::firstOrCreate([
|
||||
|
|
@ -183,8 +150,10 @@ class DeviceLogSyncCommand extends Command
|
|||
$device->update([
|
||||
'status' => DeviceStatus::Offline,
|
||||
]);
|
||||
$this->warn('设备数据为空');
|
||||
$this->warn('设备数据: 无');
|
||||
break;
|
||||
} else {
|
||||
$this->info('设备数据: '.json_encode($data));
|
||||
}
|
||||
|
||||
foreach ($data['imgUrl'] as $item) {
|
||||
|
|
@ -215,6 +184,16 @@ class DeviceLogSyncCommand extends Command
|
|||
break;
|
||||
}
|
||||
|
||||
switch ($device->status) {
|
||||
case DeviceStatus::Online:
|
||||
$this->info('设备状态: 在线');
|
||||
break;
|
||||
|
||||
case DeviceStatus::Offline:
|
||||
$this->warn('设备状态: 离线');
|
||||
break;
|
||||
}
|
||||
|
||||
$this->info('同步成功!');
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,21 @@ class HttpClient
|
|||
return $result['data'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新的水质设备数据
|
||||
*/
|
||||
public function getLatestWaterDeviceReport(string $deviceId)
|
||||
{
|
||||
$result = $this->get(
|
||||
$this->apiUrl('/api/open-api/open/getWaterDeviceData'),
|
||||
[
|
||||
'deviceId' => $deviceId,
|
||||
]
|
||||
);
|
||||
|
||||
return $result['data'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新的气象数据
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue