From 1e3ca4d390a1985390f44dd80afd5edfe3fdc150 Mon Sep 17 00:00:00 2001 From: sanshengshui Date: Wed, 8 Nov 2023 23:10:49 +0800 Subject: [PATCH 1/4] :poop: improve user experience --- toolkit-app/src/main/resources/i18n/messages_zh.properties | 2 +- .../client/toolkit/nb/service/node/MobAppConfigNode.java | 2 +- .../client/toolkit/nb/service/node/NbLwM2MConfigNode.java | 1 - .../client/toolkit/nb/service/node/NbTelecomAppConfigNode.java | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/toolkit-app/src/main/resources/i18n/messages_zh.properties b/toolkit-app/src/main/resources/i18n/messages_zh.properties index c7adb751..858c3f0c 100644 --- a/toolkit-app/src/main/resources/i18n/messages_zh.properties +++ b/toolkit-app/src/main/resources/i18n/messages_zh.properties @@ -191,7 +191,7 @@ nb.cmd.endTime.desc=\u67e5\u8be2\u8bbe\u5907\u65e5\u5fd7\u6570\u636e\u5217\u8868 nbType.prompt=\u8bf7\u9009\u62e9 Nb-IoT \u5e73\u53f0 nb.new.config.desc=\u589e\u52a0\u4e00\u4e2a\u65b0\u7684\u914d\u7f6e nb.select.config.error=\u8bf7\u8f93\u51650,1,2...\u6216new -nbTelecomAppConfig.prompt=\u8bf7\u9009\u62e9\u60a8\u7684\u79fb\u52a8\u5e94\u7528\u914d\u7f6e: +nbTelecomAppConfig.prompt=\u8bf7\u9009\u62e9\u60a8\u7684\u7535\u4fe1\u5e94\u7528\u914d\u7f6e: nbTelProjectName.prompt=\u8bf7\u8f93\u5165\u4f60\u7684\u9879\u76ee\u540d\u79f0: nbTelAppSecret.prompt=\u8bf7\u8f93\u5165\u4f60\u7684\u5e94\u7528\u7684 appSecret: nbTelAppKey.prompt=\u8bf7\u8f93\u5165\u4f60\u7684\u5e94\u7528\u7684 appKey: diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/MobAppConfigNode.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/MobAppConfigNode.java index 5c69052c..4afcc7c7 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/MobAppConfigNode.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/MobAppConfigNode.java @@ -47,7 +47,7 @@ public boolean check(NodeContext context) { context.setCheck(true); return true; } - System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error"))); + System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error")) + "%n"); context.setCheck(false); return false; } diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbLwM2MConfigNode.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbLwM2MConfigNode.java index f55000c9..fce4132d 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbLwM2MConfigNode.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbLwM2MConfigNode.java @@ -8,7 +8,6 @@ import iot.technology.client.toolkit.common.utils.ColorUtils; import iot.technology.client.toolkit.common.utils.JsonUtils; import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting; -import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings; import java.util.List; import java.util.Objects; diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbTelecomAppConfigNode.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbTelecomAppConfigNode.java index 99487e16..ea7f6242 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbTelecomAppConfigNode.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/node/NbTelecomAppConfigNode.java @@ -46,7 +46,7 @@ public boolean check(NodeContext context) { context.setCheck(true); return true; } - System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error"))); + System.out.format(ColorUtils.redError(bundle.getString("nb.select.config.error")) + "%n"); context.setCheck(false); return false; } From c7042c2f76fe2609f84fd8216161562a3bced63f Mon Sep 17 00:00:00 2001 From: sanshengshui Date: Thu, 9 Nov 2023 23:20:30 +0800 Subject: [PATCH 2/4] :wrench: add lwm2m settings operations --- .../nb/command/sub/NbSettingsCommand.java | 2 -- .../lwm2m/domain/Lwm2mConfigSetting.java | 10 +++++++ .../settings/NbSettingsDelProcessor.java | 5 ++++ .../settings/NbSettingsListProcessor.java | 28 +++++++++++++++++++ .../settings/NbSettingsShowProcessor.java | 17 +++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java index 7cda4ccc..2943dec3 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java @@ -21,7 +21,6 @@ import iot.technology.client.toolkit.common.rule.TkNode; import iot.technology.client.toolkit.common.rule.TkProcessor; import iot.technology.client.toolkit.common.utils.ObjectUtils; -import iot.technology.client.toolkit.common.utils.StringUtils; import iot.technology.client.toolkit.nb.service.NbBizService; import iot.technology.client.toolkit.nb.service.NbConfigSettingsDomain; import iot.technology.client.toolkit.nb.service.NbRuleChainProcessor; @@ -58,7 +57,6 @@ ) public class NbSettingsCommand implements Callable { - private final NbBizService bizService = new NbBizService(); private final NbRuleChainProcessor ruleChain = new NbRuleChainProcessor(); private final Map processor = ruleChain.getNbRuleChainProcessor(); diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/lwm2m/domain/Lwm2mConfigSetting.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/lwm2m/domain/Lwm2mConfigSetting.java index 9c55cede..b71a458a 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/lwm2m/domain/Lwm2mConfigSetting.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/lwm2m/domain/Lwm2mConfigSetting.java @@ -62,6 +62,8 @@ public class Lwm2mConfigSetting implements Serializable { private String lwm2mCertUsage; + private String serial; + public String getLwm2mServer() { return lwm2mServer; @@ -222,4 +224,12 @@ public String getLwm2mCertUsage() { public void setLwm2mCertUsage(String lwm2mCertUsage) { this.lwm2mCertUsage = lwm2mCertUsage; } + + public String getSerial() { + return serial; + } + + public void setSerial(String serial) { + this.serial = serial; + } } diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsDelProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsDelProcessor.java index d9188611..f83b795e 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsDelProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsDelProcessor.java @@ -64,5 +64,10 @@ public void handle(ProcessContext context) { configStringList.remove(configStringList.get(serial)); FileUtils.updateAllFileContents(SystemConfigConst.SYS_NB_MOBILE_PRODUCT_FILE_NAME, configStringList); } + if (nbSettingsContext.getNbType().equals(NBTypeEnum.LWM2M.getValue())) { + List configStringList = FileUtils.getDataFromFile(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME); + configStringList.remove(configStringList.get(serial)); + FileUtils.updateAllFileContents(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME, configStringList); + } } } diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsListProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsListProcessor.java index 7d91b708..b56e9e65 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsListProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsListProcessor.java @@ -24,6 +24,7 @@ import iot.technology.client.toolkit.common.rule.TkProcessor; import iot.technology.client.toolkit.common.utils.FileUtils; import iot.technology.client.toolkit.common.utils.JsonUtils; +import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting; import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings; import iot.technology.client.toolkit.nb.service.processor.NbSettingsContext; import iot.technology.client.toolkit.nb.service.telecom.domain.settings.TelProjectSettings; @@ -103,5 +104,32 @@ public void handle(ProcessContext context) { System.out.println(tableInfo); } } + if (nbSettingsContext.getNbType().equals(NBTypeEnum.LWM2M.getValue())) { + List configStringList = FileUtils.getDataFromFile(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME); + if (!configStringList.isEmpty()) { + AtomicInteger cal = new AtomicInteger(); + List lwm2mConfigSettings = new ArrayList<>(); + configStringList.stream() + .map(s -> JsonUtils.jsonToObject(s, Lwm2mConfigSetting.class)) + .filter(Objects::nonNull) + .forEach(s -> { + s.setSerial(cal + ""); + lwm2mConfigSettings.add(s); + cal.getAndIncrement(); + }); + String tableInfo = AsciiTable.getTable(AsciiTable.BASIC_ASCII_NO_OUTSIDE_BORDER, lwm2mConfigSettings, Arrays.asList( + new Column().header("Serial").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with( + Lwm2mConfigSetting::getSerial), + new Column().header("Endpoint").minWidth(10).headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT) + .with(Lwm2mConfigSetting::getLwm2mEndpoint), + new Column().header("ServerAndPort").minWidth(10).headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT) + .with(Lwm2mConfigSetting::getServerAndPort), + new Column().header("LifeTime").minWidth(10).headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT) + .with(Lwm2mConfigSetting::getLwm2mLifeTime) + )); + System.out.println(tableInfo); + } + + } } } diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsShowProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsShowProcessor.java index cb546ad9..94dce7a6 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsShowProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/settings/NbSettingsShowProcessor.java @@ -24,6 +24,7 @@ import iot.technology.client.toolkit.common.utils.FileUtils; import iot.technology.client.toolkit.common.utils.JsonUtils; import iot.technology.client.toolkit.common.utils.ObjectUtils; +import iot.technology.client.toolkit.nb.service.lwm2m.domain.Lwm2mConfigSetting; import iot.technology.client.toolkit.nb.service.mobile.domain.settings.MobProjectSettings; import iot.technology.client.toolkit.nb.service.processor.NbSettingsContext; import iot.technology.client.toolkit.nb.service.telecom.domain.settings.TelProjectSettings; @@ -74,5 +75,21 @@ public void handle(ProcessContext context) { System.out.format("ProductId: " + mobProjectSettings.getProductId() + "%n"); System.out.format("AccessKey: " + mobProjectSettings.getAccessKey() + "%n"); } + if (nbSettingsContext.getNbType().equals(NBTypeEnum.LWM2M.getValue())) { + List configStringList = FileUtils.getDataFromFile(SystemConfigConst.SYS_NB_LWM2M_SETTINGS_FILE_NAME); + var lwm2mConfigSetting = JsonUtils.jsonToObject(configStringList.get(serial), Lwm2mConfigSetting.class); + System.out.format("Endpoint: " + lwm2mConfigSetting.getLwm2mEndpoint() + "%n"); + System.out.format("ServerAndPort: " + lwm2mConfigSetting.getServerAndPort() + "%n"); + System.out.format("LifeTime: " + lwm2mConfigSetting.getLwm2mLifeTime() + "%n"); + System.out.format("BootstrapServer: " + lwm2mConfigSetting.getLwm2mBootstrapServer() + "%n"); + System.out.format("PskIdentity: " + lwm2mConfigSetting.getLwm2mPskIdentity() + "%n"); + System.out.format("PskShareKey: " + lwm2mConfigSetting.getLwm2mPskShareKey() + "%n"); + System.out.format("ClientPrivateKey: " + lwm2mConfigSetting.getLwm2mClientPrivateKey() + "%n"); + System.out.format("ClientPublicKey: " + lwm2mConfigSetting.getLwm2mClientPublicKey() + "%n"); + System.out.format("ServerPublicKey: " + lwm2mConfigSetting.getLwm2mServerPublicKey() + "%n"); + System.out.format("ClientCert: " + lwm2mConfigSetting.getLwm2mClientCert() + "%n"); + System.out.format("ServerCert: " + lwm2mConfigSetting.getLwm2mServerCert() + "%n"); + System.out.format("CertUsage: " + lwm2mConfigSetting.getLwm2mCertUsage() + "%n"); + } } } From 1090721ee56b4122951cbae8bb72241aa69c0106 Mon Sep 17 00:00:00 2001 From: sanshengshui Date: Thu, 16 Nov 2023 12:05:05 +0800 Subject: [PATCH 3/4] :arrow_up: update java compiler version to 21 --- pom.xml | 4 +++- toolkit-app/pom.xml | 4 ++-- toolkit-coap/pom.xml | 4 ++-- toolkit-common/pom.xml | 4 ++-- toolkit-mqtt/pom.xml | 4 ++-- toolkit-nbiot/pom.xml | 4 ++-- .../client/toolkit/nb/command/sub/NbSettingsCommand.java | 1 - .../processor/telecom/TelCommandDataDeviceProcessor.java | 6 +++--- .../nb/service/processor/telecom/TelHelpProcessor.java | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 89ba9ae5..c3948268 100644 --- a/pom.xml +++ b/pom.xml @@ -261,7 +261,7 @@ IoT Protocol Client CLI Toolkit is a client command line tool that supports multiple IoT protocols. - CoAP and MQTT protocols are currently supported. more protocols will be supported in the future. + CoAP、MQTT and LwM2M protocols are currently supported. more protocols will be supported in the future. it is written in the java language, but does not rely on the JRE environment. https://github.com/IoT-Technology/IoT-Toolkit @@ -271,6 +271,8 @@ mqtt-client coap coap-client + lwm2m + lwm2m-client https://github.com/IoT-Technology/IoT-Toolkit/wiki diff --git a/toolkit-app/pom.xml b/toolkit-app/pom.xml index 12846d4a..6c344c95 100644 --- a/toolkit-app/pom.xml +++ b/toolkit-app/pom.xml @@ -37,8 +37,8 @@ ${project.basedir}/target false - 17 - 17 + 21 + 21 utf-8 0.9.27 4.6.3 diff --git a/toolkit-coap/pom.xml b/toolkit-coap/pom.xml index 3174d4e1..5ab478f9 100644 --- a/toolkit-coap/pom.xml +++ b/toolkit-coap/pom.xml @@ -31,8 +31,8 @@ jar - 17 - 17 + 21 + 21 diff --git a/toolkit-common/pom.xml b/toolkit-common/pom.xml index 768f9305..46175630 100644 --- a/toolkit-common/pom.xml +++ b/toolkit-common/pom.xml @@ -30,8 +30,8 @@ jar - 17 - 17 + 21 + 21 diff --git a/toolkit-mqtt/pom.xml b/toolkit-mqtt/pom.xml index 716ba8f3..2bbe7ad0 100644 --- a/toolkit-mqtt/pom.xml +++ b/toolkit-mqtt/pom.xml @@ -30,8 +30,8 @@ IoT Technology ToolKit MQTT - 17 - 17 + 21 + 21 diff --git a/toolkit-nbiot/pom.xml b/toolkit-nbiot/pom.xml index 57a9b821..c3802a36 100644 --- a/toolkit-nbiot/pom.xml +++ b/toolkit-nbiot/pom.xml @@ -31,8 +31,8 @@ IoT Technology Toolkit NB-IoT - 17 - 17 + 21 + 21 UTF-8 diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java index 2943dec3..be451e09 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/command/sub/NbSettingsCommand.java @@ -21,7 +21,6 @@ import iot.technology.client.toolkit.common.rule.TkNode; import iot.technology.client.toolkit.common.rule.TkProcessor; import iot.technology.client.toolkit.common.utils.ObjectUtils; -import iot.technology.client.toolkit.nb.service.NbBizService; import iot.technology.client.toolkit.nb.service.NbConfigSettingsDomain; import iot.technology.client.toolkit.nb.service.NbRuleChainProcessor; import iot.technology.client.toolkit.nb.service.processor.NbSettingsContext; diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelCommandDataDeviceProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelCommandDataDeviceProcessor.java index 050b9254..98fb9bf5 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelCommandDataDeviceProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelCommandDataDeviceProcessor.java @@ -74,7 +74,7 @@ public void handle(ProcessContext context) { if (!cmd.hasOption(imeiOption)) { StringBuilder sb = new StringBuilder(); sb.append(ColorUtils.redError("imei is required")).append(StringUtils.lineSeparator); - sb.append(ColorUtils.blackBold("detail usage please enter: help log")); + sb.append(ColorUtils.blackBold("detail usage please enter: help command")); System.out.println(sb); return; } @@ -86,7 +86,7 @@ public void handle(ProcessContext context) { if (!validateParam(pageNoStr)) { StringBuilder sb = new StringBuilder(); sb.append(ColorUtils.redError("pageNo is not a number")).append(StringUtils.lineSeparator); - sb.append(ColorUtils.blackBold("detail usage please enter: help list")); + sb.append(ColorUtils.blackBold("detail usage please enter: help command")); System.out.println(sb); return; } @@ -99,7 +99,7 @@ public void handle(ProcessContext context) { if (!validateParam(pageSizeStr)) { StringBuilder sb = new StringBuilder(); sb.append(ColorUtils.redError("pageSize is not a number")).append(StringUtils.lineSeparator); - sb.append(ColorUtils.blackBold("detail usage please enter: help list")); + sb.append(ColorUtils.blackBold("detail usage please enter: help command")); System.out.println(sb); return; } diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelHelpProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelHelpProcessor.java index dee66d6c..b7652e12 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelHelpProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelHelpProcessor.java @@ -173,7 +173,7 @@ public void handle(ProcessContext context) { break; case "log": sb.append(ColorUtils.colorBold("Usage: ", "black") - + String.format("> %s %s [%s ] [%s] [%s ]", + + String.format("> %s %s [%s ] [%s ] [%s ] %s", ColorUtils.colorBold("log", "green"), ColorUtils.colorBold("-imei", "green"), ColorUtils.colorBold("-limit", "green"), From 521956d1248f438992d1bb078453a2dbaeb16463 Mon Sep 17 00:00:00 2001 From: sanshengshui Date: Fri, 17 Nov 2023 14:15:51 +0800 Subject: [PATCH 4/4] :art: improve telecom del and show subcommand --- .../telecom/TelDelDeviceByImeiProcessor.java | 10 +++++++++- .../telecom/TelShowDeviceByImeiProcessor.java | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelDelDeviceByImeiProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelDelDeviceByImeiProcessor.java index 518719ea..3e4d6829 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelDelDeviceByImeiProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelDelDeviceByImeiProcessor.java @@ -42,7 +42,15 @@ public boolean supports(ProcessContext context) { @Override public void handle(ProcessContext context) { TelProcessContext telProcessContext = (TelProcessContext) context; - String imeiListString = context.getData().substring(context.getData().indexOf(" ") + 1); + String[] arr = context.getData().split(" "); + if (arr.length < 2) { + StringBuilder sb = new StringBuilder(); + sb.append(ColorUtils.redError("imei is required")).append(StringUtils.lineSeparator); + sb.append(ColorUtils.blackBold("detail usage please enter: help del")); + System.out.println(sb); + return; + } + String imeiListString = arr[2]; if (StringUtils.isNotBlank(imeiListString)) { List imeiList = List.of(imeiListString.split(",")); TelDelDeviceByImeiResponse response = diff --git a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelShowDeviceByImeiProcessor.java b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelShowDeviceByImeiProcessor.java index fe5e4a79..afa5e53c 100644 --- a/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelShowDeviceByImeiProcessor.java +++ b/toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/telecom/TelShowDeviceByImeiProcessor.java @@ -17,6 +17,7 @@ import iot.technology.client.toolkit.common.rule.ProcessContext; import iot.technology.client.toolkit.common.rule.TkProcessor; +import iot.technology.client.toolkit.common.utils.ColorUtils; import iot.technology.client.toolkit.common.utils.StringUtils; import iot.technology.client.toolkit.nb.service.processor.TelProcessContext; import iot.technology.client.toolkit.nb.service.telecom.TelecomDeviceService; @@ -38,7 +39,15 @@ public boolean supports(ProcessContext context) { @Override public void handle(ProcessContext context) { - String imei = context.getData().substring(context.getData().indexOf(" ") + 1); + String[] arr = context.getData().split(" "); + if (arr.length < 2) { + StringBuilder sb = new StringBuilder(); + sb.append(ColorUtils.redError("imei is required")).append(StringUtils.lineSeparator); + sb.append(ColorUtils.blackBold("detail usage please enter: help show")); + System.out.println(sb); + return; + } + String imei = arr[2]; TelProcessContext telProcessContext = (TelProcessContext) context; if (StringUtils.isNotBlank(imei)) { TelQueryDeviceByImeiResponse response =