Commit c42749a8b19cdbc683c58181181594dd991c8dca
1 parent
28e47111
update...
Showing
75 changed files
with
3932 additions
and
5153 deletions
pom.xml
| ... | ... | @@ -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
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 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/entity/StationRoute.java renamed to src/main/java/com/bsth/data/gpsdata_v2/entity/StationRoute.java
| 1 | -package com.bsth.data.gpsdata.arrival.entity; | |
| 2 | - | |
| 3 | -import com.vividsolutions.jts.geom.Point; | |
| 4 | -import com.vividsolutions.jts.geom.Polygon; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * Created by panzhao on 2016/12/23. | |
| 8 | - */ | |
| 9 | -public class StationRoute { | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * 线路编码 | |
| 13 | - */ | |
| 14 | - private String lineCode; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 上下行 | |
| 18 | - */ | |
| 19 | - private int directions; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 站点编码 | |
| 23 | - */ | |
| 24 | - private String code; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 路由顺序 | |
| 28 | - */ | |
| 29 | - private int routeSort; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 站点位置 | |
| 33 | - */ | |
| 34 | - private Point point; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * 圆形半径 | |
| 38 | - */ | |
| 39 | - private Float radius; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 多边形电子围栏 | |
| 43 | - */ | |
| 44 | - private Polygon polygon; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * 站点标记 | |
| 48 | - */ | |
| 49 | - private String mark; | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * 下一站 | |
| 53 | - */ | |
| 54 | - private StationRoute next; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * 上一站 | |
| 58 | - */ | |
| 59 | - private StationRoute prve; | |
| 60 | - | |
| 61 | - private String name; | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 是否有前置进站约束 | |
| 65 | - */ | |
| 66 | - private boolean premise; | |
| 67 | - | |
| 68 | - public String getCode() { | |
| 69 | - return code; | |
| 70 | - } | |
| 71 | - | |
| 72 | - public void setCode(String code) { | |
| 73 | - this.code = code; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public int getRouteSort() { | |
| 77 | - return routeSort; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void setRouteSort(int routeSort) { | |
| 81 | - this.routeSort = routeSort; | |
| 82 | - } | |
| 83 | - | |
| 84 | - public Point getPoint() { | |
| 85 | - return point; | |
| 86 | - } | |
| 87 | - | |
| 88 | - public void setPoint(Point point) { | |
| 89 | - this.point = point; | |
| 90 | - } | |
| 91 | - | |
| 92 | - public Float getRadius() { | |
| 93 | - return radius; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public void setRadius(Float radius) { | |
| 97 | - this.radius = radius; | |
| 98 | - } | |
| 99 | - | |
| 100 | - public Polygon getPolygon() { | |
| 101 | - return polygon; | |
| 102 | - } | |
| 103 | - | |
| 104 | - public void setPolygon(Polygon polygon) { | |
| 105 | - this.polygon = polygon; | |
| 106 | - } | |
| 107 | - | |
| 108 | - public String getLineCode() { | |
| 109 | - return lineCode; | |
| 110 | - } | |
| 111 | - | |
| 112 | - public void setLineCode(String lineCode) { | |
| 113 | - this.lineCode = lineCode; | |
| 114 | - } | |
| 115 | - | |
| 116 | - public int getDirections() { | |
| 117 | - return directions; | |
| 118 | - } | |
| 119 | - | |
| 120 | - public void setDirections(int directions) { | |
| 121 | - this.directions = directions; | |
| 122 | - } | |
| 123 | - | |
| 124 | - public StationRoute getNext() { | |
| 125 | - return next; | |
| 126 | - } | |
| 127 | - | |
| 128 | - public void setNext(StationRoute next) { | |
| 129 | - this.next = next; | |
| 130 | - } | |
| 131 | - | |
| 132 | - public StationRoute getPrve() { | |
| 133 | - return prve; | |
| 134 | - } | |
| 135 | - | |
| 136 | - public void setPrve(StationRoute prve) { | |
| 137 | - this.prve = prve; | |
| 138 | - } | |
| 139 | - | |
| 140 | - public String getMark() { | |
| 141 | - return mark; | |
| 142 | - } | |
| 143 | - | |
| 144 | - public void setMark(String mark) { | |
| 145 | - this.mark = mark; | |
| 146 | - } | |
| 147 | - | |
| 148 | - public String getName() { | |
| 149 | - return name; | |
| 150 | - } | |
| 151 | - | |
| 152 | - public void setName(String name) { | |
| 153 | - this.name = name; | |
| 154 | - } | |
| 155 | - | |
| 156 | - public boolean isPremise() { | |
| 157 | - return premise; | |
| 158 | - } | |
| 159 | - | |
| 160 | - public void setPremise(boolean premise) { | |
| 161 | - this.premise = premise; | |
| 162 | - } | |
| 163 | -} | |
| 164 | - | |
| 1 | +package com.bsth.data.gpsdata_v2.entity; | |
| 2 | + | |
| 3 | +import com.bsth.util.Geo.Point; | |
| 4 | +import com.bsth.util.Geo.Polygon; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by panzhao on 2016/12/23. | |
| 8 | + */ | |
| 9 | +public class StationRoute { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * 线路编码 | |
| 13 | + */ | |
| 14 | + private String lineCode; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 上下行 | |
| 18 | + */ | |
| 19 | + private int directions; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 站点编码 | |
| 23 | + */ | |
| 24 | + private String code; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 路由顺序 | |
| 28 | + */ | |
| 29 | + private int routeSort; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 站点位置 | |
| 33 | + */ | |
| 34 | + private Point point; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 圆形半径 | |
| 38 | + */ | |
| 39 | + private Float radius; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 多边形电子围栏 | |
| 43 | + */ | |
| 44 | + private Polygon polygon; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 站点标记 | |
| 48 | + */ | |
| 49 | + private String mark; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 下一站 | |
| 53 | + */ | |
| 54 | + private StationRoute next; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 上一站 | |
| 58 | + */ | |
| 59 | + private StationRoute prve; | |
| 60 | + | |
| 61 | + private String name; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 是否有前置进站约束 | |
| 65 | + */ | |
| 66 | + private boolean premise; | |
| 67 | + | |
| 68 | + public String getCode() { | |
| 69 | + return code; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setCode(String code) { | |
| 73 | + this.code = code; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public int getRouteSort() { | |
| 77 | + return routeSort; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void setRouteSort(int routeSort) { | |
| 81 | + this.routeSort = routeSort; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public Point getPoint() { | |
| 85 | + return point; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void setPoint(Point point) { | |
| 89 | + this.point = point; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public Float getRadius() { | |
| 93 | + return radius; | |
| 94 | + } | |
| 95 | + | |
| 96 | + public void setRadius(Float radius) { | |
| 97 | + this.radius = radius; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public Polygon getPolygon() { | |
| 101 | + return polygon; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public void setPolygon(Polygon polygon) { | |
| 105 | + this.polygon = polygon; | |
| 106 | + } | |
| 107 | + | |
| 108 | + public String getLineCode() { | |
| 109 | + return lineCode; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public void setLineCode(String lineCode) { | |
| 113 | + this.lineCode = lineCode; | |
| 114 | + } | |
| 115 | + | |
| 116 | + public int getDirections() { | |
| 117 | + return directions; | |
| 118 | + } | |
| 119 | + | |
| 120 | + public void setDirections(int directions) { | |
| 121 | + this.directions = directions; | |
| 122 | + } | |
| 123 | + | |
| 124 | + public StationRoute getNext() { | |
| 125 | + return next; | |
| 126 | + } | |
| 127 | + | |
| 128 | + public void setNext(StationRoute next) { | |
| 129 | + this.next = next; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public StationRoute getPrve() { | |
| 133 | + return prve; | |
| 134 | + } | |
| 135 | + | |
| 136 | + public void setPrve(StationRoute prve) { | |
| 137 | + this.prve = prve; | |
| 138 | + } | |
| 139 | + | |
| 140 | + public String getMark() { | |
| 141 | + return mark; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public void setMark(String mark) { | |
| 145 | + this.mark = mark; | |
| 146 | + } | |
| 147 | + | |
| 148 | + public String getName() { | |
| 149 | + return name; | |
| 150 | + } | |
| 151 | + | |
| 152 | + public void setName(String name) { | |
| 153 | + this.name = name; | |
| 154 | + } | |
| 155 | + | |
| 156 | + public boolean isPremise() { | |
| 157 | + return premise; | |
| 158 | + } | |
| 159 | + | |
| 160 | + public void setPremise(boolean premise) { | |
| 161 | + this.premise = premise; | |
| 162 | + } | |
| 163 | +} | |
| 164 | + | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/entity/trail/GpsExecTrail.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.entity.trail; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * GPS 班次执行轨迹,过程数据 | |
| 9 | + * Created by panzhao on 2017/11/16. | |
| 10 | + */ | |
| 11 | +public class GpsExecTrail { | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 执行的班次ID | |
| 15 | + */ | |
| 16 | + private Long schId; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 实际经过的站点路由 | |
| 20 | + */ | |
| 21 | + private LinkedList<GpsEntity> srs = new LinkedList<>(); | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 车辆编码 | |
| 25 | + */ | |
| 26 | + private String nbbm; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 是否结束 | |
| 30 | + */ | |
| 31 | + private boolean end; | |
| 32 | + | |
| 33 | + public Long getSchId() { | |
| 34 | + return schId; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void setSchId(Long schId) { | |
| 38 | + this.schId = schId; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public LinkedList<GpsEntity> getSrs() { | |
| 42 | + return srs; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public void setSrs(LinkedList<GpsEntity> srs) { | |
| 46 | + this.srs = srs; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public String getNbbm() { | |
| 50 | + return nbbm; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public void setNbbm(String nbbm) { | |
| 54 | + this.nbbm = nbbm; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public boolean isEnd() { | |
| 58 | + return end; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public void setEnd(boolean end) { | |
| 62 | + this.end = end; | |
| 63 | + } | |
| 64 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/AbnormalStateHandle.java renamed to src/main/java/com/bsth/data/gpsdata_v2/handlers/AbnormalStateProcess.java
| 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 com.bsth.data.gpsdata.arrival.utils.GeoUtils; | |
| 8 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 9 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 10 | -import com.vividsolutions.jts.geom.LineString; | |
| 11 | -import com.vividsolutions.jts.geom.Point; | |
| 12 | -import org.springframework.stereotype.Component; | |
| 13 | - | |
| 14 | -import java.util.List; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * GPS异常状态判定 (越界/超速) | |
| 18 | - * Created by panzhao on 2017/1/10. | |
| 19 | - */ | |
| 20 | -@Component | |
| 21 | -public class AbnormalStateHandle extends SignalHandle{ | |
| 22 | - | |
| 23 | - //默认限速 | |
| 24 | - private static final double DEFAULT_SPEED_LIMIT = 60; | |
| 25 | - //越界阈值 | |
| 26 | - private static final double OUT_BOUNDS_THRESHOLD = 100; | |
| 27 | - | |
| 28 | - GeometryFactory geometryFactory = new GeometryFactory(); | |
| 29 | - | |
| 30 | - @Override | |
| 31 | - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 32 | - | |
| 33 | - if(isOffline(gps)) | |
| 34 | - return false; | |
| 35 | - | |
| 36 | - if(overspeed(gps)) | |
| 37 | - return true; | |
| 38 | - | |
| 39 | - if(outOfBounds((gps))) | |
| 40 | - return true; | |
| 41 | - | |
| 42 | - return false; | |
| 43 | - } | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * 是否超速 | |
| 47 | - * @param gps | |
| 48 | - * @return | |
| 49 | - */ | |
| 50 | - public boolean overspeed(GpsEntity gps){ | |
| 51 | - double maxSpeed = DEFAULT_SPEED_LIMIT; | |
| 52 | - if(GeoCacheData.speedLimit(gps.getLineId()) != null) | |
| 53 | - maxSpeed = GeoCacheData.speedLimit(gps.getLineId()); | |
| 54 | - | |
| 55 | - if(gps.getSpeed() > maxSpeed){ | |
| 56 | - gps.setAbnormalStatus("overspeed"); | |
| 57 | - return true; | |
| 58 | - } | |
| 59 | - return false; | |
| 60 | - } | |
| 61 | - | |
| 62 | - /** | |
| 63 | - * 是否越界 | |
| 64 | - * @param gps | |
| 65 | - * @return | |
| 66 | - */ | |
| 67 | - public boolean outOfBounds(GpsEntity gps){ | |
| 68 | - //只处理电子围栏外的车 | |
| 69 | - if(gps.getInstation() != 0){ | |
| 70 | - return false; | |
| 71 | - } | |
| 72 | - | |
| 73 | - List<LineString> list = GeoCacheData.getLineStringList(gps); | |
| 74 | - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 75 | - | |
| 76 | - double min = -1, distance; | |
| 77 | - | |
| 78 | - for(LineString lineString : list){ | |
| 79 | - distance = GeoUtils.getDistanceFromLine(lineString, point); | |
| 80 | - | |
| 81 | - if(min == -1 || min > distance) | |
| 82 | - min = distance; | |
| 83 | - } | |
| 84 | - | |
| 85 | - gps.setOutOfBoundDistance(min); | |
| 86 | - if(min > OUT_BOUNDS_THRESHOLD){ | |
| 87 | - gps.setAbnormalStatus("outBounds"); | |
| 88 | - return true; | |
| 89 | - } | |
| 90 | - return false; | |
| 91 | - } | |
| 92 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.CtLineString; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 7 | +import com.bsth.util.Geo.Point; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 越界/超速 判断 | |
| 14 | + * Created by panzhao on 2017/11/16. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class AbnormalStateProcess { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 默认限速 | |
| 21 | + */ | |
| 22 | + private static final double DEFAULT_SPEED_LIMIT = 60; | |
| 23 | + /** | |
| 24 | + * 越界阈值 | |
| 25 | + */ | |
| 26 | + private static final double OUT_BOUNDS_THRESHOLD = 100; | |
| 27 | + | |
| 28 | + | |
| 29 | + public void process(GpsEntity gps) { | |
| 30 | + if(isOffline(gps)) | |
| 31 | + return; | |
| 32 | + | |
| 33 | + if(overspeed(gps)) | |
| 34 | + return; | |
| 35 | + | |
| 36 | + if(outOfBounds((gps))) | |
| 37 | + return; | |
| 38 | + } | |
| 39 | + | |
| 40 | + private boolean isOffline(GpsEntity gps){ | |
| 41 | + return gps.getAbnormalStatus() != null && gps.getAbnormalStatus().equals("offline"); | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 是否超速 | |
| 47 | + * @param gps | |
| 48 | + * @return | |
| 49 | + */ | |
| 50 | + private boolean overspeed(GpsEntity gps){ | |
| 51 | + double maxSpeed = DEFAULT_SPEED_LIMIT; | |
| 52 | + if(GeoCacheData.speedLimit(gps.getLineId()) != null) | |
| 53 | + maxSpeed = GeoCacheData.speedLimit(gps.getLineId()); | |
| 54 | + | |
| 55 | + if(gps.getSpeed() > maxSpeed){ | |
| 56 | + gps.setAbnormalStatus("overspeed"); | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | + return false; | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 是否越界 | |
| 65 | + * @param gps | |
| 66 | + * @return | |
| 67 | + */ | |
| 68 | + public boolean outOfBounds(GpsEntity gps){ | |
| 69 | + //只处理场站外的车 | |
| 70 | + if(gps.getInstation() != 0){ | |
| 71 | + return false; | |
| 72 | + } | |
| 73 | + | |
| 74 | + List<CtLineString> list = GeoCacheData.getLineStringList(gps); | |
| 75 | + Point point = new Point(gps.getLon(), gps.getLat()); | |
| 76 | + | |
| 77 | + double min = -1, distance; | |
| 78 | + | |
| 79 | + for(CtLineString lineString : list){ | |
| 80 | + distance = GeoUtils.getDistanceFromLine(lineString.getS(),lineString.getE(), point); | |
| 81 | + | |
| 82 | + if(min == -1 || min > distance) | |
| 83 | + min = distance; | |
| 84 | + } | |
| 85 | + | |
| 86 | + gps.setOutOfBoundDistance(min); | |
| 87 | + if(min > OUT_BOUNDS_THRESHOLD){ | |
| 88 | + gps.setAbnormalStatus("outBounds"); | |
| 89 | + return true; | |
| 90 | + } | |
| 91 | + return false; | |
| 92 | + } | |
| 93 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/GpsStateProcess.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 5 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 6 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * GPS 状态处理 | |
| 12 | + * Created by panzhao on 2017/11/15. | |
| 13 | + */ | |
| 14 | +@Component | |
| 15 | +public class GpsStateProcess { | |
| 16 | + | |
| 17 | + @Autowired | |
| 18 | + DayOfSchedule dayOfSchedule; | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + GpsStatusManager gpsStatusManager; | |
| 22 | + | |
| 23 | + public void process(GpsEntity gps){ | |
| 24 | + //在执行的任务 | |
| 25 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 26 | + | |
| 27 | + if(null == sch) | |
| 28 | + return; | |
| 29 | + | |
| 30 | + byte upDown = Byte.parseByte(sch.getXlDir()); | |
| 31 | + | |
| 32 | + if(gps.getUpDown() != upDown){ | |
| 33 | + gps.setUpDown(upDown);//修正走向 | |
| 34 | + } | |
| 35 | + | |
| 36 | + if((!gps.isService() || gps.getUpDown() != upDown) && | |
| 37 | + !dayOfSchedule.emptyService(sch)){ | |
| 38 | + //下发指令纠正车载的 营运状态 和 走向 | |
| 39 | + gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, 0, "同步@系统"); | |
| 40 | + } | |
| 41 | + | |
| 42 | + if(!sch.getXlBm().equals(gps.getLineId())){ | |
| 43 | + //切换车载的 线路编码 | |
| 44 | + gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统"); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/InStationProcess.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.LineConfigData; | |
| 4 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 5 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 7 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 8 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 9 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 10 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 11 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 12 | +import com.bsth.data.schedule.late_adjust.LateAdjustHandle; | |
| 13 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 14 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 15 | +import com.bsth.websocket.handler.SendUtils; | |
| 16 | +import org.apache.commons.lang3.StringUtils; | |
| 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.util.List; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 车辆到站处理程序 | |
| 26 | + * Created by panzhao on 2017/11/16. | |
| 27 | + */ | |
| 28 | +@Component | |
| 29 | +public class InStationProcess { | |
| 30 | + | |
| 31 | + @Autowired | |
| 32 | + DayOfSchedule dayOfSchedule; | |
| 33 | + | |
| 34 | + @Autowired | |
| 35 | + LineConfigData lineConfigData; | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + SendUtils sendUtils; | |
| 39 | + | |
| 40 | + @Autowired | |
| 41 | + GpsStatusManager gpsStatusManager; | |
| 42 | + | |
| 43 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 44 | + | |
| 45 | + public void process(GpsEntity gps){ | |
| 46 | + GpsEntity prev = GpsCacheData.getPrev(gps); | |
| 47 | + | |
| 48 | + if(isInsideStation(gps) && | |
| 49 | + (prev == null || !isInsideStation(prev) || !prev.getStopNo().equals(gps.getStopNo()))){ | |
| 50 | + inStation(gps, prev); //进站 | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + private boolean isInsideStation(GpsEntity gps){ | |
| 55 | + return gps.getInstation() >= 1; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 进站 | |
| 60 | + * @param gps | |
| 61 | + * @param prev | |
| 62 | + */ | |
| 63 | + private void inStation(GpsEntity gps, GpsEntity prev){ | |
| 64 | + //要经过一个中途站才能进 | |
| 65 | + StationRoute s = GpsCacheData.prevStation(gps); | |
| 66 | + List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | |
| 67 | + if(routes.size() > 3 && null != s && s.getName().equals(gps.getStation().getName())){ | |
| 68 | + logger.info("没有进中途站,拒绝进场... -" + gps.getNbbm() + " -time:" + gps.getTimestamp()); | |
| 69 | + return; | |
| 70 | + } | |
| 71 | + | |
| 72 | + | |
| 73 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 74 | + boolean isEnd=false; | |
| 75 | + | |
| 76 | + //进终点 | |
| 77 | + if(null != sch && sch.getZdzCode().equals(gps.getStopNo())){ | |
| 78 | + inEndStation(sch, gps); | |
| 79 | + isEnd = true; | |
| 80 | + } | |
| 81 | + | |
| 82 | + GpsCacheData.in(gps, isEnd); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * 进班次终点 | |
| 87 | + * @param gps | |
| 88 | + */ | |
| 89 | + private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) { | |
| 90 | + String nbbm = sch.getClZbh(); | |
| 91 | + //校验进站前置约束 | |
| 92 | + if(!validInPremise(gps)) | |
| 93 | + return; | |
| 94 | + | |
| 95 | + //实达时间不覆盖 | |
| 96 | + if(StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 97 | + return; | |
| 98 | + | |
| 99 | + //应用到离站缓冲区设置参数 | |
| 100 | + long rsT = lineConfigData.applyIn(sch, gps.getTimestamp()); | |
| 101 | + | |
| 102 | + sch.setZdsjActualAll(rsT); | |
| 103 | + sch.setSiginCompate(2); | |
| 104 | + //通知误点停靠程序,有车辆到站 | |
| 105 | + LateAdjustHandle.carArrive(gps); | |
| 106 | + | |
| 107 | + //持久化 | |
| 108 | + dayOfSchedule.save(sch); | |
| 109 | + | |
| 110 | + //车辆的下一个班次 | |
| 111 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 112 | + if(next != null){ | |
| 113 | + dayOfSchedule.addExecPlan(next); | |
| 114 | + inStationAndInPark(sch, next);//进站既进场 | |
| 115 | + } | |
| 116 | + | |
| 117 | + //路牌的下一个班次,页面显示起点实际到达时间 | |
| 118 | + ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch); | |
| 119 | + if(lpNext != null){ | |
| 120 | + lpNext.setQdzArrDatesj(sch.getZdsjActual()); | |
| 121 | + } | |
| 122 | + | |
| 123 | + //已完成班次数 | |
| 124 | + int doneSum = dayOfSchedule.doneSum(nbbm); | |
| 125 | + //webSocket | |
| 126 | + sendUtils.sendZdsj(sch, lpNext, doneSum); | |
| 127 | + | |
| 128 | + logger.info("车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual()); | |
| 129 | + | |
| 130 | + //清除车辆误点调整监听 | |
| 131 | + LateAdjustHandle.remove(nbbm); | |
| 132 | + | |
| 133 | + //将gps转换成下一个班次走向的站内信号(应对只有一个站内信号 即 发出时) | |
| 134 | + transformUpDown(gps, next); | |
| 135 | + | |
| 136 | + //下发调度指令 | |
| 137 | + DirectivePushQueue.put6002(next, doneSum, "到站@系统"); | |
| 138 | + | |
| 139 | + //套跑 -下发线路切换指令 | |
| 140 | + if(null != next && !next.getXlBm().equals(sch.getXlBm())){ | |
| 141 | + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统"); | |
| 142 | + } | |
| 143 | + | |
| 144 | + if(null == next && gps.isService()) | |
| 145 | + nonService(sch, "结束@系统");//班次结束 | |
| 146 | + else if(dayOfSchedule.emptyService(next)) | |
| 147 | + nonService(sch, "空驶@系统");//下一班非营运 | |
| 148 | + } | |
| 149 | + | |
| 150 | + /** | |
| 151 | + * 校验进站前置约束 | |
| 152 | + * @param gps | |
| 153 | + * @return | |
| 154 | + */ | |
| 155 | + private boolean validInPremise(GpsEntity gps) { | |
| 156 | + StationRoute sr = gps.getStation(); | |
| 157 | + if(null == sr || !sr.isPremise()) | |
| 158 | + return true; | |
| 159 | + | |
| 160 | + String premiseCode = gps.getPremiseCode(); | |
| 161 | + | |
| 162 | + if(StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())){ | |
| 163 | + logger.info("满足前置进站约束 " + premiseCode); | |
| 164 | + return true; | |
| 165 | + } | |
| 166 | + else{ | |
| 167 | + logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode); | |
| 168 | + } | |
| 169 | + return false; | |
| 170 | + } | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * 进站既进场 | |
| 174 | + * @param sch | |
| 175 | + */ | |
| 176 | + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next){ | |
| 177 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 178 | + //限定出站既出场的停车场 | |
| 179 | + String park = config.getTwinsPark(); | |
| 180 | + boolean limitPark = StringUtils.isNotEmpty(park); | |
| 181 | + | |
| 182 | + | |
| 183 | + if (next.getBcType().equals("in") && config.getOutConfig() == 2 && isEmptyMileage(next) | |
| 184 | + && (!limitPark || park.equals(next.getZdzCode()))) { | |
| 185 | + | |
| 186 | + endSch(next, sch.getZdsjActualTime()); | |
| 187 | + | |
| 188 | + sendUtils.refreshSch(next); | |
| 189 | + dayOfSchedule.save(next); | |
| 190 | + | |
| 191 | + //分班的时候,需要再跳过1个班次 | |
| 192 | + next = dayOfSchedule.next(next); | |
| 193 | + if(next != null) | |
| 194 | + dayOfSchedule.addExecPlan(next); | |
| 195 | + | |
| 196 | + //进场,切换成非营运状态 | |
| 197 | + nonService(sch, "进场@系统"); | |
| 198 | + } | |
| 199 | + } | |
| 200 | + | |
| 201 | + | |
| 202 | + private boolean isEmptyMileage(ScheduleRealInfo sch){ | |
| 203 | + return sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0; | |
| 204 | + } | |
| 205 | + | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * 切换为非营运状态 | |
| 209 | + * @param sch | |
| 210 | + * @param sender | |
| 211 | + */ | |
| 212 | + private void nonService(ScheduleRealInfo sch, String sender){ | |
| 213 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender); | |
| 214 | + } | |
| 215 | + | |
| 216 | + private void endSch(ScheduleRealInfo sch, Long t){ | |
| 217 | + sch.setFcsjActualAll(t); | |
| 218 | + sch.setZdsjActualAll(t); | |
| 219 | + } | |
| 220 | + | |
| 221 | + private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) { | |
| 222 | + if(null == sch) | |
| 223 | + return; | |
| 224 | + byte upDown = Byte.parseByte(sch.getXlDir()); | |
| 225 | + //gps 切换走向 | |
| 226 | + gps.setUpDown(upDown); | |
| 227 | + gps.setPremiseCode(null); | |
| 228 | + | |
| 229 | + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown); | |
| 230 | + StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 231 | + if (station != null) { | |
| 232 | + gps.setStopNo(station.getCode()); | |
| 233 | + } | |
| 234 | + } | |
| 235 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/OutStationProcess.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.LineConfigData; | |
| 4 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 7 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 8 | +import com.bsth.data.schedule.late_adjust.LateAdjustHandle; | |
| 9 | +import com.bsth.entity.realcontrol.LineConfig; | |
| 10 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 11 | +import com.bsth.websocket.handler.SendUtils; | |
| 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.stereotype.Component; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * 车辆出站处理程序 | |
| 20 | + * Created by panzhao on 2017/11/16. | |
| 21 | + */ | |
| 22 | +@Component | |
| 23 | +public class OutStationProcess { | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + DayOfSchedule dayOfSchedule; | |
| 27 | + | |
| 28 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + LineConfigData lineConfigData; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + SendUtils sendUtils; | |
| 35 | + | |
| 36 | + @Autowired | |
| 37 | + GpsStatusManager gpsStatusManager; | |
| 38 | + | |
| 39 | + public void process(GpsEntity gps){ | |
| 40 | + GpsEntity prev = GpsCacheData.getPrev(gps); | |
| 41 | + if(gps.getInstation()==0 && prev!=null && isInsideStation(prev)){ | |
| 42 | + outStation(gps); //出站 | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + private boolean isInsideStation(GpsEntity gps){ | |
| 47 | + return gps.getInstation() >= 1; | |
| 48 | + } | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 出站 | |
| 52 | + * @param gps | |
| 53 | + */ | |
| 54 | + private void outStation(GpsEntity gps) { | |
| 55 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 56 | + | |
| 57 | + //起点发车 | |
| 58 | + if (null != sch && sch.getQdzCode().equals(gps.getStopNo())){ | |
| 59 | + gps.setPremiseCode(null);//清除前置围栏标记 | |
| 60 | + | |
| 61 | + if(StringUtils.isNotEmpty(sch.getFcsjActual()) | |
| 62 | + && !outManyFit(gps, sch)){ | |
| 63 | + return;//班次已经实发 | |
| 64 | + } | |
| 65 | + | |
| 66 | + //应用到离站缓冲区设置参数 | |
| 67 | + long rsT = lineConfigData.applyOut(sch, gps.getTimestamp()); | |
| 68 | + //实发时间 | |
| 69 | + sch.setFcsjActualAll(rsT); | |
| 70 | + sch.setSiginCompate(1); | |
| 71 | + | |
| 72 | + //出站既出场 | |
| 73 | + outStationAndOutPark(sch); | |
| 74 | + | |
| 75 | + //webSocket | |
| 76 | + sendUtils.sendFcsj(sch); | |
| 77 | + | |
| 78 | + //持久化 | |
| 79 | + dayOfSchedule.save(sch); | |
| 80 | + | |
| 81 | + //清理应发未发标记 | |
| 82 | + LateAdjustHandle.remove(sch.getClZbh()); | |
| 83 | + | |
| 84 | + //发车的时候,同步一下状态 | |
| 85 | + if(!gps.isService() && !dayOfSchedule.emptyService(sch)) | |
| 86 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统"); | |
| 87 | + | |
| 88 | + logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | |
| 89 | + } | |
| 90 | + | |
| 91 | + GpsCacheData.out(gps); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * 是否是一个更合适的发车信号 | |
| 96 | + * @param gps | |
| 97 | + * @param sch | |
| 98 | + * @return | |
| 99 | + */ | |
| 100 | + private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) { | |
| 101 | + LineConfig conf = lineConfigData.get(sch.getXlBm()); | |
| 102 | + if(null != conf && conf.isLockFirstOutTime()) | |
| 103 | + return false; | |
| 104 | + | |
| 105 | + if(StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 106 | + return false; | |
| 107 | + | |
| 108 | + long t1 = sch.getFcsjActualTime(); | |
| 109 | + long t2 = gps.getTimestamp(); | |
| 110 | + long c = sch.getDfsjT(); | |
| 111 | + | |
| 112 | + int threshold = 1000 * 60 * 5; | |
| 113 | + if(Math.abs(t2 - c) < threshold && c - t1 > threshold){ | |
| 114 | + return true; | |
| 115 | + } | |
| 116 | + return false; | |
| 117 | + } | |
| 118 | + | |
| 119 | + private void outStationAndOutPark(ScheduleRealInfo sch){ | |
| 120 | + try{ | |
| 121 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 122 | + //限定出站既出场的停车场 | |
| 123 | + String park = config.getTwinsPark(); | |
| 124 | + boolean limitPark = StringUtils.isNotEmpty(park); | |
| 125 | + | |
| 126 | + if (config != null && config.getOutConfig() == 2) { | |
| 127 | + //出站既出场 | |
| 128 | + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | |
| 129 | + if (isOut(schPrev) && isEmptyMileage(schPrev) | |
| 130 | + && (!limitPark || park.equals(schPrev.getQdzCode()))) { | |
| 131 | + | |
| 132 | + endSch(schPrev, sch.getFcsjActualTime()); | |
| 133 | + | |
| 134 | + //起点实到 | |
| 135 | + sch.setQdzArrDatesj(schPrev.getZdsjActual()); | |
| 136 | + | |
| 137 | + sendUtils.refreshSch(schPrev); | |
| 138 | + dayOfSchedule.save(schPrev); | |
| 139 | + } | |
| 140 | + } | |
| 141 | + }catch (Exception e){ | |
| 142 | + logger.error("", e); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + private boolean isEmptyMileage(ScheduleRealInfo sch){ | |
| 147 | + return sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0; | |
| 148 | + } | |
| 149 | + | |
| 150 | + private boolean isOut(ScheduleRealInfo sch){ | |
| 151 | + return sch != null && sch.getBcType().equals("out"); | |
| 152 | + } | |
| 153 | + | |
| 154 | + private void endSch(ScheduleRealInfo sch, Long t){ | |
| 155 | + sch.setFcsjActualAll(t); | |
| 156 | + sch.setZdsjActualAll(t); | |
| 157 | + } | |
| 158 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/handlers/ReverseRouteProcess.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 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.entity.StationRoute; | |
| 6 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | +import org.springframework.stereotype.Component; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 反向路由处理(进站的时候处理) | |
| 15 | + * Created by panzhao on 2017/11/20. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class ReverseRouteProcess { | |
| 19 | + | |
| 20 | + private static final int REVER_THRESHOLD = 3; | |
| 21 | + | |
| 22 | + private static final long TIME_THRESHOLD = 1000 * 60 * 120; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DayOfSchedule dayOfSchedule; | |
| 26 | + | |
| 27 | + public void process(GpsEntity gps){ | |
| 28 | + if(reversRoute(gps)){ | |
| 29 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 30 | + if(isInOut(sch) || !sch.getXlBm().equals(gps.getLineId())) | |
| 31 | + return; | |
| 32 | + | |
| 33 | + //next | |
| 34 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 35 | + if(isInOut(next)) | |
| 36 | + return; | |
| 37 | + | |
| 38 | + //跳下一个班次 | |
| 39 | + if(Math.abs(next.getDfsjT() - gps.getTimestamp()) < TIME_THRESHOLD) | |
| 40 | + dayOfSchedule.addExecPlan(next); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + private boolean reversRoute(GpsEntity gps) { | |
| 45 | + if(gps.getInstation() != 1) | |
| 46 | + return false; | |
| 47 | + | |
| 48 | + int sortNo = gps.getStation().getRouteSort(); | |
| 49 | + StationRoute prev = GpsCacheData.prevStation(gps); | |
| 50 | + //和上一个站点是反向 | |
| 51 | + if(sortNo < prev.getRouteSort()){ | |
| 52 | + | |
| 53 | + //满足3个进站反向信号 | |
| 54 | + List<StationRoute> prevs = GpsCacheData.prevMultiStation(gps); | |
| 55 | + | |
| 56 | + int count = 0; | |
| 57 | + for(StationRoute s : prevs){ | |
| 58 | + if(sortNo < s.getRouteSort()) | |
| 59 | + count ++; | |
| 60 | + sortNo = s.getRouteSort(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + if(count >= REVER_THRESHOLD) | |
| 64 | + return true; | |
| 65 | + } | |
| 66 | + | |
| 67 | + return false; | |
| 68 | + } | |
| 69 | + | |
| 70 | + private boolean isInOut(ScheduleRealInfo sch){ | |
| 71 | + return sch.getBcType().equals("in") || sch.getBcType().equals("out"); | |
| 72 | + } | |
| 73 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/StationInsideHandle.java renamed to src/main/java/com/bsth/data/gpsdata_v2/handlers/StationInsideProcess.java
| 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.StationRoute; | |
| 7 | -import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 8 | -import com.bsth.data.gpsdata.arrival.utils.GeoUtils; | |
| 9 | -import org.slf4j.Logger; | |
| 10 | -import org.slf4j.LoggerFactory; | |
| 11 | -import org.springframework.stereotype.Component; | |
| 12 | - | |
| 13 | -import java.util.List; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 站内站外判定 | |
| 17 | - * Created by panzhao on 2016/12/27. | |
| 18 | - */ | |
| 19 | -@Component | |
| 20 | -public class StationInsideHandle extends SignalHandle { | |
| 21 | - | |
| 22 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 23 | - | |
| 24 | - @Override | |
| 25 | - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { | |
| 26 | - //是否在场内 | |
| 27 | - String parkCode = GeoUtils.gpsInCarpark(gps); | |
| 28 | - if (parkCode != null) { | |
| 29 | - gps.setInstation(2); | |
| 30 | - gps.setStopNo(parkCode); | |
| 31 | - gps.setCarparkNo(parkCode); | |
| 32 | - } | |
| 33 | - | |
| 34 | - //是否在站内 | |
| 35 | - List<StationRoute> srs = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | |
| 36 | - StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 37 | - if (station != null) { | |
| 38 | - gps.setInstation(1); | |
| 39 | - gps.setStopNo(station.getCode()); | |
| 40 | - gps.setStation(station); | |
| 41 | - } | |
| 42 | - | |
| 43 | - //是否在进站前置围栏内 | |
| 44 | - String premiseCode = GeoUtils.gpsInPremiseGeo(gps); | |
| 45 | - gps.setPremiseCode(premiseCode); | |
| 46 | - | |
| 47 | - if(isNotEmpty(prevs)){ | |
| 48 | - try { | |
| 49 | - GpsEntity prev = prevs.getTail(); | |
| 50 | - //继承前置围栏 | |
| 51 | - if(null == premiseCode && null != prev.getPremiseCode()) | |
| 52 | - gps.setPremiseCode(prev.getPremiseCode()); | |
| 53 | - | |
| 54 | - //在场,站外 | |
| 55 | - if(gps.getInstation() == 0){ | |
| 56 | - //继承上一个点的站点编码 | |
| 57 | - gps.setStopNo(prev.getStopNo()); | |
| 58 | - | |
| 59 | - /*if(null == premiseCode && null != prev.getPremiseCode()) | |
| 60 | - gps.setPremiseCode(prev.getPremiseCode());*/ | |
| 61 | - } | |
| 62 | - /*else if(null != gps.getPremiseCode() && !gps.getStopNo().equals(gps.getPremiseCode())){ | |
| 63 | - gps.setPremiseCode(null); | |
| 64 | - }*/ | |
| 65 | - }catch (Exception e){ | |
| 66 | - logger.error("", e); | |
| 67 | - } | |
| 68 | - } | |
| 69 | - | |
| 70 | -/* | |
| 71 | - //在场,站外 | |
| 72 | - if(gps.getInstation() == 0 && isNotEmpty(prevs)){ | |
| 73 | - //继承上一个点的站点编码 | |
| 74 | - GpsEntity prev = prevs.getTail(); | |
| 75 | - gps.setStopNo(prev.getStopNo()); | |
| 76 | - } | |
| 77 | -*/ | |
| 78 | - return true; | |
| 79 | - } | |
| 80 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.handlers; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 7 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 站内 场内判定 | |
| 14 | + * Created by panzhao on 2017/11/16. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class StationInsideProcess { | |
| 18 | + | |
| 19 | + public void process(GpsEntity gps){ | |
| 20 | + //是否在场内 | |
| 21 | + String parkCode = GeoUtils.gpsInCarpark(gps); | |
| 22 | + | |
| 23 | + if (parkCode != null) { | |
| 24 | + gps.setInstation(2); | |
| 25 | + gps.setStopNo(parkCode); | |
| 26 | + gps.setCarparkNo(parkCode); | |
| 27 | + } | |
| 28 | + | |
| 29 | + //是否在站内 | |
| 30 | + List<StationRoute> srs = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | |
| 31 | + StationRoute station = GeoUtils.gpsInStation(gps, srs); | |
| 32 | + if (station != null) { | |
| 33 | + gps.setInstation(1); | |
| 34 | + gps.setStopNo(station.getCode()); | |
| 35 | + gps.setStation(station); | |
| 36 | + } | |
| 37 | + | |
| 38 | + //是否在进站前置围栏内 | |
| 39 | + String premiseCode = GeoUtils.gpsInPremiseGeo(gps); | |
| 40 | + gps.setPremiseCode(premiseCode); | |
| 41 | + | |
| 42 | + //上一个点位 | |
| 43 | + GpsEntity prev = GpsCacheData.getPrev(gps); | |
| 44 | + | |
| 45 | + if(null != prev){ | |
| 46 | + //继承前置围栏状态 | |
| 47 | + if(null == premiseCode && null != prev.getPremiseCode()) | |
| 48 | + gps.setPremiseCode(prev.getPremiseCode()); | |
| 49 | + | |
| 50 | + //在场,站外 | |
| 51 | + if(gps.getInstation() == 0){ | |
| 52 | + gps.setStopNo(prev.getStopNo());//继承上一个点的站点编码 | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/load/GatewayHttpLoader.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.load; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.bsth.data.BasicData; | |
| 5 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 7 | +import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; | |
| 8 | +import com.bsth.util.ConfigUtil; | |
| 9 | +import org.apache.commons.lang3.StringUtils; | |
| 10 | +import org.apache.http.HttpEntity; | |
| 11 | +import org.apache.http.client.config.RequestConfig; | |
| 12 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 13 | +import org.apache.http.client.methods.HttpGet; | |
| 14 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 15 | +import org.apache.http.impl.client.HttpClients; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | +import org.springframework.beans.BeansException; | |
| 19 | +import org.springframework.context.ApplicationContext; | |
| 20 | +import org.springframework.context.ApplicationContextAware; | |
| 21 | +import org.springframework.stereotype.Component; | |
| 22 | + | |
| 23 | +import java.io.BufferedReader; | |
| 24 | +import java.io.InputStreamReader; | |
| 25 | +import java.util.ArrayList; | |
| 26 | +import java.util.List; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * 从网关http 接口加载数据 | |
| 30 | + * Created by panzhao on 2017/11/15. | |
| 31 | + */ | |
| 32 | +@Component | |
| 33 | +public class GatewayHttpLoader implements ApplicationContextAware{ | |
| 34 | + | |
| 35 | + static Logger logger = LoggerFactory.getLogger(GatewayHttpLoader.class); | |
| 36 | + | |
| 37 | + static String url; | |
| 38 | + static List<GpsEntity> list; | |
| 39 | + static CloseableHttpClient httpClient = null; | |
| 40 | + static HttpGet get; | |
| 41 | + static RequestConfig requestConfig; | |
| 42 | + static CloseableHttpResponse response; | |
| 43 | + static HttpEntity entity; | |
| 44 | + static BufferedReader br; | |
| 45 | + | |
| 46 | + static GpsRealData gpsRealData; | |
| 47 | + | |
| 48 | + static{ | |
| 49 | + url = ConfigUtil.get("http.gps.real.url"); | |
| 50 | + list = new ArrayList<>(); | |
| 51 | + httpClient = HttpClients.createDefault(); | |
| 52 | + get = new HttpGet(url); | |
| 53 | + requestConfig = RequestConfig.custom() | |
| 54 | + .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 55 | + .setSocketTimeout(1500).build(); | |
| 56 | + get.setConfig(requestConfig); | |
| 57 | + } | |
| 58 | + | |
| 59 | + public static List<GpsEntity> load(){ | |
| 60 | + try{ | |
| 61 | + if(list.size() > 0) | |
| 62 | + list.clear(); | |
| 63 | + | |
| 64 | + response = httpClient.execute(get); | |
| 65 | + entity = response.getEntity(); | |
| 66 | + | |
| 67 | + if(null == entity) | |
| 68 | + return list; | |
| 69 | + | |
| 70 | + br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 71 | + | |
| 72 | + StringBuilder sb = new StringBuilder(); | |
| 73 | + String str; | |
| 74 | + while ((str = br.readLine()) != null) | |
| 75 | + sb.append(str); | |
| 76 | + | |
| 77 | + list = JSON.parseArray(JSON.parseObject(sb.toString()).getString("data"), GpsEntity.class); | |
| 78 | + //过滤掉无效的点位 | |
| 79 | + list = GpsDataUtils.clearInvalid(list); | |
| 80 | + | |
| 81 | + List<GpsEntity> ups = new ArrayList<>(); | |
| 82 | + String nbbm; | |
| 83 | + for (GpsEntity gps : list) { | |
| 84 | + if (StringUtils.isBlank(gps.getDeviceId())) | |
| 85 | + continue; | |
| 86 | + | |
| 87 | + if (gps_equals(gpsRealData.get(gps.getDeviceId()), gps)) | |
| 88 | + continue; | |
| 89 | + | |
| 90 | + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId()); | |
| 91 | + gps.setNbbm(nbbm); | |
| 92 | + ups.add(gps); | |
| 93 | + } | |
| 94 | + list = ups; | |
| 95 | + | |
| 96 | + if (null != response) | |
| 97 | + response.close(); | |
| 98 | + }catch (Exception e){ | |
| 99 | + logger.error("", e); | |
| 100 | + } | |
| 101 | + return list; | |
| 102 | + } | |
| 103 | + | |
| 104 | + | |
| 105 | + private static boolean gps_equals(GpsEntity old, GpsEntity gps){ | |
| 106 | + if(old != null && | |
| 107 | + old.getTimestamp().equals(gps.getTimestamp()) && | |
| 108 | + old.getLat().equals(gps.getLat()) && | |
| 109 | + old.getLon().equals(gps.getLon())) | |
| 110 | + return true; | |
| 111 | + return false; | |
| 112 | + } | |
| 113 | + | |
| 114 | + @Override | |
| 115 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 116 | + gpsRealData = applicationContext.getBean(GpsRealData.class); | |
| 117 | + } | |
| 118 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/load/SocketClientLoader.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.load; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.bsth.data.BasicData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; | |
| 7 | +import com.bsth.util.ConfigUtil; | |
| 8 | +import org.apache.http.HttpEntity; | |
| 9 | +import org.apache.http.client.config.RequestConfig; | |
| 10 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 11 | +import org.apache.http.client.methods.HttpGet; | |
| 12 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 13 | +import org.apache.http.impl.client.HttpClients; | |
| 14 | +import org.slf4j.Logger; | |
| 15 | +import org.slf4j.LoggerFactory; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +import java.io.BufferedReader; | |
| 19 | +import java.io.InputStreamReader; | |
| 20 | +import java.util.ArrayList; | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * 从专用的socket client 加载数据 | |
| 25 | + * Created by panzhao on 2017/11/15. | |
| 26 | + */ | |
| 27 | +@Component | |
| 28 | +public class SocketClientLoader { | |
| 29 | + | |
| 30 | + static Logger logger = LoggerFactory.getLogger(SocketClientLoader.class); | |
| 31 | + | |
| 32 | + static String url; | |
| 33 | + static List<GpsEntity> list; | |
| 34 | + static CloseableHttpClient httpClient = null; | |
| 35 | + static HttpGet get; | |
| 36 | + static RequestConfig requestConfig; | |
| 37 | + static CloseableHttpResponse response; | |
| 38 | + static HttpEntity entity; | |
| 39 | + static BufferedReader br; | |
| 40 | + | |
| 41 | + static { | |
| 42 | + url = ConfigUtil.get("http.gps.real.cache.url"); | |
| 43 | + list = new ArrayList<>(); | |
| 44 | + httpClient = HttpClients.createDefault(); | |
| 45 | + get = new HttpGet(url); | |
| 46 | + requestConfig = RequestConfig.custom() | |
| 47 | + .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | |
| 48 | + .setSocketTimeout(1500).build(); | |
| 49 | + get.setConfig(requestConfig); | |
| 50 | + } | |
| 51 | + | |
| 52 | + public static List<GpsEntity> load(){ | |
| 53 | + try { | |
| 54 | + if(list.size() > 0) | |
| 55 | + list.clear(); | |
| 56 | + logger.info("load start..."); | |
| 57 | + response = httpClient.execute(get); | |
| 58 | + entity = response.getEntity(); | |
| 59 | + if(null == entity) | |
| 60 | + return list; | |
| 61 | + | |
| 62 | + br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 63 | + StringBuilder sb = new StringBuilder(); | |
| 64 | + String str; | |
| 65 | + while ((str = br.readLine()) != null) | |
| 66 | + sb.append(str); | |
| 67 | + | |
| 68 | + list = JSON.parseArray(sb.toString(), GpsEntity.class); | |
| 69 | + | |
| 70 | + //过滤掉无效的点位 | |
| 71 | + list = GpsDataUtils.clearInvalid(list); | |
| 72 | + | |
| 73 | + logger.info("load end!"); | |
| 74 | + for (GpsEntity gps : list) { | |
| 75 | + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 76 | + } | |
| 77 | + | |
| 78 | + if (null != response) | |
| 79 | + response.close(); | |
| 80 | + } catch (Exception e) { | |
| 81 | + logger.error("", e); | |
| 82 | + } | |
| 83 | + | |
| 84 | + return list; | |
| 85 | + } | |
| 86 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/rfid/UploadRfidDataService.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.rfid; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation; | |
| 4 | +import com.bsth.data.gpsdata_v2.rfid.handle.RfidSignalHandle; | |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 6 | +import org.springframework.web.bind.annotation.RequestBody; | |
| 7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | +import org.springframework.web.bind.annotation.RestController; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * RFID 数据上传入口 | |
| 14 | + * Created by panzhao on 2017/11/22. | |
| 15 | + */ | |
| 16 | +@RestController | |
| 17 | +@RequestMapping("/up/rfid") | |
| 18 | +public class UploadRfidDataService { | |
| 19 | + | |
| 20 | + @Autowired | |
| 21 | + RfidSignalHandle rfidSignalHandle; | |
| 22 | + | |
| 23 | + @RequestMapping("inside") | |
| 24 | + public void inside(@RequestBody List<RfidInoutStation> list) { | |
| 25 | + rfidSignalHandle.handle(list); | |
| 26 | + } | |
| 27 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/rfid/entity/RfidInoutStation.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.rfid.entity; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * RFID 进出数据 | |
| 5 | + * Created by panzhao on 2017/11/22. | |
| 6 | + */ | |
| 7 | +public class RfidInoutStation { | |
| 8 | + | |
| 9 | + private String nbbm; | |
| 10 | + | |
| 11 | + private String station; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 0 进 | |
| 15 | + * 1 出 | |
| 16 | + */ | |
| 17 | + private int type; | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 信号时间 | |
| 21 | + */ | |
| 22 | + private long t; | |
| 23 | + | |
| 24 | + public String getNbbm() { | |
| 25 | + return nbbm; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public void setNbbm(String nbbm) { | |
| 29 | + this.nbbm = nbbm; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public String getStation() { | |
| 33 | + return station; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public void setStation(String station) { | |
| 37 | + this.station = station; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public int getType() { | |
| 41 | + return type; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public void setType(int type) { | |
| 45 | + this.type = type; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public long getT() { | |
| 49 | + return t; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public void setT(long t) { | |
| 53 | + this.t = t; | |
| 54 | + } | |
| 55 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/rfid/handle/RfidSignalHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.rfid.handle; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation; | |
| 4 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 7 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 8 | +import com.bsth.websocket.handler.SendUtils; | |
| 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.List; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * RFID信号处理 | |
| 19 | + * Created by panzhao on 2017/11/22. | |
| 20 | + */ | |
| 21 | +@Component | |
| 22 | +public class RfidSignalHandle { | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DayOfSchedule dayOfSchedule; | |
| 26 | + | |
| 27 | + @Autowired | |
| 28 | + SendUtils sendUtils; | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + GpsStatusManager gpsStatusManager; | |
| 32 | + | |
| 33 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 34 | + | |
| 35 | + public void handle(List<RfidInoutStation> list){ | |
| 36 | + for(RfidInoutStation signal : list){ | |
| 37 | + if(signal.getType()==0) | |
| 38 | + in(signal); | |
| 39 | + else if(signal.getType()==1) | |
| 40 | + out(signal); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 出 | |
| 46 | + * @param signal | |
| 47 | + */ | |
| 48 | + private void out(RfidInoutStation signal) { | |
| 49 | + try{ | |
| 50 | + String nbbm = signal.getNbbm(); | |
| 51 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm); | |
| 52 | + | |
| 53 | + if(null == sch) | |
| 54 | + return; | |
| 55 | + | |
| 56 | + if(sch.getQdzCode().equals(signal.getStation()) | |
| 57 | + && StringUtils.isEmpty(sch.getFcsjActual())){ | |
| 58 | + | |
| 59 | + //班次发车 | |
| 60 | + sch.setFcsjActualAll(signal.getT()); | |
| 61 | + | |
| 62 | + //webSocket | |
| 63 | + sendUtils.sendFcsj(sch); | |
| 64 | + | |
| 65 | + //持久化 | |
| 66 | + dayOfSchedule.save(sch); | |
| 67 | + | |
| 68 | + logger.info("RFID; 车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | |
| 69 | + } | |
| 70 | + }catch (Exception e){ | |
| 71 | + logger.error("", e); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 进 | |
| 77 | + * @param signal | |
| 78 | + */ | |
| 79 | + private void in(RfidInoutStation signal) { | |
| 80 | + try{ | |
| 81 | + String nbbm = signal.getNbbm(); | |
| 82 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm); | |
| 83 | + | |
| 84 | + if(sch.getZdzCode().equals(signal.getStation()) | |
| 85 | + && StringUtils.isEmpty(sch.getZdsjActual())){ | |
| 86 | + | |
| 87 | + sch.setZdsjActualAll(signal.getT()); | |
| 88 | + | |
| 89 | + | |
| 90 | + //持久化 | |
| 91 | + dayOfSchedule.save(sch); | |
| 92 | + | |
| 93 | + //车辆的下一个班次 | |
| 94 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | |
| 95 | + if(next != null){ | |
| 96 | + dayOfSchedule.addExecPlan(next); | |
| 97 | + //inStationAndInPark(sch, next);//进站既进场 | |
| 98 | + } | |
| 99 | + | |
| 100 | + //路牌的下一个班次,页面显示起点实际到达时间 | |
| 101 | + ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch); | |
| 102 | + if(lpNext != null){ | |
| 103 | + lpNext.setQdzArrDatesj(sch.getZdsjActual()); | |
| 104 | + } | |
| 105 | + | |
| 106 | + //已完成班次数 | |
| 107 | + int doneSum = dayOfSchedule.doneSum(nbbm); | |
| 108 | + | |
| 109 | + //webSocket | |
| 110 | + sendUtils.sendZdsj(sch, lpNext, doneSum); | |
| 111 | + | |
| 112 | + logger.info("RFID; 车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual()); | |
| 113 | + | |
| 114 | + //下发调度指令 | |
| 115 | + DirectivePushQueue.put6002(next, doneSum, "rfid@系统"); | |
| 116 | + | |
| 117 | + //套跑 -下发线路切换指令 | |
| 118 | + if(null != next && !next.getXlBm().equals(sch.getXlBm())){ | |
| 119 | + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "rfid@系统"); | |
| 120 | + } | |
| 121 | + | |
| 122 | + if(null == next) | |
| 123 | + nonService(sch, "rfid1@系统");//班次结束 | |
| 124 | + else if(dayOfSchedule.emptyService(next)) | |
| 125 | + nonService(sch, "rfid2@系统");//下一班非营运 | |
| 126 | + } | |
| 127 | + }catch (Exception e){ | |
| 128 | + logger.error("", e); | |
| 129 | + } | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * 将车载设备切换为非营运状态 | |
| 134 | + * @param sch | |
| 135 | + * @param sender | |
| 136 | + */ | |
| 137 | + private void nonService(ScheduleRealInfo sch, String sender){ | |
| 138 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender); | |
| 139 | + } | |
| 140 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/GpsStatusManager.java renamed to src/main/java/com/bsth/data/gpsdata_v2/status_manager/GpsStatusManager.java
| 1 | -package com.bsth.data.gpsdata.status_manager; | |
| 2 | - | |
| 3 | -import com.bsth.Application; | |
| 4 | -import com.bsth.data.gpsdata.status_manager.gps_line_state.LineStateHandle; | |
| 5 | -import com.bsth.data.gpsdata.status_manager.gps_service_state.ServiceStateHandle; | |
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | -import org.springframework.boot.CommandLineRunner; | |
| 8 | -import org.springframework.stereotype.Component; | |
| 9 | - | |
| 10 | -import java.util.concurrent.TimeUnit; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * GPS 状态管理 | |
| 14 | - * Created by panzhao on 2017/7/13. | |
| 15 | - */ | |
| 16 | -@Component | |
| 17 | -public class GpsStatusManager implements CommandLineRunner { | |
| 18 | - | |
| 19 | - @Autowired | |
| 20 | - StatusCheckThread checkThread; | |
| 21 | - | |
| 22 | - @Autowired | |
| 23 | - LineStateHandle lineStateHandle; | |
| 24 | - | |
| 25 | - @Autowired | |
| 26 | - ServiceStateHandle serviceStateHandle; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 切换线路 | |
| 30 | - * @param nbbm | |
| 31 | - * @param lineCode | |
| 32 | - * @param sender | |
| 33 | - */ | |
| 34 | - public void changeLine(String nbbm, String lineCode, String sender){ | |
| 35 | - lineStateHandle.changeLine(nbbm, lineCode, sender); | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * 切换营运状态 | |
| 40 | - * @param nbbm | |
| 41 | - * @param state 0 营运, 1:非营运 | |
| 42 | - * @param sender | |
| 43 | - */ | |
| 44 | - public void changeServiceState(String nbbm, String upDown,int state, String sender){ | |
| 45 | - changeServiceState(nbbm, Integer.parseInt(upDown), state, sender); | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * 切换营运状态 | |
| 50 | - * @param nbbm | |
| 51 | - * @param state 0 营运, 1:非营运 | |
| 52 | - * @param sender | |
| 53 | - */ | |
| 54 | - public void changeServiceState(String nbbm, int upDown,int state, String sender){ | |
| 55 | - serviceStateHandle.changeState(nbbm, upDown, state, sender); | |
| 56 | - } | |
| 57 | - | |
| 58 | - @Override | |
| 59 | - public void run(String... strings) throws Exception { | |
| 60 | - Application.mainServices.scheduleWithFixedDelay(checkThread, 120, 120, TimeUnit.SECONDS); | |
| 61 | - } | |
| 62 | - | |
| 63 | - @Component | |
| 64 | - public static class StatusCheckThread extends Thread{ | |
| 65 | - | |
| 66 | - @Autowired | |
| 67 | - LineStateHandle lineStateHandle; | |
| 68 | - | |
| 69 | - @Autowired | |
| 70 | - ServiceStateHandle serviceStateHandle; | |
| 71 | - | |
| 72 | - @Override | |
| 73 | - public void run() { | |
| 74 | - /** 检查线路切换结果 */ | |
| 75 | - lineStateHandle.checkResultAll(); | |
| 76 | - /** 检查营运状态切换结果 */ | |
| 77 | - serviceStateHandle.checkResultAll(); | |
| 78 | - } | |
| 79 | - } | |
| 80 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager; | |
| 2 | + | |
| 3 | +import com.bsth.Application; | |
| 4 | +import com.bsth.data.gpsdata_v2.status_manager.gps_line_state.LineStateHandle; | |
| 5 | +import com.bsth.data.gpsdata_v2.status_manager.gps_service_state.ServiceStateHandle; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.boot.CommandLineRunner; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.concurrent.TimeUnit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * GPS 状态管理 | |
| 14 | + * Created by panzhao on 2017/7/13. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class GpsStatusManager implements CommandLineRunner { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + StatusCheckThread checkThread; | |
| 21 | + | |
| 22 | + @Autowired | |
| 23 | + LineStateHandle lineStateHandle; | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + ServiceStateHandle serviceStateHandle; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 切换线路 | |
| 30 | + * @param nbbm | |
| 31 | + * @param lineCode | |
| 32 | + * @param sender | |
| 33 | + */ | |
| 34 | + public void changeLine(String nbbm, String lineCode, String sender){ | |
| 35 | + lineStateHandle.changeLine(nbbm, lineCode, sender); | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 切换营运状态 | |
| 40 | + * @param nbbm | |
| 41 | + * @param state 0 营运, 1:非营运 | |
| 42 | + * @param sender | |
| 43 | + */ | |
| 44 | + public void changeServiceState(String nbbm, String upDown,int state, String sender){ | |
| 45 | + changeServiceState(nbbm, Integer.parseInt(upDown), state, sender); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 切换营运状态 | |
| 50 | + * @param nbbm | |
| 51 | + * @param state 0 营运, 1:非营运 | |
| 52 | + * @param sender | |
| 53 | + */ | |
| 54 | + public void changeServiceState(String nbbm, int upDown,int state, String sender){ | |
| 55 | + serviceStateHandle.changeState(nbbm, upDown, state, sender); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void run(String... strings) throws Exception { | |
| 60 | + Application.mainServices.scheduleWithFixedDelay(checkThread, 120, 120, TimeUnit.SECONDS); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Component | |
| 64 | + public static class StatusCheckThread extends Thread{ | |
| 65 | + | |
| 66 | + @Autowired | |
| 67 | + LineStateHandle lineStateHandle; | |
| 68 | + | |
| 69 | + @Autowired | |
| 70 | + ServiceStateHandle serviceStateHandle; | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void run() { | |
| 74 | + /** 检查线路切换结果 */ | |
| 75 | + lineStateHandle.checkResultAll(); | |
| 76 | + /** 检查营运状态切换结果 */ | |
| 77 | + serviceStateHandle.checkResultAll(); | |
| 78 | + } | |
| 79 | + } | |
| 80 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_line_state/ChangeBean.java renamed to src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_line_state/ChangeBean.java
| 1 | -package com.bsth.data.gpsdata.status_manager.gps_line_state; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Created by panzhao on 2017/7/13. | |
| 5 | - */ | |
| 6 | -public class ChangeBean { | |
| 7 | - | |
| 8 | - /** | |
| 9 | - * 车辆自编号 | |
| 10 | - */ | |
| 11 | - private String nbbm; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 要切换到的线路 | |
| 15 | - */ | |
| 16 | - private String lineCode; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * 指令发送次数 | |
| 20 | - */ | |
| 21 | - private int sendCount; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 上次指令时间 | |
| 25 | - */ | |
| 26 | - private long st; | |
| 27 | - | |
| 28 | - /**发送人 */ | |
| 29 | - private String sender; | |
| 30 | - | |
| 31 | - public static ChangeBean getInstance(String nbbm, String lineCode, String sender){ | |
| 32 | - ChangeBean cb = new ChangeBean(); | |
| 33 | - cb.setNbbm(nbbm); | |
| 34 | - cb.setLineCode(lineCode); | |
| 35 | - cb.setSendCount(0); | |
| 36 | - cb.setSender(sender); | |
| 37 | - return cb; | |
| 38 | - } | |
| 39 | - | |
| 40 | - public void countPlus(){ | |
| 41 | - sendCount ++; | |
| 42 | - } | |
| 43 | - | |
| 44 | - public String getLineCode() { | |
| 45 | - return lineCode; | |
| 46 | - } | |
| 47 | - | |
| 48 | - public void setLineCode(String lineCode) { | |
| 49 | - this.lineCode = lineCode; | |
| 50 | - } | |
| 51 | - | |
| 52 | - public int getSendCount() { | |
| 53 | - return sendCount; | |
| 54 | - } | |
| 55 | - | |
| 56 | - public void setSendCount(int sendCount) { | |
| 57 | - this.sendCount = sendCount; | |
| 58 | - } | |
| 59 | - | |
| 60 | - public long getSt() { | |
| 61 | - return st; | |
| 62 | - } | |
| 63 | - | |
| 64 | - public void setSt(long st) { | |
| 65 | - this.st = st; | |
| 66 | - } | |
| 67 | - | |
| 68 | - public String getSender() { | |
| 69 | - return sender; | |
| 70 | - } | |
| 71 | - | |
| 72 | - public void setSender(String sender) { | |
| 73 | - this.sender = sender; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public String getNbbm() { | |
| 77 | - return nbbm; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void setNbbm(String nbbm) { | |
| 81 | - this.nbbm = nbbm; | |
| 82 | - } | |
| 83 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_line_state; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by panzhao on 2017/7/13. | |
| 5 | + */ | |
| 6 | +public class ChangeBean { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 车辆自编号 | |
| 10 | + */ | |
| 11 | + private String nbbm; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 要切换到的线路 | |
| 15 | + */ | |
| 16 | + private String lineCode; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 指令发送次数 | |
| 20 | + */ | |
| 21 | + private int sendCount; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 上次指令时间 | |
| 25 | + */ | |
| 26 | + private long st; | |
| 27 | + | |
| 28 | + /**发送人 */ | |
| 29 | + private String sender; | |
| 30 | + | |
| 31 | + public static ChangeBean getInstance(String nbbm, String lineCode, String sender){ | |
| 32 | + ChangeBean cb = new ChangeBean(); | |
| 33 | + cb.setNbbm(nbbm); | |
| 34 | + cb.setLineCode(lineCode); | |
| 35 | + cb.setSendCount(0); | |
| 36 | + cb.setSender(sender); | |
| 37 | + return cb; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public void countPlus(){ | |
| 41 | + sendCount ++; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public String getLineCode() { | |
| 45 | + return lineCode; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public void setLineCode(String lineCode) { | |
| 49 | + this.lineCode = lineCode; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public int getSendCount() { | |
| 53 | + return sendCount; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setSendCount(int sendCount) { | |
| 57 | + this.sendCount = sendCount; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public long getSt() { | |
| 61 | + return st; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void setSt(long st) { | |
| 65 | + this.st = st; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public String getSender() { | |
| 69 | + return sender; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setSender(String sender) { | |
| 73 | + this.sender = sender; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public String getNbbm() { | |
| 77 | + return nbbm; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void setNbbm(String nbbm) { | |
| 81 | + this.nbbm = nbbm; | |
| 82 | + } | |
| 83 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_line_state/LineStateHandle.java renamed to src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_line_state/LineStateHandle.java
| 1 | -package com.bsth.data.gpsdata.status_manager.gps_line_state; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata.GpsRealData; | |
| 5 | -import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | -import com.bsth.service.directive.DirectiveService; | |
| 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.Collection; | |
| 13 | -import java.util.concurrent.ConcurrentHashMap; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 设备线路状态处理 | |
| 17 | - * Created by panzhao on 2017/7/13. | |
| 18 | - */ | |
| 19 | -@Component | |
| 20 | -public class LineStateHandle { | |
| 21 | - | |
| 22 | - private static ConcurrentHashMap<String, ChangeBean> map; | |
| 23 | - | |
| 24 | - @Autowired | |
| 25 | - DirectiveService directiveService; | |
| 26 | - @Autowired | |
| 27 | - GpsRealData gpsRealData; | |
| 28 | - | |
| 29 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | - | |
| 31 | - /** 重发次数 */ | |
| 32 | - private final static int MAX_SEND_COUNT=3; | |
| 33 | - /** 重发间隔 */ | |
| 34 | - private final static int SEND_SPACE=1000 * 60 * 6; | |
| 35 | - /** 最大有效时间 */ | |
| 36 | - private final static int MAX_AVAIL_TIME=1000 * 60 * 60 * 2; | |
| 37 | - | |
| 38 | - static{ | |
| 39 | - map = new ConcurrentHashMap(); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public void changeLine(String nbbm, String lineCode, String sender){ | |
| 43 | - ChangeBean cb = map.get(nbbm); | |
| 44 | - if(cb != null && cb.getLineCode().equals(lineCode)){ | |
| 45 | - return; | |
| 46 | - } | |
| 47 | - | |
| 48 | - cb = ChangeBean.getInstance(nbbm, lineCode, sender); | |
| 49 | - map.put(nbbm, cb); | |
| 50 | - | |
| 51 | - changeLine(cb); | |
| 52 | - } | |
| 53 | - | |
| 54 | - private void changeLine(ChangeBean cb){ | |
| 55 | - cb.setSt(System.currentTimeMillis()); | |
| 56 | - cb.countPlus(); | |
| 57 | - DirectivePushQueue.put64(cb.getNbbm(), cb.getLineCode(), cb.getSender()); | |
| 58 | - } | |
| 59 | - | |
| 60 | - | |
| 61 | - public void checkResultAll(){ | |
| 62 | - Collection<ChangeBean> cbs = map.values(); | |
| 63 | - for(ChangeBean cb : cbs){ | |
| 64 | - checkResult(cb); | |
| 65 | - } | |
| 66 | - } | |
| 67 | - | |
| 68 | - private void checkResult(ChangeBean cb){ | |
| 69 | - try{ | |
| 70 | - GpsEntity gps = gpsRealData.getByNbbm(cb.getNbbm()); | |
| 71 | - if(gps == null) | |
| 72 | - return; | |
| 73 | - | |
| 74 | - if(cb.getLineCode().equals(gps.getLineId())){ | |
| 75 | - map.remove(cb.getNbbm()); | |
| 76 | - logger.info("线路切换成功," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 77 | - } | |
| 78 | - else{ | |
| 79 | - reSend(cb); | |
| 80 | - } | |
| 81 | - }catch (Exception e){ | |
| 82 | - logger.error("", e); | |
| 83 | - } | |
| 84 | - } | |
| 85 | - | |
| 86 | - private void reSend(ChangeBean cb){ | |
| 87 | - if(cb.getSendCount() >= MAX_SEND_COUNT){ | |
| 88 | - map.remove(cb.getNbbm()); | |
| 89 | - logger.info("超过重发次数," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 90 | - return; | |
| 91 | - } | |
| 92 | - | |
| 93 | - long diff = System.currentTimeMillis() - cb.getSt(); | |
| 94 | - if(diff >= MAX_AVAIL_TIME){ | |
| 95 | - map.remove(cb.getNbbm()); | |
| 96 | - logger.info("超过有效时间," + cb.getNbbm() + "、" + cb.getLineCode() + "、" + cb.getSt()); | |
| 97 | - return; | |
| 98 | - } | |
| 99 | - | |
| 100 | - if(diff >= SEND_SPACE){ | |
| 101 | - cb.setSender("补发@系统"); | |
| 102 | - changeLine(cb); | |
| 103 | - logger.info("重发线路切换指令," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 104 | - return; | |
| 105 | - } | |
| 106 | - } | |
| 107 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_line_state; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.service.directive.DirectiveService; | |
| 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.Collection; | |
| 13 | +import java.util.concurrent.ConcurrentHashMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 设备线路状态处理 | |
| 17 | + * Created by panzhao on 2017/7/13. | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class LineStateHandle { | |
| 21 | + | |
| 22 | + private static ConcurrentHashMap<String, ChangeBean> map; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DirectiveService directiveService; | |
| 26 | + @Autowired | |
| 27 | + GpsRealData gpsRealData; | |
| 28 | + | |
| 29 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | + | |
| 31 | + /** 重发次数 */ | |
| 32 | + private final static int MAX_SEND_COUNT=3; | |
| 33 | + /** 重发间隔 */ | |
| 34 | + private final static int SEND_SPACE=1000 * 60 * 6; | |
| 35 | + /** 最大有效时间 */ | |
| 36 | + private final static int MAX_AVAIL_TIME=1000 * 60 * 60 * 2; | |
| 37 | + | |
| 38 | + static{ | |
| 39 | + map = new ConcurrentHashMap(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void changeLine(String nbbm, String lineCode, String sender){ | |
| 43 | + ChangeBean cb = map.get(nbbm); | |
| 44 | + if(cb != null && cb.getLineCode().equals(lineCode)){ | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 48 | + cb = ChangeBean.getInstance(nbbm, lineCode, sender); | |
| 49 | + map.put(nbbm, cb); | |
| 50 | + | |
| 51 | + changeLine(cb); | |
| 52 | + } | |
| 53 | + | |
| 54 | + private void changeLine(ChangeBean cb){ | |
| 55 | + cb.setSt(System.currentTimeMillis()); | |
| 56 | + cb.countPlus(); | |
| 57 | + DirectivePushQueue.put64(cb.getNbbm(), cb.getLineCode(), cb.getSender()); | |
| 58 | + } | |
| 59 | + | |
| 60 | + | |
| 61 | + public void checkResultAll(){ | |
| 62 | + Collection<ChangeBean> cbs = map.values(); | |
| 63 | + for(ChangeBean cb : cbs){ | |
| 64 | + checkResult(cb); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + private void checkResult(ChangeBean cb){ | |
| 69 | + try{ | |
| 70 | + GpsEntity gps = gpsRealData.getByNbbm(cb.getNbbm()); | |
| 71 | + if(gps == null) | |
| 72 | + return; | |
| 73 | + | |
| 74 | + if(cb.getLineCode().equals(gps.getLineId())){ | |
| 75 | + map.remove(cb.getNbbm()); | |
| 76 | + logger.info("线路切换成功," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 77 | + } | |
| 78 | + else{ | |
| 79 | + reSend(cb); | |
| 80 | + } | |
| 81 | + }catch (Exception e){ | |
| 82 | + logger.error("", e); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + private void reSend(ChangeBean cb){ | |
| 87 | + if(cb.getSendCount() >= MAX_SEND_COUNT){ | |
| 88 | + map.remove(cb.getNbbm()); | |
| 89 | + logger.info("超过重发次数," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + | |
| 93 | + long diff = System.currentTimeMillis() - cb.getSt(); | |
| 94 | + if(diff >= MAX_AVAIL_TIME){ | |
| 95 | + map.remove(cb.getNbbm()); | |
| 96 | + logger.info("超过有效时间," + cb.getNbbm() + "、" + cb.getLineCode() + "、" + cb.getSt()); | |
| 97 | + return; | |
| 98 | + } | |
| 99 | + | |
| 100 | + if(diff >= SEND_SPACE){ | |
| 101 | + cb.setSender("补发@系统"); | |
| 102 | + changeLine(cb); | |
| 103 | + logger.info("重发线路切换指令," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 104 | + return; | |
| 105 | + } | |
| 106 | + } | |
| 107 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_service_state/ServiceStateHandle.java renamed to src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_service_state/ServiceStateHandle.java
| 1 | -package com.bsth.data.gpsdata.status_manager.gps_service_state; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata.GpsRealData; | |
| 5 | -import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | -import com.bsth.service.directive.DirectiveService; | |
| 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.Collection; | |
| 13 | -import java.util.concurrent.ConcurrentHashMap; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * 设备营运状态/上下行 处理 | |
| 17 | - * Created by panzhao on 2017/7/13. | |
| 18 | - */ | |
| 19 | -@Component | |
| 20 | -public class ServiceStateHandle { | |
| 21 | - | |
| 22 | - private static ConcurrentHashMap<String, StateBean> map; | |
| 23 | - | |
| 24 | - @Autowired | |
| 25 | - DirectiveService directiveService; | |
| 26 | - @Autowired | |
| 27 | - GpsRealData gpsRealData; | |
| 28 | - | |
| 29 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | - | |
| 31 | - /** 重发次数 */ | |
| 32 | - private final static int MAX_SEND_COUNT=3; | |
| 33 | - /** 重发间隔 */ | |
| 34 | - private final static int SEND_SPACE=1000 * 60 * 3; | |
| 35 | - /** 最大有效时间 */ | |
| 36 | - private final static int MAX_AVAIL_TIME=1000 * 60 * 50; | |
| 37 | - | |
| 38 | - static{ | |
| 39 | - map = new ConcurrentHashMap(); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public void changeState(String nbbm, int upDown ,int state, String sender){ | |
| 43 | - if(map.containsKey(nbbm)){ | |
| 44 | - return; | |
| 45 | - } | |
| 46 | - StateBean sb = StateBean.getInstance(nbbm, upDown, state, sender); | |
| 47 | - map.put(nbbm, sb); | |
| 48 | - changeState(sb); | |
| 49 | - } | |
| 50 | - | |
| 51 | - private void changeState(StateBean sb){ | |
| 52 | - sb.setSt(System.currentTimeMillis()); | |
| 53 | - sb.countPlus(); | |
| 54 | - DirectivePushQueue.put6003(sb.getNbbm(), sb.getState(), sb.getUpDown(), sb.getSender()); | |
| 55 | - } | |
| 56 | - | |
| 57 | - public void checkResultAll(){ | |
| 58 | - Collection<StateBean> sbs = map.values(); | |
| 59 | - for(StateBean sb : sbs){ | |
| 60 | - checkResult(sb); | |
| 61 | - } | |
| 62 | - } | |
| 63 | - | |
| 64 | - private void checkResult(StateBean sb){ | |
| 65 | - try{ | |
| 66 | - GpsEntity gps = gpsRealData.getByNbbm(sb.getNbbm()); | |
| 67 | - if(gps == null) | |
| 68 | - return; | |
| 69 | - | |
| 70 | - if(gps.getState().equals(sb.getState()) && gps.getUpDown() == sb.getUpDown()){ | |
| 71 | - map.remove(sb.getNbbm()); | |
| 72 | - logger.info("状态切换成功," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 73 | - } | |
| 74 | - else | |
| 75 | - reSend(sb); | |
| 76 | - }catch (Exception e){ | |
| 77 | - logger.error("", e); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - private void reSend(StateBean sb){ | |
| 82 | - if(sb.getSendCount() >= MAX_SEND_COUNT){ | |
| 83 | - map.remove(sb.getNbbm()); | |
| 84 | - logger.info("超过重发次数," + sb.getNbbm() + "、" + sb.getState()); | |
| 85 | - return; | |
| 86 | - } | |
| 87 | - | |
| 88 | - long diff = System.currentTimeMillis() - sb.getSt(); | |
| 89 | - if(diff >= MAX_AVAIL_TIME){ | |
| 90 | - map.remove(sb.getNbbm()); | |
| 91 | - logger.info("状态切换超过有效时间," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getSt()); | |
| 92 | - return; | |
| 93 | - } | |
| 94 | - | |
| 95 | - if(diff >= SEND_SPACE){ | |
| 96 | - sb.setSender("补发@系统"); | |
| 97 | - changeState(sb); | |
| 98 | - logger.info("重发状态切换指令," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 99 | - return; | |
| 100 | - } | |
| 101 | - } | |
| 102 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_service_state; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.service.directive.DirectiveService; | |
| 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.Collection; | |
| 13 | +import java.util.concurrent.ConcurrentHashMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 设备营运状态/上下行 处理 | |
| 17 | + * Created by panzhao on 2017/7/13. | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class ServiceStateHandle { | |
| 21 | + | |
| 22 | + private static ConcurrentHashMap<String, StateBean> map; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DirectiveService directiveService; | |
| 26 | + @Autowired | |
| 27 | + GpsRealData gpsRealData; | |
| 28 | + | |
| 29 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | + | |
| 31 | + /** 重发次数 */ | |
| 32 | + private final static int MAX_SEND_COUNT=3; | |
| 33 | + /** 重发间隔 */ | |
| 34 | + private final static int SEND_SPACE=1000 * 60 * 3; | |
| 35 | + /** 最大有效时间 */ | |
| 36 | + private final static int MAX_AVAIL_TIME=1000 * 60 * 50; | |
| 37 | + | |
| 38 | + static{ | |
| 39 | + map = new ConcurrentHashMap(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void changeState(String nbbm, int upDown ,int state, String sender){ | |
| 43 | + if(map.containsKey(nbbm)){ | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + StateBean sb = StateBean.getInstance(nbbm, upDown, state, sender); | |
| 47 | + map.put(nbbm, sb); | |
| 48 | + changeState(sb); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private void changeState(StateBean sb){ | |
| 52 | + sb.setSt(System.currentTimeMillis()); | |
| 53 | + sb.countPlus(); | |
| 54 | + DirectivePushQueue.put6003(sb.getNbbm(), sb.getState(), sb.getUpDown(), sb.getSender()); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void checkResultAll(){ | |
| 58 | + Collection<StateBean> sbs = map.values(); | |
| 59 | + for(StateBean sb : sbs){ | |
| 60 | + checkResult(sb); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + private void checkResult(StateBean sb){ | |
| 65 | + try{ | |
| 66 | + GpsEntity gps = gpsRealData.getByNbbm(sb.getNbbm()); | |
| 67 | + if(gps == null) | |
| 68 | + return; | |
| 69 | + | |
| 70 | + if(gps.getState().equals(sb.getState()) && gps.getUpDown() == sb.getUpDown()){ | |
| 71 | + map.remove(sb.getNbbm()); | |
| 72 | + logger.info("状态切换成功," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 73 | + } | |
| 74 | + else | |
| 75 | + reSend(sb); | |
| 76 | + }catch (Exception e){ | |
| 77 | + logger.error("", e); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void reSend(StateBean sb){ | |
| 82 | + if(sb.getSendCount() >= MAX_SEND_COUNT){ | |
| 83 | + map.remove(sb.getNbbm()); | |
| 84 | + logger.info("超过重发次数," + sb.getNbbm() + "、" + sb.getState()); | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + | |
| 88 | + long diff = System.currentTimeMillis() - sb.getSt(); | |
| 89 | + if(diff >= MAX_AVAIL_TIME){ | |
| 90 | + map.remove(sb.getNbbm()); | |
| 91 | + logger.info("状态切换超过有效时间," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getSt()); | |
| 92 | + return; | |
| 93 | + } | |
| 94 | + | |
| 95 | + if(diff >= SEND_SPACE){ | |
| 96 | + sb.setSender("补发@系统"); | |
| 97 | + changeState(sb); | |
| 98 | + logger.info("重发状态切换指令," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getUpDown()); | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + } | |
| 102 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_service_state/StateBean.java renamed to src/main/java/com/bsth/data/gpsdata_v2/status_manager/gps_service_state/StateBean.java
| 1 | -package com.bsth.data.gpsdata.status_manager.gps_service_state; | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Created by panzhao on 2017/7/13. | |
| 5 | - */ | |
| 6 | -public class StateBean { | |
| 7 | - | |
| 8 | - /** | |
| 9 | - * 车辆自编号 | |
| 10 | - */ | |
| 11 | - private String nbbm; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * 要切换到营运状态 | |
| 15 | - */ | |
| 16 | - private int state; | |
| 17 | - | |
| 18 | - /** | |
| 19 | - * 要切换到的上下行 | |
| 20 | - */ | |
| 21 | - private int upDown; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * 指令发送次数 | |
| 25 | - */ | |
| 26 | - private int sendCount; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * 上次指令时间 | |
| 30 | - */ | |
| 31 | - private long st; | |
| 32 | - | |
| 33 | - /**发送人 */ | |
| 34 | - private String sender; | |
| 35 | - | |
| 36 | - public static StateBean getInstance(String nbbm, int upDown, int state, String sender){ | |
| 37 | - StateBean sb = new StateBean(); | |
| 38 | - sb.setNbbm(nbbm); | |
| 39 | - sb.setState(state); | |
| 40 | - sb.setSendCount(0); | |
| 41 | - sb.setSender(sender); | |
| 42 | - sb.setUpDown(upDown); | |
| 43 | - return sb; | |
| 44 | - } | |
| 45 | - | |
| 46 | - public int getState() { | |
| 47 | - return state; | |
| 48 | - } | |
| 49 | - | |
| 50 | - public void setState(int state) { | |
| 51 | - this.state = state; | |
| 52 | - } | |
| 53 | - | |
| 54 | - public int getSendCount() { | |
| 55 | - return sendCount; | |
| 56 | - } | |
| 57 | - | |
| 58 | - public void setSendCount(int sendCount) { | |
| 59 | - this.sendCount = sendCount; | |
| 60 | - } | |
| 61 | - | |
| 62 | - public long getSt() { | |
| 63 | - return st; | |
| 64 | - } | |
| 65 | - | |
| 66 | - public void setSt(long st) { | |
| 67 | - this.st = st; | |
| 68 | - } | |
| 69 | - | |
| 70 | - public String getSender() { | |
| 71 | - return sender; | |
| 72 | - } | |
| 73 | - | |
| 74 | - public void setSender(String sender) { | |
| 75 | - this.sender = sender; | |
| 76 | - } | |
| 77 | - | |
| 78 | - public void countPlus(){ | |
| 79 | - sendCount ++; | |
| 80 | - } | |
| 81 | - | |
| 82 | - public int getUpDown() { | |
| 83 | - return upDown; | |
| 84 | - } | |
| 85 | - | |
| 86 | - public void setUpDown(int upDown) { | |
| 87 | - this.upDown = upDown; | |
| 88 | - } | |
| 89 | - | |
| 90 | - public String getNbbm() { | |
| 91 | - return nbbm; | |
| 92 | - } | |
| 93 | - | |
| 94 | - public void setNbbm(String nbbm) { | |
| 95 | - this.nbbm = nbbm; | |
| 96 | - } | |
| 97 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.status_manager.gps_service_state; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by panzhao on 2017/7/13. | |
| 5 | + */ | |
| 6 | +public class StateBean { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 车辆自编号 | |
| 10 | + */ | |
| 11 | + private String nbbm; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 要切换到营运状态 | |
| 15 | + */ | |
| 16 | + private int state; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 要切换到的上下行 | |
| 20 | + */ | |
| 21 | + private int upDown; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 指令发送次数 | |
| 25 | + */ | |
| 26 | + private int sendCount; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 上次指令时间 | |
| 30 | + */ | |
| 31 | + private long st; | |
| 32 | + | |
| 33 | + /**发送人 */ | |
| 34 | + private String sender; | |
| 35 | + | |
| 36 | + public static StateBean getInstance(String nbbm, int upDown, int state, String sender){ | |
| 37 | + StateBean sb = new StateBean(); | |
| 38 | + sb.setNbbm(nbbm); | |
| 39 | + sb.setState(state); | |
| 40 | + sb.setSendCount(0); | |
| 41 | + sb.setSender(sender); | |
| 42 | + sb.setUpDown(upDown); | |
| 43 | + return sb; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public int getState() { | |
| 47 | + return state; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setState(int state) { | |
| 51 | + this.state = state; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public int getSendCount() { | |
| 55 | + return sendCount; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setSendCount(int sendCount) { | |
| 59 | + this.sendCount = sendCount; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public long getSt() { | |
| 63 | + return st; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setSt(long st) { | |
| 67 | + this.st = st; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public String getSender() { | |
| 71 | + return sender; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void setSender(String sender) { | |
| 75 | + this.sender = sender; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void countPlus(){ | |
| 79 | + sendCount ++; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public int getUpDown() { | |
| 83 | + return upDown; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setUpDown(int upDown) { | |
| 87 | + this.upDown = upDown; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public String getNbbm() { | |
| 91 | + return nbbm; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public void setNbbm(String nbbm) { | |
| 95 | + this.nbbm = nbbm; | |
| 96 | + } | |
| 97 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/thread/GpsDataLoaderThread.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.thread; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.DataHandleProcess; | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 5 | +import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader; | |
| 6 | +import com.bsth.data.gpsdata_v2.load.SocketClientLoader; | |
| 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.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Created by panzhao on 2017/1/11. | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +public class GpsDataLoaderThread extends Thread { | |
| 19 | + | |
| 20 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 21 | + | |
| 22 | + //0:从GPS客户端内存获取 -1:从网关获取 | |
| 23 | + private static int flag = 0; | |
| 24 | + | |
| 25 | + public static void setFlag(int v) { | |
| 26 | + flag = v; | |
| 27 | + } | |
| 28 | + | |
| 29 | + @Autowired | |
| 30 | + DataHandleProcess handleProcess; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public void run() { | |
| 34 | + try { | |
| 35 | + List<GpsEntity> list; | |
| 36 | + if (flag == 0) | |
| 37 | + list = SocketClientLoader.load(); | |
| 38 | + else | |
| 39 | + list = GatewayHttpLoader.load(); | |
| 40 | + | |
| 41 | + if(null != list && list.size() > 0) | |
| 42 | + handleProcess.handle(list); | |
| 43 | + } catch (Exception e) { | |
| 44 | + logger.error("", e); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} | |
| 0 | 48 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/utils/CircleQueue.java renamed to src/main/java/com/bsth/data/gpsdata_v2/utils/CircleQueue.java
| 1 | -package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | - | |
| 3 | -import java.util.Arrays; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * 循环队列 | |
| 7 | - * Created by panzhao on 2016/12/23. | |
| 8 | - */ | |
| 9 | -public class CircleQueue<T> { | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * (循环队列)数组的容量 | |
| 13 | - */ | |
| 14 | - public int capacity; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * 数组:保存循环队列的元素 | |
| 18 | - */ | |
| 19 | - public Object[] elementData; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * 头 | |
| 23 | - */ | |
| 24 | - public int head = 0; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * 尾 | |
| 28 | - */ | |
| 29 | - public int tail = 0; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * 以指定长度的数组来创建循环队列 | |
| 33 | - * | |
| 34 | - * @param initSize | |
| 35 | - */ | |
| 36 | - public CircleQueue(final int initSize) { | |
| 37 | - capacity = initSize; | |
| 38 | - elementData = new Object[capacity]; | |
| 39 | - } | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * 获取循环队列的大小 | |
| 43 | - */ | |
| 44 | - public int size() { | |
| 45 | - if (isEmpty()) { | |
| 46 | - return 0; | |
| 47 | - } else if (isFull()) { | |
| 48 | - return capacity; | |
| 49 | - } else { | |
| 50 | - return tail + 1; | |
| 51 | - } | |
| 52 | - } | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * 插入队尾一个元素 | |
| 56 | - */ | |
| 57 | - public void add(final T element) { | |
| 58 | - if (isEmpty()) { | |
| 59 | - elementData[0] = element; | |
| 60 | - } else if (isFull()) { | |
| 61 | - elementData[head] = element; | |
| 62 | - head++; | |
| 63 | - tail++; | |
| 64 | - head = head == capacity ? 0 : head; | |
| 65 | - tail = tail == capacity ? 0 : tail; | |
| 66 | - } else { | |
| 67 | - elementData[tail + 1] = element; | |
| 68 | - tail++; | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - public boolean isEmpty() { | |
| 73 | - return tail == head && tail == 0 && elementData[tail] == null; | |
| 74 | - } | |
| 75 | - | |
| 76 | - public boolean isFull() { | |
| 77 | - return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public void clear() { | |
| 81 | - Arrays.fill(elementData, null); | |
| 82 | - head = 0; | |
| 83 | - tail = 0; | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @return 取 循环队列里的值(先进的index=0) | |
| 88 | - */ | |
| 89 | - public Object[] getQueue() { | |
| 90 | - final Object[] elementDataSort; | |
| 91 | - final Object[] elementDataCopy = elementData.clone(); | |
| 92 | - if (isEmpty()) { | |
| 93 | - elementDataSort = new Object[0]; | |
| 94 | - } else if (isFull()) { | |
| 95 | - elementDataSort = new Object[capacity]; | |
| 96 | - int indexMax = capacity; | |
| 97 | - int indexSort = 0; | |
| 98 | - for (int i = head; i < indexMax;) { | |
| 99 | - elementDataSort[indexSort] = elementDataCopy[i]; | |
| 100 | - indexSort++; | |
| 101 | - i++; | |
| 102 | - if (i == capacity) { | |
| 103 | - i = 0; | |
| 104 | - indexMax = head; | |
| 105 | - } | |
| 106 | - } | |
| 107 | - } else { | |
| 108 | - elementDataSort = new Object[tail + 1]; | |
| 109 | - for (int i = 0; i <= tail; i++) { | |
| 110 | - elementDataSort[i] = elementDataCopy[i]; | |
| 111 | - } | |
| 112 | - } | |
| 113 | - return elementDataSort; | |
| 114 | - } | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * 取最后一个值 | |
| 118 | - * @return | |
| 119 | - */ | |
| 120 | - public T getTail(){ | |
| 121 | - return elementData[tail] == null?null:(T)elementData[tail]; | |
| 122 | - } | |
| 1 | +package com.bsth.data.gpsdata_v2.utils; | |
| 2 | + | |
| 3 | +import java.util.Arrays; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 循环队列 | |
| 7 | + * Created by panzhao on 2016/12/23. | |
| 8 | + */ | |
| 9 | +public class CircleQueue<T> { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * (循环队列)数组的容量 | |
| 13 | + */ | |
| 14 | + public int capacity; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 数组:保存循环队列的元素 | |
| 18 | + */ | |
| 19 | + public Object[] elementData; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 头 | |
| 23 | + */ | |
| 24 | + public int head = 0; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 尾 | |
| 28 | + */ | |
| 29 | + public int tail = 0; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 以指定长度的数组来创建循环队列 | |
| 33 | + * | |
| 34 | + * @param initSize | |
| 35 | + */ | |
| 36 | + public CircleQueue(final int initSize) { | |
| 37 | + capacity = initSize; | |
| 38 | + elementData = new Object[capacity]; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获取循环队列的大小 | |
| 43 | + */ | |
| 44 | + public int size() { | |
| 45 | + if (isEmpty()) { | |
| 46 | + return 0; | |
| 47 | + } else if (isFull()) { | |
| 48 | + return capacity; | |
| 49 | + } else { | |
| 50 | + return tail + 1; | |
| 51 | + } | |
| 52 | + } | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 插入队尾一个元素 | |
| 56 | + */ | |
| 57 | + public void add(final T element) { | |
| 58 | + if (isEmpty()) { | |
| 59 | + elementData[0] = element; | |
| 60 | + } else if (isFull()) { | |
| 61 | + elementData[head] = element; | |
| 62 | + head++; | |
| 63 | + tail++; | |
| 64 | + head = head == capacity ? 0 : head; | |
| 65 | + tail = tail == capacity ? 0 : tail; | |
| 66 | + } else { | |
| 67 | + elementData[tail + 1] = element; | |
| 68 | + tail++; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + public boolean isEmpty() { | |
| 73 | + return tail == head && tail == 0 && elementData[tail] == null; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public boolean isFull() { | |
| 77 | + return head != 0 && head - tail == 1 || head == 0 && tail == capacity - 1; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void clear() { | |
| 81 | + Arrays.fill(elementData, null); | |
| 82 | + head = 0; | |
| 83 | + tail = 0; | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @return 取 循环队列里的值(先进的index=0) | |
| 88 | + */ | |
| 89 | + public Object[] getQueue() { | |
| 90 | + final Object[] elementDataSort; | |
| 91 | + final Object[] elementDataCopy = elementData.clone(); | |
| 92 | + if (isEmpty()) { | |
| 93 | + elementDataSort = new Object[0]; | |
| 94 | + } else if (isFull()) { | |
| 95 | + elementDataSort = new Object[capacity]; | |
| 96 | + int indexMax = capacity; | |
| 97 | + int indexSort = 0; | |
| 98 | + for (int i = head; i < indexMax;) { | |
| 99 | + elementDataSort[indexSort] = elementDataCopy[i]; | |
| 100 | + indexSort++; | |
| 101 | + i++; | |
| 102 | + if (i == capacity) { | |
| 103 | + i = 0; | |
| 104 | + indexMax = head; | |
| 105 | + } | |
| 106 | + } | |
| 107 | + } else { | |
| 108 | + elementDataSort = new Object[tail + 1]; | |
| 109 | + for (int i = 0; i <= tail; i++) { | |
| 110 | + elementDataSort[i] = elementDataCopy[i]; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + return elementDataSort; | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * 取最后一个值 | |
| 118 | + * @return | |
| 119 | + */ | |
| 120 | + public T getTail(){ | |
| 121 | + return elementData[tail] == null?null:(T)elementData[tail]; | |
| 122 | + } | |
| 123 | 123 | } |
| 124 | 124 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/utils/GeoUtils.java renamed to src/main/java/com/bsth/data/gpsdata_v2/utils/GeoUtils.java
| 1 | -package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | -import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 5 | -import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 6 | -import com.bsth.data.gpsdata.arrival.precondition.entity.PreconditionGeo; | |
| 7 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 8 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 9 | -import com.vividsolutions.jts.geom.LineString; | |
| 10 | -import com.vividsolutions.jts.geom.Point; | |
| 11 | - | |
| 12 | -import java.util.List; | |
| 13 | -import java.util.Map; | |
| 14 | -import java.util.Set; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * Created by panzhao on 2016/12/23. | |
| 18 | - */ | |
| 19 | -public class GeoUtils { | |
| 20 | - | |
| 21 | - private final static double EARTHRADIUS = 6378137; | |
| 22 | - | |
| 23 | - private static GeometryFactory geometryFactory = new GeometryFactory(); | |
| 24 | - /** | |
| 25 | - * gps是否在路由上的某个站内 | |
| 26 | - * | |
| 27 | - * @param gps | |
| 28 | - * @param srs | |
| 29 | - * @return | |
| 30 | - */ | |
| 31 | - public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) { | |
| 32 | - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 33 | - double min = -1, distance; | |
| 34 | - StationRoute stationRoute = null; | |
| 35 | - | |
| 36 | - for (StationRoute sr : srs) { | |
| 37 | - if (sr.getPolygon() == null) { | |
| 38 | - //圆形 | |
| 39 | - distance = getDistance(sr.getPoint(), point);//sr.getPoint().distance(point); | |
| 40 | - | |
| 41 | - if (distance > sr.getRadius()) | |
| 42 | - continue; | |
| 43 | - | |
| 44 | - if (min > distance || min == -1) { | |
| 45 | - min = distance; | |
| 46 | - stationRoute = sr; | |
| 47 | - } | |
| 48 | - } else { | |
| 49 | - //多边形 | |
| 50 | - /*if (sr.getPolygon().contains(point)) { | |
| 51 | - stationRoute = sr; | |
| 52 | - break; | |
| 53 | - }*/ | |
| 54 | - com.bsth.util.Geo.Polygon polygon2 = GeoCacheData.convertPolygon(sr.getPolygon()); | |
| 55 | - com.bsth.util.Geo.Point point2 = new com.bsth.util.Geo.Point(gps.getLon(), gps.getLat()); | |
| 56 | - if(com.bsth.util.Geo.GeoUtils.isPointInPolygon(point2, polygon2)){ | |
| 57 | - stationRoute = sr; | |
| 58 | - break; | |
| 59 | - } | |
| 60 | - } | |
| 61 | - } | |
| 62 | - return stationRoute; | |
| 63 | - } | |
| 64 | - | |
| 65 | - public static double getDistance(Point p1, Point p2) { | |
| 66 | - double lng1 = getLoop(p1.getY(), -180, 180), lat1 = getRange( | |
| 67 | - p1.getX(), -74, 74); | |
| 68 | - double lng2 = getLoop(p2.getY(), -180, 180), lat2 = getRange( | |
| 69 | - p2.getX(), -74, 74); | |
| 70 | - | |
| 71 | - double x1, x2, y1, y2; | |
| 72 | - x1 = degreeToRad(lng1); | |
| 73 | - y1 = degreeToRad(lat1); | |
| 74 | - x2 = degreeToRad(lng2); | |
| 75 | - y2 = degreeToRad(lat2); | |
| 76 | - return EARTHRADIUS | |
| 77 | - * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1) | |
| 78 | - * Math.cos(y2) * Math.cos(x2 - x1))); | |
| 79 | - } | |
| 80 | - | |
| 81 | - private static double getLoop(double v, double a, double b) { | |
| 82 | - while (v > b) { | |
| 83 | - v -= b - a; | |
| 84 | - } | |
| 85 | - while (v < a) { | |
| 86 | - v += b - a; | |
| 87 | - } | |
| 88 | - return v; | |
| 89 | - } | |
| 90 | - | |
| 91 | - private static double getRange(double v, double a, double b) { | |
| 92 | - v = Math.min(Math.max(v, a), b); | |
| 93 | - return v; | |
| 94 | - } | |
| 95 | - | |
| 96 | - private static double degreeToRad(double degree) { | |
| 97 | - return Math.PI * degree / 180; | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * 计算点 到 线的距离 | |
| 102 | - * @param line | |
| 103 | - * @param p | |
| 104 | - * @return | |
| 105 | - */ | |
| 106 | - public static double getDistanceFromLine(LineString line, Point p){ | |
| 107 | - Point s = line.getStartPoint(); | |
| 108 | - Point e = line.getEndPoint(); | |
| 109 | - return getDistanceFromLine(s, e, p); | |
| 110 | - } | |
| 111 | - | |
| 112 | - public static double getDistanceFromLine(Point s, Point e, Point p){ | |
| 113 | - double d1 = getDistance(s, p); | |
| 114 | - double d2 = getDistance(p, e); | |
| 115 | - double d3 = getDistance(s, e); | |
| 116 | - double distance = 0; | |
| 117 | - | |
| 118 | - double alpha = Math.acos((d1*d1 + d3*d3 - d2*d2)/(2*d1*d3)); | |
| 119 | - double beta = Math.acos((d2*d2 + d3*d3 - d1*d1)/(2*d2*d3)); | |
| 120 | - | |
| 121 | - if(alpha>Math.PI/2) { | |
| 122 | - distance = d1; | |
| 123 | - } | |
| 124 | - else if(beta > Math.PI/2) { | |
| 125 | - distance = d2; | |
| 126 | - } | |
| 127 | - else { | |
| 128 | - distance = Math.sin(alpha) * d1; | |
| 129 | - } | |
| 130 | - return distance; | |
| 131 | - } | |
| 132 | - | |
| 133 | - | |
| 134 | - /** | |
| 135 | - * gps 是否在某个停车场内 | |
| 136 | - * @param gps | |
| 137 | - * @return | |
| 138 | - public static String gpsInCarpark(GpsEntity gps){ | |
| 139 | - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 140 | - | |
| 141 | - Map<String, Polygon> carparkMap = GeoCacheData.tccMap; | |
| 142 | - Set<String> codes = carparkMap.keySet(); | |
| 143 | - Polygon polygon; | |
| 144 | - for(String code : codes){ | |
| 145 | - polygon = carparkMap.get(code); | |
| 146 | - if(point.within(polygon)){ | |
| 147 | - return code; | |
| 148 | - } | |
| 149 | - } | |
| 150 | - return null; | |
| 151 | - }*/ | |
| 152 | - | |
| 153 | - /** | |
| 154 | - * gps 是否在某个停车场内 | |
| 155 | - * @param gps | |
| 156 | - * @return | |
| 157 | - */ | |
| 158 | - public static String gpsInCarpark(GpsEntity gps){ | |
| 159 | - com.bsth.util.Geo.Point point = new com.bsth.util.Geo.Point(gps.getLon(), gps.getLat()); | |
| 160 | - Map<String, com.bsth.util.Geo.Polygon> carparkMap = GeoCacheData.tccMap2; | |
| 161 | - com.bsth.util.Geo.Polygon polygon; | |
| 162 | - Set<String> codes = carparkMap.keySet(); | |
| 163 | - for(String code : codes){ | |
| 164 | - polygon = carparkMap.get(code); | |
| 165 | - if(com.bsth.util.Geo.GeoUtils.isPointInPolygon(point, polygon)){ | |
| 166 | - return code; | |
| 167 | - } | |
| 168 | - } | |
| 169 | - return null; | |
| 170 | - } | |
| 171 | - | |
| 172 | - /** | |
| 173 | - * 是否在进站前置围栏内 | |
| 174 | - * @param gps | |
| 175 | - * @return | |
| 176 | - */ | |
| 177 | - public static String gpsInPremiseGeo(GpsEntity gps) { | |
| 178 | - List<PreconditionGeo> list = GeoCacheData.premiseGeoMap.get(gps.getLineId()+"_"+gps.getUpDown()); | |
| 179 | - | |
| 180 | - if(null == list || list.size()==0) | |
| 181 | - return null; | |
| 182 | - | |
| 183 | - com.bsth.util.Geo.Point point = new com.bsth.util.Geo.Point(gps.getLon(), gps.getLat()); | |
| 184 | - com.bsth.util.Geo.Polygon polygon; | |
| 185 | - for(PreconditionGeo p : list){ | |
| 186 | - polygon = p.getPolygon(); | |
| 187 | - if(com.bsth.util.Geo.GeoUtils.isPointInPolygon(point, polygon)){ | |
| 188 | - return p.getStationCode(); | |
| 189 | - } | |
| 190 | - } | |
| 191 | - return null; | |
| 192 | - } | |
| 193 | - | |
| 194 | - /** | |
| 195 | - * 是否是有效的连续点 | |
| 196 | - * @param prevGps | |
| 197 | - * @param gps | |
| 198 | - * @return | |
| 199 | - */ | |
| 200 | - public static boolean overdue(GpsEntity prevGps, GpsEntity gps) { | |
| 201 | - return gps.getTimestamp() - prevGps.getTimestamp() < 120000; | |
| 202 | - } | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * 计算2条直线的最短距离 | |
| 206 | - * @param p1 | |
| 207 | - * @param p2 | |
| 208 | - * @param p3 | |
| 209 | - * @param p4 | |
| 210 | - * @return | |
| 211 | - */ | |
| 212 | - public static double getDistanceLineToLine(Point p1, Point p2, Point p3, Point p4){ | |
| 213 | - double distance; | |
| 214 | - double x1 = p1.getX(); //A点坐标(x1,y1,z1) | |
| 215 | - double y1 = p1.getY(); | |
| 216 | - double z1 = 0; | |
| 217 | - double x2 = p2.getX(); //B点坐标(x2,y2,z2) | |
| 218 | - double y2 = p2.getY(); | |
| 219 | - double z2 = 0; | |
| 220 | - double x3 = p3.getX(); //C点坐标(x3,y3,z3) | |
| 221 | - double y3 = p3.getY(); | |
| 222 | - double z3 = 0; | |
| 223 | - double x4 = p4.getX(); //D点坐标(x4,y4,z4) | |
| 224 | - double y4 = p4.getY(); | |
| 225 | - double z4 = 0; | |
| 226 | - | |
| 227 | - double a = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1); | |
| 228 | - double b = -((x2-x1)*(x4-x3)+(y2-y1)*(y4-y3)+(z2-z1)*(z4-z3)); | |
| 229 | - double c = -((x1-x2)*(x1-x3)+(y1-y2)*(y1-y3)+(z1-z2)*(z1-z3)); | |
| 230 | - | |
| 231 | - double d = -((x2-x1)*(x4-x3)+(y2-y1)*(y4-y3)+(z2-z1)*(z4-z3)); | |
| 232 | - double e = (x4-x3)*(x4-x3)+(y4-y3)*(y4-y3)+(z4-z3)*(z4-z3); | |
| 233 | - double f = -((x1-x3)*(x4-x3)+(y1-y3)*(y4-y3)+(z1-z3)*(z4-z3)); | |
| 234 | - | |
| 235 | - //平行 | |
| 236 | - if ((a*e-b*d)==0&&(b*d-a*e)==0) | |
| 237 | - { | |
| 238 | - double d1 = getDistance(p1, p3); | |
| 239 | - double d2 = getDistance(p1, p4); | |
| 240 | - distance = (d1<d2)?d1:d2; | |
| 241 | - return distance; | |
| 242 | - } | |
| 243 | - | |
| 244 | - double s = (b*f-e*c)/(a*e-b*d); | |
| 245 | - double t = (a*f-d*c)/(b*d-a*e); | |
| 246 | - | |
| 247 | - //说明P点落在线段AB上,Q点落在线段CD上 | |
| 248 | - if(0<=s&&s<=1&&0<=t&&t<=1) | |
| 249 | - { | |
| 250 | - //2条线段的公垂线段PQ; | |
| 251 | - //P点坐标 | |
| 252 | - double X = x1+s*(x2-x1); | |
| 253 | - double Y = y1+s*(y2-y1); | |
| 254 | - double Z = z1+s*(z2-z1); | |
| 255 | - //Q点坐标 | |
| 256 | - double U = x3+t*(x4-x3); | |
| 257 | - double V = y3+t*(y4-y3); | |
| 258 | - double W = z3+t*(z4-z3); | |
| 259 | - Point p = geometryFactory.createPoint(new Coordinate(X, Y, Z)); | |
| 260 | - Point q = geometryFactory.createPoint(new Coordinate(U, V, W)); | |
| 261 | - distance = getDistance(p, q); | |
| 262 | - } | |
| 263 | - else | |
| 264 | - { | |
| 265 | - double d1 = getDistanceFromLine(p3,p4,p1); | |
| 266 | - double d2 = getDistanceFromLine(p3,p4,p2); | |
| 267 | - double d3 = getDistanceFromLine(p1,p2,p3); | |
| 268 | - double d4 = getDistanceFromLine(p1,p2,p4); | |
| 269 | - distance = (d1<d2)?d1:d2; | |
| 270 | - distance = (distance<d3)?distance:d3; | |
| 271 | - distance = (distance<d4)?distance:d4; | |
| 272 | - } | |
| 273 | - | |
| 274 | - return distance; | |
| 275 | - } | |
| 276 | - | |
| 277 | - /** | |
| 278 | - * 计算点 到 线的垂直交点 | |
| 279 | - * @param lp1 | |
| 280 | - * @param lp2 | |
| 281 | - * @param p | |
| 282 | - * @return | |
| 283 | - */ | |
| 284 | - public static Point perpendularPoint(Point lp1, Point lp2, Point p){ | |
| 285 | - double a = lp1.getX() - lp2.getX(), b = lp2.getY() - lp1.getY(), c = lp1.getY() * lp2.getX() - lp2.getY() * lp1.getX(); | |
| 286 | - double lon = (Math.pow(b, 2) * p.getY() - a * b * p.getX() - a * c) / (Math.pow(a, 2) + Math.pow(b, 2)); | |
| 287 | - double lat = (Math.pow(a, 2) * p.getX() - a * b * p.getY() - b * c) / (Math.pow(a, 2) + Math.pow(b, 2)); | |
| 288 | - | |
| 289 | - return geometryFactory.createPoint(new Coordinate(lat, lon)); | |
| 290 | - } | |
| 291 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 4 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.CtLineString; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 7 | +import com.bsth.data.gpsdata_v2.entity.PreconditionGeo; | |
| 8 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 9 | +import com.bsth.util.Geo.Bounds; | |
| 10 | +import com.bsth.util.Geo.Point; | |
| 11 | +import com.bsth.util.Geo.Polygon; | |
| 12 | + | |
| 13 | +import java.util.*; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by panzhao on 2016/12/23. | |
| 17 | + */ | |
| 18 | +public class GeoUtils { | |
| 19 | + | |
| 20 | + private final static double EARTH_RADIUS = 6378137; | |
| 21 | + | |
| 22 | + private static StationRouteComp sComp = new StationRouteComp(); | |
| 23 | + /** | |
| 24 | + * gps是否在路由上的某个站内 | |
| 25 | + * | |
| 26 | + * @param gps | |
| 27 | + * @param srs | |
| 28 | + * @return | |
| 29 | + */ | |
| 30 | + public static StationRoute gpsInStation(GpsEntity gps, List<StationRoute> srs) { | |
| 31 | + List<StationRoute> rs = new ArrayList<>(); | |
| 32 | + | |
| 33 | + Point point = new Point(gps.getLon(), gps.getLat()); | |
| 34 | + double distance; | |
| 35 | + | |
| 36 | + for (StationRoute sr : srs) { | |
| 37 | + if (sr.getPolygon() == null) { | |
| 38 | + //圆形 | |
| 39 | + distance = getDistance(sr.getPoint(), point); | |
| 40 | + | |
| 41 | + if (distance > sr.getRadius()) | |
| 42 | + continue; | |
| 43 | + | |
| 44 | + rs.add(sr); | |
| 45 | + } else if(isPointInPolygon(point, sr.getPolygon())){ | |
| 46 | + rs.add(sr); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + if(rs.size() == 0) | |
| 51 | + return null; | |
| 52 | + else | |
| 53 | + return findNearStation(rs, gps); | |
| 54 | + } | |
| 55 | + | |
| 56 | + private static StationRoute findNearStation(List<StationRoute> rs, GpsEntity gps) { | |
| 57 | + if(rs.size() > 1){ | |
| 58 | + //按路由顺序排序 | |
| 59 | + Collections.sort(rs, sComp); | |
| 60 | + | |
| 61 | + //上一个进出的站点 | |
| 62 | + StationRoute ps = GpsCacheData.prevStation(gps); | |
| 63 | + if(null != ps){ | |
| 64 | + for(StationRoute s : rs){ | |
| 65 | + if(s.getRouteSort() >= ps.getRouteSort()) | |
| 66 | + return s; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + } | |
| 70 | + return rs.get(0); | |
| 71 | + } | |
| 72 | + | |
| 73 | + | |
| 74 | + public static double getDistance(Point p1, Point p2) { | |
| 75 | + double lng1 = getLoop(p1.getLon(), -180, 180), lat1 = getRange( | |
| 76 | + p1.getLat(), -74, 74); | |
| 77 | + double lng2 = getLoop(p2.getLon(), -180, 180), lat2 = getRange( | |
| 78 | + p2.getLat(), -74, 74); | |
| 79 | + | |
| 80 | + double x1, x2, y1, y2; | |
| 81 | + x1 = degreeToRad(lng1); | |
| 82 | + y1 = degreeToRad(lat1); | |
| 83 | + x2 = degreeToRad(lng2); | |
| 84 | + y2 = degreeToRad(lat2); | |
| 85 | + return EARTH_RADIUS | |
| 86 | + * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1) | |
| 87 | + * Math.cos(y2) * Math.cos(x2 - x1))); | |
| 88 | + } | |
| 89 | + | |
| 90 | + private static double getLoop(double v, double a, double b) { | |
| 91 | + while (v > b) { | |
| 92 | + v -= b - a; | |
| 93 | + } | |
| 94 | + while (v < a) { | |
| 95 | + v += b - a; | |
| 96 | + } | |
| 97 | + return v; | |
| 98 | + } | |
| 99 | + | |
| 100 | + private static double getRange(double v, double a, double b) { | |
| 101 | + v = Math.min(Math.max(v, a), b); | |
| 102 | + return v; | |
| 103 | + } | |
| 104 | + | |
| 105 | + private static double degreeToRad(double degree) { | |
| 106 | + return Math.PI * degree / 180; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public static double getDistanceFromLine(CtLineString lineString, Point p){ | |
| 110 | + return getDistanceFromLine(lineString.getS(), lineString.getE(), p); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * 计算点 到 线的距离 | |
| 115 | + * @param line | |
| 116 | + * @param p | |
| 117 | + * @return | |
| 118 | + */ | |
| 119 | + public static double getDistanceFromLine(Point s, Point e, Point p){ | |
| 120 | + double d1 = getDistance(s, p); | |
| 121 | + double d2 = getDistance(p, e); | |
| 122 | + double d3 = getDistance(s, e); | |
| 123 | + double distance = 0; | |
| 124 | + | |
| 125 | + double alpha = Math.acos((d1*d1 + d3*d3 - d2*d2)/(2*d1*d3)); | |
| 126 | + double beta = Math.acos((d2*d2 + d3*d3 - d1*d1)/(2*d2*d3)); | |
| 127 | + | |
| 128 | + if(alpha>Math.PI/2) { | |
| 129 | + distance = d1; | |
| 130 | + } | |
| 131 | + else if(beta > Math.PI/2) { | |
| 132 | + distance = d2; | |
| 133 | + } | |
| 134 | + else { | |
| 135 | + distance = Math.sin(alpha) * d1; | |
| 136 | + } | |
| 137 | + return distance; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * gps 是否在某个停车场内 | |
| 142 | + * @param gps | |
| 143 | + * @return | |
| 144 | + */ | |
| 145 | + public static String gpsInCarpark(GpsEntity gps){ | |
| 146 | + Point point = new Point(gps.getLon(), gps.getLat()); | |
| 147 | + Map<String, Polygon> carparkMap = GeoCacheData.tccMap; | |
| 148 | + | |
| 149 | + Set<String> codes = carparkMap.keySet(); | |
| 150 | + for(String code : codes){ | |
| 151 | + if(isPointInPolygon(point, carparkMap.get(code))){ | |
| 152 | + return code; | |
| 153 | + } | |
| 154 | + } | |
| 155 | + return null; | |
| 156 | + } | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * 是否在进站前置围栏内 | |
| 160 | + * @param gps | |
| 161 | + * @return | |
| 162 | + */ | |
| 163 | + public static String gpsInPremiseGeo(GpsEntity gps) { | |
| 164 | + List<PreconditionGeo> list = GeoCacheData.premiseGeoMap.get(gps.getLineId()+"_"+gps.getUpDown()); | |
| 165 | + | |
| 166 | + if(null == list || list.size()==0) | |
| 167 | + return null; | |
| 168 | + | |
| 169 | + Point point = new Point(gps.getLon(), gps.getLat()); | |
| 170 | + for(PreconditionGeo p : list){ | |
| 171 | + if(isPointInPolygon(point, p.getPolygon())){ | |
| 172 | + return p.getStationCode(); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + return null; | |
| 176 | + } | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * 是否是有效的连续点 | |
| 180 | + * @param prevGps | |
| 181 | + * @param gps | |
| 182 | + * @return | |
| 183 | + */ | |
| 184 | + public static boolean overdue(GpsEntity prevGps, GpsEntity gps) { | |
| 185 | + return gps.getTimestamp() - prevGps.getTimestamp() < 120000; | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * 计算2条直线的最短距离 | |
| 190 | + * @param p1 | |
| 191 | + * @param p2 | |
| 192 | + * @param p3 | |
| 193 | + * @param p4 | |
| 194 | + * @return | |
| 195 | + */ | |
| 196 | + public static double getDistanceLineToLine(Point p1, Point p2, Point p3, Point p4){ | |
| 197 | + double distance; | |
| 198 | + double x1 = p1.getLat(); //A点坐标(x1,y1,z1) | |
| 199 | + double y1 = p1.getLon(); | |
| 200 | + double z1 = 0; | |
| 201 | + double x2 = p2.getLat(); //B点坐标(x2,y2,z2) | |
| 202 | + double y2 = p2.getLon(); | |
| 203 | + double z2 = 0; | |
| 204 | + double x3 = p3.getLat(); //C点坐标(x3,y3,z3) | |
| 205 | + double y3 = p3.getLon(); | |
| 206 | + double z3 = 0; | |
| 207 | + double x4 = p4.getLat(); //D点坐标(x4,y4,z4) | |
| 208 | + double y4 = p4.getLon(); | |
| 209 | + double z4 = 0; | |
| 210 | + | |
| 211 | + double a = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1); | |
| 212 | + double b = -((x2-x1)*(x4-x3)+(y2-y1)*(y4-y3)+(z2-z1)*(z4-z3)); | |
| 213 | + double c = -((x1-x2)*(x1-x3)+(y1-y2)*(y1-y3)+(z1-z2)*(z1-z3)); | |
| 214 | + | |
| 215 | + double d = -((x2-x1)*(x4-x3)+(y2-y1)*(y4-y3)+(z2-z1)*(z4-z3)); | |
| 216 | + double e = (x4-x3)*(x4-x3)+(y4-y3)*(y4-y3)+(z4-z3)*(z4-z3); | |
| 217 | + double f = -((x1-x3)*(x4-x3)+(y1-y3)*(y4-y3)+(z1-z3)*(z4-z3)); | |
| 218 | + | |
| 219 | + //平行 | |
| 220 | + if ((a*e-b*d)==0&&(b*d-a*e)==0) | |
| 221 | + { | |
| 222 | + double d1 = getDistance(p1, p3); | |
| 223 | + double d2 = getDistance(p1, p4); | |
| 224 | + distance = (d1<d2)?d1:d2; | |
| 225 | + return distance; | |
| 226 | + } | |
| 227 | + | |
| 228 | + double s = (b*f-e*c)/(a*e-b*d); | |
| 229 | + double t = (a*f-d*c)/(b*d-a*e); | |
| 230 | + | |
| 231 | + //说明P点落在线段AB上,Q点落在线段CD上 | |
| 232 | + if(0<=s&&s<=1&&0<=t&&t<=1) | |
| 233 | + { | |
| 234 | + //2条线段的公垂线段PQ; | |
| 235 | + //P点坐标 | |
| 236 | + double X = x1+s*(x2-x1); | |
| 237 | + double Y = y1+s*(y2-y1); | |
| 238 | + double Z = z1+s*(z2-z1); | |
| 239 | + //Q点坐标 | |
| 240 | + double U = x3+t*(x4-x3); | |
| 241 | + double V = y3+t*(y4-y3); | |
| 242 | + double W = z3+t*(z4-z3); | |
| 243 | + | |
| 244 | + Point p = new Point(Y, X); | |
| 245 | + Point q = new Point(V, U); | |
| 246 | + distance = getDistance(p, q); | |
| 247 | + } | |
| 248 | + else | |
| 249 | + { | |
| 250 | + double d1 = getDistanceFromLine(p3,p4,p1); | |
| 251 | + double d2 = getDistanceFromLine(p3,p4,p2); | |
| 252 | + double d3 = getDistanceFromLine(p1,p2,p3); | |
| 253 | + double d4 = getDistanceFromLine(p1,p2,p4); | |
| 254 | + distance = (d1<d2)?d1:d2; | |
| 255 | + distance = (distance<d3)?distance:d3; | |
| 256 | + distance = (distance<d4)?distance:d4; | |
| 257 | + } | |
| 258 | + | |
| 259 | + return distance; | |
| 260 | + } | |
| 261 | + | |
| 262 | + /** | |
| 263 | + * 计算点 到 线的垂直交点 | |
| 264 | + * @param lp1 | |
| 265 | + * @param lp2 | |
| 266 | + * @param p | |
| 267 | + * @return | |
| 268 | + */ | |
| 269 | + public static Point perpendularPoint(Point lp1, Point lp2, Point p){ | |
| 270 | + double a = lp1.getLat() - lp2.getLat(), b = lp2.getLon() - lp1.getLon(), c = lp1.getLon() * lp2.getLat() - lp2.getLon() * lp1.getLat(); | |
| 271 | + double lon = (Math.pow(b, 2) * p.getLon() - a * b * p.getLat() - a * c) / (Math.pow(a, 2) + Math.pow(b, 2)); | |
| 272 | + double lat = (Math.pow(a, 2) * p.getLat() - a * b * p.getLon() - b * c) / (Math.pow(a, 2) + Math.pow(b, 2)); | |
| 273 | + | |
| 274 | + return new Point(lon, lat); | |
| 275 | + } | |
| 276 | + | |
| 277 | + public static boolean isPointInRect(Point point, Bounds bounds) { | |
| 278 | + Point sw = bounds.getSouthWest(); // 西南脚点 | |
| 279 | + Point ne = bounds.getNorthEast(); // 东北脚点 | |
| 280 | + return (point.getLon() >= sw.getLon() && point.getLon() <= ne.getLon() | |
| 281 | + && point.getLat() >= sw.getLat() && point.getLat() <= ne | |
| 282 | + .getLat()); | |
| 283 | + } | |
| 284 | + | |
| 285 | + public static boolean isPointInPolygon(Point point, Polygon polygon) { | |
| 286 | + Bounds polygonBounds = polygon.getBounds(); | |
| 287 | + if (!isPointInRect(point, polygonBounds)) { | |
| 288 | + return false; | |
| 289 | + } | |
| 290 | + | |
| 291 | + List<Point> pts = polygon.getPoints();// 获取多边形点 | |
| 292 | + | |
| 293 | + // 下述代码来源:http://paulbourke.net/geometry/insidepoly/,进行了部分修改 | |
| 294 | + // 基本思想是利用射线法,计算射线与多边形各边的交点,如果是偶数,则点在多边形外,否则 | |
| 295 | + // 在多边形内。还会考虑一些特殊情况,如点在多边形顶点上,点在多边形边上等特殊情况。 | |
| 296 | + | |
| 297 | + int N = pts.size(); | |
| 298 | + boolean boundOrVertex = true; // 如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true | |
| 299 | + int intersectCount = 0;// cross points count of x | |
| 300 | + double precision = 2e-10; // 浮点类型计算时候与0比较时候的容差 | |
| 301 | + Point p1, p2;// neighbour bound vertices | |
| 302 | + Point p = point; // 测试点 | |
| 303 | + | |
| 304 | + p1 = pts.get(0);// left vertex | |
| 305 | + for (int i = 1; i <= N; ++i) {// check all rays | |
| 306 | + if (p.equals(p1)) { | |
| 307 | + return boundOrVertex;// p is an vertex | |
| 308 | + } | |
| 309 | + | |
| 310 | + p2 = pts.get(i % N);// right vertex | |
| 311 | + if (p.getLat() < Math.min(p1.getLat(), p2.getLat()) | |
| 312 | + || p.getLat() > Math.max(p1.getLat(), p2.getLat())) {// ray | |
| 313 | + // is | |
| 314 | + // outside | |
| 315 | + // of | |
| 316 | + // our | |
| 317 | + // interests | |
| 318 | + p1 = p2; | |
| 319 | + continue;// next ray left point | |
| 320 | + } | |
| 321 | + | |
| 322 | + if (p.getLat() > Math.min(p1.getLat(), p2.getLat()) | |
| 323 | + && p.getLat() < Math.max(p1.getLat(), p2.getLat())) {// ray | |
| 324 | + // is | |
| 325 | + // crossing | |
| 326 | + // over | |
| 327 | + // by | |
| 328 | + // the | |
| 329 | + // algorithm | |
| 330 | + // (common | |
| 331 | + // part | |
| 332 | + // of) | |
| 333 | + if (p.getLon() <= Math.max(p1.getLon(), p2.getLon())) {// x is | |
| 334 | + // before | |
| 335 | + // of | |
| 336 | + // ray | |
| 337 | + if (p1.getLat() == p2.getLat() | |
| 338 | + && p.getLon() >= Math.min(p1.getLon(), p2.getLon())) {// overlies | |
| 339 | + // on | |
| 340 | + // a | |
| 341 | + // horizontal | |
| 342 | + // ray | |
| 343 | + return boundOrVertex; | |
| 344 | + } | |
| 345 | + | |
| 346 | + if (p1.getLon() == p2.getLon()) {// ray is vertical | |
| 347 | + if (p1.getLon() == p.getLon()) {// overlies on a | |
| 348 | + // vertical ray | |
| 349 | + return boundOrVertex; | |
| 350 | + } else {// before ray | |
| 351 | + ++intersectCount; | |
| 352 | + } | |
| 353 | + } else {// cross point on the left side | |
| 354 | + double xinters = (p.getLat() - p1.getLat()) | |
| 355 | + * (p2.getLon() - p1.getLon()) | |
| 356 | + / (p2.getLat() - p1.getLat()) + p1.getLon();// cross | |
| 357 | + // point | |
| 358 | + // of | |
| 359 | + // lng | |
| 360 | + if (Math.abs(p.getLon() - xinters) < precision) {// overlies | |
| 361 | + // on | |
| 362 | + // a | |
| 363 | + // ray | |
| 364 | + return boundOrVertex; | |
| 365 | + } | |
| 366 | + | |
| 367 | + if (p.getLon() < xinters) {// before ray | |
| 368 | + ++intersectCount; | |
| 369 | + } | |
| 370 | + } | |
| 371 | + } | |
| 372 | + } else {// special case when ray is crossing through the vertex | |
| 373 | + if (p.getLat() == p2.getLat() && p.getLon() <= p2.getLon()) {// p | |
| 374 | + // crossing | |
| 375 | + // over | |
| 376 | + // p2 | |
| 377 | + Point p3 = pts.get((i + 1) % N); // next vertex | |
| 378 | + if (p.getLat() >= Math.min(p1.getLat(), p3.getLat()) | |
| 379 | + && p.getLat() <= Math.max(p1.getLat(), p3.getLat())) {// p.lat | |
| 380 | + // lies | |
| 381 | + // between | |
| 382 | + // p1.lat | |
| 383 | + // & | |
| 384 | + // p3.lat | |
| 385 | + ++intersectCount; | |
| 386 | + } else { | |
| 387 | + intersectCount += 2; | |
| 388 | + } | |
| 389 | + } | |
| 390 | + } | |
| 391 | + p1 = p2;// next ray left point | |
| 392 | + } | |
| 393 | + | |
| 394 | + if (intersectCount % 2 == 0) {// 偶数在多边形外 | |
| 395 | + return false; | |
| 396 | + } else { // 奇数在多边形内 | |
| 397 | + return true; | |
| 398 | + } | |
| 399 | + } | |
| 400 | + | |
| 401 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java renamed to src/main/java/com/bsth/data/gpsdata_v2/utils/GpsDataRecovery.java
| 1 | -package com.bsth.data.gpsdata.recovery; | |
| 2 | - | |
| 3 | -import com.bsth.data.BasicData; | |
| 4 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | -import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 6 | -import com.bsth.data.gpsdata.arrival.handlers.*; | |
| 7 | -import com.bsth.data.gpsdata.arrival.utils.CircleQueue; | |
| 8 | -import com.bsth.util.db.DBUtils_MS; | |
| 9 | -import com.google.common.collect.ArrayListMultimap; | |
| 10 | -import org.slf4j.Logger; | |
| 11 | -import org.slf4j.LoggerFactory; | |
| 12 | -import org.springframework.beans.BeansException; | |
| 13 | -import org.springframework.context.ApplicationContext; | |
| 14 | -import org.springframework.context.ApplicationContextAware; | |
| 15 | -import org.springframework.jdbc.core.JdbcTemplate; | |
| 16 | -import org.springframework.jdbc.core.RowMapper; | |
| 17 | -import org.springframework.stereotype.Component; | |
| 18 | - | |
| 19 | -import java.sql.ResultSet; | |
| 20 | -import java.sql.SQLException; | |
| 21 | -import java.util.*; | |
| 22 | -import java.util.concurrent.CountDownLatch; | |
| 23 | -import java.util.concurrent.ExecutorService; | |
| 24 | -import java.util.concurrent.Executors; | |
| 25 | - | |
| 26 | -/** | |
| 27 | - * gps数据恢复 | |
| 28 | - * Created by panzhao on 2016/12/24. | |
| 29 | - */ | |
| 30 | -@Component | |
| 31 | -public class GpsDataRecovery implements ApplicationContextAware { | |
| 32 | - | |
| 33 | - static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class); | |
| 34 | - | |
| 35 | - public static boolean run; | |
| 36 | - | |
| 37 | - static ExecutorService threadPool = Executors.newFixedThreadPool(10); | |
| 38 | - | |
| 39 | - static OfflineSignalHandle offlineSignalHandle; | |
| 40 | - static CorrectSignalHandle correctSignalHandle; | |
| 41 | - static StationInsideHandle stationInsideHandle; | |
| 42 | - static InOutStationSignalHandle inOutStationSignalHandle; | |
| 43 | - static ReverseSignalHandle reverseSignalHandle; | |
| 44 | - | |
| 45 | - public void recovery() { | |
| 46 | - List<GpsEntity> list = loadData(); | |
| 47 | - | |
| 48 | - //按线路分组数据 | |
| 49 | - ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create(); | |
| 50 | - for (GpsEntity gps : list) { | |
| 51 | - if (gps.getNbbm() != null) | |
| 52 | - listMap.put(gps.getNbbm(), gps); | |
| 53 | - } | |
| 54 | - | |
| 55 | - | |
| 56 | - Set<String> keys = listMap.keySet(); | |
| 57 | - | |
| 58 | - CountDownLatch count = new CountDownLatch(keys.size()); | |
| 59 | - GpsComp comp = new GpsComp(); | |
| 60 | - for (String nbbm : keys) { | |
| 61 | - Collections.sort(listMap.get(nbbm), comp); | |
| 62 | - threadPool.execute(new RecoveryThread(listMap.get(nbbm), count)); | |
| 63 | - /*if(nbbm.equals("W2H-015")) | |
| 64 | - new RecoveryThread(listMap.get(nbbm), count).run();*/ | |
| 65 | - /*if(lineId.equals("60028")) | |
| 66 | - new RecoveryThread(listMap.get(lineId), count).run();*/ | |
| 67 | - } | |
| 68 | - | |
| 69 | - try { | |
| 70 | - count.await(); | |
| 71 | - run = false; | |
| 72 | - logger.info("数据恢复完成...."); | |
| 73 | - } catch (InterruptedException e) { | |
| 74 | - logger.error("", e); | |
| 75 | - } | |
| 76 | - } | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * 加载当天的gps数据 | |
| 80 | - * | |
| 81 | - * @return | |
| 82 | - */ | |
| 83 | - public List<GpsEntity> loadData() { | |
| 84 | - Calendar calendar = Calendar.getInstance(); | |
| 85 | - int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); | |
| 86 | - | |
| 87 | - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=285";// + dayOfYear; | |
| 88 | - JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 89 | - | |
| 90 | - List<GpsEntity> list = | |
| 91 | - jdbcTemplate.query(sql, new RowMapper<GpsEntity>() { | |
| 92 | - @Override | |
| 93 | - public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 94 | - GpsEntity gps = new GpsEntity(); | |
| 95 | - | |
| 96 | - gps.setDeviceId(rs.getString("DEVICE_ID")); | |
| 97 | - gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 98 | - gps.setSpeed(rs.getFloat("SPEED_GPS")); | |
| 99 | - gps.setLat(rs.getFloat("LAT")); | |
| 100 | - gps.setLon(rs.getFloat("LON")); | |
| 101 | - gps.setLineId(rs.getString("LINE_ID")); | |
| 102 | - gps.setTimestamp(rs.getLong("TS")); | |
| 103 | - gps.setUpDown((byte) getUpOrDown(rs.getLong("SERVICE_STATE"))); | |
| 104 | - return gps; | |
| 105 | - } | |
| 106 | - }); | |
| 107 | - return list; | |
| 108 | - } | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 112 | - * | |
| 113 | - * @return -1无效 0上行 1下行 | |
| 114 | - */ | |
| 115 | - public static int getUpOrDown(long serviceState) { | |
| 116 | - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 117 | - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 118 | - return -1; | |
| 119 | - return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 120 | - } | |
| 121 | - | |
| 122 | - @Override | |
| 123 | - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 124 | - offlineSignalHandle = applicationContext.getBean(OfflineSignalHandle.class); | |
| 125 | - correctSignalHandle = applicationContext.getBean(CorrectSignalHandle.class); | |
| 126 | - stationInsideHandle = applicationContext.getBean(StationInsideHandle.class); | |
| 127 | - inOutStationSignalHandle = applicationContext.getBean(InOutStationSignalHandle.class); | |
| 128 | - reverseSignalHandle = applicationContext.getBean(ReverseSignalHandle.class); | |
| 129 | - } | |
| 130 | - | |
| 131 | - public static class GpsComp implements Comparator<GpsEntity> { | |
| 132 | - | |
| 133 | - @Override | |
| 134 | - public int compare(GpsEntity g1, GpsEntity g2) { | |
| 135 | - return g1.getTimestamp().compareTo(g2.getTimestamp()); | |
| 136 | - } | |
| 137 | - } | |
| 138 | - | |
| 139 | - public static class RecoveryThread implements Runnable { | |
| 140 | - List<GpsEntity> list; | |
| 141 | - CountDownLatch count; | |
| 142 | - | |
| 143 | - RecoveryThread(List<GpsEntity> list, CountDownLatch count) { | |
| 144 | - this.list = list; | |
| 145 | - this.count = count; | |
| 146 | - } | |
| 147 | - | |
| 148 | - @Override | |
| 149 | - public void run() { | |
| 150 | - try { | |
| 151 | - //循环gps恢复数据 | |
| 152 | - CircleQueue<GpsEntity> prevs; | |
| 153 | - boolean task; | |
| 154 | - for (GpsEntity gps : list) { | |
| 155 | - try { | |
| 156 | - /*if(gps.getTimestamp() >= 1506216540000L){ | |
| 157 | - System.out.println("debugger..."); | |
| 158 | - }*/ | |
| 159 | - //是否有任务 | |
| 160 | - | |
| 161 | - prevs = GeoCacheData.getGps(gps.getNbbm()); | |
| 162 | - //掉线处理 | |
| 163 | - offlineSignalHandle.handle(gps, prevs); | |
| 164 | - //状态处理 | |
| 165 | - task = correctSignalHandle.handle(gps, prevs); | |
| 166 | - //场,站内外判断 | |
| 167 | - stationInsideHandle.handle(gps, prevs); | |
| 168 | - //异常判定(越界/超速) | |
| 169 | - //abnormalStateHandle.handle(gps, prevs); | |
| 170 | - | |
| 171 | - if (!task) | |
| 172 | - continue; //无任务的,到这里就结束 | |
| 173 | - | |
| 174 | - //反向处理 | |
| 175 | - reverseSignalHandle.handle(gps, prevs); | |
| 176 | - //进出站动作处理 | |
| 177 | - inOutStationSignalHandle.handle(gps, prevs); | |
| 178 | - GeoCacheData.putGps(gps); | |
| 179 | - } catch (Exception e) { | |
| 180 | - logger.error("", e); | |
| 181 | - } | |
| 182 | - } | |
| 183 | - } finally { | |
| 184 | - count.countDown(); | |
| 185 | - } | |
| 186 | - } | |
| 187 | - } | |
| 1 | +package com.bsth.data.gpsdata_v2.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.BasicData; | |
| 4 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 5 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.handlers.*; | |
| 7 | +import com.bsth.util.db.DBUtils_MS; | |
| 8 | +import com.google.common.collect.ArrayListMultimap; | |
| 9 | +import org.slf4j.Logger; | |
| 10 | +import org.slf4j.LoggerFactory; | |
| 11 | +import org.springframework.beans.BeansException; | |
| 12 | +import org.springframework.context.ApplicationContext; | |
| 13 | +import org.springframework.context.ApplicationContextAware; | |
| 14 | +import org.springframework.jdbc.core.JdbcTemplate; | |
| 15 | +import org.springframework.jdbc.core.RowMapper; | |
| 16 | +import org.springframework.stereotype.Component; | |
| 17 | + | |
| 18 | +import java.sql.ResultSet; | |
| 19 | +import java.sql.SQLException; | |
| 20 | +import java.util.*; | |
| 21 | +import java.util.concurrent.CountDownLatch; | |
| 22 | +import java.util.concurrent.ExecutorService; | |
| 23 | +import java.util.concurrent.Executors; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * gps数据恢复 | |
| 27 | + * Created by panzhao on 2016/12/24. | |
| 28 | + */ | |
| 29 | +@Component | |
| 30 | +public class GpsDataRecovery implements ApplicationContextAware { | |
| 31 | + | |
| 32 | + static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class); | |
| 33 | + | |
| 34 | + public static boolean run; | |
| 35 | + | |
| 36 | + static ExecutorService threadPool = Executors.newFixedThreadPool(10); | |
| 37 | + | |
| 38 | + static GpsStateProcess gpsStateProcess; | |
| 39 | + static StationInsideProcess stationInsideProcess; | |
| 40 | + static InStationProcess inStationProcess; | |
| 41 | + static OutStationProcess outStationProcess; | |
| 42 | + static AbnormalStateProcess abnormalStateProcess; | |
| 43 | + | |
| 44 | + public void recovery() { | |
| 45 | + List<GpsEntity> list = loadData(); | |
| 46 | + | |
| 47 | + //按线路分组数据 | |
| 48 | + ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create(); | |
| 49 | + for (GpsEntity gps : list) { | |
| 50 | + if (gps.getNbbm() != null) | |
| 51 | + listMap.put(gps.getNbbm(), gps); | |
| 52 | + } | |
| 53 | + | |
| 54 | + | |
| 55 | + Set<String> keys = listMap.keySet(); | |
| 56 | + | |
| 57 | + CountDownLatch count = new CountDownLatch(keys.size()); | |
| 58 | + GpsComp comp = new GpsComp(); | |
| 59 | + for (String nbbm : keys) { | |
| 60 | + Collections.sort(listMap.get(nbbm), comp); | |
| 61 | + threadPool.submit(new RecoveryThread(listMap.get(nbbm), count)); | |
| 62 | + /*if(nbbm.equals("W2H-015")) | |
| 63 | + new RecoveryThread(listMap.get(nbbm), count).run();*/ | |
| 64 | + /*if(lineId.equals("60028")) | |
| 65 | + new RecoveryThread(listMap.get(lineId), count).run();*/ | |
| 66 | + } | |
| 67 | + | |
| 68 | + try { | |
| 69 | + count.await(); | |
| 70 | + run = false; | |
| 71 | + logger.info("数据恢复完成...."); | |
| 72 | + } catch (InterruptedException e) { | |
| 73 | + logger.error("", e); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * 加载当天的gps数据 | |
| 79 | + * | |
| 80 | + * @return | |
| 81 | + */ | |
| 82 | + public List<GpsEntity> loadData() { | |
| 83 | + Calendar calendar = Calendar.getInstance(); | |
| 84 | + int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); | |
| 85 | + | |
| 86 | + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear; | |
| 87 | + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 88 | + | |
| 89 | + List<GpsEntity> list = | |
| 90 | + jdbcTemplate.query(sql, new RowMapper<GpsEntity>() { | |
| 91 | + @Override | |
| 92 | + public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 93 | + GpsEntity gps = new GpsEntity(); | |
| 94 | + | |
| 95 | + gps.setDeviceId(rs.getString("DEVICE_ID")); | |
| 96 | + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())); | |
| 97 | + gps.setSpeed(rs.getFloat("SPEED_GPS")); | |
| 98 | + gps.setLat(rs.getFloat("LAT")); | |
| 99 | + gps.setLon(rs.getFloat("LON")); | |
| 100 | + gps.setLineId(rs.getString("LINE_ID")); | |
| 101 | + gps.setTimestamp(rs.getLong("TS")); | |
| 102 | + gps.setUpDown((byte) getUpOrDown(rs.getLong("SERVICE_STATE"))); | |
| 103 | + return gps; | |
| 104 | + } | |
| 105 | + }); | |
| 106 | + return list; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 111 | + * | |
| 112 | + * @return -1无效 0上行 1下行 | |
| 113 | + */ | |
| 114 | + public static int getUpOrDown(long serviceState) { | |
| 115 | + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 116 | + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 117 | + return -1; | |
| 118 | + return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 123 | + gpsStateProcess = applicationContext.getBean(GpsStateProcess.class); | |
| 124 | + stationInsideProcess = applicationContext.getBean(StationInsideProcess.class); | |
| 125 | + inStationProcess = applicationContext.getBean(InStationProcess.class); | |
| 126 | + outStationProcess = applicationContext.getBean(OutStationProcess.class); | |
| 127 | + abnormalStateProcess = applicationContext.getBean(AbnormalStateProcess.class); | |
| 128 | + } | |
| 129 | + | |
| 130 | + public static class GpsComp implements Comparator<GpsEntity> { | |
| 131 | + | |
| 132 | + @Override | |
| 133 | + public int compare(GpsEntity g1, GpsEntity g2) { | |
| 134 | + return g1.getTimestamp().compareTo(g2.getTimestamp()); | |
| 135 | + } | |
| 136 | + } | |
| 137 | + | |
| 138 | + public static class RecoveryThread implements Runnable { | |
| 139 | + List<GpsEntity> list; | |
| 140 | + CountDownLatch count; | |
| 141 | + | |
| 142 | + RecoveryThread(List<GpsEntity> list, CountDownLatch count) { | |
| 143 | + this.list = list; | |
| 144 | + this.count = count; | |
| 145 | + } | |
| 146 | + | |
| 147 | + @Override | |
| 148 | + public void run() { | |
| 149 | + try { | |
| 150 | + //循环gps恢复数据 | |
| 151 | + for (GpsEntity gps : list) { | |
| 152 | + try { | |
| 153 | + | |
| 154 | + gpsStateProcess.process(gps);//状态处理 | |
| 155 | + stationInsideProcess.process(gps);//场站内外判定 | |
| 156 | + | |
| 157 | + | |
| 158 | + abnormalStateProcess.process(gps);//超速越界 | |
| 159 | + | |
| 160 | + inStationProcess.process(gps);//进站 | |
| 161 | + outStationProcess.process(gps);//出站 | |
| 162 | + | |
| 163 | + GpsCacheData.putGps(gps);//历史gps缓存 | |
| 164 | + } catch (Exception e) { | |
| 165 | + logger.error("", e); | |
| 166 | + } | |
| 167 | + } | |
| 168 | + } finally { | |
| 169 | + count.countDown(); | |
| 170 | + } | |
| 171 | + } | |
| 172 | + } | |
| 188 | 173 | } |
| 189 | 174 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/gpsdata_v2/utils/GpsDataUtils.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.utils; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 4 | +import org.slf4j.Logger; | |
| 5 | +import org.slf4j.LoggerFactory; | |
| 6 | + | |
| 7 | +import java.util.ArrayList; | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Created by panzhao on 2017/11/15. | |
| 12 | + */ | |
| 13 | +public class GpsDataUtils { | |
| 14 | + | |
| 15 | + static Logger logger = LoggerFactory.getLogger(GpsDataUtils.class); | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 过滤无效的gps点位 | |
| 19 | + * | |
| 20 | + * @param list | |
| 21 | + * @return | |
| 22 | + */ | |
| 23 | + public static List<GpsEntity> clearInvalid(List<GpsEntity> list) { | |
| 24 | + List<GpsEntity> rs = new ArrayList<>(); | |
| 25 | + | |
| 26 | + try { | |
| 27 | + for (GpsEntity gps : list) { | |
| 28 | + if (gps.getValid() == 0) | |
| 29 | + rs.add(gps); | |
| 30 | + } | |
| 31 | + | |
| 32 | + if (rs.size() < list.size()) | |
| 33 | + logger.info("过滤无效的点位 : " + (list.size() - rs.size())); | |
| 34 | + } catch (Exception e) { | |
| 35 | + logger.error("", e); | |
| 36 | + rs = list; | |
| 37 | + } | |
| 38 | + return rs; | |
| 39 | + } | |
| 40 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/utils/StationRouteComp.java renamed to src/main/java/com/bsth/data/gpsdata_v2/utils/StationRouteComp.java
| 1 | -package com.bsth.data.gpsdata.arrival.utils; | |
| 2 | - | |
| 3 | -import com.bsth.data.gpsdata.arrival.entity.StationRoute; | |
| 4 | - | |
| 5 | -import java.util.Comparator; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * Created by panzhao on 2016/12/24. | |
| 9 | - */ | |
| 10 | -public class StationRouteComp implements Comparator<StationRoute>{ | |
| 11 | - @Override | |
| 12 | - public int compare(StationRoute s1, StationRoute s2) { | |
| 13 | - return s1.getRouteSort() - s2.getRouteSort(); | |
| 14 | - } | |
| 15 | -} | |
| 1 | +package com.bsth.data.gpsdata_v2.utils; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.bsth.data.gpsdata_v2.entity.StationRoute; | |
| 5 | + | |
| 6 | +import java.util.Comparator; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Created by panzhao on 2016/12/24. | |
| 10 | + */ | |
| 11 | +public class StationRouteComp implements Comparator<StationRoute>{ | |
| 12 | + @Override | |
| 13 | + public int compare(StationRoute s1, StationRoute s2) { | |
| 14 | + return s1.getRouteSort() - s2.getRouteSort(); | |
| 15 | + } | |
| 16 | +} | ... | ... |
src/main/java/com/bsth/data/msg_queue/DirectivePushQueue.java
| ... | ... | @@ -29,6 +29,8 @@ public class DirectivePushQueue implements ApplicationContextAware { |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public static void put6002(ScheduleRealInfo sch, int finish, String sender){ |
| 32 | + if(null == sch) | |
| 33 | + return; | |
| 32 | 34 | QueueData_Directive qd6002 = new QueueData_Directive(); |
| 33 | 35 | qd6002.setSch(sch); |
| 34 | 36 | qd6002.setFinish(finish); | ... | ... |
src/main/java/com/bsth/data/pilot80/PilotReport.java
| ... | ... | @@ -2,8 +2,8 @@ package com.bsth.data.pilot80; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.data.BasicData; |
| 4 | 4 | import com.bsth.data.LineConfigData; |
| 5 | -import com.bsth.data.gpsdata.GpsRealData; | |
| 6 | -import com.bsth.data.gpsdata.status_manager.GpsStatusManager; | |
| 5 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 6 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 7 | 7 | import com.bsth.data.msg_queue.DirectivePushQueue; |
| 8 | 8 | import com.bsth.data.schedule.DayOfSchedule; |
| 9 | 9 | import com.bsth.entity.directive.D80; |
| ... | ... | @@ -93,13 +93,13 @@ public class PilotReport { |
| 93 | 93 | break; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - //推送到页面 | |
| 97 | - sendUtils.send80ToPage(d80); | |
| 98 | - | |
| 99 | 96 | //反射搜索用 瞬时字段 |
| 100 | 97 | d80.setLineId(d80.getData().getLineId()); |
| 101 | 98 | d80.setNbbm(d80.getData().getNbbm()); |
| 102 | 99 | d80.setRequestCode(d80.getData().getRequestCode()); |
| 100 | + | |
| 101 | + //推送到页面 | |
| 102 | + sendUtils.send80ToPage(d80); | |
| 103 | 103 | } catch (Exception e) { |
| 104 | 104 | logger.error("", e); |
| 105 | 105 | } |
| ... | ... | @@ -242,6 +242,8 @@ public class PilotReport { |
| 242 | 242 | for (D80 d80 : rems) { |
| 243 | 243 | d80Maps.remove(d80.getId()); |
| 244 | 244 | } |
| 245 | + | |
| 246 | + rems.clear(); | |
| 245 | 247 | logger.info("清除 80数据 after: " + d80Maps.size()); |
| 246 | 248 | } |
| 247 | 249 | } | ... | ... |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -5,8 +5,8 @@ import com.alibaba.fastjson.JSONArray; |
| 5 | 5 | import com.bsth.common.Constants; |
| 6 | 6 | import com.bsth.common.ResponseCode; |
| 7 | 7 | import com.bsth.data.LineConfigData; |
| 8 | -import com.bsth.data.gpsdata.GpsRealData; | |
| 9 | -import com.bsth.data.gpsdata.recovery.GpsDataRecovery; | |
| 8 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 9 | +import com.bsth.data.gpsdata_v2.utils.GpsDataRecovery; | |
| 10 | 10 | import com.bsth.data.schedule.f_a_l.FirstAndLastHandler; |
| 11 | 11 | import com.bsth.entity.realcontrol.LineConfig; |
| 12 | 12 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| ... | ... | @@ -111,8 +111,6 @@ public class DayOfSchedule { |
| 111 | 111 | |
| 112 | 112 | //数据恢复 |
| 113 | 113 | public void dataRecovery() { |
| 114 | - GpsDataRecovery.run = true; | |
| 115 | - | |
| 116 | 114 | Collection<LineConfig> confs = lineConfigs.getAll(); |
| 117 | 115 | String lineCode, currSchDate; |
| 118 | 116 | for (LineConfig conf : confs) { |
| ... | ... | @@ -260,8 +258,8 @@ public class DayOfSchedule { |
| 260 | 258 | public void clearRAMData(String lineCode) { |
| 261 | 259 | int count = 0; |
| 262 | 260 | List<ScheduleRealInfo> remList = new ArrayList<>(); |
| 263 | - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values(); | |
| 264 | - for (ScheduleRealInfo sch : schs) { | |
| 261 | + Collection<ScheduleRealInfo> all = id2SchedulMap.values(); | |
| 262 | + for (ScheduleRealInfo sch : all) { | |
| 265 | 263 | if (sch.getXlBm().equals(lineCode)) |
| 266 | 264 | remList.add(sch); |
| 267 | 265 | } |
| ... | ... | @@ -271,22 +269,19 @@ public class DayOfSchedule { |
| 271 | 269 | nbbmScheduleMap.remove(sch.getClZbh(), sch); |
| 272 | 270 | id2SchedulMap.remove(sch.getId()); |
| 273 | 271 | count++; |
| 274 | - } | |
| 275 | - } | |
| 276 | 272 | |
| 277 | - //清理路牌对照 | |
| 278 | - List<String> lprms = new ArrayList<>(); | |
| 279 | - Set<String> lps = lpScheduleMap.keySet(); | |
| 280 | - for (String lp : lps) { | |
| 281 | - if (lp.startsWith(lineCode + "_")) | |
| 282 | - lprms.add(lp); | |
| 283 | - } | |
| 273 | + //清理路牌对照 | |
| 274 | + lpScheduleMap.removeAll(sch.getXlBm() + "_" + sch.getLpName()); | |
| 284 | 275 | |
| 285 | - for (String lp : lprms){ | |
| 286 | - logger.info("清理路牌映射 " + lp); | |
| 287 | - lpScheduleMap.removeAll(lp); | |
| 276 | + //清除车辆 ——> 执行班次对照 | |
| 277 | + carExecutePlanMap.remove(sch.getClZbh()); | |
| 278 | + } | |
| 288 | 279 | } |
| 280 | + //清理计划排班 | |
| 281 | + schedulePlanMap.remove(lineCode); | |
| 289 | 282 | |
| 283 | + remList.clear(); | |
| 284 | + remList = null; | |
| 290 | 285 | logger.info(lineCode + "排班清理 " + count); |
| 291 | 286 | } |
| 292 | 287 | |
| ... | ... | @@ -512,35 +507,6 @@ public class DayOfSchedule { |
| 512 | 507 | return item.getXlDir().equals(sch.getXlDir()); |
| 513 | 508 | } |
| 514 | 509 | }); |
| 515 | - /*int outConfig = -1; | |
| 516 | - LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 517 | - if (config != null) | |
| 518 | - outConfig = config.getOutConfig(); | |
| 519 | - | |
| 520 | - //限定出站既出场的停车场 | |
| 521 | - String park = config.getTwinsPark(); | |
| 522 | - boolean limitPark = StringUtils.isNotEmpty(park); | |
| 523 | - boolean flag = false; | |
| 524 | - ScheduleRealInfo next = null; | |
| 525 | - for (ScheduleRealInfo temp : list) { | |
| 526 | - if (temp.getId() == sch.getId()) { | |
| 527 | - flag = true; | |
| 528 | - continue; | |
| 529 | - } | |
| 530 | - //忽略烂班 | |
| 531 | - if (temp.isDestroy()) | |
| 532 | - continue; | |
| 533 | - | |
| 534 | - //出站既出场,忽略出场班次 | |
| 535 | - if (outConfig == 2 && temp.getBcType().equals("out") | |
| 536 | - && (!limitPark || park.equals(temp.getQdzCode()))) | |
| 537 | - continue; | |
| 538 | - | |
| 539 | - if (flag && temp.getXlDir().equals(sch.getXlDir())) { | |
| 540 | - next = temp; | |
| 541 | - break; | |
| 542 | - } | |
| 543 | - }*/ | |
| 544 | 510 | return next(subList, sch); |
| 545 | 511 | } |
| 546 | 512 | |
| ... | ... | @@ -724,12 +690,6 @@ public class DayOfSchedule { |
| 724 | 690 | } |
| 725 | 691 | } |
| 726 | 692 | |
| 727 | - | |
| 728 | -/* public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm) { | |
| 729 | - Collections.sort(nbbmScheduleMap.get(nbbm), schFCSJComparator); | |
| 730 | - return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm)); | |
| 731 | - }*/ | |
| 732 | - | |
| 733 | 693 | public List<ScheduleRealInfo> updateQdzTimePlan(String lpName) { |
| 734 | 694 | List<ScheduleRealInfo> list = lpScheduleMap.get(lpName); |
| 735 | 695 | Collections.sort(list, schFCSJComparator); |
| ... | ... | @@ -755,45 +715,6 @@ public class DayOfSchedule { |
| 755 | 715 | return rs; |
| 756 | 716 | } |
| 757 | 717 | |
| 758 | - /** | |
| 759 | - * @Title: prveNotExecNum | |
| 760 | - * @Description: TODO(班次之前未执行班次数量) | |
| 761 | - | |
| 762 | - public int prveNotExecNum(ScheduleRealInfo sch) { | |
| 763 | - int n = 0; | |
| 764 | - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); | |
| 765 | - for (ScheduleRealInfo s : list) { | |
| 766 | - if (s.getFcsjActual() == null && !s.isDestroy()) | |
| 767 | - n++; | |
| 768 | - | |
| 769 | - if (s.getId().equals(sch.getId())) | |
| 770 | - break; | |
| 771 | - } | |
| 772 | - return n; | |
| 773 | - }*/ | |
| 774 | - | |
| 775 | - /** | |
| 776 | - * @Title: validEndTime | |
| 777 | - * @Description: TODO(是否是有效的到达时间) | |
| 778 | - | |
| 779 | - public boolean validEndTime(ScheduleRealInfo sch, Long ts) { | |
| 780 | - if (sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts) | |
| 781 | - return false; | |
| 782 | - | |
| 783 | - return validTime(sch, ts); | |
| 784 | - }*/ | |
| 785 | - | |
| 786 | - /** | |
| 787 | - * @Title: validStartTime | |
| 788 | - * @Description: TODO(是否是合适的发车时间) | |
| 789 | - | |
| 790 | - public boolean validStartTime(ScheduleRealInfo sch, Long ts) { | |
| 791 | - if (sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts) | |
| 792 | - return false; | |
| 793 | - | |
| 794 | - return validTime(sch, ts); | |
| 795 | - }*/ | |
| 796 | - | |
| 797 | 718 | public boolean validTime(ScheduleRealInfo sch, Long ts) { |
| 798 | 719 | List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); |
| 799 | 720 | int ci = list.indexOf(sch); |
| ... | ... | @@ -825,7 +746,6 @@ public class DayOfSchedule { |
| 825 | 746 | } |
| 826 | 747 | |
| 827 | 748 | public void save(ScheduleRealInfo sch) { |
| 828 | - //schRepository.save(sch); | |
| 829 | 749 | sch.setUpdateDate(new Date()); |
| 830 | 750 | pstBuffer.add(sch); |
| 831 | 751 | } |
| ... | ... | @@ -904,10 +824,6 @@ public class DayOfSchedule { |
| 904 | 824 | return outList; |
| 905 | 825 | } |
| 906 | 826 | |
| 907 | -/* public Set<String> allCar() { | |
| 908 | - return nbbmScheduleMap.keySet(); | |
| 909 | - }*/ | |
| 910 | - | |
| 911 | 827 | public Collection<ScheduleRealInfo> findAll() { |
| 912 | 828 | return nbbmScheduleMap.values(); |
| 913 | 829 | } |
| ... | ... | @@ -961,10 +877,6 @@ public class DayOfSchedule { |
| 961 | 877 | nbbmScheduleMap.put(newClZbh, sch); |
| 962 | 878 | } |
| 963 | 879 | |
| 964 | - //重新计算班次应到时间 | |
| 965 | - //ups.addAll(updateQdzTimePlan(oldClzbh)); | |
| 966 | - //ups.addAll(updateQdzTimePlan(newClZbh)); | |
| 967 | - | |
| 968 | 880 | //重新计算车辆当前执行班次 |
| 969 | 881 | reCalcExecPlan(newClZbh); |
| 970 | 882 | reCalcExecPlan(sch.getClZbh()); |
| ... | ... | @@ -986,50 +898,6 @@ public class DayOfSchedule { |
| 986 | 898 | |
| 987 | 899 | ScheduleRealInfo sch = schAttrCalculator.calcCurrentExecSch(list); |
| 988 | 900 | carExecutePlanMap.put(nbbm, sch); |
| 989 | - | |
| 990 | - | |
| 991 | - /* try{ | |
| 992 | - GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); | |
| 993 | - if (gps == null || !gps.isOnline()) | |
| 994 | - return;//设备不在线 | |
| 995 | - | |
| 996 | - *//*if(sch == null && gps.isService()) | |
| 997 | - DirectivePushQueue.put6003(nbbm, 1, 0, null, "系统");//无任务*//* | |
| 998 | - | |
| 999 | - //String bcType = sch.getBcType(); | |
| 1000 | - *//*if(bcType.equals("normal") | |
| 1001 | - || bcType.equals("region") | |
| 1002 | - || bcType.equals("major")){ | |
| 1003 | - //全程、区间、放站,切换到营运状态 | |
| 1004 | - if(!gps.isService()){ | |
| 1005 | - DirectivePushQueue.put6003(nbbm, 0, Integer.parseInt(sch.getXlDir()), sch, "系统"); | |
| 1006 | - } | |
| 1007 | - } | |
| 1008 | - else if(gps.isService()){ | |
| 1009 | - DirectivePushQueue.put6003(nbbm, 1, 0, null, "系统");//空驶任务 | |
| 1010 | - }*//* | |
| 1011 | - }catch (Exception e){ | |
| 1012 | - logger.error("", e); | |
| 1013 | - } | |
| 1014 | - *//*try { | |
| 1015 | - //切换设备状态 | |
| 1016 | - GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); | |
| 1017 | - if (gps == null || !gps.isOnline()) | |
| 1018 | - return; | |
| 1019 | - if (sch == null) { | |
| 1020 | - logger.info("车辆" + nbbm + "无可执行任务,切换至非营运状态"); | |
| 1021 | - DirectivePushQueue.put6003(nbbm, 1, 0, null, "系统"); | |
| 1022 | - return; | |
| 1023 | - } | |
| 1024 | - | |
| 1025 | - if (StringUtils.isNotEmpty(gps.getLineId()) && !gps.getLineId().equals(sch.getXlBm())) { | |
| 1026 | - //下发线路切换指令 | |
| 1027 | - DirectivePushQueue.put64(nbbm, sch.getXlBm(), "系统"); | |
| 1028 | - logger.info("车辆" + nbbm + "切换至" + sch.getXlBm() + " -原" + gps.getLineId() + " --重新计算当前执行班次!"); | |
| 1029 | - } | |
| 1030 | - } catch (Exception e) { | |
| 1031 | - logger.error("", e); | |
| 1032 | - }*/ | |
| 1033 | 901 | } |
| 1034 | 902 | |
| 1035 | 903 | /** |
| ... | ... | @@ -1043,30 +911,6 @@ public class DayOfSchedule { |
| 1043 | 911 | return type.equals("out") || type.equals("in") || type.equals("venting") || type.equals("ldks"); |
| 1044 | 912 | } |
| 1045 | 913 | |
| 1046 | - /** | |
| 1047 | - * 是否在执行首班出场 | |
| 1048 | - * | |
| 1049 | - * @param nbbm | |
| 1050 | - * @return | |
| 1051 | - | |
| 1052 | - public boolean isExecFirstOut(String nbbm, long time) { | |
| 1053 | - try { | |
| 1054 | - List<ScheduleRealInfo> list = nbbmScheduleMap.get(nbbm); | |
| 1055 | - ScheduleRealInfo second = list.get(2), | |
| 1056 | - first = executeCurr(nbbm); | |
| 1057 | - | |
| 1058 | - if (first.getBcType().equals("out") | |
| 1059 | - && first.getDfsjT() < second.getDfsjT() | |
| 1060 | - && doneSum(nbbm) == 0 && second.getDfsjT() > time) | |
| 1061 | - return true; | |
| 1062 | - } catch (Exception e) { | |
| 1063 | - logger.error("", e); | |
| 1064 | - } | |
| 1065 | - | |
| 1066 | - return false; | |
| 1067 | - }*/ | |
| 1068 | - | |
| 1069 | - | |
| 1070 | 914 | @Autowired |
| 1071 | 915 | JdbcTemplate jdbcTemplate; |
| 1072 | 916 | ... | ... |
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
| ... | ... | @@ -208,7 +208,7 @@ public class SchAttrCalculator { |
| 208 | 208 | public ScheduleRealInfo calcCurrentExecSch(List<ScheduleRealInfo> list) { |
| 209 | 209 | String lineCode = list.get(0).getXlBm(); |
| 210 | 210 | LineConfig conf = lineConfigData.get(lineCode); |
| 211 | - long t = System.currentTimeMillis(); | |
| 211 | + | |
| 212 | 212 | int outConfig = -1; |
| 213 | 213 | //限定出站既出场的停车场 |
| 214 | 214 | String park = null; |
| ... | ... | @@ -218,7 +218,10 @@ public class SchAttrCalculator { |
| 218 | 218 | } |
| 219 | 219 | boolean limitPark = StringUtils.isNotEmpty(park); |
| 220 | 220 | |
| 221 | - for (ScheduleRealInfo sch : list) { | |
| 221 | + ScheduleRealInfo sch, prev = null; | |
| 222 | + for(int i = list.size() - 1; i > 0; i --){ | |
| 223 | + sch = list.get(i); | |
| 224 | + | |
| 222 | 225 | //如果是出站既出场,忽略出场班次 |
| 223 | 226 | if (outConfig == 2 && sch.getBcType().equals("out") |
| 224 | 227 | && (!limitPark || park.equals(sch.getQdzCode())) |
| ... | ... | @@ -229,81 +232,11 @@ public class SchAttrCalculator { |
| 229 | 232 | if (sch.isDestroy()) |
| 230 | 233 | continue; |
| 231 | 234 | |
| 232 | - //已执行 | |
| 233 | 235 | if (StringUtils.isNotEmpty(sch.getZdsjActual())) |
| 234 | - continue; | |
| 235 | - | |
| 236 | - if (Math.abs((t - sch.getDfsjT())) > 1000 * 60 * 60) { | |
| 237 | - //差值较大,倒着找看有没有更合适的 | |
| 238 | - ScheduleRealInfo schReverse = calcCurrentExecSchReverse(list, outConfig, limitPark, park); | |
| 239 | - if (null != schReverse && !schReverse.getId().equals(sch.getId())) { | |
| 240 | - logger.info("calc_current_exec_sch_reverse... -" + schReverse.getId()); | |
| 241 | - return suitableExecSch(schReverse, sch, t); | |
| 242 | - } | |
| 243 | - } | |
| 244 | - return sch; | |
| 245 | - } | |
| 246 | - return null; | |
| 247 | - } | |
| 248 | - | |
| 249 | - /** | |
| 250 | - * 反转匹配一个班次 | |
| 251 | - * | |
| 252 | - * @param list | |
| 253 | - * @param outConfig | |
| 254 | - * @param limitPark | |
| 255 | - * @param park | |
| 256 | - * @return | |
| 257 | - */ | |
| 258 | - private ScheduleRealInfo calcCurrentExecSchReverse(List<ScheduleRealInfo> list, int outConfig, boolean limitPark, String park) { | |
| 259 | - ScheduleRealInfo near = null; | |
| 260 | - for (ScheduleRealInfo sch : list) { | |
| 261 | - //如果是出站既出场,忽略出场班次 | |
| 262 | - if (outConfig == 2 && isInout(sch) | |
| 263 | - && (!limitPark || park.equals(sch.getQdzCode()) || park.equals(sch.getZdzCode())) | |
| 264 | - && (sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0)) | |
| 265 | - continue; | |
| 266 | - | |
| 267 | - //忽略烂班 | |
| 268 | - if (sch.isDestroy()) | |
| 269 | - continue; | |
| 270 | - | |
| 271 | - if (StringUtils.isNotEmpty(sch.getZdsjActual())) { | |
| 272 | - near = null; | |
| 273 | - continue; | |
| 274 | - } | |
| 236 | + break; | |
| 275 | 237 | |
| 276 | - if (null == near) | |
| 277 | - near = sch; | |
| 238 | + prev = sch; | |
| 278 | 239 | } |
| 279 | - return near; | |
| 280 | - } | |
| 281 | - | |
| 282 | - /** | |
| 283 | - * 比较2个班次,谁是指定时间更合适执行的 | |
| 284 | - * | |
| 285 | - * @param schReverse | |
| 286 | - * @param sch | |
| 287 | - * @param t | |
| 288 | - * @return | |
| 289 | - */ | |
| 290 | - private ScheduleRealInfo suitableExecSch(ScheduleRealInfo schReverse, ScheduleRealInfo sch, long t) { | |
| 291 | - return Math.abs(t - schReverse.getDfsjT()) > Math.abs(t - sch.getDfsjT()) ? sch : schReverse; | |
| 292 | - } | |
| 293 | - | |
| 294 | - private boolean isInout(ScheduleRealInfo sch) { | |
| 295 | - return sch.getBcType().equals("out") || sch.getBcType().equals("in"); | |
| 296 | - } | |
| 297 | - | |
| 298 | - /** | |
| 299 | - * | |
| 300 | - * @param fcsjT | |
| 301 | - * @param zdsjT | |
| 302 | - */ | |
| 303 | - public boolean isValid(Long fcsjT, Long zdsjT) { | |
| 304 | - if(null != fcsjT && null != zdsjT) | |
| 305 | - return fcsjT < zdsjT; | |
| 306 | - | |
| 307 | - return true; | |
| 240 | + return prev; | |
| 308 | 241 | } |
| 309 | 242 | } | ... | ... |
src/main/java/com/bsth/data/schedule/auto_exec/RealScheduleAutoExecHandler.java
| 1 | 1 | package com.bsth.data.schedule.auto_exec; |
| 2 | 2 | |
| 3 | -import com.bsth.data.gpsdata.status_manager.GpsStatusManager; | |
| 3 | +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager; | |
| 4 | 4 | import com.bsth.data.schedule.DayOfSchedule; |
| 5 | 5 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 6 | 6 | import com.bsth.websocket.handler.SendUtils; | ... | ... |
src/main/java/com/bsth/data/schedule/late_adjust/LateAdjustHandle.java
| ... | ... | @@ -3,7 +3,7 @@ package com.bsth.data.schedule.late_adjust; |
| 3 | 3 | |
| 4 | 4 | import com.bsth.data.BasicData; |
| 5 | 5 | import com.bsth.data.LineConfigData; |
| 6 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 7 | 7 | import com.bsth.entity.realcontrol.LineConfig; |
| 8 | 8 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 9 | 9 | import com.bsth.util.Arith; | ... | ... |
src/main/java/com/bsth/data/schedule/thread/ScheduleRefreshThread.java
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
| ... | ... | @@ -7,8 +7,8 @@ import com.bsth.data.BasicData; |
| 7 | 7 | import com.bsth.data.directive.DayOfDirectives; |
| 8 | 8 | import com.bsth.data.directive.DirectiveCreator; |
| 9 | 9 | import com.bsth.data.directive.GatewayHttpUtils; |
| 10 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 11 | -import com.bsth.data.gpsdata.GpsRealData; | |
| 10 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 11 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 12 | 12 | import com.bsth.data.pilot80.PilotReport; |
| 13 | 13 | import com.bsth.data.schedule.DayOfSchedule; |
| 14 | 14 | import com.bsth.data.utils.ListFilterUtils; | ... | ... |
src/main/java/com/bsth/service/gps/GpsService.java
| 1 | 1 | package com.bsth.service.gps; |
| 2 | 2 | |
| 3 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | 3 | import com.bsth.service.gps.entity.GpsOutbound_DTO; |
| 5 | 4 | import com.bsth.service.gps.entity.GpsSpeed; |
| 6 | 5 | import com.bsth.service.gps.entity.GpsSpeed_DTO; |
| 7 | -import com.bsth.util.PageObject; | |
| 8 | 6 | |
| 9 | 7 | import javax.servlet.http.HttpServletResponse; |
| 10 | - | |
| 11 | 8 | import java.text.ParseException; |
| 12 | 9 | import java.util.List; |
| 13 | 10 | import java.util.Map; | ... | ... |
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
| ... | ... | @@ -3,10 +3,10 @@ package com.bsth.service.gps; |
| 3 | 3 | import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.data.BasicData; |
| 5 | 5 | import com.bsth.data.forecast.entity.ArrivalEntity; |
| 6 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 7 | -import com.bsth.data.gpsdata.GpsRealData; | |
| 8 | -import com.bsth.data.gpsdata.arrival.GeoCacheData; | |
| 9 | -import com.bsth.data.gpsdata.arrival.utils.GeoUtils; | |
| 6 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 7 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 8 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 9 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 10 | 10 | import com.bsth.data.safe_driv.SafeDriv; |
| 11 | 11 | import com.bsth.data.safe_driv.SafeDrivCenter; |
| 12 | 12 | import com.bsth.data.schedule.DayOfSchedule; | ... | ... |
src/main/java/com/bsth/service/gps/entity/HistoryGps_DTO.java
| ... | ... | @@ -3,10 +3,8 @@ package com.bsth.service.gps.entity; |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | 5 | import com.bsth.data.forecast.entity.ArrivalEntity; |
| 6 | +import com.bsth.util.Geo.Point; | |
| 6 | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 7 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 8 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 9 | -import com.vividsolutions.jts.geom.Point; | |
| 10 | 8 | |
| 11 | 9 | import java.util.List; |
| 12 | 10 | import java.util.Map; |
| ... | ... | @@ -20,10 +18,9 @@ public class HistoryGps_DTO { |
| 20 | 18 | public static List<HistoryGps_DTO> craete(List<Map<String, Object>> mapList) { |
| 21 | 19 | List<HistoryGps_DTO> list = JSONObject.parseArray(JSON.toJSONString(mapList), HistoryGps_DTO.class); |
| 22 | 20 | |
| 23 | - GeometryFactory geometryFactory = new GeometryFactory(); | |
| 24 | 21 | Point point; |
| 25 | 22 | for (HistoryGps_DTO gps : list) { |
| 26 | - point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 23 | + point = new Point(gps.getLon(), gps.getLat()); | |
| 27 | 24 | gps.setPoint(point); |
| 28 | 25 | } |
| 29 | 26 | return list; | ... | ... |
src/main/java/com/bsth/service/gps/entity/HistoryGps_DTOV3.java
| ... | ... | @@ -3,10 +3,8 @@ package com.bsth.service.gps.entity; |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | 5 | import com.bsth.data.forecast.entity.ArrivalEntity; |
| 6 | +import com.bsth.util.Geo.Point; | |
| 6 | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 7 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 8 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 9 | -import com.vividsolutions.jts.geom.Point; | |
| 10 | 8 | |
| 11 | 9 | import java.util.List; |
| 12 | 10 | import java.util.Map; |
| ... | ... | @@ -20,10 +18,9 @@ public class HistoryGps_DTOV3 { |
| 20 | 18 | public static List<HistoryGps_DTOV3> craete(List<Map<String, Object>> mapList) { |
| 21 | 19 | List<HistoryGps_DTOV3> list = JSONObject.parseArray(JSON.toJSONString(mapList), HistoryGps_DTOV3.class); |
| 22 | 20 | |
| 23 | - GeometryFactory geometryFactory = new GeometryFactory(); | |
| 24 | 21 | Point point; |
| 25 | 22 | for (HistoryGps_DTOV3 gps : list) { |
| 26 | - point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); | |
| 23 | + point = new Point(gps.getLon(), gps.getLat()); | |
| 27 | 24 | gps.setPoint(point); |
| 28 | 25 | } |
| 29 | 26 | return list; | ... | ... |
src/main/java/com/bsth/service/gps/entity/Road_DTO.java
| ... | ... | @@ -2,10 +2,9 @@ package com.bsth.service.gps.entity; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONObject; |
| 5 | +import com.bsth.data.gpsdata_v2.entity.CtLineString; | |
| 6 | +import com.bsth.util.Geo.Point; | |
| 5 | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 6 | -import com.vividsolutions.jts.geom.Coordinate; | |
| 7 | -import com.vividsolutions.jts.geom.GeometryFactory; | |
| 8 | -import com.vividsolutions.jts.geom.LineString; | |
| 9 | 8 | |
| 10 | 9 | import java.util.ArrayList; |
| 11 | 10 | import java.util.List; |
| ... | ... | @@ -24,9 +23,9 @@ public class Road_DTO { |
| 24 | 23 | String[] coords; |
| 25 | 24 | int i, len; |
| 26 | 25 | String[] temps;//1, temps2; |
| 27 | - List<Coordinate> cds; | |
| 26 | + List<Point> cds; | |
| 28 | 27 | |
| 29 | - GeometryFactory geometryFactory = new GeometryFactory(); | |
| 28 | + //GeometryFactory geometryFactory = new GeometryFactory(); | |
| 30 | 29 | for(Road_DTO road : list){ |
| 31 | 30 | polygonStr = road.getGROAD_VECTOR(); |
| 32 | 31 | coords = polygonStr.substring(11, polygonStr.length() - 1).split(","); |
| ... | ... | @@ -36,11 +35,10 @@ public class Road_DTO { |
| 36 | 35 | //每2个点连一条线 |
| 37 | 36 | for(i = 0; i < len; i ++){ |
| 38 | 37 | temps = coords[i].split(" "); |
| 39 | - cds.add(new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0]))); | |
| 38 | + cds.add(new Point(Float.parseFloat(temps[0]), Float.parseFloat(temps[1]))); | |
| 40 | 39 | } |
| 41 | 40 | |
| 42 | - Coordinate[] cdsArray = new Coordinate[cds.size()]; | |
| 43 | - road.setLineStr(geometryFactory.createLineString(cds.toArray(cdsArray))); | |
| 41 | + road.setLineStr(new CtLineString(cds)); | |
| 44 | 42 | } |
| 45 | 43 | return list; |
| 46 | 44 | } |
| ... | ... | @@ -57,7 +55,7 @@ public class Road_DTO { |
| 57 | 55 | private double SPEED; |
| 58 | 56 | |
| 59 | 57 | @JsonIgnore |
| 60 | - private LineString lineStr; | |
| 58 | + private CtLineString lineStr; | |
| 61 | 59 | |
| 62 | 60 | public long getID() { |
| 63 | 61 | return ID; |
| ... | ... | @@ -99,11 +97,12 @@ public class Road_DTO { |
| 99 | 97 | this.SPEED = SPEED; |
| 100 | 98 | } |
| 101 | 99 | |
| 102 | - public LineString getLineStr() { | |
| 100 | + | |
| 101 | + public CtLineString getLineStr() { | |
| 103 | 102 | return lineStr; |
| 104 | 103 | } |
| 105 | 104 | |
| 106 | - public void setLineStr(LineString lineStr) { | |
| 105 | + public void setLineStr(CtLineString lineStr) { | |
| 107 | 106 | this.lineStr = lineStr; |
| 108 | 107 | } |
| 109 | 108 | } | ... | ... |
src/main/java/com/bsth/service/realcontrol/impl/RealMapServiceImpl.java
| ... | ... | @@ -2,15 +2,12 @@ package com.bsth.service.realcontrol.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.common.ResponseCode; |
| 4 | 4 | import com.bsth.controller.realcontrol.dto.StationSpatialData; |
| 5 | -import com.bsth.data.gpsdata.arrival.utils.GeoUtils; | |
| 6 | 5 | import com.bsth.entity.CarPark; |
| 7 | 6 | import com.bsth.service.realcontrol.RealMapService; |
| 8 | 7 | import com.bsth.service.realcontrol.dto.SectionRouteCoords; |
| 9 | 8 | import com.bsth.util.TransGPS; |
| 10 | -import com.google.common.base.Joiner; | |
| 11 | 9 | import com.google.common.base.Splitter; |
| 12 | 10 | import com.google.common.collect.ArrayListMultimap; |
| 13 | -import com.vividsolutions.jts.geom.*; | |
| 14 | 11 | import org.slf4j.Logger; |
| 15 | 12 | import org.slf4j.LoggerFactory; |
| 16 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -250,171 +247,4 @@ public class RealMapServiceImpl implements RealMapService { |
| 250 | 247 | } |
| 251 | 248 | return gcjList; |
| 252 | 249 | } |
| 253 | - | |
| 254 | - /** | |
| 255 | - * 将相连的路段拼接起来,去掉接口覆盖区域。 | |
| 256 | - * 主要因为前端地图绘制时,过多的路段会带来性能消耗。在这里提前拼接好以减少路段数量 | |
| 257 | - * @param list | |
| 258 | - * @return | |
| 259 | - */ | |
| 260 | - private List<String> jointCoords(List<String> list){ | |
| 261 | - List<String> rs = new ArrayList<>(); | |
| 262 | - int len = list.size(); | |
| 263 | - if(len == 0) | |
| 264 | - return rs; | |
| 265 | - | |
| 266 | - String joinstr = list.get(0); | |
| 267 | - String str; | |
| 268 | - for(int i = 1; i < len; i ++){ | |
| 269 | - str = jointCoords(joinstr.toString(), list.get(i)); | |
| 270 | - if(str != null) | |
| 271 | - joinstr = str; | |
| 272 | - else{ | |
| 273 | - rs.add(joinstr.toString()); | |
| 274 | - joinstr = list.get(i); | |
| 275 | - } | |
| 276 | - } | |
| 277 | - rs.add(joinstr); | |
| 278 | - return rs; | |
| 279 | - } | |
| 280 | - | |
| 281 | - static GeometryFactory geometryFactory = new GeometryFactory(); | |
| 282 | - private String jointCoords(String c1, String c2){ | |
| 283 | - String rs=null; | |
| 284 | - LineString s1 = createLineString(c1); | |
| 285 | - LineString s2 = createLineString(c2); | |
| 286 | - | |
| 287 | - | |
| 288 | - /*if(s1.intersects(s2)){ | |
| 289 | - //2条线相交 | |
| 290 | - Geometry g = s1.intersection(s2); | |
| 291 | - Point inPoint = geometryFactory.createPoint(g.getCoordinates()[0]); | |
| 292 | - //s1 = replacePoint(s1, s1.getCoordinates().length - 1, inPoint); | |
| 293 | - //s2 = replacePoint(s2, 0, inPoint); | |
| 294 | - | |
| 295 | - //rs = toString(s1); | |
| 296 | - //rs += ("," + toString(s2)); | |
| 297 | - rs = replacePoint(c1, s1.getCoordinates().length - 1, inPoint); | |
| 298 | - rs += ("," + replacePoint(c2, 0, null)); | |
| 299 | - } | |
| 300 | - else {*/ | |
| 301 | - //距离10米内的点直接连起来 | |
| 302 | - double distance = GeoUtils.getDistanceLineToLine(s1.getStartPoint(), s1.getEndPoint(), s2.getStartPoint(), s2.getEndPoint()); | |
| 303 | - if(distance < 10){ | |
| 304 | - //s2 = replacePoint(s2, 0, s1.getEndPoint()); | |
| 305 | - rs = c1; | |
| 306 | - | |
| 307 | - //获取c1终点到 c2 的垂直交点 | |
| 308 | - //s1.getEndPoint() | |
| 309 | - //rs += ("," + replacePoint(c2, 0, null)); | |
| 310 | - //rs = toString(s1); | |
| 311 | - //rs += ("," + toString(s2)); | |
| 312 | - } | |
| 313 | - //} | |
| 314 | - return rs; | |
| 315 | - } | |
| 316 | - | |
| 317 | - /** | |
| 318 | - * 替换线段中指定的一个点位 | |
| 319 | - * @param index | |
| 320 | - * @param p | |
| 321 | - | |
| 322 | - private LineString replacePoint(LineString line, int index, Point p){ | |
| 323 | - Coordinate[] array = line.getCoordinates(); | |
| 324 | - array[index] = p.getCoordinate(); | |
| 325 | - | |
| 326 | - return geometryFactory.createLineString(array); | |
| 327 | - }*/ | |
| 328 | - | |
| 329 | - private String replacePoint(String lineStr, int index, Point p){ | |
| 330 | - List<String> list = new ArrayList<>(Splitter.on(",").splitToList(lineStr)); | |
| 331 | - list.remove(index); | |
| 332 | - if(p != null){ | |
| 333 | - list.add(index, p.getX() + " " + p.getY()); | |
| 334 | - } | |
| 335 | - return Joiner.on(",").join(list); | |
| 336 | - } | |
| 337 | - | |
| 338 | - private LineString createLineString(String c){ | |
| 339 | - List<String> list = Splitter.on(",").splitToList(c); | |
| 340 | - | |
| 341 | - Coordinate[] cds = new Coordinate[list.size()]; | |
| 342 | - String[] strs; | |
| 343 | - for(int i = 0; i < list.size(); i ++){ | |
| 344 | - strs = list.get(i).split(" "); | |
| 345 | - cds[i] = new Coordinate(Float.parseFloat(strs[1]), Float.parseFloat(strs[0])); | |
| 346 | - } | |
| 347 | - return geometryFactory.createLineString(cds); | |
| 348 | - } | |
| 349 | - | |
| 350 | - private String toString(LineString line){ | |
| 351 | - Coordinate[] all = line.getCoordinates(); | |
| 352 | - | |
| 353 | - Coordinate[] cs; | |
| 354 | - StringBuilder sb = new StringBuilder(""); | |
| 355 | - for(int i = 0; i < all.length - 1; i ++){ | |
| 356 | - cs = new Coordinate[2]; | |
| 357 | - cs[0] = all[i]; | |
| 358 | - cs[1] = all[i + 1]; | |
| 359 | - | |
| 360 | - sb.append("," + cs[0].y + " " + cs[0].x); | |
| 361 | - sb.append("," + cs[1].y + " " + cs[1].x); | |
| 362 | - } | |
| 363 | - sb.deleteCharAt(0); | |
| 364 | - return sb.toString(); | |
| 365 | - } | |
| 366 | - | |
| 367 | -/* private String truncationEnd(LineString lineString, Point p){ | |
| 368 | - Coordinate[] all = lineString.getCoordinates(); | |
| 369 | - LineString sl; | |
| 370 | - | |
| 371 | - Coordinate[] cs; | |
| 372 | - StringBuilder sb = new StringBuilder(""); | |
| 373 | - double threshold = 0.1,distance; | |
| 374 | - for(int i = 0; i < all.length - 1; i ++){ | |
| 375 | - cs = new Coordinate[2]; | |
| 376 | - cs[0] = all[i]; | |
| 377 | - cs[1] = all[i + 1]; | |
| 378 | - sl = geometryFactory.createLineString(cs); | |
| 379 | - | |
| 380 | - sb.append("," + cs[0].y + " " + cs[0].x); | |
| 381 | - distance = GeoUtils.getDistanceFromLine(sl, p); | |
| 382 | - if(distance < threshold){ | |
| 383 | - sb.append("," + p.getY() + " " + p.getX()); | |
| 384 | - break; | |
| 385 | - } | |
| 386 | - else | |
| 387 | - sb.append("," + cs[1].y + " " + cs[1].x); | |
| 388 | - } | |
| 389 | - sb.deleteCharAt(0); | |
| 390 | - return sb.toString(); | |
| 391 | - } | |
| 392 | - | |
| 393 | - private String truncationStart(LineString lineString, Point p){ | |
| 394 | - Coordinate[] all = lineString.getCoordinates(); | |
| 395 | - LineString sl; | |
| 396 | - | |
| 397 | - Coordinate[] cs; | |
| 398 | - StringBuilder sb = new StringBuilder(""); | |
| 399 | - double threshold = 0.1,distance; | |
| 400 | - for(int i = 0; i < all.length - 1; i ++){ | |
| 401 | - cs = new Coordinate[2]; | |
| 402 | - cs[0] = all[i]; | |
| 403 | - cs[1] = all[i + 1]; | |
| 404 | - sl = geometryFactory.createLineString(cs); | |
| 405 | - | |
| 406 | - distance = GeoUtils.getDistanceFromLine(sl, p); | |
| 407 | - if(distance < threshold){ | |
| 408 | - sb.append("," + p.getY() + " " + p.getX()); | |
| 409 | - sb.append("," + cs[1].y + " " + cs[1].x); | |
| 410 | - break; | |
| 411 | - } | |
| 412 | - else{ | |
| 413 | - sb.append("," + cs[0].y + " " + cs[0].x); | |
| 414 | - sb.append("," + cs[1].y + " " + cs[1].x); | |
| 415 | - } | |
| 416 | - } | |
| 417 | - sb.deleteCharAt(0); | |
| 418 | - return sb.toString(); | |
| 419 | - }*/ | |
| 420 | 250 | } | ... | ... |
src/main/java/com/bsth/websocket/handler/SendUtils.java
| ... | ... | @@ -3,8 +3,7 @@ package com.bsth.websocket.handler; |
| 3 | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.bsth.data.BasicData; |
| 5 | 5 | import com.bsth.data.LineConfigData; |
| 6 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 7 | -import com.bsth.data.gpsdata.arrival.entity.SignalState; | |
| 6 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 8 | 7 | import com.bsth.data.safe_driv.SafeDriv; |
| 9 | 8 | import com.bsth.entity.directive.D80; |
| 10 | 9 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| ... | ... | @@ -81,8 +80,6 @@ public class SendUtils{ |
| 81 | 80 | * TODO(推送到达终点时间) @param @param schedule 班次 @throws |
| 82 | 81 | */ |
| 83 | 82 | public void sendZdsj(ScheduleRealInfo sch, ScheduleRealInfo nextSch, int finish) { |
| 84 | - //处理进站即进场的班次 | |
| 85 | - //connectInSchTime(sch); | |
| 86 | 83 | |
| 87 | 84 | Map<String, Object> map = new HashMap<>(); |
| 88 | 85 | map.put("fn", "zhongDian"); |
| ... | ... | @@ -103,7 +100,7 @@ public class SendUtils{ |
| 103 | 100 | /** |
| 104 | 101 | * 推送班次信号状态 |
| 105 | 102 | * @param state |
| 106 | - */ | |
| 103 | + | |
| 107 | 104 | public void sendSignalState(SignalState state){ |
| 108 | 105 | Map<String, Object> map = new HashMap<>(); |
| 109 | 106 | map.put("fn", "signal_state"); |
| ... | ... | @@ -116,7 +113,7 @@ public class SendUtils{ |
| 116 | 113 | } catch (Exception e) { |
| 117 | 114 | logger.error("", e); |
| 118 | 115 | } |
| 119 | - } | |
| 116 | + }*/ | |
| 120 | 117 | |
| 121 | 118 | /** |
| 122 | 119 | * | ... | ... |
src/main/resources/static/real_control_v2/mapmonitor/fragments/map_infowindow.html
| ... | ... | @@ -38,6 +38,7 @@ |
| 38 | 38 | {{if expectStopTime!=null}} |
| 39 | 39 | <a href="javascript:;" style="color: #07D;margin-right: 7px;">预计 {{expectStopTime}} 分钟到达终点</a> |
| 40 | 40 | {{/if}} |
| 41 | + <a href="javascript:;" style="float: left;" onclick="javascript:window.open('http://180.166.5.82:9005/transport_server/dvr_monitor1.jsp?userid=4&deviceid={{deviceId}}');">DVR</a> | |
| 41 | 42 | <a href="javascript:;" style="float: right;" onclick="javascript:gb_map_play_back.initParams('{{deviceId}}', '{{nbbm}}');">轨迹回放</a> |
| 42 | 43 | </div> |
| 43 | 44 | </script> | ... | ... |