Skip to content

Commit

Permalink
Merge pull request #6 from kyouji/master
Browse files Browse the repository at this point in the history
fix(插件): 修复默认配置每次重复添加的问题
  • Loading branch information
zhou-hao authored Jun 30, 2023
2 parents 5768ef2 + b869b61 commit 94e7309
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +16,10 @@
*/
public interface PluginProduct {

String USERNAME = "user";
String PASSWORD = "psw";
ConfigKey<Boolean> required = ConfigKey.of("required", "是否必填", Boolean.TYPE);

String getId();

String getGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.Map;
import java.util.stream.Collectors;

import static org.jetlinks.plugin.example.sdk.PluginProduct.*;

/**
* 输入描述.
*
Expand All @@ -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<Boolean> required = ConfigKey.of("required", "是否必填", Boolean.TYPE);
private static final NetSDKDemo sdk = new NetSDKDemo();
public static final Map<String, PluginProduct> pluginProducts = new HashMap<>();

Expand All @@ -73,9 +72,6 @@ public Mono<ConfigMetadata> 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))
Expand Down

0 comments on commit 94e7309

Please sign in to comment.