Commit cb88db97c73ca6565c7e74e513be94fac82ac40c

Authored by 徐烜
2 parents 3e44b0ca f06e882a

Update

Showing 47 changed files with 1284 additions and 2894 deletions

Too many changes to show.

To preserve performance only 47 of 216 files are displayed.

... ... @@ -250,15 +250,6 @@
250 250 <version>1.7.4</version>
251 251 </dependency>
252 252  
253   -
254   - <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId>
255   - <optional>true</optional> </dependency> -->
256   - <dependency>
257   - <groupId>com.vividsolutions</groupId>
258   - <artifactId>jts</artifactId>
259   - <version>1.13</version>
260   - </dependency>
261   -
262 253 <dependency>
263 254 <groupId>org.dbunit</groupId>
264 255 <artifactId>dbunit</artifactId>
... ...
src/main/java/com/bsth/XDApplication.java
... ... @@ -5,10 +5,10 @@ import com.bsth.data.ThreadMonotor;
5 5 import com.bsth.data.car_out_info.UpdateDBThread;
6 6 import com.bsth.data.directive.DirectivesPstThread;
7 7 import com.bsth.data.forecast.SampleTimeDataLoader;
8   -import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
9   -import com.bsth.data.gpsdata.thread.OfflineMonitorThread;
  8 +import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
10 9 import com.bsth.data.msg_queue.DirectivePushQueue;
11 10 import com.bsth.data.msg_queue.WebSocketPushQueue;
  11 +import com.bsth.data.schedule.DayOfSchedule;
12 12 import com.bsth.data.schedule.auto_exec.AutoExecScanThread;
13 13 import com.bsth.data.schedule.edit_logs.SeiPstThread;
14 14 import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
... ... @@ -42,10 +42,6 @@ public class XDApplication implements CommandLineRunner {
42 42 @Autowired
43 43 UpdateDBThread fcxxUpdateThread;
44 44 @Autowired
45   - GpsDataLoaderThread gpsDataLoader;
46   - @Autowired
47   - OfflineMonitorThread offlineMonitorThread;
48   - @Autowired
49 45 ScheduleRefreshThread scheduleRefreshThread;
50 46 @Autowired
51 47 SchedulePstThread schedulePstThread;
... ... @@ -68,6 +64,9 @@ public class XDApplication implements CommandLineRunner {
68 64 @Autowired
69 65 AutoExecScanThread autoExecScanThread;
70 66  
  67 + @Autowired
  68 + GpsDataLoaderThread gpsDataLoader;
  69 +
71 70 private static long timeDiff;
72 71 private static long timeDiffTraffic;
73 72  
... ... @@ -103,15 +102,15 @@ public class XDApplication implements CommandLineRunner {
103 102 }
104 103 }
105 104  
106   - //@Autowired
107   - //DayOfSchedule dayOfSchedule;
  105 + @Autowired
  106 + DayOfSchedule dayOfSchedule;
108 107 public void devInit(){
109 108 log.info("devInit...");
110 109 ScheduledExecutorService sexec = Application.mainServices;
111 110 //抓取GPS数据
112 111 gpsDataLoader.setFlag(-1);
113 112 //dayOfSchedule.dataRecovery();
114   - //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
  113 + //sexec.scheduleWithFixedDelay(gpsDataLoader, 60, 4, TimeUnit.SECONDS);
115 114 //实际排班更新线程
116 115 //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
117 116 //sexec.scheduleWithFixedDelay(autoExecScanThread, 100, 50, TimeUnit.SECONDS);//班次自动执行
... ... @@ -131,14 +130,14 @@ public class XDApplication implements CommandLineRunner {
131 130 ScheduledExecutorService sexec = Application.mainServices;
132 131  
133 132 /** 线调业务 */
134   - sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);//班次更新线程
  133 + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
135 134 sexec.scheduleWithFixedDelay(scheduleLateThread, 70, 30, TimeUnit.SECONDS);//检查班次误点
136 135 sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据
137 136  
138   - sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
  137 + //sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
139 138 sexec.scheduleWithFixedDelay(schedulePstThread, 120, 10, TimeUnit.SECONDS);//班次延迟入库线程
140 139 sexec.scheduleWithFixedDelay(seiPstThread, 160, 60, TimeUnit.SECONDS);//班次修正日志入库
141   - sexec.scheduleWithFixedDelay(directivesPstThread, 180, 100, TimeUnit.SECONDS);//调度指令延迟入库
  140 + sexec.scheduleWithFixedDelay(directivesPstThread, 180, 120, TimeUnit.SECONDS);//调度指令延迟入库
142 141 sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
143 142 sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 140, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
144 143 sexec.scheduleWithFixedDelay(basicDataLoader, 2, 2, TimeUnit.HOURS);//基础数据更新
... ...
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/LineController.java
1 1 package com.bsth.controller;
2 2  
  3 +import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.Date;
3 6 import java.util.HashMap;
4 7 import java.util.Map;
5 8  
... ... @@ -11,7 +14,9 @@ import org.springframework.web.bind.annotation.RestController;
11 14  
12 15 import com.bsth.common.ResponseCode;
13 16 import com.bsth.entity.Line;
  17 +import com.bsth.entity.LineVersions;
14 18 import com.bsth.service.LineService;
  19 +import com.bsth.service.LineVersionsService;
15 20 import com.bsth.util.GetUIDAndCode;
16 21  
17 22 /**
... ... @@ -36,6 +41,9 @@ public class LineController extends BaseController&lt;Line, Integer&gt; {
36 41 @Autowired
37 42 private LineService service;
38 43  
  44 + @Autowired
  45 + private LineVersionsService lineVersionsService;
  46 +
39 47 /**
40 48 * 获取线路编码与ID
41 49 *
... ... @@ -74,13 +82,31 @@ public class LineController extends BaseController&lt;Line, Integer&gt; {
74 82 map.put("status", ResponseCode.ERROR);
75 83 return map;
76 84 }
77   - return service.save(t);
  85 + // 添加线路版本
  86 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  87 + try {
  88 + Date endDate = simpleDateFormat.parse("2088-08-08 00:00:00");
  89 + LineVersions lineVersions = new LineVersions();
  90 + lineVersions.setName("原始版本");
  91 + lineVersions.setLine(t);
  92 + lineVersions.setLineCode(t.getLineCode());
  93 + lineVersions.setStartDate(t.getCreateDate());
  94 + lineVersions.setEndDate(new java.sql.Date(endDate.getTime()));// 2088-8-8 00:00:00
  95 + lineVersions.setVersions(1);
  96 + lineVersions.setStatus(1);
  97 + // 先添加线路再添加版本
  98 + service.save(t);
  99 + return lineVersionsService.save(lineVersions);
  100 + } catch (ParseException e) {
  101 + // TODO Auto-generated catch block
  102 + e.printStackTrace();
  103 + map.put("status", ResponseCode.ERROR);
  104 + return map;
  105 + }
78 106 }
79 107  
80 108 /**
81   - *
82 109 * 更改
83   - *
84 110 */
85 111 @RequestMapping(value="/update", method = RequestMethod.POST)
86 112 public Map<String, Object> update(Line l){
... ...
src/main/java/com/bsth/controller/LineVersionsController.java
... ... @@ -12,16 +12,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
12 12 import org.springframework.web.bind.annotation.RequestParam;
13 13 import org.springframework.web.bind.annotation.RestController;
14 14  
15   -import com.alibaba.fastjson.JSON;
16   -import com.alibaba.fastjson.JSONObject;
17   -import com.alibaba.fastjson.TypeReference;
18   -import com.bsth.data.LineVersionsData;
19 15 import com.bsth.entity.Line;
20 16 import com.bsth.entity.LineVersions;
21   -import com.bsth.entity.LsStationRoute;
22   -import com.bsth.entity.StationRoute;
23 17 import com.bsth.repository.LineRepository;
24   -import com.bsth.repository.LsStationRouteRepository;
25 18 import com.bsth.service.LineVersionsService;
26 19  
27 20 /**
... ... @@ -46,8 +39,15 @@ public class LineVersionsController extends BaseController&lt;LineVersions, Integer
46 39  
47 40 @Autowired
48 41 LineRepository lineRepository;
49   - @Autowired
50   - LsStationRouteRepository lsStationRouteRepository ;
  42 +
  43 + /**
  44 + * 获取线路所有版本
  45 + */
  46 + @RequestMapping(value = "findLineVersionsMax", method = RequestMethod.GET)
  47 + public LineVersions findLineVersionsMax(@RequestParam(defaultValue = "lineId") int lineId) {
  48 + return service.findLineVersionsMax(lineId);
  49 + }
  50 +
51 51 /**
52 52 * 获取线路所有版本
53 53 *
... ... @@ -63,7 +63,6 @@ public class LineVersionsController extends BaseController&lt;LineVersions, Integer
63 63 */
64 64 @RequestMapping(value = "findById", method = RequestMethod.GET)
65 65 public LineVersions findOne(@RequestParam(defaultValue = "id") int id) {
66   - service.lineUpdate();
67 66 return service.findById(id);
68 67 }
69 68  
... ... @@ -78,25 +77,7 @@ public class LineVersionsController extends BaseController&lt;LineVersions, Integer
78 77  
79 78 @RequestMapping(value = "add", method = RequestMethod.POST)
80 79 public Map<String, Object> add(@RequestParam Map<String, Object> map) {
81   - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
82   -
83   - LineVersions lineVersions = new LineVersions();
84   - try {
85   - Date startDate = simpleDateFormat.parse(map.get("startDate").toString());
86   - Date endDate = simpleDateFormat.parse(map.get("endDate").toString());
87   - Line line = lineRepository.findOne(Integer.valueOf(map.get("lineId").toString()));
88   - lineVersions.setLine(line);
89   - lineVersions.setLineCode(map.get("lineCode").toString());
90   - lineVersions.setStartDate(new java.sql.Date(startDate.getTime()));
91   - lineVersions.setEndDate(new java.sql.Date(endDate.getTime()));
92   - lineVersions.setVersions(Integer.valueOf(map.get("versions").toString()));
93   - lineVersions.setStatus(Integer.valueOf(map.get("status").toString()));
94   - lineVersions.setRemark(map.get("remark").toString());
95   - } catch (ParseException e) {
96   - // TODO Auto-generated catch block
97   - e.printStackTrace();
98   - }
99   - return service.save(lineVersions);
  80 + return service.add(map);
100 81 }
101 82  
102 83 }
... ...
src/main/java/com/bsth/controller/RoadSpeedController.java 0 → 100644
  1 +package com.bsth.controller;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import com.bsth.entity.RoadSpeed;
  13 +import com.bsth.service.RoadSpeedService;
  14 +
  15 +/**
  16 + *
  17 + * @ClassName: RoadSpeedController(路段限速控制器)
  18 + *
  19 + * @Extends : BaseController
  20 + *
  21 + * @Description: TODO(路段限速控制层)
  22 + *
  23 + * @Author bsth@lq
  24 + *
  25 + * @Version 公交调度系统BS版 0.1
  26 + *
  27 + */
  28 +@RestController
  29 +@RequestMapping("roadSpeed")
  30 +public class RoadSpeedController extends BaseController<RoadSpeed, Integer> {
  31 +
  32 + @Autowired
  33 + private RoadSpeedService service;
  34 +
  35 + /*@RequestMapping(value="all", method = RequestMethod.GET)
  36 + public List<RoadSpeed> allRoadSpeed(){
  37 + return service.allRoadSpeed();
  38 + }*/
  39 +
  40 + @RequestMapping(value="save", method = RequestMethod.POST)
  41 + public Map<String, Object> save(@RequestParam Map<String, Object> map){
  42 + return service.roadSpeedSave(map);
  43 + }
  44 +
  45 + @RequestMapping(value="update", method = RequestMethod.POST)
  46 + public Map<String, Object> update(@RequestParam Map<String, Object> map){
  47 + return service.update(map);
  48 + }
  49 +
  50 + @RequestMapping(value="findById", method = RequestMethod.GET)
  51 + public RoadSpeed findById(@RequestParam(defaultValue = "id") Integer id){
  52 + return service.findId(id);
  53 + }
  54 +}
... ...
src/main/java/com/bsth/controller/StationController.java
... ... @@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
8 8 import org.springframework.web.bind.annotation.RequestParam;
9 9 import org.springframework.web.bind.annotation.RestController;
10 10  
11   -import antlr.collections.List;
12   -
13 11 import com.bsth.entity.Station;
14 12 import com.bsth.service.StationService;
15 13 import com.bsth.util.GetUIDAndCode;
... ... @@ -128,6 +126,27 @@ public class StationController extends BaseController&lt;Station, Integer&gt; {
128 126 map.put("updateBy", "");
129 127 return service.stationUpdate(map);
130 128 }
  129 +
  130 + /**
  131 + * @Description :TODO(更新缓存站点保存)
  132 + *
  133 + * @param map <bJwpoints:中心点百度坐标;bPolygonGrid:多边形图形百度坐标;dbType:原坐标类型;
  134 + *
  135 + * descriptions:说明;destroy:是否撤销;directions:方向;distances:到站距离;gJwpoints:中心点WGS坐标;
  136 + *
  137 + * gPolygonGrid:多边形图形WGS坐标;lineId:线路ID;radius:圆半径;roadCoding:道路编码;shapesType:图形类型;
  138 + *
  139 + * stationCod:站点编码;stationMark:站点类型;stationName:站点名称;stationRouteCode:站点序号;toTime:到站时间
  140 + *
  141 + * versions:版本号;x:城建坐标x;y:城建坐标y>
  142 + *
  143 + * @return Map<String, Object> <SUCCESS ; ERROR>
  144 + */
  145 + @RequestMapping(value="stationCacheUpdate" , method = RequestMethod.POST)
  146 + public Map<String, Object> stationCacheUpdate(@RequestParam Map<String, Object> map) {
  147 + map.put("updateBy", "");
  148 + return service.stationCacheUpdate(map);
  149 + }
131 150 /**
132 151 * @Description :TODO(查询站点编码)
133 152 *
... ...
src/main/java/com/bsth/controller/StationRouteController.java
1 1 package com.bsth.controller;
2 2  
3 3 import com.bsth.entity.StationRoute;
  4 +import com.bsth.entity.StationRouteCache;
  5 +import com.bsth.repository.StationRouteCacheRepository;
4 6 import com.bsth.repository.StationRouteRepository;
5 7 import com.bsth.service.StationRouteService;
6 8 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -37,6 +39,8 @@ public class StationRouteController extends BaseController&lt;StationRoute, Integer
37 39 StationRouteService service;
38 40 @Autowired
39 41 StationRouteRepository stationRouteRepository;
  42 + @Autowired
  43 + StationRouteCacheRepository stationRouteCacheRepository;
40 44  
41 45 /**
42 46 * @param @param map
... ... @@ -49,6 +53,11 @@ public class StationRouteController extends BaseController&lt;StationRoute, Integer
49 53 return service.list(map);
50 54 }
51 55  
  56 + @RequestMapping(value = "/cacheList", method = RequestMethod.GET)
  57 + public List<StationRouteCache> cacheList(@RequestParam Map<String, Object> map) {
  58 + return service.cacheList(map);
  59 + }
  60 +
52 61 /**
53 62 * @Description :TODO(查询路段信息)
54 63 *
... ... @@ -101,6 +110,14 @@ public class StationRouteController extends BaseController&lt;StationRoute, Integer
101 110 }
102 111  
103 112 /**
  113 + * @Description :TODO(查询缓存站点的上一个缓存站点)
  114 + */
  115 + @RequestMapping(value = "/findCacheUpStationRouteCode" , method = RequestMethod.GET)
  116 + public List<Map<String, Object>> findCacheUpStationRouteCode(@RequestParam Map<String, Object> map) {
  117 + return service.findCacheUpStationRouteCode(map);
  118 + }
  119 +
  120 + /**
104 121 * @Description :TODO(查询线路某方向下所有站点的中心百度坐标)
105 122 *
106 123 * @param map <lineId:线路ID; direction:方向>
... ... @@ -195,4 +212,31 @@ public class StationRouteController extends BaseController&lt;StationRoute, Integer
195 212 public Map<String, Object> upddis(@RequestParam Map<String, Object> map) {
196 213 return service.upddis(map);
197 214 }
  215 +
  216 + /**
  217 + *
  218 + * @Title: findCacheStationRoute
  219 + * @Description: TODO(查询缓存路由)
  220 + */
  221 + @RequestMapping(value = "/findCacheStationRoute",method = RequestMethod.GET)
  222 + public List<StationRouteCache> findCacheStationRoute(@RequestParam Map<String, Object> map) {
  223 + int lineId = Integer.parseInt(map.get("lineId").toString());
  224 + int dir = Integer.parseInt(map.get("dir").toString());
  225 + return stationRouteCacheRepository.findstationRoute(lineId, dir);
  226 + }
  227 +
  228 + /**
  229 + *
  230 + * @Title: findCachePoint
  231 + *
  232 + * @param map <lineId:线路ID; dir:方向>
  233 + *
  234 + * @Description: TODO(查询缓存路由)
  235 + */
  236 + @RequestMapping(value = "/findCachePoint",method = RequestMethod.GET)
  237 + public List<Map<String, Object>> findCachePoint(@RequestParam Map<String, Object> map) {
  238 + int lineId = Integer.parseInt(map.get("lineId").toString());
  239 + int dir = Integer.parseInt(map.get("dir").toString());
  240 + return service.findCachePoint(lineId, dir);
  241 + }
198 242 }
... ...
src/main/java/com/bsth/controller/calc/CalcWaybillController.java 0 → 100644
  1 +package com.bsth.controller.calc;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.List;
  5 +import java.util.Map;
  6 +
  7 +import com.bsth.common.ResponseCode;
  8 +import com.bsth.controller.BaseController;
  9 +import com.bsth.entity.calc.CalcWaybill;
  10 +import com.bsth.service.calc.CalcWaybillService;
  11 +
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.RequestParam;
  15 +import org.springframework.web.bind.annotation.RestController;
  16 +
  17 +/**
  18 + * Created by 17/10/23.
  19 + */
  20 +@RestController
  21 +@RequestMapping("calcWaybill")
  22 +public class CalcWaybillController extends BaseController<CalcWaybill, Integer> {
  23 +
  24 + @Autowired
  25 + private CalcWaybillService calcWaybillService;
  26 +
  27 + @RequestMapping(value="/generateNew")
  28 + public Map<String, Object> generateNews(@RequestParam Map<String, Object> map) throws Exception{
  29 + String date = "", line = "";
  30 + if(map.get("date")!=null){
  31 + date=map.get("date").toString().trim();
  32 + }
  33 + if(map.get("line")!=null){
  34 + line=map.get("line").toString().trim();
  35 + }
  36 +
  37 + Map<String, Object> m = new HashMap<String, Object>();
  38 + try {
  39 +
  40 + m = calcWaybillService.generateNew(date, line);
  41 +
  42 + } catch (Exception e) {
  43 + // TODO: handle exception
  44 + e.printStackTrace();
  45 + m.put("status", ResponseCode.ERROR);
  46 + return m;
  47 + }
  48 +
  49 + return m;
  50 + }
  51 +
  52 + @RequestMapping(value="/statisticsDailyTj")
  53 + public List<Map<String,Object>> statisticsDailyTj(@RequestParam Map<String, Object> map){
  54 + String gsdm="";
  55 + if(map.get("gsdm")!=null){
  56 + gsdm=map.get("gsdm").toString().trim();
  57 + }
  58 + String fgsdm="";
  59 + if(map.get("fgsdm")!=null){
  60 + fgsdm=map.get("fgsdm").toString().trim();
  61 + }
  62 + String line="";
  63 + if(map.get("line")!=null){
  64 + line=map.get("line").toString().trim();
  65 + }
  66 + String date="";
  67 + if(map.get("date")!=null){
  68 + date=map.get("date").toString().trim();
  69 + }
  70 + String date2="";
  71 + if(map.get("date2")!=null){
  72 + date2=map.get("date2").toString().trim();
  73 + }
  74 + String xlName="";
  75 + if(map.get("xlName")!=null){
  76 + xlName=map.get("xlName").toString().trim();
  77 + }
  78 + String type="";
  79 + if(map.get("type")!=null){
  80 + type=map.get("type").toString().trim();
  81 + }
  82 + return calcWaybillService.statisticsDailyTj(gsdm,fgsdm,line,date,date2,xlName,type);
  83 + }
  84 +
  85 +}
... ...
src/main/java/com/bsth/controller/directive/DirectiveController.java
... ... @@ -165,11 +165,11 @@ public class DirectiveController {
165 165 * @throws
166 166 */
167 167 @RequestMapping(value = "/list", method = RequestMethod.GET)
168   - public Map<String, Object> findDirective(String nbbm,@RequestParam int dType
  168 + public Map<String, Object> findDirective(String nbbms,@RequestParam int dType
169 169 , @RequestParam(defaultValue = "0") int page,
170 170 @RequestParam(defaultValue = "10") int size){
171 171  
172   - return directiveService.findDirective(nbbm, dType, page, size);
  172 + return directiveService.findDirective(nbbms, dType, page, size);
173 173 }
174 174  
175 175 @RequestMapping(value = "/c0a4", method = RequestMethod.POST)
... ...
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/oil/YlbController.java
... ... @@ -288,4 +288,22 @@ public class YlbController extends BaseController&lt;Ylb, Integer&gt;{
288 288 return resList;
289 289  
290 290 }
  291 +
  292 + /*
  293 + * 历史修改行车路单后重新统计油量信息 (传参:line --线路编码 date --日期)
  294 + */
  295 +
  296 + @RequestMapping(value = "/updateHistory",method = RequestMethod.POST)
  297 + public Map<String, Object> updateHistory(@RequestParam Map<String, Object> map) throws Exception{
  298 + Map<String, Object> list =new HashMap<String, Object>();
  299 + try {
  300 + list = yblService.updateHistory(map);
  301 + } catch (Exception e) {
  302 + // TODO Auto-generated catch block
  303 + throw e;
  304 + }
  305 + return list;
  306 + }
  307 +
  308 +
291 309 }
... ...
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
1 1 package com.bsth.controller.realcontrol;
2 2  
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.data.BasicData;
  5 +import com.bsth.data.directive.DayOfDirectives;
  6 +import com.bsth.data.directive.DirectiveCreator;
  7 +import com.bsth.data.directive.GatewayHttpUtils;
  8 +import com.bsth.data.gpsdata_v2.GpsRealData;
  9 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
3 10 import com.bsth.data.schedule.DayOfSchedule;
  11 +import com.bsth.entity.directive.D60;
4 12 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  13 +import com.bsth.repository.directive.D60Repository;
  14 +import com.google.common.base.Splitter;
5 15 import org.apache.commons.lang3.StringUtils;
  16 +import org.slf4j.Logger;
  17 +import org.slf4j.LoggerFactory;
6 18 import org.springframework.beans.factory.annotation.Autowired;
7   -import org.springframework.web.bind.annotation.RequestMapping;
8   -import org.springframework.web.bind.annotation.RequestParam;
9   -import org.springframework.web.bind.annotation.RestController;
  19 +import org.springframework.web.bind.annotation.*;
10 20  
11   -import java.util.ArrayList;
12   -import java.util.List;
  21 +import java.util.*;
13 22  
14 23 /**
15 24 * 对外的营运数据接口
... ... @@ -21,9 +30,58 @@ public class ServiceDataInterface {
21 30  
22 31 private final static String SECRE_KEY = "dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki";
23 32  
  33 + Logger logger = LoggerFactory.getLogger(this.getClass());
  34 +
24 35 @Autowired
25 36 DayOfSchedule dayOfSchedule;
26 37  
  38 + @Autowired
  39 + DayOfDirectives dayOfDirectives;
  40 +
  41 + @Autowired
  42 + D60Repository d60Repository;
  43 +
  44 + @Autowired
  45 + GpsRealData gpsRealData;
  46 +
  47 + /**
  48 + * 获取车辆 和 当前执行班次对照信息
  49 + * @return
  50 + */
  51 + @RequestMapping("/execSchList")
  52 + public List<Map<String, Object>> execSchList(@RequestParam String secretKey){
  53 + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
  54 + return null;
  55 +
  56 + List<Map<String, Object>> rs = new ArrayList<>();
  57 + Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values();
  58 +
  59 + Map<String, Object> map;
  60 + for(ScheduleRealInfo sch : list){
  61 + if(null == sch)
  62 + continue;
  63 + map = new HashMap<>();
  64 + map.put("clZbh", sch.getClZbh());
  65 + map.put("jGh", sch.getjGh());
  66 + map.put("sGh", sch.getsGh());
  67 + map.put("lpName", sch.getLpName());
  68 + map.put("xlBm", sch.getXlBm());
  69 + map.put("xlName", sch.getXlName());
  70 + map.put("xlDir", sch.getXlDir());
  71 + map.put("qdzName", sch.getQdzName());
  72 + map.put("zdzName", sch.getZdzName());
  73 + map.put("fcsj", sch.getFcsj());
  74 + map.put("dfsj", sch.getDfsj());
  75 + map.put("zdsj", sch.getZdsj());
  76 + map.put("bcType", sch.getBcType());
  77 + map.put("remarks", sch.getRemark());
  78 + map.put("status", sch.getStatus());
  79 +
  80 + rs.add(map);
  81 + }
  82 + return rs;
  83 + }
  84 +
27 85 @RequestMapping("/getCurrentDayPlan")
28 86 public List<ScheduleRealInfo> getCurrentDayPlan(
29 87 @RequestParam String companyId,
... ... @@ -98,4 +156,87 @@ public class ServiceDataInterface {
98 156 }
99 157 return rs;
100 158 }
  159 +
  160 + /**
  161 + * 向指定的车辆下发消息短语
  162 + * @param nbbm
  163 + * @param txt
  164 + * @return
  165 + */
  166 + @RequestMapping(value = "/send60Phrase", method = RequestMethod.POST)
  167 + public int send60Phrase(@RequestBody Map<String, String> map,@RequestParam String secretKey){
  168 + try{
  169 + String nbbm = map.get("nbbm");
  170 + String txt = map.get("txt");
  171 + String sender = map.get("sender");
  172 + if(txt.length() > 50)
  173 + txt = txt.substring(0, 50);
  174 + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
  175 + return -500;
  176 +
  177 + //车辆和设备号对照
  178 + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
  179 + if(StringUtils.isEmpty(deviceId))
  180 + return -404;
  181 +
  182 + //检查设备是否在线
  183 + long t = System.currentTimeMillis();
  184 + GpsEntity gps = gpsRealData.get(deviceId);
  185 + if(null == gps || (t - gps.getServerTimestamp()) > 1000 * 60 * 5)
  186 + return -405;
  187 +
  188 + Short dispatchInstruct = 0;//消息短语
  189 + D60 d60 = new DirectiveCreator().createD60(nbbm, txt, dispatchInstruct, gps.getUpDown(), gps.getState(), gps.getLineId());
  190 + d60.setSender(sender);
  191 + // 发送指令
  192 + int code = GatewayHttpUtils.postJson(JSON.toJSONString(d60));
  193 + d60.setHttpCode(code);
  194 +
  195 + if (code == 0) {
  196 + // 添加到缓存
  197 + dayOfDirectives.put60(d60, true);
  198 + } else {
  199 + d60.setErrorText("网关通讯失败, code: " + code);
  200 + d60Repository.save(d60);
  201 + dayOfDirectives.put60(d60, false);
  202 + }
  203 +
  204 + return d60.getMsgId();
  205 + }catch (Exception e){
  206 + logger.error("", e);
  207 + return -500;
  208 + }
  209 + }
  210 +
  211 + /**
  212 + * 根据msg id 查询指令响应情况
  213 + * @param msgIDs
  214 + * @return
  215 + */
  216 + @RequestMapping("/findD60Reply")
  217 + public List<Map<String, Object>> findD60Reply(@RequestParam String msgIds){
  218 + List<Map<String, Object>> rs = new ArrayList<>();
  219 + try{
  220 + Map<String, Object> map = new HashMap();
  221 +
  222 + List<String> ids = Splitter.on(",").splitToList(msgIds);
  223 + D60 d60;
  224 + for(String id : ids){
  225 + if(StringUtils.isEmpty(id))
  226 + continue;
  227 +
  228 + d60 = dayOfDirectives.get(Integer.parseInt(id));
  229 + if(null == d60)
  230 + continue;
  231 +
  232 + map.put("msgId", d60.getMsgId());
  233 + map.put("deviceReplyTime", d60.getReply46Time());
  234 + map.put("jsyReplyTime", d60.getReply47Time());
  235 + rs.add(map);
  236 + }
  237 + }catch (Exception e){
  238 + logger.error("", e);
  239 + }
  240 + return rs;
  241 + }
101 242 }
... ...
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/controller/schedule/TrafficManageController.java
... ... @@ -30,6 +30,15 @@ public class TrafficManageController {
30 30 }
31 31 }
32 32  
  33 + @RequestMapping(value = "/setXLByInUse", method = RequestMethod.GET)
  34 + public String setXLByInUse(@RequestParam("inUse") String inUse) throws Exception {
  35 + try {
  36 + return trManageService.setXLByInUse(inUse);
  37 + } catch (Exception exp) {
  38 + throw new Exception(exp.getCause());
  39 + }
  40 + }
  41 +
33 42 @RequestMapping(value = "/setCL", method = RequestMethod.GET)
34 43 public String setCL() throws Exception {
35 44 try {
... ...
src/main/java/com/bsth/data/BasicData.java
1 1 package com.bsth.data;
2 2  
3   -import com.bsth.data.gpsdata.arrival.GeoCacheData;
  3 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
4 4 import com.bsth.data.pinyin.PersionPinYinBuffer;
5 5 import com.bsth.entity.*;
6 6 import com.bsth.entity.schedule.CarConfigInfo;
... ...
src/main/java/com/bsth/data/LineConfigData.java
... ... @@ -2,7 +2,6 @@ package com.bsth.data;
2 2  
3 3 import com.bsth.Application;
4 4 import com.bsth.entity.Line;
5   -import com.bsth.entity.realcontrol.D80ReplyTemp;
6 5 import com.bsth.entity.realcontrol.LineConfig;
7 6 import com.bsth.entity.realcontrol.ScheduleRealInfo;
8 7 import com.bsth.service.LineService;
... ... @@ -135,31 +134,15 @@ public class LineConfigData implements CommandLineRunner {
135 134 conf.setLine(line);
136 135 //开始运营时间
137 136 conf.setStartOpt("02:00");
138   - //托管状态
139   - conf.setTrust(true);
140 137 //出场时间类型
141 138 conf.setOutConfig(0);
142   - //进场时间类型
143   - //conf.setInConfig(1);
144   - //短语模板
145   - conf.setPhraseTemps("");
146 139 //调度指令模板
147 140 conf.setSchDirectiveTemp("");
148 141  
149   - //80指令回复 闵行用
150   - D80ReplyTemp t50 = new D80ReplyTemp(conf, (short) 0x50, "同意,回电详谈", "不同意,请回电"), t60 = new D80ReplyTemp(conf, (short) 0x60, "同意,回电详谈", "不同意,请回电"), tA2 = new D80ReplyTemp(conf, (short) 0xA2, "同意,回电详谈", "不同意,请回电"), t70 = new D80ReplyTemp(conf, (short) 0x70, "同意,回电详谈", "不同意,请回电"), t11 = new D80ReplyTemp(conf, (short) 0x11, "同意,回电详谈", "不同意,请回电");
151   -
152 142 //应急停靠默认值
153 143 conf.setYjtkStart("00:00");
154 144 conf.setYjtkEnd("23:59");
155 145  
156   - Set<D80ReplyTemp> temps = conf.getD80Temps();
157   - temps.add(t50);
158   - temps.add(t60);
159   - temps.add(tA2);
160   - temps.add(t70);
161   - temps.add(t11);
162   -
163 146 set(conf);
164 147 }
165 148 }
... ...
src/main/java/com/bsth/data/LineVersionsData.java
... ... @@ -21,7 +21,7 @@ import com.bsth.service.StationRouteService;
21 21 */
22 22 @Component
23 23 @Order(20)
24   -public class LineVersionsData implements CommandLineRunner {
  24 +public class LineVersionsData extends Thread {
25 25  
26 26 static Logger logger = LoggerFactory.getLogger(LineVersionsData.class);
27 27  
... ... @@ -33,9 +33,7 @@ public class LineVersionsData implements CommandLineRunner {
33 33 StationRouteService stationRouteService;
34 34  
35 35 @Override
36   - public void run(String... arg0) throws Exception {
37   -
38   -
  36 + public void run() {
39 37 try {
40 38 List<LineVersions> list = lineVersionsService.lineUpdate();
41 39 for (LineVersions lineVersions : list) {
... ... @@ -44,10 +42,11 @@ public class LineVersionsData implements CommandLineRunner {
44 42 Map<String, Object> map = new HashMap<>();
45 43 map.put("lineId", lineId);
46 44 stationRouteService.usingSingle(map);
  45 + logger.info("线路版本更新成功!");
47 46 }
48 47 } catch (Exception e) {
49   - // TODO Auto-generated catch block
50 48 e.printStackTrace();
  49 + logger.error("线路版本更新出现异常!", e);
51 50 }
52 51 }
53 52 }
... ...
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   -import com.bsth.data.msg_queue.DirectivePushQueue;
6   -import com.bsth.data.msg_queue.WebSocketPushQueue;
7 3 import org.slf4j.Logger;
8 4 import org.slf4j.LoggerFactory;
9 5 import org.springframework.stereotype.Component;
... ... @@ -20,26 +16,26 @@ public class ThreadMonotor extends Thread{
20 16 public void run() {
21 17  
22 18 //线调GPS分析主线程
23   - if(GpsRealAnalyse.isBlock()){
  19 + /*if(GpsRealAnalyse.isBlock()){
24 20 log.warn("GpsRealAnalyse isBlock true !!!!");
25 21 GpsRealAnalyse.shutdown();
26   - }
  22 + }*/
27 23  
28   - if(GpsRealAnalyse.isIdle()){
  24 + /*if(GpsRealAnalyse.isIdle()){
29 25 //切换到备用的网关实时GPS对照数据
30 26 GpsDataLoaderThread.setFlag(-1);
31   - }
  27 + }*/
32 28  
33 29 //webSocket 消息推送队列
34   - if(WebSocketPushQueue.isIdle()){
  30 + /*if(WebSocketPushQueue.isIdle()){
35 31 log.warn("WebSocketPushQueue isIdle true !!!!");
36 32 WebSocketPushQueue.start();
37   - }
  33 + }*/
38 34  
39 35 //网关指令推送队列(系统自动发送的)
40   - if(DirectivePushQueue.isIdle()){
  36 + /*if(DirectivePushQueue.isIdle()){
41 37 log.warn("DirectivePushQueue isIdle true !!!!");
42 38 DirectivePushQueue.start();
43   - }
  39 + }*/
44 40 }
45 41 }
46 42 \ No newline at end of file
... ...
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 }
... ... @@ -197,7 +201,11 @@ public class DayOfDirectives {
197 201 public Collection<D64> all64(){
198 202 return d64Map.values();
199 203 }
200   -
  204 +
  205 + public D60 get(Integer msgId){
  206 + return d60Map.get(msgId);
  207 + }
  208 +
201 209 public Collection<Directive> all(){
202 210 List<Directive> all = new ArrayList<>();
203 211 all.addAll(d60Map.values());
... ...
src/main/java/com/bsth/data/directive/MsgIdGenerator.java
... ... @@ -12,7 +12,7 @@ public class MsgIdGenerator {
12 12  
13 13 private static int msgId = 1;
14 14  
15   - private final static int MAX_VALUE = Integer.MAX_VALUE - 10;
  15 + private final static int MAX_VALUE = Integer.MAX_VALUE - 1000;
16 16  
17 17 public synchronized static int getMsgId(){
18 18 msgId ++;
... ...
src/main/java/com/bsth/data/forecast/ArrivalDataLoader.java
... ... @@ -3,7 +3,6 @@ package com.bsth.data.forecast;
3 3 import com.bsth.data.BasicData;
4 4 import com.bsth.data.LineConfigData;
5 5 import com.bsth.data.forecast.entity.ArrivalEntity;
6   -import com.bsth.entity.realcontrol.LineConfig;
7 6 import com.bsth.util.db.DBUtils_MS;
8 7 import org.slf4j.Logger;
9 8 import org.slf4j.LoggerFactory;
... ... @@ -16,7 +15,6 @@ import java.sql.ResultSet;
16 15 import java.sql.SQLException;
17 16 import java.util.ArrayList;
18 17 import java.util.Calendar;
19   -import java.util.Collection;
20 18 import java.util.List;
21 19  
22 20 /**
... ... @@ -43,7 +41,7 @@ public class ArrivalDataLoader {
43 41 *
44 42 * @Title: load
45 43 * @Description: TODO(根据上次加载时间,查询之后的增量数据)
46   - */
  44 +
47 45 public List<ArrivalEntity> load(){
48 46 List<ArrivalEntity> list = null;
49 47  
... ... @@ -79,13 +77,13 @@ public class ArrivalDataLoader {
79 77 }
80 78 }
81 79 return list;
82   - }
  80 + }*/
83 81  
84 82 /**
85 83 *
86 84 * @Title: recovery
87 85 * @Description: TODO(从数据库恢复数据,按照线路的开始运营时间恢复)
88   - */
  86 +
89 87 public List<ArrivalEntity> recovery(){
90 88 Collection<LineConfig> confs = lineConfigData.getAll();
91 89 long t = System.currentTimeMillis()
... ... @@ -105,7 +103,7 @@ public class ArrivalDataLoader {
105 103  
106 104 prveLoadTime = t;
107 105 return all;
108   - }
  106 + }*/
109 107  
110 108 /**
111 109 *
... ...
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 = null;
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 = 30;
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 +}
... ...