Skip to content

Commit

Permalink
improve list command and show command
Browse files Browse the repository at this point in the history
  • Loading branch information
sanshengshui committed Apr 4, 2023
1 parent e9ea9c2 commit 8251153
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void handle(ProcessContext context) {
// list telecom nb-iot devices
sb.append(ColorUtils.cyanAnnotation("list: " + bundle.getString("nb.operation.list.desc")))
.append(StringUtils.lineSeparator());
sb.append(" usage: list pageNo searchValue").append(StringUtils.lineSeparator());
sb.append(" usage: list searchValue pageNo").append(StringUtils.lineSeparator());
sb.append(StringUtils.lineSeparator());

// get telecom nb-iot device detail info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.freva.asciitable.HorizontalAlign;
import com.github.freva.asciitable.OverflowBehaviour;
import iot.technology.client.toolkit.common.rule.ProcessContext;
import iot.technology.client.toolkit.common.rule.TkAbstractProcessor;
import iot.technology.client.toolkit.common.rule.TkProcessor;
import iot.technology.client.toolkit.common.utils.ColorUtils;
import iot.technology.client.toolkit.nb.service.mobile.MobileDeviceService;
Expand All @@ -33,9 +34,18 @@
import java.util.List;

/**
* usage:
* <p>
* 1、list: print first page device list
* <p>
* 2、list pageNo: print pageNo device list
* <p>
* 3、list searchValue pageNo: print searchValue pageNo device list
* <p>
*
* @author mushuwei
*/
public class MobListDeviceProcessor implements TkProcessor {
public class MobListDeviceProcessor extends TkAbstractProcessor implements TkProcessor {

private final MobileDeviceService mobileDeviceService = new MobileDeviceService();

Expand All @@ -47,15 +57,29 @@ public boolean supports(ProcessContext context) {
@Override
public void handle(ProcessContext context) {
List<String> arguArgs = List.of(context.getData().split(" "));
if (arguArgs.size() > 3 || arguArgs.size() < 2) {
if (arguArgs.size() > 3) {
System.out.format(ColorUtils.blackBold("argument:%s is illegal"), context.getData());
System.out.format(" " + "%n");
return;
}
Integer pageNo = 1;
String searchValue = null;
Integer pageNo = Integer.valueOf(arguArgs.get(1));
if (arguArgs.size() > 2) {
searchValue = arguArgs.get(2);
if (arguArgs.size() == 1) {
}
if (arguArgs.size() == 2) {
String pageNoStr = arguArgs.get(1);
if (!validateLimit(pageNoStr)) {
return;
}
pageNo = Integer.parseInt(pageNoStr);
}
if (arguArgs.size() == 3) {
searchValue = arguArgs.get(1);
String pageNoStr = arguArgs.get(2);
if (!validateLimit(pageNoStr)) {
return;
}
pageNo = Integer.parseInt(pageNoStr);
}
MobProcessContext mobProcessContext = (MobProcessContext) context;
MobileConfigDomain mobileConfigDomain = mobProcessContext.getMobileConfigDomain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void handle(ProcessContext context) {
// list telecom nb-iot devices
sb.append(ColorUtils.cyanAnnotation("list: " + bundle.getString("nb.operation.list.desc")))
.append(StringUtils.lineSeparator());
sb.append(" usage: list pageNo searchValue").append(StringUtils.lineSeparator());
sb.append(" usage: list searchValue pageNo").append(StringUtils.lineSeparator());
sb.append(StringUtils.lineSeparator());

// get telecom nb-iot device detail info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@
import java.util.List;

/**
* 1、list
* usage:
* <p>
* 2、list 1
* 1、list: print first page device list
* <p>
* 2、list pageNo: print pageNo device list
* <p>
* 3、list searchValue pageNo: print searchValue pageNo device list
* <p>
* 3、list searchValue 1
*
* @author mushuwei
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,29 @@ public class TelQueryDeviceByImeiResponse extends BaseTelResponse {
private TelQueryDeviceByImeiBody result;

public void printToConsole() {
System.out.format("deviceId: " + ColorUtils.blackBold(result.getDeviceId()) + "%n");
System.out.format("deviceName: " + ColorUtils.blackBold(result.getDeviceName()) + "%n");
System.out.format("productId: " + ColorUtils.blackBold(String.valueOf(result.getProductId())) + "%n");
System.out.format("imei: " + ColorUtils.blackBold(result.getImei()) + "%n");
System.out.format("deviceStatus: " + ColorUtils.blackBold(TelDeviceStatusEnum.type(result.getDeviceStatus())) + "%n");
System.out.format(
"imsi: " + (Objects.nonNull(result.getImsi()) ? ColorUtils.blackBold(String.valueOf(result.getImsi())) : "") + "%n");
System.out.format("firmwareVersion: " +
(Objects.nonNull(result.getFirmwareVersion()) ? ColorUtils.blackBold(result.getFirmwareVersion()) : "") + "%n");
System.out.format("autoObserver: " + ColorUtils.blackBold(TelAutoObserverEnum.type(result.getAutoObserver())) + "%n");
System.out.format("netStatus: " + ColorUtils.blackBold(TelNetStatusEnum.type(result.getNetStatus())) + "%n");
System.out.format("onlineAt: " +
(Objects.nonNull(result.getOnlineAt()) ? ColorUtils.blackBold(DateUtils.timestampToFormatterTime(result.getOnlineAt())) :
"") + "%n");
System.out.format("offlineAt: " +
(Objects.nonNull(result.getOfflineAt()) ? ColorUtils.blackBold(DateUtils.timestampToFormatterTime(result.getOfflineAt())) :
"") + "%n");
if (Objects.nonNull(result)) {
System.out.format("deviceId: " + ColorUtils.blackBold(result.getDeviceId()) + "%n");
System.out.format("deviceName: " + ColorUtils.blackBold(result.getDeviceName()) + "%n");
System.out.format("productId: " + ColorUtils.blackBold(String.valueOf(result.getProductId())) + "%n");
System.out.format("imei: " + ColorUtils.blackBold(result.getImei()) + "%n");
System.out.format("deviceStatus: " + ColorUtils.blackBold(TelDeviceStatusEnum.type(result.getDeviceStatus())) + "%n");
System.out.format(
"imsi: " + (Objects.nonNull(result.getImsi()) ? ColorUtils.blackBold(String.valueOf(result.getImsi())) : "") + "%n");
System.out.format("firmwareVersion: " +
(Objects.nonNull(result.getFirmwareVersion()) ? ColorUtils.blackBold(result.getFirmwareVersion()) : "") + "%n");
System.out.format("autoObserver: " + ColorUtils.blackBold(TelAutoObserverEnum.type(result.getAutoObserver())) + "%n");
System.out.format("netStatus: " + ColorUtils.blackBold(TelNetStatusEnum.type(result.getNetStatus())) + "%n");
System.out.format("onlineAt: " +
(Objects.nonNull(result.getOnlineAt()) ? ColorUtils.blackBold(DateUtils.timestampToFormatterTime(result.getOnlineAt())) :
"") + "%n");
System.out.format("offlineAt: " +
(Objects.nonNull(result.getOfflineAt()) ? ColorUtils.blackBold(DateUtils.timestampToFormatterTime(result.getOfflineAt())) :
"") + "%n");
} else {
System.out.println("this product does not have this imei!");
}


}

public TelQueryDeviceByImeiBody getResult() {
Expand Down

0 comments on commit 8251153

Please sign in to comment.