GpsDataServiceImpl.java
2.83 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
package com.bsth.vehicle.gpsdata.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.bsth.util.TransGPS;
import com.bsth.util.TransGPS.Location;
import com.bsth.util.db.DBUtils_MS;
@Service
public class GpsDataServiceImpl implements GpsDataService{
//历史gps查询
@Override
public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) {
Calendar sCal = Calendar.getInstance();
sCal.setTime(new Date(/*startTime*/));
Calendar eCal = Calendar.getInstance();
eCal.setTime(new Date(endTime));
int dayOfYear = sCal.get(Calendar.DAY_OF_YEAR);
/*if(dayOfYear != eCal.get(Calendar.DAY_OF_YEAR)){
System.out.println("暂时不支持跨天查询...");
return null;
}*/
String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE from BSTH_C_GPS_INFO where days_year=? and device_id=? and ts > ? and ts < ?";
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> map = null;
try{
conn = DBUtils_MS.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1, dayOfYear);
ps.setString(2, device);
ps.setLong(3, startTime);
ps.setLong(4, endTime);
rs = ps.executeQuery();
Float lon, lat;
Location location;
int upDown;
while (rs.next()) {
upDown = getUpOrDown(rs.getLong("SERVICE_STATE"));
if(upDown != directions)
continue;
//to 百度坐标
lon = rs.getFloat("LON");
lat = rs.getFloat("lat");
location = TransGPS.LocationMake(lon, lat);
location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
map = new HashMap<>();
map.put("device", rs.getString("DEVICE_ID"));
map.put("lon", location.getLng());
map.put("lat", location.getLat());
map.put("ts", rs.getLong("ts"));
map.put("inout_stop", rs.getInt("INOUT_STOP"));
//上下行
map.put("upDown", upDown);
list.add(map);
}
}catch(Exception e){
e.printStackTrace();
}finally {
DBUtils_MS.close(rs, ps, conn);
}
return list;
}
/**王通 2016/6/29 9:23:24
* 获取车辆线路上下行
* @return -1无效 0上行 1下行
*/
public static byte getUpOrDown(long serviceState) {
if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
|| (serviceState & 0x01000000) == 0x01000000
|| (serviceState & 0x08000000) == 0x08000000) return -1;
return (byte)(((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
}
}