From cc0db07345d828704f1ad6a9c9d48bba1f49ebb4 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Mon, 24 Oct 2022 11:11:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/gateway/DeviceGatewayHelper.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/DeviceGatewayHelper.java b/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/DeviceGatewayHelper.java index fc770bcb..edf8d6d0 100755 --- a/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/DeviceGatewayHelper.java +++ b/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/DeviceGatewayHelper.java @@ -19,6 +19,7 @@ import reactor.core.publisher.Mono; import reactor.util.context.Context; import java.time.Duration; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -124,8 +125,16 @@ public class DeviceGatewayHelper { .createOrUpdateSession(childrenId, children, child -> Mono.just(new ChildrenDeviceSession(childrenId, parentSession, child)), - Mono::empty)); - + Mono::empty) + .doOnNext(session -> { + if (session.isWrapFrom(ChildrenDeviceSession.class)) { + ChildrenDeviceSession childrenSession = session.unwrap(ChildrenDeviceSession.class); + //网关发生变化,替换新的上级会话 + if (!Objects.equals(deviceId, childrenSession.getParent().getDeviceId())) { + childrenSession.replaceWith(parentSession); + } + } + })); //子设备注册 if (isDoRegister(children)) {