IceRtMileStatClient.java
17.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
package com.glsx.ice.iceClient;
import Ice.Communicator;
import com.glsx.base.enums.MapTypeEnum;
import com.glsx.ice.HDaoMile.Date;
import com.glsx.ice.HDaoMile.*;
import com.glsx.utils.SystemProperty;
import lombok.extern.slf4j.Slf4j;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* 计算里程
*
* @author Administrator
*/
@Slf4j
public class IceRtMileStatClient {
// ice接口服务器地址
private static String ICE_URL = SystemProperty.getProperty("ice.mileUrl");
static Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static DaoMileServicePrx mileagePrx = DaoMileServicePrxHelper.checkedCast(base);
/**
* 通过经纬度查询所属行政区域
*
* @return
*/
public static Map<String, Object> getJourneyByGpsRecords(long sn, int dType, long beginTime, long endTime) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
}
MileStatEndResponseHolder res = new MileStatEndResponseHolder(new MileStatEndResponse());
MileStatEndRequest req = new MileStatEndRequest();
req.userID = sn;
req.apType = dType;
//开始时间
req.beginTime = parseTimeMillis(beginTime);
//结束时间
req.endTime = parseTimeMillis(endTime);
//返回最后GPS记录时间
req.bRetGpsTime = true;
mileagePrx.endUserMileStat(req, res);
Map<String, Object> map = null;
log.info("getJourneyByGpsRecords====="+res.value.oprResult);
if (res != null && res.value != null && res.value.oprResult == 0) {
MileStatEndResponse val = res.value;
map = new HashMap<>();
//设备号
map.put("sn", sn);
//行驶里程:单位(米)
map.put("mileage", val.mileage);
//行程开始信息
map.put("start_gpsinfo", convertGpsPos(val.beginPos));
//行程结束信息
map.put("end_gpsinfo", convertGpsPos(val.endPos));
//80~120km所占百分比
map.put("over80km_percent", val.over80Percent);
//120km以上所占百分比
map.put("over120km_percent", val.over120Percent);
//最大的速度
map.put("maxspeed", val.maxSpeed);
return map;
}
} catch (Ice.LocalException e) {
log.error("invoke ice getJourneyByGpsRecords ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getJourneyByGpsRecords exception" + e.getMessage(), e);
}
return null;
}
/**
* 通过经纬度查询所属行政区域
*
* @return
*/
public static Map<String, Object> getJourneyRecords(long sn, int apType, java.util.Date bgnDate, java.util.Date endDate) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
}
GetJourneyRecordsResHolder res = new GetJourneyRecordsResHolder(new GetJourneyRecordsRes());
GetJourneyRecordsReq req = new GetJourneyRecordsReq();
req.userID = sn;
req.apType = apType;
// 缺省是false,为true时,表示响应结果中携带中文地址
req.bReqAddr = true;
//开始日期
//req.bgnDate = bgnDate;
//结束日期
//req.endDate = endDate;
//0:原始坐标 1:转换高德和百度坐标 2:转换高德坐标 3:转换百度坐标
req.extraMapReq = MapTypeEnum.DOUBLE_TYPE.getId();
Calendar calendar = Calendar.getInstance();
calendar.setTime(bgnDate); //放入Date类型数据
com.glsx.ice.HDaoMile.Date bdate = new com.glsx.ice.HDaoMile.Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
req.bgnDate = bdate;
calendar.setTime(endDate); //放入Date类型数据
com.glsx.ice.HDaoMile.Date eDate = new com.glsx.ice.HDaoMile.Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
req.endDate = eDate;
mileagePrx.getJourneyRecords(req, res);
log.info("getJourneyRecords====="+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
JourneyRecord[] vals = res.value.jourRecords;
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> journeyrecords = Arrays.stream(vals).map(jrecord -> {
Map<String, Object> jmap = new HashMap<>();
//行驶开始时间
jmap.put("bgntime", jrecord.bgnTime);
//行驶结束时间
jmap.put("endtime", jrecord.endTime);
//行驶时长
jmap.put("duration", jrecord.duration);
//开始地址
jmap.put("bgnaddress", jrecord.bgnAddress);
//行程开始位置信息
jmap.put("bgngps", convertGpsLoc(jrecord.bgnGps));
//结束地址
jmap.put("endaddress", jrecord.endAddress);
//行程结束位置信息
jmap.put("endgps", convertGpsLoc(jrecord.endGps));
//行驶里程
jmap.put("mileage", jrecord.mileage);
return jmap;
}).collect(Collectors.toList());
map.put("journeyrecords", journeyrecords);
return map;
}
} catch (Ice.LocalException e) {
log.error("invoke ice getJourneyRecords ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getJourneyRecords exception" + e.getMessage(), e);
}
return null;
}
public static Map<String, Object> getDailyMileageRecords(long sn, Integer dType, java.util.Date bgnDate, java.util.Date endDate) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
}
GetDailyMileRecordsResHolder res = new GetDailyMileRecordsResHolder(new GetDailyMileRecordsRes());
GetDailyMileRecordsReq req = new GetDailyMileRecordsReq();
req.userID = sn;
req.apType = dType;
Calendar calendar = Calendar.getInstance();
calendar.setTime(bgnDate); //放入Date类型数据
com.glsx.ice.HDaoMile.Date bdate = new com.glsx.ice.HDaoMile.Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
req.bgnDate = bdate;
calendar.setTime(endDate); //放入Date类型数据
com.glsx.ice.HDaoMile.Date eDate = new com.glsx.ice.HDaoMile.Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
req.endDate = eDate;
mileagePrx.getDailyMileageRecords(req, res);
log.info("getDailyMileageRecords====="+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
DailyMileRecord[] vals = res.value.dailMileRecords;
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> dailyrecords = Arrays.stream(vals).map(drecord -> {
Map<String, Object> jmap = new HashMap<>();
//开车次数
jmap.put("jourcount", drecord.jourCount);
//行驶里程
jmap.put("mileage", drecord.mileage);
//行驶时长
jmap.put("duration", drecord.duration);
//开车日期
jmap.put("jourdate", drecord.jourDate);
return jmap;
}).collect(Collectors.toList());
map.put("dailyrecords", dailyrecords);
return map;
}
} catch (Ice.LocalException e) {
log.error("invoke ice getDailyMileageRecords ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getDailyMileageRecords exception" + e.getMessage(), e);
}
return null;
}
public static Map<String, Object> getTotalMileageRecords(long sn, Integer apType) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
}
GetTotalMileageResHolder res = new GetTotalMileageResHolder(new GetTotalMileageRes());
GetTotalMileageReq req = new GetTotalMileageReq();
req.userID = sn;
req.apType = apType;
//默认0,非0:获取日里程记录
//req.bReqDailyRecord
mileagePrx.getToatlMileage(req, res);
log.info("getTotalMileageRecords=====code:"+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
DailyMileRecord[] vals = res.value.dailMileRecords;
log.info("getTotalMileageRecords=====list:"+vals.length);
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> dailyrecords = Arrays.stream(vals).map(drecord -> {
Map<String, Object> jmap = new HashMap<>();
//设备号
jmap.put("sn", drecord.jourCount);
//行驶总里程
jmap.put("totalmileage", drecord.mileage);
//行驶总时长
jmap.put("totalduration", drecord.duration);
//行驶总开车次数
jmap.put("totaljourcount", drecord.jourDate);
return jmap;
}).collect(Collectors.toList());
map.put("totalmileagerecords", dailyrecords);
return map;
}
} catch (Ice.LocalException e) {
log.error("invoke ice getDailyMileageRecords ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getDailyMileageRecords exception" + e.getMessage(), e);
}
return null;
}
public static Map<String, Object> getMonthResideRecords(long sn, Integer dType, String bgn_month, String end_month) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
}
GetMonthResideRecordsResHolder res = new GetMonthResideRecordsResHolder(new GetMonthResideRecordsRes());
GetMonthResideRecordsReq req = new GetMonthResideRecordsReq();
req.userID = sn;
req.apType = dType;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");//注意月份是MM
Calendar calendar = Calendar.getInstance();
calendar.setTime(simpleDateFormat.parse(bgn_month)); //放入Date类型数据
Month bm = new Month(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH));
//开始月份 如: 2019-08
req.bgnMonth = bm;
calendar.setTime(simpleDateFormat.parse(end_month)); //放入Date类型数据
Month em = new Month(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH));
//结束月份 如:2019-10
req.endMonth = em;
mileagePrx.getMonthResideRecords(req, res);
log.info("getMonthResideRecords=====code:"+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
MonthResideRecord[] vals = res.value.monResideRecords;
log.info("getMonthResideRecords=====list:"+vals.length);
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> monthRecords = Arrays.stream(vals).map(mrecord -> {
Map<String, Object> jmap = new HashMap<>();
//第一常驻地位置信息
jmap.put("fstresideloc", mrecord.fstResideLoc);
//第一常驻地停留时长
jmap.put("fstresideduration", mrecord.fstResideDuration);
//第一常驻地停留次数
jmap.put("fstresidetimes", mrecord.fstResideTimes);
//第二常驻地位置信息
jmap.put("sndresideloc", mrecord.sndResideLoc);
//第二常驻地停留时长
jmap.put("sndresideduration", mrecord.sndResideDuration);
//第二常驻地停留次数
jmap.put("sndresidetimes", mrecord.sndResideTimes);
//第三常驻地位置信息
jmap.put("trdresideloc", mrecord.trdResideLoc);
//第三常驻地停留时长
jmap.put("trdresideduration", mrecord.trdResideDuration);
//第三常驻地停留次数
jmap.put("trdresidetimes", mrecord.trdResideTimes);
//常驻地所属月份
jmap.put("whichmonth", mrecord.whichMonth);
return jmap;
}).collect(Collectors.toList());
map.put("monthresiderecord", monthRecords);
return map;
}
} catch (Ice.LocalException e) {
log.error("invoke ice getMonthResideRecords ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getMonthResideRecords exception" + e.getMessage(), e);
}
return null;
}
public static Map<String, Object> getDeviceStayRecords(long sn, Integer dType, String start_date, String end_date, Integer period_type, Integer max_duration, Integer min_duration) {
try {
if (mileagePrx == null) {
throw new Exception("Invalid proxy");
}
GetStayPointRecordsResHolder res = new GetStayPointRecordsResHolder(new GetStayPointRecordsRes());
GetStayPointRecordsReq req = new GetStayPointRecordsReq();
req.userID = sn;
req.apType = dType;
req.periodType = period_type;
req.maxDuration = max_duration;
req.minDuration = min_duration;
req.extraMapReq = MapTypeEnum.DOUBLE_TYPE.getId();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
Calendar calendar = Calendar.getInstance();
calendar.setTime(simpleDateFormat.parse(start_date)); //放入Date类型数据
Date bm = new Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
req.bgnDate = bm;
calendar.setTime(simpleDateFormat.parse(end_date)); //放入Date类型数据
Date em = new Date(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
req.endDate = em;
mileagePrx.getStayPointRecords(req, res);
log.info("getStayPointRecords=====code:"+res.value.oprResult);
Map<String, Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
StayPointRecord[] vals = res.value.stayPoints;
log.info("getStayPointRecords=====list:"+vals.length);
map = new HashMap<>();
map.put("sn", sn);
List<Map<String, Object>> stayRecords = Arrays.stream(vals).map(srecord -> {
Map<String, Object> jmap = new HashMap<>();
//开始停留时间
jmap.put("bgntime", srecord.bgnTime);
//结束停留时间
jmap.put("endtime", srecord.endTime);
//停留时长
jmap.put("duration", srecord.duration);
//第二常驻地位置信息
jmap.put("staygps", convertGpsLoc(srecord.stayGps));
return jmap;
}).collect(Collectors.toList());
map.put("staypointrecord", stayRecords);
return map;
}
} catch (Ice.LocalException e) {
log.error("invoke ice getMonthResideRecords ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getMonthResideRecords exception" + e.getMessage(), e);
}
return null;
}
private static Object convertGpsLoc(GpsLoc bgnGps) {
Map<String, Object> map = new HashMap<>();
//经度
map.put("lng", bgnGps.lng / 1000000D);
//纬度
map.put("lat", bgnGps.lat / 1000000D);
//高德经度
map.put("glng", bgnGps.glng / 1000000D);
//高德纬度
map.put("glat", bgnGps.glat / 1000000D);
//百度经度
map.put("blng", bgnGps.blng / 1000000D);
//百度纬度
map.put("blat", bgnGps.blat / 1000000D);
return map;
}
private static Map<String, Object> convertGpsPos(GpsPos beginPos) {
Map<String, Object> map = new HashMap<>();
map.put("gpstime", beginPos.gpsTime);
//经度
map.put("lng", beginPos.lng / 1000000D);
//纬度
map.put("lat", beginPos.lat / 1000000D);
//地址描述
map.put("addr", beginPos.addr);
return map;
}
public static Integer parseTimeMillis(long time) throws Exception{
String s = String.valueOf(time);
return Integer.parseInt(s.substring(0, s.length()-3));
}
}