Commit f49348db033036905dad1bc6766ab9e3568b5f00

Authored by 娄高锋
2 parents 77550be5 af02e4e1

Merge branch 'minhang' of 192.168.168.201:panzhaov5/bsth_control into minhang

src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
@@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, @@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo,
131 * @Title: adjust @Description: TODO(调整人车) @param @param id 131 * @Title: adjust @Description: TODO(调整人车) @param @param id
132 * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy 132 * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy
133 * 售票员 @throws 133 * 售票员 @throws
134 - */ 134 +
135 @RequestMapping(value = "/adjust", method = RequestMethod.POST) 135 @RequestMapping(value = "/adjust", method = RequestMethod.POST)
136 public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy, 136 public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy,
137 String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) { 137 String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
138 return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr); 138 return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr);
139 } 139 }
140 - 140 + */
141 /** 141 /**
142 * 142 *
143 * @Title: realOutAdjust 143 * @Title: realOutAdjust
src/main/java/com/bsth/data/LineConfigData.java
1 package com.bsth.data; 1 package com.bsth.data;
2 2
3 -import java.util.Collection;  
4 -import java.util.HashMap;  
5 -import java.util.Iterator;  
6 -import java.util.Map;  
7 -import java.util.Set;  
8 -  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory;  
11 -import org.springframework.beans.factory.annotation.Autowired;  
12 -import org.springframework.boot.CommandLineRunner;  
13 -import org.springframework.stereotype.Component;  
14 -  
15 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
16 import com.bsth.entity.realcontrol.D80ReplyTemp; 4 import com.bsth.entity.realcontrol.D80ReplyTemp;
17 import com.bsth.entity.realcontrol.LineConfig; 5 import com.bsth.entity.realcontrol.LineConfig;
18 import com.bsth.oplog.normal.OpLogger; 6 import com.bsth.oplog.normal.OpLogger;
19 import com.bsth.service.LineService; 7 import com.bsth.service.LineService;
20 import com.bsth.service.realcontrol.LineConfigService; 8 import com.bsth.service.realcontrol.LineConfigService;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.boot.CommandLineRunner;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.*;
21 16
22 /** 17 /**
23 * 18 *
@@ -92,7 +87,7 @@ public class LineConfigData implements CommandLineRunner { @@ -92,7 +87,7 @@ public class LineConfigData implements CommandLineRunner {
92 //出场时间类型 87 //出场时间类型
93 conf.setOutConfig(1); 88 conf.setOutConfig(1);
94 //进场时间类型 89 //进场时间类型
95 - conf.setInConfig(1); 90 + //conf.setInConfig(1);
96 //短语模板 91 //短语模板
97 conf.setPhraseTemps(""); 92 conf.setPhraseTemps("");
98 //调度指令模板 93 //调度指令模板
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
5 import com.bsth.Application; 5 import com.bsth.Application;
6 import com.bsth.data.BasicData; 6 import com.bsth.data.BasicData;
7 import com.bsth.data.forecast.ForecastRealServer; 7 import com.bsth.data.forecast.ForecastRealServer;
  8 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
8 import com.bsth.data.gpsdata.analyse.GpsAnalyse; 9 import com.bsth.data.gpsdata.analyse.GpsAnalyse;
9 import com.bsth.data.gpsdata.recovery.GpsDataRecovery; 10 import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
10 import com.bsth.data.schedule.DayOfSchedule; 11 import com.bsth.data.schedule.DayOfSchedule;
@@ -58,8 +59,6 @@ public class GpsRealData implements CommandLineRunner{ @@ -58,8 +59,6 @@ public class GpsRealData implements CommandLineRunner{
58 @Autowired 59 @Autowired
59 ForecastRealServer forecastRealServer; 60 ForecastRealServer forecastRealServer;
60 61
61 -  
62 -  
63 /** 62 /**
64 * 构造函数 63 * 构造函数
65 */ 64 */
@@ -72,13 +71,18 @@ public class GpsRealData implements CommandLineRunner{ @@ -72,13 +71,18 @@ public class GpsRealData implements CommandLineRunner{
72 @Override 71 @Override
73 public void run(String... arg0) throws Exception { 72 public void run(String... arg0) throws Exception {
74 logger.info("gpsDataLoader,20,6"); 73 logger.info("gpsDataLoader,20,6");
75 - Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 20, TimeUnit.SECONDS); 74 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 40, 6, TimeUnit.SECONDS);
76 } 75 }
77 76
  77 + static final long CLEAR_DIFF = 1000 * 60 * 60 * 2;
78 public GpsEntity add(GpsEntity gps) { 78 public GpsEntity add(GpsEntity gps) {
79 String device = gps.getDeviceId(); 79 String device = gps.getDeviceId();
80 GpsEntity old = gpsMap.get(device); 80 GpsEntity old = gpsMap.get(device);
81 81
  82 + //断线2个小时,清除缓存数据
  83 + if(gps.getTimestamp() - old.getTimestamp() > CLEAR_DIFF && gps.getNbbm() != null)
  84 + GeoCacheData.clear(gps.getNbbm());
  85 +
82 //分析gps 86 //分析gps
83 if(isAvailable(gps) && (old == null || old.getTimestamp() != gps.getTimestamp())) 87 if(isAvailable(gps) && (old == null || old.getTimestamp() != gps.getTimestamp()))
84 GpsAnalyse.start(gps); 88 GpsAnalyse.start(gps);
src/main/java/com/bsth/data/gpsdata/analyse/GeoCacheData.java
1 -package com.bsth.data.gpsdata.analyse;  
2 -  
3 -import com.bsth.data.gpsdata.GpsEntity;  
4 -import com.google.common.collect.ArrayListMultimap;  
5 -import com.vividsolutions.jts.geom.Coordinate;  
6 -import com.vividsolutions.jts.geom.GeometryFactory;  
7 -import com.vividsolutions.jts.geom.LineString;  
8 -import com.vividsolutions.jts.geom.Polygon;  
9 -import org.apache.commons.lang3.StringUtils;  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.jdbc.core.JdbcTemplate;  
14 -import org.springframework.jdbc.core.RowMapper;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import java.sql.ResultSet;  
18 -import java.sql.SQLException;  
19 -import java.util.*;  
20 -  
21 -/**  
22 - * Created by panzhao on 2016/12/23.  
23 - */  
24 -@Component  
25 -public class GeoCacheData {  
26 -  
27 - static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);  
28 -  
29 - //每辆车缓存最后200条gps  
30 - private static final int CACHE_SIZE = 200;  
31 - private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>();  
32 -  
33 - //线路路段走向  
34 - private static ArrayListMultimap<String, LineString> sectionCacheMap;  
35 -  
36 - //线路站点路由  
37 - private static ArrayListMultimap<String, StationRoute> stationCacheMap;  
38 -  
39 - //停车场  
40 - public static Map<String, Polygon> tccMap;  
41 -  
42 - @Autowired  
43 - JdbcTemplate jdbcTemplate;  
44 -  
45 - public static CircleQueue<GpsEntity> getGps(String nbbm) {  
46 - return gpsCacheMap.get(nbbm);  
47 - }  
48 -  
49 - public static void putGps(GpsEntity gps) {  
50 - CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm());  
51 - if (queue == null) {  
52 - //第一个点从站内开始  
53 - if(!gps.isInstation())  
54 - return;  
55 -  
56 - queue = new CircleQueue<>(CACHE_SIZE);  
57 - gpsCacheMap.put(gps.getNbbm(), queue);  
58 - }  
59 - queue.add(gps);  
60 - }  
61 -  
62 - public static List<StationRoute> getStationRoute(String lineCode, int directions) {  
63 - return stationCacheMap.get(lineCode + "_" + directions);  
64 - }  
65 -  
66 - public static StationRoute getStation(String lineCode, int directions, String code) {  
67 - List<StationRoute> list = getStationRoute(lineCode, directions);  
68 -  
69 - for (StationRoute sr : list) {  
70 - if (sr.getCode().equals(code)) {  
71 - return sr;  
72 - }  
73 - }  
74 - return null;  
75 - }  
76 -  
77 - public static Polygon getTccPolygon(String code){  
78 - return tccMap.get(code);  
79 - }  
80 -  
81 - public void loadData() {  
82 - final GeometryFactory geometryFactory = new GeometryFactory();  
83 - //加载站点路由  
84 - 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 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";  
85 - List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {  
86 - @Override  
87 - public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {  
88 - StationRoute sRoute = new StationRoute();  
89 - sRoute.setCode(rs.getString("STATION_CODE"));  
90 - sRoute.setLineCode(rs.getString("LINE_CODE"));  
91 - sRoute.setDirections(rs.getInt("DIRECTIONS"));  
92 - sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX"))));  
93 - sRoute.setRadius(rs.getFloat("RADIUS"));  
94 - sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));  
95 - sRoute.setMark(rs.getString("STATION_MARK"));  
96 -  
97 - String shapesType = rs.getString("SHAPES_TYPE");  
98 - //多边形电子围栏  
99 - if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {  
100 - geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));  
101 - }  
102 - return sRoute;  
103 - }  
104 - });  
105 - //按线路和走向分组  
106 - if (routeList.size() > 0) {  
107 - ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();  
108 - for (StationRoute sr : routeList) {  
109 - tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);  
110 - }  
111 -  
112 - StationRouteComp srCom = new StationRouteComp();  
113 - //连接路由  
114 - Set<String> set = tempMap.keySet();  
115 - for (String key : set) {  
116 - Collections.sort(tempMap.get(key), srCom);  
117 - connectStationRoute(tempMap.get(key));  
118 - }  
119 -  
120 - stationCacheMap = tempMap;  
121 - }  
122 -  
123 - //加载停车场数据  
124 - 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";  
125 - List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);  
126 - Map<String, Polygon> tccTempMap = new HashMap<>();  
127 -  
128 - Polygon polygon;  
129 - for (Map<String, Object> tMap : tccList) {  
130 -  
131 - try {  
132 - polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString()));  
133 - tccTempMap.put(tMap.get("PARK_CODE").toString()  
134 - , polygon);  
135 - } catch (Exception e) {  
136 - logger.error("停车场:" + tMap.get("PARK_CODE") , e);  
137 - }  
138 - }  
139 -  
140 - if(tccTempMap.size() > 0)  
141 - tccMap = tccTempMap;  
142 - }  
143 -  
144 - private void connectStationRoute(List<StationRoute> list) {  
145 - int size = list.size();  
146 - StationRoute sr = null;  
147 - for (int i = 0; i < size; i++) {  
148 - sr = list.get(i);  
149 - //上一个  
150 - if (i > 0)  
151 - sr.setPrve(list.get(i - 1));  
152 - //下一个  
153 - if (i < size - 1)  
154 - sr.setNext(list.get(i + 1));  
155 - }  
156 - }  
157 -  
158 - public Coordinate[] parsePolygon(String polygonStr) {  
159 - String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;  
160 -  
161 - Coordinate[] cds = new Coordinate[coords.length];  
162 - int len = coords.length;  
163 - for (int i = 0; i < len; i++) {  
164 - temps = coords[i].split(" ");  
165 - cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0]));  
166 - }  
167 - return cds;  
168 - }  
169 - 1 +package com.bsth.data.gpsdata.analyse;
  2 +
  3 +import com.bsth.data.gpsdata.GpsEntity;
  4 +import com.google.common.collect.ArrayListMultimap;
  5 +import com.vividsolutions.jts.geom.Coordinate;
  6 +import com.vividsolutions.jts.geom.GeometryFactory;
  7 +import com.vividsolutions.jts.geom.LineString;
  8 +import com.vividsolutions.jts.geom.Polygon;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
  14 +import org.springframework.jdbc.core.RowMapper;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.sql.ResultSet;
  18 +import java.sql.SQLException;
  19 +import java.util.*;
  20 +
  21 +/**
  22 + * Created by panzhao on 2016/12/23.
  23 + */
  24 +@Component
  25 +public class GeoCacheData {
  26 +
  27 + static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);
  28 +
  29 + //每辆车缓存最后200条gps
  30 + private static final int CACHE_SIZE = 200;
  31 + private static Map<String, CircleQueue<GpsEntity>> gpsCacheMap = new HashMap<>();
  32 +
  33 + //线路路段走向
  34 + private static ArrayListMultimap<String, LineString> sectionCacheMap;
  35 +
  36 + //线路站点路由
  37 + private static ArrayListMultimap<String, StationRoute> stationCacheMap;
  38 +
  39 + //停车场
  40 + public static Map<String, Polygon> tccMap;
  41 +
  42 + @Autowired
  43 + JdbcTemplate jdbcTemplate;
  44 +
  45 + public static CircleQueue<GpsEntity> getGps(String nbbm) {
  46 + return gpsCacheMap.get(nbbm);
  47 + }
  48 +
  49 + public static void putGps(GpsEntity gps) {
  50 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(gps.getNbbm());
  51 + if (queue == null) {
  52 + //第一个点从站内开始
  53 + if (!gps.isInstation())
  54 + return;
  55 +
  56 + queue = new CircleQueue<>(CACHE_SIZE);
  57 + gpsCacheMap.put(gps.getNbbm(), queue);
  58 + }
  59 + queue.add(gps);
  60 + }
  61 +
  62 + public static void clear(String nbbm) {
  63 + try {
  64 + CircleQueue<GpsEntity> queue = gpsCacheMap.get(nbbm);
  65 + if (queue != null)
  66 + queue.clear();
  67 + } catch (Exception e) {
  68 + logger.error("", e);
  69 + }
  70 + }
  71 +
  72 + public static List<StationRoute> getStationRoute(String lineCode, int directions) {
  73 + return stationCacheMap.get(lineCode + "_" + directions);
  74 + }
  75 +
  76 + public static StationRoute getStation(String lineCode, int directions, String code) {
  77 + List<StationRoute> list = getStationRoute(lineCode, directions);
  78 +
  79 + for (StationRoute sr : list) {
  80 + if (sr.getCode().equals(code)) {
  81 + return sr;
  82 + }
  83 + }
  84 + return null;
  85 + }
  86 +
  87 + public static Polygon getTccPolygon(String code) {
  88 + return tccMap.get(code);
  89 + }
  90 +
  91 + public void loadData() {
  92 + final GeometryFactory geometryFactory = new GeometryFactory();
  93 + //加载站点路由
  94 + 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 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";
  95 + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
  96 + @Override
  97 + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
  98 + StationRoute sRoute = new StationRoute();
  99 + sRoute.setCode(rs.getString("STATION_CODE"));
  100 + sRoute.setLineCode(rs.getString("LINE_CODE"));
  101 + sRoute.setDirections(rs.getInt("DIRECTIONS"));
  102 + sRoute.setPoint(geometryFactory.createPoint(new Coordinate(rs.getFloat("G_LATY"), rs.getFloat("G_LONX"))));
  103 + sRoute.setRadius(rs.getFloat("RADIUS"));
  104 + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
  105 + sRoute.setMark(rs.getString("STATION_MARK"));
  106 +
  107 + String shapesType = rs.getString("SHAPES_TYPE");
  108 + //多边形电子围栏
  109 + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {
  110 + sRoute.setPolygon(geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID"))));
  111 + }
  112 + return sRoute;
  113 + }
  114 + });
  115 + //按线路和走向分组
  116 + if (routeList.size() > 0) {
  117 + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
  118 + for (StationRoute sr : routeList) {
  119 + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  120 + }
  121 +
  122 + StationRouteComp srCom = new StationRouteComp();
  123 + //连接路由
  124 + Set<String> set = tempMap.keySet();
  125 + for (String key : set) {
  126 + Collections.sort(tempMap.get(key), srCom);
  127 + connectStationRoute(tempMap.get(key));
  128 + }
  129 +
  130 + stationCacheMap = tempMap;
  131 + }
  132 +
  133 + //加载停车场数据
  134 + 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";
  135 + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
  136 + Map<String, Polygon> tccTempMap = new HashMap<>();
  137 +
  138 + Polygon polygon;
  139 + for (Map<String, Object> tMap : tccList) {
  140 +
  141 + try {
  142 + polygon = geometryFactory.createPolygon(parsePolygon(tMap.get("G_PARK_POINT").toString()));
  143 + tccTempMap.put(tMap.get("PARK_CODE").toString()
  144 + , polygon);
  145 + } catch (Exception e) {
  146 + logger.error("停车场:" + tMap.get("PARK_CODE"), e);
  147 + }
  148 + }
  149 +
  150 + if (tccTempMap.size() > 0)
  151 + tccMap = tccTempMap;
  152 + }
  153 +
  154 + private void connectStationRoute(List<StationRoute> list) {
  155 + int size = list.size();
  156 + StationRoute sr = null;
  157 + for (int i = 0; i < size; i++) {
  158 + sr = list.get(i);
  159 + //上一个
  160 + if (i > 0)
  161 + sr.setPrve(list.get(i - 1));
  162 + //下一个
  163 + if (i < size - 1)
  164 + sr.setNext(list.get(i + 1));
  165 + }
  166 + }
  167 +
  168 + public Coordinate[] parsePolygon(String polygonStr) {
  169 + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
  170 +
  171 + Coordinate[] cds = new Coordinate[coords.length];
  172 + int len = coords.length;
  173 + for (int i = 0; i < len; i++) {
  174 + temps = coords[i].split(" ");
  175 + cds[i] = new Coordinate(Float.parseFloat(temps[1]), Float.parseFloat(temps[0]));
  176 + }
  177 + return cds;
  178 + }
170 } 179 }
171 \ No newline at end of file 180 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsArrival.java
1 -package com.bsth.data.gpsdata.analyse.components;  
2 -  
3 -import com.bsth.data.LineConfigData;  
4 -import com.bsth.data.gpsdata.GpsEntity;  
5 -import com.bsth.data.gpsdata.analyse.CircleQueue;  
6 -import com.bsth.data.gpsdata.analyse.GeoCacheData;  
7 -import com.bsth.data.gpsdata.analyse.StationRoute;  
8 -import com.bsth.data.gpsdata.analyse.util.GeoUtils;  
9 -import com.bsth.data.schedule.DayOfSchedule;  
10 -import com.bsth.entity.realcontrol.LineConfig;  
11 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -import org.springframework.beans.BeansException;  
15 -import org.springframework.context.ApplicationContext;  
16 -import org.springframework.context.ApplicationContextAware;  
17 -import org.springframework.stereotype.Component;  
18 -  
19 -import java.util.List;  
20 -  
21 -/**  
22 - * gps 到离站判断  
23 - * Created by panzhao on 2016/12/24.  
24 - */  
25 -@Component  
26 -public class GpsArrival implements ApplicationContextAware {  
27 -  
28 - static Logger logger = LoggerFactory.getLogger(GpsArrival.class);  
29 -  
30 - static DayOfSchedule dayOfSchedule;  
31 -  
32 - static LineConfigData lineConfigData;  
33 -  
34 - public static void arrival(GpsEntity gps) {  
35 -  
36 - if (gps.getLat() == 0 || gps.getLon() == 0) {  
37 - //logger.error("无效的gps");  
38 - return;  
39 - }  
40 -  
41 - Object task = DayOfSchedule.executeCurr(gps.getNbbm());  
42 - if (task == null)  
43 - return;  
44 - if (task.getClass().isAssignableFrom(ScheduleRealInfo.class)) {  
45 - ScheduleRealInfo sch = (ScheduleRealInfo) task;  
46 - //和班次同步走向  
47 - gps.setUpDown(Integer.parseInt(sch.getXlDir()));  
48 -  
49 - //出场  
50 - if (sch.getBcType().equals("out")) {  
51 - outCarpark(gps, sch);  
52 - }  
53 - else if (sch.getBcType().equals("normal"))  
54 - normalInOut(gps, sch);  
55 - else if(sch.getBcType().equals("in")){  
56 - inCarpark(gps, sch);  
57 - }  
58 - }  
59 -  
60 - GeoCacheData.putGps(gps);  
61 - }  
62 -  
63 - /**  
64 - * 正常班次  
65 - *  
66 - * @param gps  
67 - * @param sch  
68 - */  
69 - private static void normalInOut(GpsEntity gps, ScheduleRealInfo sch) {  
70 - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());  
71 - GpsEntity prev = null;  
72 - if (queue != null)  
73 - prev = queue.getTail();  
74 -  
75 - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());  
76 - StationRoute station = GeoUtils.gpsInStation(gps, srs);  
77 -  
78 - if (station != null) {  
79 - //站内  
80 - gps.setStopNo(station.getCode());  
81 - gps.setInstation(true);  
82 - stationInside(gps, prev, sch);  
83 - } else {  
84 - //站外  
85 - stationOutside(gps, prev, sch);  
86 - }  
87 - }  
88 -  
89 - /**  
90 - * GPS在站点内  
91 - *  
92 - * @param gps  
93 - * @param prev  
94 - * @param sch  
95 - */  
96 - private static void stationInside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {  
97 - if(prev == null)  
98 - return;  
99 -  
100 - if (gps.getStopNo().equals(sch.getZdzCode()) && sch.getZdsjActual() == null) {  
101 - //到终点站  
102 - arriveEnd(sch, gps);  
103 - return;  
104 - }  
105 -  
106 - //上一个点在站外  
107 - if(!prev.isInstation())  
108 - return;  
109 - //超过 (待发时间 + 90%的单程运送时间),还在起点站。默认烂一圈  
110 - if (prev.getStopNo().equals(gps.getStopNo())){  
111 - if(gps.getStopNo().equals(sch.getQdzCode())  
112 - && gps.getTimestamp() > sch.getDfsjT() + (sch.getBcsj() * 60 * 1000 * 0.9)){  
113 -  
114 - ScheduleRealInfo next = dayOfSchedule.next(dayOfSchedule.next(sch));  
115 - dayOfSchedule.addExecPlan(next);  
116 - }  
117 - return;  
118 - }  
119 -  
120 - //发车  
121 - if (prev.getStopNo().equals(sch.getQdzCode())) {  
122 - busWillDepart(sch, gps);  
123 - return;  
124 - }  
125 -  
126 - //中途站  
127 - StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), prev.getUpDown(), prev.getStopNo());  
128 - StationRoute currStation = GeoCacheData.getStation(gps.getLineId(), gps.getUpDown(), gps.getStopNo());  
129 - if (currStation.getRouteSort() < prevStation.getRouteSort()) {  
130 - //开始下一个班次  
131 - finishPlan(sch);  
132 -  
133 - logger.info("路由反向。。。。。。:" + gps.getTimestamp());  
134 - //为班次补上实际时间  
135 -  
136 - }  
137 - }  
138 -  
139 - /**  
140 - * GPS在站点外  
141 - *  
142 - * @param gps  
143 - * @param prev  
144 - * @param sch  
145 - */  
146 - private static void stationOutside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {  
147 - if(prev == null)  
148 - return;  
149 -  
150 - gps.setStopNo(prev.getStopNo());  
151 - if (prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {  
152 - //发车  
153 - busWillDepart(sch, gps);  
154 - return;  
155 - }  
156 - }  
157 -  
158 - /**  
159 - * 公交车起点发出  
160 - */  
161 - final static long DRIFT_VAL_TIME = 1000 * 60 * 10;  
162 - //班次最大差值1小时  
163 - final static long MAX_DIFF = 1000 * 60 * 60;  
164 - private static void busWillDepart(ScheduleRealInfo sch, GpsEntity gps) {  
165 - //实发时间不覆盖  
166 - if (sch.getFcsjActual() == null && Math.abs(gps.getTimestamp() - sch.getDfsjT()) < MAX_DIFF) {  
167 -  
168 - //提前10分钟以上发出,判断一下是否是漂移  
169 - if(sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME){  
170 - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);  
171 - if(schPrev != null && schPrev.getZdsjActual() != null){  
172 - //计划停站时间  
173 - long stopTimeJH = sch.getDfsjT() - schPrev.getZdsjT();  
174 - //实际停站时间  
175 - long actualStopTime = gps.getTimestamp() - schPrev.getZdsjActualTime();  
176 - /*  
177 - 没停够计划百分之60的,算漂移  
178 - (这里出现的误判,由程序在车辆到中途站的时候进行补偿)  
179 - */  
180 - if(stopTimeJH * 0.6 < actualStopTime){  
181 - logger.info("漂移.... 车辆:" + gps.getNbbm() + " ts: " + gps.getTimestamp());  
182 - return;  
183 - }  
184 - }  
185 - }  
186 -  
187 - LineConfig config = lineConfigData.get(sch.getXlBm());  
188 - if(config != null && config.getOutConfig() == 2){  
189 - //出站既出场  
190 - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);  
191 - if(schPrev.getBcType().equals("out")){  
192 - schPrev.setFcsjActualAll(schPrev.getDfsjT());  
193 - schPrev.setZdsjActualAll(schPrev.getZdsjT());  
194 - }  
195 - }  
196 -  
197 - sch.setFcsjActualAll(gps.getTimestamp());  
198 - logger.info("(站外)班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());  
199 - }  
200 - }  
201 -  
202 - /**  
203 - * 公交车到达终点  
204 - *  
205 - * @param sch  
206 - * @param gps  
207 - */  
208 - private static void arriveEnd(ScheduleRealInfo sch, GpsEntity gps) {  
209 - sch.setZdsjActualAll(gps.getTimestamp());  
210 - ScheduleRealInfo next = finishPlan(sch);  
211 - logger.info("班次:" + sch.getDfsj() + "到达终点, 时间:" + sch.getZdsjActual());  
212 -  
213 - if (next == null)  
214 - return;  
215 -  
216 - //将gps转换为下一个班次走向的站内信号  
217 - int updown = Integer.parseInt(next.getXlDir());  
218 - List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown);  
219 - StationRoute station = GeoUtils.gpsInStation(gps, srs);  
220 - if (station != null) {  
221 - gps.setUpDown(updown);  
222 - gps.setStopNo(station.getCode());  
223 - }  
224 - }  
225 -  
226 - /**  
227 - * 出场班次  
228 - *  
229 - * @param gps  
230 - * @param sch  
231 - */  
232 - private static void outCarpark(GpsEntity gps, ScheduleRealInfo sch) {  
233 - String carpark = GeoUtils.gpsInCarpark(gps);  
234 - if (carpark != null) {  
235 - gps.setInstation(true);  
236 - gps.setStopNo(carpark);  
237 - return; // 还在场内  
238 - }  
239 -  
240 - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());  
241 - if (queue == null)  
242 - return;  
243 - //上一个gps  
244 - GpsEntity prev = queue.getTail();  
245 -  
246 - if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {  
247 - gps.setStopNo(prev.getStopNo());  
248 - //停车场发出  
249 - busWillDepart(sch, gps);  
250 - return;  
251 - }  
252 -  
253 - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());  
254 - StationRoute station = GeoUtils.gpsInStation(gps, srs);  
255 -  
256 - if (station != null && station.getCode().equals(sch.getZdzCode())) {  
257 - gps.setStopNo(station.getCode());  
258 - //到达终点  
259 - arriveEnd(sch, gps);  
260 - }  
261 - }  
262 -  
263 -  
264 - /**  
265 - * 进场班次  
266 - * @param gps  
267 - * @param sch  
268 - */  
269 - private static void inCarpark(GpsEntity gps, ScheduleRealInfo sch) {  
270 - String carpark = GeoUtils.gpsInCarpark(gps);  
271 - if (carpark != null && carpark.equals(sch.getZdzCode())) {  
272 - //进场班次取第一个实际进场时间  
273 - if(sch.getZdsjActual() != null)  
274 - return;  
275 -  
276 - //进场  
277 - arriveEnd(sch, gps);  
278 - return;  
279 - }  
280 -  
281 - CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());  
282 - if (queue == null)  
283 - return;  
284 - //上一个gps  
285 - GpsEntity prev = queue.getTail();  
286 -  
287 - if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {  
288 - gps.setStopNo(prev.getStopNo());  
289 - //进场班次发出  
290 - busWillDepart(sch, gps);  
291 - return;  
292 - }  
293 - }  
294 -  
295 - /**  
296 - * 完成班次 -返回下一个班次  
297 - *  
298 - * @param sch  
299 - */  
300 - private static ScheduleRealInfo finishPlan(ScheduleRealInfo sch) {  
301 - ScheduleRealInfo next = dayOfSchedule.next(sch);  
302 - if (next != null) {  
303 - next.setQdzArrDatesj(sch.getZdsjActual());  
304 - dayOfSchedule.addExecPlan(next);  
305 - }  
306 - return next;  
307 - }  
308 -  
309 - @Override  
310 - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
311 - dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);  
312 - lineConfigData = applicationContext.getBean(LineConfigData.class);  
313 - }  
314 -} 1 +package com.bsth.data.gpsdata.analyse.components;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.gpsdata.GpsEntity;
  5 +import com.bsth.data.gpsdata.analyse.CircleQueue;
  6 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
  7 +import com.bsth.data.gpsdata.analyse.StationRoute;
  8 +import com.bsth.data.gpsdata.analyse.util.GeoUtils;
  9 +import com.bsth.data.schedule.DayOfSchedule;
  10 +import com.bsth.entity.realcontrol.LineConfig;
  11 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +import com.bsth.service.directive.DirectiveService;
  13 +import com.bsth.websocket.handler.SendUtils;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.BeansException;
  17 +import org.springframework.context.ApplicationContext;
  18 +import org.springframework.context.ApplicationContextAware;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import java.util.List;
  22 +
  23 +/**
  24 + * gps 到离站判断
  25 + * Created by panzhao on 2016/12/24.
  26 + */
  27 +@Component
  28 +public class GpsArrival implements ApplicationContextAware {
  29 +
  30 + static Logger logger = LoggerFactory.getLogger(GpsArrival.class);
  31 +
  32 + static DayOfSchedule dayOfSchedule;
  33 + static LineConfigData lineConfigData;
  34 + static SendUtils sendUtils;
  35 + static DirectiveService directiveService;
  36 +
  37 + public static void arrival(GpsEntity gps) {
  38 +
  39 + if (gps.getLat() == 0 || gps.getLon() == 0) {
  40 + //logger.error("无效的gps");
  41 + return;
  42 + }
  43 +
  44 + Object task = DayOfSchedule.executeCurr(gps.getNbbm());
  45 + if (task == null)
  46 + return;
  47 + if (task.getClass().isAssignableFrom(ScheduleRealInfo.class)) {
  48 + ScheduleRealInfo sch = (ScheduleRealInfo) task;
  49 + //和班次同步走向
  50 + gps.setUpDown(Integer.parseInt(sch.getXlDir()));
  51 +
  52 + //出场
  53 + if (sch.getBcType().equals("out")) {
  54 + outCarpark(gps, sch);
  55 + } else if (sch.getBcType().equals("normal"))
  56 + normalInOut(gps, sch);
  57 + else if (sch.getBcType().equals("in")) {
  58 + inCarpark(gps, sch);
  59 + }
  60 + }
  61 +
  62 + GeoCacheData.putGps(gps);
  63 + }
  64 +
  65 + /**
  66 + * 正常班次
  67 + *
  68 + * @param gps
  69 + * @param sch
  70 + */
  71 + private static void normalInOut(GpsEntity gps, ScheduleRealInfo sch) {
  72 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  73 + GpsEntity prev = null;
  74 + if (queue != null)
  75 + prev = queue.getTail();
  76 +
  77 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());
  78 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  79 +
  80 + if (station != null) {
  81 + //站内
  82 + gps.setStopNo(station.getCode());
  83 + gps.setInstation(true);
  84 + stationInside(gps, prev, sch);
  85 + } else {
  86 + //站外
  87 + stationOutside(gps, prev, sch);
  88 + }
  89 + }
  90 +
  91 + /**
  92 + * GPS在站点内
  93 + *
  94 + * @param gps
  95 + * @param prev
  96 + * @param sch
  97 + */
  98 + private static void stationInside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
  99 + if (prev == null)
  100 + return;
  101 +
  102 + if (gps.getStopNo().equals(sch.getZdzCode()) && sch.getZdsjActual() == null) {
  103 + //到终点站
  104 + arriveEnd(sch, gps);
  105 + return;
  106 + }
  107 +
  108 + //上一个点在站外
  109 + if (!prev.isInstation())
  110 + return;
  111 + //超过 (待发时间 + 90%的单程运送时间) 并且超过下一个班次的待发时间,还在起点站。默认烂一圈
  112 + if (prev.getStopNo().equals(gps.getStopNo())) {
  113 + if (gps.getStopNo().equals(sch.getQdzCode())
  114 + && gps.getTimestamp() > sch.getDfsjT() + (sch.getBcsj() * 60 * 1000 * 0.9)) {
  115 +
  116 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  117 + if(gps.getTimestamp() > next.getDfsjT())
  118 + dayOfSchedule.addExecPlan(dayOfSchedule.next(next));
  119 + }
  120 + return;
  121 + }
  122 +
  123 + //发车
  124 + if (prev.getStopNo().equals(sch.getQdzCode())) {
  125 + busWillDepart(sch, gps);
  126 + return;
  127 + }
  128 +
  129 + if (gps.getUpDown() != prev.getUpDown())
  130 + return;
  131 +
  132 + //中途站
  133 + StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), prev.getUpDown(), prev.getStopNo());
  134 + StationRoute currStation = GeoCacheData.getStation(gps.getLineId(), gps.getUpDown(), gps.getStopNo());
  135 + if (currStation.getRouteSort() < prevStation.getRouteSort()) {
  136 + //开始下一个班次
  137 + finishPlan(sch);
  138 +
  139 + logger.info("路由反向。。。。。。:" + gps.getTimestamp());
  140 + //为班次补上实际时间
  141 + }
  142 + }
  143 +
  144 + /**
  145 + * GPS在站点外
  146 + *
  147 + * @param gps
  148 + * @param prev
  149 + * @param sch
  150 + */
  151 + private static void stationOutside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
  152 + if (prev == null)
  153 + return;
  154 +
  155 + gps.setStopNo(prev.getStopNo());
  156 + if (prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  157 + //发车
  158 + busWillDepart(sch, gps);
  159 + return;
  160 + }
  161 + }
  162 +
  163 + /**
  164 + * 公交车起点发出
  165 + */
  166 + final static long DRIFT_VAL_TIME = 1000 * 60 * 10;
  167 + //班次最大差值2小时
  168 + final static long MAX_DIFF = 1000 * 60 * 60 * 2;
  169 +
  170 + private static void busWillDepart(ScheduleRealInfo sch, GpsEntity gps) {
  171 + //实发时间不覆盖
  172 + if (sch.getFcsjActual() == null && Math.abs(gps.getTimestamp() - sch.getDfsjT()) < MAX_DIFF) {
  173 +
  174 + //提前10分钟以上发出,判断一下是否是漂移
  175 + /*if (sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME) {
  176 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  177 + if (schPrev != null && schPrev.getZdsjActual() != null) {
  178 + //计划停站时间
  179 + long stopTimeJH = sch.getDfsjT() - schPrev.getZdsjT();
  180 + //实际停站时间
  181 + long actualStopTime = gps.getTimestamp() - schPrev.getZdsjActualTime();
  182 + *//*
  183 + 没停够计划百分之30的,算漂移
  184 + (这里出现的误判,由程序在车辆到中途站的时候进行补偿)
  185 + *//*
  186 + if (stopTimeJH * 0.3 > actualStopTime) {
  187 + logger.info("漂移.... 车辆:" + gps.getNbbm() + " ts: " + gps.getTimestamp());
  188 + return;
  189 + }
  190 + }
  191 + }*/
  192 +
  193 + LineConfig config = lineConfigData.get(sch.getXlBm());
  194 + if (config != null && config.getOutConfig() == 2) {
  195 + //出站既出场
  196 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  197 + if (schPrev.getBcType().equals("out")) {
  198 + schPrev.setFcsjActualAll(gps.getTimestamp());
  199 + schPrev.setZdsjActualAll(gps.getTimestamp());
  200 + }
  201 + }
  202 +
  203 + sch.setFcsjActualAll(gps.getTimestamp());
  204 + //通知客户端
  205 + sendUtils.sendFcsj(sch);
  206 + //持久化
  207 + dayOfSchedule.save(sch);
  208 + logger.info("(站外)班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
  209 + }
  210 + }
  211 +
  212 + /**
  213 + * 公交车到达终点
  214 + *
  215 + * @param sch
  216 + * @param gps
  217 + */
  218 + private static void arriveEnd(ScheduleRealInfo sch, GpsEntity gps) {
  219 + if(Math.abs(gps.getTimestamp() - sch.getZdsjT()) >= MAX_DIFF)
  220 + return;
  221 +
  222 + sch.setZdsjActualAll(gps.getTimestamp());
  223 + ScheduleRealInfo next = finishPlan(sch);
  224 + //已完成班次数
  225 + int doneSum = dayOfSchedule.doneSum(sch.getClZbh());
  226 + //通知客户端
  227 + sendUtils.sendZdsj(sch, next, doneSum);
  228 + //持久化
  229 + dayOfSchedule.save(sch);
  230 + logger.info("班次:" + sch.getDfsj() + "到达终点, 时间:" + sch.getZdsjActual());
  231 +
  232 + if (next == null)
  233 + return;
  234 +
  235 + LineConfig config = lineConfigData.get(sch.getXlBm());
  236 + //进站既进场
  237 + if (next.getBcType().equals("in") &&
  238 + config != null && config.getOutConfig() == 2) {
  239 + next.setFcsjActualAll(gps.getTimestamp());
  240 + next.setZdsjActualAll(gps.getTimestamp());
  241 +
  242 + finishPlan(next);
  243 + } else {
  244 + //下发调度指令
  245 + directiveService.send60Dispatch(next, doneSum, "到站@系统");
  246 +
  247 + //套跑 -下发线路切换指令
  248 + /* if (!next.getXlBm().equals(sch.getXlBm()))
  249 + directiveService.lineChange(sch.getClZbh(), next.getXlBm(), "套跑@系统");*/
  250 + }
  251 +
  252 + //将gps转换为下一个班次走向的站内信号
  253 + int updown = Integer.parseInt(next.getXlDir());
  254 + List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown);
  255 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  256 + if (station != null) {
  257 + gps.setUpDown(updown);
  258 + gps.setStopNo(station.getCode());
  259 + }
  260 + }
  261 +
  262 + /**
  263 + * 出场班次
  264 + *
  265 + * @param gps
  266 + * @param sch
  267 + */
  268 + private static void outCarpark(GpsEntity gps, ScheduleRealInfo sch) {
  269 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  270 + GpsEntity prev = null;
  271 + if (queue != null)
  272 + prev = queue.getTail();
  273 +
  274 + //是否在停车场内
  275 + String carpark = GeoUtils.gpsInCarpark(gps);
  276 + if (carpark != null && carpark.equals(sch.getQdzCode())) {
  277 + gps.setInstation(true);
  278 + gps.setStopNo(carpark);
  279 + return; // 还在场内
  280 + }
  281 +
  282 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());
  283 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  284 + //线路上 站点内
  285 + if (station != null) {
  286 + gps.setInstation(true);
  287 + gps.setStopNo(station.getCode());
  288 +
  289 + //上一个点附带的站点站标记
  290 + if (prev != null && prev.getStopNo() != null
  291 + && prev.getStopNo().equals(sch.getZdzCode()))
  292 + return;
  293 +
  294 + //到达终点
  295 + if (station.getCode().equals(sch.getZdzCode()))
  296 + arriveEnd(sch, gps);
  297 + }
  298 +
  299 + //上一个点在场内
  300 + if (prev != null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  301 + //当前点在场外
  302 + if (carpark == null) {
  303 + gps.setStopNo(prev.getStopNo());
  304 + //停车场发出
  305 + busWillDepart(sch, gps);
  306 + return;
  307 + }
  308 + }
  309 + }
  310 +
  311 +
  312 + /**
  313 + * 进场班次
  314 + *
  315 + * @param gps
  316 + * @param sch
  317 + */
  318 + private static void inCarpark(GpsEntity gps, ScheduleRealInfo sch) {
  319 + String carpark = GeoUtils.gpsInCarpark(gps);
  320 + if (carpark != null && carpark.equals(sch.getZdzCode())) {
  321 + //进场班次取第一个实际进场时间
  322 + if (sch.getZdsjActual() != null)
  323 + return;
  324 +
  325 + //进场
  326 + arriveEnd(sch, gps);
  327 + return;
  328 + }
  329 +
  330 + CircleQueue<GpsEntity> queue = GeoCacheData.getGps(gps.getNbbm());
  331 + if (queue == null)
  332 + return;
  333 + //上一个gps
  334 + GpsEntity prev = queue.getTail();
  335 +
  336 + if (carpark == null && prev.isInstation() && prev.getStopNo().equals(sch.getQdzCode())) {
  337 + gps.setStopNo(prev.getStopNo());
  338 + //进场班次发出
  339 + busWillDepart(sch, gps);
  340 + return;
  341 + }
  342 + }
  343 +
  344 + /**
  345 + * 完成班次 -返回下一个班次
  346 + *
  347 + * @param sch
  348 + */
  349 + private static ScheduleRealInfo finishPlan(ScheduleRealInfo sch) {
  350 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  351 + if (next != null) {
  352 + next.setQdzArrDatesj(sch.getZdsjActual());
  353 + dayOfSchedule.addExecPlan(next);
  354 + }
  355 + return next;
  356 + }
  357 +
  358 + @Override
  359 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  360 + dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
  361 + lineConfigData = applicationContext.getBean(LineConfigData.class);
  362 + sendUtils = applicationContext.getBean(SendUtils.class);
  363 + directiveService = applicationContext.getBean(DirectiveService.class);
  364 + }
  365 +}
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
1 -package com.bsth.data.gpsdata.recovery;  
2 -  
3 -import com.bsth.data.BasicData;  
4 -import com.bsth.data.gpsdata.GpsEntity;  
5 -import com.bsth.data.gpsdata.analyse.components.GpsArrival;  
6 -import com.bsth.util.db.DBUtils_MS;  
7 -import com.google.common.collect.ArrayListMultimap;  
8 -import org.slf4j.Logger;  
9 -import org.slf4j.LoggerFactory;  
10 -import org.springframework.jdbc.core.JdbcTemplate;  
11 -import org.springframework.jdbc.core.RowMapper;  
12 -  
13 -import java.sql.ResultSet;  
14 -import java.sql.SQLException;  
15 -import java.util.*;  
16 -import java.util.concurrent.CountDownLatch;  
17 -import java.util.concurrent.ExecutorService;  
18 -import java.util.concurrent.Executors;  
19 -  
20 -/**  
21 - * 数据恢复  
22 - * Created by panzhao on 2016/12/24.  
23 - */  
24 -public class GpsDataRecovery {  
25 -  
26 - static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class);  
27 -  
28 - public static boolean run;  
29 -  
30 - static ExecutorService threadPool = Executors.newFixedThreadPool(50);  
31 -  
32 - private static CountDownLatch count;  
33 -  
34 - public static void recovery() {  
35 - List<GpsEntity> list = loadData();  
36 -  
37 - //按车辆分组数据  
38 - ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create();  
39 - for (GpsEntity gps : list) {  
40 - if(gps.getNbbm() != null)  
41 - listMap.put(gps.getNbbm(), gps);  
42 - }  
43 -  
44 - count = new CountDownLatch(listMap.keySet().size());  
45 -  
46 - Set<String> keys = listMap.keySet();  
47 - for (String nbbm : keys) {  
48 - threadPool.execute(new RecoveryDataThread(listMap.get(nbbm), count));  
49 - /*if(nbbm.equals("W9A-250"))  
50 - new RecoveryDataThread(listMap.get(nbbm), count).run();*/  
51 - }  
52 - try {  
53 - //等待子线程结束  
54 - count.await();  
55 - logger.info("GPS 数据恢复完成....");  
56 - } catch (InterruptedException e) {  
57 - logger.error("", e);  
58 - }  
59 - }  
60 -  
61 - /**  
62 - * 加载当天的gps数据  
63 - *  
64 - * @return  
65 - */  
66 - public static List<GpsEntity> loadData() {  
67 - Calendar calendar = Calendar.getInstance();  
68 - int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);  
69 -  
70 - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from BSTH_C_GPS_INFO where days_year=" + dayOfYear;  
71 - JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());  
72 -  
73 - List<GpsEntity> list =  
74 - jdbcTemplate.query(sql, new RowMapper<GpsEntity>() {  
75 - @Override  
76 - public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException {  
77 - GpsEntity gps = new GpsEntity();  
78 -  
79 - gps.setDeviceId(rs.getString("DEVICE_ID"));  
80 - gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));  
81 - gps.setSpeed(rs.getFloat("SPEED_GPS"));  
82 - gps.setLat(rs.getFloat("LAT"));  
83 - gps.setLon(rs.getFloat("LON"));  
84 - gps.setLineId(rs.getString("LINE_ID"));  
85 - gps.setTimestamp(rs.getLong("TS"));  
86 - gps.setUpDown(getUpOrDown(rs.getLong("SERVICE_STATE")));  
87 - return gps;  
88 - }  
89 - });  
90 - return list;  
91 - }  
92 -  
93 - /**  
94 - * 王通 2016/6/29 9:23:24 获取车辆线路上下行  
95 - *  
96 - * @return -1无效 0上行 1下行  
97 - */  
98 - public static int getUpOrDown(long serviceState) {  
99 - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000  
100 - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)  
101 - return -1;  
102 - return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);  
103 - }  
104 -  
105 - public static class RecoveryDataThread implements Runnable {  
106 -  
107 - List<GpsEntity> list;  
108 - CountDownLatch count;  
109 -  
110 - public RecoveryDataThread(List<GpsEntity> list, CountDownLatch count) {  
111 - this.list = list;  
112 - this.count = count;  
113 - }  
114 -  
115 - @Override  
116 - public void run() {  
117 - try {  
118 - //排序  
119 - Collections.sort(list, new GpsComp());  
120 - //依次跑完gps  
121 - //int i = 0;  
122 - for(GpsEntity gps : list){  
123 - /* i++;  
124 - if(i == 383){  
125 - System.out.println("aaa");  
126 - }*/  
127 - GpsArrival.arrival(gps);  
128 - }  
129 - } catch (Exception e) {  
130 - logger.error("", e);  
131 - } finally {  
132 - count.countDown();  
133 - }  
134 - }  
135 - }  
136 -  
137 - public static class GpsComp implements Comparator<GpsEntity>{  
138 -  
139 - @Override  
140 - public int compare(GpsEntity g1, GpsEntity g2) {  
141 - return (int) (g1.getTimestamp() - g2.getTimestamp());  
142 - }  
143 - }  
144 -} 1 +package com.bsth.data.gpsdata.recovery;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.gpsdata.GpsEntity;
  5 +import com.bsth.data.gpsdata.analyse.components.GpsArrival;
  6 +import com.bsth.util.db.DBUtils_MS;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.jdbc.core.JdbcTemplate;
  11 +import org.springframework.jdbc.core.RowMapper;
  12 +
  13 +import java.sql.ResultSet;
  14 +import java.sql.SQLException;
  15 +import java.util.*;
  16 +import java.util.concurrent.CountDownLatch;
  17 +import java.util.concurrent.ExecutorService;
  18 +import java.util.concurrent.Executors;
  19 +
  20 +/**
  21 + * 数据恢复
  22 + * Created by panzhao on 2016/12/24.
  23 + */
  24 +public class GpsDataRecovery {
  25 +
  26 + static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class);
  27 +
  28 + public static boolean run;
  29 +
  30 + static ExecutorService threadPool = Executors.newFixedThreadPool(50);
  31 +
  32 + private static CountDownLatch count;
  33 +
  34 + public static void recovery() {
  35 + List<GpsEntity> list = loadData();
  36 +
  37 + //按车辆分组数据
  38 + ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create();
  39 + for (GpsEntity gps : list) {
  40 + if(gps.getNbbm() != null)
  41 + listMap.put(gps.getNbbm(), gps);
  42 + }
  43 +
  44 + count = new CountDownLatch(listMap.keySet().size());
  45 +
  46 + Set<String> keys = listMap.keySet();
  47 + for (String nbbm : keys) {
  48 + threadPool.execute(new RecoveryDataThread(listMap.get(nbbm), count));
  49 + /*if(nbbm.equals("W9H-003"))
  50 + new RecoveryDataThread(listMap.get(nbbm), count).run();*/
  51 + }
  52 + try {
  53 + //等待子线程结束
  54 + count.await();
  55 + logger.info("GPS 数据恢复完成....");
  56 + run = false;
  57 + } catch (InterruptedException e) {
  58 + logger.error("", e);
  59 + }
  60 + }
  61 +
  62 + /**
  63 + * 加载当天的gps数据
  64 + *
  65 + * @return
  66 + */
  67 + public static List<GpsEntity> loadData() {
  68 + Calendar calendar = Calendar.getInstance();
  69 + int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
  70 +
  71 + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear;
  72 + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  73 +
  74 + List<GpsEntity> list =
  75 + jdbcTemplate.query(sql, new RowMapper<GpsEntity>() {
  76 + @Override
  77 + public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
  78 + GpsEntity gps = new GpsEntity();
  79 +
  80 + gps.setDeviceId(rs.getString("DEVICE_ID"));
  81 + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
  82 + gps.setSpeed(rs.getFloat("SPEED_GPS"));
  83 + gps.setLat(rs.getFloat("LAT"));
  84 + gps.setLon(rs.getFloat("LON"));
  85 + gps.setLineId(rs.getString("LINE_ID"));
  86 + gps.setTimestamp(rs.getLong("TS"));
  87 + gps.setUpDown(getUpOrDown(rs.getLong("SERVICE_STATE")));
  88 + return gps;
  89 + }
  90 + });
  91 + return list;
  92 + }
  93 +
  94 + /**
  95 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  96 + *
  97 + * @return -1无效 0上行 1下行
  98 + */
  99 + public static int getUpOrDown(long serviceState) {
  100 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  101 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  102 + return -1;
  103 + return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  104 + }
  105 +
  106 + public static class RecoveryDataThread implements Runnable {
  107 +
  108 + List<GpsEntity> list;
  109 + CountDownLatch count;
  110 +
  111 + public RecoveryDataThread(List<GpsEntity> list, CountDownLatch count) {
  112 + this.list = list;
  113 + this.count = count;
  114 + }
  115 +
  116 + @Override
  117 + public void run() {
  118 + try {
  119 + //排序
  120 + Collections.sort(list, new GpsComp());
  121 + //依次跑完gps
  122 + //int i = 0;
  123 + for(GpsEntity gps : list){
  124 + /* i++;
  125 + if(i == 4527){
  126 + System.out.println("aaa");
  127 + }
  128 +
  129 + if(gps.getTimestamp() == 1482726071000L)
  130 + System.out.println("bbb");*/
  131 + GpsArrival.arrival(gps);
  132 + }
  133 + } catch (Exception e) {
  134 + logger.error("", e);
  135 + } finally {
  136 + count.countDown();
  137 + }
  138 + }
  139 + }
  140 +
  141 + public static class GpsComp implements Comparator<GpsEntity>{
  142 +
  143 + @Override
  144 + public int compare(GpsEntity g1, GpsEntity g2) {
  145 + return (int) (g1.getTimestamp() - g2.getTimestamp());
  146 + }
  147 + }
  148 +}
145 \ No newline at end of file 149 \ No newline at end of file
src/main/java/com/bsth/data/pilot80/PilotReport.java
1 package com.bsth.data.pilot80; 1 package com.bsth.data.pilot80;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.Collection;  
5 -import java.util.List;  
6 -  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 import com.bsth.data.BasicData; 3 import com.bsth.data.BasicData;
13 import com.bsth.data.LineConfigData; 4 import com.bsth.data.LineConfigData;
14 import com.bsth.data.gpsdata.GpsEntity; 5 import com.bsth.data.gpsdata.GpsEntity;
@@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository; @@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository;
23 import com.bsth.service.directive.DirectiveService; 14 import com.bsth.service.directive.DirectiveService;
24 import com.bsth.websocket.handler.SendUtils; 15 import com.bsth.websocket.handler.SendUtils;
25 import com.google.common.collect.ArrayListMultimap; 16 import com.google.common.collect.ArrayListMultimap;
  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.ArrayList;
  23 +import java.util.Collection;
  24 +import java.util.List;
26 25
27 /** 26 /**
28 * 27 *
@@ -180,7 +179,7 @@ public class PilotReport { @@ -180,7 +179,7 @@ public class PilotReport {
180 return; 179 return;
181 180
182 LineConfig conf = lineConfigData.get(sch.getXlBm()); 181 LineConfig conf = lineConfigData.get(sch.getXlBm());
183 - if(conf.getInConfig() == 1){ 182 + if(conf.getOutConfig() == 1){
184 //为相关班次写入进场时间 183 //为相关班次写入进场时间
185 sch.setZdsjActualAll(d80.getTimestamp()); 184 sch.setZdsjActualAll(d80.getTimestamp());
186 185
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
@@ -37,547 +37,535 @@ import java.util.*; @@ -37,547 +37,535 @@ import java.util.*;
37 import java.util.concurrent.TimeUnit; 37 import java.util.concurrent.TimeUnit;
38 38
39 /** 39 /**
40 - * 40 + * @author PanZhao
41 * @ClassName: DayOfSchedule 41 * @ClassName: DayOfSchedule
42 * @Description: TODO(当日实际排班) 42 * @Description: TODO(当日实际排班)
43 - * @author PanZhao  
44 * @date 2016年8月15日 上午10:16:12 43 * @date 2016年8月15日 上午10:16:12
45 - *  
46 */ 44 */
47 @Component 45 @Component
48 public class DayOfSchedule implements CommandLineRunner { 46 public class DayOfSchedule implements CommandLineRunner {
49 47
50 - Logger logger = LoggerFactory.getLogger(this.getClass());  
51 -  
52 - // 按车辆分组的班次数据  
53 - private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;  
54 -  
55 - // 班次主键映射  
56 - private static Map<Long, ScheduleRealInfo> id2SchedulMap;  
57 -  
58 - // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)  
59 - private static TreeMultimap<String, String> nbbm2SEStationMap;  
60 -  
61 - //车辆 ——> 当前执行班次  
62 - private static Map<String, ScheduleRealInfo> carExecutePlanMap;  
63 -  
64 - // 持久化缓冲区  
65 - public static LinkedList<ScheduleRealInfo> pstBuffer;  
66 -  
67 - // 排序器  
68 - private static ScheduleComparator.FCSJ schFCSJComparator;  
69 -  
70 - @Autowired  
71 - LineConfigData lineConfigData;  
72 -  
73 - @Autowired  
74 - ScheduleRealInfoRepository schRepository;  
75 -  
76 - @Autowired  
77 - SchedulePlanInfoService schPlanService;  
78 -  
79 - @Autowired  
80 - SchAttrCalculator schAttrCalculator;  
81 -  
82 - @Autowired  
83 - SendUtils sendUtils;  
84 -  
85 - @Autowired  
86 - GpsRealData gpsRealData;  
87 -  
88 - /** 线路当前使用的排班的日期 */  
89 - public static Map<String, String> currSchDateMap;  
90 -  
91 - static {  
92 - nbbmScheduleMap = ArrayListMultimap.create();  
93 - id2SchedulMap = new HashMap<>();  
94 - pstBuffer = new LinkedList<>();  
95 - schFCSJComparator = new ScheduleComparator.FCSJ();  
96 - currSchDateMap = new HashMap<>();  
97 - nbbm2SEStationMap = TreeMultimap.create();  
98 - carExecutePlanMap = new HashMap<>();  
99 - }  
100 -  
101 - @Autowired  
102 - ScheduleRefreshThread scheduleRefreshThread;  
103 -  
104 - @Autowired  
105 - SchedulePstThread schedulePstThread;  
106 -  
107 - @Autowired  
108 - FirstScheduleCheckThread firstScheduleCheckThread;  
109 -  
110 - @Autowired  
111 - ScheduleLateThread scheduleLateThread;  
112 -  
113 - @Autowired  
114 - SubmitToTrafficManage submitToTrafficManage;  
115 -  
116 - @Autowired  
117 - LineConfigData lineConfigs;  
118 -  
119 - @Autowired  
120 - BasicData.BasicDataLoader dataLoader;  
121 -  
122 - private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd")  
123 - ,fmtHHmm = DateTimeFormat.forPattern("HH:mm");  
124 -  
125 - @Override  
126 - public void run(String... arg0) throws Exception {  
127 - //加载基础数据  
128 - dataLoader.loadAllData();  
129 - //从数据库恢复排班  
130 - //dataRecovery();  
131 -  
132 - //翻班线程  
133 - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);  
134 - //入库  
135 - Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);  
136 - //首班出场指令补发器  
137 -// Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);  
138 - //班次误点扫描  
139 - Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);  
140 -  
141 - //每天凌晨2点20提交数据到运管处  
142 - long diff = (DateUtils.getTimestamp() + 1000*60*140) - System.currentTimeMillis();  
143 - if(diff < 0)  
144 - diff+=(1000*60*60*24);  
145 -  
146 - logger.info(diff/1000/60 + "分钟之后提交到运管处");  
147 - //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);  
148 - }  
149 -  
150 - //数据恢复  
151 - private void dataRecovery() {  
152 - GpsDataRecovery.run = true;  
153 -  
154 - Collection<LineConfig> confs = lineConfigs.getAll();  
155 - String lineCode, currSchDate;  
156 - for(LineConfig conf : confs){  
157 - lineCode = conf.getLine().getLineCode();  
158 - currSchDate = calcSchDate(lineCode);  
159 - //加载班次数据  
160 - reloadSch(lineCode, currSchDate, false);  
161 - } 48 + Logger logger = LoggerFactory.getLogger(this.getClass());
162 49
163 - //恢复gps数据  
164 - GpsDataRecovery.recovery();  
165 - }  
166 -  
167 - public Map<String, String> getCurrSchDate() {  
168 - return currSchDateMap;  
169 - }  
170 -  
171 - /**  
172 - *  
173 - * @Title: calcSchDateB  
174 - * @Description: TODO(计算线路当前应该使用的排班日期)  
175 - */  
176 - public String calcSchDate(String lineCode) {  
177 - LineConfig conf = lineConfigData.get(lineCode);  
178 - long ct = System.currentTimeMillis();  
179 -  
180 - String schDate = fmtyyyyMMdd.print(ct);  
181 - // 小于当天起始运营时间,则取前一天的排班  
182 - if (ct < conf.getCurrStartTime())  
183 - schDate = DateUtils.subtractDay(schDate, 1);  
184 -  
185 - return schDate;  
186 - }  
187 -  
188 - /**  
189 - * @Title: reloadSch  
190 - * @Title: reloadSch  
191 - * @Description: TODO(重新载入排班)  
192 - * @param @param  
193 - * lineCode 线路编码  
194 - * @param @param  
195 - * schDate 班次日期 yyyy-MM-dd  
196 - * @param @param  
197 - * forcePlan 强制从计划调度重新抓取  
198 - */  
199 - public int reloadSch(String lineCode, String schDate, boolean forcePlan) {  
200 - try {  
201 - List<ScheduleRealInfo> list;  
202 -  
203 - if (forcePlan)  
204 - removeRealSch(lineCode, schDate);  
205 - else  
206 - clearRAMData(lineCode);  
207 -  
208 - if (existRealSch(lineCode, schDate))  
209 - list = loadRealSch(lineCode, schDate);// 从实际排班表加载  
210 - else {  
211 - list = loadPlanSch(lineCode, schDate);// 从计划排班表加载  
212 - // 写入数据库  
213 - batchSave(list);  
214 - }  
215 -  
216 - //更新线路和班次日期对照  
217 - currSchDateMap.put(lineCode, schDate);  
218 - //添加到缓存  
219 - putAll(list);  
220 -  
221 - Set<String> cars = searchAllCars(list);  
222 - for(String nbbm : cars){  
223 - //计算“起点站应到”时间  
224 - schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));  
225 - //车辆 ——> 要执行的班次对照  
226 - carExecutePlanMap.put(nbbm, schAttrCalculator.calcCurrentExecSch(nbbmScheduleMap.get(nbbm)));  
227 - }  
228 -  
229 - //是否是出站即出场  
230 - LineConfig conf = lineConfigData.get(lineCode);  
231 - if(conf.getOutConfig() == 2){  
232 - for(String nbbm : cars)  
233 - schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));  
234 - }  
235 -  
236 - // 页面 翻班通知  
237 - sendUtils.shiftSchedule(lineCode);  
238 - } catch (Exception e) {  
239 - logger.error("", e);  
240 - return -1;  
241 - } 50 + // 按车辆分组的班次数据
  51 + private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;
242 52
243 - return 0;  
244 - }  
245 -  
246 - /**  
247 - *  
248 - * @Title: searchAllCars  
249 - * @Description: TODO(搜索班次集合中的车辆)  
250 - */  
251 - private Set<String> searchAllCars(List<ScheduleRealInfo> list) {  
252 - Set<String> cars = new HashSet<>();  
253 - for(ScheduleRealInfo sch : list)  
254 - cars.add(sch.getClZbh());  
255 -  
256 - return cars;  
257 - }  
258 -  
259 - private void putAll(List<ScheduleRealInfo> list) {  
260 - for (ScheduleRealInfo sch : list)  
261 - put(sch);  
262 - }  
263 -  
264 - /**  
265 - * @Title: removeRealSch  
266 - * @Description: TODO(清除实际排班,包括数据库和内存数据)  
267 - * @param @param  
268 - * lineCode 线路编码  
269 - * @param @param  
270 - * schDate 班次日期 yyyy-MM-dd  
271 - */  
272 - public void removeRealSch(String lineCode, String schDate) throws Exception {  
273 - try {  
274 - // 清理数据库数据  
275 - schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);  
276 -  
277 - // 清理内存数据  
278 - clearRAMData(lineCode + "");  
279 - } catch (Exception e) {  
280 - logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);  
281 - throw e;  
282 - }  
283 - }  
284 -  
285 - /**  
286 - *  
287 - * @Title: clearRAMData  
288 - * @Description: TODO(清理内存数据)  
289 - */  
290 - public void clearRAMData(String lineCode) {  
291 - int count = 0;  
292 - List<ScheduleRealInfo> remList = new ArrayList<>();  
293 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
294 - for (ScheduleRealInfo sch : schs) {  
295 - if (sch.getXlBm().equals(lineCode))  
296 - remList.add(sch);  
297 - }  
298 -  
299 - for(ScheduleRealInfo sch : remList){  
300 - if(null != sch){  
301 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
302 - id2SchedulMap.remove(sch.getId());  
303 - count ++;  
304 - }  
305 - }  
306 -  
307 - logger.info(lineCode + "排班清理 " + count);  
308 - }  
309 -  
310 - /**  
311 - * @Title: existRealSch  
312 - * @Description: TODO(实际排班是否已存在)  
313 - */  
314 - public boolean existRealSch(String lineCode, String schDate) {  
315 - int count = schRepository.countByLineCodeAndDate(lineCode, schDate);  
316 - return count > 0;  
317 - }  
318 -  
319 - /**  
320 - * @Title: loadRealSch  
321 - * @Description: TODO(从实际排班表加载数据)  
322 - */  
323 - public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {  
324 - return schRepository.findByLineCodeAndDate(lineCode, schDate);  
325 - }  
326 -  
327 - /**  
328 - * @Title: loadPlanSch  
329 - * @Description: TODO(从计划排班表加载数据)  
330 - */  
331 - public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {  
332 - logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);  
333 - List<ScheduleRealInfo> realList = new ArrayList<>();  
334 -  
335 - try {  
336 - Map<String, Object> data = new HashMap<>();  
337 -  
338 - data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());  
339 - data.put("xlBm_eq", lineCode);  
340 -  
341 - // 查询计划排班  
342 - List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());  
343 -  
344 - // 转换为实际排班  
345 - realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);  
346 -  
347 - SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");  
348 - String fcsj;  
349 - for (ScheduleRealInfo sch : realList) {  
350 - sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));  
351 - sch.setRealExecDate(sch.getScheduleDateStr());  
352 -  
353 - if(StringUtils.isEmpty(sch.getFcsj()))  
354 - sch.setFcsj("00:00");  
355 -  
356 - fcsj=sch.getFcsj().trim();  
357 - //处理一下发车时间格式没有:号的问题  
358 - if(fcsj.indexOf(":") == -1 && fcsj.length() >= 4){  
359 - sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));  
360 - }  
361 -  
362 - try {  
363 - sdf.parse(sch.getFcsj());  
364 - } catch (ParseException e) {  
365 - //发车时间仍然校验不过的,直接写成00:00  
366 - sch.setFcsj("00:00");  
367 - }  
368 - sch.setDfsj(sch.getFcsj());  
369 -  
370 - // 计划终点时间  
371 - if (sch.getBcsj() != null) {  
372 - sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));  
373 - sch.setLate(false);  
374 - }  
375 - //计划里程为0,设置NULL  
376 - if(sch.getJhlc() != null && sch.getJhlc() == 0)  
377 - sch.setJhlc(null);  
378 - }  
379 - } catch (Exception e) {  
380 - logger.error("", e);  
381 - }  
382 - return realList;  
383 - }  
384 -  
385 - /**  
386 - * @Title: batchSave  
387 - * @Description: TODO(批量入库)  
388 - */  
389 - private void batchSave(List<ScheduleRealInfo> list) {  
390 - // 查询数据库最大ID  
391 - Long id = schRepository.getMaxId();  
392 - if (null == id)  
393 - id = 0L;  
394 - id++;  
395 -  
396 - SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");  
397 - for (ScheduleRealInfo item : list) {  
398 - item.setSpId(item.getId());// 保留原始的计划ID  
399 - item.setId(id++);// 设置ID  
400 - item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));  
401 - } 53 + // 班次主键映射
  54 + private static Map<Long, ScheduleRealInfo> id2SchedulMap;
402 55
403 - // 入库  
404 - new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);  
405 - } 56 + // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
  57 + private static TreeMultimap<String, String> nbbm2SEStationMap;
406 58
407 - private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {  
408 - List<SchedulePlanInfo> list = new ArrayList<>(); 59 + //车辆 ——> 当前执行班次
  60 + private static Map<String, ScheduleRealInfo> carExecutePlanMap;
409 61
410 - SchedulePlanInfo sp;  
411 - while (itrab.hasNext()) {  
412 - sp = itrab.next();  
413 - sp.setSchedulePlan(null);  
414 - list.add(sp);  
415 - }  
416 - return list;  
417 - }  
418 -  
419 - /**  
420 - *  
421 - * @Title: findByLineCode  
422 - * @Description: TODO(lineCode 获取班次)  
423 - */  
424 - public List<ScheduleRealInfo> findByLineCode(String lineCode) {  
425 - List<ScheduleRealInfo> rs = new ArrayList<>(); 62 + // 持久化缓冲区
  63 + public static LinkedList<ScheduleRealInfo> pstBuffer;
426 64
427 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
428 - for (ScheduleRealInfo sch : schs) {  
429 - if (sch.getXlBm().equals(lineCode))  
430 - rs.add(sch);  
431 - }  
432 - return rs;  
433 - }  
434 -  
435 - /**  
436 - *  
437 - * @Title: findCarByLineCode  
438 - * @Description: TODO(线路下运营的车辆)  
439 - */  
440 - public Set<String> findCarByLineCode(String lineCode){  
441 - Set<String> rs = new HashSet<>();  
442 -  
443 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
444 - for (ScheduleRealInfo sch : schs) {  
445 - if (sch.getXlBm().equals(lineCode))  
446 - rs.add(sch.getClZbh());  
447 - }  
448 -  
449 - return rs;  
450 - }  
451 -  
452 - public List<ScheduleRealInfo> findByNbbm(String nbbm) {  
453 - return nbbmScheduleMap.get(nbbm);  
454 - }  
455 -  
456 - /**  
457 - *  
458 - * @Title: findByLineAndUpDown  
459 - * @Description: TODO(lineCode 和走向获取班次)  
460 - */  
461 - public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {  
462 - List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();  
463 -  
464 - for (ScheduleRealInfo sch : list) {  
465 - if (sch.getXlDir().equals(upDown + ""))  
466 - rs.add(sch);  
467 - }  
468 - return rs;  
469 - }  
470 -  
471 - public ScheduleRealInfo get(long id) {  
472 - return id2SchedulMap.get(id);  
473 - }  
474 -  
475 - public Set<String> getSEStationList(String nbbm) {  
476 - return nbbm2SEStationMap.get(nbbm);  
477 - }  
478 -  
479 - /**  
480 - *  
481 - * @Title: next  
482 - * @Description: TODO(下一个班次)  
483 - */  
484 - public ScheduleRealInfo next(ScheduleRealInfo sch) {  
485 -  
486 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
487 - int outConfig = -1;  
488 - LineConfig config = lineConfigData.get(sch.getXlBm());  
489 - if(config != null)  
490 - outConfig = config.getOutConfig();  
491 -  
492 - boolean flag = false;  
493 - ScheduleRealInfo next = null;  
494 - for(ScheduleRealInfo temp : list){  
495 - if(temp.getId() == sch.getId()){  
496 - flag = true;  
497 - continue;  
498 - }  
499 - //忽略烂班  
500 - if(temp.isDestroy())  
501 - continue; 65 + // 排序器
  66 + private static ScheduleComparator.FCSJ schFCSJComparator;
502 67
503 - //出站既出场,忽略出场班次  
504 - if(outConfig == 2 && temp.getBcType().equals("out"))  
505 - continue;  
506 -  
507 - if(flag){  
508 - next = temp;  
509 - break;  
510 - }  
511 - }  
512 - return next;  
513 - }  
514 -  
515 - /**  
516 - * 上一个班次  
517 - * @param sch  
518 - * @return  
519 - */  
520 - public ScheduleRealInfo prev(ScheduleRealInfo sch){  
521 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
522 -  
523 - //boolean flag = false;  
524 - ScheduleRealInfo prev = null;  
525 - int size = list.size();  
526 -  
527 - for(int i = 0; i < size; i ++){  
528 - if(list.get(i).isDestroy())  
529 - continue; 68 + @Autowired
  69 + LineConfigData lineConfigData;
  70 +
  71 + @Autowired
  72 + ScheduleRealInfoRepository schRepository;
  73 +
  74 + @Autowired
  75 + SchedulePlanInfoService schPlanService;
  76 +
  77 + @Autowired
  78 + SchAttrCalculator schAttrCalculator;
  79 +
  80 + @Autowired
  81 + SendUtils sendUtils;
  82 +
  83 + @Autowired
  84 + GpsRealData gpsRealData;
  85 +
  86 + /**
  87 + * 线路当前使用的排班的日期
  88 + */
  89 + public static Map<String, String> currSchDateMap;
  90 +
  91 + static {
  92 + nbbmScheduleMap = ArrayListMultimap.create();
  93 + id2SchedulMap = new HashMap<>();
  94 + pstBuffer = new LinkedList<>();
  95 + schFCSJComparator = new ScheduleComparator.FCSJ();
  96 + currSchDateMap = new HashMap<>();
  97 + nbbm2SEStationMap = TreeMultimap.create();
  98 + carExecutePlanMap = new HashMap<>();
  99 + }
  100 +
  101 + @Autowired
  102 + ScheduleRefreshThread scheduleRefreshThread;
  103 +
  104 + @Autowired
  105 + SchedulePstThread schedulePstThread;
  106 +
  107 + @Autowired
  108 + FirstScheduleCheckThread firstScheduleCheckThread;
  109 +
  110 + @Autowired
  111 + ScheduleLateThread scheduleLateThread;
  112 +
  113 + @Autowired
  114 + SubmitToTrafficManage submitToTrafficManage;
  115 +
  116 + @Autowired
  117 + LineConfigData lineConfigs;
  118 +
  119 + @Autowired
  120 + BasicData.BasicDataLoader dataLoader;
  121 +
  122 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"), fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  123 +
  124 + @Override
  125 + public void run(String... arg0) throws Exception {
  126 + //加载基础数据
  127 + dataLoader.loadAllData();
  128 + //从数据库恢复排班
  129 + //dataRecovery();
  130 +
  131 + //翻班线程
  132 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  133 + //入库
  134 + Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
  135 + //首班出场指令补发器
  136 +// Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);
  137 + //班次误点扫描
  138 + Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
  139 +
  140 + //每天凌晨2点20提交数据到运管处
  141 + long diff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
  142 + if (diff < 0)
  143 + diff += (1000 * 60 * 60 * 24);
  144 +
  145 + logger.info(diff / 1000 / 60 + "分钟之后提交到运管处");
  146 + //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  147 + }
  148 +
  149 + //数据恢复
  150 + private void dataRecovery() {
  151 + GpsDataRecovery.run = true;
  152 +
  153 + Collection<LineConfig> confs = lineConfigs.getAll();
  154 + String lineCode, currSchDate;
  155 + for (LineConfig conf : confs) {
  156 + lineCode = conf.getLine().getLineCode();
  157 + currSchDate = calcSchDate(lineCode);
  158 + //加载班次数据
  159 + reloadSch(lineCode, currSchDate, false);
  160 + }
  161 +
  162 + //恢复gps数据
  163 + GpsDataRecovery.recovery();
  164 + }
  165 +
  166 + public Map<String, String> getCurrSchDate() {
  167 + return currSchDateMap;
  168 + }
  169 +
  170 + /**
  171 + * @Title: calcSchDateB
  172 + * @Description: TODO(计算线路当前应该使用的排班日期)
  173 + */
  174 + public String calcSchDate(String lineCode) {
  175 + LineConfig conf = lineConfigData.get(lineCode);
  176 + long ct = System.currentTimeMillis();
  177 +
  178 + String schDate = fmtyyyyMMdd.print(ct);
  179 + // 小于当天起始运营时间,则取前一天的排班
  180 + if (ct < conf.getCurrStartTime())
  181 + schDate = DateUtils.subtractDay(schDate, 1);
  182 +
  183 + return schDate;
  184 + }
  185 +
  186 + /**
  187 + * @param @param lineCode 线路编码
  188 + * @param @param schDate 班次日期 yyyy-MM-dd
  189 + * @param @param forcePlan 强制从计划调度重新抓取
  190 + * @Title: reloadSch
  191 + * @Title: reloadSch
  192 + * @Description: TODO(重新载入排班)
  193 + */
  194 + public int reloadSch(String lineCode, String schDate, boolean forcePlan) {
  195 + try {
  196 + List<ScheduleRealInfo> list;
  197 +
  198 + if (forcePlan)
  199 + removeRealSch(lineCode, schDate);
  200 + else
  201 + clearRAMData(lineCode);
  202 +
  203 + if (existRealSch(lineCode, schDate))
  204 + list = loadRealSch(lineCode, schDate);// 从实际排班表加载
  205 + else {
  206 + list = loadPlanSch(lineCode, schDate);// 从计划排班表加载
  207 + // 写入数据库
  208 + batchSave(list);
  209 + }
  210 +
  211 + //更新线路和班次日期对照
  212 + currSchDateMap.put(lineCode, schDate);
  213 + //添加到缓存
  214 + putAll(list);
  215 +
  216 + Set<String> cars = searchAllCars(list);
  217 + for (String nbbm : cars) {
  218 + //计算“起点站应到”时间
  219 + schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
  220 + //车辆 ——> 要执行的班次对照
  221 + reCalcExecPlan(nbbm);
  222 + }
  223 +
  224 + //是否是出站即出场
  225 + LineConfig conf = lineConfigData.get(lineCode);
  226 + if (conf.getOutConfig() == 2) {
  227 + for (String nbbm : cars)
  228 + schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));
  229 + }
  230 +
  231 + // 页面 翻班通知
  232 + sendUtils.shiftSchedule(lineCode);
  233 + } catch (Exception e) {
  234 + logger.error("", e);
  235 + return -1;
  236 + }
  237 +
  238 + return 0;
  239 + }
  240 +
  241 + /**
  242 + * @Title: searchAllCars
  243 + * @Description: TODO(搜索班次集合中的车辆)
  244 + */
  245 + private Set<String> searchAllCars(List<ScheduleRealInfo> list) {
  246 + Set<String> cars = new HashSet<>();
  247 + for (ScheduleRealInfo sch : list)
  248 + cars.add(sch.getClZbh());
  249 +
  250 + return cars;
  251 + }
  252 +
  253 + private void putAll(List<ScheduleRealInfo> list) {
  254 + for (ScheduleRealInfo sch : list)
  255 + put(sch);
  256 + }
  257 +
  258 + /**
  259 + * @param @param lineCode 线路编码
  260 + * @param @param schDate 班次日期 yyyy-MM-dd
  261 + * @Title: removeRealSch
  262 + * @Description: TODO(清除实际排班,包括数据库和内存数据)
  263 + */
  264 + public void removeRealSch(String lineCode, String schDate) throws Exception {
  265 + try {
  266 + // 清理数据库数据
  267 + schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);
  268 +
  269 + // 清理内存数据
  270 + clearRAMData(lineCode + "");
  271 + } catch (Exception e) {
  272 + logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);
  273 + throw e;
  274 + }
  275 + }
  276 +
  277 + /**
  278 + * @Title: clearRAMData
  279 + * @Description: TODO(清理内存数据)
  280 + */
  281 + public void clearRAMData(String lineCode) {
  282 + int count = 0;
  283 + List<ScheduleRealInfo> remList = new ArrayList<>();
  284 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  285 + for (ScheduleRealInfo sch : schs) {
  286 + if (sch.getXlBm().equals(lineCode))
  287 + remList.add(sch);
  288 + }
  289 +
  290 + for (ScheduleRealInfo sch : remList) {
  291 + if (null != sch) {
  292 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  293 + id2SchedulMap.remove(sch.getId());
  294 + count++;
  295 + }
  296 + }
  297 +
  298 + logger.info(lineCode + "排班清理 " + count);
  299 + }
  300 +
  301 + /**
  302 + * @Title: existRealSch
  303 + * @Description: TODO(实际排班是否已存在)
  304 + */
  305 + public boolean existRealSch(String lineCode, String schDate) {
  306 + int count = schRepository.countByLineCodeAndDate(lineCode, schDate);
  307 + return count > 0;
  308 + }
  309 +
  310 + /**
  311 + * @Title: loadRealSch
  312 + * @Description: TODO(从实际排班表加载数据)
  313 + */
  314 + public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {
  315 + return schRepository.findByLineCodeAndDate(lineCode, schDate);
  316 + }
  317 +
  318 + /**
  319 + * @Title: loadPlanSch
  320 + * @Description: TODO(从计划排班表加载数据)
  321 + */
  322 + public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {
  323 + logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);
  324 + List<ScheduleRealInfo> realList = new ArrayList<>();
  325 +
  326 + try {
  327 + Map<String, Object> data = new HashMap<>();
  328 +
  329 + data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());
  330 + data.put("xlBm_eq", lineCode);
  331 +
  332 + // 查询计划排班
  333 + List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());
  334 +
  335 + // 转换为实际排班
  336 + realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
  337 +
  338 + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
  339 + String fcsj;
  340 + for (ScheduleRealInfo sch : realList) {
  341 + sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));
  342 + sch.setRealExecDate(sch.getScheduleDateStr());
  343 +
  344 + if (StringUtils.isEmpty(sch.getFcsj()))
  345 + sch.setFcsj("00:00");
  346 +
  347 + fcsj = sch.getFcsj().trim();
  348 + //处理一下发车时间格式没有:号的问题
  349 + if (fcsj.indexOf(":") == -1 && fcsj.length() >= 4) {
  350 + sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));
  351 + }
  352 +
  353 + try {
  354 + sdf.parse(sch.getFcsj());
  355 + } catch (ParseException e) {
  356 + //发车时间仍然校验不过的,直接写成00:00
  357 + sch.setFcsj("00:00");
  358 + }
  359 + sch.setDfsj(sch.getFcsj());
  360 +
  361 + // 计划终点时间
  362 + if (sch.getBcsj() != null) {
  363 + sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));
  364 + sch.setLate(false);
  365 + }
  366 + //计划里程为0,设置NULL
  367 + if (sch.getJhlc() != null && sch.getJhlc() == 0)
  368 + sch.setJhlc(null);
  369 + }
  370 + } catch (Exception e) {
  371 + logger.error("", e);
  372 + }
  373 + return realList;
  374 + }
  375 +
  376 + /**
  377 + * @Title: batchSave
  378 + * @Description: TODO(批量入库)
  379 + */
  380 + private void batchSave(List<ScheduleRealInfo> list) {
  381 + // 查询数据库最大ID
  382 + Long id = schRepository.getMaxId();
  383 + if (null == id)
  384 + id = 0L;
  385 + id++;
  386 +
  387 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  388 + for (ScheduleRealInfo item : list) {
  389 + item.setSpId(item.getId());// 保留原始的计划ID
  390 + item.setId(id++);// 设置ID
  391 + item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
  392 + }
  393 +
  394 + // 入库
  395 + new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);
  396 + }
  397 +
  398 + private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
  399 + List<SchedulePlanInfo> list = new ArrayList<>();
  400 +
  401 + SchedulePlanInfo sp;
  402 + while (itrab.hasNext()) {
  403 + sp = itrab.next();
  404 + sp.setSchedulePlan(null);
  405 + list.add(sp);
  406 + }
  407 + return list;
  408 + }
  409 +
  410 + /**
  411 + * @Title: findByLineCode
  412 + * @Description: TODO(lineCode 获取班次)
  413 + */
  414 + public List<ScheduleRealInfo> findByLineCode(String lineCode) {
  415 + List<ScheduleRealInfo> rs = new ArrayList<>();
  416 +
  417 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  418 + for (ScheduleRealInfo sch : schs) {
  419 + if (sch.getXlBm().equals(lineCode))
  420 + rs.add(sch);
  421 + }
  422 + return rs;
  423 + }
  424 +
  425 + /**
  426 + * @Title: findCarByLineCode
  427 + * @Description: TODO(线路下运营的车辆)
  428 + */
  429 + public Set<String> findCarByLineCode(String lineCode) {
  430 + Set<String> rs = new HashSet<>();
  431 +
  432 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  433 + for (ScheduleRealInfo sch : schs) {
  434 + if (sch.getXlBm().equals(lineCode))
  435 + rs.add(sch.getClZbh());
  436 + }
  437 +
  438 + return rs;
  439 + }
  440 +
  441 + public List<ScheduleRealInfo> findByNbbm(String nbbm) {
  442 + return nbbmScheduleMap.get(nbbm);
  443 + }
  444 +
  445 + /**
  446 + * @Title: findByLineAndUpDown
  447 + * @Description: TODO(lineCode 和走向获取班次)
  448 + */
  449 + public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {
  450 + List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();
  451 +
  452 + for (ScheduleRealInfo sch : list) {
  453 + if (sch.getXlDir().equals(upDown + ""))
  454 + rs.add(sch);
  455 + }
  456 + return rs;
  457 + }
  458 +
  459 + public ScheduleRealInfo get(long id) {
  460 + return id2SchedulMap.get(id);
  461 + }
  462 +
  463 + public Set<String> getSEStationList(String nbbm) {
  464 + return nbbm2SEStationMap.get(nbbm);
  465 + }
  466 +
  467 + /**
  468 + * @Title: next
  469 + * @Description: TODO(下一个班次)
  470 + */
  471 + public ScheduleRealInfo next(ScheduleRealInfo sch) {
  472 +
  473 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  474 + int outConfig = -1;
  475 + LineConfig config = lineConfigData.get(sch.getXlBm());
  476 + if (config != null)
  477 + outConfig = config.getOutConfig();
  478 +
  479 + boolean flag = false;
  480 + ScheduleRealInfo next = null;
  481 + for (ScheduleRealInfo temp : list) {
  482 + if (temp.getId() == sch.getId()) {
  483 + flag = true;
  484 + continue;
  485 + }
  486 + //忽略烂班
  487 + if (temp.isDestroy())
  488 + continue;
  489 +
  490 + //出站既出场,忽略出场班次
  491 + if (outConfig == 2 && temp.getBcType().equals("out"))
  492 + continue;
  493 +
  494 + if (flag) {
  495 + next = temp;
  496 + break;
  497 + }
  498 + }
  499 + return next;
  500 + }
  501 +
  502 + /**
  503 + * 上一个班次
  504 + *
  505 + * @param sch
  506 + * @return
  507 + */
  508 + public ScheduleRealInfo prev(ScheduleRealInfo sch) {
  509 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  510 +
  511 + //boolean flag = false;
  512 + ScheduleRealInfo prev = null;
  513 + int size = list.size();
  514 +
  515 + for (int i = 0; i < size; i++) {
  516 + if (list.get(i).isDestroy())
  517 + continue;
  518 +
  519 + if (list.get(i).getId().equals(sch.getId())) {
  520 + return prev;
  521 + }
  522 + prev = list.get(i);
  523 + }
  524 + return prev;
  525 + }
  526 +
  527 + public void put(ScheduleRealInfo sch) {
  528 + schAttrCalculator
  529 + .calcRealDate(sch)
  530 + .calcAllTimeByFcsj(sch);
  531 +
  532 + String nbbm = sch.getClZbh();
  533 + nbbmScheduleMap.put(nbbm, sch);
  534 + nbbm2SEStationMap.put(nbbm, sch.getQdzCode());
  535 + nbbm2SEStationMap.put(nbbm, sch.getZdzCode());
  536 +
  537 + //主键索引
  538 + id2SchedulMap.put(sch.getId(), sch);
  539 + //跨24点的,再save一次
  540 + if (!sch.getRealExecDate().equals(sch.getScheduleDateStr()))
  541 + save(sch);
  542 + }
  543 +
  544 + public void delete(ScheduleRealInfo sch) {
  545 + //ScheduleRealInfo sch = id2SchedulMap.get(id);
  546 + if (!sch.isSflj())
  547 + return;
  548 +
  549 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  550 + id2SchedulMap.remove(sch.getId());
  551 + //return sch;
  552 + }
530 553
531 - if(list.get(i).getId().equals(sch.getId())){  
532 - return prev;  
533 - }  
534 - prev = list.get(i);  
535 - }  
536 - return prev;  
537 - }  
538 -  
539 - public void put(ScheduleRealInfo sch) {  
540 - schAttrCalculator  
541 - .calcRealDate(sch)  
542 - .calcAllTimeByFcsj(sch);  
543 -  
544 - String nbbm = sch.getClZbh();  
545 - nbbmScheduleMap.put(nbbm, sch);  
546 - nbbm2SEStationMap.put(nbbm, sch.getQdzCode());  
547 - nbbm2SEStationMap.put(nbbm, sch.getZdzCode());  
548 -  
549 - //主键索引  
550 - id2SchedulMap.put(sch.getId(), sch);  
551 - //跨24点的,再save一次  
552 - if(!sch.getRealExecDate().equals(sch.getScheduleDateStr()))  
553 - save(sch);  
554 - }  
555 -  
556 - public void delete(ScheduleRealInfo sch) {  
557 - //ScheduleRealInfo sch = id2SchedulMap.get(id);  
558 - if(!sch.isSflj())  
559 - return;  
560 -  
561 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
562 - id2SchedulMap.remove(sch.getId());  
563 - //return sch;  
564 - }  
565 -  
566 // public void calcQdzTimePlan(String nbbm){ 554 // public void calcQdzTimePlan(String nbbm){
567 // schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm)); 555 // schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
568 // } 556 // }
569 -  
570 - public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm){  
571 - return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));  
572 - }  
573 -  
574 - /**  
575 - *  
576 - * @Title: nextAll  
577 - * @Description: TODO(之后的所有班次)  
578 - */ 557 +
  558 + public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm) {
  559 + return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));
  560 + }
  561 +
  562 + /**
  563 + *
  564 + * @Title: nextAll
  565 + * @Description: TODO(之后的所有班次)
  566 + */
579 /* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) { 567 /* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) {
580 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); 568 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
581 // 排序 569 // 排序
582 Collections.sort(list, schFCSJComparator); 570 Collections.sort(list, schFCSJComparator);
583 571
@@ -592,190 +580,193 @@ public class DayOfSchedule implements CommandLineRunner { @@ -592,190 +580,193 @@ public class DayOfSchedule implements CommandLineRunner {
592 return rs; 580 return rs;
593 }*/ 581 }*/
594 582
595 - /**  
596 - *  
597 - * @Title: doneSum  
598 - * @Description: TODO(已完成班次总数)  
599 - */  
600 - public int doneSum(String clZbh) {  
601 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);  
602 - int rs = 0;  
603 -  
604 - for(ScheduleRealInfo sch : list){  
605 - if(sch.getStatus() == 2 && !sch.isDestroy())  
606 - rs ++;  
607 - }  
608 - return rs;  
609 - }  
610 -  
611 - /**  
612 - *  
613 - * @Title: prveNotExecNum  
614 - * @Description: TODO(班次之前未执行班次数量)  
615 - */  
616 - public int prveNotExecNum(ScheduleRealInfo sch){  
617 - int n = 0;  
618 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
619 - for(ScheduleRealInfo s : list){  
620 - if(s.getFcsjActual() == null && !s.isDestroy())  
621 - n ++;  
622 -  
623 - if(s.getId().equals(sch.getId()))  
624 - break;  
625 - }  
626 - return n;  
627 - }  
628 -  
629 - /**  
630 - *  
631 - * @Title: validEndTime  
632 - * @Description: TODO(是否是有效的到达时间)  
633 - */  
634 - public boolean validEndTime(ScheduleRealInfo sch, Long ts) {  
635 - if(sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)  
636 - return false;  
637 -  
638 - return validTime(sch, ts);  
639 - }  
640 -  
641 - /**  
642 - *  
643 - * @Title: validStartTime  
644 - * @Description: TODO(是否是合适的发车时间)  
645 - */  
646 - public boolean validStartTime(ScheduleRealInfo sch, Long ts) {  
647 - if(sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)  
648 - return false;  
649 -  
650 - return validTime(sch, ts);  
651 - }  
652 -  
653 - public boolean validTime(ScheduleRealInfo sch, Long ts){  
654 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
655 - int ci = list.indexOf(sch);  
656 - ScheduleRealInfo prve, next;  
657 - if(ci > 0){  
658 - //之前班次实际时间不能大于该时间  
659 - for(int i = ci - 1; i >= 0; i --){  
660 - prve = list.get(i);  
661 - if(prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts )  
662 - return false;  
663 -  
664 - if(prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)  
665 - return false;  
666 - }  
667 - }  
668 -  
669 - if(ci < list.size() - 1){  
670 - //之后班次实际时间不能小于该时间  
671 - for(int i = ci + 1; i < list.size(); i ++){  
672 - next = list.get(i);  
673 - if(next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)  
674 - return false;  
675 -  
676 - if(next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)  
677 - return false;  
678 - }  
679 - }  
680 - return true;  
681 - }  
682 -  
683 - public void save(ScheduleRealInfo sch){  
684 - //schRepository.save(sch);  
685 - pstBuffer.add(sch);  
686 - }  
687 -  
688 -  
689 - /**  
690 - *  
691 - * @Title: nextByBcType  
692 - * @Description: TODO(获取下一个指定班次类型的班次)  
693 - */  
694 - public ScheduleRealInfo nextByBcType(String nbbm, String bcType){  
695 - List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);  
696 -  
697 - Collections.sort(list, schFCSJComparator);  
698 - ScheduleRealInfo sch = null;  
699 - for(ScheduleRealInfo temp : list){  
700 - if(temp.getFcsjActual() == null)  
701 - sch = temp;  
702 - }  
703 -  
704 - return sch;  
705 - }  
706 -  
707 - public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType){  
708 - List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)  
709 - ,outList = new ArrayList<>();  
710 -  
711 - for(ScheduleRealInfo sch : all){  
712 - if(sch.getBcType().equals(bcType))  
713 - outList.add(sch);  
714 - }  
715 - return outList;  
716 - }  
717 -  
718 - public Set<String> allCar(){  
719 - return nbbmScheduleMap.keySet();  
720 - }  
721 -  
722 - public Collection<ScheduleRealInfo> findAll(){  
723 - return nbbmScheduleMap.values();  
724 - }  
725 -  
726 - public void addExecPlan(ScheduleRealInfo sch){  
727 - carExecutePlanMap.put(sch.getClZbh(), sch);  
728 - }  
729 -  
730 - public void removeExecPlan(String clzbh){  
731 - carExecutePlanMap.remove(clzbh);  
732 - }  
733 -  
734 - public Map<String, ScheduleRealInfo> execPlanMap(){  
735 - return carExecutePlanMap;  
736 - }  
737 -  
738 - /**  
739 - * 车辆当前执行的班次  
740 - * @param nbbm  
741 - * @return  
742 - */  
743 - public static ScheduleRealInfo executeCurr(String nbbm){  
744 - return carExecutePlanMap.get(nbbm);  
745 - }  
746 -  
747 - /**  
748 - * @Title: changeCar  
749 - * @Description: TODO(班次换车) 返回有更新的班次  
750 - * @param @param sch  
751 - * @param @param newClZbh 新的车辆自编号  
752 - */  
753 - public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch , String newClZbh){  
754 - List<ScheduleRealInfo> ups = new ArrayList<>();  
755 - String oldClzbh = sch.getClZbh();  
756 - if(oldClzbh.equals(newClZbh))  
757 - return ups;  
758 -  
759 -  
760 - //变更相关映射信息  
761 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
762 -  
763 - sch.setClZbh(newClZbh);  
764 - nbbmScheduleMap.put(newClZbh, sch);  
765 - nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());  
766 - nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());  
767 -  
768 - //重新计算班次应到时间  
769 - ups.addAll(updateQdzTimePlan(oldClzbh));  
770 - ups.addAll(updateQdzTimePlan(newClZbh));  
771 - return ups;  
772 - }  
773 -  
774 - /**  
775 - *  
776 - * @Title: linkToSchPlan  
777 - * @Description: TODO(车辆关联到班次)  
778 - */ 583 + /**
  584 + * @Title: doneSum
  585 + * @Description: TODO(已完成班次总数)
  586 + */
  587 + public int doneSum(String clZbh) {
  588 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);
  589 + int rs = 0;
  590 +
  591 + for (ScheduleRealInfo sch : list) {
  592 + if (sch.getStatus() == 2 && !sch.isDestroy())
  593 + rs++;
  594 + }
  595 + return rs;
  596 + }
  597 +
  598 + /**
  599 + * @Title: prveNotExecNum
  600 + * @Description: TODO(班次之前未执行班次数量)
  601 + */
  602 + public int prveNotExecNum(ScheduleRealInfo sch) {
  603 + int n = 0;
  604 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  605 + for (ScheduleRealInfo s : list) {
  606 + if (s.getFcsjActual() == null && !s.isDestroy())
  607 + n++;
  608 +
  609 + if (s.getId().equals(sch.getId()))
  610 + break;
  611 + }
  612 + return n;
  613 + }
  614 +
  615 + /**
  616 + * @Title: validEndTime
  617 + * @Description: TODO(是否是有效的到达时间)
  618 + */
  619 + public boolean validEndTime(ScheduleRealInfo sch, Long ts) {
  620 + if (sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)
  621 + return false;
  622 +
  623 + return validTime(sch, ts);
  624 + }
  625 +
  626 + /**
  627 + * @Title: validStartTime
  628 + * @Description: TODO(是否是合适的发车时间)
  629 + */
  630 + public boolean validStartTime(ScheduleRealInfo sch, Long ts) {
  631 + if (sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)
  632 + return false;
  633 +
  634 + return validTime(sch, ts);
  635 + }
  636 +
  637 + public boolean validTime(ScheduleRealInfo sch, Long ts) {
  638 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  639 + int ci = list.indexOf(sch);
  640 + ScheduleRealInfo prve, next;
  641 + if (ci > 0) {
  642 + //之前班次实际时间不能大于该时间
  643 + for (int i = ci - 1; i >= 0; i--) {
  644 + prve = list.get(i);
  645 + if (prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts)
  646 + return false;
  647 +
  648 + if (prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)
  649 + return false;
  650 + }
  651 + }
  652 +
  653 + if (ci < list.size() - 1) {
  654 + //之后班次实际时间不能小于该时间
  655 + for (int i = ci + 1; i < list.size(); i++) {
  656 + next = list.get(i);
  657 + if (next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)
  658 + return false;
  659 +
  660 + if (next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)
  661 + return false;
  662 + }
  663 + }
  664 + return true;
  665 + }
  666 +
  667 + public void save(ScheduleRealInfo sch) {
  668 + //schRepository.save(sch);
  669 + pstBuffer.add(sch);
  670 + }
  671 +
  672 +
  673 + /**
  674 + * @Title: nextByBcType
  675 + * @Description: TODO(获取下一个指定班次类型的班次)
  676 + */
  677 + public ScheduleRealInfo nextByBcType(String nbbm, String bcType) {
  678 + List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);
  679 +
  680 + Collections.sort(list, schFCSJComparator);
  681 + ScheduleRealInfo sch = null;
  682 + for (ScheduleRealInfo temp : list) {
  683 + if (temp.getFcsjActual() == null)
  684 + sch = temp;
  685 + }
  686 +
  687 + return sch;
  688 + }
  689 +
  690 + public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType) {
  691 + List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm), outList = new ArrayList<>();
  692 +
  693 + for (ScheduleRealInfo sch : all) {
  694 + if (sch.getBcType().equals(bcType))
  695 + outList.add(sch);
  696 + }
  697 + return outList;
  698 + }
  699 +
  700 + public Set<String> allCar() {
  701 + return nbbmScheduleMap.keySet();
  702 + }
  703 +
  704 + public Collection<ScheduleRealInfo> findAll() {
  705 + return nbbmScheduleMap.values();
  706 + }
  707 +
  708 + public void addExecPlan(ScheduleRealInfo sch) {
  709 + carExecutePlanMap.put(sch.getClZbh(), sch);
  710 + }
  711 +
  712 + public void removeExecPlan(String clzbh) {
  713 + carExecutePlanMap.remove(clzbh);
  714 + }
  715 +
  716 + public Map<String, ScheduleRealInfo> execPlanMap() {
  717 + return carExecutePlanMap;
  718 + }
  719 +
  720 + /**
  721 + * 车辆当前执行的班次
  722 + *
  723 + * @param nbbm
  724 + * @return
  725 + */
  726 + public static ScheduleRealInfo executeCurr(String nbbm) {
  727 + return carExecutePlanMap.get(nbbm);
  728 + }
  729 +
  730 + /**
  731 + * @param @param sch
  732 + * @param @param newClZbh 新的车辆自编号
  733 + * @Title: changeCar
  734 + * @Description: TODO(班次换车) 返回有更新的班次
  735 + */
  736 + public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch, String newClZbh) {
  737 + List<ScheduleRealInfo> ups = new ArrayList<>();
  738 + String oldClzbh = sch.getClZbh();
  739 + if (oldClzbh.equals(newClZbh))
  740 + return ups;
  741 +
  742 +
  743 + //变更相关映射信息
  744 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  745 +
  746 + sch.setClZbh(newClZbh);
  747 + nbbmScheduleMap.put(newClZbh, sch);
  748 + nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());
  749 + nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());
  750 +
  751 + //重新计算班次应到时间
  752 + ups.addAll(updateQdzTimePlan(oldClzbh));
  753 + ups.addAll(updateQdzTimePlan(newClZbh));
  754 +
  755 + //重新计算车辆当前执行班次
  756 + reCalcExecPlan(newClZbh);
  757 + reCalcExecPlan(sch.getClZbh());
  758 + return ups;
  759 + }
  760 +
  761 + public void reCalcExecPlan(String nbbm){
  762 + carExecutePlanMap.put(nbbm, schAttrCalculator.calcCurrentExecSch(nbbmScheduleMap.get(nbbm)));
  763 + }
  764 +
  765 + /**
  766 + *
  767 + * @Title: linkToSchPlan
  768 + * @Description: TODO(车辆关联到班次)
  769 + */
779 /* public void linkToSchPlan(String nbbm) { 770 /* public void linkToSchPlan(String nbbm) {
780 //当前GPS状态 771 //当前GPS状态
781 GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); 772 GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
src/main/java/com/bsth/entity/realcontrol/LineConfig.java
1 package com.bsth.entity.realcontrol; 1 package com.bsth.entity.realcontrol;
2 2
  3 +import com.bsth.entity.Line;
  4 +
  5 +import javax.persistence.*;
3 import java.text.ParseException; 6 import java.text.ParseException;
4 import java.text.SimpleDateFormat; 7 import java.text.SimpleDateFormat;
5 import java.util.Date; 8 import java.util.Date;
6 import java.util.HashSet; 9 import java.util.HashSet;
7 import java.util.Set; 10 import java.util.Set;
8 11
9 -import javax.persistence.CascadeType;  
10 -import javax.persistence.Entity;  
11 -import javax.persistence.GeneratedValue;  
12 -import javax.persistence.Id;  
13 -import javax.persistence.NamedAttributeNode;  
14 -import javax.persistence.NamedEntityGraph;  
15 -import javax.persistence.NamedEntityGraphs;  
16 -import javax.persistence.OneToMany;  
17 -import javax.persistence.OneToOne;  
18 -import javax.persistence.Table;  
19 -import javax.persistence.Transient;  
20 -  
21 -import com.bsth.entity.Line;  
22 -import com.bsth.util.DateUtils;  
23 -  
24 /** 12 /**
25 * 13 *
26 * @ClassName: LineConfig 14 * @ClassName: LineConfig
@@ -59,9 +47,6 @@ public class LineConfig { @@ -59,9 +47,6 @@ public class LineConfig {
59 /** 出场时间设置 0:真实出场(设备离开缓冲区时间) 1:请求出场时间 2:出站即出场 */ 47 /** 出场时间设置 0:真实出场(设备离开缓冲区时间) 1:请求出场时间 2:出站即出场 */
60 private int outConfig; 48 private int outConfig;
61 49
62 - /** 进场时间设置 0:真实进场(设备进入缓冲区时间) 1:请求进场时间 2:出站即出场*/  
63 - private int inConfig;  
64 -  
65 /** 短语模板 , 号分隔多个 */ 50 /** 短语模板 , 号分隔多个 */
66 private String phraseTemps; 51 private String phraseTemps;
67 52
@@ -111,14 +96,6 @@ public class LineConfig { @@ -111,14 +96,6 @@ public class LineConfig {
111 this.outConfig = outConfig; 96 this.outConfig = outConfig;
112 } 97 }
113 98
114 - public int getInConfig() {  
115 - return inConfig;  
116 - }  
117 -  
118 - public void setInConfig(int inConfig) {  
119 - this.inConfig = inConfig;  
120 - }  
121 -  
122 public String getPhraseTemps() { 99 public String getPhraseTemps() {
123 return phraseTemps; 100 return phraseTemps;
124 } 101 }
src/main/java/com/bsth/service/realcontrol/ScheduleRealInfoService.java
@@ -27,8 +27,8 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L @@ -27,8 +27,8 @@ public interface ScheduleRealInfoService extends BaseService&lt;ScheduleRealInfo, L
27 27
28 List<Map<String, String>> sreachVehic(String nbbm); 28 List<Map<String, String>> sreachVehic(String nbbm);
29 29
30 - Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr);  
31 - 30 +/* Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr);
  31 + */
32 /** 32 /**
33 * 33 *
34 * @Title: adjustCar 34 * @Title: adjustCar
src/main/java/com/bsth/service/realcontrol/impl/LineConfigServiceImpl.java
@@ -70,7 +70,7 @@ public class LineConfigServiceImpl extends BaseServiceImpl&lt;LineConfig, Integer&gt; @@ -70,7 +70,7 @@ public class LineConfigServiceImpl extends BaseServiceImpl&lt;LineConfig, Integer&gt;
70 LineConfig conf = lineConfigData.get(lineCode); 70 LineConfig conf = lineConfigData.get(lineCode);
71 71
72 conf.setOutConfig(type); 72 conf.setOutConfig(type);
73 - conf.setInConfig(type); 73 + //conf.setInConfig(type);
74 lineConfigData.set(conf); 74 lineConfigData.set(conf);
75 75
76 rs.put("status", ResponseCode.SUCCESS); 76 rs.put("status", ResponseCode.SUCCESS);
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
@@ -382,7 +382,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -382,7 +382,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
382 return list; 382 return list;
383 } 383 }
384 384
385 - @Override 385 +/* @Override
386 public Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) { 386 public Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
387 // 班次 387 // 班次
388 ScheduleRealInfo schedule = dayOfSchedule.get(id); 388 ScheduleRealInfo schedule = dayOfSchedule.get(id);
@@ -435,7 +435,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -435,7 +435,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
435 map.put("status", 200); 435 map.put("status", 200);
436 map.put("t", schedule); 436 map.put("t", schedule);
437 return map; 437 return map;
438 - } 438 + }*/
439 439
440 @Override 440 @Override
441 public void adjustCar(ScheduleRealInfo schedule, String car) { 441 public void adjustCar(ScheduleRealInfo schedule, String car) {
@@ -678,7 +678,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -678,7 +678,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
678 sch.addRemarks(remarks); 678 sch.addRemarks(remarks);
679 sch.calcStatus(); 679 sch.calcStatus();
680 680
681 - scheduleRealInfoRepository.save(sch); 681 + dayOfSchedule.save(sch);
  682 + //scheduleRealInfoRepository.save(sch);
682 683
683 ts.add(sch); 684 ts.add(sch);
684 685
@@ -881,10 +882,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -881,10 +882,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
881 next.setQdzArrDateSJ(zdsjActual); 882 next.setQdzArrDateSJ(zdsjActual);
882 ts.add(next); 883 ts.add(next);
883 } 884 }
  885 +
  886 + //重新计算车辆执行班次
  887 + dayOfSchedule.reCalcExecPlan(sch.getClZbh());
884 } 888 }
885 } 889 }
886 else { 890 else {
887 - if(sch.getZdsjActual() != null){ 891 + /*if(sch.getZdsjActual() != null){
888 //将对应的到离站数据标记为不可信 892 //将对应的到离站数据标记为不可信
889 List<ArrivalEntity> list = ArrivalData_GPS.findByNbbm(sch.getClZbh()); 893 List<ArrivalEntity> list = ArrivalData_GPS.findByNbbm(sch.getClZbh());
890 for(ArrivalEntity arr : list){ 894 for(ArrivalEntity arr : list){
@@ -896,7 +900,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf @@ -896,7 +900,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
896 break; 900 break;
897 } 901 }
898 } 902 }
899 - } 903 + }*/
900 904
901 //清除实达时间 905 //清除实达时间
902 sch.clearZdsjActual(); 906 sch.clearZdsjActual();
src/main/resources/static/pages/control/lineConfig/config.html
@@ -108,7 +108,7 @@ butto.line-config-btn{ @@ -108,7 +108,7 @@ butto.line-config-btn{
108 font-size: 85%; 108 font-size: 85%;
109 } 109 }
110 110
111 -butto.line-config-btn:HOVER{ 111 +button.line-config-btn:HOVER{
112 background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0); 112 background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
113 border-color: rgba(0, 0, 0, 0.3); 113 border-color: rgba(0, 0, 0, 0.3);
114 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12), inset 0 1px 2px rgba(255, 255, 255, 0.95); 114 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12), inset 0 1px 2px rgba(255, 255, 255, 0.95);
@@ -116,7 +116,7 @@ butto.line-config-btn:HOVER{ @@ -116,7 +116,7 @@ butto.line-config-btn:HOVER{
116 } 116 }
117 117
118 118
119 -butto.line-config-btn:active{ 119 +button.line-config-btn:active{
120 background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0); 120 background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
121 border-color: #5b5bec; 121 border-color: #5b5bec;
122 box-shadow: 0 1px 0 rgba(91, 91, 236, 0.32), inset 0 1px 2px rgba(91, 91, 236, 0.32); 122 box-shadow: 0 1px 0 rgba(91, 91, 236, 0.32), inset 0 1px 2px rgba(91, 91, 236, 0.32);
@@ -212,7 +212,11 @@ butto.line-config-btn:active{ @@ -212,7 +212,11 @@ butto.line-config-btn:active{
212 </section> 212 </section>
213 213
214 <section> 214 <section>
215 - <h3>班次进出场时间</h3> 215 + <h3>班次进出场
  216 +{{if conf.outConfig == 2}}
  217 +(“出站既出场” 只影响<a href="/pages/base/lineinformation/list.html?no={{conf.line.id}}" target="_blank" style="color: grey;margin: 0 2px;">线路标准</a>内配置的停车场发出的班次)
  218 +{{/if}}
  219 + </h3>
216 220
217 <div class="settings-row" > 221 <div class="settings-row" >
218 <p > 使用 <a href="javascript:;" data-type="select" id="outTimeType"></a> 时间作为出场班次的实际时间。</p> 222 <p > 使用 <a href="javascript:;" data-type="select" id="outTimeType"></a> 时间作为出场班次的实际时间。</p>
@@ -273,18 +277,19 @@ butto.line-config-btn:active{ @@ -273,18 +277,19 @@ butto.line-config-btn:active{
273 } 277 }
274 278
275 function defaultConfig(lineCode, name){ 279 function defaultConfig(lineCode, name){
276 - layer.confirm('没有找到['+html_encode(name)+']的配置信息,系统将生成默认配置?', {  
277 - btn : [ '我同意' ],  
278 - icon : 3,  
279 - shift: 5,  
280 - closeBtn: 0  
281 - }, function(){  
282 - showLoad('生成中...');  
283 - $.post('/lineConfig/init/' + lineCode, function(rs){  
284 - if(rs == 1)  
285 - showConfDetail();  
286 - });  
287 - }); 280 + $body.html('无配置信息');
  281 +// layer.confirm('没有找到['+html_encode(name)+']的配置信息,系统将生成默认配置?', {
  282 +// btn : [ '我同意' ],
  283 +// icon : 3,
  284 +// shift: 5,
  285 +// closeBtn: 0
  286 +// }, function(){
  287 +// showLoad('生成中...');
  288 +// $.post('/lineConfig/init/' + lineCode, function(rs){
  289 +// if(rs == 1)
  290 +// showConfDetail();
  291 +// });
  292 +// });
288 } 293 }
289 294
290 function showLoad(text){ 295 function showLoad(text){
src/main/resources/static/pages/mapmonitor/real/js/playBack.js
@@ -269,7 +269,7 @@ var playBack = (function() { @@ -269,7 +269,7 @@ var playBack = (function() {
269 269
270 if(defaultLine){ 270 if(defaultLine){
271 layer.msg('加载线路图层数据...', {icon: 16, time: 0,shade:0.3}); 271 layer.msg('加载线路图层数据...', {icon: 16, time: 0,shade:0.3});
272 - $.get('/realSchedule/findRouteByLine', {lineCode: defaultLine} 272 + $.get('/realMap/findRouteByLine', {lineCode: defaultLine}
273 ,function(route){ 273 ,function(route){
274 lineRoute = route; 274 lineRoute = route;
275 iMap.call('drawLine', {route: lineRoute}); 275 iMap.call('drawLine', {route: lineRoute});
src/main/resources/static/real_control_v2/css/line_schedule.css
@@ -257,7 +257,7 @@ span.fcsj-diff { @@ -257,7 +257,7 @@ span.fcsj-diff {
257 } 257 }
258 258
259 .tl-wd{ 259 .tl-wd{
260 - background: #caca4f; 260 + background: #dede57;
261 color: #444; 261 color: #444;
262 } 262 }
263 263
src/main/resources/static/real_control_v2/js/line_schedule/sch_table.js
@@ -188,6 +188,7 @@ var gb_schedule_table = (function () { @@ -188,6 +188,7 @@ var gb_schedule_table = (function () {
188 188
189 //更新班次 189 //更新班次
190 var updateSchedule = function (schArr) { 190 var updateSchedule = function (schArr) {
  191 +
191 if (!isArray(schArr)) 192 if (!isArray(schArr))
192 schArr = [schArr]; 193 schArr = [schArr];
193 194
@@ -199,12 +200,12 @@ var gb_schedule_table = (function () { @@ -199,12 +200,12 @@ var gb_schedule_table = (function () {
199 tMaps[this.xlBm+'_'+this.clZbh]=1; 200 tMaps[this.xlBm+'_'+this.clZbh]=1;
200 }); 201 });
201 202
202 - //重新标记末班 203 + /* //重新标记末班
203 var ts=[]; 204 var ts=[];
204 for(var k in tMaps){ 205 for(var k in tMaps){
205 ts = k.split('_'); 206 ts = k.split('_');
206 markerLastByNbbm(ts[0], ts[1]); 207 markerLastByNbbm(ts[0], ts[1]);
207 - } 208 + }*/
208 }; 209 };
209 210
210 //update dom 211 //update dom
@@ -216,11 +217,11 @@ var gb_schedule_table = (function () { @@ -216,11 +217,11 @@ var gb_schedule_table = (function () {
216 217
217 //车辆自编号 218 //车辆自编号
218 $(dds[2]).replaceWith(temps['line-schedule-nbbm-temp'](sch)); 219 $(dds[2]).replaceWith(temps['line-schedule-nbbm-temp'](sch));
219 - if (sch.qdzArrDateJH)  
220 - $(dds[3]).text(sch.qdzArrDateJH); 220 + //if (sch.qdzArrDateJH)
  221 + $(dds[3]).text(sch.qdzArrDateJH?sch.qdzArrDateJH:'');
221 222
222 - if (sch.qdzArrDateSJ)  
223 - $(dds[4]).text(sch.qdzArrDateSJ); 223 + //if (sch.qdzArrDateSJ)
  224 + $(dds[4]).text(sch.qdzArrDateSJ?sch.qdzArrDateSJ:'');
224 225
225 //计发时间 226 //计发时间
226 $(dds[5]).replaceWith(temps['line-schedule-fcsj-temp'](sch)); 227 $(dds[5]).replaceWith(temps['line-schedule-fcsj-temp'](sch));
src/main/resources/static/real_control_v2/js/utils/svg_chart.js
@@ -296,8 +296,9 @@ var gb_svg_chart = (function() { @@ -296,8 +296,9 @@ var gb_svg_chart = (function() {
296 return isDown ? y + 7 : y - 32; 296 return isDown ? y + 7 : y - 32;
297 }); 297 });
298 //merge text 298 //merge text
299 - mergerG.append('text').text(gpsArr.length)  
300 - .attr('x', x - 4) 299 + var len = gpsArr.length;
  300 + mergerG.append('text').text(len)
  301 + .attr('x', x - ((len + '').length * 4))
301 .attr('y', isDown ? y + 24 : y - 14); 302 .attr('y', isDown ? y + 24 : y - 14);
302 } 303 }
303 304
src/main/resources/static/real_control_v2/mapmonitor/fragments/playback/before_form.html
@@ -75,12 +75,12 @@ @@ -75,12 +75,12 @@
75 $('[name=sDate]', this).val(m.subtract(2, 'hour').format(rq)); 75 $('[name=sDate]', this).val(m.subtract(2, 'hour').format(rq));
76 $('[name=sTime]', this).val(m.format(sj)); 76 $('[name=sTime]', this).val(m.format(sj));
77 77
78 - //test 78 +/* //test
79 $('[name=nbbm]', this).val('W9H-003'); 79 $('[name=nbbm]', this).val('W9H-003');
80 $('[name=eDate]', this).val('2016-12-10'); 80 $('[name=eDate]', this).val('2016-12-10');
81 $('[name=eTime]', this).val('09:00'); 81 $('[name=eTime]', this).val('09:00');
82 $('[name=sDate]', this).val('2016-12-10'); 82 $('[name=sDate]', this).val('2016-12-10');
83 - $('[name=sTime]', this).val('07:00'); 83 + $('[name=sTime]', this).val('07:00');*/
84 }); 84 });
85 85
86 var ONE_DAY = 1000 * 60 * 60 * 24; 86 var ONE_DAY = 1000 * 60 * 60 * 24;