update 数据采集-设备链接事件

This commit is contained in:
chenbo 2023-12-14 16:32:25 +08:00
parent d318614d48
commit 6d42143fd2
1 changed files with 13 additions and 2 deletions

View File

@ -30,8 +30,6 @@ class DataCollectController extends BaseApiController
if ($parmas['event'] == 'message.publish') { if ($parmas['event'] == 'message.publish') {
$payload= json_decode($parmas['payload'], true); $payload= json_decode($parmas['payload'], true);
// 如果该设备之前离线,现在重新上线则删除之前的设备离线记录
DeviceOffline::where('land_id', $land[3])->delete();
$device = explode('_', $parmas['topic']); // 命名规则topic_deviceid deviceid为设备主键id $device = explode('_', $parmas['topic']); // 命名规则topic_deviceid deviceid为设备主键id
$data = [ $data = [
'land_id' => $land[3], 'land_id' => $land[3],
@ -188,6 +186,19 @@ class DataCollectController extends BaseApiController
} }
return $this->success('接收成功'); return $this->success('接收成功');
} }
// 连接链接事件 设备已上线
if ($parmas['event'] == 'client.connected') {
// 查询该土地关联的设备
$landProduct = LandProduct::where('land_id', $land[3])->find();
$productDevice = ProductDevice::where('product_id', $landProduct['product_id'])->select();
// 如果该设备之前离线,现在重新上线则删除之前的设备离线记录
DeviceOffline::where('land_id', $land[3])->delete();
foreach ($productDevice as $item) {
Device::where('id', $item['device_id'])->update(['is_online' => 1]);
}
return $this->success('接收成功');
}
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e->getMessage()); return $this->fail($e->getMessage());
} }