DeviceLocationUtil.java
5.84 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package cn.com.glsx.stdinterface.modules.util;
import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.com.glsx.stdinterface.dto.WorkOrderDeviceAddressItem;
import cn.com.glsx.stdinterface.modules.model.XBDeviceAddressItem;
import org.apache.commons.lang.StringUtils;
import java.util.Date;
/**
* 设备位置信息 - 工具类
*/
public class DeviceLocationUtil {
/**
* 解析设备位置状态:有效,无效
*
* @param gpsTime
* @param bsTime
* @param source
* @return
*/
public static Integer resolutionGpsType(String gpsTime, String bsTime, Integer source) {
if (StringUtils.isBlank(gpsTime) && StringUtils.isEmpty(bsTime)) {
return Constants.Verification.SN_INVALID;
}
// 初始化设备有源无源状态:默认无源
int currentSource = (source == null) ? Constants.DeviceSource.WIRELESS : source;
long differBase = (currentSource == Constants.DeviceSource.WIRED) ? Constants.Verification.WIRED_TIME : Constants.Verification.WIRELESS_TIME;
if (StringUtils.isBlank(gpsTime)) {
return Constants.Verification.SN_INVALID;
}
long timeDiff = DateUtils.getTimeDifference(gpsTime);
if (currentSource == Constants.DeviceSource.WIRELESS) {
long gpsDiffer = DateUtils.getTimeDifference(gpsTime);
long bsDiffer = DateUtils.getTimeDifference(bsTime);
timeDiff = (gpsDiffer > bsDiffer) ? bsDiffer : gpsDiffer;
}
return timeDiff > differBase ? Constants.Verification.SN_INVALID : Constants.Verification.SN_VALID;
}
/**
* 解析设备在线状态
*
* @param addressItem
* @param source
* @param speedValue
* @return
*/
public static Integer resolutionDeviceOnlineStatus(WorkOrderDeviceAddressItem addressItem, Integer source, String speedValue) {
if (StringUtils.isBlank(addressItem.getGpsTime())) {
return Constants.DeviceOnline.OFFLINE;
}
int currentSource = (source == null) ? Constants.DeviceSource.WIRELESS : source;
int speed = StringUtils.isEmpty(speedValue) ? 0 : Integer.parseInt(speedValue);
Date gpsDate = DateUtils.toDate(addressItem.getGpsTime(), DateUtils.pattern19);
Date bsDate = DateUtils.toDate(addressItem.getBsTime(), DateUtils.pattern19);
long rtTrckTime = (gpsDate != null) ? gpsDate.getTime() : 0l;
long gprsTime = (bsDate != null) ? bsDate.getTime() : 0l;
int status = 0;
long now = System.currentTimeMillis();
if (gprsTime == 0 && rtTrckTime == 0) {
//离线
status = Constants.DeviceOnline.OFFLINE;
} else if (gprsTime == 0 && rtTrckTime != 0) {
status = commonResolutionOnline(now, rtTrckTime, speed, currentSource);
} else if (gprsTime != 0 && rtTrckTime == 0) {
status = commonResolutionOnline(now, gprsTime, speed, currentSource);
} else {
long time = 0;
time = gprsTime >= rtTrckTime ? gprsTime : rtTrckTime;
status = commonResolutionOnline(now, time, speed, currentSource);
}
return status;
}
/**
* 解析设备在线状态(襄本)
*
* @param addressItem
* @param source
* @param speedValue
* @return
*/
public static Integer resolutionDeviceOnlineStatus(XBDeviceAddressItem addressItem, Integer source, String speedValue) {
if (StringUtils.isBlank(addressItem.getGpsTime())) {
return Constants.DeviceOnline.OFFLINE;
}
int currentSource = (source == null) ? Constants.DeviceSource.WIRELESS : source;
int speed = StringUtils.isEmpty(speedValue) ? 0 : Integer.parseInt(speedValue);
Date gpsDate = DateUtils.toDate(addressItem.getGpsTime(), DateUtils.pattern19);
Date bsDate = DateUtils.toDate(addressItem.getBsTime(), DateUtils.pattern19);
long rtTrckTime = (gpsDate != null) ? gpsDate.getTime() : 0l;
long gprsTime = (bsDate != null) ? bsDate.getTime() : 0l;
int status = 0;
long now = System.currentTimeMillis();
if (gprsTime == 0 && rtTrckTime == 0) {
//离线
status = Constants.DeviceOnline.OFFLINE;
} else if (gprsTime == 0 && rtTrckTime != 0) {
status = commonResolutionOnline(now, rtTrckTime, speed, currentSource);
} else if (gprsTime != 0 && rtTrckTime == 0) {
status = commonResolutionOnline(now, gprsTime, speed, currentSource);
} else {
long time = 0;
time = gprsTime >= rtTrckTime ? gprsTime : rtTrckTime;
status = commonResolutionOnline(now, time, speed, currentSource);
}
return status;
}
/**
* 根据当前时间判断设备的行驶状态
*
* @param now
* @param rtTrckTime
* @param speed
* @param currentSource
* @return
*/
private static int commonResolutionOnline(long now, long rtTrckTime, int speed, int currentSource) {
int status = Constants.DeviceOnline.DRIVING;
if (now - rtTrckTime > Constants.DeviceOnline.TIME_TWENTY_HOURS) {
status = Constants.DeviceOnline.OFFLINE;
} else {
if (currentSource == Constants.DeviceSource.WIRELESS) {
status = Constants.DeviceOnline.ONLINE;
} else {
if (now - rtTrckTime > Constants.DeviceOnline.TIME_SIX_MINITES) {
//大于6分钟 有源在线
status = Constants.DeviceOnline.ONLINE;
} else {
if (speed > 0) {
//行驶状态
status = Constants.DeviceOnline.DRIVING;
} else {
status = Constants.DeviceOnline.STANDSTILL;
}
}
}
}
return status;
}
}