Skip to content

Commit 2716873

Browse files
committed
add OneNet offline histroy class
1 parent 564d5e6 commit 2716873

File tree

7 files changed

+75
-70
lines changed

7 files changed

+75
-70
lines changed

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/MobileDeviceDataService.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import iot.technology.client.toolkit.common.utils.JsonUtils;
2525
import iot.technology.client.toolkit.common.utils.StringUtils;
2626
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
27-
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobCachedCommandResponse;
27+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.OneNetCachedCommandResponse;
2828
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataResponse;
2929
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataResponse;
3030

@@ -110,43 +110,4 @@ public MobDeviceHisDataResponse getHisDataPoints(MobileConfigDomain config, Stri
110110
}
111111
}
112112

113-
114-
public MobCachedCommandResponse getCachedCommandList(MobileConfigDomain config, String imei,
115-
String startTime, String endTime,
116-
Integer pageNo, Integer pageSize) {
117-
MobCachedCommandResponse mobCachedCommandResponse = new MobCachedCommandResponse();
118-
try {
119-
HttpRequestEntity entity = new HttpRequestEntity();
120-
entity.setType(NBTypeEnum.MOBILE.getValue());
121-
entity.setUrl(MobileSettings.MOBILE_CACHED_COMMAND_LIST);
122-
Map<String, String> headerMap = getHeaderMap(config);
123-
entity.setHeaders(headerMap);
124-
125-
Map<String, String> params = new HashMap<>();
126-
params.put("imei", imei);
127-
params.put("start", startTime);
128-
params.put("end", endTime);
129-
params.put("page", pageNo + "");
130-
params.put("per_page", pageSize + "");
131-
entity.setParams(params);
132-
HttpResponseEntity response = HttpRequestExecutor.executeGet(entity);
133-
if (StringUtils.isNotBlank(response.getBody())) {
134-
mobCachedCommandResponse = JsonUtils.jsonToObject(response.getBody(), MobCachedCommandResponse.class);
135-
if (mobCachedCommandResponse.getErrno() == 0) {
136-
mobCachedCommandResponse.setSuccess(Boolean.TRUE);
137-
} else {
138-
System.out.format(ColorUtils.redError(mobCachedCommandResponse.getError()));
139-
mobCachedCommandResponse.setSuccess(Boolean.FALSE);
140-
}
141-
} else {
142-
mobCachedCommandResponse.setSuccess(Boolean.FALSE);
143-
System.out.format(config.getProductId() + ColorUtils.redError(" getCachedCommandList failed!"));
144-
}
145-
return mobCachedCommandResponse;
146-
} catch (Exception e) {
147-
mobCachedCommandResponse.setSuccess(Boolean.FALSE);
148-
System.out.format(config.getProductId() + ColorUtils.redError(" getCachedCommandList failed!"));
149-
return mobCachedCommandResponse;
150-
}
151-
}
152113
}

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/OneNetService.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package iot.technology.client.toolkit.nb.service.mobile;
22

3+
import iot.technology.client.toolkit.common.constants.MobileSettings;
34
import iot.technology.client.toolkit.common.constants.NBTypeEnum;
45
import iot.technology.client.toolkit.common.constants.OneNetSettings;
56
import iot.technology.client.toolkit.common.http.HttpRequestEntity;
@@ -9,6 +10,7 @@
910
import iot.technology.client.toolkit.common.utils.JsonUtils;
1011
import iot.technology.client.toolkit.common.utils.StringUtils;
1112
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
13+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.OneNetCachedCommandResponse;
1214
import iot.technology.client.toolkit.nb.service.mobile.domain.action.device.*;
1315
import iot.technology.client.toolkit.nb.service.mobile.domain.settings.OneNetRespCodeEnum;
1416

@@ -215,4 +217,43 @@ public OneNetDeviceListResponse list(MobileConfigDomain config, OneNetDeviceList
215217
}
216218
}
217219

220+
public OneNetCachedCommandResponse getCachedCommandList(MobileConfigDomain config, String imei,
221+
String startTime, String endTime,
222+
Integer pageNo, Integer pageSize) {
223+
OneNetCachedCommandResponse oneNetCachedCommandResponse = new OneNetCachedCommandResponse();
224+
try {
225+
HttpRequestEntity entity = new HttpRequestEntity();
226+
entity.setType(NBTypeEnum.MOBILE.getValue());
227+
entity.setUrl(OneNetSettings.HISTORY_OFFLINE_COMMAND_URL);
228+
Map<String, String> headerMap = getHeaderMap(config);
229+
entity.setHeaders(headerMap);
230+
231+
Map<String, String> params = new HashMap<>();
232+
params.put("imei", imei);
233+
params.put("start", startTime);
234+
params.put("end", endTime);
235+
params.put("page", pageNo + "");
236+
params.put("per_page", pageSize + "");
237+
entity.setParams(params);
238+
HttpResponseEntity response = HttpRequestExecutor.executeGet(entity);
239+
if (StringUtils.isNotBlank(response.getBody())) {
240+
oneNetCachedCommandResponse = JsonUtils.jsonToObject(response.getBody(), OneNetCachedCommandResponse.class);
241+
if (oneNetCachedCommandResponse.getCode().equals(OneNetRespCodeEnum.SUCCESS.getCode())) {
242+
oneNetCachedCommandResponse.setSuccess(Boolean.TRUE);
243+
} else {
244+
System.out.format(ColorUtils.redError(oneNetCachedCommandResponse.getMsg()));
245+
oneNetCachedCommandResponse.setSuccess(Boolean.FALSE);
246+
}
247+
} else {
248+
oneNetCachedCommandResponse.setSuccess(Boolean.FALSE);
249+
System.out.format(config.getProductId() + ColorUtils.redError(" getCachedCommandList failed!"));
250+
}
251+
return oneNetCachedCommandResponse;
252+
} catch (Exception e) {
253+
oneNetCachedCommandResponse.setSuccess(Boolean.FALSE);
254+
System.out.format(config.getProductId() + ColorUtils.redError(" getCachedCommandList failed!"));
255+
return oneNetCachedCommandResponse;
256+
}
257+
}
258+
218259
}

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/domain/action/data/MobCachedCommandBody.java renamed to toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/domain/action/data/OneNetCachedCommandBody.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
*/
1616
package iot.technology.client.toolkit.nb.service.mobile.domain.action.data;
1717

18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
1820
import java.io.Serializable;
1921
import java.util.List;
2022

2123
/**
2224
* @author mushuwei
2325
*/
24-
public class MobCachedCommandBody implements Serializable {
26+
public class OneNetCachedCommandBody implements Serializable {
2527

28+
@JsonProperty("total_count")
2629
private Integer totalCount;
2730

28-
private List<MobCachedCommandItem> items;
31+
private List<OneNetCachedCommandItem> items;
2932

3033
public Integer getTotalCount() {
3134
return totalCount;
@@ -35,11 +38,11 @@ public void setTotalCount(Integer totalCount) {
3538
this.totalCount = totalCount;
3639
}
3740

38-
public List<MobCachedCommandItem> getItems() {
41+
public List<OneNetCachedCommandItem> getItems() {
3942
return items;
4043
}
4144

42-
public void setItems(List<MobCachedCommandItem> items) {
45+
public void setItems(List<OneNetCachedCommandItem> items) {
4346
this.items = items;
4447
}
4548
}

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/domain/action/data/MobCachedCommandItem.java renamed to toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/domain/action/data/OneNetCachedCommandItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* @author mushuwei
2424
*/
25-
public class MobCachedCommandItem implements Serializable {
25+
public class OneNetCachedCommandItem implements Serializable {
2626

2727
@JsonProperty("cmd_uuid")
2828
private String cmdUuid;

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/domain/action/data/MobCachedCommandResponse.java renamed to toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/mobile/domain/action/data/OneNetCachedCommandResponse.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
*/
1616
package iot.technology.client.toolkit.nb.service.mobile.domain.action.data;
1717

18-
import iot.technology.client.toolkit.nb.service.mobile.domain.BaseMobileResponse;
18+
import iot.technology.client.toolkit.nb.service.mobile.domain.BaseOneNetResponse;
1919

2020
/**
2121
* @author mushuwei
2222
*/
23-
public class MobCachedCommandResponse extends BaseMobileResponse {
23+
public class OneNetCachedCommandResponse extends BaseOneNetResponse {
2424

25-
private MobCachedCommandBody data;
25+
private OneNetCachedCommandBody data;
2626

27-
public MobCachedCommandBody getData() {
27+
public OneNetCachedCommandBody getData() {
2828
return data;
2929
}
3030

31-
public void setData(MobCachedCommandBody data) {
31+
public void setData(OneNetCachedCommandBody data) {
3232
this.data = data;
3333
}
3434
}

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/MobileBizService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final List<TkProcessor> getTkProcessorList() {
4242
tkProcessorList.add(new OneNetUpdateDeviceProcessor());
4343
tkProcessorList.add(new OneNetHelpProcessor());
4444
tkProcessorList.add(new MobLogDeviceDataProcessor());
45-
tkProcessorList.add(new MobCommandDataDeviceProcessor());
45+
tkProcessorList.add(new OneNetCommandDataDeviceProcessor());
4646
return tkProcessorList;
4747
}
4848

toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/mobile/MobCommandDataDeviceProcessor.java renamed to toolkit-nbiot/src/main/java/iot/technology/client/toolkit/nb/service/processor/mobile/OneNetCommandDataDeviceProcessor.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import iot.technology.client.toolkit.common.utils.ColorUtils;
2525
import iot.technology.client.toolkit.common.utils.DateUtils;
2626
import iot.technology.client.toolkit.common.utils.StringUtils;
27-
import iot.technology.client.toolkit.nb.service.mobile.MobileDeviceDataService;
27+
import iot.technology.client.toolkit.nb.service.mobile.OneNetService;
2828
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
29-
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobCachedCommandItem;
30-
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobCachedCommandResponse;
29+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.OneNetCachedCommandItem;
30+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.OneNetCachedCommandResponse;
3131
import iot.technology.client.toolkit.nb.service.processor.MobProcessContext;
3232
import org.apache.commons.cli.*;
3333

@@ -37,9 +37,9 @@
3737
/**
3838
* @author mushuwei
3939
*/
40-
public class MobCommandDataDeviceProcessor extends TkAbstractProcessor implements TkProcessor {
40+
public class OneNetCommandDataDeviceProcessor extends TkAbstractProcessor implements TkProcessor {
4141

42-
private final MobileDeviceDataService mobileDeviceDataService = new MobileDeviceDataService();
42+
private final OneNetService oneNetService = new OneNetService();
4343

4444
@Override
4545
public boolean supports(ProcessContext context) {
@@ -140,32 +140,32 @@ public void handle(ProcessContext context) {
140140
sb.append(ColorUtils.redError("command parse failed!")).append(StringUtils.lineSeparator);
141141
System.out.println(sb);
142142
}
143-
MobCachedCommandResponse
144-
mobCachedCommandResponse = mobileDeviceDataService.getCachedCommandList(
143+
OneNetCachedCommandResponse
144+
oneNetCachedCommandResponse = oneNetService.getCachedCommandList(
145145
mobileConfigDomain, imei, startTime, endTime, pageNo, pageSize);
146-
if (mobCachedCommandResponse.isSuccess()
147-
&& mobCachedCommandResponse.getData() != null
148-
&& !mobCachedCommandResponse.getData().getItems().isEmpty()) {
149-
List<MobCachedCommandItem> items = mobCachedCommandResponse.getData().getItems();
146+
if (oneNetCachedCommandResponse.isSuccess()
147+
&& oneNetCachedCommandResponse.getData() != null
148+
&& !oneNetCachedCommandResponse.getData().getItems().isEmpty()) {
149+
List<OneNetCachedCommandItem> items = oneNetCachedCommandResponse.getData().getItems();
150150
String asciiTable = AsciiTable.getTable(AsciiTable.NO_BORDERS, items, Arrays.asList(
151151
new Column().header("cmdUuid").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
152-
MobCachedCommandItem::getCmdUuid),
152+
OneNetCachedCommandItem::getCmdUuid),
153153
new Column().header("type").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
154-
MobCachedCommandItem::getType),
154+
OneNetCachedCommandItem::getType),
155155
new Column().header("createTime").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
156-
MobCachedCommandItem::getCreateTime),
156+
OneNetCachedCommandItem::getCreateTime),
157157
new Column().header("validTime").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
158-
MobCachedCommandItem::getValidTime),
158+
OneNetCachedCommandItem::getValidTime),
159159
new Column().header("expiredTime").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
160-
MobCachedCommandItem::getExpiredTime),
160+
OneNetCachedCommandItem::getExpiredTime),
161161
new Column().header("sendTime").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
162-
MobCachedCommandItem::getSendTime),
162+
OneNetCachedCommandItem::getSendTime),
163163
new Column().header("sendStatus").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
164164
s -> String.valueOf(s.getSendStatus())),
165165
new Column().header("confirmTime").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
166-
MobCachedCommandItem::getConfirmTime),
166+
OneNetCachedCommandItem::getConfirmTime),
167167
new Column().header("confirmStatus").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
168-
MobCachedCommandItem::getConfirmStatus),
168+
OneNetCachedCommandItem::getConfirmStatus),
169169
new Column().header("remain").headerAlign(HorizontalAlign.CENTER).dataAlign(HorizontalAlign.LEFT).with(
170170
s -> String.valueOf(s.getRemain()))
171171
));

0 commit comments

Comments
 (0)