IceRtMileStatClient.java
6.4 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
package com.glsx.ice.iceClient;
import Ice.Communicator;
import com.glsx.config.SystemProperty;
import com.glsx.ice.HDaoMile.*;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import java.util.*;
import java.util.Date;
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, int beginTime, int endTime) {
boolean result = false;
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 = beginTime;
req.endTime = endTime;
mileagePrx.endUserMileStat(req, res);
Map<String,Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
MileStatEndResponse val = res.value;
map.put("sn",sn);
map.put("mileage",val.mileage);
map.put("start_gpsinfo",convertGpsPos(val.beginPos));
map.put("end_gpsinfo",convertGpsPos(val.endPos));
map.put("over80km_percent",val.over80Percent);
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 dType, 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 = 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.getJourneyRecords(req, res);
Map<String,Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
JourneyRecord[] vals = res.value.jourRecords;
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);
Map<String,Object> map = null;
if (res != null && res.value != null && res.value.oprResult == 0) {
DailyMileRecord[] vals = res.value.dailMileRecords;
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;
}
private static Object convertGpsLoc(GpsLoc bgnGps) {
Map<String,Object> map = new HashMap<>();
map.put("lng",bgnGps.lng);
map.put("lat",bgnGps.lat);
map.put("glat",bgnGps.glat);
map.put("glng",bgnGps.glng);
map.put("blng",bgnGps.blng);
map.put("blat",bgnGps.blat);
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);
map.put("lat",beginPos.lat);
map.put("addr",beginPos.addr);
return map;
}
}