This commit is contained in:
chenbo 2024-02-20 13:54:08 +08:00
parent 520e1037d7
commit e6c36a5d60
2 changed files with 11 additions and 21 deletions

View File

@ -167,14 +167,14 @@ class FarmController extends BaseApiController
$deviceIds = ProductDevice::whereIn('product_id', $productIds)->column('device_id');
$query->whereIn('d.id', $deviceIds);
});
$deviceList = $query->select()->toArray();
$total = $query->count();
$online = $query->where('d.is_online', 1)->count();
$offline = $query->where('d.is_online', 2)->count();
$deviceList = $query->select()->toArray();
// 请求mqtt
[$alarmCount,$todayAlarmCount] = RemoteRequestLogic::getAlarmCount($deviceList);

View File

@ -138,7 +138,12 @@ class RemoteRequestLogic extends BaseLogic
// 获取设备报警信息
foreach ($deviceList as $deivce) {
if (empty($deivce['code'])) {
continue;
}
$row = self::requestAlarmCount($deivce);
$totalAlarmCount += $row['totoal_warning_count'];
$todayAlarmCount += $row['today_warning_count'];
}
return [$totalAlarmCount, $todayAlarmCount];
}
@ -146,27 +151,13 @@ class RemoteRequestLogic extends BaseLogic
// 设备总告警数
public static function requestAlarmCount($device = [])
{
// todo 接口地址
$response = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). '', [
$response = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). 'api/xumu/warning/statistics', [
'query' => [
'deviceId' => $device['code']
]
]);
$monitor = json_decode($response->getContent(), true);
return $monitor['data']['values'];
}
// 设备今日告警数
public static function requestTodayAlarmCount($device = [])
{
// todo 接口地址
$response = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). '', [
'query' => [
'deviceId' => $device['code']
]
]);
$monitor = json_decode($response->getContent(), true);
return $monitor['data']['values'];
return $monitor['data'];
}
// 获取近一周的监控数据
@ -224,8 +215,7 @@ class RemoteRequestLogic extends BaseLogic
public static function requestRangeMonitorData($device)
{
// todo 接口地址
$response = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). '', [
$response = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). 'api/xumu/warning/past_seven_days', [
'query' => [
'deviceId' => $device['code']
]