Commit de20530f59303fb9222c0b8e9b22f7ca9e7ba07b

Authored by 廖磊
2 parents 41e4b946 93a8257b

Merge branch 'pudong' of http://222.66.0.204:8090/panzhaov5/bsth_control

into pudong
Showing 52 changed files with 1637 additions and 2734 deletions

Too many changes to show.

To preserve performance only 52 of 115 files are displayed.

@@ -250,15 +250,6 @@ @@ -250,15 +250,6 @@
250 <version>1.7.4</version> 250 <version>1.7.4</version>
251 </dependency> 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 <dependency> 253 <dependency>
263 <groupId>org.dbunit</groupId> 254 <groupId>org.dbunit</groupId>
264 <artifactId>dbunit</artifactId> 255 <artifactId>dbunit</artifactId>
src/main/java/com/bsth/XDApplication.java
@@ -5,10 +5,10 @@ import com.bsth.data.ThreadMonotor; @@ -5,10 +5,10 @@ import com.bsth.data.ThreadMonotor;
5 import com.bsth.data.car_out_info.UpdateDBThread; 5 import com.bsth.data.car_out_info.UpdateDBThread;
6 import com.bsth.data.directive.DirectivesPstThread; 6 import com.bsth.data.directive.DirectivesPstThread;
7 import com.bsth.data.forecast.SampleTimeDataLoader; 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 import com.bsth.data.msg_queue.DirectivePushQueue; 9 import com.bsth.data.msg_queue.DirectivePushQueue;
11 import com.bsth.data.msg_queue.WebSocketPushQueue; 10 import com.bsth.data.msg_queue.WebSocketPushQueue;
  11 +import com.bsth.data.schedule.DayOfSchedule;
12 import com.bsth.data.schedule.auto_exec.AutoExecScanThread; 12 import com.bsth.data.schedule.auto_exec.AutoExecScanThread;
13 import com.bsth.data.schedule.edit_logs.SeiPstThread; 13 import com.bsth.data.schedule.edit_logs.SeiPstThread;
14 import com.bsth.data.schedule.late_adjust.ScheduleLateThread; 14 import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
@@ -42,10 +42,6 @@ public class XDApplication implements CommandLineRunner { @@ -42,10 +42,6 @@ public class XDApplication implements CommandLineRunner {
42 @Autowired 42 @Autowired
43 UpdateDBThread fcxxUpdateThread; 43 UpdateDBThread fcxxUpdateThread;
44 @Autowired 44 @Autowired
45 - GpsDataLoaderThread gpsDataLoader;  
46 - @Autowired  
47 - OfflineMonitorThread offlineMonitorThread;  
48 - @Autowired  
49 ScheduleRefreshThread scheduleRefreshThread; 45 ScheduleRefreshThread scheduleRefreshThread;
50 @Autowired 46 @Autowired
51 SchedulePstThread schedulePstThread; 47 SchedulePstThread schedulePstThread;
@@ -68,6 +64,9 @@ public class XDApplication implements CommandLineRunner { @@ -68,6 +64,9 @@ public class XDApplication implements CommandLineRunner {
68 @Autowired 64 @Autowired
69 AutoExecScanThread autoExecScanThread; 65 AutoExecScanThread autoExecScanThread;
70 66
  67 + @Autowired
  68 + GpsDataLoaderThread gpsDataLoader;
  69 +
71 private static long timeDiff; 70 private static long timeDiff;
72 private static long timeDiffTraffic; 71 private static long timeDiffTraffic;
73 72
@@ -103,15 +102,15 @@ public class XDApplication implements CommandLineRunner { @@ -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 public void devInit(){ 107 public void devInit(){
109 log.info("devInit..."); 108 log.info("devInit...");
110 ScheduledExecutorService sexec = Application.mainServices; 109 ScheduledExecutorService sexec = Application.mainServices;
111 //抓取GPS数据 110 //抓取GPS数据
112 gpsDataLoader.setFlag(-1); 111 gpsDataLoader.setFlag(-1);
113 //dayOfSchedule.dataRecovery(); 112 //dayOfSchedule.dataRecovery();
114 - //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); 113 + //sexec.scheduleWithFixedDelay(gpsDataLoader, 60, 4, TimeUnit.SECONDS);
115 //实际排班更新线程 114 //实际排班更新线程
116 //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); 115 //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
117 //sexec.scheduleWithFixedDelay(autoExecScanThread, 100, 50, TimeUnit.SECONDS);//班次自动执行 116 //sexec.scheduleWithFixedDelay(autoExecScanThread, 100, 50, TimeUnit.SECONDS);//班次自动执行
@@ -135,7 +134,7 @@ public class XDApplication implements CommandLineRunner { @@ -135,7 +134,7 @@ public class XDApplication implements CommandLineRunner {
135 sexec.scheduleWithFixedDelay(scheduleLateThread, 70, 30, TimeUnit.SECONDS);//检查班次误点 134 sexec.scheduleWithFixedDelay(scheduleLateThread, 70, 30, TimeUnit.SECONDS);//检查班次误点
136 sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据 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 sexec.scheduleWithFixedDelay(schedulePstThread, 120, 10, TimeUnit.SECONDS);//班次延迟入库线程 138 sexec.scheduleWithFixedDelay(schedulePstThread, 120, 10, TimeUnit.SECONDS);//班次延迟入库线程
140 sexec.scheduleWithFixedDelay(seiPstThread, 160, 60, TimeUnit.SECONDS);//班次修正日志入库 139 sexec.scheduleWithFixedDelay(seiPstThread, 160, 60, TimeUnit.SECONDS);//班次修正日志入库
141 sexec.scheduleWithFixedDelay(directivesPstThread, 180, 120, TimeUnit.SECONDS);//调度指令延迟入库 140 sexec.scheduleWithFixedDelay(directivesPstThread, 180, 120, TimeUnit.SECONDS);//调度指令延迟入库
src/main/java/com/bsth/controller/DeviceGpsController.java
1 package com.bsth.controller; 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 import com.fasterxml.jackson.core.JsonParseException; 5 import com.fasterxml.jackson.core.JsonParseException;
6 import com.fasterxml.jackson.databind.JsonMappingException; 6 import com.fasterxml.jackson.databind.JsonMappingException;
7 import com.fasterxml.jackson.databind.ObjectMapper; 7 import com.fasterxml.jackson.databind.ObjectMapper;
src/main/java/com/bsth/controller/LineVersionsController.java
@@ -77,28 +77,7 @@ public class LineVersionsController extends BaseController&lt;LineVersions, Integer @@ -77,28 +77,7 @@ public class LineVersionsController extends BaseController&lt;LineVersions, Integer
77 77
78 @RequestMapping(value = "add", method = RequestMethod.POST) 78 @RequestMapping(value = "add", method = RequestMethod.POST)
79 public Map<String, Object> add(@RequestParam Map<String, Object> map) { 79 public Map<String, Object> add(@RequestParam Map<String, Object> map) {
80 - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
81 -  
82 - LineVersions lineVersions = new LineVersions();  
83 - try {  
84 - Date startDate = simpleDateFormat.parse(map.get("startDate").toString());  
85 - Date endDate = simpleDateFormat.parse(map.get("endDate").toString());  
86 - Line line = lineRepository.findOne(Integer.valueOf(map.get("lineId").toString()));  
87 - lineVersions.setName(map.get("name").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 -  
96 -  
97 - } catch (ParseException e) {  
98 - // TODO Auto-generated catch block  
99 - e.printStackTrace();  
100 - }  
101 - return service.save(lineVersions); 80 + return service.add(map);
102 } 81 }
103 82
104 } 83 }
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/gps/GpsController.java
1 package com.bsth.controller.gps; 1 package com.bsth.controller.gps;
2 2
3 import com.bsth.data.BasicData; 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 import com.bsth.service.gps.GpsService; 6 import com.bsth.service.gps.GpsService;
8 import com.bsth.service.gps.entity.GpsSpeed; 7 import com.bsth.service.gps.entity.GpsSpeed;
9 -import com.bsth.util.PageObject;  
10 import com.google.common.base.Splitter; 8 import com.google.common.base.Splitter;
11 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.web.bind.annotation.*; 10 import org.springframework.web.bind.annotation.*;
13 11
14 import javax.servlet.http.HttpServletResponse; 12 import javax.servlet.http.HttpServletResponse;
15 -  
16 import java.text.ParseException; 13 import java.text.ParseException;
17 import java.util.ArrayList; 14 import java.util.ArrayList;
18 import java.util.List; 15 import java.util.List;
src/main/java/com/bsth/controller/realcontrol/RealMapController.java
1 package com.bsth.controller.realcontrol; 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 import com.bsth.service.realcontrol.RealMapService; 3 import com.bsth.service.realcontrol.RealMapService;
6 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RequestMapping;
8 -import org.springframework.web.bind.annotation.RequestMethod;  
9 import org.springframework.web.bind.annotation.RequestParam; 6 import org.springframework.web.bind.annotation.RequestParam;
10 import org.springframework.web.bind.annotation.RestController; 7 import org.springframework.web.bind.annotation.RestController;
11 8
@@ -77,9 +74,4 @@ public class RealMapController { @@ -77,9 +74,4 @@ public class RealMapController {
77 public Map<String, Object> multiSectionRoute(@RequestParam String codeIdx){ 74 public Map<String, Object> multiSectionRoute(@RequestParam String codeIdx){
78 return realMapService.multiSectionRoute(codeIdx); 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 package com.bsth.controller.realcontrol; 1 package com.bsth.controller.realcontrol;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 -import com.alibaba.fastjson.JSONObject;  
5 import com.bsth.data.BasicData; 4 import com.bsth.data.BasicData;
6 import com.bsth.data.directive.DayOfDirectives; 5 import com.bsth.data.directive.DayOfDirectives;
7 import com.bsth.data.directive.DirectiveCreator; 6 import com.bsth.data.directive.DirectiveCreator;
8 import com.bsth.data.directive.GatewayHttpUtils; 7 import com.bsth.data.directive.GatewayHttpUtils;
9 -import com.bsth.data.gpsdata.GpsEntity;  
10 -import com.bsth.data.gpsdata.GpsRealData; 8 +import com.bsth.data.gpsdata_v2.GpsRealData;
  9 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
11 import com.bsth.data.schedule.DayOfSchedule; 10 import com.bsth.data.schedule.DayOfSchedule;
12 import com.bsth.entity.directive.D60; 11 import com.bsth.entity.directive.D60;
13 import com.bsth.entity.realcontrol.ScheduleRealInfo; 12 import com.bsth.entity.realcontrol.ScheduleRealInfo;
@@ -50,33 +49,35 @@ public class ServiceDataInterface { @@ -50,33 +49,35 @@ public class ServiceDataInterface {
50 * @return 49 * @return
51 */ 50 */
52 @RequestMapping("/execSchList") 51 @RequestMapping("/execSchList")
53 - public List<JSONObject> execSchList(@RequestParam String secretKey){ 52 + public List<Map<String, Object>> execSchList(@RequestParam String secretKey){
54 if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) 53 if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY))
55 return null; 54 return null;
56 55
57 - List<JSONObject> rs = new ArrayList<>(); 56 + List<Map<String, Object>> rs = new ArrayList<>();
58 Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values(); 57 Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values();
59 58
60 - JSONObject obj; 59 + Map<String, Object> map;
61 for(ScheduleRealInfo sch : list){ 60 for(ScheduleRealInfo sch : list){
62 - obj = new JSONObject();  
63 - obj.put("clZbh", sch.getClZbh());  
64 - obj.put("jGh", sch.getjGh());  
65 - obj.put("sGh", sch.getsGh());  
66 - obj.put("lpName", sch.getLpName());  
67 - obj.put("xlBm", sch.getXlBm());  
68 - obj.put("xlName", sch.getXlName());  
69 - obj.put("xlDir", sch.getXlDir());  
70 - obj.put("qdzName", sch.getQdzName());  
71 - obj.put("zdzName", sch.getZdzName());  
72 - obj.put("fcsj", sch.getFcsj());  
73 - obj.put("dfsj", sch.getDfsj());  
74 - obj.put("zdsj", sch.getZdsj());  
75 - obj.put("bcType", sch.getBcType());  
76 - obj.put("remarks", sch.getRemark());  
77 - obj.put("status", sch.getStatus());  
78 -  
79 - rs.add(obj); 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);
80 } 81 }
81 return rs; 82 return rs;
82 } 83 }
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 package com.bsth.controller.realcontrol; 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 import com.bsth.data.msg_queue.DirectivePushQueue; 5 import com.bsth.data.msg_queue.DirectivePushQueue;
7 import com.bsth.data.msg_queue.WebSocketPushQueue; 6 import com.bsth.data.msg_queue.WebSocketPushQueue;
8 import com.bsth.data.schedule.DayOfSchedule; 7 import com.bsth.data.schedule.DayOfSchedule;
@@ -59,11 +58,6 @@ public class anomalyCheckController { @@ -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 @RequestMapping(value = "/directivePushQueue") 61 @RequestMapping(value = "/directivePushQueue")
68 public void directivePushQueue(){ 62 public void directivePushQueue(){
69 DirectivePushQueue.start(); 63 DirectivePushQueue.start();
src/main/java/com/bsth/data/BasicData.java
1 package com.bsth.data; 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 import com.bsth.data.pinyin.PersionPinYinBuffer; 4 import com.bsth.data.pinyin.PersionPinYinBuffer;
5 import com.bsth.entity.*; 5 import com.bsth.entity.*;
6 import com.bsth.entity.schedule.CarConfigInfo; 6 import com.bsth.entity.schedule.CarConfigInfo;
src/main/java/com/bsth/data/LineConfigData.java
@@ -2,7 +2,6 @@ package com.bsth.data; @@ -2,7 +2,6 @@ package com.bsth.data;
2 2
3 import com.bsth.Application; 3 import com.bsth.Application;
4 import com.bsth.entity.Line; 4 import com.bsth.entity.Line;
5 -import com.bsth.entity.realcontrol.D80ReplyTemp;  
6 import com.bsth.entity.realcontrol.LineConfig; 5 import com.bsth.entity.realcontrol.LineConfig;
7 import com.bsth.entity.realcontrol.ScheduleRealInfo; 6 import com.bsth.entity.realcontrol.ScheduleRealInfo;
8 import com.bsth.service.LineService; 7 import com.bsth.service.LineService;
@@ -135,31 +134,15 @@ public class LineConfigData implements CommandLineRunner { @@ -135,31 +134,15 @@ public class LineConfigData implements CommandLineRunner {
135 conf.setLine(line); 134 conf.setLine(line);
136 //开始运营时间 135 //开始运营时间
137 conf.setStartOpt("02:00"); 136 conf.setStartOpt("02:00");
138 - //托管状态  
139 - conf.setTrust(true);  
140 //出场时间类型 137 //出场时间类型
141 conf.setOutConfig(0); 138 conf.setOutConfig(0);
142 - //进场时间类型  
143 - //conf.setInConfig(1);  
144 - //短语模板  
145 - conf.setPhraseTemps("");  
146 //调度指令模板 139 //调度指令模板
147 conf.setSchDirectiveTemp(""); 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 conf.setYjtkStart("00:00"); 143 conf.setYjtkStart("00:00");
154 conf.setYjtkEnd("23:59"); 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 set(conf); 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,7 +21,7 @@ import com.bsth.service.StationRouteService;
21 */ 21 */
22 @Component 22 @Component
23 @Order(20) 23 @Order(20)
24 -public class LineVersionsData implements CommandLineRunner { 24 +public class LineVersionsData extends Thread {
25 25
26 static Logger logger = LoggerFactory.getLogger(LineVersionsData.class); 26 static Logger logger = LoggerFactory.getLogger(LineVersionsData.class);
27 27
@@ -33,9 +33,7 @@ public class LineVersionsData implements CommandLineRunner { @@ -33,9 +33,7 @@ public class LineVersionsData implements CommandLineRunner {
33 StationRouteService stationRouteService; 33 StationRouteService stationRouteService;
34 34
35 @Override 35 @Override
36 - public void run(String... arg0) throws Exception {  
37 -  
38 - 36 + public void run() {
39 try { 37 try {
40 List<LineVersions> list = lineVersionsService.lineUpdate(); 38 List<LineVersions> list = lineVersionsService.lineUpdate();
41 for (LineVersions lineVersions : list) { 39 for (LineVersions lineVersions : list) {
@@ -44,10 +42,11 @@ public class LineVersionsData implements CommandLineRunner { @@ -44,10 +42,11 @@ public class LineVersionsData implements CommandLineRunner {
44 Map<String, Object> map = new HashMap<>(); 42 Map<String, Object> map = new HashMap<>();
45 map.put("lineId", lineId); 43 map.put("lineId", lineId);
46 stationRouteService.usingSingle(map); 44 stationRouteService.usingSingle(map);
  45 + logger.info("线路版本更新成功!");
47 } 46 }
48 } catch (Exception e) { 47 } catch (Exception e) {
49 - // TODO Auto-generated catch block  
50 e.printStackTrace(); 48 e.printStackTrace();
  49 + logger.error("线路版本更新出现异常!", e);
51 } 50 }
52 } 51 }
53 } 52 }
src/main/java/com/bsth/data/ThreadMonotor.java
1 package com.bsth.data; 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 import org.slf4j.Logger; 3 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
9 import org.springframework.stereotype.Component; 5 import org.springframework.stereotype.Component;
@@ -20,26 +16,26 @@ public class ThreadMonotor extends Thread{ @@ -20,26 +16,26 @@ public class ThreadMonotor extends Thread{
20 public void run() { 16 public void run() {
21 17
22 //线调GPS分析主线程 18 //线调GPS分析主线程
23 - if(GpsRealAnalyse.isBlock()){ 19 + /*if(GpsRealAnalyse.isBlock()){
24 log.warn("GpsRealAnalyse isBlock true !!!!"); 20 log.warn("GpsRealAnalyse isBlock true !!!!");
25 GpsRealAnalyse.shutdown(); 21 GpsRealAnalyse.shutdown();
26 - } 22 + }*/
27 23
28 - if(GpsRealAnalyse.isIdle()){ 24 + /*if(GpsRealAnalyse.isIdle()){
29 //切换到备用的网关实时GPS对照数据 25 //切换到备用的网关实时GPS对照数据
30 GpsDataLoaderThread.setFlag(-1); 26 GpsDataLoaderThread.setFlag(-1);
31 - } 27 + }*/
32 28
33 //webSocket 消息推送队列 29 //webSocket 消息推送队列
34 - if(WebSocketPushQueue.isIdle()){ 30 + /*if(WebSocketPushQueue.isIdle()){
35 log.warn("WebSocketPushQueue isIdle true !!!!"); 31 log.warn("WebSocketPushQueue isIdle true !!!!");
36 WebSocketPushQueue.start(); 32 WebSocketPushQueue.start();
37 - } 33 + }*/
38 34
39 //网关指令推送队列(系统自动发送的) 35 //网关指令推送队列(系统自动发送的)
40 - if(DirectivePushQueue.isIdle()){ 36 + /*if(DirectivePushQueue.isIdle()){
41 log.warn("DirectivePushQueue isIdle true !!!!"); 37 log.warn("DirectivePushQueue isIdle true !!!!");
42 DirectivePushQueue.start(); 38 DirectivePushQueue.start();
43 - } 39 + }*/
44 } 40 }
45 } 41 }
46 \ No newline at end of file 42 \ No newline at end of file
src/main/java/com/bsth/data/directive/DayOfDirectives.java
@@ -152,13 +152,14 @@ public class DayOfDirectives { @@ -152,13 +152,14 @@ public class DayOfDirectives {
152 152
153 public void clear(String device){ 153 public void clear(String device){
154 int c60 = 0, c64 = 0; 154 int c60 = 0, c64 = 0;
155 - //找到该设备的60数据 155 +
156 Collection<D60> d60s = d60Map.values(); 156 Collection<D60> d60s = d60Map.values();
157 List<D60> rem60List = new ArrayList<>(); 157 List<D60> rem60List = new ArrayList<>();
158 for(D60 d60 : d60s){ 158 for(D60 d60 : d60s){
159 if(device.equals(d60.getDeviceId())) 159 if(device.equals(d60.getDeviceId()))
160 rem60List.add(d60); 160 rem60List.add(d60);
161 } 161 }
  162 +
162 //清除60数据 163 //清除60数据
163 for(D60 d60 : rem60List){ 164 for(D60 d60 : rem60List){
164 if(d60.getReply47() == null) 165 if(d60.getReply47() == null)
@@ -166,6 +167,8 @@ public class DayOfDirectives { @@ -166,6 +167,8 @@ public class DayOfDirectives {
166 if(null != d60Map.remove(d60.getMsgId())) 167 if(null != d60Map.remove(d60.getMsgId()))
167 c60 ++; 168 c60 ++;
168 } 169 }
  170 +
  171 + rem60List.clear();
169 if(c60 > 0) 172 if(c60 > 0)
170 logger.info("清除60数据 ," + c60); 173 logger.info("清除60数据 ," + c60);
171 174
@@ -186,6 +189,7 @@ public class DayOfDirectives { @@ -186,6 +189,7 @@ public class DayOfDirectives {
186 c64 ++; 189 c64 ++;
187 } 190 }
188 191
  192 + rem64List.clear();
189 if(c64 > 0) 193 if(c64 > 0)
190 logger.info("清除64数据 ," + c64); 194 logger.info("清除64数据 ," + c64);
191 } 195 }
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
@@ -4,8 +4,8 @@ import com.bsth.data.forecast.entity.ForecastResult; @@ -4,8 +4,8 @@ import com.bsth.data.forecast.entity.ForecastResult;
4 import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem; 4 import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem;
5 import com.bsth.data.forecast.entity.SimpleRoute; 5 import com.bsth.data.forecast.entity.SimpleRoute;
6 import com.bsth.data.forecast.entity.SimpleRoute.TimeRange; 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 import com.bsth.data.schedule.DayOfSchedule; 9 import com.bsth.data.schedule.DayOfSchedule;
10 import com.bsth.entity.realcontrol.ScheduleRealInfo; 10 import com.bsth.entity.realcontrol.ScheduleRealInfo;
11 import com.google.common.collect.ArrayListMultimap; 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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 \ No newline at end of file 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; 1 +package com.bsth.data.gpsdata_v2;
2 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; 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.*;
8 import com.google.common.collect.ArrayListMultimap; 6 import com.google.common.collect.ArrayListMultimap;
9 import org.slf4j.Logger; 7 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
11 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
13 11
14 -import java.util.*; 12 +import java.util.ArrayList;
  13 +import java.util.List;
  14 +import java.util.Set;
15 import java.util.concurrent.CountDownLatch; 15 import java.util.concurrent.CountDownLatch;
16 import java.util.concurrent.ExecutorService; 16 import java.util.concurrent.ExecutorService;
17 import java.util.concurrent.Executors; 17 import java.util.concurrent.Executors;
  18 +import java.util.concurrent.ThreadFactory;
18 19
19 /** 20 /**
20 - * gps 实时数据分析  
21 - * Created by panzhao on 2016/12/27. 21 + * 实时信号数据处理
  22 + * Created by panzhao on 2017/11/15.
22 */ 23 */
23 @Component 24 @Component
24 -public class GpsRealAnalyse { 25 +public class DataHandleProcess {
25 26
26 - static Logger logger = LoggerFactory.getLogger(GpsRealAnalyse.class); 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;
27 32
28 @Autowired 33 @Autowired
29 - OfflineSignalHandle offlineSignalHandle; 34 + GpsStateProcess gpsStateProcess;
30 @Autowired 35 @Autowired
31 - CorrectSignalHandle correctSignalHandle; 36 + StationInsideProcess stationInsideProcess;
32 @Autowired 37 @Autowired
33 - StationInsideHandle stationInsideHandle; 38 + AbnormalStateProcess abnormalStateProcess;
34 @Autowired 39 @Autowired
35 - InOutStationSignalHandle inOutStationSignalHandle; 40 + InStationProcess inStationProcess;
36 @Autowired 41 @Autowired
37 - ReverseSignalHandle reverseSignalHandle; 42 + OutStationProcess outStationProcess;
38 @Autowired 43 @Autowired
39 - AbnormalStateHandle abnormalStateHandle; 44 + ReverseRouteProcess reverseRouteProcess;
40 45
41 @Autowired 46 @Autowired
42 GpsRealData gpsRealData; 47 GpsRealData gpsRealData;
43 48
44 - final static int POOL_SIZE = 25;  
45 - static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1);  
46 -  
47 - public static long st;  
48 - public static CountDownLatch count;  
49 -  
50 - public static boolean isBlock() {  
51 - return System.currentTimeMillis() - st > 1000 * 20;  
52 - }  
53 -  
54 - public static boolean isIdle(){  
55 - return System.currentTimeMillis() - st > 1000 * 60;  
56 - }  
57 -  
58 - public void analyse(List<GpsEntity> list) { 49 + public void handle(List<GpsEntity> list) {
59 try { 50 try {
60 - if(list.size() == 0 || GpsDataRecovery.run)  
61 - return;  
62 - st = System.currentTimeMillis();  
63 -  
64 - //按设备号分组数据(一个设备号的多条数据,必须在一个线程里跑) 51 + //按设备号分组数据(一个设备的多条数据,必须在一个线程里跑)
65 ArrayListMultimap multimap = ArrayListMultimap.create(); 52 ArrayListMultimap multimap = ArrayListMultimap.create();
66 for (GpsEntity gps : list) { 53 for (GpsEntity gps : list) {
67 multimap.put(gps.getDeviceId(), gps); 54 multimap.put(gps.getDeviceId(), gps);
@@ -70,10 +57,10 @@ public class GpsRealAnalyse { @@ -70,10 +57,10 @@ public class GpsRealAnalyse {
70 57
71 //数据均分给线程 58 //数据均分给线程
72 ArrayListMultimap dataListMap = ArrayListMultimap.create(); 59 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 ++; 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++;
77 dataListMap.putAll(threadIndex, multimap.get(deviceList.get(i))); 64 dataListMap.putAll(threadIndex, multimap.get(deviceList.get(i)));
78 } 65 }
79 Set<Integer> ks = dataListMap.keySet(); 66 Set<Integer> ks = dataListMap.keySet();
@@ -81,7 +68,7 @@ public class GpsRealAnalyse { @@ -81,7 +68,7 @@ public class GpsRealAnalyse {
81 count = new CountDownLatch(ks.size()); 68 count = new CountDownLatch(ks.size());
82 69
83 for (Integer index : ks) { 70 for (Integer index : ks) {
84 - threadPool.execute(new SignalHandleThread(dataListMap.get(index), count)); 71 + threadPool.submit(new SignalHandleThread(dataListMap.get(index), count));
85 } 72 }
86 73
87 //等待子线程结束 74 //等待子线程结束
@@ -90,26 +77,11 @@ public class GpsRealAnalyse { @@ -90,26 +77,11 @@ public class GpsRealAnalyse {
90 //加入实时gps对照 77 //加入实时gps对照
91 for (GpsEntity gps : list) 78 for (GpsEntity gps : list)
92 gpsRealData.put(gps); 79 gpsRealData.put(gps);
93 -  
94 - logger.info("time , " + (System.currentTimeMillis() - st));  
95 } catch (Exception e) { 80 } catch (Exception e) {
96 logger.error("", e); 81 logger.error("", e);
97 } 82 }
98 } 83 }
99 84
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 { 85 public class SignalHandleThread implements Runnable {
114 86
115 List<GpsEntity> list; 87 List<GpsEntity> list;
@@ -122,31 +94,18 @@ public class GpsRealAnalyse { @@ -122,31 +94,18 @@ public class GpsRealAnalyse {
122 94
123 @Override 95 @Override
124 public void run() { 96 public void run() {
125 -  
126 try { 97 try {
127 - Collections.sort(list, comp);  
128 for (GpsEntity gps : list) { 98 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); 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缓存
150 }catch (Exception e){ 109 }catch (Exception e){
151 logger.error("", e); 110 logger.error("", e);
152 } 111 }
@@ -158,11 +117,19 @@ public class GpsRealAnalyse { @@ -158,11 +117,19 @@ public class GpsRealAnalyse {
158 } 117 }
159 } 118 }
160 119
161 - public static class GpsComp implements Comparator<GpsEntity> { 120 + static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
  121 + @Override
  122 + public void uncaughtException(Thread t, Throwable e) {
  123 + logger.error("caught " , e);
  124 + }
  125 + }
162 126
  127 + static class HandlerThreadFactory implements ThreadFactory {
163 @Override 128 @Override
164 - public int compare(GpsEntity g1, GpsEntity g2) {  
165 - return g1.getTimestamp().compareTo(g2.getTimestamp()); 129 + public Thread newThread(Runnable r) {
  130 + Thread t = new Thread(r);
  131 + t.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
  132 + return t;
166 } 133 }
167 } 134 }
168 } 135 }
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; 1 +package com.bsth.data.gpsdata_v2;
2 2
3 import com.bsth.data.BasicData; 3 import com.bsth.data.BasicData;
4 import com.bsth.data.forecast.ForecastRealServer; 4 import com.bsth.data.forecast.ForecastRealServer;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
5 import com.bsth.data.schedule.DayOfSchedule; 6 import com.bsth.data.schedule.DayOfSchedule;
6 import com.bsth.entity.realcontrol.ScheduleRealInfo; 7 import com.bsth.entity.realcontrol.ScheduleRealInfo;
7 import com.google.common.collect.TreeMultimap; 8 import com.google.common.collect.TreeMultimap;
@@ -130,7 +131,7 @@ public class GpsRealData { @@ -130,7 +131,7 @@ public class GpsRealData {
130 for (String device : set) { 131 for (String device : set) {
131 gps = gpsMap.get(device); 132 gps = gpsMap.get(device);
132 //过滤异常GPS数据 133 //过滤异常GPS数据
133 - if (gps == null || gps.isIncomplete()) 134 + if (gps == null || StringUtils.isBlank(gps.getNbbm()))
134 continue; 135 continue;
135 136
136 sch = dayOfSchedule.execPlanMap().get(gps.getNbbm()); 137 sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());
src/main/java/com/bsth/data/gpsdata_v2/cache/GeoCacheData.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.cache;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.CtLineString;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.entity.PreconditionGeo;
  6 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  7 +import com.bsth.data.gpsdata_v2.utils.StationRouteComp;
  8 +import com.bsth.util.Geo.Point;
  9 +import com.bsth.util.Geo.Polygon;
  10 +import com.google.common.base.Splitter;
  11 +import com.google.common.collect.ArrayListMultimap;
  12 +import org.apache.commons.lang3.StringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  17 +import org.springframework.jdbc.core.JdbcTemplate;
  18 +import org.springframework.jdbc.core.RowMapper;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import java.sql.ResultSet;
  22 +import java.sql.SQLException;
  23 +import java.util.*;
  24 +
  25 +/**
  26 + * 空间数据缓存
  27 + * Created by panzhao on 2017/11/15.
  28 + */
  29 +@Component
  30 +public class GeoCacheData {
  31 +
  32 + static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);
  33 +
  34 + /**
  35 + * 线路路段走向
  36 + */
  37 + private static ArrayListMultimap<String, CtLineString> sectionCacheMap;
  38 + /**
  39 + * 路段编码和名称对照
  40 + */
  41 + private static Map<String, String> sectionCode2Name;
  42 + /**
  43 + * 线路站点路由
  44 + */
  45 + private static ArrayListMultimap<String, StationRoute> stationCacheMap;
  46 + /**
  47 + * 线路前置进站围栏
  48 + */
  49 + public static ArrayListMultimap<String, PreconditionGeo> premiseGeoMap;
  50 + /**
  51 + * 线路_上下行_站点编码 ——> 站点
  52 + */
  53 + private static Map<String, StationRoute> routeCodeMap;
  54 + /**
  55 + * 停车场
  56 + */
  57 + public static Map<String, Polygon> tccMap;
  58 + /**
  59 + * 线路限速信息
  60 + */
  61 + private static Map<String, Double> speedLimitMap;
  62 +
  63 + @Autowired
  64 + JdbcTemplate jdbcTemplate;
  65 +
  66 + public void loadData() {
  67 + loadStationRoutesData();
  68 + loadTccMapData();
  69 + loadSpeedLimit();
  70 +
  71 + //加载路段信息
  72 + loadRoadsData();
  73 +
  74 + //加载前置进站围栏
  75 + loadPremiseGeoData();
  76 + }
  77 +
  78 + public static List<StationRoute> getStationRoute(String lineCode, int directions) {
  79 + return stationCacheMap.get(lineCode + "_" + directions);
  80 + }
  81 +
  82 + public static StationRoute getRouteCode(GpsEntity gps) {
  83 + return routeCodeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo());
  84 + }
  85 +
  86 + public static Double speedLimit(String lineCode){
  87 + return speedLimitMap.get(lineCode);
  88 + }
  89 +
  90 + public static List<CtLineString> getLineStringList(GpsEntity gps){
  91 + return sectionCacheMap.get(gps.getLineId() + "_" + gps.getUpDown());
  92 + }
  93 +
  94 + private void loadStationRoutesData(){
  95 + String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE,s.STATION_NAME from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code";
  96 + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
  97 +
  98 + @Override
  99 + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
  100 + StationRoute sRoute = new StationRoute();
  101 + sRoute.setCode(rs.getString("STATION_CODE"));
  102 + sRoute.setLineCode(rs.getString("LINE_CODE"));
  103 + sRoute.setDirections(rs.getInt("DIRECTIONS"));
  104 + sRoute.setPoint(new Point(rs.getFloat("G_LONX"), rs.getFloat("G_LATY")));
  105 + sRoute.setRadius(rs.getFloat("RADIUS"));
  106 + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
  107 + sRoute.setMark(rs.getString("STATION_MARK"));
  108 + sRoute.setName(rs.getString("STATION_NAME"));
  109 +
  110 + String shapesType = rs.getString("SHAPES_TYPE");
  111 + //多边形电子围栏
  112 + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d"))
  113 + sRoute.setPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));
  114 + return sRoute;
  115 + }
  116 + });
  117 +
  118 + //按线路和走向分组
  119 + if (routeList.size() > 0) {
  120 + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
  121 + Map<String, StationRoute> codeMap = new HashMap<>(routeList.size());
  122 + for (StationRoute sr : routeList) {
  123 + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  124 + //站点编码 ——> 和路由顺序对照
  125 + codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr);
  126 + }
  127 +
  128 + StationRouteComp srCom = new StationRouteComp();
  129 + //连接路由
  130 + Set<String> set = tempMap.keySet();
  131 + for (String key : set) {
  132 + Collections.sort(tempMap.get(key), srCom);
  133 + connectStationRoute(tempMap.get(key));
  134 + }
  135 + stationCacheMap = tempMap;
  136 + routeCodeMap = codeMap;
  137 + }
  138 + }
  139 +
  140 + private void loadTccMapData(){
  141 + //加载停车场数据
  142 + String sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null";
  143 + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
  144 + Map<String, Polygon> tccTempMap = new HashMap<>();
  145 +
  146 + Polygon polygon;
  147 + for (Map<String, Object> tMap : tccList) {
  148 +
  149 + try {
  150 + polygon = parsePolygon(tMap.get("G_PARK_POINT").toString());
  151 + tccTempMap.put(tMap.get("PARK_CODE").toString()
  152 + , polygon);
  153 + } catch (Exception e) {
  154 + logger.error("停车场:" + tMap.get("PARK_CODE"), e);
  155 + }
  156 + }
  157 + if (tccTempMap.size() > 0){
  158 + tccMap = tccTempMap;
  159 + }
  160 + }
  161 +
  162 + private void loadSpeedLimit(){
  163 + //加载线路限速信息
  164 + String sql = "select l.LINE_CODE,i.SPEEDING from bsth_c_line_information i left join bsth_c_line l on i.line=l.id where i.speed_limit is not null";
  165 + List<Map<String, Object>> speedMap = jdbcTemplate.queryForList(sql);
  166 + Map<String, Double> speedTempMap = new HashMap<>();
  167 + for (Map<String, Object> tMap : speedMap) {
  168 + try {
  169 + speedTempMap.put(tMap.get("LINE_CODE").toString(), Double.parseDouble(tMap.get("SPEEDING").toString()));
  170 + } catch (NumberFormatException e) {
  171 + logger.error("speeding is null...");
  172 + }
  173 + }
  174 + speedLimitMap = speedTempMap;
  175 + }
  176 +
  177 + private void loadRoadsData() {
  178 + //加载线路下路段空间数据
  179 + String sql = "select r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) as GSECTION_VECTOR, r.DIRECTIONS, s.CROSES_ROAD from bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section=s.id where r.destroy=0 and GSECTION_VECTOR is not null order by line_code,directions,sectionroute_code";
  180 + List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql);
  181 +
  182 + String polygonStr, key;
  183 + String[] coords;
  184 + int i, len;
  185 + ArrayListMultimap<String, CtLineString> sectionCacheTempMap = ArrayListMultimap.create();
  186 + String[] temps1, temps2;
  187 + CtLineString lineString;
  188 + for (Map<String, Object> tMap : secList) {
  189 + //空间数据映射
  190 + polygonStr = tMap.get("GSECTION_VECTOR").toString();
  191 + key = tMap.get("LINE_CODE") + "_" + tMap.get("DIRECTIONS");
  192 +
  193 + coords = polygonStr.substring(11, polygonStr.length() - 1).split(",");
  194 + len = coords.length - 1;
  195 + //每2个点连一条线
  196 + for(i = 0; i < len; i ++){
  197 + temps1 = coords[i].split(" ");
  198 + temps2 = coords[i + 1].split(" ");
  199 +
  200 + lineString = new CtLineString();
  201 + lineString.setS(new Point(Float.parseFloat(temps1[0]), Float.parseFloat(temps1[1])));
  202 + lineString.setE(new Point(Float.parseFloat(temps2[0]), Float.parseFloat(temps2[1])));
  203 +
  204 + sectionCacheTempMap.put(key, lineString);
  205 + }
  206 + }
  207 +
  208 + if(sectionCacheTempMap.size() > 0)
  209 + sectionCacheMap = sectionCacheTempMap;
  210 +
  211 + Map<String, String> sectionCode2NameTemp = new HashMap<>();
  212 +
  213 + //加载全量路段编码和名称对照
  214 + sql = "select SECTION_CODE,SECTION_NAME,CROSES_ROAD from bsth_c_section";
  215 + secList = jdbcTemplate.queryForList(sql);
  216 + String name = null, code;
  217 + for (Map<String, Object> tMap : secList) {
  218 + if(tMap.get("CROSES_ROAD") != null && StringUtils.isNotEmpty(tMap.get("CROSES_ROAD").toString()))
  219 + name = tMap.get("CROSES_ROAD").toString();
  220 + else if(tMap.get("SECTION_NAME") != null && StringUtils.isNotEmpty(tMap.get("SECTION_NAME").toString()))
  221 + name = tMap.get("SECTION_NAME").toString();
  222 +
  223 + code = tMap.get("SECTION_CODE").toString();
  224 + sectionCode2NameTemp.put(code, name);
  225 + }
  226 + if(sectionCode2NameTemp.size() > 0)
  227 + sectionCode2Name = sectionCode2NameTemp;
  228 + }
  229 +
  230 + private void loadPremiseGeoData() {
  231 + ArrayListMultimap<String, PreconditionGeo> premiseGeoMapCopy = ArrayListMultimap.create();
  232 +
  233 + String sql = "select * from bsth_f_geo_premise";
  234 + List<PreconditionGeo> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PreconditionGeo.class));
  235 +
  236 + List<String> coordList;
  237 + String[] cs;
  238 + Point point;
  239 + List<Point> ps;
  240 + StationRoute sr;
  241 + for(PreconditionGeo p : list){
  242 + try{
  243 + sr = routeCodeMap.get(p.getLineCode()+"_"+p.getUpDown()+"_"+p.getStationCode());
  244 + p.setOrder(sr.getRouteSort());
  245 + //polygon
  246 + ps = new ArrayList<>();
  247 + coordList = Splitter.on(",").trimResults().splitToList(p.getCoords());
  248 + for(String c : coordList){
  249 + cs = c.split(" ");
  250 + point = new Point(Double.parseDouble(cs[0]), Double.parseDouble(cs[1]));
  251 + ps.add(point);
  252 + }
  253 +
  254 + p.setPolygon(new Polygon(ps));
  255 +
  256 + sr.setPremise(true);
  257 + //按线路,走向分组
  258 + premiseGeoMapCopy.put(p.getLineCode()+"_"+p.getUpDown(), p);
  259 + }catch (Exception e){
  260 + logger.error("", e);
  261 + }
  262 + }
  263 +
  264 + //排序
  265 + Set<String> ks = premiseGeoMapCopy.keySet();
  266 + PreconditionGeoComp comp = new PreconditionGeoComp();
  267 + for(String k : ks){
  268 + Collections.sort(premiseGeoMapCopy.get(k), comp);
  269 + }
  270 +
  271 + premiseGeoMap = premiseGeoMapCopy;
  272 + }
  273 +
  274 + public Polygon parsePolygon(String polygonStr) {
  275 + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
  276 +
  277 + List<Point> cds = new ArrayList<>(coords.length);
  278 + int len = coords.length;
  279 + for (int i = 0; i < len; i++) {
  280 + temps = coords[i].split(" ");
  281 + cds.add(new Point(Float.parseFloat(temps[1]), Float.parseFloat(temps[0])));
  282 + }
  283 + return new Polygon(cds);
  284 + }
  285 +
  286 + private void connectStationRoute(List<StationRoute> list) {
  287 + int size = list.size();
  288 + StationRoute sr = null;
  289 + for (int i = 0; i < size; i++) {
  290 + sr = list.get(i);
  291 + //上一个
  292 + if (i > 0)
  293 + sr.setPrve(list.get(i - 1));
  294 + //下一个
  295 + if (i < size - 1)
  296 + sr.setNext(list.get(i + 1));
  297 + }
  298 + }
  299 +
  300 + private static class PreconditionGeoComp implements Comparator<PreconditionGeo>{
  301 +
  302 + @Override
  303 + public int compare(PreconditionGeo p1, PreconditionGeo p2) {
  304 + return p1.getOrder() - p2.getOrder();
  305 + }
  306 + }
  307 +
  308 + public static Map<String, String> sectionCode2NameMap(){
  309 + return sectionCode2Name;
  310 + }
  311 +}
src/main/java/com/bsth/data/gpsdata_v2/cache/GpsCacheData.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.cache;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  4 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  5 +import com.bsth.data.gpsdata_v2.entity.trail.GpsExecTrail;
  6 +import com.bsth.data.gpsdata_v2.utils.CircleQueue;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +
  11 +import java.util.*;
  12 +
  13 +/**
  14 + * gps 数据缓存
  15 + * Created by panzhao on 2017/11/15.
  16 + */
  17 +public class GpsCacheData {
  18 +
  19 + /**
  20 + * 每辆车缓存最后300条gps
  21 + */
  22 + private static final int CACHE_SIZE = 300;
  23 + private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>();
  24 +
  25 + /**
  26 + * 车辆执行班次的详细 进出站数据
  27 + */
  28 + private static ArrayListMultimap<String, GpsExecTrail> trailListMultimap = ArrayListMultimap.create();
  29 +
  30 + static Logger logger = LoggerFactory.getLogger(GpsCacheData.class);
  31 +
  32 + public static CircleQueue<GpsEntity> getGps(String device) {
  33 + return gpsCacheMap.get(device);
  34 + }
  35 +
  36 + public static GpsExecTrail gpsExecTrail(String nbbm){
  37 + List<GpsExecTrail> list = trailListMultimap.get(nbbm);
  38 +
  39 + GpsExecTrail trail;
  40 + if(null == list || list.size() == 0
  41 + || list.get(list.size() - 1).isEnd()){
  42 + trail = new GpsExecTrail();
  43 +
  44 + trailListMultimap.put(nbbm, trail);
  45 + }
  46 + else{
  47 + trail = list.get(list.size() - 1);
  48 + }
  49 +
  50 + return trail;
  51 + }
  52 +
  53 + public static void out(GpsEntity gps){
  54 + GpsExecTrail trail = gpsExecTrail(gps.getNbbm());
  55 + trail.getSrs().add(gps);
  56 +
  57 + }
  58 +
  59 + public static void in(GpsEntity gps, boolean end){
  60 + GpsExecTrail trail = gpsExecTrail(gps.getNbbm());
  61 + trail.getSrs().add(gps);
  62 + trail.setEnd(end);
  63 + }
  64 +
  65 + public static GpsEntity getPrev(GpsEntity gps){
  66 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId());
  67 + if(queue != null)
  68 + return queue.getTail();
  69 + return null;
  70 + }
  71 +
  72 + public static void putGps(GpsEntity gps) {
  73 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getDeviceId());
  74 + if (queue == null) {
  75 + queue = new CircleQueue<>(CACHE_SIZE);
  76 + gpsCacheMap.put(gps.getDeviceId(), queue);
  77 + }
  78 + queue.add(gps);
  79 + }
  80 +
  81 + public static void clear(String deviceId) {
  82 + try {
  83 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(deviceId);
  84 + if (queue != null)
  85 + queue.clear();
  86 + } catch (Exception e) {
  87 + logger.error("", e);
  88 + }
  89 + }
  90 +
  91 + public static StationRoute prevStation(GpsEntity gps) {
  92 + List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm());
  93 + if(null == trails || trails.size() == 0)
  94 + return null;
  95 +
  96 + GpsEntity prev;
  97 + for(int i = trails.size() - 1; i > 0; i--){
  98 + prev = trails.get(i).getSrs().peekLast();
  99 +
  100 + if(prev != null){
  101 + return GeoCacheData.getRouteCode(prev);
  102 + }
  103 + }
  104 + return null;
  105 + }
  106 +
  107 + public static List<StationRoute> prevMultiStation(GpsEntity gps) {
  108 + List<StationRoute> rs = new ArrayList<>();
  109 + List<GpsExecTrail> trails = trailListMultimap.get(gps.getNbbm());
  110 + if(null == trails || trails.size() == 0)
  111 + return null;
  112 +
  113 + for(int i = trails.size() - 1; i > 0; i--){
  114 + rs.addAll(searchLinked(trails.get(i).getSrs(), gps.getUpDown()));
  115 + if(rs.size() > 3)
  116 + break;
  117 + }
  118 + return rs;
  119 + }
  120 +
  121 + private static List<StationRoute> searchLinked(LinkedList<GpsEntity> list, int upDown){
  122 + List<StationRoute> rs = new ArrayList<>();
  123 + Iterator<GpsEntity> iterator = list.iterator();
  124 + GpsEntity gps;
  125 + int prevCode=0;
  126 + while (iterator.hasNext()){
  127 + gps = iterator.next();
  128 + if(gps.getInstation()!=1)
  129 + continue;
  130 +
  131 + if(gps.getUpDown() != upDown)
  132 + break;
  133 +
  134 + if(gps.getStation().getRouteSort() != prevCode)
  135 + rs.add(gps.getStation());
  136 +
  137 + prevCode = gps.getStation().getRouteSort();
  138 +
  139 + if(rs.size() >= 3)
  140 + break;
  141 + }
  142 + return rs;
  143 + }
  144 +}
src/main/java/com/bsth/data/gpsdata_v2/entity/CtLineString.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.entity;
  2 +
  3 +import com.bsth.util.Geo.Point;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * Created by panzhao on 2017/11/15.
  9 + */
  10 +public class CtLineString {
  11 +
  12 + public CtLineString(){}
  13 + public CtLineString(List<Point> ps){
  14 + s = ps.get(0);
  15 + e = ps.get(1);
  16 + }
  17 +
  18 + Point s;
  19 +
  20 + Point e;
  21 +
  22 + public Point getS() {
  23 + return s;
  24 + }
  25 +
  26 + public void setS(Point s) {
  27 + this.s = s;
  28 + }
  29 +
  30 + public Point getE() {
  31 + return e;
  32 + }
  33 +
  34 + public void setE(Point e) {
  35 + this.e = e;
  36 + }
  37 +}
src/main/java/com/bsth/data/gpsdata/GpsEntity.java renamed to src/main/java/com/bsth/data/gpsdata_v2/entity/GpsEntity.java
1 -package com.bsth.data.gpsdata; 1 +package com.bsth.data.gpsdata_v2.entity;
2 2
3 -import com.bsth.data.gpsdata.arrival.entity.StationRoute;  
4 import com.fasterxml.jackson.annotation.JsonIgnore; 3 import com.fasterxml.jackson.annotation.JsonIgnore;
5 4
6 /** 5 /**
@@ -66,9 +65,6 @@ public class GpsEntity implements Cloneable{ @@ -66,9 +65,6 @@ public class GpsEntity implements Cloneable{
66 65
67 /** 当前执行班次ID */ 66 /** 当前执行班次ID */
68 private Long schId; 67 private Long schId;
69 -  
70 - /** 是否是不完整的数据 */  
71 - private boolean incomplete;  
72 68
73 private int version; 69 private int version;
74 70
@@ -258,14 +254,6 @@ public class GpsEntity implements Cloneable{ @@ -258,14 +254,6 @@ public class GpsEntity implements Cloneable{
258 this.abnormalStatus = abnormalStatus; 254 this.abnormalStatus = abnormalStatus;
259 } 255 }
260 256
261 - public boolean isIncomplete() {  
262 - return incomplete;  
263 - }  
264 -  
265 - public void setIncomplete(boolean incomplete) {  
266 - this.incomplete = incomplete;  
267 - }  
268 -  
269 public double getOutOfBoundDistance() { 257 public double getOutOfBoundDistance() {
270 return outOfBoundDistance; 258 return outOfBoundDistance;
271 } 259 }
src/main/java/com/bsth/data/gpsdata/arrival/precondition/entity/PreconditionGeo.java renamed to src/main/java/com/bsth/data/gpsdata_v2/entity/PreconditionGeo.java
1 -package com.bsth.data.gpsdata.arrival.precondition.entity; 1 +package com.bsth.data.gpsdata_v2.entity;
2 2
3 import com.bsth.util.Geo.Polygon; 3 import com.bsth.util.Geo.Polygon;
4 4
src/main/java/com/bsth/data/gpsdata/arrival/entity/StationRoute.java renamed to src/main/java/com/bsth/data/gpsdata_v2/entity/StationRoute.java
1 -package com.bsth.data.gpsdata.arrival.entity; 1 +package com.bsth.data.gpsdata_v2.entity;
2 2
3 -import com.vividsolutions.jts.geom.Point;  
4 -import com.vividsolutions.jts.geom.Polygon; 3 +import com.bsth.util.Geo.Point;
  4 +import com.bsth.util.Geo.Polygon;
5 5
6 /** 6 /**
7 * Created by panzhao on 2016/12/23. 7 * Created by panzhao on 2016/12/23.
src/main/java/com/bsth/data/gpsdata_v2/entity/trail/GpsExecTrail.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.entity.trail;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  4 +
  5 +import java.util.LinkedList;
  6 +
  7 +/**
  8 + * GPS 班次执行轨迹,过程数据
  9 + * Created by panzhao on 2017/11/16.
  10 + */
  11 +public class GpsExecTrail {
  12 +
  13 + /**
  14 + * 执行的班次ID
  15 + */
  16 + private Long schId;
  17 +
  18 + /**
  19 + * 实际经过的站点路由
  20 + */
  21 + private LinkedList<GpsEntity> srs = new LinkedList<>();
  22 +
  23 + /**
  24 + * 车辆编码
  25 + */
  26 + private String nbbm;
  27 +
  28 + /**
  29 + * 是否结束
  30 + */
  31 + private boolean end;
  32 +
  33 + public Long getSchId() {
  34 + return schId;
  35 + }
  36 +
  37 + public void setSchId(Long schId) {
  38 + this.schId = schId;
  39 + }
  40 +
  41 + public LinkedList<GpsEntity> getSrs() {
  42 + return srs;
  43 + }
  44 +
  45 + public void setSrs(LinkedList<GpsEntity> srs) {
  46 + this.srs = srs;
  47 + }
  48 +
  49 + public String getNbbm() {
  50 + return nbbm;
  51 + }
  52 +
  53 + public void setNbbm(String nbbm) {
  54 + this.nbbm = nbbm;
  55 + }
  56 +
  57 + public boolean isEnd() {
  58 + return end;
  59 + }
  60 +
  61 + public void setEnd(boolean end) {
  62 + this.end = end;
  63 + }
  64 +}
src/main/java/com/bsth/data/gpsdata/arrival/handlers/AbnormalStateHandle.java renamed to src/main/java/com/bsth/data/gpsdata_v2/handlers/AbnormalStateProcess.java
1 -package com.bsth.data.gpsdata.arrival.handlers;  
2 -  
3 -import com.bsth.data.gpsdata.GpsEntity;  
4 -import com.bsth.data.gpsdata.arrival.GeoCacheData;  
5 -import com.bsth.data.gpsdata.arrival.SignalHandle;  
6 -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;  
7 -import com.bsth.data.gpsdata.arrival.utils.GeoUtils;  
8 -import com.vividsolutions.jts.geom.Coordinate;  
9 -import com.vividsolutions.jts.geom.GeometryFactory;  
10 -import com.vividsolutions.jts.geom.LineString;  
11 -import com.vividsolutions.jts.geom.Point; 1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  4 +import com.bsth.data.gpsdata_v2.entity.CtLineString;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.gpsdata_v2.utils.GeoUtils;
  7 +import com.bsth.util.Geo.Point;
12 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
13 9
14 import java.util.List; 10 import java.util.List;
15 11
16 /** 12 /**
17 - * GPS异常状态判定 (越界/超速)  
18 - * Created by panzhao on 2017/1/10. 13 + * 越界/超速 判断
  14 + * Created by panzhao on 2017/11/16.
19 */ 15 */
20 @Component 16 @Component
21 -public class AbnormalStateHandle extends SignalHandle{ 17 +public class AbnormalStateProcess {
22 18
23 - //默认限速 19 + /**
  20 + * 默认限速
  21 + */
24 private static final double DEFAULT_SPEED_LIMIT = 60; 22 private static final double DEFAULT_SPEED_LIMIT = 60;
25 - //越界阈值 23 + /**
  24 + * 越界阈值
  25 + */
26 private static final double OUT_BOUNDS_THRESHOLD = 100; 26 private static final double OUT_BOUNDS_THRESHOLD = 100;
27 27
28 - GeometryFactory geometryFactory = new GeometryFactory();  
29 -  
30 - @Override  
31 - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) {  
32 28
  29 + public void process(GpsEntity gps) {
33 if(isOffline(gps)) 30 if(isOffline(gps))
34 - return false; 31 + return;
35 32
36 if(overspeed(gps)) 33 if(overspeed(gps))
37 - return true; 34 + return;
38 35
39 if(outOfBounds((gps))) 36 if(outOfBounds((gps)))
40 - return true; 37 + return;
  38 + }
41 39
42 - return false; 40 + private boolean isOffline(GpsEntity gps){
  41 + return gps.getAbnormalStatus() != null && gps.getAbnormalStatus().equals("offline");
43 } 42 }
44 43
  44 +
45 /** 45 /**
46 * 是否超速 46 * 是否超速
47 * @param gps 47 * @param gps
48 * @return 48 * @return
49 */ 49 */
50 - public boolean overspeed(GpsEntity gps){ 50 + private boolean overspeed(GpsEntity gps){
51 double maxSpeed = DEFAULT_SPEED_LIMIT; 51 double maxSpeed = DEFAULT_SPEED_LIMIT;
52 if(GeoCacheData.speedLimit(gps.getLineId()) != null) 52 if(GeoCacheData.speedLimit(gps.getLineId()) != null)
53 maxSpeed = GeoCacheData.speedLimit(gps.getLineId()); 53 maxSpeed = GeoCacheData.speedLimit(gps.getLineId());
@@ -59,24 +59,25 @@ public class AbnormalStateHandle extends SignalHandle{ @@ -59,24 +59,25 @@ public class AbnormalStateHandle extends SignalHandle{
59 return false; 59 return false;
60 } 60 }
61 61
  62 +
62 /** 63 /**
63 * 是否越界 64 * 是否越界
64 * @param gps 65 * @param gps
65 * @return 66 * @return
66 */ 67 */
67 public boolean outOfBounds(GpsEntity gps){ 68 public boolean outOfBounds(GpsEntity gps){
68 - //只处理电子围栏外的车 69 + //只处理场站外的车
69 if(gps.getInstation() != 0){ 70 if(gps.getInstation() != 0){
70 return false; 71 return false;
71 } 72 }
72 73
73 - List<LineString> list = GeoCacheData.getLineStringList(gps);  
74 - Point point = geometryFactory.createPoint(new Coordinate(gps.getLat(), gps.getLon())); 74 + List<CtLineString> list = GeoCacheData.getLineStringList(gps);
  75 + Point point = new Point(gps.getLon(), gps.getLat());
75 76
76 double min = -1, distance; 77 double min = -1, distance;
77 78
78 - for(LineString lineString : list){  
79 - distance = GeoUtils.getDistanceFromLine(lineString, point); 79 + for(CtLineString lineString : list){
  80 + distance = GeoUtils.getDistanceFromLine(lineString.getS(),lineString.getE(), point);
80 81
81 if(min == -1 || min > distance) 82 if(min == -1 || min > distance)
82 min = distance; 83 min = distance;
src/main/java/com/bsth/data/gpsdata_v2/handlers/GpsStateProcess.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  4 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  5 +import com.bsth.data.schedule.DayOfSchedule;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Component;
  9 +
  10 +/**
  11 + * GPS 状态处理
  12 + * Created by panzhao on 2017/11/15.
  13 + */
  14 +@Component
  15 +public class GpsStateProcess {
  16 +
  17 + @Autowired
  18 + DayOfSchedule dayOfSchedule;
  19 +
  20 + @Autowired
  21 + GpsStatusManager gpsStatusManager;
  22 +
  23 + public void process(GpsEntity gps){
  24 + //在执行的任务
  25 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  26 +
  27 + if(null == sch)
  28 + return;
  29 +
  30 + byte upDown = Byte.parseByte(sch.getXlDir());
  31 +
  32 + if(gps.getUpDown() != upDown){
  33 + gps.setUpDown(upDown);//修正走向
  34 + }
  35 +
  36 + if((!gps.isService() || gps.getUpDown() != upDown) &&
  37 + !dayOfSchedule.emptyService(sch)){
  38 + //下发指令纠正车载的 营运状态 和 走向
  39 + gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, 0, "同步@系统");
  40 + }
  41 +
  42 + if(!sch.getXlBm().equals(gps.getLineId())){
  43 + //切换车载的 线路编码
  44 + gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统");
  45 + }
  46 + }
  47 +}
src/main/java/com/bsth/data/gpsdata_v2/handlers/InStationProcess.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  5 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  6 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  7 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  8 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  9 +import com.bsth.data.gpsdata_v2.utils.GeoUtils;
  10 +import com.bsth.data.msg_queue.DirectivePushQueue;
  11 +import com.bsth.data.schedule.DayOfSchedule;
  12 +import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
  13 +import com.bsth.entity.realcontrol.LineConfig;
  14 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  15 +import com.bsth.websocket.handler.SendUtils;
  16 +import org.apache.commons.lang3.StringUtils;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.stereotype.Component;
  21 +
  22 +import java.util.List;
  23 +
  24 +/**
  25 + * 车辆到站处理程序
  26 + * Created by panzhao on 2017/11/16.
  27 + */
  28 +@Component
  29 +public class InStationProcess {
  30 +
  31 + @Autowired
  32 + DayOfSchedule dayOfSchedule;
  33 +
  34 + @Autowired
  35 + LineConfigData lineConfigData;
  36 +
  37 + @Autowired
  38 + SendUtils sendUtils;
  39 +
  40 + @Autowired
  41 + GpsStatusManager gpsStatusManager;
  42 +
  43 + Logger logger = LoggerFactory.getLogger(this.getClass());
  44 +
  45 + public void process(GpsEntity gps){
  46 + GpsEntity prev = GpsCacheData.getPrev(gps);
  47 +
  48 + if(isInsideStation(gps) &&
  49 + (prev == null || !isInsideStation(prev) || !prev.getStopNo().equals(gps.getStopNo()))){
  50 + inStation(gps, prev); //进站
  51 + }
  52 + }
  53 +
  54 + private boolean isInsideStation(GpsEntity gps){
  55 + return gps.getInstation() >= 1;
  56 + }
  57 +
  58 + /**
  59 + * 进站
  60 + * @param gps
  61 + * @param prev
  62 + */
  63 + private void inStation(GpsEntity gps, GpsEntity prev){
  64 + boolean flow=true;
  65 + //要经过一个中途站才能进
  66 + StationRoute s = GpsCacheData.prevStation(gps);
  67 + List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown());
  68 + if(routes.size() > 3 && null != s && s.getName().equals(gps.getStation().getName())){
  69 + logger.info("没有进中途站,拒绝进站... -" + gps.getNbbm() + " -time:" + gps.getTimestamp());
  70 + flow = false;
  71 + }
  72 +
  73 +
  74 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  75 + boolean isEnd=false;
  76 +
  77 + //进终点
  78 + if(flow && null != sch && sch.getZdzCode().equals(gps.getStopNo())){
  79 + inEndStation(sch, gps);
  80 + isEnd = true;
  81 + }
  82 +
  83 + GpsCacheData.in(gps, isEnd);
  84 + }
  85 +
  86 + /**
  87 + * 进班次终点
  88 + * @param gps
  89 + */
  90 + private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) {
  91 + String nbbm = sch.getClZbh();
  92 + //校验进站前置约束
  93 + if(!validInPremise(gps))
  94 + return;
  95 +
  96 + //实达时间不覆盖
  97 + if(StringUtils.isNotEmpty(sch.getZdsjActual()))
  98 + return;
  99 +
  100 + //应用到离站缓冲区设置参数
  101 + long rsT = lineConfigData.applyIn(sch, gps.getTimestamp());
  102 +
  103 + sch.setZdsjActualAll(rsT);
  104 + sch.setSiginCompate(2);
  105 + //通知误点停靠程序,有车辆到站
  106 + LateAdjustHandle.carArrive(gps);
  107 +
  108 + //持久化
  109 + dayOfSchedule.save(sch);
  110 +
  111 + //车辆的下一个班次
  112 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  113 + if(next != null){
  114 + dayOfSchedule.addExecPlan(next);
  115 + inStationAndInPark(sch, next);//进站既进场
  116 + }
  117 +
  118 + //路牌的下一个班次,页面显示起点实际到达时间
  119 + ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
  120 + if(lpNext != null){
  121 + lpNext.setQdzArrDatesj(sch.getZdsjActual());
  122 + }
  123 +
  124 + //已完成班次数
  125 + int doneSum = dayOfSchedule.doneSum(nbbm);
  126 + //webSocket
  127 + sendUtils.sendZdsj(sch, lpNext, doneSum);
  128 +
  129 + logger.info("车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual());
  130 +
  131 + //清除车辆误点调整监听
  132 + LateAdjustHandle.remove(nbbm);
  133 +
  134 + //将gps转换成下一个班次走向的站内信号(应对只有一个站内信号 即 发出时)
  135 + transformUpDown(gps, next);
  136 +
  137 + //下发调度指令
  138 + DirectivePushQueue.put6002(next, doneSum, "到站@系统");
  139 +
  140 + //套跑 -下发线路切换指令
  141 + if(null != next && !next.getXlBm().equals(sch.getXlBm())){
  142 + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统");
  143 + }
  144 +
  145 + if(null == next && gps.isService())
  146 + nonService(sch, "结束@系统");//班次结束
  147 + else if(dayOfSchedule.emptyService(next))
  148 + nonService(sch, "空驶@系统");//下一班非营运
  149 + }
  150 +
  151 + /**
  152 + * 校验进站前置约束
  153 + * @param gps
  154 + * @return
  155 + */
  156 + private boolean validInPremise(GpsEntity gps) {
  157 + StationRoute sr = gps.getStation();
  158 + if(null == sr || !sr.isPremise())
  159 + return true;
  160 +
  161 + String premiseCode = gps.getPremiseCode();
  162 +
  163 + if(StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())){
  164 + logger.info("满足前置进站约束 " + premiseCode);
  165 + return true;
  166 + }
  167 + else{
  168 + logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode);
  169 + }
  170 + return false;
  171 + }
  172 +
  173 + /**
  174 + * 进站既进场
  175 + * @param sch
  176 + */
  177 + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next){
  178 + LineConfig config = lineConfigData.get(sch.getXlBm());
  179 + //限定出站既出场的停车场
  180 + String park = config.getTwinsPark();
  181 + boolean limitPark = StringUtils.isNotEmpty(park);
  182 +
  183 +
  184 + if (next.getBcType().equals("in") && config.getOutConfig() == 2 && isEmptyMileage(next)
  185 + && (!limitPark || park.equals(next.getZdzCode()))) {
  186 +
  187 + endSch(next, sch.getZdsjActualTime());
  188 +
  189 + sendUtils.refreshSch(next);
  190 + dayOfSchedule.save(next);
  191 +
  192 + //分班的时候,需要再跳过1个班次
  193 + next = dayOfSchedule.next(next);
  194 + if(next != null)
  195 + dayOfSchedule.addExecPlan(next);
  196 +
  197 + //进场,切换成非营运状态
  198 + nonService(sch, "进场@系统");
  199 + }
  200 + }
  201 +
  202 +
  203 + private boolean isEmptyMileage(ScheduleRealInfo sch){
  204 + return sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0;
  205 + }
  206 +
  207 +
  208 + /**
  209 + * 切换为非营运状态
  210 + * @param sch
  211 + * @param sender
  212 + */
  213 + private void nonService(ScheduleRealInfo sch, String sender){
  214 + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);
  215 + }
  216 +
  217 + private void endSch(ScheduleRealInfo sch, Long t){
  218 + sch.setFcsjActualAll(t);
  219 + sch.setZdsjActualAll(t);
  220 + }
  221 +
  222 + private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) {
  223 + if(null == sch)
  224 + return;
  225 + byte upDown = Byte.parseByte(sch.getXlDir());
  226 + //gps 切换走向
  227 + gps.setUpDown(upDown);
  228 + gps.setPremiseCode(null);
  229 +
  230 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown);
  231 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  232 + if (station != null) {
  233 + gps.setStopNo(station.getCode());
  234 + }
  235 + }
  236 +}
src/main/java/com/bsth/data/gpsdata_v2/handlers/OutStationProcess.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  7 +import com.bsth.data.schedule.DayOfSchedule;
  8 +import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
  9 +import com.bsth.entity.realcontrol.LineConfig;
  10 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  11 +import com.bsth.websocket.handler.SendUtils;
  12 +import org.apache.commons.lang3.StringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +/**
  19 + * 车辆出站处理程序
  20 + * Created by panzhao on 2017/11/16.
  21 + */
  22 +@Component
  23 +public class OutStationProcess {
  24 +
  25 + @Autowired
  26 + DayOfSchedule dayOfSchedule;
  27 +
  28 + Logger logger = LoggerFactory.getLogger(this.getClass());
  29 +
  30 + @Autowired
  31 + LineConfigData lineConfigData;
  32 +
  33 + @Autowired
  34 + SendUtils sendUtils;
  35 +
  36 + @Autowired
  37 + GpsStatusManager gpsStatusManager;
  38 +
  39 + public void process(GpsEntity gps){
  40 + GpsEntity prev = GpsCacheData.getPrev(gps);
  41 + if(gps.getInstation()==0 && prev!=null && isInsideStation(prev)){
  42 + outStation(gps); //出站
  43 + }
  44 + }
  45 +
  46 + private boolean isInsideStation(GpsEntity gps){
  47 + return gps.getInstation() >= 1;
  48 + }
  49 +
  50 + /**
  51 + * 出站
  52 + * @param gps
  53 + */
  54 + private void outStation(GpsEntity gps) {
  55 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  56 +
  57 + //起点发车
  58 + if (null != sch && sch.getQdzCode().equals(gps.getStopNo())){
  59 + gps.setPremiseCode(null);//清除前置围栏标记
  60 +
  61 + if(StringUtils.isNotEmpty(sch.getFcsjActual())
  62 + && !outManyFit(gps, sch)){
  63 + return;//班次已经实发
  64 + }
  65 +
  66 + //应用到离站缓冲区设置参数
  67 + long rsT = lineConfigData.applyOut(sch, gps.getTimestamp());
  68 + //实发时间
  69 + sch.setFcsjActualAll(rsT);
  70 + sch.setSiginCompate(1);
  71 +
  72 + //出站既出场
  73 + outStationAndOutPark(sch);
  74 +
  75 + //webSocket
  76 + sendUtils.sendFcsj(sch);
  77 +
  78 + //持久化
  79 + dayOfSchedule.save(sch);
  80 +
  81 + //清理应发未发标记
  82 + LateAdjustHandle.remove(sch.getClZbh());
  83 +
  84 + //发车的时候,同步一下状态
  85 + if(!gps.isService() && !dayOfSchedule.emptyService(sch))
  86 + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统");
  87 +
  88 + logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
  89 + }
  90 +
  91 + GpsCacheData.out(gps);
  92 + }
  93 +
  94 + /**
  95 + * 是否是一个更合适的发车信号
  96 + * @param gps
  97 + * @param sch
  98 + * @return
  99 + */
  100 + private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) {
  101 + LineConfig conf = lineConfigData.get(sch.getXlBm());
  102 + if(null != conf && conf.isLockFirstOutTime())
  103 + return false;
  104 +
  105 + if(StringUtils.isNotEmpty(sch.getZdsjActual()))
  106 + return false;
  107 +
  108 + long t1 = sch.getFcsjActualTime();
  109 + long t2 = gps.getTimestamp();
  110 + long c = sch.getDfsjT();
  111 +
  112 + int threshold = 1000 * 60 * 5;
  113 + if(Math.abs(t2 - c) < threshold && c - t1 > threshold){
  114 + return true;
  115 + }
  116 + return false;
  117 + }
  118 +
  119 + private void outStationAndOutPark(ScheduleRealInfo sch){
  120 + try{
  121 + LineConfig config = lineConfigData.get(sch.getXlBm());
  122 + //限定出站既出场的停车场
  123 + String park = config.getTwinsPark();
  124 + boolean limitPark = StringUtils.isNotEmpty(park);
  125 +
  126 + if (config != null && config.getOutConfig() == 2) {
  127 + //出站既出场
  128 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  129 + if (isOut(schPrev) && isEmptyMileage(schPrev)
  130 + && (!limitPark || park.equals(schPrev.getQdzCode()))) {
  131 +
  132 + endSch(schPrev, sch.getFcsjActualTime());
  133 +
  134 + //起点实到
  135 + sch.setQdzArrDatesj(schPrev.getZdsjActual());
  136 +
  137 + sendUtils.refreshSch(schPrev);
  138 + dayOfSchedule.save(schPrev);
  139 + }
  140 + }
  141 + }catch (Exception e){
  142 + logger.error("", e);
  143 + }
  144 + }
  145 +
  146 + private boolean isEmptyMileage(ScheduleRealInfo sch){
  147 + return sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0;
  148 + }
  149 +
  150 + private boolean isOut(ScheduleRealInfo sch){
  151 + return sch != null && sch.getBcType().equals("out");
  152 + }
  153 +
  154 + private void endSch(ScheduleRealInfo sch, Long t){
  155 + sch.setFcsjActualAll(t);
  156 + sch.setZdsjActualAll(t);
  157 + }
  158 +}
src/main/java/com/bsth/data/gpsdata_v2/handlers/ReverseRouteProcess.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  6 +import com.bsth.data.schedule.DayOfSchedule;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 反向路由处理(进站的时候处理)
  15 + * Created by panzhao on 2017/11/20.
  16 + */
  17 +@Component
  18 +public class ReverseRouteProcess {
  19 +
  20 + private static final int REVER_THRESHOLD = 3;
  21 +
  22 + private static final long TIME_THRESHOLD = 1000 * 60 * 120;
  23 +
  24 + @Autowired
  25 + DayOfSchedule dayOfSchedule;
  26 +
  27 + public void process(GpsEntity gps){
  28 + if(reversRoute(gps)){
  29 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  30 + if(isInOut(sch) || !sch.getXlBm().equals(gps.getLineId()))
  31 + return;
  32 +
  33 + //next
  34 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  35 + if(isInOut(next))
  36 + return;
  37 +
  38 + //跳下一个班次
  39 + if(Math.abs(next.getDfsjT() - gps.getTimestamp()) < TIME_THRESHOLD)
  40 + dayOfSchedule.addExecPlan(next);
  41 + }
  42 + }
  43 +
  44 + private boolean reversRoute(GpsEntity gps) {
  45 + if(gps.getInstation() != 1)
  46 + return false;
  47 +
  48 + int sortNo = gps.getStation().getRouteSort();
  49 + StationRoute prev = GpsCacheData.prevStation(gps);
  50 + //和上一个站点是反向
  51 + if(null != prev && sortNo < prev.getRouteSort()){
  52 +
  53 + //满足3个进站反向信号
  54 + List<StationRoute> prevs = GpsCacheData.prevMultiStation(gps);
  55 +
  56 + int count = 0;
  57 + for(StationRoute s : prevs){
  58 + if(sortNo < s.getRouteSort())
  59 + count ++;
  60 + sortNo = s.getRouteSort();
  61 + }
  62 +
  63 + if(count >= REVER_THRESHOLD)
  64 + return true;
  65 + }
  66 +
  67 + return false;
  68 + }
  69 +
  70 + private boolean isInOut(ScheduleRealInfo sch){
  71 + return sch.getBcType().equals("in") || sch.getBcType().equals("out");
  72 + }
  73 +}
src/main/java/com/bsth/data/gpsdata/arrival/handlers/StationInsideHandle.java renamed to src/main/java/com/bsth/data/gpsdata_v2/handlers/StationInsideProcess.java
1 -package com.bsth.data.gpsdata.arrival.handlers; 1 +package com.bsth.data.gpsdata_v2.handlers;
2 2
3 -import com.bsth.data.gpsdata.GpsEntity;  
4 -import com.bsth.data.gpsdata.arrival.GeoCacheData;  
5 -import com.bsth.data.gpsdata.arrival.SignalHandle;  
6 -import com.bsth.data.gpsdata.arrival.entity.StationRoute;  
7 -import com.bsth.data.gpsdata.arrival.utils.CircleQueue;  
8 -import com.bsth.data.gpsdata.arrival.utils.GeoUtils;  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory; 3 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  4 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  7 +import com.bsth.data.gpsdata_v2.utils.GeoUtils;
11 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
12 9
13 import java.util.List; 10 import java.util.List;
14 11
15 /** 12 /**
16 - * 站内站外判定  
17 - * Created by panzhao on 2016/12/27. 13 + * 站内 场内判定
  14 + * Created by panzhao on 2017/11/16.
18 */ 15 */
19 @Component 16 @Component
20 -public class StationInsideHandle extends SignalHandle { 17 +public class StationInsideProcess {
21 18
22 - Logger logger = LoggerFactory.getLogger(this.getClass());  
23 -  
24 - @Override  
25 - public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { 19 + public void process(GpsEntity gps){
26 //是否在场内 20 //是否在场内
27 String parkCode = GeoUtils.gpsInCarpark(gps); 21 String parkCode = GeoUtils.gpsInCarpark(gps);
  22 +
28 if (parkCode != null) { 23 if (parkCode != null) {
29 gps.setInstation(2); 24 gps.setInstation(2);
30 gps.setStopNo(parkCode); 25 gps.setStopNo(parkCode);
@@ -44,37 +39,18 @@ public class StationInsideHandle extends SignalHandle { @@ -44,37 +39,18 @@ public class StationInsideHandle extends SignalHandle {
44 String premiseCode = GeoUtils.gpsInPremiseGeo(gps); 39 String premiseCode = GeoUtils.gpsInPremiseGeo(gps);
45 gps.setPremiseCode(premiseCode); 40 gps.setPremiseCode(premiseCode);
46 41
47 - if(isNotEmpty(prevs)){  
48 - try {  
49 - GpsEntity prev = prevs.getTail();  
50 - //继承前置围栏  
51 - if(null == premiseCode && null != prev.getPremiseCode())  
52 - gps.setPremiseCode(prev.getPremiseCode()); 42 + //上一个点位
  43 + GpsEntity prev = GpsCacheData.getPrev(gps);
53 44
54 - //在场,站外  
55 - if(gps.getInstation() == 0){  
56 - //继承上一个点的站点编码  
57 - gps.setStopNo(prev.getStopNo()); 45 + if(null != prev){
  46 + //继承前置围栏状态
  47 + if(null == premiseCode && null != prev.getPremiseCode())
  48 + gps.setPremiseCode(prev.getPremiseCode());
58 49
59 - /*if(null == premiseCode && null != prev.getPremiseCode())  
60 - gps.setPremiseCode(prev.getPremiseCode());*/  
61 - }  
62 - /*else if(null != gps.getPremiseCode() && !gps.getStopNo().equals(gps.getPremiseCode())){  
63 - gps.setPremiseCode(null);  
64 - }*/  
65 - }catch (Exception e){  
66 - logger.error("", e); 50 + //在场,站外
  51 + if(gps.getInstation() == 0){
  52 + gps.setStopNo(prev.getStopNo());//继承上一个点的站点编码
67 } 53 }
68 } 54 }
69 -  
70 -/*  
71 - //在场,站外  
72 - if(gps.getInstation() == 0 && isNotEmpty(prevs)){  
73 - //继承上一个点的站点编码  
74 - GpsEntity prev = prevs.getTail();  
75 - gps.setStopNo(prev.getStopNo());  
76 - }  
77 -*/  
78 - return true;  
79 } 55 }
80 } 56 }
src/main/java/com/bsth/data/gpsdata_v2/load/GatewayHttpLoader.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.load;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.data.BasicData;
  5 +import com.bsth.data.gpsdata_v2.GpsRealData;
  6 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  7 +import com.bsth.data.gpsdata_v2.utils.GpsDataUtils;
  8 +import com.bsth.util.ConfigUtil;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.apache.http.HttpEntity;
  11 +import org.apache.http.client.config.RequestConfig;
  12 +import org.apache.http.client.methods.CloseableHttpResponse;
  13 +import org.apache.http.client.methods.HttpGet;
  14 +import org.apache.http.impl.client.CloseableHttpClient;
  15 +import org.apache.http.impl.client.HttpClients;
  16 +import org.slf4j.Logger;
  17 +import org.slf4j.LoggerFactory;
  18 +import org.springframework.beans.BeansException;
  19 +import org.springframework.context.ApplicationContext;
  20 +import org.springframework.context.ApplicationContextAware;
  21 +import org.springframework.stereotype.Component;
  22 +
  23 +import java.io.BufferedReader;
  24 +import java.io.InputStreamReader;
  25 +import java.util.ArrayList;
  26 +import java.util.List;
  27 +
  28 +/**
  29 + * 从网关http 接口加载数据
  30 + * Created by panzhao on 2017/11/15.
  31 + */
  32 +@Component
  33 +public class GatewayHttpLoader implements ApplicationContextAware{
  34 +
  35 + static Logger logger = LoggerFactory.getLogger(GatewayHttpLoader.class);
  36 +
  37 + static String url;
  38 + static List<GpsEntity> list;
  39 + static CloseableHttpClient httpClient = null;
  40 + static HttpGet get;
  41 + static RequestConfig requestConfig;
  42 + static CloseableHttpResponse response;
  43 + static HttpEntity entity;
  44 + static BufferedReader br;
  45 +
  46 + static GpsRealData gpsRealData;
  47 +
  48 + static{
  49 + url = ConfigUtil.get("http.gps.real.url");
  50 + list = new ArrayList<>();
  51 + httpClient = HttpClients.createDefault();
  52 + get = new HttpGet(url);
  53 + requestConfig = RequestConfig.custom()
  54 + .setConnectTimeout(1500).setConnectionRequestTimeout(1000)
  55 + .setSocketTimeout(1500).build();
  56 + get.setConfig(requestConfig);
  57 + }
  58 +
  59 + public static List<GpsEntity> load(){
  60 + try{
  61 + if(list.size() > 0)
  62 + list.clear();
  63 +
  64 + response = httpClient.execute(get);
  65 + entity = response.getEntity();
  66 +
  67 + if(null == entity)
  68 + return list;
  69 +
  70 + br = new BufferedReader(new InputStreamReader(entity.getContent()));
  71 +
  72 + StringBuilder sb = new StringBuilder();
  73 + String str;
  74 + while ((str = br.readLine()) != null)
  75 + sb.append(str);
  76 +
  77 + list = JSON.parseArray(JSON.parseObject(sb.toString()).getString("data"), GpsEntity.class);
  78 + //过滤掉无效的点位
  79 + list = GpsDataUtils.clearInvalid(list);
  80 +
  81 + List<GpsEntity> ups = new ArrayList<>();
  82 + String nbbm;
  83 + for (GpsEntity gps : list) {
  84 + if (StringUtils.isBlank(gps.getDeviceId()))
  85 + continue;
  86 +
  87 + if (gps_equals(gpsRealData.get(gps.getDeviceId()), gps))
  88 + continue;
  89 +
  90 + nbbm = BasicData.deviceId2NbbmMap.get(gps.getDeviceId());
  91 + gps.setNbbm(nbbm);
  92 + ups.add(gps);
  93 + }
  94 + list = ups;
  95 +
  96 + if (null != response)
  97 + response.close();
  98 + }catch (Exception e){
  99 + logger.error("", e);
  100 + }
  101 + return list;
  102 + }
  103 +
  104 +
  105 + private static boolean gps_equals(GpsEntity old, GpsEntity gps){
  106 + if(old != null &&
  107 + old.getTimestamp().equals(gps.getTimestamp()) &&
  108 + old.getLat().equals(gps.getLat()) &&
  109 + old.getLon().equals(gps.getLon()))
  110 + return true;
  111 + return false;
  112 + }
  113 +
  114 + @Override
  115 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  116 + gpsRealData = applicationContext.getBean(GpsRealData.class);
  117 + }
  118 +}
src/main/java/com/bsth/data/gpsdata_v2/load/SocketClientLoader.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.load;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.data.BasicData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.gpsdata_v2.utils.GpsDataUtils;
  7 +import com.bsth.util.ConfigUtil;
  8 +import org.apache.http.HttpEntity;
  9 +import org.apache.http.client.config.RequestConfig;
  10 +import org.apache.http.client.methods.CloseableHttpResponse;
  11 +import org.apache.http.client.methods.HttpGet;
  12 +import org.apache.http.impl.client.CloseableHttpClient;
  13 +import org.apache.http.impl.client.HttpClients;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import java.io.BufferedReader;
  19 +import java.io.InputStreamReader;
  20 +import java.util.ArrayList;
  21 +import java.util.List;
  22 +
  23 +/**
  24 + * 从专用的socket client 加载数据
  25 + * Created by panzhao on 2017/11/15.
  26 + */
  27 +@Component
  28 +public class SocketClientLoader {
  29 +
  30 + static Logger logger = LoggerFactory.getLogger(SocketClientLoader.class);
  31 +
  32 + static String url;
  33 + static List<GpsEntity> list;
  34 + static CloseableHttpClient httpClient = null;
  35 + static HttpGet get;
  36 + static RequestConfig requestConfig;
  37 + static CloseableHttpResponse response;
  38 + static HttpEntity entity;
  39 + static BufferedReader br;
  40 +
  41 + static {
  42 + url = ConfigUtil.get("http.gps.real.cache.url");
  43 + list = new ArrayList<>();
  44 + httpClient = HttpClients.createDefault();
  45 + get = new HttpGet(url);
  46 + requestConfig = RequestConfig.custom()
  47 + .setConnectTimeout(1500).setConnectionRequestTimeout(1000)
  48 + .setSocketTimeout(1500).build();
  49 + get.setConfig(requestConfig);
  50 + }
  51 +
  52 + public static List<GpsEntity> load(){
  53 + try {
  54 + if(list.size() > 0)
  55 + list.clear();
  56 + logger.info("load start...");
  57 + response = httpClient.execute(get);
  58 + entity = response.getEntity();
  59 + if(null == entity)
  60 + return list;
  61 +
  62 + br = new BufferedReader(new InputStreamReader(entity.getContent()));
  63 + StringBuilder sb = new StringBuilder();
  64 + String str;
  65 + while ((str = br.readLine()) != null)
  66 + sb.append(str);
  67 +
  68 + list = JSON.parseArray(sb.toString(), GpsEntity.class);
  69 +
  70 + //过滤掉无效的点位
  71 + list = GpsDataUtils.clearInvalid(list);
  72 +
  73 + logger.info("load end!");
  74 + for (GpsEntity gps : list) {
  75 + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
  76 + }
  77 +
  78 + if (null != response)
  79 + response.close();
  80 + } catch (Exception e) {
  81 + logger.error("", e);
  82 + }
  83 +
  84 + return list;
  85 + }
  86 +}
src/main/java/com/bsth/data/gpsdata_v2/rfid/UploadRfidDataService.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.rfid;
  2 +
  3 +import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation;
  4 +import com.bsth.data.gpsdata_v2.rfid.handle.RfidSignalHandle;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.RequestBody;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RestController;
  9 +
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * RFID 数据上传入口
  14 + * Created by panzhao on 2017/11/22.
  15 + */
  16 +@RestController
  17 +@RequestMapping("/up/rfid")
  18 +public class UploadRfidDataService {
  19 +
  20 + @Autowired
  21 + RfidSignalHandle rfidSignalHandle;
  22 +
  23 + @RequestMapping("inside")
  24 + public void inside(@RequestBody List<RfidInoutStation> list) {
  25 + rfidSignalHandle.handle(list);
  26 + }
  27 +}
src/main/java/com/bsth/data/gpsdata_v2/rfid/entity/RfidInoutStation.java 0 → 100644
  1 +package com.bsth.data.gpsdata_v2.rfid.entity;
  2 +
  3 +/**
  4 + * RFID 进出数据
  5 + * Created by panzhao on 2017/11/22.
  6 + */
  7 +public class RfidInoutStation {
  8 +
  9 + private String nbbm;
  10 +
  11 + private String station;
  12 +
  13 + /**
  14 + * 0 进
  15 + * 1 出
  16 + */
  17 + private int type;
  18 +
  19 + /**
  20 + * 信号时间
  21 + */
  22 + private long t;
  23 +
  24 + public String getNbbm() {
  25 + return nbbm;
  26 + }
  27 +
  28 + public void setNbbm(String nbbm) {
  29 + this.nbbm = nbbm;
  30 + }
  31 +
  32 + public String getStation() {
  33 + return station;
  34 + }
  35 +
  36 + public void setStation(String station) {
  37 + this.station = station;
  38 + }
  39 +
  40 + public int getType() {
  41 + return type;
  42 + }
  43 +
  44 + public void setType(int type) {
  45 + this.type = type;
  46 + }
  47 +
  48 + public long getT() {
  49 + return t;
  50 + }
  51 +
  52 + public void setT(long t) {
  53 + this.t = t;
  54 + }
  55 +}