Commit c42749a8b19cdbc683c58181181594dd991c8dca

Authored by 潘钊
1 parent 28e47111

update...

Showing 35 changed files with 1292 additions and 3272 deletions

Too many changes to show.

To preserve performance only 35 of 75 files are displayed.

... ... @@ -250,15 +250,6 @@
250 250 <version>1.7.4</version>
251 251 </dependency>
252 252  
253   -
254   - <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId>
255   - <optional>true</optional> </dependency> -->
256   - <dependency>
257   - <groupId>com.vividsolutions</groupId>
258   - <artifactId>jts</artifactId>
259   - <version>1.13</version>
260   - </dependency>
261   -
262 253 <dependency>
263 254 <groupId>org.dbunit</groupId>
264 255 <artifactId>dbunit</artifactId>
... ...
src/main/java/com/bsth/controller/DeviceGpsController.java
1 1 package com.bsth.controller;
2 2  
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.GpsRealData;
  3 +import com.bsth.data.gpsdata_v2.GpsRealData;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
5 5 import com.fasterxml.jackson.core.JsonParseException;
6 6 import com.fasterxml.jackson.databind.JsonMappingException;
7 7 import com.fasterxml.jackson.databind.ObjectMapper;
... ...
src/main/java/com/bsth/controller/gps/GpsController.java
1 1 package com.bsth.controller.gps;
2 2  
3 3 import com.bsth.data.BasicData;
4   -import com.bsth.data.gpsdata.GpsEntity;
5   -import com.bsth.data.gpsdata.GpsRealData;
6   -import com.bsth.entity.excep.Speeding;
  4 +import com.bsth.data.gpsdata_v2.GpsRealData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
7 6 import com.bsth.service.gps.GpsService;
8 7 import com.bsth.service.gps.entity.GpsSpeed;
9   -import com.bsth.util.PageObject;
10 8 import com.google.common.base.Splitter;
11 9 import org.springframework.beans.factory.annotation.Autowired;
12 10 import org.springframework.web.bind.annotation.*;
13 11  
14 12 import javax.servlet.http.HttpServletResponse;
15   -
16 13 import java.text.ParseException;
17 14 import java.util.ArrayList;
18 15 import java.util.List;
... ...
src/main/java/com/bsth/controller/realcontrol/RealMapController.java
1 1 package com.bsth.controller.realcontrol;
2 2  
3   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
4   -import com.bsth.data.gpsdata.arrival.entity.TimedEnableStationRoute;
5 3 import com.bsth.service.realcontrol.RealMapService;
6 4 import org.springframework.beans.factory.annotation.Autowired;
7 5 import org.springframework.web.bind.annotation.RequestMapping;
8   -import org.springframework.web.bind.annotation.RequestMethod;
9 6 import org.springframework.web.bind.annotation.RequestParam;
10 7 import org.springframework.web.bind.annotation.RestController;
11 8  
... ... @@ -77,9 +74,4 @@ public class RealMapController {
77 74 public Map<String, Object> multiSectionRoute(@RequestParam String codeIdx){
78 75 return realMapService.multiSectionRoute(codeIdx);
79 76 }
80   -
81   - @RequestMapping(value = "/lockAndFlxedTimeEnabled", method = RequestMethod.POST)
82   - public void lockAndFlxedTimeEnabled(TimedEnableStationRoute tes){
83   - GeoCacheData.tesMap.put(tes.getLineCode(), tes);
84   - }
85 77 }
... ...
src/main/java/com/bsth/controller/realcontrol/ServiceDataInterface.java
... ... @@ -5,8 +5,8 @@ import com.bsth.data.BasicData;
5 5 import com.bsth.data.directive.DayOfDirectives;
6 6 import com.bsth.data.directive.DirectiveCreator;
7 7 import com.bsth.data.directive.GatewayHttpUtils;
8   -import com.bsth.data.gpsdata.GpsEntity;
9   -import com.bsth.data.gpsdata.GpsRealData;
  8 +import com.bsth.data.gpsdata_v2.GpsRealData;
  9 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
10 10 import com.bsth.data.schedule.DayOfSchedule;
11 11 import com.bsth.entity.directive.D60;
12 12 import com.bsth.entity.realcontrol.ScheduleRealInfo;
... ...
src/main/java/com/bsth/controller/realcontrol/SignalStateController.java
1   -package com.bsth.controller.realcontrol;
2   -
3   -import com.bsth.data.gpsdata.SignalStateData;
4   -import com.bsth.data.gpsdata.arrival.entity.SignalState;
5   -import org.springframework.beans.factory.annotation.Autowired;
6   -import org.springframework.web.bind.annotation.RequestMapping;
7   -import org.springframework.web.bind.annotation.RequestParam;
8   -import org.springframework.web.bind.annotation.RestController;
9   -
10   -import java.util.List;
11   -
12   -/**
13   - * Created by panzhao on 2016/12/30.
14   - */
15   -@RestController
16   -@RequestMapping("signalState")
17   -public class SignalStateController {
18   -
19   - @Autowired
20   - SignalStateData signalStateData;
21   -
22   - @RequestMapping("/multi")
23   - public List<SignalState> findByMultiLine(@RequestParam String idx){
24   - return signalStateData.get(idx);
25   - }
26   -}
  1 +//package com.bsth.controller.realcontrol;
  2 +//
  3 +//import com.bsth.data.gpsdata.SignalStateData;
  4 +//import com.bsth.data.gpsdata.arrival.entity.SignalState;
  5 +//import org.springframework.beans.factory.annotation.Autowired;
  6 +//import org.springframework.web.bind.annotation.RequestMapping;
  7 +//import org.springframework.web.bind.annotation.RequestParam;
  8 +//import org.springframework.web.bind.annotation.RestController;
  9 +//
  10 +//import java.util.List;
  11 +//
  12 +///**
  13 +// * Created by panzhao on 2016/12/30.
  14 +// */
  15 +//@RestController
  16 +//@RequestMapping("signalState")
  17 +//public class SignalStateController {
  18 +//
  19 +// @Autowired
  20 +// SignalStateData signalStateData;
  21 +//
  22 +// @RequestMapping("/multi")
  23 +// public List<SignalState> findByMultiLine(@RequestParam String idx){
  24 +// return signalStateData.get(idx);
  25 +// }
  26 +//}
... ...
src/main/java/com/bsth/controller/realcontrol/anomalyCheckController.java
1 1 package com.bsth.controller.realcontrol;
2 2  
3   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
4   -import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
5   -import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
  3 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  4 +import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
6 5 import com.bsth.data.msg_queue.DirectivePushQueue;
7 6 import com.bsth.data.msg_queue.WebSocketPushQueue;
8 7 import com.bsth.data.schedule.DayOfSchedule;
... ... @@ -59,11 +58,6 @@ public class anomalyCheckController {
59 58 }
60 59 }
61 60  
62   - @RequestMapping(value = "/shutdownThreadPool")
63   - public void shutdownThreadPool(){
64   - GpsRealAnalyse.shutdown();
65   - }
66   -
67 61 @RequestMapping(value = "/directivePushQueue")
68 62 public void directivePushQueue(){
69 63 DirectivePushQueue.start();
... ...
src/main/java/com/bsth/data/BasicData.java
1 1 package com.bsth.data;
2 2  
3   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
  3 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
4 4 import com.bsth.data.pinyin.PersionPinYinBuffer;
5 5 import com.bsth.entity.*;
6 6 import com.bsth.entity.schedule.CarConfigInfo;
... ...
src/main/java/com/bsth/data/ThreadMonotor.java
1 1 package com.bsth.data;
2 2  
3   -import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
4   -import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
5 3 import org.slf4j.Logger;
6 4 import org.slf4j.LoggerFactory;
7 5 import org.springframework.stereotype.Component;
... ... @@ -23,10 +21,10 @@ public class ThreadMonotor extends Thread{
23 21 GpsRealAnalyse.shutdown();
24 22 }*/
25 23  
26   - if(GpsRealAnalyse.isIdle()){
  24 + /*if(GpsRealAnalyse.isIdle()){
27 25 //切换到备用的网关实时GPS对照数据
28 26 GpsDataLoaderThread.setFlag(-1);
29   - }
  27 + }*/
30 28  
31 29 //webSocket 消息推送队列
32 30 /*if(WebSocketPushQueue.isIdle()){
... ...
src/main/java/com/bsth/data/directive/DayOfDirectives.java
... ... @@ -152,13 +152,14 @@ public class DayOfDirectives {
152 152  
153 153 public void clear(String device){
154 154 int c60 = 0, c64 = 0;
155   - //找到该设备的60数据
  155 +
156 156 Collection<D60> d60s = d60Map.values();
157 157 List<D60> rem60List = new ArrayList<>();
158 158 for(D60 d60 : d60s){
159 159 if(device.equals(d60.getDeviceId()))
160 160 rem60List.add(d60);
161 161 }
  162 +
162 163 //清除60数据
163 164 for(D60 d60 : rem60List){
164 165 if(d60.getReply47() == null)
... ... @@ -166,6 +167,8 @@ public class DayOfDirectives {
166 167 if(null != d60Map.remove(d60.getMsgId()))
167 168 c60 ++;
168 169 }
  170 +
  171 + rem60List.clear();
169 172 if(c60 > 0)
170 173 logger.info("清除60数据 ," + c60);
171 174  
... ... @@ -186,6 +189,7 @@ public class DayOfDirectives {
186 189 c64 ++;
187 190 }
188 191  
  192 + rem64List.clear();
189 193 if(c64 > 0)
190 194 logger.info("清除64数据 ," + c64);
191 195 }
... ...
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
... ... @@ -4,8 +4,8 @@ import com.bsth.data.forecast.entity.ForecastResult;
4 4 import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem;
5 5 import com.bsth.data.forecast.entity.SimpleRoute;
6 6 import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;
7   -import com.bsth.data.gpsdata.GpsEntity;
8   -import com.bsth.data.gpsdata.GpsRealData;
  7 +import com.bsth.data.gpsdata_v2.GpsRealData;
  8 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
9 9 import com.bsth.data.schedule.DayOfSchedule;
10 10 import com.bsth.entity.realcontrol.ScheduleRealInfo;
11 11 import com.google.common.collect.ArrayListMultimap;
... ...
src/main/java/com/bsth/data/gpsdata/SignalStateData.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata;
2   -
3   -import com.bsth.data.gpsdata.arrival.entity.SignalState;
4   -import com.bsth.websocket.handler.SendUtils;
5   -import com.google.common.base.Splitter;
6   -import com.google.common.collect.ArrayListMultimap;
7   -import org.springframework.beans.factory.annotation.Autowired;
8   -import org.springframework.stereotype.Component;
9   -
10   -import java.util.ArrayList;
11   -import java.util.List;
12   -
13   -/**
14   - * 信号状态数据
15   - * Created by panzhao on 2016/12/30.
16   - */
17   -@Component
18   -public class SignalStateData {
19   -
20   - @Autowired
21   - SendUtils sendUtils;
22   -
23   - private static ArrayListMultimap<String, SignalState> listMultimap = ArrayListMultimap.create();
24   -
25   - public void put(SignalState state){
26   - //listMultimap.put(state.getLineCode(), state);
27   - //推送到客户端
28   - //sendUtils.sendSignalState(state);
29   - }
30   -
31   - public List<SignalState> get(String idx){
32   - List<SignalState> rs = new ArrayList<>();
33   - List<String> ids = Splitter.on(",").splitToList(idx);
34   -
35   - for(String lineCode : ids){
36   - rs.addAll(listMultimap.get(lineCode));
37   - }
38   - return rs;
39   - }
40   -}
src/main/java/com/bsth/data/gpsdata/arrival/GeoCacheData.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.arrival.entity.StationRoute;
5   -import com.bsth.data.gpsdata.arrival.entity.TimedEnableStationRoute;
6   -import com.bsth.data.gpsdata.arrival.precondition.entity.PreconditionGeo;
7   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
8   -import com.bsth.data.gpsdata.arrival.utils.StationRouteComp;
9   -import com.google.common.base.Splitter;
10   -import com.google.common.collect.ArrayListMultimap;
11   -import com.vividsolutions.jts.geom.Coordinate;
12   -import com.vividsolutions.jts.geom.GeometryFactory;
13   -import com.vividsolutions.jts.geom.LineString;
14   -import com.vividsolutions.jts.geom.Polygon;
15   -import org.apache.commons.lang3.StringUtils;
16   -import org.slf4j.Logger;
17   -import org.slf4j.LoggerFactory;
18   -import org.springframework.beans.factory.annotation.Autowired;
19   -import org.springframework.jdbc.core.BeanPropertyRowMapper;
20   -import org.springframework.jdbc.core.JdbcTemplate;
21   -import org.springframework.jdbc.core.RowMapper;
22   -import org.springframework.stereotype.Component;
23   -
24   -import java.sql.ResultSet;
25   -import java.sql.SQLException;
26   -import java.util.*;
27   -
28   -/**
29   - * Created by panzhao on 2016/12/23.
30   - */
31   -@Component
32   -public class GeoCacheData {
33   -
34   - static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);
35   -
36   - //每辆车缓存最后500条gps
37   - private static final int CACHE_SIZE = 500;
38   - private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>();
39   -
40   - //线路路段走向
41   - private static ArrayListMultimap<String, LineString> sectionCacheMap;
42   -
43   - //路段编码和名称对照
44   - private static Map<String, String> sectionCode2Name;
45   -
46   - //线路站点路由
47   - private static ArrayListMultimap<String, StationRoute> stationCacheMap;
48   - //线路前置进站围栏
49   - public static ArrayListMultimap<String, PreconditionGeo> premiseGeoMap;
50   -
51   - //线路_上下行_站点编码 ——> 站点
52   - private static Map<String, StationRoute> routeCodeMap;
53   -
54   - //停车场
55   - public static Map<String, Polygon> tccMap;
56   - //停车场
57   - public static Map<String, com.bsth.util.Geo.Polygon> tccMap2;
58   -
59   - //线路限速信息
60   - private static Map<String, Double> speedLimitMap;
61   -
62   - //需要定时刷新的站点路由
63   - public static Map<String, TimedEnableStationRoute> tesMap = new HashMap<>();
64   -
65   - @Autowired
66   - JdbcTemplate jdbcTemplate;
67   -
68   - public static CircleQueue<GpsEntity> getGps(String nbbm) {
69   - return gpsCacheMap.get(nbbm);
70   - }
71   -
72   - public static void putGps(GpsEntity gps) {
73   - CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm());
74   - if (queue == null) {
75   - queue = new CircleQueue<>(CACHE_SIZE);
76   - gpsCacheMap.put(gps.getNbbm(), queue);
77   - }
78   - queue.add(gps);
79   - }
80   -
81   - public static void clear(String nbbm) {
82   - try {
83   - CircleQueue<GpsEntity> queue = gpsCacheMap.get(nbbm);
84   - if (queue != null)
85   - queue.clear();
86   - } catch (Exception e) {
87   - logger.error("", e);
88   - }
89   - }
90   -
91   - public static Map<String, String> sectionCode2NameMap(){
92   - return sectionCode2Name;
93   - }
94   -
95   - public static StationRoute getRouteCode(GpsEntity gps) {
96   - return routeCodeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo());
97   - }
98   -
99   - public static List<StationRoute> getStationRoute(String lineCode, int directions) {
100   - return stationCacheMap.get(lineCode + "_" + directions);
101   - }
102   -
103   - public static StationRoute getStation(String lineCode, int directions, String code) {
104   - List<StationRoute> list = getStationRoute(lineCode, directions);
105   -
106   - for (StationRoute sr : list) {
107   - if (sr.getCode().equals(code)) {
108   - return sr;
109   - }
110   - }
111   - return null;
112   - }
113   -
114   - public static Double speedLimit(String lineCode){
115   - return speedLimitMap.get(lineCode);
116   - }
117   -
118   - public static List<LineString> getLineStringList(GpsEntity gps){
119   - return sectionCacheMap.get(gps.getLineId() + "_" + gps.getUpDown());
120   - }
121   -
122   - public static List<StationRoute> midwayStation(String lineCode, int directions, String sCode, String eCode) {
123   - List<StationRoute> list = getStationRoute(lineCode, directions), rs = new ArrayList<>();
124   -
125   - boolean flag = false;
126   - for (StationRoute sr : list) {
127   - if (flag)
128   - rs.add(sr);
129   - if (sr.getCode().equals(sCode))
130   - flag = true;
131   - else if (sr.getCode().equals(eCode))
132   - break;
133   - }
134   - return rs;
135   - }
136   -
137   - public static Polygon getTccPolygon(String code) {
138   - return tccMap.get(code);
139   - }
140   -
141   - GeometryFactory geometryFactory = new GeometryFactory();
142   - public void loadData() {
143   - loadStationRoutesData();
144   - loadTccMapData();
145   - loadSpeedLimit();
146   -
147   - //加载路段信息
148   - loadRoadsData();
149   -
150   - //加载前置进站围栏
151   - loadPremiseGeoData();
152   - }
153   -
154   - private void loadPremiseGeoData() {
155   - ArrayListMultimap<String, PreconditionGeo> premiseGeoMapCopy = ArrayListMultimap.create();
156   -
157   - String sql = "select * from bsth_f_geo_premise";
158   - List<PreconditionGeo> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PreconditionGeo.class));
159   -
160   - List<String> coordList;
161   - String[] cs;
162   - com.bsth.util.Geo.Point point;
163   - List<com.bsth.util.Geo.Point> ps;
164   - StationRoute sr;
165   - for(PreconditionGeo p : list){
166   - try{
167   - sr = routeCodeMap.get(p.getLineCode()+"_"+p.getUpDown()+"_"+p.getStationCode());
168   - p.setOrder(sr.getRouteSort());
169   - //polygon
170   - ps = new ArrayList<>();
171   - coordList = Splitter.on(",").trimResults().splitToList(p.getCoords());
172   - for(String c : coordList){
173   - cs = c.split(" ");
174   - point = new com.bsth.util.Geo.Point(Double.parseDouble(cs[0]), Double.parseDouble(cs[1]));
175   - ps.add(point);
176   - }
177   -
178   - p.setPolygon(new com.bsth.util.Geo.Polygon(ps));
179   -
180   - sr.setPremise(true);
181   - //按线路,走向分组
182   - premiseGeoMapCopy.put(p.getLineCode()+"_"+p.getUpDown(), p);
183   - }catch (Exception e){
184   - logger.error("", e);
185   - }
186   - }
187   -
188   - //排序
189   - Set<String> ks = premiseGeoMapCopy.keySet();
190   - PreconditionGeoComp comp = new PreconditionGeoComp();
191   - for(String k : ks){
192   - Collections.sort(premiseGeoMapCopy.get(k), comp);
193   - }
194   -
195   - premiseGeoMap = premiseGeoMapCopy;
196   - }
197   -
198   - private static class PreconditionGeoComp implements Comparator<PreconditionGeo>{
199   -
200   - @Override
201   - public int compare(PreconditionGeo p1, PreconditionGeo p2) {
202   - return p1.getOrder() - p2.getOrder();
203   - }
204   - }
205   -
206   - private void loadRoadsData() {
207   - //加载线路下路段空间数据
208   - String sql = "select r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) as GSECTION_VECTOR, r.DIRECTIONS, s.CROSES_ROAD from bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section=s.id where r.destroy=0 and GSECTION_VECTOR is not null order by line_code,directions,sectionroute_code";
209   - List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql);
210   -
211   - String polygonStr, key;
212   - String[] coords;
213   - int i, len;
214   - ArrayListMultimap<String, LineString> sectionCacheTempMap = ArrayListMultimap.create();
215   - Coordinate[] cds;
216   - String[] temps1, temps2;
217   - for (Map<String, Object> tMap : secList) {
218   - //空间数据映射
219   - polygonStr = tMap.get("GSECTION_VECTOR").toString();
220   - key = tMap.get("LINE_CODE") + "_" + tMap.get("DIRECTIONS");
221   -
222   - coords = polygonStr.substring(11, polygonStr.length() - 1).split(",");
223   - len = coords.length - 1;
224   - //每2个点连一条线
225   - for(i = 0; i < len; i ++){
226   - temps1 = coords[i].split(" ");
227   - temps2 = coords[i + 1].split(" ");
228   -
229   - cds = new Coordinate[2];
230   - cds[0] = new Coordinate(Float.parseFloat(temps1[1]), Float.parseFloat(temps1[0]));
231   - cds[1] = new Coordinate(Float.parseFloat(temps2[1]), Float.parseFloat(temps2[0]));
232   -
233   - sectionCacheTempMap.put(key, geometryFactory.createLineString(cds));
234   - }
235   - }
236   -
237   - if(sectionCacheTempMap.size() > 0)
238   - sectionCacheMap = sectionCacheTempMap;
239   -
240   - Map<String, String> sectionCode2NameTemp = new HashMap<>();
241   -
242   - //加载全量路段编码和名称对照
243   - sql = "select SECTION_CODE,SECTION_NAME,CROSES_ROAD from bsth_c_section";
244   - secList = jdbcTemplate.queryForList(sql);
245   - String name = null, code;
246   - for (Map<String, Object> tMap : secList) {
247   - if(tMap.get("CROSES_ROAD") != null && StringUtils.isNotEmpty(tMap.get("CROSES_ROAD").toString()))
248   - name = tMap.get("CROSES_ROAD").toString();
249   - else if(tMap.get("SECTION_NAME") != null && StringUtils.isNotEmpty(tMap.get("SECTION_NAME").toString()))
250   - name = tMap.get("SECTION_NAME").toString();
251   -
252   - code = tMap.get("SECTION_CODE").toString();
253   - sectionCode2NameTemp.put(code, name);
254   - }
255   - if(sectionCode2NameTemp.size() > 0)
256   - sectionCode2Name = sectionCode2NameTemp;
257   - }
258   -
259   - private void loadTccMapData(){
260   - //加载停车场数据
261   - String sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null";
262   - List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
263   - Map<String, Polygon> tccTempMap = new HashMap<>();
264   -
265   - Polygon polygon;
266   - for (Map<String, Object> tMap : tccList) {
267   -
268   - try {
269   - polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString()));
270   - tccTempMap.put(tMap.get("PARK_CODE").toString()
271   - , polygon);
272   - } catch (Exception e) {
273   - logger.error("停车场:" + tMap.get("PARK_CODE"), e);
274   - }
275   - }
276   - if (tccTempMap.size() > 0){
277   - tccMap = tccTempMap;
278   - tccMap2 = convertPolygonMap(tccMap);
279   - }
280   - }
281   -
282   - private Map<String, com.bsth.util.Geo.Polygon> convertPolygonMap(Map<String, Polygon> tccMap) {
283   - Map<String, com.bsth.util.Geo.Polygon> rsMap = new HashMap<>();
284   - Set<String> ks = tccMap.keySet();
285   - for(String k : ks){
286   - rsMap.put(k, convertPolygon(tccMap.get(k)));
287   - }
288   - return rsMap;
289   - }
290   -
291   - public static com.bsth.util.Geo.Polygon convertPolygon(Polygon polygon) {
292   - List<com.bsth.util.Geo.Point> ps = new ArrayList<>();
293   - com.bsth.util.Geo.Point p;
294   -
295   - Coordinate[] cs = polygon.getCoordinates();
296   - for(int i = 0; i < cs.length;i ++){
297   - p = new com.bsth.util.Geo.Point(cs[i].y, cs[i].x);
298   - ps.add(p);
299   - }
300   - return new com.bsth.util.Geo.Polygon(ps);
301   - }
302   -
303   - private void loadStationRoutesData(){
304   - //加载站点路由
305   - String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE,s.STATION_NAME from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code";
306   - List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
307   - @Override
308   - public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
309   - StationRoute sRoute = new StationRoute();
310   - sRoute.setCode(rs.getString("STATION_CODE"));
311   - sRoute.setLineCode(rs.getString("LINE_CODE"));
312   - sRoute.setDirections(rs.getInt("DIRECTIONS"));
313   - sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX"))));
314   - sRoute.setRadius(rs.getFloat("RADIUS"));
315   - sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
316   - sRoute.setMark(rs.getString("STATION_MARK"));
317   - sRoute.setName(rs.getString("STATION_NAME"));
318   -
319   - String shapesType = rs.getString("SHAPES_TYPE");
320   - //多边形电子围栏
321   - if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {
322   - sRoute.setPolygon(geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID"))));
323   - }
324   - return sRoute;
325   - }
326   - });
327   - //按线路和走向分组
328   - if (routeList.size() > 0) {
329   - ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
330   - Map<String, StationRoute> codeMap = new HashMap<>(routeList.size());
331   - for (StationRoute sr : routeList) {
332   - tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
333   - //站点编码 ——> 和路由顺序对照
334   - codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr);
335   - }
336   -
337   - StationRouteComp srCom = new StationRouteComp();
338   - //连接路由
339   - Set<String> set = tempMap.keySet();
340   - for (String key : set) {
341   - Collections.sort(tempMap.get(key), srCom);
342   - connectStationRoute(tempMap.get(key));
343   - }
344   -
345   - //定时启用的站点走向
346   - if(tesMap.size() > 0){
347   - List<String> rems = new ArrayList<>();
348   - long t = System.currentTimeMillis();
349   - for(TimedEnableStationRoute tes : tesMap.values()){
350   - if(tes.getEnableTime() > t){
351   - logger.info("锁住站点路由," + tes.getLineCode());
352   - tempMap.replaceValues(tes.getLineCode() + "_0", stationCacheMap.get(tes.getLineCode() + "_0"));
353   - tempMap.replaceValues(tes.getLineCode() + "_1", stationCacheMap.get(tes.getLineCode() + "_1"));
354   - }
355   - else
356   - rems.add(tes.getLineCode());
357   - }
358   -
359   - //remove
360   - if(rems.size() > 0){
361   - for(String lineCode : rems){
362   - logger.info("启用路由," + lineCode);
363   - tesMap.remove(lineCode);
364   - }
365   - }
366   - }
367   - stationCacheMap = tempMap;
368   - routeCodeMap = codeMap;
369   - }
370   - }
371   -
372   - private void loadSpeedLimit(){
373   - //加载线路限速信息
374   - String sql = "select l.LINE_CODE,i.SPEEDING from bsth_c_line_information i left join bsth_c_line l on i.line=l.id where i.speed_limit is not null";
375   - List<Map<String, Object>> speedMap = jdbcTemplate.queryForList(sql);
376   - Map<String, Double> speedTempMap = new HashMap<>();
377   - for (Map<String, Object> tMap : speedMap) {
378   - try {
379   - speedTempMap.put(tMap.get("LINE_CODE").toString(), Double.parseDouble(tMap.get("SPEEDING").toString()));
380   - } catch (NumberFormatException e) {
381   - logger.error("speeding is null...");
382   - }
383   - }
384   - speedLimitMap = speedTempMap;
385   - }
386   -
387   - private void connectStationRoute(List<StationRoute> list) {
388   - int size = list.size();
389   - StationRoute sr = null;
390   - for (int i = 0; i < size; i++) {
391   - sr = list.get(i);
392   - //上一个
393   - if (i > 0)
394   - sr.setPrve(list.get(i - 1));
395   - //下一个
396   - if (i < size - 1)
397   - sr.setNext(list.get(i + 1));
398   - }
399   - }
400   -
401   - public Coordinate[] parsePolygon(String polygonStr) {
402   - String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
403   -
404   - Coordinate[] cds = new Coordinate[coords.length];
405   - int len = coords.length;
406   - for (int i = 0; i < len; i++) {
407   - temps = coords[i].split(" ");
408   - cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0]));
409   - }
410   - return cds;
411   - }
412   -
413   - /**
414   - * 是不是终点站
415   - *
416   - * @param lineId
417   - * @param upDown
418   - * @param stationCode
419   - * @return
420   - */
421   - public static boolean isEndStation(String lineId, Byte upDown, String stationCode) {
422   - StationRoute station = routeCodeMap.get(lineId + "_" + upDown + "_" + stationCode);
423   - return station != null && station.getMark().equals("E");
424   - }
425   -}
426 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/SignalHandle.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.arrival.entity.StationRoute;
5   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
6   -import com.bsth.data.gpsdata.arrival.utils.GeoUtils;
7   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
8   -import org.joda.time.format.DateTimeFormat;
9   -import org.joda.time.format.DateTimeFormatter;
10   -import org.slf4j.Logger;
11   -import org.slf4j.LoggerFactory;
12   -
13   -import java.util.List;
14   -
15   -/**
16   - * Created by panzhao on 2016/12/27.
17   - */
18   -public abstract class SignalHandle {
19   -
20   - public abstract boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs);
21   -
22   - protected boolean isNotEmpty(CircleQueue<GpsEntity> prevs) {
23   - return prevs != null && prevs.size() > 0 && prevs.getTail() != null;
24   - }
25   -
26   -/* protected boolean isDriftSignal(GpsEntity gps) {
27   - return gps.getLat() == 0 || gps.getLon() == 0;
28   - }*/
29   -
30   - /**
31   - * gps掉线
32   - * @param gps
33   - * @return
34   - */
35   - protected boolean isGpsOffline(GpsEntity gps){
36   - return gps.getLat() == 0 || gps.getLon() == 0;
37   - }
38   -
39   - protected boolean isOffline(GpsEntity gps){
40   - return gps.getAbnormalStatus() != null && gps.getAbnormalStatus().equals("offline");
41   - }
42   - /**
43   - * 是不是异常信号
44   - *
45   - * @param gps
46   - * @return protected boolean isAbnormal(GpsEntity gps) {
47   - return gps.getLat() == 0 || gps.getLon() == 0;
48   - }*/
49   -
50   - /**
51   - * 连续异常信号个数统计
52   - *
53   - * @param
54   - * @return protected int abnormalCount(CircleQueue<GpsEntity> prevs) {
55   - * int count = 0;
56   - * <p>
57   - * if (!isNotEmpty(prevs))
58   - * return count;
59   - * <p>
60   - * GpsEntity[] array = (GpsEntity[]) prevs.getQueue();
61   - * GpsEntity gps;
62   - * for (int i = array.length - 1; i > 0; i--) {
63   - * gps = array[i];
64   - * <p>
65   - * if (isAbnormal(gps))
66   - * count++;
67   - * else
68   - * break;
69   - * }
70   - * <p>
71   - * return count;
72   - * }
73   - */
74   -
75   - Logger logger = LoggerFactory.getLogger(this.getClass());
76   - private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm");
77   - protected void transformUpdown(GpsEntity gps, ScheduleRealInfo sch) {
78   - byte updown = Byte.parseByte(sch.getXlDir());
79   - //gps 切换走向
80   - gps.setUpDown(updown);
81   - gps.setPremiseCode(null);
82   -
83   - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), updown);
84   - StationRoute station = GeoUtils.gpsInStation(gps, srs);
85   - if (station != null) {
86   - gps.setStopNo(station.getCode());
87   - }
88   -
89   - logger.info(gps.getTimestamp() + " -" + fmtHHmm.print(gps.getTimestamp()) + " 车辆 :" + gps.getNbbm() + " 切换到走向 : " + updown);
90   - }
91   -
92   - /**
93   - * 是否是从异常状态恢复的第一个信号
94   - *
95   - * @param gps
96   - * @param prevs
97   - * @return
98   - */
99   - protected boolean abnormalRecovery(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
100   - if (prevs == null || prevs.size() == 0)
101   - return false;
102   -
103   - GpsEntity prev = prevs.getTail();
104   - //从异常状态恢复
105   - if (isGpsOffline(prev)
106   - && !isGpsOffline(gps)) {
107   - return true;
108   - }
109   -
110   - return false;
111   - }
112   -}
113 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/entity/ArrivalInfo.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.entity;
2   -
3   -/**
4   - * 到离站信息
5   - * Created by panzhao on 2017/2/20.
6   - */
7   -public class ArrivalInfo {
8   -
9   - private String lineCode;
10   -
11   - private String deviceId;
12   -
13   - /** 时间戳 */
14   - private Long ts;
15   -
16   - private String stop;
17   -
18   - private Integer upDown;
19   -
20   - private int inOut;
21   -
22   -
23   -}
src/main/java/com/bsth/data/gpsdata/arrival/entity/RouteReverse.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.entity;
2   -
3   -/** 路由反转
4   - * Created by panzhao on 2016/12/28.
5   - */
6   -public class RouteReverse {
7   -
8   - private String nbbm;
9   - //反转个数
10   - private int count;
11   -
12   - //详细 1,2,3,2,1
13   - private String detail;
14   -
15   - //掉头站点
16   - private String turned;
17   -
18   - //掉头时间
19   - private long zt;
20   -
21   - //检测时间
22   - private long ct;
23   -
24   - //是否闭合
25   - private boolean close;
26   -
27   - //信号不明确
28   - private boolean vague;
29   -
30   - public int getCount() {
31   - return count;
32   - }
33   -
34   - public void setCount(int count) {
35   - this.count = count;
36   - }
37   -
38   - public String getDetail() {
39   - return detail;
40   - }
41   -
42   - public void setDetail(String detail) {
43   - this.detail = detail;
44   - }
45   -
46   - public String getTurned() {
47   - return turned;
48   - }
49   -
50   - public void setTurned(String turned) {
51   - this.turned = turned;
52   - }
53   -
54   - public boolean isClose() {
55   - return close;
56   - }
57   -
58   - public void setClose(boolean close) {
59   - this.close = close;
60   - }
61   -
62   - public long getZt() {
63   - return zt;
64   - }
65   -
66   - public void setZt(long zt) {
67   - this.zt = zt;
68   - }
69   -
70   - public long getCt() {
71   - return ct;
72   - }
73   -
74   - public void setCt(long ct) {
75   - this.ct = ct;
76   - }
77   -
78   - public String getNbbm() {
79   - return nbbm;
80   - }
81   -
82   - public void setNbbm(String nbbm) {
83   - this.nbbm = nbbm;
84   - }
85   -
86   - public boolean isVague() {
87   - return vague;
88   - }
89   -
90   - public void setVague(boolean vague) {
91   - this.vague = vague;
92   - }
93   -}
94 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/entity/SignalAbnormal.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.entity;
2   -
3   -/**
4   - * 班次信号异常(漂移 或 断线)
5   - * Created by panzhao on 2016/12/31.
6   - */
7   -public class SignalAbnormal {
8   -
9   - private Long et;
10   -
11   - /** drift or reconnection */
12   - private String abnormalType;
13   -
14   - private Long st;
15   -
16   - private String nearPoint;
17   -
18   - private String destCode;
19   -
20   - private Long ct;
21   -
22   - //0: 发车 1:到站
23   - private int outOrIn;
24   -
25   - public Long getEt() {
26   - return et;
27   - }
28   -
29   - public void setEt(Long et) {
30   - this.et = et;
31   - }
32   -
33   - public String getAbnormalType() {
34   - return abnormalType;
35   - }
36   -
37   - public void setAbnormalType(String abnormalType) {
38   - this.abnormalType = abnormalType;
39   - }
40   -
41   - public Long getSt() {
42   - return st;
43   - }
44   -
45   - public void setSt(Long st) {
46   - this.st = st;
47   - }
48   -
49   - public String getNearPoint() {
50   - return nearPoint;
51   - }
52   -
53   - public void setNearPoint(String nearPoint) {
54   - this.nearPoint = nearPoint;
55   - }
56   -
57   - public Long getCt() {
58   - return ct;
59   - }
60   -
61   - public void setCt(Long ct) {
62   - this.ct = ct;
63   - }
64   -
65   - public int getOutOrIn() {
66   - return outOrIn;
67   - }
68   -
69   - public void setOutOrIn(int outOrIn) {
70   - this.outOrIn = outOrIn;
71   - }
72   -
73   - public String getDestCode() {
74   - return destCode;
75   - }
76   -
77   - public void setDestCode(String destCode) {
78   - this.destCode = destCode;
79   - }
80   -}
src/main/java/com/bsth/data/gpsdata/arrival/entity/SignalState.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.entity;
2   -
3   -import com.bsth.data.BasicData;
4   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
5   -import org.joda.time.format.DateTimeFormat;
6   -import org.joda.time.format.DateTimeFormatter;
7   -
8   -/**
9   - * 信号状态
10   - * Created by panzhao on 2016/12/30.
11   - */
12   -public class SignalState {
13   -
14   - private String type;
15   -
16   - private Long st;
17   -
18   - //private Long checkTime;
19   -
20   - private Long schId;
21   -
22   - private String lineCode;
23   -
24   - private String text;
25   -
26   - private RouteReverse reverse;
27   -
28   - private SignalAbnormal signalAbnormal;
29   -
30   - private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm");
31   -
32   - /**
33   - * 记录区间调头
34   - *
35   - * @param sch
36   - * @param reverse
37   - * @return
38   - */
39   - public static SignalState reverseSignalSTate(ScheduleRealInfo sch, RouteReverse reverse) {
40   - /*if(reverse.isVague())
41   - return null;*/
42   -
43   - SignalState state = new SignalState();
44   - state.setSchId(sch.getId());
45   - state.setType("route_reverse");
46   - //state.setCheckTime(System.currentTimeMillis());
47   -
48   - String stationName = BasicData.stationCode2NameMap.get(sch.getXlBm() + "_" + sch.getXlDir() + "_" + reverse.getTurned());
49   - state.setText(fmtHHmm.print(reverse.getZt()) + " 从 " + stationName + " 站掉头");
50   - state.setSt(sch.getFcsjActualTime());
51   - state.setLineCode(sch.getXlBm());
52   - state.setReverse(reverse);
53   - return state;
54   - }
55   -
56   - public static SignalState abnormalSignalSTate(ScheduleRealInfo sch, SignalAbnormal signalAbnormal) {
57   - SignalState state = new SignalState();
58   - state.setSchId(sch.getId());
59   - state.setType("abnormal_signal");
60   - //state.setCheckTime(signalAbnormal.getCt());
61   - state.setLineCode(sch.getXlBm());
62   -
63   - String text = (fmtHHmm.print(signalAbnormal.getSt()) + " ~ " + fmtHHmm.print(signalAbnormal.getEt()));
64   - String abnormType = signalAbnormal.getAbnormalType();
65   - if (abnormType.equals("drift"))
66   - text += "(GPS无效)";
67   - else if (abnormType.equals("reconnection"))
68   - text += "(信号丢失)";
69   -
70   - state.setText(text);
71   - state.setSignalAbnormal(signalAbnormal);
72   - return state;
73   - }
74   -
75   - public String getType() {
76   - return type;
77   - }
78   -
79   - public void setType(String type) {
80   - this.type = type;
81   - }
82   -
83   - public long getSchId() {
84   - return schId;
85   - }
86   -
87   - public void setSchId(long schId) {
88   - this.schId = schId;
89   - }
90   -
91   - public String getLineCode() {
92   - return lineCode;
93   - }
94   -
95   - public void setLineCode(String lineCode) {
96   - this.lineCode = lineCode;
97   - }
98   -
99   - public Long getSt() {
100   - return st;
101   - }
102   -
103   - public void setSt(Long st) {
104   - this.st = st;
105   - }
106   -
107   - public String getText() {
108   - return text;
109   - }
110   -
111   - public void setText(String text) {
112   - this.text = text;
113   - }
114   -
115   - public RouteReverse getReverse() {
116   - return reverse;
117   - }
118   -
119   - public void setReverse(RouteReverse reverse) {
120   - this.reverse = reverse;
121   - }
122   -
123   - public SignalAbnormal getSignalAbnormal() {
124   - return signalAbnormal;
125   - }
126   -
127   - public void setSignalAbnormal(SignalAbnormal signalAbnormal) {
128   - this.signalAbnormal = signalAbnormal;
129   - }
130   -}
src/main/java/com/bsth/data/gpsdata/arrival/entity/TimedEnableStationRoute.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.entity;
2   -
3   -/**
4   - * 定时启用站点路由
5   - * Created by panzhao on 2017/8/28.
6   - */
7   -public class TimedEnableStationRoute {
8   -
9   - private String lineCode;
10   -
11   - private Long enableTime;
12   -
13   - public String getLineCode() {
14   - return lineCode;
15   - }
16   -
17   - public void setLineCode(String lineCode) {
18   - this.lineCode = lineCode;
19   - }
20   -
21   - public Long getEnableTime() {
22   - return enableTime;
23   - }
24   -
25   - public void setEnableTime(Long enableTime) {
26   - this.enableTime = enableTime;
27   - }
28   -}
src/main/java/com/bsth/data/gpsdata/arrival/handlers/CorrectSignalHandle.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.handlers;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.arrival.SignalHandle;
5   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
6   -import com.bsth.data.gpsdata.status_manager.GpsStatusManager;
7   -import com.bsth.data.schedule.DayOfSchedule;
8   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
9   -import com.bsth.service.directive.DirectiveService;
10   -import org.slf4j.Logger;
11   -import org.slf4j.LoggerFactory;
12   -import org.springframework.beans.factory.annotation.Autowired;
13   -import org.springframework.stereotype.Component;
14   -
15   -/**
16   - * 信号状态纠正
17   - * Created by panzhao on 2016/12/27.
18   - */
19   -@Component
20   -public class CorrectSignalHandle extends SignalHandle {
21   -
22   - @Autowired
23   - DayOfSchedule dayOfSchedule;
24   - @Autowired
25   - DirectiveService directiveService;
26   -
27   - @Autowired
28   - GpsStatusManager gpsStatusManager;
29   -
30   - Logger logger = LoggerFactory.getLogger(this.getClass());
31   -
32   - @Override
33   - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
34   - ScheduleRealInfo task = dayOfSchedule.executeCurr(gps.getNbbm());
35   - if(task == null)
36   - return false;
37   - //ScheduleRealInfo sch;
38   -
39   - //子任务
40   - /*if(task.getClass().isAssignableFrom(ChildTaskPlan.class)){
41   - ChildTaskPlan childTask = (ChildTaskPlan) task;
42   - sch = childTask.getSchedule();
43   - }
44   - else
45   - sch = (ScheduleRealInfo) task;*/
46   -
47   - byte updown = Byte.parseByte(task.getXlDir());
48   - //走向
49   - if(gps.getUpDown() != updown){
50   - gps.setUpDown(updown);
51   - //gps.setState(0);
52   - }
53   -
54   - //(转发的数据不管)
55   - if(gps.getSource() != 0){
56   - //gps=非营运 或走向不对 && 班次=非空驶 ;切换到营运状态
57   - if((!gps.isService() || gps.getUpDown() != updown) &&
58   - !dayOfSchedule.emptyService(task)){
59   - gpsStatusManager.changeServiceState(gps.getNbbm(), updown, 0, "同步@系统");
60   - }
61   -
62   - //需要切换线路
63   - if(!task.getXlBm().equals(gps.getLineId())){
64   - gpsStatusManager.changeLine(gps.getNbbm(), task.getXlBm(), "同步@系统");
65   - }
66   - }
67   -
68   - return true;
69   - }
70   -}
71 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/handlers/InOutStationSignalHandle.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.handlers;
2   -
3   -import com.bsth.data.LineConfigData;
4   -import com.bsth.data.gpsdata.GpsEntity;
5   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
6   -import com.bsth.data.gpsdata.arrival.SignalHandle;
7   -import com.bsth.data.gpsdata.arrival.entity.StationRoute;
8   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
9   -import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState;
10   -import com.bsth.data.gpsdata.arrival.utils.SignalSchPlanMatcher;
11   -import com.bsth.data.gpsdata.status_manager.GpsStatusManager;
12   -import com.bsth.data.msg_queue.DirectivePushQueue;
13   -import com.bsth.data.schedule.DayOfSchedule;
14   -import com.bsth.data.schedule.ScheduleComparator;
15   -import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
16   -import com.bsth.entity.realcontrol.LineConfig;
17   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
18   -import com.bsth.websocket.handler.SendUtils;
19   -import org.apache.commons.lang3.StringUtils;
20   -import org.slf4j.Logger;
21   -import org.slf4j.LoggerFactory;
22   -import org.springframework.beans.factory.annotation.Autowired;
23   -import org.springframework.stereotype.Component;
24   -
25   -import java.util.Collections;
26   -import java.util.List;
27   -
28   -/**
29   - * 进出站动作处理
30   - * Created by panzhao on 2016/12/27.
31   - */
32   -@Component
33   -public class InOutStationSignalHandle extends SignalHandle{
34   -
35   - Logger logger = LoggerFactory.getLogger(this.getClass());
36   -
37   - @Autowired
38   - DayOfSchedule dayOfSchedule;
39   -
40   - @Autowired
41   - LineConfigData lineConfigData;
42   -
43   - @Autowired
44   - SendUtils sendUtils;
45   -
46   - @Autowired
47   - ScheduleSignalState scheduleSignalState;
48   -
49   - @Autowired
50   - SignalSchPlanMatcher signalSchPlanMatcher;
51   -
52   - @Autowired
53   - GpsStatusManager gpsStatusManager;
54   -
55   - private final static int MAX_BEFORE_TIME = 1000 * 60 * 120;
56   -
57   - //最大的班次时间差,防止异常的GPS时间打乱数据
58   - private final static int MAX_NORMAL_DIFF = 1000 * 60 * 60 * 12;
59   -
60   - @Override
61   - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
62   - //忽略掉线信号
63   - if(isGpsOffline(gps))
64   - return false;
65   -
66   - /*//从异常状态恢复的第一个信号*/
67   - if(abnormalRecovery(gps, prevs)){
68   - //回溯一下之前的轨迹
69   - //scheduleSignalState.signalRetrospect(gps);
70   - return false;
71   - }
72   -
73   - try{
74   - if(isNotEmpty(prevs)){
75   - GpsEntity prev = prevs.getTail();
76   - if(isOutStation(gps, prev))
77   - outStation(gps, prev);
78   -
79   -
80   - if(isInStation(gps, prev))
81   - inStation(gps, prev);
82   - }
83   - }catch (Exception e){
84   - logger.error("in out error info ..", e);
85   - }
86   -
87   - return true;
88   - }
89   -
90   - private boolean isOutStation(GpsEntity gps, GpsEntity prev){
91   - //从站内到站外
92   - if(prev.getInstation() > 0 && gps.getInstation() == 0)
93   - return true;
94   -
95   - //从站内到另一个站内
96   - if(prev.getInstation() > 0 && gps.getInstation() > 0
97   - && !prev.getStopNo().equals(gps.getStopNo()))
98   - return true;
99   -
100   - //在被起点站覆盖的情况下出场
101   - if(isOutPark(gps, prev)){
102   - return true;
103   - }
104   - return false;
105   - }
106   -
107   - private boolean isInStation(GpsEntity gps, GpsEntity prev){
108   - //从站外到站内
109   - if(prev.getInstation() == 0 && gps.getInstation() > 0
110   - /*&& !prev.getStopNo().equals(gps.getStopNo())*/){
111   - return true;
112   - }
113   -
114   - //从站内到另一个站内
115   - if(prev.getInstation() == 1 && gps.getInstation() == 1
116   - && !prev.getStopNo().equals(gps.getStopNo())
117   - && !prev.getStation().getName().equals(gps.getStation().getName()))
118   - return true;
119   -
120   - //从场内到站内
121   - if(prev.getInstation() == 2 && gps.getInstation() == 1){
122   - return true;
123   - }
124   -
125   - //被起点站覆盖的情况下进场
126   - if(isInPark(gps, prev))
127   - return true;
128   - return false;
129   - }
130   -
131   - /**
132   - * 出站/出场
133   - * @param gps 当前点
134   - * @param prev 上一个点
135   - */
136   - private void outStation(GpsEntity gps, GpsEntity prev) {
137   - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
138   - String qdzCode = sch.getQdzCode();
139   -
140   - int diff = (int) (sch.getDfsjT() - gps.getTimestamp());
141   -
142   - //首班出场最多提前2小时
143   - if((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2)
144   - return;
145   -
146   - //正常班次最大时间差
147   - if(Math.abs(diff) > MAX_NORMAL_DIFF)
148   - return;
149   -
150   - //起点发车
151   - if(qdzCode != null
152   - && prev.getStopNo().equals(qdzCode)
153   - && (gps.getInstation()==0 || !gps.getStopNo().equals(prev.getStopNo()))
154   - && !willDepart(gps, prev, sch)){
155   -
156   - gps.setPremiseCode(null);
157   - //发车班次匹配
158   - signalSchPlanMatcher.outMatch(gps, sch);
159   - sch = dayOfSchedule.executeCurr(gps.getNbbm());
160   -
161   - //班次已经实发
162   - if(StringUtils.isNotEmpty(sch.getFcsjActual())
163   - && !outManyFit(gps, sch)){
164   - return;
165   - }
166   -
167   - //应用到离站缓冲区设置参数
168   - long rsT = lineConfigData.applyOut(sch, gps.getTimestamp());
169   -
170   - //实发时间
171   - sch.setFcsjActualAll(rsT);
172   - sch.setSiginCompate(1);
173   -
174   - //出站既出场
175   - outStationAndOutPark(sch);
176   - //通知客户端
177   - sendUtils.sendFcsj(sch);
178   - //持久化
179   - dayOfSchedule.save(sch);
180   -
181   - //清理应发未发标记
182   - LateAdjustHandle.remove(sch.getClZbh());
183   -
184   - if(!gps.isService() && !dayOfSchedule.emptyService(sch)){
185   - //切换成营运状态
186   - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统");
187   - }
188   -
189   - logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
190   - }
191   - else if(isOutSch(sch)){
192   - //有出场动作(起点站覆盖停车场时,并且不设置出站既出场,逻辑可能会走到这里)
193   - try{
194   - if(isOutPark(gps, prev)){
195   - if(prev.getCarparkNo().equals(sch.getQdzCode())){
196   - //再试一下出场
197   - GpsEntity prevClone = (GpsEntity) prev.clone(),
198   - gpsClone = (GpsEntity) gps.clone();
199   - prevClone.setStopNo(prevClone.getCarparkNo());
200   - gpsClone.setInstation(0);
201   - outStation(gpsClone, prevClone);
202   - return;
203   - }
204   - }
205   - }catch (Exception e){logger.error("",e);}
206   -
207   - ScheduleRealInfo next = dayOfSchedule.nextSame(sch);
208   - //如果下一个班次是区间,并且是环线
209   - if(next != null && next.getBcType().equals("region")){
210   - next = dayOfSchedule.nextSame(next);
211   - if(next == null || !next.getQdzName().equals(next.getZdzName())){
212   - return;
213   - }
214   - }
215   - if(next != null && prev.getStopNo().equals(next.getQdzCode())){
216   - //发下一个班次
217   - if(dayOfSchedule.addExecPlan(next))
218   - outStation(gps, prev);
219   - }
220   - }
221   - //当前班次是区间
222   - else if(sch.getBcType().equals("region")){
223   - ScheduleRealInfo next = dayOfSchedule.nextSame(sch);
224   - if(next==null || !next.getQdzName().equals(next.getZdzName())){
225   - return;
226   - }
227   - //是环线
228   - if(prev.getStopNo().equals(next.getQdzCode())){
229   - //发下一个班次
230   - if(dayOfSchedule.addExecPlan(next))
231   - outStation(gps, prev);
232   - }
233   - }
234   - }
235   -
236   - /**
237   - * 是否是一个更合适的发车信号
238   - * @param gps
239   - * @param sch
240   - * @return
241   - */
242   - private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) {
243   - LineConfig conf = lineConfigData.get(sch.getXlBm());
244   - if(null != conf && conf.isLockFirstOutTime())
245   - return false;//锁定第一个发车信号,不匹配最佳
246   -
247   - if(StringUtils.isNotEmpty(sch.getZdsjActual()))
248   - return false;
249   -
250   - long t1 = sch.getFcsjActualTime();
251   - long t2 = gps.getTimestamp();
252   - long c = sch.getDfsjT();
253   -
254   - /*if(c - t1 > 1000 * 60 * 15 && Math.abs(t2 - c) < 1000 * 60 * 5){
255   - return true;
256   - }*/
257   - int threshold = 1000 * 60 * 5;
258   - if(Math.abs(t2 - c) < threshold && c - t1 > threshold){
259   - return true;
260   - }
261   - //if(Math.abs(t2 - c) < 1000 * 60 * 5 && c - t1 > 1000 * 60 * 5)
262   - return false;
263   - }
264   -
265   -
266   - private void outStationAndOutPark(ScheduleRealInfo sch){
267   - try{
268   - LineConfig config = lineConfigData.get(sch.getXlBm());
269   - //限定出站既出场的停车场
270   - String park = config.getTwinsPark();
271   - boolean limitPark = StringUtils.isNotEmpty(park);
272   -
273   - if (config != null && config.getOutConfig() == 2) {
274   - //出站既出场
275   - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
276   - if (schPrev != null && schPrev.getBcType().equals("out") && (schPrev.getBcsj()==0 || schPrev.getJhlcOrig().intValue()==0)
277   - && (!limitPark || park.equals(schPrev.getQdzCode()))) {
278   -
279   - schPrev.setFcsjActualAll(sch.getFcsjActualTime());
280   - schPrev.setZdsjActualAll(sch.getFcsjActualTime());
281   - //起点实到
282   - sch.setQdzArrDatesj(schPrev.getZdsjActual());
283   -
284   - sendUtils.refreshSch(schPrev);
285   - dayOfSchedule.save(schPrev);
286   - }
287   - }
288   - }catch (Exception e){
289   - logger.error("", e);
290   - }
291   - }
292   -
293   - /**
294   - * 进站
295   - * @param gps 当前点
296   - * @param prev 上一个点
297   - */
298   - private void inStation(GpsEntity gps, GpsEntity prev){
299   - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
300   -
301   - if(gps.getStopNo().equals(sch.getZdzCode())
302   - && (!gps.getStopNo().equals(prev.getStopNo()) || gps.getStopNo().equals(prev.getPremiseCode()))){
303   -
304   - int diff = 0;
305   - try{
306   - diff = (int) (sch.getZdsjT() - gps.getTimestamp());
307   - }catch(NullPointerException e){
308   - logger.info("NullPointerException " + sch.getXlName() + " 有班次无班次历时,,,检查一下是否需要出站既出场。");
309   - }
310   - //进场最多提前1.2小时
311   - if((sch.getBcType().equals("in") && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME/2)
312   - return;
313   -
314   - //正常班次最大时间差
315   - if(Math.abs(diff) > MAX_NORMAL_DIFF)
316   - return;
317   -
318   - //校验进站前置约束
319   - if(!validInPremise(gps)){
320   - return;
321   - }
322   -
323   - //环线或内外圈 ,飘出去再回来
324   - if(sch.getQdzCode().equals(sch.getZdzCode())
325   - && StringUtils.isNotEmpty(sch.getFcsjActual())
326   - && gps.getTimestamp() - sch.getFcsjActualTime() < 1000 * 60 * 3){
327   - sch.clearFcsjActual();
328   - sendUtils.refreshSch(sch);
329   - return;
330   - }
331   -
332   - //实达时间不覆盖
333   - if(StringUtils.isNotEmpty(sch.getZdsjActual()))
334   - return;
335   -
336   - //应用到离站缓冲区设置参数
337   - long rsT = lineConfigData.applyIn(sch, gps.getTimestamp());
338   -
339   - sch.setZdsjActualAll(rsT);
340   - sch.setSiginCompate(2);
341   - //通知误点停靠程序,有车辆到站
342   - LateAdjustHandle.carArrive(gps);
343   -
344   - //已完成班次数
345   - int doneSum = dayOfSchedule.doneSum(sch.getClZbh());
346   - ScheduleRealInfo next = dayOfSchedule.next(sch);
347   - //持久化
348   - dayOfSchedule.save(sch);
349   -
350   - if(next != null){
351   - dayOfSchedule.addExecPlan(next);
352   - //进站既进场
353   - inStationAndInPark(sch, next);
354   - }
355   -
356   - //该路牌的下一个班次,起点实际到达时间
357   - ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
358   - if(lpNext != null){
359   - lpNext.setQdzArrDatesj(sch.getZdsjActual());
360   - }
361   -
362   - //通知客户端
363   - sendUtils.sendZdsj(sch, lpNext, doneSum);
364   - logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual());
365   - //清除车辆误点调整监听
366   - LateAdjustHandle.remove(sch.getClZbh());
367   - //准备执行下一个班次
368   - if (next != null) {
369   - //将gps转换为下一个班次走向的站内信号
370   - transformUpdown(gps, next);
371   - //下发调度指令
372   - DirectivePushQueue.put6002(next, doneSum, "到站@系统");
373   -
374   - //套跑 -下发线路切换指令
375   - if(!next.getXlBm().equals(sch.getXlBm())){
376   - gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统");
377   - }
378   -
379   - //下一个班次是空驶班次
380   - if(dayOfSchedule.emptyService(next))
381   - nonService(sch, "空驶@系统");
382   - } else
383   - nonService(sch, "结束@系统");
384   - }
385   - else {
386   - /*if(sch.getFcsjActual() == null){
387   - //有进站,但班次没有实发,向前追溯一下信号
388   - scheduleSignalState.signalRetrospect(gps, sch);
389   - }
390   -*/
391   - //被起点站覆盖的情况下进场,没有设置出站既是出场,逻辑会走到这里(模拟进站信号)
392   - if(isInSch(sch)){
393   - try{
394   - if(isInPark(gps, prev)){
395   - if(gps.getCarparkNo().equals(sch.getZdzCode())){
396   - //再试一下进场
397   - GpsEntity gpsClone = (GpsEntity) gps.clone(),
398   - prevClone = (GpsEntity) prev.clone();
399   - gpsClone.setStopNo(gpsClone.getCarparkNo());
400   - prevClone.setStopNo(null);
401   - inStation(gpsClone, prevClone);
402   - return;
403   - }
404   - }
405   - }catch (Exception e){
406   - logger.error("", e);
407   - }
408   - }
409   -
410   - //如果当前班次是出场,并且进的是下一个班次的终点
411   - if(sch.getBcType().equals("out")){
412   - ScheduleRealInfo next = dayOfSchedule.next(sch);
413   - if(next != null && next.getZdzCode().equals(gps.getStopNo())){
414   - List<ScheduleRealInfo> halfList = dayOfSchedule.findByNbbm(sch.getClZbh());
415   - //和当前进站信号最匹配的一个班次
416   - ScheduleRealInfo nearSch = nearScheduleByGpsIn(gps, halfList);
417   -
418   - if(nearSch != null){
419   - //直接跳到这个班次
420   - if(dayOfSchedule.addExecPlan(nearSch))
421   - inStation(gps, prev);//重新进站
422   - }
423   - }
424   - }
425   - }
426   - }
427   -
428   - /**
429   - * 校验进站前置约束
430   - * @param gps
431   - * @return
432   - */
433   - private boolean validInPremise(GpsEntity gps) {
434   - StationRoute sr = gps.getStation();
435   - if(null == sr || !sr.isPremise())
436   - return true;
437   -
438   - String premiseCode = gps.getPremiseCode();
439   -
440   - if(StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())){
441   - logger.info("满足前置进站约束 " + premiseCode);
442   - return true;
443   - }
444   - else{
445   - logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode);
446   - }
447   - return false;
448   - }
449   -
450   - /**
451   - * 和当前进站信号最匹配的一个班次
452   - * @param gps
453   - * @param halfList
454   - * @return
455   - */
456   - private ScheduleRealInfo nearScheduleByGpsIn(GpsEntity gps, List<ScheduleRealInfo> halfList){
457   - if(halfList == null || halfList.size() == 0)
458   - return null;
459   -
460   - //排序
461   - Collections.sort(halfList, new ScheduleComparator.FCSJ());
462   - ScheduleRealInfo near = null;// = halfList.get(0);
463   - ScheduleRealInfo sch;
464   -
465   - String stopId = gps.getStopNo();
466   - for(int i = 0; i < halfList.size(); i ++){
467   - sch = halfList.get(i);
468   - if(!sch.getZdzCode().equals(stopId) || sch.getStatus()==2)
469   - continue;
470   -
471   - if(sch.getZdsjT() < gps.getTimestamp())
472   - near = sch;
473   - else
474   - break;
475   -
476   - }
477   - return near;
478   - }
479   -
480   - /**
481   - * 进站既进场
482   - * @param sch
483   - */
484   - private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next){
485   - LineConfig config = lineConfigData.get(sch.getXlBm());
486   - //限定出站既出场的停车场
487   - String park = config.getTwinsPark();
488   - boolean limitPark = StringUtils.isNotEmpty(park);
489   -
490   -
491   - if (next.getBcType().equals("in") && config.getOutConfig() == 2 && (next.getBcsj()==0 || next.getJhlcOrig().intValue()==0)
492   - && (!limitPark || park.equals(next.getZdzCode()))) {
493   -
494   - next.setFcsjActualAll(sch.getZdsjActualTime());
495   - next.setZdsjActualAll(sch.getZdsjActualTime());
496   -
497   - sendUtils.refreshSch(next);
498   - dayOfSchedule.save(next);
499   -
500   - //分班的时候,需要再跳过1个班次
501   - next = dayOfSchedule.next(next);
502   - if(next != null)
503   - dayOfSchedule.addExecPlan(next);
504   -
505   - //进场,切换成非营运状态
506   - nonService(sch, "进场@系统");
507   - }
508   - }
509   -
510   - /**
511   - * 发车漂移判定(这里出现的误判,由车辆到达中途站的时候补偿)
512   - * @param gps
513   - * @param prev
514   - * @param task
515   - * @return
516   - */
517   - private boolean willDepart(GpsEntity gps, GpsEntity prev, Object task){
518   -
519   - /*ScheduleRealInfo sch = (ScheduleRealInfo) task;
520   - ScheduleRealInfo prevTask = dayOfSchedule.prev(sch);
521   - if(prevTask == null || prevTask.getBcType().equals("out"))
522   - return false;
523   -
524   - //计划停站时间
525   - int stopTimePlan = (int) (sch.getDfsjT() - prevTask.getZdsjT());
526   -
527   - if(stopTimePlan < 1000 * 60 * 10)
528   - return false;
529   -
530   - //实际停站时间
531   - if(prevTask.getZdsjActual() != null){
532   - int actualTime = (int) (gps.getTimestamp() - prevTask.getZdsjActualTime());
533   -
534   - if(actualTime < stopTimePlan * 0.8){
535   - logger.info("漂移判定");
536   -
537   - return true;
538   - }
539   - }*/
540   - return false;
541   - }
542   -
543   - private boolean isOutPark(GpsEntity gps, GpsEntity prve){
544   - if(StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo()))
545   - return true;
546   - return false;
547   - }
548   -
549   - private boolean isInPark(GpsEntity gps, GpsEntity prve){
550   - if(StringUtils.isNotEmpty(gps.getCarparkNo()) && StringUtils.isEmpty(prve.getCarparkNo()))
551   - return true;
552   - return false;
553   - }
554   -
555   - private boolean isOutSch(ScheduleRealInfo sch){
556   - return sch.getBcType().equals("out") || GeoCacheData.tccMap.keySet().contains(sch.getQdzCode());
557   - }
558   -
559   - private boolean isInSch(ScheduleRealInfo sch){
560   - return sch.getBcType().equals("in") || GeoCacheData.tccMap.keySet().contains(sch.getZdzCode());
561   - }
562   -
563   - /**
564   - * 切换为非营运状态
565   - * @param sch
566   - * @param sender
567   - */
568   - private void nonService(ScheduleRealInfo sch, String sender){
569   - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);
570   - }
571   -}
572 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/handlers/OfflineSignalHandle.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.handlers;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
5   -import com.bsth.data.gpsdata.arrival.SignalHandle;
6   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
7   -import org.springframework.stereotype.Component;
8   -
9   -/**
10   - * 信号断线重连处理
11   - * Created by panzhao on 2016/12/27.
12   - */
13   -@Component
14   -public class OfflineSignalHandle extends SignalHandle{
15   -
16   - //断开4分钟,标记为重连信号
17   - private final static int OFFLINE_TIME = 1000 * 60 * 4;
18   -
19   - //断开70分钟,之前的信号不再有参考价值
20   - private final static int CLEAR_TIME = 1000 * 60 * 70;
21   -
22   - @Override
23   - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
24   - //掉线信号不管
25   - if(isGpsOffline(gps)){
26   - gps.setSignalState("gps-offline");
27   - gps.setAbnormalStatus("gps-offline");
28   - return true;
29   - }
30   -
31   - if(isNotEmpty(prevs)){
32   - GpsEntity prev = prevs.getTail();
33   - //间隔太大就丢弃,不管之前还是之后
34   - int space = Math.abs((int) (gps.getTimestamp() - prev.getTimestamp()));
35   - if(space > OFFLINE_TIME)
36   - gps.setSignalState("reconnection");
37   -
38   - if(space > CLEAR_TIME){
39   - //清理缓存的信号
40   - GeoCacheData.clear(gps.getNbbm());
41   - }
42   - }
43   - return true;
44   - }
45   -}
46 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/handlers/ReverseSignalHandle.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.handlers;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
5   -import com.bsth.data.gpsdata.arrival.SignalHandle;
6   -import com.bsth.data.gpsdata.arrival.entity.RouteReverse;
7   -import com.bsth.data.gpsdata.arrival.entity.StationRoute;
8   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
9   -import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState;
10   -import com.bsth.data.schedule.DayOfSchedule;
11   -import org.slf4j.Logger;
12   -import org.slf4j.LoggerFactory;
13   -import org.springframework.beans.factory.annotation.Autowired;
14   -import org.springframework.stereotype.Component;
15   -
16   -/**
17   - * 路由反向信号处理
18   - * Created by panzhao on 2016/12/28.
19   - */
20   -@Component
21   -public class ReverseSignalHandle extends SignalHandle {
22   -
23   - Logger logger = LoggerFactory.getLogger(this.getClass());
24   -
25   - @Autowired
26   - DayOfSchedule dayOfSchedule;
27   -
28   - @Autowired
29   - ScheduleSignalState scheduleSignalState;
30   -
31   - @Override
32   - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {
33   - if (!isNotEmpty(prevs))
34   - return false;
35   -
36   - GpsEntity prev = prevs.getTail();
37   -
38   - if (isReverse(gps, prev)) {
39   - RouteReverse reverse = reverseSearch(prevs, gps);
40   -
41   - if (reverse != null && reverse.getCount() >= 3
42   - && reverse.isClose()
43   - && !GeoCacheData.isEndStation(gps.getLineId(), gps.getUpDown(), reverse.getTurned())) {
44   - scheduleSignalState.reverseAnalyse(reverse);
45   - }
46   - }
47   - return false;
48   - }
49   -
50   - /**
51   - * 搜索路由反向详细
52   - *
53   - * @param prevs
54   - * @param gps
55   - * @return
56   - */
57   - public RouteReverse reverseSearch(CircleQueue<GpsEntity> prevs, GpsEntity gps) {
58   - RouteReverse routeReverse = new RouteReverse();
59   - int count = 0;
60   - String path = "";
61   - long zt = 0L;
62   - boolean half = false;
63   -
64   - //当前站点
65   - StationRoute curr = GeoCacheData.getRouteCode(gps), sr;
66   - GpsEntity prev;
67   - Object[] array = prevs.getQueue();
68   - for (int i = array.length - 1; i > 0; i--) {
69   - prev = (GpsEntity) array[i];
70   -
71   - if (!prev.getUpDown().equals(gps.getUpDown())
72   - || prev.getSignalState().equals("reconnection"))
73   - break;
74   -
75   - if (prev.getInstation() == 1) {
76   - sr = GeoCacheData.getRouteCode(prev);
77   - if(sr == null)
78   - return null;
79   -
80   - if (sr.getRouteSort() > curr.getRouteSort()) {
81   - if(half){
82   - routeReverse.setVague(true);
83   - }
84   -
85   - path += (curr.getCode() + ",");
86   - count++;
87   - zt = prev.getTimestamp();
88   - } else if (sr.getRouteSort() < curr.getRouteSort()) {
89   - if (routeReverse.getTurned() == null) {
90   - routeReverse.setTurned(curr.getCode());
91   - half = true;
92   - }
93   -
94   - path += (curr.getCode() + ",");
95   - //掉头前当前站
96   - if (sr.getCode().equals(gps.getStopNo())) {
97   - routeReverse.setClose(true);
98   - path += sr.getCode();
99   - break;
100   - }
101   - }
102   -
103   - curr = sr;
104   - }
105   - }
106   -
107   - routeReverse.setZt(zt);
108   - routeReverse.setCount(count);
109   - routeReverse.setDetail(path);
110   - routeReverse.setCt(gps.getTimestamp());
111   - routeReverse.setNbbm(gps.getNbbm());
112   - return routeReverse;
113   - }
114   -
115   - /**
116   - * 是否反向
117   - *
118   - * @param gps
119   - * @param prev
120   - * @return
121   - */
122   - public boolean isReverse(GpsEntity gps, GpsEntity prev) {
123   - if (gps.getInstation() == 1
124   - &&
125   - gps.getUpDown().equals(prev.getUpDown())
126   - && !gps.getStopNo().equals(prev.getStopNo())) {
127   -
128   - StationRoute currStation = GeoCacheData.getRouteCode(gps);
129   - StationRoute prevStation = GeoCacheData.getRouteCode(prev);
130   -
131   - if (currStation == null || prevStation == null)
132   - return false;
133   -
134   - if (currStation.getRouteSort() < prevStation.getRouteSort())
135   - return true;
136   - }
137   - return false;
138   - }
139   -}
140 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/precondition/InPreconditionHandler.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.precondition;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import org.springframework.stereotype.Component;
5   -
6   -/**
7   - * 进站(前置电子围栏)
8   - * Created by panzhao on 2017/9/23.
9   - */
10   -@Component
11   -public class InPreconditionHandler {
12   -
13   - /**
14   - * 进站动作是否有通过前置围栏
15   - * @param gps
16   - * @param prev
17   - * @return
18   - */
19   - public boolean isPass(GpsEntity gps, GpsEntity prev){
20   - return false;
21   - }
22   -}
src/main/java/com/bsth/data/gpsdata/arrival/utils/ScheduleSignalState.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.utils;
2   -
3   -import com.bsth.data.LineConfigData;
4   -import com.bsth.data.gpsdata.GpsEntity;
5   -import com.bsth.data.gpsdata.SignalStateData;
6   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
7   -import com.bsth.data.gpsdata.arrival.entity.RouteReverse;
8   -import com.bsth.data.gpsdata.arrival.entity.SignalAbnormal;
9   -import com.bsth.data.gpsdata.arrival.entity.SignalState;
10   -import com.bsth.data.schedule.DayOfSchedule;
11   -import com.bsth.entity.realcontrol.LineConfig;
12   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
13   -import org.slf4j.Logger;
14   -import org.slf4j.LoggerFactory;
15   -import org.springframework.beans.factory.annotation.Autowired;
16   -import org.springframework.stereotype.Component;
17   -
18   -/**
19   - * 班次信号状态分析
20   - * Created by panzhao on 2016/12/29.
21   - */
22   -@Component
23   -public class ScheduleSignalState {
24   -
25   - @Autowired
26   - DayOfSchedule dayOfSchedule;
27   -
28   - Logger logger = LoggerFactory.getLogger(this.getClass());
29   -
30   - @Autowired
31   - LineConfigData lineConfigData;
32   -
33   - @Autowired
34   - SignalStateData signalStateData;
35   -
36   - /**
37   - * 路由反向分析
38   - */
39   - public void reverseAnalyse(RouteReverse reverse) {
40   - ScheduleRealInfo sch = dayOfSchedule.executeCurr(reverse.getNbbm());
41   -
42   - String bcType = sch.getBcType();
43   -
44   - switch (bcType) {
45   - case "out":
46   - outReverseAnalyse(sch, reverse);
47   - break;
48   - case "normal":
49   - normalReverseAnalyse(sch, reverse);
50   - break;
51   - }
52   - }
53   -
54   - /**
55   - * 出场班次路由反向分析
56   - *
57   - * @param sch
58   - */
59   - private void outReverseAnalyse(ScheduleRealInfo sch, RouteReverse reverse) {
60   - long t = reverse.getCt();
61   - //出场班次终点时间前,允许反向轨迹
62   - if (sch.getZdsjT() != null && sch.getZdsjT() > t) {
63   - return;
64   - }
65   -
66   - int rt;
67   - //从实发 到 当前时间 < 计划运送时间 * 0.9
68   - if (sch.getFcsjActual() != null && sch.getBcsj() != null) {
69   - rt = (int) (t - sch.getFcsjActualTime());
70   - if (rt < sch.getBcsj() * 0.9)
71   - return;
72   - }
73   -
74   - ScheduleRealInfo next = dayOfSchedule.next(sch);
75   - if (next != null && next.getXlDir().equals(sch.getXlDir()))
76   - return;
77   -
78   - if(next == null)
79   - return;
80   - //时间足够下一个班次待发时间运行到当前站
81   - int runTime = reverse.getCount() * 1500 * 60;
82   - if (next.getDfsjT() + runTime < t) {
83   - //跳到下一个班次
84   - dayOfSchedule.addExecPlan(next);
85   - }
86   - }
87   -
88   - /**
89   - * 正常班次路由反向分析
90   - *
91   - * @param sch
92   - * @param reverse
93   - */
94   - private void normalReverseAnalyse(ScheduleRealInfo sch, RouteReverse reverse) {
95   - LineConfig conf = lineConfigData.get(sch.getXlBm());
96   -
97   - if (conf.isReadReverse()) {
98   - //跳下一个班次
99   - ScheduleRealInfo next = dayOfSchedule.next(sch);
100   - if (next != null)
101   - dayOfSchedule.addExecPlan(next);
102   -
103   - //记录信号状态
104   - SignalState signalState = SignalState.reverseSignalSTate(sch, reverse);
105   - if(signalState != null)
106   - signalStateData.put(signalState);
107   - }
108   - }
109   -
110   - public void signalRetrospect(GpsEntity gps) {
111   - signalRetrospect(gps, dayOfSchedule.executeCurr(gps.getNbbm()));
112   - }
113   -
114   - /**
115   - * 信号追溯
116   - *
117   - * @param gps
118   - * @param sch
119   - */
120   - public void signalRetrospect(GpsEntity gps, ScheduleRealInfo sch) {
121   - //回放数据,是否有掉线或者漂移
122   - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
123   - if (queue == null || queue.size() == 0 /*|| gps.getInstation() == 0*/)
124   - return;
125   -
126   - //起始时间点
127   - long st = 0;
128   - ScheduleRealInfo prev = dayOfSchedule.prev(sch);
129   -
130   - if (prev != null) {
131   - if (prev.getZdsjActual() != null)
132   - st = prev.getZdsjActualTime();
133   - else
134   - st = (GeoCacheData.midwayStation(gps.getLineId(), gps.getUpDown(), sch.getQdzCode(), gps.getStopNo()).size() + 1) * (1000 * 60 * 5);
135   - }
136   -
137   - Object[] tempArray = queue.getQueue();
138   - int len = tempArray.length;
139   -
140   - Object[] array = new Object[len + 1];
141   - System.arraycopy(tempArray, 0, array, 0, len);
142   - array[len] = gps;
143   -
144   - String gpsState = "";
145   - GpsEntity tempGps, nearGps = null;
146   - int i = len - 1;
147   - for (; i >= 0; i--) {
148   - tempGps = (GpsEntity) array[i];
149   -
150   - gpsState = tempGps.getSignalState();
151   - if (gpsState.equals("truncation"))
152   - break;
153   - else if (gpsState.equals("drift")) {
154   - nearGps = (GpsEntity) array[i + 1];
155   - break;
156   - } else if (gpsState.equals("reconnection")) {
157   - nearGps = tempGps;
158   - break;
159   - }
160   -
161   - if (tempGps.getTimestamp() < st)
162   - break;
163   - }
164   -
165   - if (nearGps != null && i > 0) {
166   - createSignalAbnormal(gpsState, nearGps, i, array, sch);
167   - }
168   - }
169   -
170   - private void createSignalAbnormal(String gpsState, GpsEntity nearGps, int i, Object[] array, ScheduleRealInfo sch) {
171   - switch (gpsState) {
172   - case "drift":
173   - driftSignalAbnormal(nearGps, i, array, sch);
174   - break;
175   - case "reconnection":
176   - offlineSignalAbnormal(nearGps, ((GpsEntity) array[i - 1]), sch);
177   - break;
178   - }
179   - }
180   -
181   - /**
182   - * 掉线异常状态记录
183   - *
184   - * @param e
185   - * @param s
186   - */
187   - private void offlineSignalAbnormal(GpsEntity e, GpsEntity s, ScheduleRealInfo sch) {
188   - long st = s.getTimestamp(), et = e.getTimestamp();
189   -
190   - //掉线超过10分钟才记录
191   - if (et - st < (1000 * 60 * 10))
192   - return;
193   -
194   - SignalAbnormal signalAbnormal = new SignalAbnormal();
195   - signalAbnormal.setSt(st);
196   - signalAbnormal.setEt(et);
197   - signalAbnormal.setAbnormalType("reconnection");
198   - signalAbnormal.setDestCode(sch.getQdzCode());
199   - signalAbnormal.setOutOrIn(0);
200   -
201   - //截断GPS
202   - e.setSignalState("truncation");
203   -
204   - //记录信号状态
205   - SignalState signalState = SignalState.abnormalSignalSTate(sch, signalAbnormal);
206   - signalStateData.put(signalState);
207   - }
208   -
209   - /**
210   - * 漂移异常状态记录
211   - *
212   - * @param nearGps
213   - * @param i
214   - * @param array
215   - */
216   - private void driftSignalAbnormal(GpsEntity nearGps, int i, Object[] array, ScheduleRealInfo sch) {
217   - GpsEntity gps, s = null;
218   - //找到漂移开始时间
219   - for (; i >= 0; i--) {
220   - gps = (GpsEntity) array[i];
221   -
222   - if (!gps.getSignalState().equals("drift") || i == 0
223   - || gps.getSignalState().equals("truncation")) {
224   - s = gps;
225   - break;
226   - }
227   - }
228   -
229   - long st = s.getTimestamp(), et = nearGps.getTimestamp();
230   - if (et - st < (1000 * 60 * 3))
231   - return;
232   - /*if (s != null){
233   - st = s.getTimestamp();
234   - //漂移小于3分钟
235   - if(et - st < (1000 * 60 * 3))
236   - return;
237   - }*/
238   -
239   -
240   - SignalAbnormal signalAbnormal = new SignalAbnormal();
241   - signalAbnormal.setSt(st);
242   - signalAbnormal.setEt(et);
243   - signalAbnormal.setAbnormalType("drift");
244   - signalAbnormal.setDestCode(sch.getQdzCode());
245   - signalAbnormal.setOutOrIn(0);
246   -
247   - //截断GPS
248   - nearGps.setSignalState("truncation");
249   -
250   - //记录信号状态
251   - SignalState signalState = SignalState.abnormalSignalSTate(sch, signalAbnormal);
252   - signalStateData.put(signalState);
253   - }
254   -}
255 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/arrival/utils/SignalSchPlanMatcher.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.arrival.utils;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.schedule.DayOfSchedule;
5   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
6   -import org.slf4j.Logger;
7   -import org.slf4j.LoggerFactory;
8   -import org.springframework.beans.factory.annotation.Autowired;
9   -import org.springframework.stereotype.Component;
10   -
11   -/**
12   - * 班次匹配器
13   - * Created by panzhao on 2016/12/31.
14   - */
15   -@Component
16   -public class SignalSchPlanMatcher {
17   -
18   - @Autowired
19   - DayOfSchedule dayOfSchedule;
20   -
21   - Logger log = LoggerFactory.getLogger(this.getClass());
22   -
23   - /**
24   - * 发车信号匹配
25   - * @param outSigal
26   - * @param sch
27   - * @return
28   - */
29   - public void outMatch(GpsEntity outSigal, ScheduleRealInfo sch){
30   - long t = outSigal.getTimestamp();
31   - if(t < sch.getDfsjT())
32   - return;
33   -
34   - try{
35   - //会不会是分班没有完成
36   - if(sch.getBcType().equals("in") && t - sch.getDfsjT() > 1000 * 60 * 20){
37   - ScheduleRealInfo fbFirst = dayOfSchedule.nextByBcType(sch, "normal");
38   -
39   - if(fbFirst == null || !fbFirst.getQdzCode().equals(outSigal.getStopNo()))
40   - return;
41   -
42   - long dt = fbFirst.getDfsjT();
43   - //晚于待发前4分钟 -执行分班的首个营运
44   - if(dt - t < 1000 * 60 * 4){
45   - dayOfSchedule.addExecPlan(fbFirst);
46   - return;
47   - }
48   - }
49   -
50   - //线路编码不匹配
51   - if("out".equals(sch.getBcType()) && !sch.getXlBm().equals(outSigal.getLineId())){
52   - ScheduleRealInfo nextOut = dayOfSchedule.nextByBcType(sch, "out");
53   - if(nextOut != null && nextOut.getXlBm().equals(outSigal.getLineId())
54   - && fcSpace(sch, outSigal) > fcSpace(nextOut, outSigal)){
55   - dayOfSchedule.addExecPlan(nextOut);
56   - return;
57   - }
58   - }
59   - }catch (Exception e){
60   - log.error("", e);
61   - }
62   -
63   - //下一个相同走向的班次
64   - ScheduleRealInfo next = dayOfSchedule.nextSame(sch);
65   - if(next == null || !next.getQdzCode().equals(sch.getQdzCode()))
66   - return;
67   -
68   - //晚于班次间隔百分之70,跳下一个班次
69   - double s = (int) (next.getDfsjT() - sch.getDfsjT());
70   - double r = (int) (t - sch.getDfsjT());
71   - if(r / s > 0.7){
72   - if(dayOfSchedule.addExecPlan(next))
73   - outMatch(outSigal, next);
74   - }
75   - }
76   -
77   - public static int fcSpace(ScheduleRealInfo sch, GpsEntity gps){
78   - return (int) Math.abs((sch.getDfsjT() - gps.getTimestamp()));
79   - }
80   -}
src/main/java/com/bsth/data/gpsdata/thread/GpsDataLoaderThread.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.thread;
2   -
3   -import com.alibaba.fastjson.JSON;
4   -import com.alibaba.fastjson.JSONObject;
5   -import com.bsth.data.BasicData;
6   -import com.bsth.data.gpsdata.GpsEntity;
7   -import com.bsth.data.gpsdata.GpsRealData;
8   -import com.bsth.data.gpsdata.arrival.GpsRealAnalyse;
9   -import com.bsth.util.ConfigUtil;
10   -import org.apache.commons.lang3.StringUtils;
11   -import org.apache.http.HttpEntity;
12   -import org.apache.http.client.config.RequestConfig;
13   -import org.apache.http.client.methods.CloseableHttpResponse;
14   -import org.apache.http.client.methods.HttpGet;
15   -import org.apache.http.impl.client.CloseableHttpClient;
16   -import org.apache.http.impl.client.HttpClients;
17   -import org.slf4j.Logger;
18   -import org.slf4j.LoggerFactory;
19   -import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.stereotype.Component;
21   -
22   -import java.io.BufferedReader;
23   -import java.io.InputStreamReader;
24   -import java.util.ArrayList;
25   -import java.util.List;
26   -
27   -/**
28   - * Created by panzhao on 2017/1/11.
29   - */
30   -@Component
31   -public class GpsDataLoaderThread extends Thread {
32   -
33   - Logger logger = LoggerFactory.getLogger(GpsDataLoaderThread.class);
34   -
35   - /**
36   - * 构造函数
37   - */
38   - public GpsDataLoaderThread() {
39   - url = ConfigUtil.get("http.gps.real.url");
40   - clientUrl = ConfigUtil.get("http.gps.real.cache.url");
41   - }
42   -
43   - // 网关数据接口地址
44   - private static String url;
45   - // GPS客户端内存数据接口
46   - private static String clientUrl;
47   -
48   - //0:从GPS客户端内存获取 -1:从网关获取
49   - private static int flag = 0;
50   -
51   - public static void setFlag(int v) {
52   - flag = v;
53   - }
54   -
55   - public static int getFlag(int v) {
56   - return flag;
57   - }
58   -
59   - @Autowired
60   - GpsRealData gpsRealData;
61   -
62   - @Autowired
63   - GpsRealAnalyse gpsRealAnalyse;
64   -
65   - @Override
66   - public void run() {
67   - try {
68   - if (flag == 0)
69   - load();
70   - else
71   - loadByGateway();
72   - } catch (Exception e) {
73   - logger.error("", e);
74   - }
75   - }
76   -
77   - /**
78   - * 从网关获取实时GPS数据
79   - *
80   - * @throws Exception
81   - */
82   - public void loadByGateway() throws Exception {
83   - List<GpsEntity> list = null;
84   - List<GpsEntity> updateList = new ArrayList<>();
85   - CloseableHttpClient httpClient = null;
86   - CloseableHttpResponse response = null;
87   - try {
88   - httpClient = HttpClients.createDefault();
89   - HttpGet get = new HttpGet(url);
90   - //超时时间
91   - RequestConfig requestConfig = RequestConfig.custom()
92   - .setConnectTimeout(1500).setConnectionRequestTimeout(1000)
93   - .setSocketTimeout(1500).build();
94   - get.setConfig(requestConfig);
95   -
96   - response = httpClient.execute(get);
97   -
98   - HttpEntity entity = response.getEntity();
99   - if (null != entity) {
100   - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
101   - StringBuilder stringBuffer = new StringBuilder();
102   - String str;
103   - while ((str = br.readLine()) != null)
104   - stringBuffer.append(str);
105   -
106   - JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
107   -
108   - if (jsonObj != null)
109   - list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
110   -
111   - //过滤掉无效的点位
112   - list = filterInvalid(list);
113   -
114   - String nbbm;
115   - GpsEntity old;
116   - for (GpsEntity gps : list) {
117   -
118   - //没有设备号
119   - if (StringUtils.isBlank(gps.getDeviceId()))
120   - continue;
121   -
122   - old = gpsRealData.get(gps.getDeviceId());
123   - if (old != null &&
124   - old.getTimestamp().equals(gps.getTimestamp()) &&
125   - old.getLat().equals(gps.getLat()) &&
126   - old.getLon().equals(gps.getLon()))
127   - continue;
128   -
129   - nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());
130   - if (StringUtils.isBlank(nbbm))
131   - gps.setIncomplete(true);//标记为异常数据
132   - else
133   - gps.setNbbm(nbbm);
134   - //有更新的点位
135   - updateList.add(gps);
136   - }
137   - logger.info("全量点:" + list.size() + ",更新点" + updateList.size());
138   - //分析数据
139   - gpsRealAnalyse.analyse(updateList);
140   - } else
141   - logger.error("real gps result is null");
142   - } catch (Exception e) {
143   - logger.error("", e);
144   - } finally {
145   - if (null != httpClient)
146   - httpClient.close();
147   - if (null != response)
148   - response.close();
149   - }
150   - }
151   -
152   - /**
153   - * 过滤无效的gps点位
154   - *
155   - * @param list
156   - * @return
157   - */
158   - private List<GpsEntity> filterInvalid(List<GpsEntity> list) {
159   - List<GpsEntity> rsList = new ArrayList<>();
160   -
161   - try {
162   - for (GpsEntity gps : list) {
163   - if (gps.getValid() == 0)
164   - rsList.add(gps);
165   - }
166   -
167   - if (rsList.size() < list.size())
168   - logger.info("过滤无效的点位 : " + (list.size() - rsList.size()));
169   - } catch (Exception e) {
170   - logger.error("", e);
171   - rsList = list;
172   - }
173   - return rsList;
174   - }
175   -
176   - /**
177   - * 从客户端内存获取GPS数据
178   - */
179   - public void load() throws Exception {
180   - List<GpsEntity> list;
181   - CloseableHttpClient httpClient = null;
182   - CloseableHttpResponse response = null;
183   -
184   - try {
185   - logger.info("load start...");
186   - httpClient = HttpClients.createDefault();
187   - HttpGet get = new HttpGet(clientUrl);
188   - //超时时间
189   - RequestConfig requestConfig = RequestConfig.custom()
190   - .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
191   - .setSocketTimeout(3000).build();
192   - get.setConfig(requestConfig);
193   -
194   - response = httpClient.execute(get);
195   -
196   - HttpEntity entity = response.getEntity();
197   - if (null != entity) {
198   - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
199   - StringBuilder stringBuffer = new StringBuilder();
200   - String str;
201   - while ((str = br.readLine()) != null)
202   - stringBuffer.append(str);
203   -
204   - list = JSON.parseArray(stringBuffer.toString(), GpsEntity.class);
205   -
206   - //过滤掉无效的点位
207   - list = filterInvalid(list);
208   -
209   - String nbbm;
210   - logger.info("load end!");
211   - for (GpsEntity gps : list) {
212   -
213   - //没有设备号
214   - if (StringUtils.isBlank(gps.getDeviceId()))
215   - continue;
216   -
217   - nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());
218   - if (StringUtils.isBlank(nbbm))
219   - gps.setIncomplete(true);//标记为异常数据
220   - else
221   - gps.setNbbm(nbbm);
222   - }
223   - //分析数据
224   - gpsRealAnalyse.analyse(list);
225   - } else
226   - logger.error("client gps result is null");
227   - } catch (Exception e) {
228   - logger.error("", e);
229   - } finally {
230   - if (null != httpClient)
231   - httpClient.close();
232   - if (null != response)
233   - response.close();
234   - }
235   - }
236   -}
237 0 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/thread/OfflineMonitorThread.java deleted 100644 → 0
1   -package com.bsth.data.gpsdata.thread;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.GpsRealData;
5   -import com.bsth.websocket.handler.SendUtils;
6   -import org.slf4j.Logger;
7   -import org.slf4j.LoggerFactory;
8   -import org.springframework.beans.factory.annotation.Autowired;
9   -import org.springframework.stereotype.Component;
10   -
11   -import java.util.Collection;
12   -
13   -/**
14   - * GPS掉离线监控
15   - * Created by panzhao on 2017/1/11.
16   - */
17   -@Component
18   -public class OfflineMonitorThread extends Thread{
19   -
20   - @Autowired
21   - GpsRealData gpsRealData;
22   -
23   - //掉线阈值
24   - private final static int LOSE_TIME = 1000 * 60 * 10;
25   -
26   - Logger logger = LoggerFactory.getLogger(this.getClass());
27   -
28   - @Autowired
29   - SendUtils sendUtils;
30   -
31   - //无任务时 离线阈值
32   - //private final static int OFFLINE_TIME = 1000 * 60 * 10;
33   -
34   - @Override
35   - public void run() {
36   - try{
37   - long t = System.currentTimeMillis();
38   - Collection<GpsEntity> list = gpsRealData.all();
39   -
40   - String state;
41   - for(GpsEntity gps : list){
42   - state = gps.getAbnormalStatus();
43   -
44   - if(state != null && state.equals("offline"))
45   - continue;
46   -
47   - if (t - gps.getTimestamp() > LOSE_TIME){
48   - gps.offline();
49   -
50   - //通知页面有设备掉线
51   - sendUtils.deviceOffline(gps);
52   - }
53   - }
54   - }catch (Exception e){
55   - logger.error("", e);
56   - }
57   - }
58   -}
src/main/java/com/bsth/data/gpsdata/arrival/GpsRealAnalyse.java renamed to src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
1   -package com.bsth.data.gpsdata.arrival;
2   -
3   -import com.bsth.data.gpsdata.GpsEntity;
4   -import com.bsth.data.gpsdata.GpsRealData;
5   -import com.bsth.data.gpsdata.arrival.handlers.*;
6   -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
7   -import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
8   -import com.google.common.collect.ArrayListMultimap;
9   -import org.slf4j.Logger;
10   -import org.slf4j.LoggerFactory;
11   -import org.springframework.beans.factory.annotation.Autowired;
12   -import org.springframework.stereotype.Component;
13   -
14   -import java.util.*;
15   -import java.util.concurrent.CountDownLatch;
16   -import java.util.concurrent.ExecutorService;
17   -import java.util.concurrent.Executors;
18   -
19   -/**
20   - * gps 实时数据分析
21   - * Created by panzhao on 2016/12/27.
22   - */
23   -@Component
24   -public class GpsRealAnalyse {
25   -
26   - static Logger logger = LoggerFactory.getLogger(GpsRealAnalyse.class);
27   -
28   - @Autowired
29   - OfflineSignalHandle offlineSignalHandle;
30   - @Autowired
31   - CorrectSignalHandle correctSignalHandle;
32   - @Autowired
33   - StationInsideHandle stationInsideHandle;
34   - @Autowired
35   - InOutStationSignalHandle inOutStationSignalHandle;
36   - @Autowired
37   - ReverseSignalHandle reverseSignalHandle;
38   - @Autowired
39   - AbnormalStateHandle abnormalStateHandle;
40   -
41   - @Autowired
42   - GpsRealData gpsRealData;
43   -
44   - final static int POOL_SIZE = 25;
45   - static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1);
46   -
47   - public static long st;
48   - public static CountDownLatch count;
49   -
50   - public static boolean isBlock() {
51   - return System.currentTimeMillis() - st > 1000 * 20;
52   - }
53   -
54   - public static boolean isIdle(){
55   - return System.currentTimeMillis() - st > 1000 * 60;
56   - }
57   -
58   - public void analyse(List<GpsEntity> list) {
59   - try {
60   - if(list.size() == 0 || GpsDataRecovery.run)
61   - return;
62   - st = System.currentTimeMillis();
63   -
64   - //按设备号分组数据(一个设备号的多条数据,必须在一个线程里跑)
65   - ArrayListMultimap multimap = ArrayListMultimap.create();
66   - for (GpsEntity gps : list) {
67   - multimap.put(gps.getDeviceId(), gps);
68   - }
69   - List<String> deviceList = new ArrayList<>(multimap.keySet());
70   -
71   - //数据均分给线程
72   - ArrayListMultimap dataListMap = ArrayListMultimap.create();
73   - int size = deviceList.size(), threadIndex=0, threadSize = size / POOL_SIZE;
74   - for(int i = 0; i < size; i++){
75   - if(i % threadSize == 0)
76   - threadIndex ++;
77   - dataListMap.putAll(threadIndex, multimap.get(deviceList.get(i)));
78   - }
79   - Set<Integer> ks = dataListMap.keySet();
80   - logger.info("analyse gps size: " + list.size() + ", ks: " + ks.size());
81   - count = new CountDownLatch(ks.size());
82   -
83   - for (Integer index : ks) {
84   - threadPool.execute(new SignalHandleThread(dataListMap.get(index), count));
85   - }
86   -
87   - //等待子线程结束
88   - count.await();
89   -
90   - //加入实时gps对照
91   - for (GpsEntity gps : list)
92   - gpsRealData.put(gps);
93   -
94   - logger.info("time , " + (System.currentTimeMillis() - st));
95   - } catch (Exception e) {
96   - logger.error("", e);
97   - }
98   - }
99   -
100   - public static void shutdown() {
101   - logger.warn("GpsRealAnalyse shutdown!!");
102   - threadPool.shutdownNow();
103   - long len = count.getCount();
104   - for (int i = 0; i < len; i++) {
105   - count.countDown();
106   - }
107   -
108   - threadPool = Executors.newFixedThreadPool(100);
109   - }
110   -
111   - static GpsComp comp = new GpsComp();
112   -
113   - public class SignalHandleThread implements Runnable {
114   -
115   - List<GpsEntity> list;
116   - CountDownLatch count;
117   -
118   - SignalHandleThread(List<GpsEntity> gpsList, CountDownLatch count) {
119   - this.list = gpsList;
120   - this.count = count;
121   - }
122   -
123   - @Override
124   - public void run() {
125   -
126   - try {
127   - Collections.sort(list, comp);
128   - for (GpsEntity gps : list) {
129   - try {
130   - //是否有任务
131   - boolean task;
132   - CircleQueue<GpsEntity> prevs = GeoCacheData.getGps(gps.getNbbm());
133   - //掉线处理
134   - offlineSignalHandle.handle(gps, prevs);
135   - //状态处理
136   - task = correctSignalHandle.handle(gps, prevs);
137   - //场,站内外判断
138   - stationInsideHandle.handle(gps, prevs);
139   - //异常判定(越界/超速)
140   - abnormalStateHandle.handle(gps, prevs);
141   -
142   - if (!task)
143   - continue; //无任务的,到这里就结束
144   -
145   - //反向处理
146   - reverseSignalHandle.handle(gps, prevs);
147   - //进出站动作处理
148   - inOutStationSignalHandle.handle(gps, prevs);
149   - GeoCacheData.putGps(gps);
150   - }catch (Exception e){
151   - logger.error("", e);
152   - }
153   - }
154   - } finally {
155   - if (count != null)
156   - count.countDown();
157   - }
158   - }
159   - }
160   -
161   - public static class GpsComp implements Comparator<GpsEntity> {
162   -
163   - @Override
164   - public int compare(GpsEntity g1, GpsEntity g2) {
165   - return g1.getTimestamp().compareTo(g2.getTimestamp());
166   - }
167   - }
168   -}
  1 +package com.bsth.data.gpsdata_v2;
  2 +
  3 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.handlers.*;
  6 +import com.google.common.collect.ArrayListMultimap;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.ArrayList;
  13 +import java.util.List;
  14 +import java.util.Set;
  15 +import java.util.concurrent.CountDownLatch;
  16 +import java.util.concurrent.ExecutorService;
  17 +import java.util.concurrent.Executors;
  18 +import java.util.concurrent.ThreadFactory;
  19 +
  20 +/**
  21 + * 实时信号数据处理
  22 + * Created by panzhao on 2017/11/15.
  23 + */
  24 +@Component
  25 +public class DataHandleProcess {
  26 +
  27 + static Logger logger = LoggerFactory.getLogger(DataHandleProcess.class);
  28 + final static int POOL_SIZE = 25;
  29 +
  30 + static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new HandlerThreadFactory());
  31 + public static CountDownLatch count;
  32 +
  33 + @Autowired
  34 + GpsStateProcess gpsStateProcess;
  35 + @Autowired
  36 + StationInsideProcess stationInsideProcess;
  37 + @Autowired
  38 + AbnormalStateProcess abnormalStateProcess;
  39 + @Autowired
  40 + InStationProcess inStationProcess;
  41 + @Autowired
  42 + OutStationProcess outStationProcess;
  43 + @Autowired
  44 + ReverseRouteProcess reverseRouteProcess;
  45 +
  46 + @Autowired
  47 + GpsRealData gpsRealData;
  48 +
  49 + public void handle(List<GpsEntity> list) {
  50 + try {
  51 + //按设备号分组数据(一个设备的多条数据,必须在一个线程里跑)
  52 + ArrayListMultimap multimap = ArrayListMultimap.create();
  53 + for (GpsEntity gps : list) {
  54 + multimap.put(gps.getDeviceId(), gps);
  55 + }
  56 + List<String> deviceList = new ArrayList<>(multimap.keySet());
  57 +
  58 + //数据均分给线程
  59 + ArrayListMultimap dataListMap = ArrayListMultimap.create();
  60 + int size = deviceList.size(), threadIndex = 0, threadSize = size / POOL_SIZE;
  61 + for (int i = 0; i < size; i++) {
  62 + if (i % threadSize == 0)
  63 + threadIndex++;
  64 + dataListMap.putAll(threadIndex, multimap.get(deviceList.get(i)));
  65 + }
  66 + Set<Integer> ks = dataListMap.keySet();
  67 + logger.info("analyse gps size: " + list.size() + ", ks: " + ks.size());
  68 + count = new CountDownLatch(ks.size());
  69 +
  70 + for (Integer index : ks) {
  71 + threadPool.submit(new SignalHandleThread(dataListMap.get(index), count));
  72 + }
  73 +
  74 + //等待子线程结束
  75 + count.await();
  76 +
  77 + //加入实时gps对照
  78 + for (GpsEntity gps : list)
  79 + gpsRealData.put(gps);
  80 + } catch (Exception e) {
  81 + logger.error("", e);
  82 + }
  83 + }
  84 +
  85 + public class SignalHandleThread implements Runnable {
  86 +
  87 + List<GpsEntity> list;
  88 + CountDownLatch count;
  89 +
  90 + SignalHandleThread(List<GpsEntity> gpsList, CountDownLatch count) {
  91 + this.list = gpsList;
  92 + this.count = count;
  93 + }
  94 +
  95 + @Override
  96 + public void run() {
  97 + try {
  98 + for (GpsEntity gps : list) {
  99 + try{
  100 + gpsStateProcess.process(gps);//状态处理
  101 + stationInsideProcess.process(gps);//场站内外判定
  102 + reverseRouteProcess.process(gps);//反向路由处理
  103 + abnormalStateProcess.process(gps);//超速越界
  104 +
  105 + inStationProcess.process(gps);//进站
  106 + outStationProcess.process(gps);//出站
  107 +
  108 + GpsCacheData.putGps(gps);//历史gps缓存
  109 + }catch (Exception e){
  110 + logger.error("", e);
  111 + }
  112 + }
  113 + } catch (Exception e) {
  114 + //logger.error("", e);
  115 + } finally {
  116 + if (count != null)
  117 + count.countDown();
  118 + }
  119 + }
  120 + }
  121 +
  122 + static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
  123 + @Override
  124 + public void uncaughtException(Thread t, Throwable e) {
  125 + logger.error("caught " , e);
  126 + }
  127 + }
  128 +
  129 + static class HandlerThreadFactory implements ThreadFactory {
  130 + @Override
  131 + public Thread newThread(Runnable r) {
  132 + Thread t = new Thread(r);
  133 + t.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
  134 + return t;
  135 + }
  136 + }
  137 +}
... ...
src/main/java/com/bsth/data/gpsdata/GpsRealData.java renamed to src/main/java/com/bsth/data/gpsdata_v2/GpsRealData.java
1   -package com.bsth.data.gpsdata;
2   -
3   -import com.bsth.data.BasicData;
4   -import com.bsth.data.forecast.ForecastRealServer;
5   -import com.bsth.data.schedule.DayOfSchedule;
6   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
7   -import com.google.common.collect.TreeMultimap;
8   -import org.apache.commons.lang3.StringUtils;
9   -import org.slf4j.Logger;
10   -import org.slf4j.LoggerFactory;
11   -import org.springframework.beans.factory.annotation.Autowired;
12   -import org.springframework.stereotype.Component;
13   -
14   -import java.util.*;
15   -import java.util.concurrent.ConcurrentHashMap;
16   -import java.util.concurrent.ConcurrentMap;
17   -
18   -/**
19   - * @author PanZhao
20   - * @ClassName: GpsRealData
21   - * @Description: TODO(实时GPS数据集合)
22   - * @date 2016年8月12日 下午2:04:41
23   - */
24   -@Component
25   -public class GpsRealData {
26   -
27   - static Logger logger = LoggerFactory.getLogger(GpsRealData.class);
28   -
29   - private static ConcurrentMap<String, GpsEntity> gpsMap;
30   -
31   - //按线路分组设备号
32   - private static TreeMultimap<String, String> lineCode2Devices;
33   -
34   - @Autowired
35   - DayOfSchedule dayOfSchedule;
36   -
37   - @Autowired
38   - ForecastRealServer forecastRealServer;
39   -
40   - /**
41   - * 构造函数
42   - */
43   - public GpsRealData() {
44   - gpsMap = new ConcurrentHashMap<>();
45   - lineCode2Devices = TreeMultimap.create();
46   - }
47   -
48   -
49   - public void put(GpsEntity gps) {
50   - String device = gps.getDeviceId();
51   - GpsEntity old = gpsMap.get(device);
52   -
53   - try {
54   - if (!StringUtils.isEmpty(gps.getStopNo())) {
55   - //站点编码改变
56   - if (null == old || !gps.getStopNo().equals(old.getStopNo())) {
57   - gps.setArrTime(gps.getTimestamp());
58   - //预测到达终点时间
59   - forecastRealServer.forecast(gps.getNbbm(), gps);
60   - } else {
61   - gps.setArrTime(old.getArrTime());
62   - //不预测, 重新计算终点时间
63   - gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));
64   - }
65   - }
66   -
67   - //刷新对照
68   - gpsMap.put(device, gps);
69   - if (StringUtils.isNotBlank(gps.getLineId())) {
70   - //站点名称
71   - gps.setStationName(getStationName(gps));
72   - lineCode2Devices.put(gps.getLineId(), device);
73   -
74   - if(old != null && !gps.getLineId().equals(old.getLineId()))
75   - lineCode2Devices.remove(old.getLineId(), device);
76   - }
77   -
78   - //车辆换设备了
79   - String nbbm = gps.getNbbm();
80   - if(old != null && StringUtils.isNotEmpty(nbbm) && !nbbm.equals(old.getNbbm())){
81   - List<GpsEntity> list = findByNbbm(nbbm);
82   - for(GpsEntity g : list){
83   - if(!g.getDeviceId().equals(device))
84   - gpsMap.remove(g.getDeviceId());
85   - }
86   - }
87   - } catch (Exception e) {
88   - logger.error("", e);
89   - }
90   - }
91   -
92   - public String getStationName(GpsEntity gps) {
93   - return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_");
94   - }
95   -
96   - /**
97   - * @Title: get @Description: TODO(设备号获取GPS)
98   - */
99   - public GpsEntity get(String deviceId) {
100   - return gpsMap.get(deviceId);
101   - }
102   -
103   - public List<GpsEntity> findByNbbm(String nbbm){
104   - Collection<GpsEntity> arr = gpsMap.values();
105   - List<GpsEntity> rs = new ArrayList<>();
106   - for(GpsEntity g : arr){
107   - if(nbbm.equals(g.getNbbm()))
108   - rs.add(g);
109   - }
110   - return rs;
111   - }
112   -
113   - public GpsEntity getByNbbm(String nbbm){
114   - String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
115   - if(StringUtils.isNotBlank(device))
116   - return get(device);
117   - else
118   - return null;
119   - }
120   -
121   - /**
122   - * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
123   - */
124   - public List<GpsEntity> getByLine(String lineCode) {
125   - NavigableSet<String> set = lineCode2Devices.get(lineCode);
126   -
127   - List<GpsEntity> rs = new ArrayList<>();
128   - GpsEntity gps;
129   - ScheduleRealInfo sch;
130   - for (String device : set) {
131   - gps = gpsMap.get(device);
132   - //过滤异常GPS数据
133   - if (gps == null || gps.isIncomplete())
134   - continue;
135   -
136   - sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());
137   - if (null != sch)
138   - gps.setSchId(sch.getId());
139   - rs.add(gps);
140   - }
141   -
142   - return rs;
143   - }
144   -
145   - public List<GpsEntity> get(List<String> pArray) {
146   - List<GpsEntity> list = new ArrayList<>();
147   -
148   - for (String code : pArray)
149   - list.addAll(getByLine(code));
150   - return list;
151   - }
152   -
153   - public Set<String> allDevices() {
154   - return gpsMap.keySet();
155   - }
156   -
157   - public Collection<GpsEntity> all() {
158   - return gpsMap.values();
159   - }
160   -
161   - public void remove(String device) {
162   - gpsMap.remove(device);
163   - }
  1 +package com.bsth.data.gpsdata_v2;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.forecast.ForecastRealServer;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.schedule.DayOfSchedule;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import com.google.common.collect.TreeMultimap;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.*;
  16 +import java.util.concurrent.ConcurrentHashMap;
  17 +import java.util.concurrent.ConcurrentMap;
  18 +
  19 +/**
  20 + * @author PanZhao
  21 + * @ClassName: GpsRealData
  22 + * @Description: TODO(实时GPS数据集合)
  23 + * @date 2016年8月12日 下午2:04:41
  24 + */
  25 +@Component
  26 +public class GpsRealData {
  27 +
  28 + static Logger logger = LoggerFactory.getLogger(GpsRealData.class);
  29 +
  30 + private static ConcurrentMap<String, GpsEntity> gpsMap;
  31 +
  32 + //按线路分组设备号
  33 + private static TreeMultimap<String, String> lineCode2Devices;
  34 +
  35 + @Autowired
  36 + DayOfSchedule dayOfSchedule;
  37 +
  38 + @Autowired
  39 + ForecastRealServer forecastRealServer;
  40 +
  41 + /**
  42 + * 构造函数
  43 + */
  44 + public GpsRealData() {
  45 + gpsMap = new ConcurrentHashMap<>();
  46 + lineCode2Devices = TreeMultimap.create();
  47 + }
  48 +
  49 +
  50 + public void put(GpsEntity gps) {
  51 + String device = gps.getDeviceId();
  52 + GpsEntity old = gpsMap.get(device);
  53 +
  54 + try {
  55 + if (!StringUtils.isEmpty(gps.getStopNo())) {
  56 + //站点编码改变
  57 + if (null == old || !gps.getStopNo().equals(old.getStopNo())) {
  58 + gps.setArrTime(gps.getTimestamp());
  59 + //预测到达终点时间
  60 + forecastRealServer.forecast(gps.getNbbm(), gps);
  61 + } else {
  62 + gps.setArrTime(old.getArrTime());
  63 + //不预测, 重新计算终点时间
  64 + gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));
  65 + }
  66 + }
  67 +
  68 + //刷新对照
  69 + gpsMap.put(device, gps);
  70 + if (StringUtils.isNotBlank(gps.getLineId())) {
  71 + //站点名称
  72 + gps.setStationName(getStationName(gps));
  73 + lineCode2Devices.put(gps.getLineId(), device);
  74 +
  75 + if(old != null && !gps.getLineId().equals(old.getLineId()))
  76 + lineCode2Devices.remove(old.getLineId(), device);
  77 + }
  78 +
  79 + //车辆换设备了
  80 + String nbbm = gps.getNbbm();
  81 + if(old != null && StringUtils.isNotEmpty(nbbm) && !nbbm.equals(old.getNbbm())){
  82 + List<GpsEntity> list = findByNbbm(nbbm);
  83 + for(GpsEntity g : list){
  84 + if(!g.getDeviceId().equals(device))
  85 + gpsMap.remove(g.getDeviceId());
  86 + }
  87 + }
  88 + } catch (Exception e) {
  89 + logger.error("", e);
  90 + }
  91 + }
  92 +
  93 + public String getStationName(GpsEntity gps) {
  94 + return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_");
  95 + }
  96 +
  97 + /**
  98 + * @Title: get @Description: TODO(设备号获取GPS)
  99 + */
  100 + public GpsEntity get(String deviceId) {
  101 + return gpsMap.get(deviceId);
  102 + }
  103 +
  104 + public List<GpsEntity> findByNbbm(String nbbm){
  105 + Collection<GpsEntity> arr = gpsMap.values();
  106 + List<GpsEntity> rs = new ArrayList<>();
  107 + for(GpsEntity g : arr){
  108 + if(nbbm.equals(g.getNbbm()))
  109 + rs.add(g);
  110 + }
  111 + return rs;
  112 + }
  113 +
  114 + public GpsEntity getByNbbm(String nbbm){
  115 + String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
  116 + if(StringUtils.isNotBlank(device))
  117 + return get(device);
  118 + else
  119 + return null;
  120 + }
  121 +
  122 + /**
  123 + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
  124 + */
  125 + public List<GpsEntity> getByLine(String lineCode) {
  126 + NavigableSet<String> set = lineCode2Devices.get(lineCode);
  127 +
  128 + List<GpsEntity> rs = new ArrayList<>();
  129 + GpsEntity gps;
  130 + ScheduleRealInfo sch;
  131 + for (String device : set) {
  132 + gps = gpsMap.get(device);
  133 + //过滤异常GPS数据
  134 + if (gps == null || StringUtils.isBlank(gps.getNbbm()))
  135 + continue;
  136 +
  137 + sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());
  138 + if (null != sch)
  139 + gps.setSchId(sch.getId());
  140 + rs.add(gps);
  141 + }
  142 +
  143 + return rs;
  144 + }
  145 +
  146 + public List<GpsEntity> get(List<String> pArray) {
  147 + List<GpsEntity> list = new ArrayList<>();
  148 +
  149 + for (String code : pArray)
  150 + list.addAll(getByLine(code));
  151 + return list;
  152 + }
  153 +
  154 + public Set<String> allDevices() {
  155 + return gpsMap.keySet();
  156 + }
  157 +
  158 + public Collection<GpsEntity> all() {
  159 + return gpsMap.values();
  160 + }
  161 +
  162 + public void remove(String device) {
  163 + gpsMap.remove(device);
  164 + }
164 165 }
165 166 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata_v2/cache/GeoCacheData.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.cache;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.CtLineString;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.entity.PreconditionGeo;
  6 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  7 +import com.bsth.data.gpsdata_v2.utils.StationRouteComp;
  8 +import com.bsth.util.Geo.Point;
  9 +import com.bsth.util.Geo.Polygon;
  10 +import com.google.common.base.Splitter;
  11 +import com.google.common.collect.ArrayListMultimap;
  12 +import org.apache.commons.lang3.StringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  17 +import org.springframework.jdbc.core.JdbcTemplate;
  18 +import org.springframework.jdbc.core.RowMapper;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import java.sql.ResultSet;
  22 +import java.sql.SQLException;
  23 +import java.util.*;
  24 +
  25 +/**
  26 + * 空间数据缓存
  27 + * Created by panzhao on 2017/11/15.
  28 + */
  29 +@Component
  30 +public class GeoCacheData {
  31 +
  32 + static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);
  33 +
  34 + /**
  35 + * 线路路段走向
  36 + */
  37 + private static ArrayListMultimap<String, CtLineString> sectionCacheMap;
  38 + /**
  39 + * 路段编码和名称对照
  40 + */
  41 + private static Map<String, String> sectionCode2Name;
  42 + /**
  43 + * 线路站点路由
  44 + */
  45 + private static ArrayListMultimap<String, StationRoute> stationCacheMap;
  46 + /**
  47 + * 线路前置进站围栏
  48 + */
  49 + public static ArrayListMultimap<String, PreconditionGeo> premiseGeoMap;
  50 + /**
  51 + * 线路_上下行_站点编码 ——> 站点
  52 + */
  53 + private static Map<String, StationRoute> routeCodeMap;
  54 + /**
  55 + * 停车场
  56 + */
  57 + public static Map<String, Polygon> tccMap;
  58 + /**
  59 + * 线路限速信息
  60 + */
  61 + private static Map<String, Double> speedLimitMap;
  62 +
  63 + @Autowired
  64 + JdbcTemplate jdbcTemplate;
  65 +
  66 + public void loadData() {
  67 + loadStationRoutesData();
  68 + loadTccMapData();
  69 + loadSpeedLimit();
  70 +
  71 + //加载路段信息
  72 + loadRoadsData();
  73 +
  74 + //加载前置进站围栏
  75 + loadPremiseGeoData();
  76 + }
  77 +
  78 + public static List<StationRoute> getStationRoute(String lineCode, int directions) {
  79 + return stationCacheMap.get(lineCode + "_" + directions);
  80 + }
  81 +
  82 + public static StationRoute getRouteCode(GpsEntity gps) {
  83 + return routeCodeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo());
  84 + }
  85 +
  86 + public static Double speedLimit(String lineCode){
  87 + return speedLimitMap.get(lineCode);
  88 + }
  89 +
  90 + public static List<CtLineString> getLineStringList(GpsEntity gps){
  91 + return sectionCacheMap.get(gps.getLineId() + "_" + gps.getUpDown());
  92 + }
  93 +
  94 + private void loadStationRoutesData(){
  95 + String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE,s.STATION_NAME from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code";
  96 + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
  97 +
  98 + @Override
  99 + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
  100 + StationRoute sRoute = new StationRoute();
  101 + sRoute.setCode(rs.getString("STATION_CODE"));
  102 + sRoute.setLineCode(rs.getString("LINE_CODE"));
  103 + sRoute.setDirections(rs.getInt("DIRECTIONS"));
  104 + sRoute.setPoint(new Point(rs.getFloat("G_LONX"), rs.getFloat("G_LATY")));
  105 + sRoute.setRadius(rs.getFloat("RADIUS"));
  106 + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
  107 + sRoute.setMark(rs.getString("STATION_MARK"));
  108 + sRoute.setName(rs.getString("STATION_NAME"));
  109 +
  110 + String shapesType = rs.getString("SHAPES_TYPE");
  111 + //多边形电子围栏
  112 + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d"))
  113 + sRoute.setPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));
  114 + return sRoute;
  115 + }
  116 + });
  117 +
  118 + //按线路和走向分组
  119 + if (routeList.size() > 0) {
  120 + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
  121 + Map<String, StationRoute> codeMap = new HashMap<>(routeList.size());
  122 + for (StationRoute sr : routeList) {
  123 + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  124 + //站点编码 ——> 和路由顺序对照
  125 + codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr);
  126 + }
  127 +
  128 + StationRouteComp srCom = new StationRouteComp();
  129 + //连接路由
  130 + Set<String> set = tempMap.keySet();
  131 + for (String key : set) {
  132 + Collections.sort(tempMap.get(key), srCom);
  133 + connectStationRoute(tempMap.get(key));
  134 + }
  135 + stationCacheMap = tempMap;
  136 + routeCodeMap = codeMap;
  137 + }
  138 + }
  139 +
  140 + private void loadTccMapData(){
  141 + //加载停车场数据
  142 + String sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null";
  143 + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
  144 + Map<String, Polygon> tccTempMap = new HashMap<>();
  145 +
  146 + Polygon polygon;
  147 + for (Map<String, Object> tMap : tccList) {
  148 +
  149 + try {
  150 + polygon = parsePolygon(tMap.get("G_PARK_POINT").toString());
  151 + tccTempMap.put(tMap.get("PARK_CODE").toString()
  152 + , polygon);
  153 + } catch (Exception e) {
  154 + logger.error("停车场:" + tMap.get("PARK_CODE"), e);
  155 + }
  156 + }
  157 + if (tccTempMap.size() > 0){
  158 + tccMap = tccTempMap;
  159 + }
  160 + }
  161 +
  162 + private void loadSpeedLimit(){
  163 + //加载线路限速信息
  164 + String sql = "select l.LINE_CODE,i.SPEEDING from bsth_c_line_information i left join bsth_c_line l on i.line=l.id where i.speed_limit is not null";
  165 + List<Map<String, Object>> speedMap = jdbcTemplate.queryForList(sql);
  166 + Map<String, Double> speedTempMap = new HashMap<>();
  167 + for (Map<String, Object> tMap : speedMap) {
  168 + try {
  169 + speedTempMap.put(tMap.get("LINE_CODE").toString(), Double.parseDouble(tMap.get("SPEEDING").toString()));
  170 + } catch (NumberFormatException e) {
  171 + logger.error("speeding is null...");
  172 + }
  173 + }
  174 + speedLimitMap = speedTempMap;
  175 + }
  176 +
  177 + private void loadRoadsData() {
  178 + //加载线路下路段空间数据
  179 + String sql = "select r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) as GSECTION_VECTOR, r.DIRECTIONS, s.CROSES_ROAD from bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section=s.id where r.destroy=0 and GSECTION_VECTOR is not null order by line_code,directions,sectionroute_code";
  180 + List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql);
  181 +
  182 + String polygonStr, key;
  183 + String[] coords;
  184 + int i, len;
  185 + ArrayListMultimap<String, CtLineString> sectionCacheTempMap = ArrayListMultimap.create();
  186 + String[] temps1, temps2;
  187 + CtLineString lineString;
  188 + for (Map<String, Object> tMap : secList) {
  189 + //空间数据映射
  190 + polygonStr = tMap.get("GSECTION_VECTOR").toString();
  191 + key = tMap.get("LINE_CODE") + "_" + tMap.get("DIRECTIONS");
  192 +
  193 + coords = polygonStr.substring(11, polygonStr.length() - 1).split(",");
  194 + len = coords.length - 1;
  195 + //每2个点连一条线
  196 + for(i = 0; i < len; i ++){
  197 + temps1 = coords[i].split(" ");
  198 + temps2 = coords[i + 1].split(" ");
  199 +
  200 + lineString = new CtLineString();
  201 + lineString.setS(new Point(Float.parseFloat(temps1[0]), Float.parseFloat(temps1[1])));
  202 + lineString.setE(new Point(Float.parseFloat(temps2[0]), Float.parseFloat(temps2[1])));
  203 +
  204 + sectionCacheTempMap.put(key, lineString);
  205 + }
  206 + }
  207 +
  208 + if(sectionCacheTempMap.size() > 0)
  209 + sectionCacheMap = sectionCacheTempMap;
  210 +
  211 + Map<String, String> sectionCode2NameTemp = new HashMap<>();
  212 +
  213 + //加载全量路段编码和名称对照
  214 + sql = "select SECTION_CODE,SECTION_NAME,CROSES_ROAD from bsth_c_section";
  215 + secList = jdbcTemplate.queryForList(sql);
  216 + String name = null, code;
  217 + for (Map<String, Object> tMap : secList) {
  218 + if(tMap.get("CROSES_ROAD") != null && StringUtils.isNotEmpty(tMap.get("CROSES_ROAD").toString()))
  219 + name = tMap.get("CROSES_ROAD").toString();
  220 + else if(tMap.get("SECTION_NAME") != null && StringUtils.isNotEmpty(tMap.get("SECTION_NAME").toString()))
  221 + name = tMap.get("SECTION_NAME").toString();
  222 +
  223 + code = tMap.get("SECTION_CODE").toString();
  224 + sectionCode2NameTemp.put(code, name);
  225 + }
  226 + if(sectionCode2NameTemp.size() > 0)
  227 + sectionCode2Name = sectionCode2NameTemp;
  228 + }
  229 +
  230 + private void loadPremiseGeoData() {
  231 + ArrayListMultimap<String, PreconditionGeo> premiseGeoMapCopy = ArrayListMultimap.create();
  232 +
  233 + String sql = "select * from bsth_f_geo_premise";
  234 + List<PreconditionGeo> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PreconditionGeo.class));
  235 +
  236 + List<String> coordList;
  237 + String[] cs;
  238 + Point point;
  239 + List<Point> ps;
  240 + StationRoute sr;
  241 + for(PreconditionGeo p : list){
  242 + try{
  243 + sr = routeCodeMap.get(p.getLineCode()+"_"+p.getUpDown()+"_"+p.getStationCode());
  244 + p.setOrder(sr.getRouteSort());
  245 + //polygon
  246 + ps = new ArrayList<>();
  247 + coordList = Splitter.on(",").trimResults().splitToList(p.getCoords());
  248 + for(String c : coordList){
  249 + cs = c.split(" ");
  250 + point = new Point(Double.parseDouble(cs[0]), Double.parseDouble(cs[1]));
  251 + ps.add(point);
  252 + }
  253 +
  254 + p.setPolygon(new Polygon(ps));
  255 +
  256 + sr.setPremise(true);
  257 + //按线路,走向分组
  258 + premiseGeoMapCopy.put(p.getLineCode()+"_"+p.getUpDown(), p);
  259 + }catch (Exception e){
  260 + logger.error("", e);
  261 + }
  262 + }
  263 +
  264 + //排序
  265 + Set<String> ks = premiseGeoMapCopy.keySet();
  266 + PreconditionGeoComp comp = new PreconditionGeoComp();
  267 + for(String k : ks){
  268 + Collections.sort(premiseGeoMapCopy.get(k), comp);
  269 + }
  270 +
  271 + premiseGeoMap = premiseGeoMapCopy;
  272 + }
  273 +
  274 + public Polygon parsePolygon(String polygonStr) {
  275 + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
  276 +
  277 + List<Point> cds = new ArrayList<>(coords.length);
  278 + int len = coords.length;
  279 + for (int i = 0; i < len; i++) {
  280 + temps = coords[i].split(" ");
  281 + cds.add(new Point(Float.parseFloat(temps[1]), Float.parseFloat(temps[0])));
  282 + }
  283 + return new Polygon(cds);
  284 + }
  285 +
  286 + private void connectStationRoute(List<StationRoute> list) {
  287 + int size = list.size();
  288 + StationRoute sr = null;
  289 + for (int i = 0; i < size; i++) {
  290 + sr = list.get(i);
  291 + //上一个
  292 + if (i > 0)
  293 + sr.setPrve(list.get(i - 1));
  294 + //下一个
  295 + if (i < size - 1)
  296 + sr.setNext(list.get(i + 1));
  297 + }
  298 + }
  299 +
  300 + private static class PreconditionGeoComp implements Comparator<PreconditionGeo>{
  301 +
  302 + @Override
  303 + public int compare(PreconditionGeo p1, PreconditionGeo p2) {
  304 + return p1.getOrder() - p2.getOrder();
  305 + }
  306 + }
  307 +
  308 + public static Map<String, String> sectionCode2NameMap(){
  309 + return sectionCode2Name;
  310 + }
  311 +}
... ...
src/main/java/com/bsth/data/gpsdata_v2/cache/GpsCacheData.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.cache;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  4 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  5 +import com.bsth.data.gpsdata_v2.entity.trail.GpsExecTrail;
  6 +import com.bsth.data.gpsdata_v2.utils.CircleQueue;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +
  11 +import java.util.*;
  12 +
  13 +/**
  14 + * gps 数据缓存
  15 + * Created by panzhao on 2017/11/15.
  16 + */
  17 +public class GpsCacheData {
  18 +
  19 + /**
  20 + * 每辆车缓存最后300条gps
  21 + */
  22 + private static final int CACHE_SIZE = 300;
  23 + private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>();
  24 +
  25 + /**
  26 + * 车辆执行班次的详细 进出站数据
  27 + */
  28 + private static ArrayListMultimap<String, GpsExecTrail> trailListMultimap = ArrayListMultimap.create();
  29 +
  30 + static Logger logger = LoggerFactory.getLogger(GpsCacheData.class);
  31 +
  32 + public static CircleQueue<GpsEntity> getGps(String device) {
  33 + return gpsCacheMap.get(device);
  34 + }
  35 +
  36 + public static GpsExecTrail gpsExecTrail(String nbbm){
  37 + List<GpsExecTrail> list = trailListMultimap.get(nbbm);
  38 +
  39 + GpsExecTrail trail;
  40 + if(null == list || list.size() == 0
  41 + || list.get(list.size() - 1).isEnd()){
  42 + trail = new GpsExecTrail();
  43 +
  44 + trailListMultimap.put(nbbm, trail);
  45 + }
  46 + else{
  47 + trail = list.get(list.size() - 1);
  48 + }
  49 +
  50 + return trail;
  51 + }
  52 +
  53 + public static void out(GpsEntity gps){
  54 + GpsExecTrail trail = gpsExecTrail(gps.getNbbm());
  55 + trail.getSrs().add(gps);
  56 +
  57 + }
  58 +
  59 + public static void in(GpsEntity gps, boolean end){
  60 + GpsExecTrail trail = gpsExecTrail(gps.getNbbm());
  61 + trail.getSrs().add(gps);
  62 + trail.setEnd(end);
  63 + }
  64 +
  65 + public static GpsEntity getPrev(GpsEntity gps){
  66 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId());
  67 + if(queue != null)
  68 + return queue.getTail();
  69 + return null;
  70 + }
  71 +
  72 + public static void putGps(GpsEntity gps) {
  73 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId());
  74 + if (queue == null) {
  75 + queue = new CircleQueue<>(CACHE_SIZE);
  76 + gpsCacheMap.put(gps.getDeviceId(), queue);
  77 + }
  78 + queue.add(gps);
  79 + }
  80 +
  81 + public static void clear(String deviceId) {
  82 + try {
  83 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(deviceId);
  84 + if (queue != null)
  85 + queue.clear();
  86 + } catch (Exception e) {
  87 + logger.error("", e);
  88 + }
  89 + }
  90 +
  91 + public static StationRoute prevStation(GpsEntity gps) {
  92 + List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm());
  93 + if(null == trails || trails.size() == 0)
  94 + return null;
  95 +
  96 + GpsEntity prev;
  97 + for(int i = trails.size() - 1; i > 0; i--){
  98 + prev = trails.get(i).getSrs().peekLast();
  99 +
  100 + if(prev != null){
  101 + return GeoCacheData.getRouteCode(prev);
  102 + }
  103 + }
  104 + return null;
  105 + }
  106 +
  107 + public static List<StationRoute> prevMultiStation(GpsEntity gps) {
  108 + List<StationRoute> rs = new ArrayList<>();
  109 + List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm());
  110 + if(null == trails || trails.size() == 0)
  111 + return null;
  112 +
  113 + for(int i = trails.size() - 1; i > 0; i--){
  114 + rs.addAll(searchLinked(trails.get(i).getSrs(), gps.getUpDown()));
  115 + if(rs.size() > 3)
  116 + break;
  117 + }
  118 + return rs;
  119 + }
  120 +
  121 + private static List<StationRoute> searchLinked(LinkedList<GpsEntity> list, int upDown){
  122 + List<StationRoute> rs = new ArrayList<>();
  123 + Iterator<GpsEntity> iterator = list.iterator();
  124 + GpsEntity gps;
  125 + int prevCode=0;
  126 + while (iterator.hasNext()){
  127 + gps = iterator.next();
  128 + if(gps.getInstation()!=1)
  129 + continue;
  130 +
  131 + if(gps.getUpDown() != upDown)
  132 + break;
  133 +
  134 + if(gps.getStation().getRouteSort() != prevCode)
  135 + rs.add(gps.getStation());
  136 +
  137 + prevCode = gps.getStation().getRouteSort();
  138 +
  139 + if(rs.size() >= 3)
  140 + break;
  141 + }
  142 + return rs;
  143 + }
  144 +}
... ...
src/main/java/com/bsth/data/gpsdata_v2/entity/CtLineString.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.entity;
  2 +
  3 +import com.bsth.util.Geo.Point;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * Created by panzhao on 2017/11/15.
  9 + */
  10 +public class CtLineString {
  11 +
  12 + public CtLineString(){}
  13 + public CtLineString(List<Point> ps){
  14 + s = ps.get(0);
  15 + e = ps.get(1);
  16 + }
  17 +
  18 + Point s;
  19 +
  20 + Point e;
  21 +
  22 + public Point getS() {
  23 + return s;
  24 + }
  25 +
  26 + public void setS(Point s) {
  27 + this.s = s;
  28 + }
  29 +
  30 + public Point getE() {
  31 + return e;
  32 + }
  33 +
  34 + public void setE(Point e) {
  35 + this.e = e;
  36 + }
  37 +}
... ...
src/main/java/com/bsth/data/gpsdata/GpsEntity.java renamed to src/main/java/com/bsth/data/gpsdata_v2/entity/GpsEntity.java
1   -package com.bsth.data.gpsdata;
2   -
3   -import com.bsth.data.gpsdata.arrival.entity.StationRoute;
4   -import com.fasterxml.jackson.annotation.JsonIgnore;
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   -public class GpsEntity implements Cloneable{
15   -
16   - /** 公司代码 */
17   - private Short companyCode;
18   -
19   - /** 线路编码 */
20   - private String lineId;
21   -
22   - /** 设备编码 */
23   - private String deviceId;
24   -
25   - /** 停车场编码 */
26   - private String carparkNo;
27   -
28   - /** 站点编码 */
29   - private String stopNo;
30   -
31   - /** 站点名称 */
32   - private String stationName;
33   -
34   - /** 到站时间 */
35   - private long arrTime;
36   -
37   - /** 经度 */
38   - private Float lon;
39   -
40   - /** 纬度 */
41   - private Float lat;
42   -
43   - /** GPS发送时间戳 */
44   - private Long timestamp;
45   -
46   - /** 网关收到时间 */
47   - private Long serverTimestamp;
48   -
49   - /** 速度 */
50   - private Float speed;
51   -
52   - /** 方向(角度) */
53   - private float direction;
54   -
55   - /** 营运状态( 0 营运 ,1 非营运, -1 无效) */
56   - private Integer state;
57   -
58   - /** 上下行(0 上行 , 1 下行 , -1 无效) */
59   - private Byte upDown;
60   -
61   - /** 车辆内部编码 */
62   - private String nbbm;
63   -
64   - /** 预计到达终点时间 */
65   - private Float expectStopTime;
66   -
67   - /** 当前执行班次ID */
68   - private Long schId;
69   -
70   - /** 是否是不完整的数据 */
71   - private boolean incomplete;
72   -
73   - private int version;
74   -
75   - /** 0: 站外 1:站内 2:场内 */
76   - private int instation;
77   -
78   - /** 站点信息,站内时有值 */
79   - @JsonIgnore
80   - private StationRoute station;
81   -
82   - /**
83   - * 前置约束 -站点编码
84   - */
85   - @JsonIgnore
86   - private String premiseCode;
87   -
88   - /** 状态 */
89   - private String signalState = "normal";
90   -
91   - /** 异常状态 */
92   - private String abnormalStatus;
93   -
94   - /** 越界距离 */
95   - private double outOfBoundDistance;
96   -
97   - /** gps是否有效 设备端发送的状态 */
98   - private int valid;
99   -
100   - /**
101   - * 数据来源
102   - * 1:网关
103   - * 0:转发
104   - */
105   - private int source = -1;
106   -
107   - public Object clone() {
108   - try {
109   - return super.clone();
110   - } catch (CloneNotSupportedException e) {
111   - return null;
112   - }
113   - }
114   -
115   - public String getDeviceId() {
116   - return deviceId;
117   - }
118   -
119   - public void setDeviceId(String deviceId) {
120   - this.deviceId = deviceId;
121   - }
122   -
123   - public String getCarparkNo() {
124   - return carparkNo;
125   - }
126   -
127   - public void setCarparkNo(String carparkNo) {
128   - this.carparkNo = carparkNo;
129   - }
130   -
131   - public String getStopNo() {
132   - return stopNo;
133   - }
134   -
135   - public void setStopNo(String stopNo) {
136   - this.stopNo = stopNo;
137   - }
138   -
139   - public Float getLon() {
140   - return lon;
141   - }
142   -
143   - public void setLon(Float lon) {
144   - this.lon = lon;
145   - }
146   -
147   - public Float getLat() {
148   - return lat;
149   - }
150   -
151   - public void setLat(Float lat) {
152   - this.lat = lat;
153   - }
154   -
155   - public Long getTimestamp() {
156   - return timestamp;
157   - }
158   -
159   - public void setTimestamp(Long timestamp) {
160   - this.timestamp = timestamp;
161   - }
162   -
163   -
164   - public Integer getState() {
165   - return state;
166   - }
167   -
168   - public void setState(Integer state) {
169   - this.state = state;
170   - }
171   -
172   - public String getNbbm() {
173   - return nbbm;
174   - }
175   -
176   - public void setNbbm(String nbbm) {
177   - this.nbbm = nbbm;
178   - }
179   -
180   - public String getStationName() {
181   - return stationName;
182   - }
183   -
184   - public void setStationName(String stationName) {
185   - this.stationName = stationName;
186   - }
187   -
188   - public long getArrTime() {
189   - return arrTime;
190   - }
191   -
192   - public void setArrTime(long arrTime) {
193   - this.arrTime = arrTime;
194   - }
195   -
196   - public Float getExpectStopTime() {
197   - return expectStopTime;
198   - }
199   -
200   - public void setExpectStopTime(Float expectStopTime) {
201   - this.expectStopTime = expectStopTime;
202   - }
203   -
204   - public String getLineId() {
205   - return lineId;
206   - }
207   -
208   - public void setLineId(String lineId) {
209   - this.lineId = lineId;
210   - }
211   -
212   - public Long getSchId() {
213   - return schId;
214   - }
215   -
216   - public void setSchId(Long schId) {
217   - this.schId = schId;
218   - }
219   -
220   -
221   - public int getVersion() {
222   - return version;
223   - }
224   -
225   - public void setVersion(int version) {
226   - this.version = version;
227   - }
228   -
229   - public StationRoute getStation() {
230   - return station;
231   - }
232   -
233   - public void setStation(StationRoute station) {
234   - this.station = station;
235   - }
236   -
237   - public String getSignalState() {
238   - return signalState;
239   - }
240   -
241   - public void setSignalState(String signalState) {
242   - this.signalState = signalState;
243   - }
244   -
245   - public int getInstation() {
246   - return instation;
247   - }
248   -
249   - public void setInstation(int instation) {
250   - this.instation = instation;
251   - }
252   -
253   - public String getAbnormalStatus() {
254   - return abnormalStatus;
255   - }
256   -
257   - public void setAbnormalStatus(String abnormalStatus) {
258   - this.abnormalStatus = abnormalStatus;
259   - }
260   -
261   - public boolean isIncomplete() {
262   - return incomplete;
263   - }
264   -
265   - public void setIncomplete(boolean incomplete) {
266   - this.incomplete = incomplete;
267   - }
268   -
269   - public double getOutOfBoundDistance() {
270   - return outOfBoundDistance;
271   - }
272   -
273   - public void setOutOfBoundDistance(double outOfBoundDistance) {
274   - this.outOfBoundDistance = outOfBoundDistance;
275   - }
276   -
277   - public int getValid() {
278   - return valid;
279   - }
280   -
281   - public void setValid(int valid) {
282   - this.valid = valid;
283   - }
284   -
285   -
286   -
287   - public short getCompanyCode() {
288   - return companyCode;
289   - }
290   -
291   - public void setCompanyCode(short companyCode) {
292   - this.companyCode = companyCode;
293   - }
294   -
295   - public Byte getUpDown() {
296   - return upDown;
297   - }
298   -
299   - public void setUpDown(Byte upDown) {
300   - this.upDown = upDown;
301   - }
302   -
303   -
304   - public float getDirection() {
305   - return direction;
306   - }
307   -
308   - public void setDirection(float direction) {
309   - this.direction = direction;
310   - }
311   -
312   - public Float getSpeed() {
313   - return speed;
314   - }
315   -
316   - public void setSpeed(Float speed) {
317   - this.speed = speed;
318   - }
319   -
320   - public int getSource() {
321   - return source;
322   - }
323   -
324   - public void setSource(int source) {
325   - this.source = source;
326   - }
327   -
328   - public void offline(){
329   - this.setAbnormalStatus("offline");
330   - }
331   -
332   -/* public boolean isOnline(){
333   - if(isOffline())
334   - return false;
335   -
336   - long t = System.currentTimeMillis();
337   -
338   - if((t - this.getServerTimestamp()) > 1000 * 60 * 2){
339   - return false;
340   - }
341   -
342   - if((this.getServerTimestamp() - t) > 1000 * 60 * 3){
343   - return false;
344   - }
345   - return true;
346   - }*/
347   -
348   - /**
349   - * 是否营运
350   - * @return
351   - */
352   - public boolean isService(){
353   - return state!=null && state==0;
354   - }
355   -
356   - public boolean isOffline(){
357   - return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline");
358   - }
359   -
360   - public Long getServerTimestamp() {
361   - return serverTimestamp;
362   - }
363   -
364   - public void setServerTimestamp(Long serverTimestamp) {
365   - this.serverTimestamp = serverTimestamp;
366   - }
367   -
368   - public String getPremiseCode() {
369   - return premiseCode;
370   - }
371   -
372   - public void setPremiseCode(String premiseCode) {
373   - this.premiseCode = premiseCode;
374   - }
375   -}
  1 +package com.bsth.data.gpsdata_v2.entity;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonIgnore;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: GpsRealData
  8 + * @Description: TODO(HTTP接口的实时GPS数据)
  9 + * @author PanZhao
  10 + * @date 2016年5月11日 下午4:32:07
  11 + *
  12 + */
  13 +public class GpsEntity implements Cloneable{
  14 +
  15 + /** 公司代码 */
  16 + private Short companyCode;
  17 +
  18 + /** 线路编码 */
  19 + private String lineId;
  20 +
  21 + /** 设备编码 */
  22 + private String deviceId;
  23 +
  24 + /** 停车场编码 */
  25 + private String carparkNo;
  26 +
  27 + /** 站点编码 */
  28 + private String stopNo;
  29 +
  30 + /** 站点名称 */
  31 + private String stationName;
  32 +
  33 + /** 到站时间 */
  34 + private long arrTime;
  35 +
  36 + /** 经度 */
  37 + private Float lon;
  38 +
  39 + /** 纬度 */
  40 + private Float lat;
  41 +
  42 + /** GPS发送时间戳 */
  43 + private Long timestamp;
  44 +
  45 + /** 网关收到时间 */
  46 + private Long serverTimestamp;
  47 +
  48 + /** 速度 */
  49 + private Float speed;
  50 +
  51 + /** 方向(角度) */
  52 + private float direction;
  53 +
  54 + /** 营运状态( 0 营运 ,1 非营运, -1 无效) */
  55 + private Integer state;
  56 +
  57 + /** 上下行(0 上行 , 1 下行 , -1 无效) */
  58 + private Byte upDown;
  59 +
  60 + /** 车辆内部编码 */
  61 + private String nbbm;
  62 +
  63 + /** 预计到达终点时间 */
  64 + private Float expectStopTime;
  65 +
  66 + /** 当前执行班次ID */
  67 + private Long schId;
  68 +
  69 + private int version;
  70 +
  71 + /** 0: 站外 1:站内 2:场内 */
  72 + private int instation;
  73 +
  74 + /** 站点信息,站内时有值 */
  75 + @JsonIgnore
  76 + private StationRoute station;
  77 +
  78 + /**
  79 + * 前置约束 -站点编码
  80 + */
  81 + @JsonIgnore
  82 + private String premiseCode;
  83 +
  84 + /** 状态 */
  85 + private String signalState = "normal";
  86 +
  87 + /** 异常状态 */
  88 + private String abnormalStatus;
  89 +
  90 + /** 越界距离 */
  91 + private double outOfBoundDistance;
  92 +
  93 + /** gps是否有效 设备端发送的状态 */
  94 + private int valid;
  95 +
  96 + /**
  97 + * 数据来源
  98 + * 1:网关
  99 + * 0:转发
  100 + */
  101 + private int source = -1;
  102 +
  103 + public Object clone() {
  104 + try {
  105 + return super.clone();
  106 + } catch (CloneNotSupportedException e) {
  107 + return null;
  108 + }
  109 + }
  110 +
  111 + public String getDeviceId() {
  112 + return deviceId;
  113 + }
  114 +
  115 + public void setDeviceId(String deviceId) {
  116 + this.deviceId = deviceId;
  117 + }
  118 +
  119 + public String getCarparkNo() {
  120 + return carparkNo;
  121 + }
  122 +
  123 + public void setCarparkNo(String carparkNo) {
  124 + this.carparkNo = carparkNo;
  125 + }
  126 +
  127 + public String getStopNo() {
  128 + return stopNo;
  129 + }
  130 +
  131 + public void setStopNo(String stopNo) {
  132 + this.stopNo = stopNo;
  133 + }
  134 +
  135 + public Float getLon() {
  136 + return lon;
  137 + }
  138 +
  139 + public void setLon(Float lon) {
  140 + this.lon = lon;
  141 + }
  142 +
  143 + public Float getLat() {
  144 + return lat;
  145 + }
  146 +
  147 + public void setLat(Float lat) {
  148 + this.lat = lat;
  149 + }
  150 +
  151 + public Long getTimestamp() {
  152 + return timestamp;
  153 + }
  154 +
  155 + public void setTimestamp(Long timestamp) {
  156 + this.timestamp = timestamp;
  157 + }
  158 +
  159 +
  160 + public Integer getState() {
  161 + return state;
  162 + }
  163 +
  164 + public void setState(Integer state) {
  165 + this.state = state;
  166 + }
  167 +
  168 + public String getNbbm() {
  169 + return nbbm;
  170 + }
  171 +
  172 + public void setNbbm(String nbbm) {
  173 + this.nbbm = nbbm;
  174 + }
  175 +
  176 + public String getStationName() {
  177 + return stationName;
  178 + }
  179 +
  180 + public void setStationName(String stationName) {
  181 + this.stationName = stationName;
  182 + }
  183 +
  184 + public long getArrTime() {
  185 + return arrTime;
  186 + }
  187 +
  188 + public void setArrTime(long arrTime) {
  189 + this.arrTime = arrTime;
  190 + }
  191 +
  192 + public Float getExpectStopTime() {
  193 + return expectStopTime;
  194 + }
  195 +
  196 + public void setExpectStopTime(Float expectStopTime) {
  197 + this.expectStopTime = expectStopTime;
  198 + }
  199 +
  200 + public String getLineId() {
  201 + return lineId;
  202 + }
  203 +
  204 + public void setLineId(String lineId) {
  205 + this.lineId = lineId;
  206 + }
  207 +
  208 + public Long getSchId() {
  209 + return schId;
  210 + }
  211 +
  212 + public void setSchId(Long schId) {
  213 + this.schId = schId;
  214 + }
  215 +
  216 +
  217 + public int getVersion() {
  218 + return version;
  219 + }
  220 +
  221 + public void setVersion(int version) {
  222 + this.version = version;
  223 + }
  224 +
  225 + public StationRoute getStation() {
  226 + return station;
  227 + }
  228 +
  229 + public void setStation(StationRoute station) {
  230 + this.station = station;
  231 + }
  232 +
  233 + public String getSignalState() {
  234 + return signalState;
  235 + }
  236 +
  237 + public void setSignalState(String signalState) {
  238 + this.signalState = signalState;
  239 + }
  240 +
  241 + public int getInstation() {
  242 + return instation;
  243 + }
  244 +
  245 + public void setInstation(int instation) {
  246 + this.instation = instation;
  247 + }
  248 +
  249 + public String getAbnormalStatus() {
  250 + return abnormalStatus;
  251 + }
  252 +
  253 + public void setAbnormalStatus(String abnormalStatus) {
  254 + this.abnormalStatus = abnormalStatus;
  255 + }
  256 +
  257 + public double getOutOfBoundDistance() {
  258 + return outOfBoundDistance;
  259 + }
  260 +
  261 + public void setOutOfBoundDistance(double outOfBoundDistance) {
  262 + this.outOfBoundDistance = outOfBoundDistance;
  263 + }
  264 +
  265 + public int getValid() {
  266 + return valid;
  267 + }
  268 +
  269 + public void setValid(int valid) {
  270 + this.valid = valid;
  271 + }
  272 +
  273 +
  274 +
  275 + public short getCompanyCode() {
  276 + return companyCode;
  277 + }
  278 +
  279 + public void setCompanyCode(short companyCode) {
  280 + this.companyCode = companyCode;
  281 + }
  282 +
  283 + public Byte getUpDown() {
  284 + return upDown;
  285 + }
  286 +
  287 + public void setUpDown(Byte upDown) {
  288 + this.upDown = upDown;
  289 + }
  290 +
  291 +
  292 + public float getDirection() {
  293 + return direction;
  294 + }
  295 +
  296 + public void setDirection(float direction) {
  297 + this.direction = direction;
  298 + }
  299 +
  300 + public Float getSpeed() {
  301 + return speed;
  302 + }
  303 +
  304 + public void setSpeed(Float speed) {
  305 + this.speed = speed;
  306 + }
  307 +
  308 + public int getSource() {
  309 + return source;
  310 + }
  311 +
  312 + public void setSource(int source) {
  313 + this.source = source;
  314 + }
  315 +
  316 + public void offline(){
  317 + this.setAbnormalStatus("offline");
  318 + }
  319 +
  320 +/* public boolean isOnline(){
  321 + if(isOffline())
  322 + return false;
  323 +
  324 + long t = System.currentTimeMillis();
  325 +
  326 + if((t - this.getServerTimestamp()) > 1000 * 60 * 2){
  327 + return false;
  328 + }
  329 +
  330 + if((this.getServerTimestamp() - t) > 1000 * 60 * 3){
  331 + return false;
  332 + }
  333 + return true;
  334 + }*/
  335 +
  336 + /**
  337 + * 是否营运
  338 + * @return
  339 + */
  340 + public boolean isService(){
  341 + return state!=null && state==0;
  342 + }
  343 +
  344 + public boolean isOffline(){
  345 + return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline");
  346 + }
  347 +
  348 + public Long getServerTimestamp() {
  349 + return serverTimestamp;
  350 + }
  351 +
  352 + public void setServerTimestamp(Long serverTimestamp) {
  353 + this.serverTimestamp = serverTimestamp;
  354 + }
  355 +
  356 + public String getPremiseCode() {
  357 + return premiseCode;
  358 + }
  359 +
  360 + public void setPremiseCode(String premiseCode) {
  361 + this.premiseCode = premiseCode;
  362 + }
  363 +}
... ...
src/main/java/com/bsth/data/gpsdata/arrival/precondition/entity/PreconditionGeo.java renamed to src/main/java/com/bsth/data/gpsdata_v2/entity/PreconditionGeo.java
1   -package com.bsth.data.gpsdata.arrival.precondition.entity;
2   -
3   -import com.bsth.util.Geo.Polygon;
4   -
5   -/**
6   - * 前置围栏 -地理坐标
7   - * Created by panzhao on 2017/9/23.
8   - */
9   -public class PreconditionGeo {
10   -
11   - private String name;
12   -
13   - /**
14   - * 前置约束的站点编码
15   - */
16   - private String stationCode;
17   -
18   - /**
19   - * 线路编码
20   - */
21   - private String lineCode;
22   -
23   - /**
24   - * 上下行
25   - */
26   - private int upDown;
27   -
28   - /**
29   - * 多边形坐标
30   - */
31   - private String coords;
32   -
33   - private com.bsth.util.Geo.Polygon polygon;
34   -
35   - private Integer order;
36   -
37   - public String getName() {
38   - return name;
39   - }
40   -
41   - public void setName(String name) {
42   - this.name = name;
43   - }
44   -
45   - public String getStationCode() {
46   - return stationCode;
47   - }
48   -
49   - public void setStationCode(String stationCode) {
50   - this.stationCode = stationCode;
51   - }
52   -
53   - public String getLineCode() {
54   - return lineCode;
55   - }
56   -
57   - public void setLineCode(String lineCode) {
58   - this.lineCode = lineCode;
59   - }
60   -
61   - public int getUpDown() {
62   - return upDown;
63   - }
64   -
65   - public void setUpDown(int upDown) {
66   - this.upDown = upDown;
67   - }
68   -
69   - public String getCoords() {
70   - return coords;
71   - }
72   -
73   - public void setCoords(String coords) {
74   - this.coords = coords;
75   - }
76   -
77   - public Integer getOrder() {
78   - return order;
79   - }
80   -
81   - public void setOrder(Integer order) {
82   - this.order = order;
83   - }
84   -
85   - public Polygon getPolygon() {
86   - return polygon;
87   - }
88   -
89   - public void setPolygon(Polygon polygon) {
90   - this.polygon = polygon;
91   - }
92   -}
  1 +package com.bsth.data.gpsdata_v2.entity;
  2 +
  3 +import com.bsth.util.Geo.Polygon;
  4 +
  5 +/**
  6 + * 前置围栏 -地理坐标
  7 + * Created by panzhao on 2017/9/23.
  8 + */
  9 +public class PreconditionGeo {
  10 +
  11 + private String name;
  12 +
  13 + /**
  14 + * 前置约束的站点编码
  15 + */
  16 + private String stationCode;
  17 +
  18 + /**
  19 + * 线路编码
  20 + */
  21 + private String lineCode;
  22 +
  23 + /**
  24 + * 上下行
  25 + */
  26 + private int upDown;
  27 +
  28 + /**
  29 + * 多边形坐标
  30 + */
  31 + private String coords;
  32 +
  33 + private com.bsth.util.Geo.Polygon polygon;
  34 +
  35 + private Integer order;
  36 +
  37 + public String getName() {
  38 + return name;
  39 + }
  40 +
  41 + public void setName(String name) {
  42 + this.name = name;
  43 + }
  44 +
  45 + public String getStationCode() {
  46 + return stationCode;
  47 + }
  48 +
  49 + public void setStationCode(String stationCode) {
  50 + this.stationCode = stationCode;
  51 + }
  52 +
  53 + public String getLineCode() {
  54 + return lineCode;
  55 + }
  56 +
  57 + public void setLineCode(String lineCode) {
  58 + this.lineCode = lineCode;
  59 + }
  60 +
  61 + public int getUpDown() {
  62 + return upDown;
  63 + }
  64 +
  65 + public void setUpDown(int upDown) {
  66 + this.upDown = upDown;
  67 + }
  68 +
  69 + public String getCoords() {
  70 + return coords;
  71 + }
  72 +
  73 + public void setCoords(String coords) {
  74 + this.coords = coords;
  75 + }
  76 +
  77 + public Integer getOrder() {
  78 + return order;
  79 + }
  80 +
  81 + public void setOrder(Integer order) {
  82 + this.order = order;
  83 + }
  84 +
  85 + public Polygon getPolygon() {
  86 + return polygon;
  87 + }
  88 +
  89 + public void setPolygon(Polygon polygon) {
  90 + this.polygon = polygon;
  91 + }
  92 +}
... ...