update 数据采集-设备链接事件
This commit is contained in:
parent
d318614d48
commit
6d42143fd2
|
@ -30,8 +30,6 @@ class DataCollectController extends BaseApiController
|
|||
if ($parmas['event'] == 'message.publish') {
|
||||
|
||||
$payload= json_decode($parmas['payload'], true);
|
||||
// 如果该设备之前离线,现在重新上线则删除之前的设备离线记录
|
||||
DeviceOffline::where('land_id', $land[3])->delete();
|
||||
$device = explode('_', $parmas['topic']); // 命名规则:topic_deviceid deviceid为设备主键id
|
||||
$data = [
|
||||
'land_id' => $land[3],
|
||||
|
@ -188,6 +186,19 @@ class DataCollectController extends BaseApiController
|
|||
}
|
||||
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) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue