Skip to content

Commit b9206e6

Browse files
committed
add mobile device log data
1 parent 57f23d6 commit b9206e6

File tree

15 files changed

+731
-2
lines changed

15 files changed

+731
-2
lines changed

.github/workflows/release_pre.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
name: release

toolkit-app/src/main/resources/META-INF/native-image/reflection-config.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,5 +589,77 @@
589589
"allPublicClasses" : true,
590590
"allDeclaredConstructors" : true,
591591
"allPublicConstructors" : true
592+
},
593+
{
594+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataBody",
595+
"allDeclaredMethods" : true,
596+
"allPublicMethods" : true,
597+
"allDeclaredClasses" : true,
598+
"allPublicClasses" : true,
599+
"allDeclaredConstructors" : true,
600+
"allPublicConstructors" : true
601+
},
602+
{
603+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataPointsBody",
604+
"allDeclaredMethods" : true,
605+
"allPublicMethods" : true,
606+
"allDeclaredClasses" : true,
607+
"allPublicClasses" : true,
608+
"allDeclaredConstructors" : true,
609+
"allPublicConstructors" : true
610+
},
611+
{
612+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataResponse",
613+
"allDeclaredMethods" : true,
614+
"allPublicMethods" : true,
615+
"allDeclaredClasses" : true,
616+
"allPublicClasses" : true,
617+
"allDeclaredConstructors" : true,
618+
"allPublicConstructors" : true
619+
},
620+
{
621+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataStreamsBody",
622+
"allDeclaredMethods" : true,
623+
"allPublicMethods" : true,
624+
"allDeclaredClasses" : true,
625+
"allPublicClasses" : true,
626+
"allDeclaredConstructors" : true,
627+
"allPublicConstructors" : true
628+
},
629+
{
630+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataBody",
631+
"allDeclaredMethods" : true,
632+
"allPublicMethods" : true,
633+
"allDeclaredClasses" : true,
634+
"allPublicClasses" : true,
635+
"allDeclaredConstructors" : true,
636+
"allPublicConstructors" : true
637+
},
638+
{
639+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataDevicesBody",
640+
"allDeclaredMethods" : true,
641+
"allPublicMethods" : true,
642+
"allDeclaredClasses" : true,
643+
"allPublicClasses" : true,
644+
"allDeclaredConstructors" : true,
645+
"allPublicConstructors" : true
646+
},
647+
{
648+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataResponse",
649+
"allDeclaredMethods" : true,
650+
"allPublicMethods" : true,
651+
"allDeclaredClasses" : true,
652+
"allPublicClasses" : true,
653+
"allDeclaredConstructors" : true,
654+
"allPublicConstructors" : true
655+
},
656+
{
657+
"name" : "iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataStreamsBody",
658+
"allDeclaredMethods" : true,
659+
"allPublicMethods" : true,
660+
"allDeclaredClasses" : true,
661+
"allPublicClasses" : true,
662+
"allDeclaredConstructors" : true,
663+
"allPublicConstructors" : true
592664
}
593665
]

toolkit-common/src/main/java/iot/technology/client/toolkit/common/constants/MobileSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ public interface MobileSettings {
3131
String MOBILE_DEVICE_URL = MOBILE_ROOT_URL + "/devices";
3232

3333
String MOBILE_DELETE_DEVICE_BY_IMEI = MOBILE_DEVICE_URL + "/getbyimei";
34+
String MOBILE_DATA_POINTS = MOBILE_DEVICE_URL + "/datapoints";
3435
}

toolkit-common/src/main/java/iot/technology/client/toolkit/common/utils/DateUtils.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,40 @@
1616
package iot.technology.client.toolkit.common.utils;
1717

1818
import java.time.Instant;
19+
import java.time.LocalDate;
1920
import java.time.LocalDateTime;
2021
import java.time.ZoneId;
2122
import java.time.format.DateTimeFormatter;
23+
import java.util.regex.Matcher;
24+
import java.util.regex.Pattern;
2225

2326
/**
2427
* @author mushuwei
2528
*/
2629
public class DateUtils {
27-
30+
2831
private static ZoneId zoneId = ZoneId.of("Asia/Shanghai");
2932

3033
public static String timestampToFormatterTime(long timestamp) {
3134
LocalDateTime resultDateTime = Instant.ofEpochMilli(timestamp).atZone(zoneId).toLocalDateTime();
3235
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
3336
return formatter.format(resultDateTime);
3437
}
38+
39+
public static String getCurrentDayStartTimeForMob() {
40+
LocalDate today = LocalDate.now(zoneId);
41+
return today + "T" + "00:00:00";
42+
}
43+
44+
public static String getCurrentDayEndTimeForMob() {
45+
LocalDate today = LocalDate.now(zoneId);
46+
return today + "T" + "23:59:59";
47+
}
48+
49+
public static boolean mobileTimePattern(String dateTime) {
50+
String pattern = "^\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{1,2}:\\d{1,2}$";
51+
Pattern r = Pattern.compile(pattern);
52+
Matcher m = r.matcher(dateTime);
53+
return m.find() ? Boolean.TRUE : Boolean.FALSE;
54+
}
3555
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright © 2019-2023 The Toolkit Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package iot.technology.client.toolkit.nb.service.mobile;
17+
18+
import iot.technology.client.toolkit.common.constants.MobileSettings;
19+
import iot.technology.client.toolkit.common.constants.NBTypeEnum;
20+
import iot.technology.client.toolkit.common.http.HttpRequestEntity;
21+
import iot.technology.client.toolkit.common.http.HttpRequestExecutor;
22+
import iot.technology.client.toolkit.common.http.HttpResponseEntity;
23+
import iot.technology.client.toolkit.common.utils.ColorUtils;
24+
import iot.technology.client.toolkit.common.utils.JsonUtils;
25+
import iot.technology.client.toolkit.common.utils.StringUtils;
26+
import iot.technology.client.toolkit.nb.service.mobile.domain.MobileConfigDomain;
27+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceHisDataResponse;
28+
import iot.technology.client.toolkit.nb.service.mobile.domain.action.data.MobDeviceLatestDataResponse;
29+
30+
import java.util.HashMap;
31+
import java.util.Map;
32+
33+
/**
34+
* @author mushuwei
35+
*/
36+
public class MobileDeviceDataService extends AbstractMobileService {
37+
38+
public MobDeviceLatestDataResponse getLatestDataPoints(MobileConfigDomain config, String id) {
39+
MobDeviceLatestDataResponse deviceLatestDataResponse = new MobDeviceLatestDataResponse();
40+
try {
41+
HttpRequestEntity entity = new HttpRequestEntity();
42+
entity.setType(NBTypeEnum.MOBILE.getValue());
43+
entity.setUrl(MobileSettings.MOBILE_DATA_POINTS);
44+
Map<String, String> headerMap = getHeaderMap(config);
45+
entity.setHeaders(headerMap);
46+
Map<String, String> params = new HashMap<>();
47+
params.put("devIds", id);
48+
entity.setParams(params);
49+
HttpResponseEntity response = HttpRequestExecutor.executeGet(entity);
50+
if (StringUtils.isNotBlank(response.getBody())) {
51+
deviceLatestDataResponse = JsonUtils.jsonToObject(response.getBody(), MobDeviceLatestDataResponse.class);
52+
if (deviceLatestDataResponse.getErrno() == 0) {
53+
deviceLatestDataResponse.setSuccess(Boolean.TRUE);
54+
} else {
55+
System.out.format(ColorUtils.redError(deviceLatestDataResponse.getError()));
56+
deviceLatestDataResponse.setSuccess(Boolean.FALSE);
57+
}
58+
} else {
59+
deviceLatestDataResponse.setSuccess(Boolean.FALSE);
60+
System.out.format(config.getProductId() + ColorUtils.redError(" getLatestDataPoints failed!"));
61+
}
62+
63+
return deviceLatestDataResponse;
64+
} catch (Exception e) {
65+
deviceLatestDataResponse.setSuccess(Boolean.FALSE);
66+
System.out.format(config.getProductId() + ColorUtils.redError(" getLatestDataPoints failed!"));
67+
return deviceLatestDataResponse;
68+
}
69+
}
70+
71+
72+
public MobDeviceHisDataResponse getHisDataPoints(MobileConfigDomain config, String id,
73+
String dataStreamIds, String start,
74+
String end, int limit) {
75+
MobDeviceHisDataResponse deviceHisDataResponse = new MobDeviceHisDataResponse();
76+
if (StringUtils.isBlank(dataStreamIds)) {
77+
return deviceHisDataResponse;
78+
}
79+
try {
80+
HttpRequestEntity entity = new HttpRequestEntity();
81+
entity.setType(NBTypeEnum.MOBILE.getValue());
82+
entity.setUrl(MobileSettings.MOBILE_DEVICE_URL + "/" + id + "/datapoints");
83+
Map<String, String> headerMap = getHeaderMap(config);
84+
entity.setHeaders(headerMap);
85+
Map<String, String> params = new HashMap<>();
86+
params.put("datastream_id", dataStreamIds);
87+
params.put("start", start);
88+
params.put("end", end);
89+
params.put("limit", limit <= 0 ? "50" : limit + "");
90+
entity.setParams(params);
91+
HttpResponseEntity response = HttpRequestExecutor.executeGet(entity);
92+
if (StringUtils.isNotBlank(response.getBody())) {
93+
deviceHisDataResponse = JsonUtils.jsonToObject(response.getBody(), MobDeviceHisDataResponse.class);
94+
if (deviceHisDataResponse.getErrno() == 0) {
95+
deviceHisDataResponse.setSuccess(Boolean.TRUE);
96+
} else {
97+
System.out.format(ColorUtils.redError(deviceHisDataResponse.getError()));
98+
deviceHisDataResponse.setSuccess(Boolean.FALSE);
99+
}
100+
} else {
101+
deviceHisDataResponse.setSuccess(Boolean.FALSE);
102+
System.out.format(config.getProductId() + ColorUtils.redError(" getHisDataPoints failed!"));
103+
}
104+
return deviceHisDataResponse;
105+
} catch (Exception e) {
106+
deviceHisDataResponse.setSuccess(Boolean.FALSE);
107+
System.out.format(config.getProductId() + ColorUtils.redError(" getHisDataPoints failed!"));
108+
return deviceHisDataResponse;
109+
}
110+
}
111+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright © 2019-2023 The Toolkit Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package iot.technology.client.toolkit.nb.service.mobile.domain.action.data;
17+
18+
import java.io.Serializable;
19+
import java.util.List;
20+
21+
/**
22+
* @author mushuwei
23+
*/
24+
public class MobDeviceHisDataBody implements Serializable {
25+
26+
private String cursor;
27+
28+
private int count;
29+
30+
private List<MobDeviceHisDataStreamsBody> datastreams;
31+
32+
public String getCursor() {
33+
return cursor;
34+
}
35+
36+
public void setCursor(String cursor) {
37+
this.cursor = cursor;
38+
}
39+
40+
public int getCount() {
41+
return count;
42+
}
43+
44+
public void setCount(int count) {
45+
this.count = count;
46+
}
47+
48+
public List<MobDeviceHisDataStreamsBody> getDatastreams() {
49+
return datastreams;
50+
}
51+
52+
public void setDatastreams(
53+
List<MobDeviceHisDataStreamsBody> datastreams) {
54+
this.datastreams = datastreams;
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright © 2019-2023 The Toolkit Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package iot.technology.client.toolkit.nb.service.mobile.domain.action.data;
17+
18+
import java.io.Serializable;
19+
20+
/**
21+
* @author mushuwei
22+
*/
23+
public class MobDeviceHisDataPointsBody implements Serializable {
24+
25+
private String at;
26+
27+
private String value;
28+
29+
public String getAt() {
30+
return at;
31+
}
32+
33+
public void setAt(String at) {
34+
this.at = at;
35+
}
36+
37+
public String getValue() {
38+
return value;
39+
}
40+
41+
public void setValue(String value) {
42+
this.value = value;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright © 2019-2023 The Toolkit Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package iot.technology.client.toolkit.nb.service.mobile.domain.action.data;
17+
18+
import iot.technology.client.toolkit.nb.service.mobile.domain.BaseMobileResponse;
19+
20+
/**
21+
* @author mushuwei
22+
*/
23+
public class MobDeviceHisDataResponse extends BaseMobileResponse {
24+
25+
private MobDeviceHisDataBody data;
26+
27+
public MobDeviceHisDataBody getData() {
28+
return data;
29+
}
30+
31+
public void setData(MobDeviceHisDataBody data) {
32+
this.data = data;
33+
}
34+
}

0 commit comments

Comments
 (0)