DeviceLocationItem.java
2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package cn.com.glsx.schedulerjob.model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* 设备经纬度接口 - 位置列表项(locationList数组元素)
* 对应文档3.11.2 locationList[]下的字段
*/
public class DeviceLocationItem implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 设备序列号
* 必填:是
* 类型:String
* 对应文档3.11.2 locationList[].sn字段
*/
private String sn;
/**
* 位置采集时间
* 必填:是
* 格式:yyyy-MM-dd HH:mm:ss
* 对应文档3.11.2 locationList[].locationTime字段
*/
private String locationTime;
/**
* 设备纬度
* 必填:是
* 类型:Double
* 约束:保留6位小数,范围[-90, 90](有效地理纬度范围)
* 对应文档3.11.2 locationList[].lat字段
*/
private Double lat;
/**
* 设备经度
* 必填:是
* 类型:Double
* 约束:保留6位小数,范围[-180, 180](有效地理经度范围)
* 对应文档3.11.2 locationList[].lng字段
*/
private Double lng;
// 无参构造(JSON反序列化必备)
public DeviceLocationItem() {
}
// 全参构造(自动处理经纬度小数位数)
public DeviceLocationItem(String sn, String locationTime, Double lat, Double lng) {
this.sn = sn;
this.locationTime = locationTime;
this.lat = roundTo6Decimals(lat);
this.lng = roundTo6Decimals(lng);
}
// 辅助方法:Double保留6位小数(符合文档格式要求)
private Double roundTo6Decimals(Double value) {
if (value == null) {
return null;
}
return BigDecimal.valueOf(value).setScale(6, RoundingMode.HALF_UP).doubleValue();
}
// Getter & Setter(Setter中补充经纬度小数位数约束)
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getLocationTime() {
return locationTime;
}
public void setLocationTime(String locationTime) {
this.locationTime = locationTime;
}
public Double getLat() {
return lat;
}
public void setLat(Double lat) {
this.lat = roundTo6Decimals(lat);
}
public Double getLng() {
return lng;
}
public void setLng(Double lng) {
this.lng = roundTo6Decimals(lng);
}
// toString(方便日志打印/调试)
@Override
public String toString() {
return "DeviceLocationItem{" +
"sn='" + sn + '\'' +
", locationTime='" + locationTime + '\'' +
", lat=" + lat +
", lng=" + lng +
'}';
}
}