Commit de8ada3f00c96dc2812e1e74984ebcb3a48ad49c

Authored by 王通
1 parent f1bab7ee

1.小码实时GPS接口

src/main/java/com/bsth/server_rs/gps/GpsRestService.java
1 -package com.bsth.server_rs.gps;  
2 -  
3 -import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;  
4 -import com.bsth.server_rs.gps.dao.HistoryGpsDao;  
5 -import com.bsth.server_rs.gps.entity.GpsEntity;  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.stereotype.Component;  
8 -  
9 -import javax.ws.rs.GET;  
10 -import javax.ws.rs.Path;  
11 -import javax.ws.rs.PathParam;  
12 -import javax.ws.rs.Produces;  
13 -import javax.ws.rs.core.MediaType;  
14 -import java.util.Collection;  
15 -import java.util.Map;  
16 -  
17 -/**  
18 - * Created by panzhao on 2017/3/28.  
19 - */  
20 -@Component  
21 -@Path("/gps")  
22 -@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})  
23 -public class GpsRestService {  
24 -  
25 - @Autowired  
26 - HistoryGpsDao historyGpsDao;  
27 -  
28 - @GET  
29 - @Path("/{deviceId}")  
30 - public GpsEntity findOne(@PathParam("deviceId") String deviceId) {  
31 - return GpsRealDataBuffer.get(deviceId);  
32 - }  
33 -  
34 - @GET  
35 - @Path("/all")  
36 - public Collection<GpsEntity> findAll() {  
37 - return GpsRealDataBuffer.all();  
38 - }  
39 -  
40 - @GET  
41 - @Path("/history/{nbbm}/{st}/{et}")  
42 - public Collection<Map<String, Object>> history(@PathParam("nbbm") String nbbm  
43 - , @PathParam("st") String st  
44 - , @PathParam("et") String et) {  
45 - return historyGpsDao.query(nbbm, Long.parseLong(st), Long.parseLong(et));  
46 - }  
47 -} 1 +package com.bsth.server_rs.gps;
  2 +
  3 +import java.text.ParseException;
  4 +import java.util.ArrayList;
  5 +import java.util.Collection;
  6 +import java.util.Date;
  7 +import java.util.HashMap;
  8 +import java.util.List;
  9 +import java.util.Map;
  10 +import java.util.Set;
  11 +
  12 +import javax.ws.rs.GET;
  13 +import javax.ws.rs.Path;
  14 +import javax.ws.rs.PathParam;
  15 +import javax.ws.rs.Produces;
  16 +import javax.ws.rs.core.MediaType;
  17 +
  18 +import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
  22 +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  23 +import com.bsth.server_rs.gps.dao.HistoryGpsDao;
  24 +import com.bsth.server_rs.gps.entity.GpsEntity;
  25 +import com.bsth.server_rs.gps.entity.LineInfo;
  26 +import com.bsth.server_rs.gps.entity.StopInfo;
  27 +import com.bsth.util.ThreadLocalDateUtil;
  28 +
  29 +/**
  30 + * Created by panzhao on 2017/3/28.
  31 + */
  32 +@Component
  33 +@Path("/gps")
  34 +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  35 +public class GpsRestService {
  36 +
  37 + @Autowired
  38 + HistoryGpsDao historyGpsDao;
  39 +
  40 + @GET
  41 + @Path("/{deviceId}")
  42 + public GpsEntity findOne(@PathParam("deviceId") String deviceId) {
  43 + return GpsRealDataBuffer.get(deviceId);
  44 + }
  45 +
  46 + @GET
  47 + @Path("/all")
  48 + public Collection<GpsEntity> findAll() {
  49 + return GpsRealDataBuffer.all();
  50 + }
  51 +
  52 + @GET
  53 + @Path("/history/{nbbm}/{st}/{et}")
  54 + public Collection<Map<String, Object>> history(@PathParam("nbbm") String nbbm
  55 + , @PathParam("st") String st
  56 + , @PathParam("et") String et) {
  57 + return historyGpsDao.query(nbbm, Long.parseLong(st), Long.parseLong(et));
  58 + }
  59 +
  60 + @GET
  61 + @Path("/gpsReport")
  62 + public List<Map<String, Object>> gpsReport() {
  63 + List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
  64 + Collection<GpsEntity> gpss = GpsRealDataBuffer.all();
  65 + Set<String> devices = BasicDataBuffer.getAllDevice();
  66 + for (GpsEntity gps : gpss) {
  67 + String device = gps.getDeviceId();
  68 + if (devices.contains(device)) {
  69 + Map<String, Object> map = new HashMap<String, Object>();
  70 + map.put("vehicleNumberPlate", BasicDataBuffer.getPlateByDevice(device));
  71 + try {
  72 + map.put("gpsDateTime", ThreadLocalDateUtil.formatDate(new Date(gps.getTimestamp())));
  73 + } catch (ParseException e) {
  74 + // TODO Auto-generated catch block
  75 + e.printStackTrace();
  76 + }
  77 + map.put("gpsLongitude", gps.getLon());
  78 + map.put("gpsLatitude", gps.getLat());
  79 + map.put("gpsDirection", gps.getDirection());
  80 + map.put("gpsSpeed", gps.getSpeed());
  81 + map.put("gpsIsValid", gps.getValid());
  82 + map.put("lineId", gps.getLineId());
  83 + map.put("lineVersion", 0);
  84 + map.put("upDownMark", gps.getUpDown());
  85 + map.put("stationOrder", getCurrStop(gps));
  86 + map.put("inOutStationState", gps.getInOrOutStation());
  87 + map.put("operationalState", gps.getState());
  88 +
  89 + result.add(map);
  90 + }
  91 + }
  92 +
  93 + return result;
  94 + }
  95 +
  96 + private static int getCurrStop(GpsEntity gps) {
  97 + int res = 0;
  98 +
  99 + LineInfo line = BasicDataBuffer.getLineById(Integer.parseInt(gps.getLineId()));
  100 + if (line != null) {
  101 + List<StopInfo> upStops = new ArrayList<>(line.getStopsUp()), downStops = new ArrayList<>(line.getStopsDown());
  102 + int updown = gps.getUpDown();
  103 + // 环线、内外换的线路
  104 + boolean isRing = line.getLinePlayType() == 1;
  105 + if (isRing) {
  106 + updown = 0;
  107 + downStops.clear();
  108 + }
  109 + List<StopInfo> stops = new ArrayList<StopInfo>();
  110 + stops.addAll(upStops);
  111 + stops.addAll(downStops);
  112 +
  113 + int idx = 1;
  114 + if (updown == 0) {
  115 + for (StopInfo stop : upStops) {
  116 + if (gps.getStopNo().trim().equals(stop.getStationCod())) break;
  117 + idx++;
  118 + }
  119 + } else {
  120 + for (StopInfo stop : downStops) {
  121 + if (gps.getStopNo().trim().equals(stop.getStationCod())) break;
  122 + idx++;
  123 + }
  124 + }
  125 + if (idx <= stops.size()) {
  126 + res = idx;
  127 + }
  128 + }
  129 +
  130 + return res;
  131 + }
  132 +}
src/main/java/com/bsth/server_rs/gps/entity/GpsEntity.java
1 -package com.bsth.server_rs.gps.entity;  
2 -  
3 -import javax.xml.bind.annotation.XmlRootElement;  
4 -import java.io.Serializable;  
5 -  
6 -/**  
7 - *  
8 - * @ClassName: GpsRealData  
9 - * @Description: TODO(HTTP接口的实时GPS数据)  
10 - * @author PanZhao  
11 - * @date 2016年5月11日 下午4:32:07  
12 - *  
13 - */  
14 -@XmlRootElement  
15 -public class GpsEntity implements Serializable{  
16 -  
17 - /** 公司代码 */  
18 - private Integer companyCode;  
19 -  
20 - /** 线路编码 */  
21 - private String lineId;  
22 -  
23 - /** 设备编码 */  
24 - private String deviceId;  
25 -  
26 - /** 停车场编码 */  
27 - private String carparkNo;  
28 -  
29 - /** 站点编码 */  
30 - private String stopNo;  
31 -  
32 - /** 站点名称 */  
33 - private String stationName;  
34 -  
35 - /** 经度 */  
36 - private Float lon;  
37 -  
38 - /** 纬度 */  
39 - private Float lat;  
40 -  
41 - /** 发送时间戳 */  
42 - private Long timestamp;  
43 -  
44 - /** 速度 */  
45 - private Float speed;  
46 -  
47 - /** 方向(角度) */  
48 - private Float direction;  
49 -  
50 - /** 营运状态( 0 营运 ,1 非营运, -1 无效) */  
51 - private Integer state;  
52 -  
53 - /** 上下行(0 上行 , 1 下行 , -1 无效) */  
54 - private Integer upDown;  
55 -  
56 - /** 车辆内部编码 */  
57 - private String nbbm;  
58 -  
59 - /** 预计到达终点时间 */  
60 - private Float expectStopTime;  
61 -  
62 - private int version;  
63 -  
64 - /** 异常状态 */  
65 - private String abnormalStatus;  
66 -  
67 - /** 越界距离 */  
68 - private double outOfBoundDistance;  
69 -  
70 - /** gps是否有效 设备端发送的状态 */  
71 - private int valid;  
72 -  
73 - private String sectionCode;  
74 -  
75 - public Integer getCompanyCode() {  
76 - return companyCode;  
77 - }  
78 -  
79 - public void setCompanyCode(Integer companyCode) {  
80 - this.companyCode = companyCode;  
81 - }  
82 -  
83 - public String getDeviceId() {  
84 - return deviceId;  
85 - }  
86 -  
87 - public void setDeviceId(String deviceId) {  
88 - this.deviceId = deviceId;  
89 - }  
90 -  
91 - public String getCarparkNo() {  
92 - return carparkNo;  
93 - }  
94 -  
95 - public void setCarparkNo(String carparkNo) {  
96 - this.carparkNo = carparkNo;  
97 - }  
98 -  
99 - public String getStopNo() {  
100 - return stopNo;  
101 - }  
102 -  
103 - public void setStopNo(String stopNo) {  
104 - this.stopNo = stopNo;  
105 - }  
106 -  
107 - public Float getLon() {  
108 - return lon;  
109 - }  
110 -  
111 - public void setLon(Float lon) {  
112 - this.lon = lon;  
113 - }  
114 -  
115 - public Float getLat() {  
116 - return lat;  
117 - }  
118 -  
119 - public void setLat(Float lat) {  
120 - this.lat = lat;  
121 - }  
122 -  
123 - public Long getTimestamp() {  
124 - return timestamp;  
125 - }  
126 -  
127 - public void setTimestamp(Long timestamp) {  
128 - this.timestamp = timestamp;  
129 - }  
130 -  
131 - public Float getSpeed() {  
132 - return speed;  
133 - }  
134 -  
135 - public void setSpeed(Float speed) {  
136 - this.speed = speed;  
137 - }  
138 -  
139 - public Float getDirection() {  
140 - return direction;  
141 - }  
142 -  
143 - public void setDirection(Float direction) {  
144 - this.direction = direction;  
145 - }  
146 -  
147 - public Integer getState() {  
148 - return state;  
149 - }  
150 -  
151 - public void setState(Integer state) {  
152 - this.state = state;  
153 - }  
154 -  
155 - public Integer getUpDown() {  
156 - return upDown;  
157 - }  
158 -  
159 - public void setUpDown(Integer upDown) {  
160 - this.upDown = upDown;  
161 - }  
162 -  
163 - public String getNbbm() {  
164 - return nbbm;  
165 - }  
166 -  
167 - public void setNbbm(String nbbm) {  
168 - this.nbbm = nbbm;  
169 - }  
170 -  
171 - public String getStationName() {  
172 - return stationName;  
173 - }  
174 -  
175 - public void setStationName(String stationName) {  
176 - this.stationName = stationName;  
177 - }  
178 -  
179 - public Float getExpectStopTime() {  
180 - return expectStopTime;  
181 - }  
182 -  
183 - public void setExpectStopTime(Float expectStopTime) {  
184 - this.expectStopTime = expectStopTime;  
185 - }  
186 -  
187 - public String getLineId() {  
188 - return lineId;  
189 - }  
190 -  
191 - public void setLineId(String lineId) {  
192 - this.lineId = lineId;  
193 - }  
194 -  
195 - public int getVersion() {  
196 - return version;  
197 - }  
198 -  
199 - public void setVersion(int version) {  
200 - this.version = version;  
201 - }  
202 -  
203 - public String getAbnormalStatus() {  
204 - return abnormalStatus;  
205 - }  
206 -  
207 - public void setAbnormalStatus(String abnormalStatus) {  
208 - this.abnormalStatus = abnormalStatus;  
209 - }  
210 -  
211 - public double getOutOfBoundDistance() {  
212 - return outOfBoundDistance;  
213 - }  
214 -  
215 - public void setOutOfBoundDistance(double outOfBoundDistance) {  
216 - this.outOfBoundDistance = outOfBoundDistance;  
217 - }  
218 -  
219 - public int getValid() {  
220 - return valid;  
221 - }  
222 -  
223 - public void setValid(int valid) {  
224 - this.valid = valid;  
225 - }  
226 -  
227 - public String getSectionCode() {  
228 - return sectionCode;  
229 - }  
230 -  
231 - public void setSectionCode(String sectionCode) {  
232 - this.sectionCode = sectionCode;  
233 - }  
234 -} 1 +package com.bsth.server_rs.gps.entity;
  2 +
  3 +import javax.xml.bind.annotation.XmlRootElement;
  4 +import java.io.Serializable;
  5 +
  6 +/**
  7 + *
  8 + * @ClassName: GpsRealData
  9 + * @Description: TODO(HTTP接口的实时GPS数据)
  10 + * @author PanZhao
  11 + * @date 2016年5月11日 下午4:32:07
  12 + *
  13 + */
  14 +@XmlRootElement
  15 +public class GpsEntity implements Serializable{
  16 +
  17 + /** 公司代码 */
  18 + private Integer companyCode;
  19 +
  20 + /** 线路编码 */
  21 + private String lineId;
  22 +
  23 + /** 设备编码 */
  24 + private String deviceId;
  25 +
  26 + /** 停车场编码 */
  27 + private String carparkNo;
  28 +
  29 + /** 站点编码 */
  30 + private String stopNo;
  31 +
  32 + /** 站点名称 */
  33 + private String stationName;
  34 +
  35 + /** 经度 */
  36 + private Float lon;
  37 +
  38 + /** 纬度 */
  39 + private Float lat;
  40 +
  41 + /** 发送时间戳 */
  42 + private Long timestamp;
  43 +
  44 + /** 速度 */
  45 + private Float speed;
  46 +
  47 + /** 方向(角度) */
  48 + private Float direction;
  49 +
  50 + /** 营运状态( 0 营运 ,1 非营运, -1 无效) */
  51 + private Integer state;
  52 +
  53 + /** 上下行(0 上行 , 1 下行 , -1 无效) */
  54 + private Integer upDown;
  55 +
  56 + /** 车辆内部编码 */
  57 + private String nbbm;
  58 +
  59 + /** 预计到达终点时间 */
  60 + private Float expectStopTime;
  61 +
  62 + private int version;
  63 +
  64 + /** 异常状态 */
  65 + private String abnormalStatus;
  66 +
  67 + /** 越界距离 */
  68 + private double outOfBoundDistance;
  69 +
  70 + /** gps是否有效 设备端发送的状态 */
  71 + private int valid;
  72 +
  73 + /** 站内外 (0站外, 1站内, -1无效) */
  74 + private int inOrOutStation;
  75 +
  76 + private String sectionCode;
  77 +
  78 + public Integer getCompanyCode() {
  79 + return companyCode;
  80 + }
  81 +
  82 + public void setCompanyCode(Integer companyCode) {
  83 + this.companyCode = companyCode;
  84 + }
  85 +
  86 + public String getDeviceId() {
  87 + return deviceId;
  88 + }
  89 +
  90 + public void setDeviceId(String deviceId) {
  91 + this.deviceId = deviceId;
  92 + }
  93 +
  94 + public String getCarparkNo() {
  95 + return carparkNo;
  96 + }
  97 +
  98 + public void setCarparkNo(String carparkNo) {
  99 + this.carparkNo = carparkNo;
  100 + }
  101 +
  102 + public String getStopNo() {
  103 + return stopNo;
  104 + }
  105 +
  106 + public void setStopNo(String stopNo) {
  107 + this.stopNo = stopNo;
  108 + }
  109 +
  110 + public Float getLon() {
  111 + return lon;
  112 + }
  113 +
  114 + public void setLon(Float lon) {
  115 + this.lon = lon;
  116 + }
  117 +
  118 + public Float getLat() {
  119 + return lat;
  120 + }
  121 +
  122 + public void setLat(Float lat) {
  123 + this.lat = lat;
  124 + }
  125 +
  126 + public Long getTimestamp() {
  127 + return timestamp;
  128 + }
  129 +
  130 + public void setTimestamp(Long timestamp) {
  131 + this.timestamp = timestamp;
  132 + }
  133 +
  134 + public Float getSpeed() {
  135 + return speed;
  136 + }
  137 +
  138 + public void setSpeed(Float speed) {
  139 + this.speed = speed;
  140 + }
  141 +
  142 + public Float getDirection() {
  143 + return direction;
  144 + }
  145 +
  146 + public void setDirection(Float direction) {
  147 + this.direction = direction;
  148 + }
  149 +
  150 + public Integer getState() {
  151 + return state;
  152 + }
  153 +
  154 + public void setState(Integer state) {
  155 + this.state = state;
  156 + }
  157 +
  158 + public Integer getUpDown() {
  159 + return upDown;
  160 + }
  161 +
  162 + public void setUpDown(Integer upDown) {
  163 + this.upDown = upDown;
  164 + }
  165 +
  166 + public String getNbbm() {
  167 + return nbbm;
  168 + }
  169 +
  170 + public void setNbbm(String nbbm) {
  171 + this.nbbm = nbbm;
  172 + }
  173 +
  174 + public String getStationName() {
  175 + return stationName;
  176 + }
  177 +
  178 + public void setStationName(String stationName) {
  179 + this.stationName = stationName;
  180 + }
  181 +
  182 + public Float getExpectStopTime() {
  183 + return expectStopTime;
  184 + }
  185 +
  186 + public void setExpectStopTime(Float expectStopTime) {
  187 + this.expectStopTime = expectStopTime;
  188 + }
  189 +
  190 + public String getLineId() {
  191 + return lineId;
  192 + }
  193 +
  194 + public void setLineId(String lineId) {
  195 + this.lineId = lineId;
  196 + }
  197 +
  198 + public int getVersion() {
  199 + return version;
  200 + }
  201 +
  202 + public void setVersion(int version) {
  203 + this.version = version;
  204 + }
  205 +
  206 + public String getAbnormalStatus() {
  207 + return abnormalStatus;
  208 + }
  209 +
  210 + public void setAbnormalStatus(String abnormalStatus) {
  211 + this.abnormalStatus = abnormalStatus;
  212 + }
  213 +
  214 + public double getOutOfBoundDistance() {
  215 + return outOfBoundDistance;
  216 + }
  217 +
  218 + public void setOutOfBoundDistance(double outOfBoundDistance) {
  219 + this.outOfBoundDistance = outOfBoundDistance;
  220 + }
  221 +
  222 + public int getValid() {
  223 + return valid;
  224 + }
  225 +
  226 + public void setValid(int valid) {
  227 + this.valid = valid;
  228 + }
  229 +
  230 + public String getSectionCode() {
  231 + return sectionCode;
  232 + }
  233 +
  234 + public void setSectionCode(String sectionCode) {
  235 + this.sectionCode = sectionCode;
  236 + }
  237 +
  238 + public int getInOrOutStation() {
  239 + return inOrOutStation;
  240 + }
  241 +
  242 + public void setInOrOutStation(int inOrOutStation) {
  243 + this.inOrOutStation = inOrOutStation;
  244 + }
  245 +}