This commit is contained in:
chenbo 2024-02-20 15:22:16 +08:00
parent e6c36a5d60
commit ba9844d3c5
1 changed files with 55 additions and 16 deletions

View File

@ -98,8 +98,9 @@ class RemoteRequestLogic extends BaseLogic
public static function getAlarmData($deviceList = [])
{
$list = [];
// 获取设备报警信息
foreach ($deviceList as &$device) {
foreach ($deviceList as $device) {
$device['alarm_value'] = ''; // 警告数据
$device['alarm_time'] = ''; // 警告时间
$device['alarm_resolution'] = ''; // 解决方案
@ -109,15 +110,21 @@ class RemoteRequestLogic extends BaseLogic
continue;
}
$temp = self::requestAlarmData($device);
if (empty($temp)) {
if (empty($temp['values'])) {
$list[] = $device;
continue;
}
$device['alarm_value'] = $temp[2];
$device['alarm_time'] = date('Y-m-d H:i:s', time()); // todo 对接接口字段
$device['alarm_reason'] = ''; // todo 对接接口字段
$device['alarm_resolution'] = 'test'; // todo 对接接口字段
foreach ($temp['values'][4] as $key => $value) {
$device['alarm_value'] = $value;
$device['alarm_time'] = date('Y-m-d H:i:s', $temp['timestamps'][$key]/1000);
$device['alarm_reason'] = $temp['values'][0][$key]; // todo 对接接口字段
$device['alarm_resolution'] = $temp['values'][2][$key]; // todo 对接接口字段
$list[] = $device;
}
}
return $deviceList;
return $list;
}
public static function requestAlarmData($device = [])
@ -128,7 +135,7 @@ class RemoteRequestLogic extends BaseLogic
]
]);
$monitor = json_decode($response->getContent(), true);
return $monitor['data']['values'];
return $monitor['data'];
}
public static function getAlarmCount($deviceList = [])
@ -167,45 +174,77 @@ class RemoteRequestLogic extends BaseLogic
$datas = [];
// 空气温度 ambient_temperature
$ambientTemperatureDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'ambient_temperature')->find();
$ambientTemperatureDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'ambient_temperature,ambient_humidity')->find();
if (!empty($ambientTemperatureDevice)) {
$ambientTemperatureDevice['RangeMonitorData'] = self::requestRangeMonitorData($ambientTemperatureDevice);
$rangeData = self::requestRangeMonitorData($ambientTemperatureDevice);
if (!empty($rangeData)) {
$ambientTemperatureDevice['RangeMonitorData'] = $rangeData[4];
} else {
$ambientTemperatureDevice['RangeMonitorData'] = [];
}
} else {
$ambientTemperatureDevice['RangeMonitorData'] = [];
}
// 空气湿度 ambient_humidity
$ambientHumidityDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'ambient_humidity')->find();
$ambientHumidityDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'ambient_temperature,ambient_humidity')->find();
if (!empty($ambientHumidityDevice)) {
$ambientHumidityDevice['RangeMonitorData'] = self::requestRangeMonitorData($ambientHumidityDevice);
$rangeData = self::requestRangeMonitorData($ambientHumidityDevice);
if (!empty($rangeData)) {
$ambientHumidityDevice['RangeMonitorData'] = $rangeData[4];
} else {
$ambientHumidityDevice['RangeMonitorData'] = [];
}
} else {
$ambientHumidityDevice['RangeMonitorData'] = [];
}
// 氮气 nitrogen
$NDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'nitrogen')->find();
if (!empty($NDevice)) {
$NDevice['RangeMonitorData'] = self::requestRangeMonitorData($NDevice);
$rangeData = self::requestRangeMonitorData($NDevice);
if (!empty($rangeData)) {
$NDevice['RangeMonitorData'] = $rangeData[4];
} else {
$NDevice['RangeMonitorData'] = [];
}
} else {
$NDevice['RangeMonitorData'] = [];
}
// 防火 fireproof
$fireproofDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'fireproof')->find();
if (!empty($fireproofDevice)) {
$fireproofDevice['RangeMonitorData'] = self::requestRangeMonitorData($fireproofDevice);
$rangeData = self::requestRangeMonitorData($fireproofDevice);
if (!empty($rangeData)) {
$fireproofDevice['RangeMonitorData'] = $rangeData[4];
} else {
$fireproofDevice['RangeMonitorData'] = [];
}
} else {
$fireproofDevice['RangeMonitorData'] = [];
}
// 甲烷 methane
$methaneDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'methane')->find();
if (!empty($methaneDevice)) {
$methaneDevice['RangeMonitorData'] = self::requestRangeMonitorData($methaneDevice);
$rangeData = self::requestRangeMonitorData($methaneDevice);
if (!empty($rangeData)) {
$methaneDevice['RangeMonitorData'] = $rangeData[4];
} else {
$methaneDevice['RangeMonitorData'] = [];
}
} else {
$methaneDevice['RangeMonitorData'] = [];
}
// 噪音 noise
$noiseDevice = Device::whereIn('id', $deviceIds)->where('monitor_item', 'noise')->find();
if (!empty($noiseDevice)) {
$noiseDevice['RangeMonitorData'] = self::requestRangeMonitorData($noiseDevice);
$rangeData = self::requestRangeMonitorData($noiseDevice);
if (!empty($rangeData)) {
$noiseDevice['RangeMonitorData'] = $rangeData[4];
} else {
$noiseDevice['RangeMonitorData'] = [];
}
} else {
$noiseDevice['RangeMonitorData'] = [];
}