Commit 299f3ea78b770740e575f06454216cb23f5d90ee

Authored by 潘钊
1 parent 7f3e723b

update

src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
... ... @@ -131,13 +131,13 @@ public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo,
131 131 * @Title: adjust @Description: TODO(调整人车) @param @param id
132 132 * 班次ID @param @param nbbm 内部编码 @param @param jsy 驾驶员 @param @param spy
133 133 * 售票员 @throws
134   - */
  134 +
135 135 @RequestMapping(value = "/adjust", method = RequestMethod.POST)
136 136 public Map<String, Object> adjust(@RequestParam Long id, String nbbm, String jsy,
137 137 String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
138 138 return scheduleRealInfoService.adjust(id, nbbm, jsy, spy, revertLine, borrowLine, borrowTimeStr, revertTimeStr);
139 139 }
140   -
  140 + */
141 141 /**
142 142 *
143 143 * @Title: realOutAdjust
... ...
src/main/java/com/bsth/data/LineConfigData.java
1 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 3 import com.bsth.entity.Line;
16 4 import com.bsth.entity.realcontrol.D80ReplyTemp;
17 5 import com.bsth.entity.realcontrol.LineConfig;
18 6 import com.bsth.oplog.normal.OpLogger;
19 7 import com.bsth.service.LineService;
20 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 87 //出场时间类型
93 88 conf.setOutConfig(1);
94 89 //进场时间类型
95   - conf.setInConfig(1);
  90 + //conf.setInConfig(1);
96 91 //短语模板
97 92 conf.setPhraseTemps("");
98 93 //调度指令模板
... ...
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
... ... @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
5 5 import com.bsth.Application;
6 6 import com.bsth.data.BasicData;
7 7 import com.bsth.data.forecast.ForecastRealServer;
  8 +import com.bsth.data.gpsdata.analyse.GeoCacheData;
8 9 import com.bsth.data.gpsdata.analyse.GpsAnalyse;
9 10 import com.bsth.data.gpsdata.recovery.GpsDataRecovery;
10 11 import com.bsth.data.schedule.DayOfSchedule;
... ... @@ -58,8 +59,6 @@ public class GpsRealData implements CommandLineRunner{
58 59 @Autowired
59 60 ForecastRealServer forecastRealServer;
60 61  
61   -
62   -
63 62 /**
64 63 * 构造函数
65 64 */
... ... @@ -72,13 +71,18 @@ public class GpsRealData implements CommandLineRunner{
72 71 @Override
73 72 public void run(String... arg0) throws Exception {
74 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 78 public GpsEntity add(GpsEntity gps) {
79 79 String device = gps.getDeviceId();
80 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 86 //分析gps
83 87 if(isAvailable(gps) && (old == null || old.getTimestamp() != gps.getTimestamp()))
84 88 GpsAnalyse.start(gps);
... ...
src/main/java/com/bsth/data/gpsdata/analyse/GeoCacheData.java
... ... @@ -59,6 +59,16 @@ public class GeoCacheData {
59 59 queue.add(gps);
60 60 }
61 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 +
62 72 public static List<StationRoute> getStationRoute(String lineCode, int directions) {
63 73 return stationCacheMap.get(lineCode + "_" + directions);
64 74 }
... ... @@ -97,7 +107,7 @@ public class GeoCacheData {
97 107 String shapesType = rs.getString("SHAPES_TYPE");
98 108 //多边形电子围栏
99 109 if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d")) {
100   - geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));
  110 + sRoute.setPolygon(geometryFactory.createPolygon(parsePolygon(rs.getString("G_POLYGON_GRID"))));
101 111 }
102 112 return sRoute;
103 113 }
... ...
src/main/java/com/bsth/data/gpsdata/analyse/components/GpsArrival.java
... ... @@ -9,6 +9,8 @@ import com.bsth.data.gpsdata.analyse.util.GeoUtils;
9 9 import com.bsth.data.schedule.DayOfSchedule;
10 10 import com.bsth.entity.realcontrol.LineConfig;
11 11 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +import com.bsth.service.directive.DirectiveService;
  13 +import com.bsth.websocket.handler.SendUtils;
12 14 import org.slf4j.Logger;
13 15 import org.slf4j.LoggerFactory;
14 16 import org.springframework.beans.BeansException;
... ... @@ -28,8 +30,9 @@ public class GpsArrival implements ApplicationContextAware {
28 30 static Logger logger = LoggerFactory.getLogger(GpsArrival.class);
29 31  
30 32 static DayOfSchedule dayOfSchedule;
31   -
32 33 static LineConfigData lineConfigData;
  34 + static SendUtils sendUtils;
  35 + static DirectiveService directiveService;
33 36  
34 37 public static void arrival(GpsEntity gps) {
35 38  
... ... @@ -49,10 +52,9 @@ public class GpsArrival implements ApplicationContextAware {
49 52 //出场
50 53 if (sch.getBcType().equals("out")) {
51 54 outCarpark(gps, sch);
52   - }
53   - else if (sch.getBcType().equals("normal"))
  55 + } else if (sch.getBcType().equals("normal"))
54 56 normalInOut(gps, sch);
55   - else if(sch.getBcType().equals("in")){
  57 + else if (sch.getBcType().equals("in")) {
56 58 inCarpark(gps, sch);
57 59 }
58 60 }
... ... @@ -94,7 +96,7 @@ public class GpsArrival implements ApplicationContextAware {
94 96 * @param sch
95 97 */
96 98 private static void stationInside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
97   - if(prev == null)
  99 + if (prev == null)
98 100 return;
99 101  
100 102 if (gps.getStopNo().equals(sch.getZdzCode()) && sch.getZdsjActual() == null) {
... ... @@ -104,15 +106,16 @@ public class GpsArrival implements ApplicationContextAware {
104 106 }
105 107  
106 108 //上一个点在站外
107   - if(!prev.isInstation())
  109 + if (!prev.isInstation())
108 110 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);
  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));
116 119 }
117 120 return;
118 121 }
... ... @@ -123,6 +126,9 @@ public class GpsArrival implements ApplicationContextAware {
123 126 return;
124 127 }
125 128  
  129 + if (gps.getUpDown() != prev.getUpDown())
  130 + return;
  131 +
126 132 //中途站
127 133 StationRoute prevStation = GeoCacheData.getStation(prev.getLineId(), prev.getUpDown(), prev.getStopNo());
128 134 StationRoute currStation = GeoCacheData.getStation(gps.getLineId(), gps.getUpDown(), gps.getStopNo());
... ... @@ -132,7 +138,6 @@ public class GpsArrival implements ApplicationContextAware {
132 138  
133 139 logger.info("路由反向。。。。。。:" + gps.getTimestamp());
134 140 //为班次补上实际时间
135   -
136 141 }
137 142 }
138 143  
... ... @@ -144,7 +149,7 @@ public class GpsArrival implements ApplicationContextAware {
144 149 * @param sch
145 150 */
146 151 private static void stationOutside(GpsEntity gps, GpsEntity prev, ScheduleRealInfo sch) {
147   - if(prev == null)
  152 + if (prev == null)
148 153 return;
149 154  
150 155 gps.setStopNo(prev.getStopNo());
... ... @@ -159,42 +164,47 @@ public class GpsArrival implements ApplicationContextAware {
159 164 * 公交车起点发出
160 165 */
161 166 final static long DRIFT_VAL_TIME = 1000 * 60 * 10;
162   - //班次最大差值1小时
163   - final static long MAX_DIFF = 1000 * 60 * 60;
  167 + //班次最大差值2小时
  168 + final static long MAX_DIFF = 1000 * 60 * 60 * 2;
  169 +
164 170 private static void busWillDepart(ScheduleRealInfo sch, GpsEntity gps) {
165 171 //实发时间不覆盖
166 172 if (sch.getFcsjActual() == null && Math.abs(gps.getTimestamp() - sch.getDfsjT()) < MAX_DIFF) {
167 173  
168 174 //提前10分钟以上发出,判断一下是否是漂移
169   - if(sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME){
  175 + /*if (sch.getDfsjT() - gps.getTimestamp() > DRIFT_VAL_TIME) {
170 176 ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
171   - if(schPrev != null && schPrev.getZdsjActual() != null){
  177 + if (schPrev != null && schPrev.getZdsjActual() != null) {
172 178 //计划停站时间
173 179 long stopTimeJH = sch.getDfsjT() - schPrev.getZdsjT();
174 180 //实际停站时间
175 181 long actualStopTime = gps.getTimestamp() - schPrev.getZdsjActualTime();
176   - /*
177   - 没停够计划百分之60的,算漂移
  182 + *//*
  183 + 没停够计划百分之30的,算漂移
178 184 (这里出现的误判,由程序在车辆到中途站的时候进行补偿)
179   - */
180   - if(stopTimeJH * 0.6 < actualStopTime){
  185 + *//*
  186 + if (stopTimeJH * 0.3 > actualStopTime) {
181 187 logger.info("漂移.... 车辆:" + gps.getNbbm() + " ts: " + gps.getTimestamp());
182 188 return;
183 189 }
184 190 }
185   - }
  191 + }*/
186 192  
187 193 LineConfig config = lineConfigData.get(sch.getXlBm());
188   - if(config != null && config.getOutConfig() == 2){
  194 + if (config != null && config.getOutConfig() == 2) {
189 195 //出站既出场
190 196 ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
191   - if(schPrev.getBcType().equals("out")){
192   - schPrev.setFcsjActualAll(schPrev.getDfsjT());
193   - schPrev.setZdsjActualAll(schPrev.getZdsjT());
  197 + if (schPrev.getBcType().equals("out")) {
  198 + schPrev.setFcsjActualAll(gps.getTimestamp());
  199 + schPrev.setZdsjActualAll(gps.getTimestamp());
194 200 }
195 201 }
196 202  
197 203 sch.setFcsjActualAll(gps.getTimestamp());
  204 + //通知客户端
  205 + sendUtils.sendFcsj(sch);
  206 + //持久化
  207 + dayOfSchedule.save(sch);
198 208 logger.info("(站外)班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
199 209 }
200 210 }
... ... @@ -206,13 +216,39 @@ public class GpsArrival implements ApplicationContextAware {
206 216 * @param gps
207 217 */
208 218 private static void arriveEnd(ScheduleRealInfo sch, GpsEntity gps) {
  219 + if(Math.abs(gps.getTimestamp() - sch.getZdsjT()) >= MAX_DIFF)
  220 + return;
  221 +
209 222 sch.setZdsjActualAll(gps.getTimestamp());
210 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);
211 230 logger.info("班次:" + sch.getDfsj() + "到达终点, 时间:" + sch.getZdsjActual());
212 231  
213 232 if (next == null)
214 233 return;
215 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 +
216 252 //将gps转换为下一个班次走向的站内信号
217 253 int updown = Integer.parseInt(next.getXlDir());
218 254 List<StationRoute> srs = GeoCacheData.getStationRoute(next.getXlBm(), updown);
... ... @@ -230,39 +266,52 @@ public class GpsArrival implements ApplicationContextAware {
230 266 * @param sch
231 267 */
232 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 + //是否在停车场内
233 275 String carpark = GeoUtils.gpsInCarpark(gps);
234   - if (carpark != null) {
  276 + if (carpark != null && carpark.equals(sch.getQdzCode())) {
235 277 gps.setInstation(true);
236 278 gps.setStopNo(carpark);
237 279 return; // 还在场内
238 280 }
239 281  
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 282 List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), gps.getUpDown());
254 283 StationRoute station = GeoUtils.gpsInStation(gps, srs);
255   -
256   - if (station != null && station.getCode().equals(sch.getZdzCode())) {
  284 + //线路上 站点内
  285 + if (station != null) {
  286 + gps.setInstation(true);
257 287 gps.setStopNo(station.getCode());
  288 +
  289 + //上一个点附带的站点站标记
  290 + if (prev != null && prev.getStopNo() != null
  291 + && prev.getStopNo().equals(sch.getZdzCode()))
  292 + return;
  293 +
258 294 //到达终点
259   - arriveEnd(sch, gps);
  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 + }
260 308 }
261 309 }
262 310  
263 311  
264 312 /**
265 313 * 进场班次
  314 + *
266 315 * @param gps
267 316 * @param sch
268 317 */
... ... @@ -270,7 +319,7 @@ public class GpsArrival implements ApplicationContextAware {
270 319 String carpark = GeoUtils.gpsInCarpark(gps);
271 320 if (carpark != null && carpark.equals(sch.getZdzCode())) {
272 321 //进场班次取第一个实际进场时间
273   - if(sch.getZdsjActual() != null)
  322 + if (sch.getZdsjActual() != null)
274 323 return;
275 324  
276 325 //进场
... ... @@ -310,5 +359,7 @@ public class GpsArrival implements ApplicationContextAware {
310 359 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
311 360 dayOfSchedule = applicationContext.getBean(DayOfSchedule.class);
312 361 lineConfigData = applicationContext.getBean(LineConfigData.class);
  362 + sendUtils = applicationContext.getBean(SendUtils.class);
  363 + directiveService = applicationContext.getBean(DirectiveService.class);
313 364 }
314 365 }
... ...
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
... ... @@ -46,13 +46,14 @@ public class GpsDataRecovery {
46 46 Set<String> keys = listMap.keySet();
47 47 for (String nbbm : keys) {
48 48 threadPool.execute(new RecoveryDataThread(listMap.get(nbbm), count));
49   - /*if(nbbm.equals("W9A-250"))
  49 + /*if(nbbm.equals("W9H-003"))
50 50 new RecoveryDataThread(listMap.get(nbbm), count).run();*/
51 51 }
52 52 try {
53 53 //等待子线程结束
54 54 count.await();
55 55 logger.info("GPS 数据恢复完成....");
  56 + run = false;
56 57 } catch (InterruptedException e) {
57 58 logger.error("", e);
58 59 }
... ... @@ -67,7 +68,7 @@ public class GpsDataRecovery {
67 68 Calendar calendar = Calendar.getInstance();
68 69 int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
69 70  
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 + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear;
71 72 JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
72 73  
73 74 List<GpsEntity> list =
... ... @@ -120,10 +121,13 @@ public class GpsDataRecovery {
120 121 //依次跑完gps
121 122 //int i = 0;
122 123 for(GpsEntity gps : list){
123   - /* i++;
124   - if(i == 383){
  124 + /* i++;
  125 + if(i == 4527){
125 126 System.out.println("aaa");
126   - }*/
  127 + }
  128 +
  129 + if(gps.getTimestamp() == 1482726071000L)
  130 + System.out.println("bbb");*/
127 131 GpsArrival.arrival(gps);
128 132 }
129 133 } catch (Exception e) {
... ...
src/main/java/com/bsth/data/pilot80/PilotReport.java
1 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 3 import com.bsth.data.BasicData;
13 4 import com.bsth.data.LineConfigData;
14 5 import com.bsth.data.gpsdata.GpsEntity;
... ... @@ -23,6 +14,14 @@ import com.bsth.repository.directive.D80Repository;
23 14 import com.bsth.service.directive.DirectiveService;
24 15 import com.bsth.websocket.handler.SendUtils;
25 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 179 return;
181 180  
182 181 LineConfig conf = lineConfigData.get(sch.getXlBm());
183   - if(conf.getInConfig() == 1){
  182 + if(conf.getOutConfig() == 1){
184 183 //为相关班次写入进场时间
185 184 sch.setZdsjActualAll(d80.getTimestamp());
186 185  
... ...
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
... ... @@ -37,547 +37,535 @@ import java.util.*;
37 37 import java.util.concurrent.TimeUnit;
38 38  
39 39 /**
40   - *
  40 + * @author PanZhao
41 41 * @ClassName: DayOfSchedule
42 42 * @Description: TODO(当日实际排班)
43   - * @author PanZhao
44 43 * @date 2016年8月15日 上午10:16:12
45   - *
46 44 */
47 45 @Component
48 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 554 // public void calcQdzTimePlan(String nbbm){
567 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 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 570 Collections.sort(list, schFCSJComparator);
583 571  
... ... @@ -592,190 +580,193 @@ public class DayOfSchedule implements CommandLineRunner {
592 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 770 /* public void linkToSchPlan(String nbbm) {
780 771 //当前GPS状态
781 772 GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
... ...
src/main/java/com/bsth/entity/realcontrol/LineConfig.java
1 1 package com.bsth.entity.realcontrol;
2 2  
  3 +import com.bsth.entity.Line;
  4 +
  5 +import javax.persistence.*;
3 6 import java.text.ParseException;
4 7 import java.text.SimpleDateFormat;
5 8 import java.util.Date;
6 9 import java.util.HashSet;
7 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 14 * @ClassName: LineConfig
... ... @@ -59,9 +47,6 @@ public class LineConfig {
59 47 /** 出场时间设置 0:真实出场(设备离开缓冲区时间) 1:请求出场时间 2:出站即出场 */
60 48 private int outConfig;
61 49  
62   - /** 进场时间设置 0:真实进场(设备进入缓冲区时间) 1:请求进场时间 2:出站即出场*/
63   - private int inConfig;
64   -
65 50 /** 短语模板 , 号分隔多个 */
66 51 private String phraseTemps;
67 52  
... ... @@ -111,14 +96,6 @@ public class LineConfig {
111 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 99 public String getPhraseTemps() {
123 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 27  
28 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 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 70 LineConfig conf = lineConfigData.get(lineCode);
71 71  
72 72 conf.setOutConfig(type);
73   - conf.setInConfig(type);
  73 + //conf.setInConfig(type);
74 74 lineConfigData.set(conf);
75 75  
76 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 382 return list;
383 383 }
384 384  
385   - @Override
  385 +/* @Override
386 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 388 ScheduleRealInfo schedule = dayOfSchedule.get(id);
... ... @@ -435,7 +435,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
435 435 map.put("status", 200);
436 436 map.put("t", schedule);
437 437 return map;
438   - }
  438 + }*/
439 439  
440 440 @Override
441 441 public void adjustCar(ScheduleRealInfo schedule, String car) {
... ... @@ -680,7 +680,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
680 680 sch.addRemarks(remarks);
681 681 sch.calcStatus();
682 682  
683   - scheduleRealInfoRepository.save(sch);
  683 + dayOfSchedule.save(sch);
  684 + //scheduleRealInfoRepository.save(sch);
684 685  
685 686 ts.add(sch);
686 687  
... ... @@ -883,10 +884,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
883 884 next.setQdzArrDateSJ(zdsjActual);
884 885 ts.add(next);
885 886 }
  887 +
  888 + //重新计算车辆执行班次
  889 + dayOfSchedule.reCalcExecPlan(sch.getClZbh());
886 890 }
887 891 }
888 892 else {
889   - if(sch.getZdsjActual() != null){
  893 + /*if(sch.getZdsjActual() != null){
890 894 //将对应的到离站数据标记为不可信
891 895 List<ArrivalEntity> list = ArrivalData_GPS.findByNbbm(sch.getClZbh());
892 896 for(ArrivalEntity arr : list){
... ... @@ -898,7 +902,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
898 902 break;
899 903 }
900 904 }
901   - }
  905 + }*/
902 906  
903 907 //清除实达时间
904 908 sch.clearZdsjActual();
... ...
src/main/resources/static/pages/control/lineConfig/config.html
... ... @@ -108,7 +108,7 @@ butto.line-config-btn{
108 108 font-size: 85%;
109 109 }
110 110  
111   -butto.line-config-btn:HOVER{
  111 +button.line-config-btn:HOVER{
112 112 background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
113 113 border-color: rgba(0, 0, 0, 0.3);
114 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 116 }
117 117  
118 118  
119   -butto.line-config-btn:active{
  119 +button.line-config-btn:active{
120 120 background-image: -webkit-linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
121 121 border-color: #5b5bec;
122 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 212 </section>
213 213  
214 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 221 <div class="settings-row" >
218 222 <p > 使用 <a href="javascript:;" data-type="select" id="outTimeType"></a> 时间作为出场班次的实际时间。</p>
... ... @@ -273,18 +277,19 @@ butto.line-config-btn:active{
273 277 }
274 278  
275 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 295 function showLoad(text){
... ...
src/main/resources/static/pages/mapmonitor/real/js/playBack.js
... ... @@ -269,7 +269,7 @@ var playBack = (function() {
269 269  
270 270 if(defaultLine){
271 271 layer.msg('加载线路图层数据...', {icon: 16, time: 0,shade:0.3});
272   - $.get('/realSchedule/findRouteByLine', {lineCode: defaultLine}
  272 + $.get('/realMap/findRouteByLine', {lineCode: defaultLine}
273 273 ,function(route){
274 274 lineRoute = route;
275 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 257 }
258 258  
259 259 .tl-wd{
260   - background: #caca4f;
  260 + background: #dede57;
261 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 188  
189 189 //更新班次
190 190 var updateSchedule = function (schArr) {
  191 +
191 192 if (!isArray(schArr))
192 193 schArr = [schArr];
193 194  
... ... @@ -199,12 +200,12 @@ var gb_schedule_table = (function () {
199 200 tMaps[this.xlBm+'_'+this.clZbh]=1;
200 201 });
201 202  
202   - //重新标记末班
  203 + /* //重新标记末班
203 204 var ts=[];
204 205 for(var k in tMaps){
205 206 ts = k.split('_');
206 207 markerLastByNbbm(ts[0], ts[1]);
207   - }
  208 + }*/
208 209 };
209 210  
210 211 //update dom
... ... @@ -216,11 +217,11 @@ var gb_schedule_table = (function () {
216 217  
217 218 //车辆自编号
218 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 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 296 return isDown ? y + 7 : y - 32;
297 297 });
298 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 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 75 $('[name=sDate]', this).val(m.subtract(2, 'hour').format(rq));
76 76 $('[name=sTime]', this).val(m.format(sj));
77 77  
78   - //test
  78 +/* //test
79 79 $('[name=nbbm]', this).val('W9H-003');
80 80 $('[name=eDate]', this).val('2016-12-10');
81 81 $('[name=eTime]', this).val('09:00');
82 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 86 var ONE_DAY = 1000 * 60 * 60 * 24;
... ...