From 4d5943d7b745345a5feff903d9db46ec827fdce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E7=9F=B3?= <569216570@qq.com> Date: Sun, 21 Dec 2025 11:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=8E=A5=E5=85=A5=E7=BD=91=E5=85=B3=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E7=B3=BB=E7=BB=9F=E9=87=8D=E5=90=AF=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=9A=84=E6=8F=92=E4=BB=B6=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=90=AF=E5=8A=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supports/DefaultDeviceGatewayManager.java | 21 ++++++++++++--- .../device/PluginDeviceGatewayProvider.java | 27 ++++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java b/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java index 2bbc87d1..ae1c78bf 100755 --- a/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java +++ b/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java @@ -123,14 +123,29 @@ public class DefaultDeviceGatewayManager implements DeviceGatewayManager { .compute(gatewayId, (id, gateway) -> { if (gateway != null) { log.debug("reload device gateway {} {}:{}", prop.getName(), prop.getProvider(), prop.getId()); - return provider + Mono reloaded = provider .reloadDeviceGateway(gateway, prop) .cast(DeviceGateway.class); + // 如果网关被禁用,重载后不启动 + if (!prop.isEnabled()) { + return reloaded.flatMap(g -> { + log.debug("device gateway {} is disabled, skip startup", gatewayId); + return Mono.just(g); + }); + } + return reloaded; } log.debug("create device gateway {} {}:{}", prop.getName(), prop.getProvider(), prop.getId()); - return provider + Mono created = provider .createDeviceGateway(prop) - .flatMap(newer -> newer.startup().thenReturn(newer)); + .cast(DeviceGateway.class); + // 只有启用的网关才自动启动 + if (prop.isEnabled()) { + return created.flatMap(newer -> newer.startup().thenReturn(newer)); + } else { + log.debug("device gateway {} is disabled, skip startup", gatewayId); + return created; + } }); }) .then(); diff --git a/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java b/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java index fbd54340..ce4c949b 100644 --- a/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java +++ b/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java @@ -17,6 +17,15 @@ package org.jetlinks.community.plugin.device; import org.hswebframework.web.exception.BusinessException; import org.hswebframework.web.i18n.LocaleUtils; +import org.jetlinks.community.PropertyConstants; +import org.jetlinks.community.codec.Serializers; +import org.jetlinks.community.gateway.DeviceGateway; +import org.jetlinks.community.gateway.supports.DeviceGatewayProperties; +import org.jetlinks.community.gateway.supports.DeviceGatewayProvider; +import org.jetlinks.community.plugin.PluginDriverManager; +import org.jetlinks.community.plugin.context.*; +import org.jetlinks.community.plugin.monitor.PluginMonitorHelper; +import org.jetlinks.community.plugin.utils.PluginUtils; import org.jetlinks.core.defaults.CompositeProtocolSupport; import org.jetlinks.core.device.DeviceOperator; import org.jetlinks.core.device.DeviceRegistry; @@ -36,15 +45,6 @@ import org.jetlinks.plugin.core.ServiceRegistry; import org.jetlinks.plugin.internal.PluginDataIdMapper; import org.jetlinks.plugin.internal.device.DeviceGatewayPlugin; import org.jetlinks.plugin.internal.device.PluginDeviceGatewayService; -import org.jetlinks.community.PropertyConstants; -import org.jetlinks.community.codec.Serializers; -import org.jetlinks.community.gateway.DeviceGateway; -import org.jetlinks.community.gateway.supports.DeviceGatewayProperties; -import org.jetlinks.community.gateway.supports.DeviceGatewayProvider; -import org.jetlinks.community.plugin.PluginDriverManager; -import org.jetlinks.community.plugin.context.*; -import org.jetlinks.community.plugin.monitor.PluginMonitorHelper; -import org.jetlinks.community.plugin.utils.PluginUtils; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -235,7 +235,14 @@ public class PluginDeviceGatewayProvider extends CompositeProtocolSupport .unwrap(PluginDeviceGateway.class) .shutdown() .then(createDeviceGateway(properties)) - .flatMap(gate -> gate.startup().thenReturn(gate)); + .flatMap(gate -> { + // 只有启用的网关才自动启动 + if (properties.isEnabled()) { + return gate.startup().thenReturn(gate); + } else { + return Mono.just(gate); + } + }); } @Override