From 81fd5bc202611267f51c01d2f86523c06ffeb365 Mon Sep 17 00:00:00 2001 From: jay <75509151@qq.com> Date: Mon, 17 Jul 2023 16:25:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8B=E5=8F=91=E6=95=B0=E6=8D=AE-?= =?UTF-8?q?=E6=97=A0tag=E5=AF=BC=E8=87=B4=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/iotkit/comps/DeviceComponentManager.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java index d088c94e..3c72ebd2 100755 --- a/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java +++ b/iot-components/iot-component-server/src/main/java/cc/iotkit/comps/DeviceComponentManager.java @@ -46,10 +46,12 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.TimeUnit; @Slf4j @@ -126,7 +128,7 @@ public class DeviceComponentManager { scriptEngine = ScriptEngineFactory.getScriptEngine(component.getScriptTyp()); String componentScript = FileUtils.readFileToString(path. - resolve(ProtocolComponent.SCRIPT_FILE_NAME).toFile(), "UTF-8"); + resolve(ProtocolComponent.SCRIPT_FILE_NAME).toFile(), StandardCharsets.UTF_8); componentInstance.setScript(componentScript); register(id, componentInstance); } catch (IOException e) { @@ -141,7 +143,7 @@ public class DeviceComponentManager { // 从文件方式内容 Path converterPath = componentConfig.getConverterFilePath(component.getConverter()); String converterScript = FileUtils.readFileToString(converterPath. - resolve(ProtocolConverter.SCRIPT_FILE_NAME).toFile(), "UTF-8"); + resolve(ProtocolConverter.SCRIPT_FILE_NAME).toFile(), StandardCharsets.UTF_8); // scriptConverter.setScript(protocolConvert.getScript()); // 从数据库加载,以后可以加版本号 scriptConverter.setScript(converterScript); @@ -224,7 +226,11 @@ public class DeviceComponentManager { //构建必要的设备信息 Map tag = new HashMap<>(); - deviceInfo.getTag().forEach((k, v) -> tag.put(k, v.getValue())); + Map tagMap = deviceInfo.getTag(); + if(Objects.nonNull(tagMap) && !tagMap.isEmpty()){ + tagMap.forEach((k, v) -> tag.put(k, v.getValue())); + } + Device device = new Device(deviceInfo.getDeviceId(), deviceInfo.getModel(), deviceInfo.getProperty(),