IceRtMileStatClient.java
11.9 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
package com.glsx.ice.iceClient;
import Ice.Communicator;
import com.glsx.config.SystemProperty;
import com.glsx.ice.HDaoMile.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
/**
* 计算里程
* @author Administrator
*
*/
public class IceRtMileStatClient {
private static Logger log = LoggerFactory.getLogger(IceRtMileStatClient.class);
// ice接口服务器地址 ice.interface.url=FenceUpdate:default -h 192.168.3.153 -p
// 10000
private static String ICE_URL = SystemProperty.getProperty("ice.mile.interface.url");
static Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(ICE_URL).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connect.timeout")));
static DaoMileServicePrx daoMileService = DaoMileServicePrxHelper.checkedCast(base);
//public static void main(String[] args) throws Exception {
// for(int i=0;i<100;i++)
// {
// IceRtMileStatClient.endEvent(6, DateUtils.parseDate("2016-04-19 14:00:00",new String[]{"yyyy-MM-dd HH:mm:ss"}), DateUtils.parseDate("2016-04-19 15:00:00",new String[]{"yyyy-MM-dd HH:mm:ss"}), 51002454);
// }
//}
/**
* 通知服务方行程已开始
* @param apType 2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
* @param beginTime 开始时间
* @param userId 嘀嘀号
* @return
*/
public static boolean beginEvent(int apType, Date beginTime, long userId) {
DaoMileServicePrx daoMileService = null;
MileStatBeginRequest req = new MileStatBeginRequest();
MileStatBeginResponseHolder resp = new MileStatBeginResponseHolder(new MileStatBeginResponse());
try {
ic = Ice.Util.initialize();
Ice.ObjectPrx base = ic.stringToProxy(ICE_URL);
daoMileService = DaoMileServicePrxHelper.checkedCast(base);
if (daoMileService == null) {
log.error("ice添加服务异常 数据:beginEvent " + userId + ":" + beginTime);
}
req.apType = apType;
req.beginTime = new Long(beginTime.getTime() / 1000-8*60*60).intValue();
req.userID = userId;
daoMileService.beginUserMileStat(req, resp);
} catch (Ice.LocalException e) {
log.error("ice添加服务异常 数据:beginEvent " + userId + ":" + beginTime, e);
} catch (Exception e) {
log.error("ice添加服务异常 数据:beginEvent ice exception" + e.getMessage(), e);
}
log.info("ice添加接口调用结束");
if (resp.value.oprResult == 0) {
return true;
}
return false;
}
/**
* 获取行程里程
* @param apType 2: OBD; 4: DDbox(DVD) 5: Tracker 6: rearMirror 7: car recorder
* @param beginTime 行程开始时间
* @param endTime 行程结束时间
* @param userId 用户嘀嘀号
* @return 85406
*/
/*public static Journey endEvent(int apType, Date beginTime, Date endTime,
long userId) {
// Communicator ic = null;
AsyncResult result = null;
MileStatEndRequest req = new MileStatEndRequest();
MileStatEndResponseHolder res = new MileStatEndResponseHolder(new MileStatEndResponse());
boolean isSucc = true;
try {
// ic = Ice.Util.initialize();
if (daoMileService == null) {
log.error("ice添加服务异常 数据:beginEvent " + userId + ":" + beginTime);
}
req.apType = apType;
req.beginTime = new Long(beginTime.getTime() / 1000).intValue();
req.endTime = new Long(endTime.getTime() / 1000).intValue();
req.userID = userId;
req.bRetGpsTime = true;
log.warn("ice请求参数:" + req.toString());
daoMileService.endUserMileStat(req, res);
log.warn("ice返回参数:" + res.toString());
} catch (Ice.LocalException e) {
log.error("ice添加服务异常 数据:beginEvent " + userId + ":" + beginTime + " [exception:" +e.getMessage(), e);
e.printStackTrace();
isSucc = false;
} catch (Exception e1) {
log.error("ice请求处理异常 数据:beginEvent " + userId + ":" + beginTime, e1.getMessage());
isSucc = false;
e1.printStackTrace();
} finally {
// if (ic != null) {
// ic.destroy();
// }
}
log.info("ice添加接口调用结束");
if (isSucc && res.value != null && res.value.oprResult == 0) {
Journey journey = new Journey();
MileStatEndResponse r = res.value;
journey.setMileage(new Double(r.mileage));
if (r.beginPos != null && !StringUtils.isEmpty(r.beginPos.addr)) {
journey.setBeginAddress(r.beginPos.addr);
} else {
journey.setBeginAddress("");
}
journey.setBeginGpsLat(r.beginPos.lat / 1000000D + "");
journey.setBeginGpsLon(r.beginPos.lng / 1000000D + "");
journey.setBeginTime(beginTime);
if (r.endPos != null && !StringUtils.isEmpty(r.endPos.addr)) {
journey.setEndAddress(r.endPos.addr);
} else {
journey.setEndAddress("");
}
journey.setEndGpsLat(r.endPos.lat / 1000000D + "");
journey.setEndGpsLon(r.endPos.lng / 1000000D + "");
journey.setMiddlePercent(new Double(r.over80Percent));
journey.setHighPercent(new Double(r.over120Percent));
journey.setFastSpeed(new Double(r.maxSpeed));
journey.setEndTime(endTime);
if(r.gpsBgnTime!=0 && r.gpsEndTime!=0)
{
journey.setGpsTotalTime(r.gpsEndTime-r.gpsBgnTime);
}
if(r.gpsBgnTime!=0)
{
long bgnTimes = (long) (r.gpsBgnTime * 1000L);
journey.setGpsBeginTime(new Date(bgnTimes));
}
if(r.gpsEndTime!=0)
{
long endTimes = (long) (r.gpsEndTime * 1000L);
journey.setGpsEndTime(new Date(endTimes));
}
return journey;
} else {
Journey journey = new Journey();
journey.setMileage(0.0);
journey.setBeginAddress("");
journey.setBeginGpsLat("0");
journey.setBeginGpsLon("0");
journey.setBeginTime(beginTime);
journey.setEndAddress("");
journey.setEndGpsLat("0");
journey.setEndGpsLon("0");
journey.setGpsBeginTime(null);
journey.setGpsEndTime(null);
journey.setGpsTotalTime(0);
journey.setGpsTotalTime(0);
journey.setEndTime(endTime);
return journey;
}
}
public static Journey endEventByImei(int deviceType, Date beginTime, Date endTime, String sn) {
MileStatEndRequest req = new MileStatEndRequest();
MileStatEndResponseHolder res = new MileStatEndResponseHolder(new MileStatEndResponse());
boolean isSucc = true;
try {
if (daoMileService == null) {
log.error("ice添加服务异常 数据:beginEvent " + sn + ":" + beginTime);
}
req.apType = deviceType;
req.beginTime = new Long(beginTime.getTime() / 1000).intValue();
req.endTime = new Long(endTime.getTime() / 1000).intValue();
req.userID = Long.parseLong(sn);
req.bRetGpsTime = true;
log.warn("ice请求参数:" + req.toString());
daoMileService.endUserMileStatByImei(req, res);
log.warn("ice返回参数:" + res.toString());
} catch (Ice.LocalException e) {
log.error("ice添加服务异常 数据:beginEvent " + sn + ":" + beginTime + " [exception:" +e.getMessage(), e);
e.printStackTrace();
isSucc = false;
} catch (Exception e1) {
log.error("ice请求处理异常 数据:beginEvent " + sn + ":" + beginTime, e1.getMessage());
isSucc = false;
e1.printStackTrace();
} finally {
// if (ic != null) {
// ic.destroy();
// }
}
log.info("ice添加接口调用结束");
if (isSucc && res.value != null && res.value.oprResult == 0) {
Journey journey = new Journey();
MileStatEndResponse r = res.value;
journey.setMileage(new Double(r.mileage));
if (r.beginPos != null && !StringUtils.isEmpty(r.beginPos.addr)) {
journey.setBeginAddress(r.beginPos.addr);
} else {
journey.setBeginAddress("");
}
journey.setBeginGpsLat(r.beginPos.lat / 1000000D + "");
journey.setBeginGpsLon(r.beginPos.lng / 1000000D + "");
journey.setBeginTime(beginTime);
if (r.endPos != null && !StringUtils.isEmpty(r.endPos.addr)) {
journey.setEndAddress(r.endPos.addr);
} else {
journey.setEndAddress("");
}
journey.setEndGpsLat(r.endPos.lat / 1000000D + "");
journey.setEndGpsLon(r.endPos.lng / 1000000D + "");
journey.setMiddlePercent(new Double(r.over80Percent));
journey.setHighPercent(new Double(r.over120Percent));
journey.setFastSpeed(new Double(r.maxSpeed));
journey.setEndTime(endTime);
if(r.gpsBgnTime!=0 && r.gpsEndTime!=0)
{
journey.setGpsTotalTime(r.gpsEndTime-r.gpsBgnTime);
}
if(r.gpsBgnTime!=0)
{
long bgnTimes = (long) (r.gpsBgnTime * 1000L);
journey.setGpsBeginTime(new Date(bgnTimes));
}
if(r.gpsEndTime!=0)
{
long endTimes = (long) (r.gpsEndTime * 1000L);
journey.setGpsEndTime(new Date(endTimes));
}
return journey;
} else {
Journey journey = new Journey();
journey.setMileage(0.0);
journey.setBeginAddress("");
journey.setBeginGpsLat("0");
journey.setBeginGpsLon("0");
journey.setBeginTime(beginTime);
journey.setEndAddress("");
journey.setEndGpsLat("0");
journey.setEndGpsLon("0");
journey.setGpsBeginTime(null);
journey.setGpsEndTime(null);
journey.setGpsTotalTime(0);
journey.setGpsTotalTime(0);
journey.setEndTime(endTime);
return journey;
}
}
public static UserTotalMileage getUserTotalMileage(long dId, Integer deviceTypeConvert, String startDate, String endDate) {
UserTotalMileage result = null;
try {
if (daoMileService == null) {
throw new Exception("daoMileService Invalid proxy");
}
int stime = (int) (DateFormatUtil.toDate(startDate, DateFormatUtil.pattern19).getTime()/1000);
int etime = (int) (DateFormatUtil.toDate(endDate, DateFormatUtil.pattern19).getTime()/1000);
// long userID:设备sn, int apType:设备类型, int bgnDayTime:开始时间, int endDayTime:结束时间, int bReqDailyRecord
GetTotalMileageReq req = new GetTotalMileageReq(dId, deviceTypeConvert, stime, etime, 0);
GetTotalMileageResHolder res = new GetTotalMileageResHolder();
boolean ret = daoMileService.getToatlMileage(req, res);
if (ret && res.value != null) {
result = new UserTotalMileage();
GetTotalMileageRes getResponse = res.value;
// result.setTotalMileage((double) (getResponse.totalMileage/1000));
// 公里,保留两位小数
result.setTotalMileage(new BigDecimal((double) (getResponse.totalMileage/1000.0)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
}
} catch (Ice.LocalException e) {
log.error("invoke ice getToatlMileage ICE_exception" + e.getMessage(), e);
} catch (Exception e) {
log.error("invoke ice getToatlMileage exception" + e.getMessage(), e);
}
return result;
}*/
}