diff --git a/app/Console/Commands/MonitorDeviceHealthCommand.php b/app/Console/Commands/MonitorDeviceHealthCommand.php index 6be915c..723987d 100644 --- a/app/Console/Commands/MonitorDeviceHealthCommand.php +++ b/app/Console/Commands/MonitorDeviceHealthCommand.php @@ -64,18 +64,14 @@ class MonitorDeviceHealthCommand extends Command ); foreach ($result['data'] as $item) { - $device = Device::supplierBy('device-supplier-yidong') + Device::where('sn', $item['deviceId']) + ->where('supplier_key', 'device-supplier-yidong') ->where('type', DeviceType::Monitor) - ->where('sn', $item['deviceId']) - ->first(); - - if (! in_array($device?->status, [DeviceStatus::Online, DeviceStatus::Offline])) { - continue; - } - - $device->update([ - 'status' => $item['deviceStatus'] === 1 ? DeviceStatus::Online : DeviceStatus::Offline, - ]); + ->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline]) + ->update([ + 'status' => $item['deviceStatus'] === 1 ? DeviceStatus::Online : DeviceStatus::Offline, + 'updated_at' => now(), + ]); } $page++; @@ -96,31 +92,23 @@ class MonitorDeviceHealthCommand extends Command ], ); - $devices = Device::supplierBy('device-supplier-dianxin') - ->where('type', DeviceType::Monitor) - ->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline]) - ->get(); - - foreach ($devices as $device) { - foreach ($result['data'] as $item) { - if ($device->sn !== $item['channelcode']) { - continue; - } - - $device->update([ - 'extends' => [ - 'ip' => '', - 'port' => '', - 'username' => '', - 'password' => '', - 'passage' => $item['citId'], - 'rtsp_url' => '', - ], - 'status' => $item['channelstatus'] === 1 ? DeviceStatus::Online : DeviceStatus::Offline, - ]); - - break; - } + foreach ($result['data'] as $item) { + Device::where('sn', $item['channelcode']) + ->where('supplier_key', 'device-supplier-dianxin') + ->where('type', DeviceType::Monitor) + ->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline]) + ->update([ + 'extends' => json_encode([ + 'ip' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'passage' => $item['citId'], + 'rtsp_url' => '', + ]), + 'status' => $item['channelstatus'] === 1 ? DeviceStatus::Online : DeviceStatus::Offline, + 'updated_at' => now(), + ]); } } } diff --git a/app/Iot/Qly/HttpClient.php b/app/Iot/Qly/HttpClient.php index d6d4f14..5fde51b 100644 --- a/app/Iot/Qly/HttpClient.php +++ b/app/Iot/Qly/HttpClient.php @@ -33,7 +33,7 @@ class HttpClient 'headers' => $headers, 'json' => $data, ]); - } catch (YiDongException $e) { + } catch (QlyException $e) { throw $e; } }