From 9f71751d01832048090434354f6f92b9524ab6e5 Mon Sep 17 00:00:00 2001 From: zhangji <125540670@qq.com> Date: Fri, 30 Jun 2023 14:15:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8F=92=E4=BB=B6):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE=E6=AF=8F=E6=AC=A1=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=BB=E5=8A=A0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jetlinks/plugin/example/sdk/PluginProduct.java | 5 +++++ .../org/jetlinks/plugin/example/sdk/PluginProductPTZ.java | 2 -- .../jetlinks/plugin/example/sdk/PluginProductRS485.java | 7 ++++--- .../org/jetlinks/plugin/example/sdk/SdkDevicePlugin.java | 8 ++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProduct.java b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProduct.java index f52be35..4ac4b21 100644 --- a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProduct.java +++ b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProduct.java @@ -1,5 +1,6 @@ package org.jetlinks.plugin.example.sdk; +import org.jetlinks.core.config.ConfigKey; import org.jetlinks.core.device.DeviceOperator; import org.jetlinks.core.metadata.ConfigMetadata; import org.jetlinks.plugin.example.sdk.hc.NetSDKDemo; @@ -15,6 +16,10 @@ */ public interface PluginProduct { + String USERNAME = "user"; + String PASSWORD = "psw"; + ConfigKey required = ConfigKey.of("required", "是否必填", Boolean.TYPE); + String getId(); String getGroup(); diff --git a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductPTZ.java b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductPTZ.java index 61d6503..f2aa8fa 100644 --- a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductPTZ.java +++ b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductPTZ.java @@ -26,8 +26,6 @@ public class PluginProductPTZ implements PluginProduct { private static String METADATA; - private static final String USERNAME = "user"; - private static final String PASSWORD = "psw"; private static final String FUNCTION_ID = "regular_inspection"; static { diff --git a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductRS485.java b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductRS485.java index 2b69da6..365e87f 100644 --- a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductRS485.java +++ b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/PluginProductRS485.java @@ -7,6 +7,7 @@ import org.jetlinks.core.metadata.ConfigMetadata; import org.jetlinks.core.metadata.DefaultConfigMetadata; import org.jetlinks.core.metadata.DeviceConfigScope; +import org.jetlinks.core.metadata.types.PasswordType; import org.jetlinks.core.metadata.types.StringType; import org.jetlinks.plugin.example.sdk.hc.HCNetSDK; import org.jetlinks.plugin.example.sdk.hc.NetSDKDemo; @@ -31,13 +32,13 @@ public class PluginProductRS485 implements PluginProduct { private static String METADATA; - private static final String USERNAME = "user"; - private static final String PASSWORD = "psw"; private static final String DW_CHANNEL = "dwChannel"; private static final String FUNCTION_ID = "monthly_record"; private static final ConfigMetadata deviceConfigMetadata = new DefaultConfigMetadata("设备配置", "设备接入配置") - .add(DW_CHANNEL, "通道号", new StringType(), DeviceConfigScope.device); + .add(DW_CHANNEL, "通道号", new StringType(), DeviceConfigScope.device) + .add(USERNAME, "用户名", new StringType().expand(required.value(true)), DeviceConfigScope.device) + .add(PASSWORD, "密码", new PasswordType().expand(required.value(true)), DeviceConfigScope.device); private static final ConfigMetadata productConfigMetadata = new DefaultConfigMetadata("产品配置", "设备接入配置") .add(DW_CHANNEL, "通道号", new StringType(), DeviceConfigScope.product); diff --git a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/SdkDevicePlugin.java b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/SdkDevicePlugin.java index 565d3c0..5b65349 100644 --- a/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/SdkDevicePlugin.java +++ b/plugin-examples/hc-net-sdk/src/main/java/org/jetlinks/plugin/example/sdk/SdkDevicePlugin.java @@ -36,6 +36,8 @@ import java.util.Map; import java.util.stream.Collectors; +import static org.jetlinks.plugin.example.sdk.PluginProduct.*; + /** * 输入描述. * @@ -46,11 +48,8 @@ public class SdkDevicePlugin extends DeviceGatewayPlugin { static final String IP = "ip"; static final String PORT = "port"; - static final String USERNAME = "user"; - static final String PASSWORD = "psw"; static final String USER_ID = "user_id"; - public static final ConfigKey required = ConfigKey.of("required", "是否必填", Boolean.TYPE); private static final NetSDKDemo sdk = new NetSDKDemo(); public static final Map pluginProducts = new HashMap<>(); @@ -73,9 +72,6 @@ public Mono getDeviceConfigMetadata(String productId) { return Mono .justOrEmpty(pluginProducts.get(productId)) .mapNotNull(PluginProduct::getDeviceConfigMetadata) - .map(configMetadata -> ((DefaultConfigMetadata) configMetadata) - .add(USERNAME, "用户名", new StringType().expand(required.value(true)), DeviceConfigScope.device) - .add(PASSWORD, "密码", new PasswordType().expand(required.value(true)), DeviceConfigScope.device)) .defaultIfEmpty(new DefaultConfigMetadata() .add(USERNAME, "用户名", new StringType().expand(required.value(true)), DeviceConfigScope.device) .add(PASSWORD, "密码", new PasswordType().expand(required.value(true)), DeviceConfigScope.device))