IceHDaoGpsClient.java
13.6 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package com.glsx.ice.iceClient;
import com.glsx.config.SystemProperty;
import com.glsx.ice.HDaoGps.*;
import com.glsx.model.DTO.*;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
public class IceHDaoGpsClient {
static String url = SystemProperty.getProperty("ice.traceUrl");
// static String url = "HDaoGpsSvc:default -h 192.168.3.153 -p 23479";
static Ice.Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(url).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static DaoGpsServicePrx prx = DaoGpsServicePrxHelper.checkedCast(base);
public static LatestGpsRecordDto getLatestGpsRecord(Long sn, Integer deviceType, Integer mapType) {
LatestGpsRecordDto gpsRecord = null;
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
// 第2个参数:2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
LatestRgpsGetRequest req = new LatestRgpsGetRequest(sn, deviceType, mapType);
LatestRgpsGetResponseHolder res = new LatestRgpsGetResponseHolder();
boolean ret = false;
ret = prx.getLatestRgpsRecord(req, res);
if (ret) {
log.info("===getLatestRGPSRecord:" + res.value.record);
gpsRecord = new LatestGpsRecordDto();
gpsRecord.setSn(sn+"");
gpsRecord.setGlng(res.value.record.gLng/ 1000000D);
gpsRecord.setGlat(res.value.record.gLat/ 1000000D);
gpsRecord.setLng(res.value.record.lng/ 1000000D);
gpsRecord.setLat(res.value.record.lat/ 1000000D);
gpsRecord.setSpeed(res.value.record.speed);
gpsRecord.setGpstime(res.value.record.gpsTime);
}
} catch (Ice.LocalException e) {
log.error("===getLatestRGPSRecord_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getLatestRGPSRecord_EXCEP:" + e.getMessage(), e);
}
return gpsRecord;
}
public static LatestBsRecordDto getLatestBsRecord(long sn, Integer deviceType) {
LatestBsRecordDto bsRecord = null;
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
// 第2个参数:2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
LatestBsGetResponseHolder res = new LatestBsGetResponseHolder();
boolean ret = false;
LatestBsGetRequest req = new LatestBsGetRequest(sn, deviceType);
ret = prx.getLatestBsRecord(req, res);
if (ret) {
log.info("===LatestBsRecord:" + res.value.record);
bsRecord = new LatestBsRecordDto();
bsRecord.setSn(sn+"");
bsRecord.setGpstime(res.value.record.gpsTime);
bsRecord.setMcc(res.value.record.mcc);
bsRecord.setMnc(res.value.record.mnc);
List<BsInfoDto> bsInfos = Arrays.stream(res.value.record.bsInfos).map(bsInfo -> {
BsInfoDto bsRecordDto = new BsInfoDto();
bsRecordDto.setCi(bsInfo.cellId);
bsRecordDto.setLac(bsInfo.lac);
bsRecordDto.setSignal(bsInfo.signal);
return bsRecordDto;
}).collect(Collectors.toList());
bsRecord.setBsrecord(bsInfos);
}
} catch (Ice.LocalException e) {
log.error("===getLatestBsRecord_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getLatestBsRecord_EXCEP:" + e.getMessage(), e);
}
return bsRecord;
}
public static LatestGpsBsRecordDto getDevicesGpsInfo(long[] userIds, int extraMapReq, int seqNo) {
LatestGpsBsRecordDto bsRecord = null;
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
// 第2个参数:2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
BatchGpsDevInfoResponseHolder res = new BatchGpsDevInfoResponseHolder();
boolean ret = false;
BatchGpsDevInfoRequest req = new BatchGpsDevInfoRequest(userIds, extraMapReq,seqNo);
ret = prx.getDevicesGpsInfo(req, res);
if (ret) {
log.info("===getDevicesGpsInfo:" + res.value.gpsDevInfos);
GpsDevInfo[] gpsDevInfos = res.value.gpsDevInfos;
if(null != gpsDevInfos && gpsDevInfos.length>0){
GpsDevInfo gpsDevInfo = gpsDevInfos[0];
bsRecord = new LatestGpsBsRecordDto();
bsRecord.setGpstime(gpsDevInfo.record.gpsTime);
//bsRecord.setMcc(gpsDevInfo.record.);
//bsRecord.setMnc(gpsDevInfo.record.mnc);
//List<BsRecordDto> bsInfos = Arrays.stream(res.value.record.bsInfos).map(bsInfo -> {
// BsRecordDto bsRecordDto = new BsRecordDto();
// bsRecordDto.setCi(bsInfo.cellId);
// bsRecordDto.setLac(bsInfo.lac);
// bsRecordDto.setSignal(bsInfo.signal);
// return bsRecordDto;
//}).collect(Collectors.toList());
//bsRecord.setBsrecord(bsInfos);
}
}
} catch (Ice.LocalException e) {
log.error("===getDevicesGpsInfo_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getDevicesGpsInfo_EXCEP:" + e.getMessage(), e);
}
return bsRecord;
}
/**
* @param apType 2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static GpsRecordsDto getGpsRecords(int apType, Date startTime, Date endTime, long sn) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
if (startTime.after(endTime)) {
return null;
}
GpsRecordsDto gpsRecordsDto = new GpsRecordsDto();
GpsGetResponseHolder res = new GpsGetResponseHolder(new GpsGetResponse());
GpsGetRequest req = new GpsGetRequest();
req.apType = apType;
req.startTime = new Long(startTime.getTime() / 1000).intValue();
req.endTime = new Long(endTime.getTime() / 1000).intValue();
req.extraMapReq = 1;
req.userID = sn;
prx.getGpsRecords(req, res);
if (res != null && res.value != null && res.value.oprResult == 0) {
GpsRecord[] r = res.value.records;
gpsRecordsDto.setGpsrecord(convertGpsRecord(r));
}
return gpsRecordsDto;
} catch (Ice.LocalException e) {
log.error("===getGpsRecords_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getGpsRecords_EXCEP:" + e.getMessage(), e);
}
return null;
}
/**
* @param apType 2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static BsRecordsDto getBsRecords(int apType, Date startTime, Date endTime, long userId) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
if (startTime.after(endTime)) {
return null;
}
BsRecordsDto bsRecordsDto = new BsRecordsDto();
BsGetResponseHolder res = new BsGetResponseHolder(new BsGetResponse());
BsGetRequest req = new BsGetRequest();
req.apType = apType;
req.startTime = new Long(startTime.getTime() / 1000).intValue();
req.endTime = new Long(endTime.getTime() / 1000).intValue();
req.userID = userId;
prx.getBsRecords(req, res);
if (res != null && res.value != null && res.value.oprResult == 0) {
BsRecord[] r = res.value.records;
bsRecordsDto.setBsrecord(convertBsRecord(r));
}
return bsRecordsDto;
} catch (Ice.LocalException e) {
log.error("===getBsRecords_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getBsRecords_EXCEP:" + e.getMessage(), e);
}
return null;
}
//查询首次GPS点
public static FirstGpsRecordDto getFirstGpsRecord(int apType, long sn) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
FirstGpsRecordDto firstGpsRecordDto = null;
GpsGetResponseHolder res = new GpsGetResponseHolder(new GpsGetResponse());
GpsGetRequest req = new GpsGetRequest();
req.apType = apType;
req.reqCount = 0;
req.userID = sn;
prx.getFirstGpsRecord(req, res);
if (res != null && res.value != null && res.value.oprResult == 0) {
GpsRecord[] r = res.value.records;
int len = r.length;
if(len>0){
GpsRecord gpsRecord = r[0];
firstGpsRecordDto = new FirstGpsRecordDto();
firstGpsRecordDto.setLat(gpsRecord.lat / 1000000D);
firstGpsRecordDto.setLng(gpsRecord.lng/ 1000000D);
firstGpsRecordDto.setGlat(gpsRecord.gLat/ 1000000D);
firstGpsRecordDto.setGlng(gpsRecord.gLng/ 1000000D);
firstGpsRecordDto.setSpeed(gpsRecord.speed);
firstGpsRecordDto.setGpstime(gpsRecord.gpsTime);
}
}
return firstGpsRecordDto;
} catch (Ice.LocalException e) {
log.error("===getFirstGpsRecord_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getFirstGpsRecord_EXCEP:" + e.getMessage(), e);
}
return null;
}
public static GpsRecordsDto getRecentGpsRecords(long sn, int apType,int reqCount) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
GpsRecordsDto gpsRecordsDto = new GpsRecordsDto();
RecentGpsGetResponseHolder res = new RecentGpsGetResponseHolder(new RecentGpsGetResponse());
RecentGpsGetRequest req = new RecentGpsGetRequest();
req.userID = sn;
req.apType = apType;
req.reqCount = reqCount;
prx.getRecentGpsRecords(req, res);
if (res != null && res.value != null && res.value.oprResult == 0) {
GpsRecord[] r = res.value.records;
gpsRecordsDto.setGpsrecord(convertGpsRecord(r));
}
return gpsRecordsDto;
} catch (Ice.LocalException e) {
log.error("===getRecentGpsRecords_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getRecentGpsRecords_EXCEP:" + e.getMessage(), e);
}
return null;
}
public static BsRecordsDto getRecentBsRecords(long sn, int apType,int reqCount) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
BsRecordsDto bsRecordsDto = new BsRecordsDto();
RecentBsGetResponseHolder res = new RecentBsGetResponseHolder(new RecentBsGetResponse());
RecentBsGetRequest req = new RecentBsGetRequest();
req.apType = apType;
req.reqCount = reqCount;
req.userID = sn;
prx.getRecentBsRecords(req, res);
if (res != null && res.value != null && res.value.oprResult == 0) {
BsRecord[] r = res.value.records;
bsRecordsDto.setBsrecord(convertBsRecord(r));
}
return bsRecordsDto;
} catch (Ice.LocalException e) {
log.error("===getRecentBsRecords_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getRecentBsRecords_EXCEP:" + e.getMessage(), e);
}
return null;
}
private static List<GpsRecordDto> convertGpsRecord(GpsRecord[] records){
return Arrays.stream(records).map(rec->{
GpsRecordDto g = new GpsRecordDto();
g.setGpstime(rec.gpsTime);
g.setAlt(rec.alt);
g.setDir(rec.dir);
g.setSpeed(rec.speed);
g.setLat(rec.lat / 1000000D);
g.setLng(rec.lng / 1000000D);
g.setGlat(rec.gLat / 1000000D);
g.setGlng(rec.gLng / 1000000D);
g.setBlat(rec.bLat / 1000000D);
g.setBlng(rec.bLat / 1000000D);
return g;
}).collect(Collectors.toList());
}
private static List<BsRecordDto> convertBsRecord(BsRecord[] records){
return Arrays.stream(records).map(rec->{
BsRecordDto g = new BsRecordDto();
g.setGpstime(rec.gpsTime);
g.setMcc(rec.mcc);
g.setMnc(rec.mnc);
List<BsInfoDto> bsInfos = Arrays.stream(rec.bsInfos).map(info ->
{
BsInfoDto bsRecord = new BsInfoDto();
bsRecord.setCi(info.cellId);
bsRecord.setLac(info.lac);
bsRecord.setSignal(info.signal);
return bsRecord;
}).collect(Collectors.toList());
g.setBsinfo(bsInfos);
return g;
}).collect(Collectors.toList());
}
}