Commit ce7e5e3ce58380f5b5367c104d96f16db052140e

Authored by 潘钊
1 parent 8c5746ae

闵行7月30号,懒得写

Showing 56 changed files with 1323 additions and 480 deletions
src/main/java/com/bsth/StartCommand.java
... ... @@ -7,11 +7,13 @@ import com.bsth.service.realcontrol.buffer.GetSchedulePlanThread;
7 7 import com.bsth.service.realcontrol.buffer.SchedulePersistenceThread;
8 8 import com.bsth.util.DateUtils;
9 9 import com.bsth.vehicle.common.CommonRefreshThread;
  10 +import com.bsth.vehicle.directive.buffer.DirectiveBuffer;
10 11 import com.bsth.vehicle.directive.service.DirectiveService;
11 12 import com.bsth.vehicle.directive.thread.DirectivePersistenceThread;
12 13 import com.bsth.vehicle.directive.thread.FirstScheduleIssuedThread;
13   -import com.bsth.vehicle.gpsdata.GpsArrivalThread;
14   -import com.bsth.vehicle.gpsdata.GpsRefreshThread;
  14 +import com.bsth.vehicle.gpsdata.ArrivalThread;
  15 +import com.bsth.vehicle.gpsdata.GpsOfflineMonitorThread;
  16 +import com.bsth.vehicle.gpsdata.GpsRealDataRefreshThread;
15 17  
16 18 import org.slf4j.Logger;
17 19 import org.slf4j.LoggerFactory;
... ... @@ -36,10 +38,10 @@ public class StartCommand implements CommandLineRunner{
36 38 @Autowired
37 39 SecurityMetadataSourceService invocationSecurityMetadataSourceService;
38 40  
39   - public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(7);
  41 + public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(8);
40 42  
41 43 @Autowired
42   - GpsRefreshThread gpsRefreshThread;
  44 + GpsRealDataRefreshThread gpsRefreshThread;
43 45 @Autowired
44 46 GetSchedulePlanThread getSchedulePlanThread;
45 47 @Autowired
... ... @@ -49,16 +51,23 @@ public class StartCommand implements CommandLineRunner{
49 51 @Autowired
50 52 SchedulePersistenceThread SchedulePersistenceThread;
51 53 @Autowired
52   - GpsArrivalThread gpsArrivalStationThread;
  54 + ArrivalThread gpsArrivalStationThread;
53 55 @Autowired
54 56 FirstScheduleIssuedThread firstScheduleIssuedThread;
55 57  
56 58 @Autowired
57 59 DirectiveService directiveService;
58 60 @Autowired
  61 + DirectiveBuffer directiveBuffer;
  62 + @Autowired
59 63 CarConfigInfoRepository carConfigInfoRepository;
60 64  
61   - static Long hourTime = 1000 * 60 * 60L;
  65 + @Autowired
  66 + GpsOfflineMonitorThread gpsOfflineMonitorThread;
  67 +
  68 + final static Long HOUR_TIME = 1000 * 60 * 60L;
  69 +
  70 + final static int HOUR_SECOND = 60 * 60;
62 71  
63 72 @Override
64 73 public void run(String... arg0){
... ... @@ -68,32 +77,44 @@ public class StartCommand implements CommandLineRunner{
68 77 invocationSecurityMetadataSourceService.loadResourceDefine();
69 78  
70 79 /**
  80 + * 车辆,设备,公司等常用的映射数据,每两小时刷新一次
  81 + */
  82 + commonRefreshThread.start();
  83 + scheduler.scheduleWithFixedDelay(commonRefreshThread, HOUR_SECOND * 2 , HOUR_SECOND * 2, TimeUnit.SECONDS);
  84 + //等映射数据加载完......睡一会吧
  85 + Thread.sleep(3000);
  86 +
  87 + /**
71 88 * GPS实时数据更新 线程
72 89 * 每8秒和网关HTTP接口同步一次
73 90 */
74 91 scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 8, TimeUnit.SECONDS);
75 92  
76 93 /**
  94 + * GPS 监控设备掉线行为
  95 + * 每分钟检测一次
  96 + */
  97 + scheduler.scheduleWithFixedDelay(gpsOfflineMonitorThread, 60, 60, TimeUnit.SECONDS);
  98 +
  99 +
  100 + /**
77 101 * 每天 凌晨 2 点 抓取当天实际排班
78 102 */
79 103 //启动时先run一次
80 104 getSchedulePlanThread.start();
81 105 scheduler.scheduleAtFixedRate(getSchedulePlanThread
82   - , ((DateUtils.getTimesnight2() + hourTime * 2) - System.currentTimeMillis()) / 1000
  106 + , ((DateUtils.getTimesnight2() + HOUR_TIME * 2) - System.currentTimeMillis()) / 1000
83 107 , 60 * 60 * 24, TimeUnit.SECONDS);
84 108  
85 109 /**
86 110 * 调度指令两分钟入库一次
87 111 * 指令会缓存在内存,直到收到所有响应再入库
88 112 */
  113 + //从数据库恢复初始数据
  114 + directiveBuffer.recovery();
89 115 scheduler.scheduleWithFixedDelay(directivePersistenceThread, 20, 60 * 2, TimeUnit.SECONDS);
90 116  
91 117 /**
92   - * 车辆,设备,公司等常用的映射数据,每两小时刷新一次
93   - */
94   - scheduler.scheduleWithFixedDelay(commonRefreshThread, 0, 60 * 60 * 2, TimeUnit.SECONDS);
95   -
96   - /**
97 118 * 每分钟将有变更的班次入库(不包括子任务)
98 119 * 单纯为了提高 线调操作 的响应速度
99 120 */
... ... @@ -103,7 +124,7 @@ public class StartCommand implements CommandLineRunner{
103 124 * 每15秒从数据库抓取到离站信息和班次匹配
104 125 * (网关生成的到离站数据也是延迟批量入库,所以缩短该线程执行周期并不会提高 “实际到离站” 的实时性)
105 126 */
106   - scheduler.scheduleWithFixedDelay(gpsArrivalStationThread, 15, 20, TimeUnit.SECONDS);
  127 + scheduler.scheduleWithFixedDelay(gpsArrivalStationThread, 35, 15, TimeUnit.SECONDS);
107 128  
108 129 /**
109 130 * 首个调度指令下发(2分钟运行一次)
... ... @@ -112,68 +133,11 @@ public class StartCommand implements CommandLineRunner{
112 133 */
113 134 scheduler.scheduleWithFixedDelay(firstScheduleIssuedThread, 60 , 60 * 2, TimeUnit.SECONDS);
114 135  
115   - /**
116   - * ######### 测试 ###############
117   - */
  136 + //延迟一会
118 137 /* new Timer().schedule(new TimerTask() {
119 138  
120 139 @Override
121 140 public void run() {
122   - //根据班次模拟一份到离站数据
123   - Set<String> set = ScheduleBuffer.vehSchListMap.keySet();
124   - ArrivalInfo outArr, inArr;
125   - List<ArrivalInfo> arrList = new ArrayList<>();
126   - Date d = new Date();
127   - for(String nbbm : set){
128   -
129   - for(ScheduleRealInfo sch : ScheduleBuffer.vehSchListMap.get(nbbm)){
130   - //发出
131   - outArr = new ArrivalInfo(CommonMapped.vehicDeviceBiMap.inverse().get(nbbm)
132   - , sch.getFcsjT(), sch.getXlBm(), Integer.parseInt(sch.getXlDir()), sch.getQdzCode(), 1, d , 31);
133   -
134   - //到达
135   - inArr = new ArrivalInfo(CommonMapped.vehicDeviceBiMap.inverse().get(nbbm)
136   - , sch.getZdsjT(), sch.getXlBm(), Integer.parseInt(sch.getXlDir()), sch.getZdzCode(), 0, d , 31);
137   -
138   - arrList.add(outArr);
139   - arrList.add(inArr);
140   - }
141   - }
142   - try {
143   - Connection conn = DBUtils_MS.getConnection();
144   - String sql = "insert into bsth_c_arrival_info(device_id, line_id, stop_no, ts, up_down, in_out, weeks_year, create_date)"
145   - + " values(?, ?, ?, ? , ?, ?,?, now())";
146   -
147   - conn.setAutoCommit(false);
148   - java.sql.PreparedStatement ps = conn.prepareStatement(sql);
149   -
150   - for(ArrivalInfo arr : arrList){
151   - ps.setString(1, arr.getDeviceId());
152   - ps.setString(2, arr.getLineCode());
153   - ps.setString(3, arr.getStopNo());
154   - ps.setLong(4, arr.getTs() == null? 0: arr.getTs());
155   - ps.setInt(5, arr.getUpDown());
156   - ps.setInt(6, arr.getInOut());
157   - ps.setInt(7, arr.getWeeksYear());
158   -
159   - ps.addBatch();
160   - }
161   -
162   - ps.executeBatch();
163   - conn.commit();
164   - } catch (SQLException e) {
165   - e.printStackTrace();
166   - }
167   -
168   - //new BatchSaveUtils<ArrivalInfo>().saveList(arrList, ArrivalInfo.class);
169   - }
170   - }, 5000);*/
171   -
172   -/* //延迟一会
173   - new Timer().schedule(new TimerTask() {
174   -
175   - @Override
176   - public void run() {
177 141 //临时全量刷车辆线路
178 142 List<CarConfigInfo> ccis = carConfigInfoRepository.findAll();
179 143 Cars car;
... ... @@ -189,6 +153,7 @@ public class StartCommand implements CommandLineRunner{
189 153 //directiveService.send60Phrase(car.getInsideCode(), "");
190 154 System.out.println("返回值:" + code);
191 155 }
  156 +
192 157 }
193 158 }, 1000 * 10);*/
194 159  
... ...
src/main/java/com/bsth/entity/StationRoute.java
... ... @@ -9,6 +9,9 @@ import javax.persistence.GeneratedValue;
9 9 import javax.persistence.GenerationType;
10 10 import javax.persistence.Id;
11 11 import javax.persistence.ManyToOne;
  12 +import javax.persistence.NamedAttributeNode;
  13 +import javax.persistence.NamedEntityGraph;
  14 +import javax.persistence.NamedEntityGraphs;
12 15 import javax.persistence.Table;
13 16  
14 17 import com.fasterxml.jackson.annotation.JsonIgnore;
... ... @@ -29,6 +32,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
29 32  
30 33 @Entity
31 34 @Table(name = "bsth_c_stationroute")
  35 +@NamedEntityGraphs({
  36 + @NamedEntityGraph(name = "stationRoute_station", attributeNodes = {
  37 + @NamedAttributeNode("station")
  38 + })
  39 +})
32 40 public class StationRoute {
33 41  
34 42 //站点路由ID
... ...
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
... ... @@ -173,6 +173,9 @@ public class ScheduleRealInfo {
173 173 /** 指令下发状态 60: 已发送, 100: 设备确认收到, 200:驾驶员确认 0:失败 */
174 174 private Integer directiveState = -1;
175 175  
  176 + /** “运营状态” 指令下发状态 60: 已发送, 100: 设备确认收到 0:失败*/
  177 + private Integer opDirectiveState;
  178 +
176 179 /** 起点站计划到达时间 */
177 180 private String qdzArrDatejh;
178 181  
... ... @@ -874,4 +877,12 @@ public class ScheduleRealInfo {
874 877  
875 878 }
876 879 }
  880 +
  881 + public Integer getOpDirectiveState() {
  882 + return opDirectiveState;
  883 + }
  884 +
  885 + public void setOpDirectiveState(Integer opDirectiveState) {
  886 + this.opDirectiveState = opDirectiveState;
  887 + }
877 888 }
... ...
src/main/java/com/bsth/repository/StationRouteRepository.java
... ... @@ -2,6 +2,7 @@ package com.bsth.repository;
2 2  
3 3 import java.util.List;
4 4  
  5 +import org.springframework.data.jpa.repository.EntityGraph;
5 6 import org.springframework.data.jpa.repository.Modifying;
6 7 import org.springframework.data.jpa.repository.Query;
7 8 import org.springframework.stereotype.Repository;
... ... @@ -220,4 +221,8 @@ public interface StationRouteRepository extends BaseRepository&lt;StationRoute, Int
220 221 List<Object[]> findStationRouteInfo(Integer id);
221 222  
222 223 List<StationRoute> findByLine(Line line);
  224 +
  225 + @EntityGraph(value = "stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
  226 + @Query("select s from StationRoute s where s.destroy=0")
  227 + List<StationRoute> findAll2();
223 228 }
... ...
src/main/java/com/bsth/service/realcontrol/buffer/GetSchedulePlanThread.java
... ... @@ -3,12 +3,15 @@ package com.bsth.service.realcontrol.buffer;
3 3 import java.text.ParseException;
4 4 import java.text.SimpleDateFormat;
5 5 import java.util.Date;
  6 +import java.util.HashMap;
6 7 import java.util.List;
  8 +import java.util.Map;
7 9  
8 10 import org.slf4j.Logger;
9 11 import org.slf4j.LoggerFactory;
10 12 import org.springframework.beans.factory.annotation.Autowired;
11 13 import org.springframework.stereotype.Component;
  14 +import org.springframework.web.socket.TextMessage;
12 15  
13 16 import com.alibaba.fastjson.JSON;
14 17 import com.alibaba.fastjson.JSONArray;
... ... @@ -18,6 +21,8 @@ import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
18 21 import com.bsth.repository.schedule.SchedulePlanInfoRepository;
19 22 import com.bsth.util.BatchSaveUtils;
20 23 import com.bsth.vehicle.directive.buffer.DirectiveBuffer;
  24 +import com.bsth.vehicle.gpsdata.buffer.ArrivalDataBuffer;
  25 +import com.bsth.websocket.handler.RealControlSocketHandler;
21 26  
22 27 /**
23 28 *
... ... @@ -43,18 +48,28 @@ public class GetSchedulePlanThread extends Thread{
43 48 @Autowired
44 49 DirectiveBuffer directiveBuffer;
45 50  
  51 + @Autowired
  52 + RealControlSocketHandler realControlSocket;
  53 +
46 54 @Override
47 55 public void run() {
48 56 try{
49 57 logger.info("从计划调度抓取排班数据...");
50 58 //清除缓存
51 59 ScheduleBuffer.clear();
  60 + ArrivalDataBuffer.clear();
52 61 //所有指令入库
53 62 directiveBuffer.saveAll();
54 63 DirectiveBuffer.clear();
55 64  
56 65 //加载新的排班
57 66 loaSchedule();
  67 +
  68 + //通知所有线调页面刷新
  69 + Map<String, Object> data = new HashMap<>();
  70 + data.put("fn", "refresh");
  71 + data.put("dateStr", sdfyyyyMMdd.format(new Date()));
  72 + realControlSocket.sendMessageToUsers(new TextMessage(JSON.toJSONString(data)));
58 73 }catch(Exception e){
59 74 logger.error("",e);
60 75 }
... ... @@ -62,7 +77,7 @@ public class GetSchedulePlanThread extends Thread{
62 77  
63 78 public void loaSchedule() throws ParseException{
64 79 List<ScheduleRealInfo> realList = null;
65   - String dateStr = sdfyyyyMMdd.format(new Date());
  80 + String dateStr = sdfyyyyMMdd.format(new Date())/*"2016-07-28"*/;
66 81 //Date cDate = sdfyyyyMMdd.parse(dateStr);
67 82 //查询数据库是否有今日排班
68 83 int size = scheduleRealInfoRepository.countByDate(dateStr);
... ...
src/main/java/com/bsth/service/realcontrol/buffer/ScheduleBuffer.java
... ... @@ -182,11 +182,11 @@ public class ScheduleBuffer {
182 182 continue;
183 183  
184 184 if(sch.getFcsjT().equals(sch2.getFcsjT())//出场,发车时间一致
185   - || sch.getFcsjT().equals(sch2.getZdsjT())//进场,上一班次站点时间为进场起点时间
  185 + //|| sch.getFcsjT().equals(sch2.getZdsjT())//进场,上一班次终点时间为进场起点时间
186 186 ){
187 187 sch.setParkIsFirstStation(true);
188 188 sch2.setFirstStationIsPark(true);
189   - //做双关联
  189 + //做双关联
190 190 sch2.setTwins(sch);
191 191 sch.setTwins(sch2);
192 192 break;
... ... @@ -354,15 +354,26 @@ public class ScheduleBuffer {
354 354 public static ScheduleRealInfo findCurrent(String nbbm){
355 355 List<ScheduleRealInfo> list = ScheduleBuffer.carSchListMap.get(nbbm);
356 356  
  357 + //long t = System.currentTimeMillis();
357 358 int size = list.size();
358   - ScheduleRealInfo sch;
  359 + ScheduleRealInfo sch = null, currentSch = null, lastOver = null;
359 360 //最后一个状态为 正在执行的班次
360 361 for(int i = size - 1; i > 0; i --){
361 362 sch = list.get(i);
362   - if(sch.getStatus() == 1)
363   - return sch;
  363 + if(sch.getStatus() == 1){
  364 + currentSch = sch;
  365 + break;
  366 + }
  367 +
  368 + //最后一个已完成的班次
  369 + if(null == lastOver && sch.getStatus() == 2)
  370 + lastOver = sch;
  371 + /*if(null != nearestSch
  372 + && Math.abs(sch.getZdsjT() - t) < Math.abs(nearestSch.getZdsjT() - t) ){
  373 + nearestSch = sch;
  374 + }*/
364 375 }
365   - return null;
  376 + return currentSch == null?lastOver:currentSch;
366 377 }
367 378  
368 379 /**
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -336,6 +336,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
336 336 public Map<String, Object> adjust(Long id, String nbbm, String jsy, String spy, Integer revertLine, Integer borrowLine, String borrowTimeStr, String revertTimeStr) {
337 337 // 班次
338 338 ScheduleRealInfo schedule = ScheduleBuffer.pkSchedulMap.get(id);
  339 + int upDown = Integer.parseInt(schedule.getXlDir());
339 340  
340 341 String rq = sdfMonth.format(new Date());
341 342 // 换车
... ... @@ -360,7 +361,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
360 361 try {
361 362 //跨线路借车
362 363 Long t = sdfMinute.parse(rq + " " + borrowTimeStr).getTime();
363   - borrowCenter.put(nbbm, borrowLine, 0, t);
  364 + borrowCenter.put(nbbm, borrowLine, 0, t, upDown);
364 365 } catch (ParseException e) {
365 366 e.printStackTrace();
366 367 }
... ... @@ -370,7 +371,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
370 371 //定时还车
371 372 try {
372 373 Long t = sdfMinute.parse(rq + " " + revertTimeStr).getTime();
373   - borrowCenter.put(nbbm, revertLine, 1, t);
  374 + //还车的时候不用切走向
  375 + borrowCenter.put(nbbm, revertLine, 1, t, -1);
374 376 } catch (ParseException e) {
375 377 e.printStackTrace();
376 378 }
... ...
src/main/java/com/bsth/vehicle/BorrowCenter.java
... ... @@ -45,15 +45,15 @@ public class BorrowCenter {
45 45 * @param @param time 时间
46 46 * @throws
47 47 */
48   - public void put(String nbbm, Integer lineCode, int type, Long time){
  48 + public void put(String nbbm, Integer lineCode, int type, Long time, int upDown){
49 49 Long t = System.currentTimeMillis();
50 50 if(t >= time){
51 51 //立即执行
52   - new Thread(new ChangeThread(nbbm, lineCode, type)).start();
  52 + new Thread(new ChangeThread(nbbm, lineCode, type, upDown)).start();
53 53 }
54 54 else{
55 55 //定时线程
56   - scheduler.schedule(new ChangeThread(nbbm, lineCode, type), (time - t) / 1000, TimeUnit.SECONDS);
  56 + scheduler.schedule(new ChangeThread(nbbm, lineCode, type, upDown), (time - t) / 1000, TimeUnit.SECONDS);
57 57 }
58 58 }
59 59  
... ... @@ -61,17 +61,23 @@ public class BorrowCenter {
61 61 String nbbm;
62 62 Integer lineCode;
63 63 int type;
  64 + int upDown;
64 65  
65   - public ChangeThread(String nbbm, Integer lineCode, int type) {
  66 + public ChangeThread(String nbbm, Integer lineCode, int type, int upDown) {
66 67 this.nbbm = nbbm;
67 68 this.lineCode = lineCode;
68 69 this.type = type;
  70 + this.upDown = upDown;
69 71 }
70 72  
71 73 @Override
72 74 public void run() {
73 75 logger.info("nbbm " + (type==0?"借出":"归还") + "线路代码 " + lineCode);
74 76 directiveService.lineChange(nbbm, lineCode);
  77 + if(upDown != -1){
  78 + //切换走向
  79 + directiveService.upDownChange(nbbm, upDown);
  80 + }
75 81 }
76 82 }
77 83 }
... ...
src/main/java/com/bsth/vehicle/UpstreamEntrance.java
... ... @@ -16,54 +16,56 @@ import com.bsth.vehicle.directive.entity.Directive80;
16 16  
17 17 /**
18 18 *
19   - * @ClassName: UpstreamEntrance
20   - * @Description: TODO(车载网关HTTP上行入口)
  19 + * @ClassName: UpstreamEntrance
  20 + * @Description: TODO(车载网关HTTP上行入口)
21 21 * @author PanZhao
22   - * @date 2016年6月7日 下午3:00:01
  22 + * @date 2016年6月7日 下午3:00:01
23 23 *
24 24 */
25 25 @RestController
26 26 @RequestMapping("/control")
27 27 public class UpstreamEntrance {
28   -
  28 +
29 29 Logger logger = LoggerFactory.getLogger(this.getClass());
30   -
  30 +
31 31 @Autowired
32 32 DirectiveBuffer directiveBuffer;
33   -
34   - @RequestMapping(value = "/upstream" , method = RequestMethod.POST)
35   - public int main(@RequestParam String json){
  33 +
  34 + @RequestMapping(value = "/upstream", method = RequestMethod.POST)
  35 + public int main(@RequestParam String json) {
36 36 logger.info("upstream: " + json);
37   - JSONObject jsonParam = JSONObject.parseObject(json);
38   -
39   - //46和47 调度指令确认
40   - if(jsonParam.getInteger("operCode") == null
41   - && jsonParam.getInteger("status") != null){
42   - try{
43   - DirectiveReply reply = JSON.toJavaObject(jsonParam, DirectiveReply.class);
44   - directiveBuffer.reply(reply);
45   - }catch(NumberFormatException e){
46   - logger.error("NumberFormatException ,,,,一般是老数据,msgId太大");
  37 + try {
  38 + JSONObject jsonParam = JSONObject.parseObject(json);
  39 +
  40 + // 46和47 调度指令确认
  41 + if (jsonParam.getInteger("operCode") == null && jsonParam.getInteger("status") != null) {
  42 + try {
  43 + DirectiveReply reply = JSON.toJavaObject(jsonParam, DirectiveReply.class);
  44 + directiveBuffer.reply(reply);
  45 + } catch (NumberFormatException e) {
  46 + logger.error("NumberFormatException ,,,,一般是老数据,msgId太大");
  47 + }
47 48 }
48   - }
49   - //80协议
50   - else if(jsonParam.getInteger("operCode") == 0X80){
51   - try{
52   - Directive80 report = JSON.toJavaObject(jsonParam, Directive80.class);
53   - //驾驶员上报
54   - if(report.getData().getOperCode2() == 0x26)
55   - directiveBuffer.jsyReport(report);
56   - }catch(Exception e){
57   - logger.error("", e);
  49 + // 80协议
  50 + else if (jsonParam.getInteger("operCode") == 0X80) {
  51 + try {
  52 + Directive80 report = JSON.toJavaObject(jsonParam, Directive80.class);
  53 + // 驾驶员上报
  54 + if (report.getData().getOperCode2() == 0x26)
  55 + directiveBuffer.jsyReport(report);
  56 + } catch (Exception e) {
  57 + logger.error("", e);
  58 + }
58 59 }
  60 + // 64协议 线路切换回复
  61 + else if (jsonParam.getInteger("operCode") == 0X64) {
  62 + directiveBuffer.reply64(jsonParam);
  63 + } else
  64 + logger.warn("未知的上行数据,p: " + json);
  65 +
  66 + } catch (Exception e) {
  67 + logger.error("", e);
59 68 }
60   - //64协议 线路切换回复
61   - else if(jsonParam.getInteger("operCode") == 0X64){
62   - directiveBuffer.reply64(jsonParam);
63   - }
64   - else
65   - logger.warn("未知的上行数据,p: " + json);
66   -
67 69 return 0;
68 70 }
69 71 }
... ...
src/main/java/com/bsth/vehicle/common/CommonMapped.java
1 1 package com.bsth.vehicle.common;
2 2  
  3 +import java.util.List;
3 4 import java.util.Map;
4 5  
5 6 import com.bsth.entity.Line;
  7 +import com.bsth.entity.StationRoute;
  8 +import com.google.common.collect.ArrayListMultimap;
6 9 import com.google.common.collect.BiMap;
7 10 import com.google.common.collect.TreeMultimap;
8 11  
... ... @@ -48,6 +51,12 @@ public class CommonMapped {
48 51 public static Map<String, String> stationCodeMap;
49 52  
50 53 /**
  54 + * 线路站点路由对照
  55 + * (K:线路编码, V:站点路由)
  56 + */
  57 + public static Map<Integer, List<StationRoute>> lineStationRouteMap;
  58 +
  59 + /**
51 60 * 线路和用户名对照
52 61 * 用于webSocket定向推送消息
53 62 */
... ...
src/main/java/com/bsth/vehicle/common/CommonRefreshThread.java
1 1 package com.bsth.vehicle.common;
2 2  
  3 +import java.util.ArrayList;
  4 +import java.util.Collections;
  5 +import java.util.Comparator;
3 6 import java.util.HashMap;
4 7 import java.util.Iterator;
  8 +import java.util.List;
5 9 import java.util.Map;
6 10  
7 11 import org.slf4j.Logger;
... ... @@ -13,10 +17,12 @@ import com.bsth.entity.CarPark;
13 17 import com.bsth.entity.Cars;
14 18 import com.bsth.entity.Line;
15 19 import com.bsth.entity.Station;
  20 +import com.bsth.entity.StationRoute;
16 21 import com.bsth.entity.schedule.CarConfigInfo;
17 22 import com.bsth.repository.CarParkRepository;
18 23 import com.bsth.repository.CarsRepository;
19 24 import com.bsth.repository.StationRepository;
  25 +import com.bsth.repository.StationRouteRepository;
20 26 import com.bsth.repository.schedule.CarConfigInfoRepository;
21 27 import com.google.common.collect.BiMap;
22 28 import com.google.common.collect.HashBiMap;
... ... @@ -44,6 +50,9 @@ public class CommonRefreshThread extends Thread{
44 50 @Autowired
45 51 CarConfigInfoRepository carConfigInfoRepository;
46 52  
  53 + @Autowired
  54 + StationRouteRepository sRouteRepository;
  55 +
47 56 Logger logger = LoggerFactory.getLogger(this.getClass());
48 57  
49 58 @Override
... ... @@ -52,6 +61,8 @@ public class CommonRefreshThread extends Thread{
52 61 initVehicMapp();
53 62 initStationCodeMap();
54 63 initVehicLineMap();
  64 +
  65 + initLineStationRouteMap();
55 66 } catch (Exception e) {
56 67 e.printStackTrace();
57 68 logger.error("", e);
... ... @@ -60,6 +71,36 @@ public class CommonRefreshThread extends Thread{
60 71  
61 72 /**
62 73 *
  74 + * @Title: initLineStationRouteMap
  75 + * @Description: TODO(加载线路站点路由信息)
  76 + * @throws
  77 + */
  78 + private void initLineStationRouteMap() {
  79 + List<StationRoute> routes = sRouteRepository.findAll2();
  80 +
  81 + Map<Integer, List<StationRoute>> map = new HashMap<>();
  82 +
  83 + Integer lineCode;
  84 + for(StationRoute route: routes){
  85 + lineCode = Integer.parseInt(route.getLineCode());
  86 + if(!map.containsKey(lineCode))
  87 + map.put(lineCode, new ArrayList<StationRoute>());
  88 +
  89 + map.get(lineCode).add(route);
  90 + }
  91 +
  92 + //排序
  93 + StationRouteComp sRouteComp = new StationRouteComp();
  94 + Iterator<List<StationRoute>> iterator = map.values().iterator();
  95 + List<StationRoute> temp;
  96 + while(iterator.hasNext()){
  97 + temp = iterator.next();
  98 + Collections.sort(temp, sRouteComp);
  99 + }
  100 + }
  101 +
  102 + /**
  103 + *
63 104 * @Title: initVehicLineMap
64 105 * @Description: TODO(根据车辆配置,加载车辆和线路对照数据)
65 106 * @throws
... ... @@ -121,4 +162,12 @@ public class CommonRefreshThread extends Thread{
121 162  
122 163 CommonMapped.stationCodeMap = newMap;
123 164 }
  165 +
  166 + public static class StationRouteComp implements Comparator<StationRoute>{
  167 +
  168 + @Override
  169 + public int compare(StationRoute o1, StationRoute o2) {
  170 + return o1.getStationRouteCode() - o2.getStationRouteCode();
  171 + }
  172 + }
124 173 }
... ...
src/main/java/com/bsth/vehicle/directive/MsgIdGenerator.java
... ... @@ -12,11 +12,16 @@ public class MsgIdGenerator {
12 12  
13 13 private static int msgId = 1;
14 14  
  15 + private final static int MAX_VALUE = Integer.MAX_VALUE - 10;
  16 +
15 17 public synchronized static int getMsgId(){
16 18 msgId ++;
17   - if(msgId == Integer.MAX_VALUE){
  19 + if(msgId == MAX_VALUE)
18 20 msgId = 0;
19   - }
20 21 return msgId;
21 22 }
  23 +
  24 + public static void setMsgId(int maxId){
  25 + msgId = maxId;
  26 + }
22 27 }
... ...
src/main/java/com/bsth/vehicle/directive/buffer/DirectiveBuffer.java
1 1 package com.bsth.vehicle.directive.buffer;
2 2  
3 3 import java.util.ArrayList;
  4 +import java.util.Calendar;
  5 +import java.util.Collection;
  6 +import java.util.Comparator;
4 7 import java.util.HashMap;
5   -import java.util.Iterator;
6 8 import java.util.LinkedList;
7 9 import java.util.List;
8 10 import java.util.Map;
... ... @@ -12,25 +14,23 @@ import org.slf4j.LoggerFactory;
12 14 import org.springframework.beans.factory.annotation.Autowired;
13 15 import org.springframework.stereotype.Component;
14 16  
15   -import com.alibaba.fastjson.JSON;
16 17 import com.alibaba.fastjson.JSONObject;
17 18 import com.bsth.entity.realcontrol.ScheduleRealInfo;
18 19 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
19 20 import com.bsth.vehicle.common.CommonMapped;
  21 +import com.bsth.vehicle.directive.MsgIdGenerator;
20 22 import com.bsth.vehicle.directive.entity.Directive60;
21 23 import com.bsth.vehicle.directive.entity.DirectiveReply;
22 24 import com.bsth.vehicle.directive.entity.Directive80;
23 25 import com.bsth.vehicle.directive.entity.DirectiveC0;
24 26 import com.bsth.vehicle.directive.entity.DirectiveC0.DirectiveC0Data;
25   -import com.bsth.vehicle.directive.entity.LineChange;
  27 +import com.bsth.vehicle.directive.entity.Directive64;
26 28 import com.bsth.vehicle.directive.repository.Directive60Repository;
27 29 import com.bsth.vehicle.directive.repository.Directive80Repository;
28 30 import com.bsth.vehicle.directive.repository.LineChangeRepository;
29 31 import com.bsth.vehicle.directive.service.DirectiveService;
30   -import com.bsth.vehicle.directive.util.HttpUtils;
31 32 import com.bsth.websocket.handler.RealControlSocketHandler;
32 33 import com.google.common.collect.ArrayListMultimap;
33   -import com.google.common.collect.Multimap;
34 34  
35 35 /**
36 36 *
... ... @@ -49,10 +49,10 @@ public class DirectiveBuffer {
49 49 Directive80Repository d80Repository;
50 50  
51 51 @Autowired
52   - LineChangeRepository lineChangeRepository;
  52 + LineChangeRepository d64Repository;
53 53  
54 54 @Autowired
55   - DirectiveService directiveService;
  55 + DirectiveService directiveService60;
56 56  
57 57  
58 58 /**
... ... @@ -61,12 +61,12 @@ public class DirectiveBuffer {
61 61 public static LinkedList<Directive60> transientList;
62 62  
63 63 /**
64   - * 等待确认的线路切换指令
  64 + * 线路切换指令 64
65 65 */
66   - public static Map<String, LineChange> changeMap;
  66 + public static Map<String, Directive64> changeMap;
67 67  
68 68 /**
69   - * 当日调度指令缓存
  69 + * 当日60指令缓存
70 70 */
71 71 private static Map<Integer, Directive60> directiveMap;
72 72  
... ... @@ -77,7 +77,7 @@ public class DirectiveBuffer {
77 77 * 驾驶员上报数据
78 78 * {K: 线路编码}
79 79 */
80   - private static Multimap<Integer, Directive80> reportMultiMap;
  80 + private static ArrayListMultimap<Integer, Directive80> reportMultiMap;
81 81  
82 82 @Autowired
83 83 RealControlSocketHandler socketHandler;
... ... @@ -126,13 +126,23 @@ public class DirectiveBuffer {
126 126 break;
127 127 }
128 128  
  129 + ScheduleRealInfo sch = directive.getSch();
  130 +
  131 + if(null == sch)
  132 + return;
  133 +
  134 + //调度指令回复
129 135 if(directive.isDispatch()){
130 136 //更新班次状态
131   - ScheduleRealInfo sch = directive.getSch();
132 137 sch.setDirectiveState(reply.getStatus() * 100);
133 138 ScheduleBuffer.persistentList.add(sch);
134 139 //通知页面
135   - directiveService.sendDirectiveToPage(sch);
  140 + directiveService60.sendDirectiveToPage(sch);
  141 + }
  142 + //运营状态指令回复
  143 + else if(directive.getData().getDispatchInstruct() == 0x03){
  144 + sch.setOpDirectiveState(reply.getStatus() * 100);
  145 + ScheduleBuffer.persistentList.add(sch);
136 146 }
137 147 transientList.add(directive);
138 148 }
... ... @@ -146,21 +156,21 @@ public class DirectiveBuffer {
146 156 public void reply64(JSONObject json){
147 157 String key = json.getString("deviceId") + "_" + json.getString("timestamp");
148 158  
149   - LineChange change = changeMap.get(key);
  159 + Directive64 change = changeMap.get(key);
150 160  
151 161 if(null == change)
152 162 logger.warn("64响应 -找不到请求源,json: " + json);
  163 + else if(change.getRespAck() != null)
  164 + logger.warn("64响应 -重复响应,json: " + json);
153 165 else{
154 166 JSONObject data = json.getJSONObject("data");
155 167  
156   - changeMap.remove(key);
157   -
158 168 if(null == data)
159 169 logger.warn("64响应 data is null ,json: " + json);
160 170 else{
161 171 change.setRespAck(data.getShort("requestAck"));
162 172 //响应入库
163   - lineChangeRepository.save(change);
  173 + d64Repository.save(change);
164 174 }
165 175 }
166 176 }
... ... @@ -174,11 +184,11 @@ public class DirectiveBuffer {
174 184 public void jsyReport(Directive80 report){
175 185 //将托管的线路自动处理掉
176 186 Integer lineCode = report.getData().getLineId();
177   - Integer status = ScheduleBuffer.trustMap.get(lineCode);
  187 + //Integer status = ScheduleBuffer.trustMap.get(lineCode);
178 188 //请求代码
179   - Short requestCode = report.getData().getRequestCode();
  189 + //Short requestCode = report.getData().getRequestCode();
180 190 //托管
181   - if(null == status || status == 0){
  191 + /*if(null == status || status == 0){
182 192 //自动处理出场请求
183 193 if(requestCode == 0xA3){
184 194 DirectiveC0 c0 = createC0(report, (short)0x06);
... ... @@ -186,10 +196,11 @@ public class DirectiveBuffer {
186 196 report.setC0(c0);
187 197 d80Repository.save(report);
188 198 }
189   - }
  199 + }*/
190 200  
191 201 //实时入库
192   - d80Repository.save(report);
  202 + d80Repository.save(report);
  203 +
193 204 reportMultiMap.put(lineCode, report);
194 205 //推送到页面
195 206 report.getData().setNbbm(CommonMapped.vehicDeviceBiMap.get(report.getDeviceId()));
... ... @@ -225,15 +236,23 @@ public class DirectiveBuffer {
225 236 * @Description: TODO(所有缓存里的指令全部入库)
226 237 */
227 238 public void saveAll(){
228   - Iterator<Directive60> iterator = directiveMap.values().iterator();
  239 + //未回复的60指令入库
  240 + Collection<Directive60> ds = directiveMap.values();
229 241 List<Directive60> pList = new ArrayList<>();
230   - Directive60 d60;
231   - while(iterator.hasNext()){
232   - d60 = iterator.next();
233   - if(!d60.isPersistent())
234   - pList.add(d60);
  242 + for(Directive60 d : ds){
  243 + if(d.getReply47() == null)
  244 + pList.add(d);
  245 + }
  246 + d60Repository.save(directiveMap.values());
  247 +
  248 + //未回复的64指令入库
  249 + Collection<Directive64> ds64 = changeMap.values();
  250 + List<Directive64> pList2 = new ArrayList<>();
  251 + for(Directive64 d : ds64){
  252 + if(d.getRespAck() == null)
  253 + pList2.add(d);
235 254 }
236   - d60Repository.save(pList);
  255 + d64Repository.save(pList2);
237 256 }
238 257  
239 258 /**
... ... @@ -248,4 +267,106 @@ public class DirectiveBuffer {
248 267 reportMultiMap = ArrayListMultimap.create();
249 268 changeMap = new HashMap<>();
250 269 }
  270 +
  271 + /**
  272 + *
  273 + * @Title: recovery
  274 + * @Description: TODO(从数据库恢复当天的指令数据到内存.)
  275 + * @throws
  276 + */
  277 + public void recovery(){
  278 + clear();
  279 +
  280 + //设置msgId
  281 + Integer maxMsgId = d60Repository.maxMsgId();
  282 + MsgIdGenerator.setMsgId(maxMsgId ++);
  283 +
  284 + Calendar cal = Calendar.getInstance();
  285 + cal.set(Calendar.HOUR_OF_DAY, 2);
  286 + cal.set(Calendar.SECOND, 0);
  287 + cal.set(Calendar.MINUTE, 0);
  288 + cal.set(Calendar.MILLISECOND, 0);
  289 + //当天2点开始恢复
  290 + long st = cal.getTimeInMillis()
  291 + ,ct = System.currentTimeMillis();
  292 +
  293 + //如果还不到2点,从前一天2点开始恢复
  294 + if(ct < st){
  295 + st -= (1000 * 60 * 60 * 24);
  296 + }
  297 +
  298 + List<Directive60> d60List = d60Repository.findByGtTime(st);
  299 + //恢复60下发指令
  300 + for(Directive60 d : d60List){
  301 + directiveMap.put(d.getMsgId(), d);
  302 + }
  303 +
  304 + //恢复80驾驶员上报
  305 + List<Directive80> d80List = d80Repository.findByGtTime(st);
  306 +
  307 + for(Directive80 d : d80List){
  308 + d.getData().setNbbm(CommonMapped.vehicDeviceBiMap.get(d.getDeviceId()));
  309 + reportMultiMap.put(d.getData().getLineId(), d);
  310 + }
  311 + }
  312 +
  313 + public static List<Directive80> findNoCofm80(Integer lineCode){
  314 + List<Directive80> list = reportMultiMap.get(lineCode)
  315 + ,rs = new ArrayList<>();
  316 +
  317 + for(Directive80 d : list){
  318 + if(!d.isConfirm())
  319 + rs.add(d);
  320 + }
  321 + return rs;
  322 + }
  323 +
  324 + public static Directive80 findById80(int id){
  325 + Collection<Directive80> ds = reportMultiMap.values();
  326 +
  327 + Directive80 rs = null;
  328 + for(Directive80 d : ds){
  329 + if(d.getId() == id){
  330 + rs = d;
  331 + break;
  332 + }
  333 + }
  334 +
  335 + return rs;
  336 + }
  337 +
  338 + /**
  339 + *
  340 + * @Title: findAll
  341 + * @Description: TODO(获取缓存里的全部指令)
  342 + * @throws
  343 + */
  344 + public static List<Object> findAll(){
  345 + List<Object> all = new ArrayList<>();
  346 + //60
  347 + all.addAll(directiveMap.values());
  348 + //64
  349 + all.addAll(changeMap.values());
  350 + return all;
  351 + }
  352 +
  353 + public static class DComparator implements Comparator<Object>{
  354 +
  355 + @Override
  356 + public int compare(Object o1, Object o2) {
  357 + Long t1,t2;
  358 + if(o1 instanceof Directive60)
  359 + t1 = ((Directive60)o1).getTimestamp();
  360 + else
  361 + t1 = ((Directive64)o1).getTimestamp();
  362 +
  363 + if(o2 instanceof Directive60)
  364 + t2 = ((Directive60)o2).getTimestamp();
  365 + else
  366 + t2 = ((Directive64)o2).getTimestamp();
  367 +
  368 + return (int) (t2 - t1);
  369 + }
  370 +
  371 + }
251 372 }
... ...
src/main/java/com/bsth/vehicle/directive/controller/DirectiveController.java
1 1 package com.bsth.vehicle.directive.controller;
2 2  
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
3 6 import org.springframework.beans.factory.annotation.Autowired;
4 7 import org.springframework.web.bind.annotation.RequestMapping;
5 8 import org.springframework.web.bind.annotation.RequestMethod;
6 9 import org.springframework.web.bind.annotation.RequestParam;
7 10 import org.springframework.web.bind.annotation.RestController;
8 11  
  12 +import com.bsth.vehicle.directive.entity.Directive80;
9 13 import com.bsth.vehicle.directive.service.DirectiveService;
10 14  
11 15 /**
... ... @@ -71,4 +75,45 @@ public class DirectiveController {
71 75 public int upDownChange(@RequestParam String nbbm, @RequestParam Integer upDown){
72 76 return directiveService.upDownChange(nbbm, upDown);
73 77 }
  78 +
  79 + /**
  80 + *
  81 + * @Title: findNoCofm80
  82 + * @Description: TODO(根据线路获取未确认的80驾驶员上报数据)
  83 + * @throws
  84 + */
  85 + @RequestMapping(value = "/findNoCofm80", method = RequestMethod.GET)
  86 + public Map<String, List<Directive80>> findNoCofm80(@RequestParam String lineCodes){
  87 + return directiveService.findNoCofm80(lineCodes);
  88 + }
  89 +
  90 + /**
  91 + *
  92 + * @Title: reply80
  93 + * @Description: TODO(回复80)
  94 + * @param @param reply 0:同意 -1:不同意
  95 + * @throws
  96 + */
  97 + @RequestMapping(value = "/reply80", method = RequestMethod.POST)
  98 + public Map<String, Object> reply80(@RequestParam int id, @RequestParam int reply){
  99 + return directiveService.reply80(id, reply);
  100 + }
  101 +
  102 + /**
  103 + *
  104 + * @Title: findDirective
  105 + * @Description: TODO(查询调度指令)
  106 + * @param @param nbbm 车辆
  107 + * @param @param dType 类型
  108 + * @param @param page 页号
  109 + * @param @param size 每页数量
  110 + * @throws
  111 + */
  112 + @RequestMapping(value = "/list", method = RequestMethod.GET)
  113 + public List<Object> findDirective(@RequestParam String nbbm,@RequestParam int dType
  114 + , @RequestParam(defaultValue = "0") int page,
  115 + @RequestParam(defaultValue = "10") int size){
  116 +
  117 + return directiveService.findDirective(nbbm, dType, page, size);
  118 + }
74 119 }
... ...
src/main/java/com/bsth/vehicle/directive/entity/Directive60.java
... ... @@ -73,7 +73,7 @@ public class Directive60 {
73 73 private boolean isDispatch;
74 74  
75 75 /**
76   - * 如果是调度指令,则关联到相关的班次
  76 + * 相关联的班次
77 77 */
78 78 @ManyToOne
79 79 private ScheduleRealInfo sch;
... ... @@ -84,9 +84,6 @@ public class Directive60 {
84 84 @ManyToOne
85 85 private SysUser sender;
86 86  
87   - @Transient
88   - private boolean persistent;
89   -
90 87 @Embeddable
91 88 public static class DirectiveData {
92 89 // 公司代码
... ... @@ -283,12 +280,4 @@ public class Directive60 {
283 280 public void setSender(SysUser sender) {
284 281 this.sender = sender;
285 282 }
286   -
287   - public boolean isPersistent() {
288   - return persistent;
289   - }
290   -
291   - public void setPersistent(boolean persistent) {
292   - this.persistent = persistent;
293   - }
294 283 }
... ...
src/main/java/com/bsth/vehicle/directive/entity/LineChange.java renamed to src/main/java/com/bsth/vehicle/directive/entity/Directive64.java
... ... @@ -17,7 +17,7 @@ import javax.persistence.Id;
17 17 */
18 18 @Entity
19 19 @Table(name = "bsth_v_directive_64")
20   -public class LineChange {
  20 +public class Directive64 {
21 21  
22 22 @Id
23 23 @GeneratedValue
... ...
src/main/java/com/bsth/vehicle/directive/entity/Directive80.java
1 1 package com.bsth.vehicle.directive.entity;
2 2  
  3 +import javax.persistence.CascadeType;
3 4 import javax.persistence.Embeddable;
4 5 import javax.persistence.Entity;
  6 +import javax.persistence.FetchType;
5 7 import javax.persistence.GeneratedValue;
6 8 import javax.persistence.Id;
7 9 import javax.persistence.NamedAttributeNode;
... ... @@ -52,8 +54,14 @@ public class Directive80 {
52 54 /**
53 55 * c0 回复
54 56 */
55   - @OneToOne
  57 + @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
56 58 private DirectiveC0 c0;
  59 +
  60 + /** 调度员是否确认 */
  61 + private boolean confirm;
  62 +
  63 + /** 处理结果 0:同意 -1:不同意 */
  64 + private int confirmRs;
57 65  
58 66 @Embeddable
59 67 public static class DriverReportData {
... ... @@ -160,4 +168,20 @@ public class Directive80 {
160 168 public void setC0(DirectiveC0 c0) {
161 169 this.c0 = c0;
162 170 }
  171 +
  172 + public boolean isConfirm() {
  173 + return confirm;
  174 + }
  175 +
  176 + public void setConfirm(boolean confirm) {
  177 + this.confirm = confirm;
  178 + }
  179 +
  180 + public int getConfirmRs() {
  181 + return confirmRs;
  182 + }
  183 +
  184 + public void setConfirmRs(int confirmRs) {
  185 + this.confirmRs = confirmRs;
  186 + }
163 187 }
... ...
src/main/java/com/bsth/vehicle/directive/entity/DirectiveC0.java
... ... @@ -4,7 +4,6 @@ import javax.persistence.Embeddable;
4 4 import javax.persistence.Entity;
5 5 import javax.persistence.GeneratedValue;
6 6 import javax.persistence.Id;
7   -import javax.persistence.OneToOne;
8 7 import javax.persistence.Table;
9 8  
10 9 /**
... ...
src/main/java/com/bsth/vehicle/directive/repository/Directive60Repository.java
1 1 package com.bsth.vehicle.directive.repository;
2 2  
  3 +import java.util.List;
  4 +
  5 +import org.springframework.data.jpa.repository.Query;
3 6 import org.springframework.stereotype.Repository;
4 7  
5 8 import com.bsth.repository.BaseRepository;
... ... @@ -8,4 +11,10 @@ import com.bsth.vehicle.directive.entity.Directive60;
8 11 @Repository
9 12 public interface Directive60Repository extends BaseRepository<Directive60, Integer>{
10 13  
  14 +
  15 + @Query("select d from Directive60 d where d.data.timestamp > ?1")
  16 + public List<Directive60> findByGtTime(Long ts);
  17 +
  18 + @Query(value = "SELECT IFNULL(num,0) as maxId from (SELECT MAX(msg_id) as num FROM bsth_v_directive_60) d", nativeQuery = true)
  19 + Integer maxMsgId();
11 20 }
... ...
src/main/java/com/bsth/vehicle/directive/repository/Directive80Repository.java
1 1 package com.bsth.vehicle.directive.repository;
2 2  
  3 +import java.util.List;
  4 +
3 5 import org.springframework.data.domain.Page;
4 6 import org.springframework.data.domain.Pageable;
5 7 import org.springframework.data.jpa.domain.Specification;
6 8 import org.springframework.data.jpa.repository.EntityGraph;
  9 +import org.springframework.data.jpa.repository.Query;
7 10 import org.springframework.stereotype.Repository;
8 11  
9 12 import com.bsth.repository.BaseRepository;
... ... @@ -15,4 +18,8 @@ public interface Directive80Repository extends BaseRepository&lt;Directive80, Integ
15 18 @EntityGraph(value = "directive80_c0", type = EntityGraph.EntityGraphType.FETCH)
16 19 @Override
17 20 Page<Directive80> findAll(Specification<Directive80> spec, Pageable pageable);
  21 +
  22 + @EntityGraph(value = "directive80_c0", type = EntityGraph.EntityGraphType.FETCH)
  23 + @Query("select d from Directive80 d where d.timestamp > ?1")
  24 + List<Directive80> findByGtTime(long timestamp);
18 25 }
... ...
src/main/java/com/bsth/vehicle/directive/repository/LineChangeRepository.java
... ... @@ -3,9 +3,9 @@ package com.bsth.vehicle.directive.repository;
3 3 import org.springframework.stereotype.Repository;
4 4  
5 5 import com.bsth.repository.BaseRepository;
6   -import com.bsth.vehicle.directive.entity.LineChange;
  6 +import com.bsth.vehicle.directive.entity.Directive64;
7 7  
8 8 @Repository
9   -public interface LineChangeRepository extends BaseRepository<LineChange, Integer>{
  9 +public interface LineChangeRepository extends BaseRepository<Directive64, Integer>{
10 10  
11 11 }
... ...
src/main/java/com/bsth/vehicle/directive/service/DirectiveService.java
1 1 package com.bsth.vehicle.directive.service;
2 2  
3 3  
  4 +import java.util.List;
  5 +import java.util.Map;
  6 +
4 7 import com.bsth.entity.realcontrol.ScheduleRealInfo;
5 8 import com.bsth.service.BaseService;
6 9 import com.bsth.vehicle.directive.entity.Directive60;
  10 +import com.bsth.vehicle.directive.entity.Directive80;
7 11  
8 12 public interface DirectiveService extends BaseService<Directive60, Integer>{
9 13  
... ... @@ -38,7 +42,7 @@ public interface DirectiveService extends BaseService&lt;Directive60, Integer&gt;{
38 42 int send60Dispatch(Long id);
39 43  
40 44 //60营运指令
41   - int send60Operation(String nbbm, int state, int upDown);
  45 + int send60Operation(String nbbm, int state, int upDown, ScheduleRealInfo sch);
42 46  
43 47 /**
44 48 *
... ... @@ -67,4 +71,10 @@ public interface DirectiveService extends BaseService&lt;Directive60, Integer&gt;{
67 71 * @throws
68 72 */
69 73 void sendDirectiveToPage(ScheduleRealInfo sch);
  74 +
  75 + Map<String, List<Directive80>> findNoCofm80(String lineCodes);
  76 +
  77 + Map<String, Object> reply80(int id, int reply);
  78 +
  79 + List<Object> findDirective(String nbbm, int dType, int page, int size);
70 80 }
... ...
src/main/java/com/bsth/vehicle/directive/service/DirectiveServiceImpl.java
1 1 package com.bsth.vehicle.directive.service;
2 2  
3 3 import java.text.SimpleDateFormat;
  4 +import java.util.Collections;
  5 +import java.util.Comparator;
4 6 import java.util.Date;
5 7 import java.util.HashMap;
  8 +import java.util.List;
6 9 import java.util.Map;
7 10  
8 11 import org.slf4j.Logger;
... ... @@ -12,6 +15,7 @@ import org.springframework.stereotype.Service;
12 15  
13 16 import com.alibaba.fastjson.JSON;
14 17 import com.alibaba.fastjson.JSONObject;
  18 +import com.bsth.common.ResponseCode;
15 19 import com.bsth.entity.realcontrol.ScheduleRealInfo;
16 20 import com.bsth.service.impl.BaseServiceImpl;
17 21 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
... ... @@ -21,14 +25,19 @@ import com.bsth.vehicle.directive.MsgIdGenerator;
21 25 import com.bsth.vehicle.directive.buffer.DirectiveBuffer;
22 26 import com.bsth.vehicle.directive.entity.Directive60;
23 27 import com.bsth.vehicle.directive.entity.Directive60.DirectiveData;
24   -import com.bsth.vehicle.directive.entity.LineChange;
25   -import com.bsth.vehicle.directive.entity.LineChange.LineChangeData;
  28 +import com.bsth.vehicle.directive.entity.DirectiveC0.DirectiveC0Data;
  29 +import com.bsth.vehicle.directive.entity.Directive80;
  30 +import com.bsth.vehicle.directive.entity.DirectiveC0;
  31 +import com.bsth.vehicle.directive.entity.Directive64;
  32 +import com.bsth.vehicle.directive.entity.Directive64.LineChangeData;
26 33 import com.bsth.vehicle.directive.repository.Directive60Repository;
  34 +import com.bsth.vehicle.directive.repository.Directive80Repository;
27 35 import com.bsth.vehicle.directive.repository.LineChangeRepository;
28 36 import com.bsth.vehicle.directive.util.HttpUtils;
29 37 import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
30 38 import com.bsth.vehicle.gpsdata.entity.GpsRealData;
31 39 import com.bsth.websocket.handler.RealControlSocketHandler;
  40 +import com.google.common.base.Splitter;
32 41  
33 42 @Service
34 43 public class DirectiveServiceImpl extends BaseServiceImpl<Directive60, Integer> implements DirectiveService{
... ... @@ -47,6 +56,9 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
47 56 @Autowired
48 57 RealControlSocketHandler socketHandler;
49 58  
  59 + @Autowired
  60 + Directive80Repository d80Repository;
  61 +
50 62 SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH点mm分");
51 63  
52 64 static Long schDiff = 1000 * 60 * 60L;
... ... @@ -142,8 +154,24 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
142 154 }
143 155  
144 156 @Override
145   - public int send60Operation(String nbbm, int state, int upDown) {
146   - return 0;
  157 + public int send60Operation(String nbbm, int state, int upDown, ScheduleRealInfo sch) {
  158 + logger.info("切换运营状态, nbbm: " + nbbm + " ,state: " + state + " ,upDown:" + upDown );
  159 +
  160 + Directive60 directive = createDirective60(nbbm, nbbm + "_" + upDown, (short) 0x03, upDown, state);
  161 +
  162 + if(null == directive)
  163 + return -1;
  164 + //发送指令
  165 + int code = HttpUtils.postJson(JSON.toJSONString(directive));
  166 + if(code == 0){
  167 + //添加到缓存,等待入库
  168 + if(null != sch)
  169 + directive.setSch(sch);
  170 + DirectiveBuffer.put(directive);
  171 + }else{
  172 + logger.error("send60Phrase error, code: " + code);
  173 + }
  174 + return code;
147 175 }
148 176  
149 177 /**
... ... @@ -154,7 +182,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
154 182 Long t = System.currentTimeMillis();
155 183 String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm);
156 184  
157   - LineChange change = new LineChange();
  185 + Directive64 change = new Directive64();
158 186 LineChangeData data = new LineChangeData();
159 187 data.setCityCode(cityCode);
160 188 data.setDeviceId(deviceId);
... ... @@ -180,14 +208,12 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
180 208  
181 209  
182 210 public Directive60 create60Data(String nbbm, String text, Short dispatchInstruct, ScheduleRealInfo sch){
183   - Long timestamp = System.currentTimeMillis();
184 211  
185 212 /*//向测试设备发送
186 213 String deviceId = "ABCDFEGH";
187 214 Short company = 5;*/
188 215  
189 216 String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm);
190   - Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm));
191 217 if(null == deviceId){
192 218 logger.error("没有设备号对照的车辆:" + nbbm);
193 219 return null;
... ... @@ -208,6 +234,14 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
208 234 state = 0;
209 235 }
210 236  
  237 + return createDirective60(nbbm, text, dispatchInstruct, upDown, state);
  238 + }
  239 +
  240 + public Directive60 createDirective60(String nbbm, String text, Short dispatchInstruct,int upDown,int state){
  241 + Long timestamp = System.currentTimeMillis();
  242 +
  243 + Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm));
  244 + String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm);
211 245  
212 246 int msgId = MsgIdGenerator.getMsgId();
213 247  
... ... @@ -242,37 +276,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
242 276  
243 277 @Override
244 278 public int upDownChange(String nbbm, Integer upDown) {
245   - //构造数据
246   - String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm);
247   - Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm));
248   - Long timestamp = System.currentTimeMillis();
249   - int msgId = MsgIdGenerator.getMsgId();
250   - Directive60 directive = new Directive60();
251   - DirectiveData data = new DirectiveData();
252   - //一级协议
253   - directive.setOperCode((short) 0x60);
254   - //设备号
255   - directive.setDeviceId(deviceId);
256   - //时间戳
257   - directive.setTimestamp(timestamp);
258   - directive.setMsgId(msgId);
259   - //构造数据
260   - data.setDeviceId(deviceId);
261   - data.setDispatchInstruct((short)0x03);
262   - data.setTimestamp(timestamp);
263   - data.setCompanyCode(company);
264   - data.setMsgId(msgId);
265   - data.setTxtContent(nbbm + "_" + upDown);
266   - directive.setData(data);
  279 + /*Directive60 directive = createDirective60(nbbm, nbbm + "_" + upDown, (short) 0x03, upDown, 0);
267 280  
268   - long serviceState;
269   - try{
270   - serviceState = Consts.SERVICE_STATE[upDown][0];
271   - }catch(IndexOutOfBoundsException e){
272   - logger.error("upDonw: " + upDown, e);
  281 + if(null == directive)
273 282 return -1;
274   - }
275   - data.setServiceState(serviceState);
276 283  
277 284 int code = HttpUtils.postJson(JSON.toJSONString(directive));
278 285 if(code == 0){
... ... @@ -280,8 +287,8 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
280 287 DirectiveBuffer.put(directive);
281 288 }else{
282 289 logger.error("send60 upDownChange error, code: " + code);
283   - }
284   - return code;
  290 + }*/
  291 + return send60Operation(nbbm, 0, upDown, null);
285 292 }
286 293  
287 294 /**
... ... @@ -312,4 +319,85 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;Directive60, Integer&gt;
312 319  
313 320 return JSON.toJSONString(param);
314 321 }
  322 +
  323 + @Override
  324 + public Map<String, List<Directive80>> findNoCofm80(String lineCodes) {
  325 + List<String> lineList = Splitter.on(",").trimResults().splitToList(lineCodes);
  326 +
  327 + Map<String, List<Directive80>> rs = new HashMap<>();
  328 + for(String code : lineList){
  329 + rs.put(code, DirectiveBuffer.findNoCofm80(Integer.parseInt(code)));
  330 + }
  331 +
  332 + return rs;
  333 + }
  334 +
  335 + @Override
  336 + public Map<String, Object> reply80(int id, int reply) {
  337 + Map<String, Object> rs = new HashMap<>();
  338 +
  339 + Directive80 d80 = DirectiveBuffer.findById80(id);
  340 + if(null == d80){
  341 + rs.put("status", ResponseCode.ERROR);
  342 + rs.put("msg", "服务器没有找到对应数据!");
  343 + }
  344 + else if(d80.isConfirm()){
  345 + rs.put("status", ResponseCode.ERROR);
  346 + rs.put("msg", "该数据已经被处理了!");
  347 + }
  348 + else{
  349 + d80.setConfirm(true);
  350 + d80.setConfirmRs(reply);
  351 + //封装C0数据包并回复设备
  352 + DirectiveC0 c0 = new DirectiveC0();
  353 + c0.setDeviceId(d80.getDeviceId());
  354 + c0.setTimestamp(d80.getTimestamp());
  355 + c0.setOperCode((short) 0xC0);
  356 +
  357 + DirectiveC0Data data = new DirectiveC0Data();
  358 + data.setOperCode2((short) 0x86);
  359 + data.setRequestAck((short)(reply==0?0x06:0x15));
  360 +
  361 + c0.setData(data);
  362 +
  363 + d80.setC0(c0);
  364 + //入库
  365 + d80Repository.save(d80);
  366 +
  367 + int code = HttpUtils.postJson(JSON.toJSONString(c0));
  368 +
  369 + rs.put("status", ResponseCode.SUCCESS);
  370 + if(code != 0)
  371 + rs.put("msg", "发送C0响应指令到车载设备失败,但该操作已经被系统记录!");
  372 +
  373 + //通知页面
  374 + Map<String, Object> sockMap = new HashMap<>();
  375 + sockMap.put("fn", "d80Confirm");
  376 + sockMap.put("id", d80.getId());
  377 + socketHandler.sendMessageToLine(d80.getData().getLineId(), JSON.toJSONString(sockMap));
  378 + }
  379 +
  380 + return rs;
  381 + }
  382 +
  383 + @Override
  384 + public List<Object> findDirective(String nbbm, int dType, int page, int size) {
  385 + List<Object> list = null;
  386 + if(dType == -1){
  387 + list = DirectiveBuffer.findAll();
  388 + //时间倒序
  389 + Collections.sort(list, new DirectiveBuffer.DComparator());
  390 +
  391 + int count = list.size();
  392 + //分页
  393 + int s = page * size
  394 + ,e = s + size;
  395 +
  396 + if(e > count)
  397 + e = count;
  398 +
  399 + list.subList(s, e);
  400 + }
  401 + return list;
  402 + }
315 403 }
... ...
src/main/java/com/bsth/vehicle/directive/thread/DirectivePersistenceThread.java
... ... @@ -38,7 +38,6 @@ public class DirectivePersistenceThread extends Thread{
38 38 if(null == directive)
39 39 break;
40 40  
41   - directive.setPersistent(true);
42 41 directiveRepository.save(directive);
43 42 }
44 43 }
... ...
src/main/java/com/bsth/vehicle/directive/thread/FirstScheduleIssuedThread.java
... ... @@ -3,12 +3,18 @@ package com.bsth.vehicle.directive.thread;
3 3 import java.util.List;
4 4 import java.util.Set;
5 5  
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
6 8 import org.springframework.beans.factory.annotation.Autowired;
7 9 import org.springframework.stereotype.Component;
8 10  
9 11 import com.bsth.entity.realcontrol.ScheduleRealInfo;
10 12 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
  13 +import com.bsth.vehicle.common.CommonMapped;
11 14 import com.bsth.vehicle.directive.service.DirectiveService;
  15 +import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
  16 +import com.bsth.vehicle.gpsdata.entity.GpsRealData;
  17 +import com.google.common.collect.BiMap;
12 18  
13 19 /**
14 20 *
... ... @@ -24,24 +30,47 @@ public class FirstScheduleIssuedThread extends Thread{
24 30 @Autowired
25 31 DirectiveService directiveService;
26 32  
  33 + //最多提前一小时开始尝试切换首班车营运状态
  34 + final static long space = 1000 * 60 * 60 ;
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
27 38 @Override
28 39 public void run() {
29 40  
30 41 Set<String> keys = ScheduleBuffer.carSchListMap.keySet();
31 42 List<ScheduleRealInfo> list;
  43 + BiMap<String, String> nbbmToDeviceMap = CommonMapped.vehicDeviceBiMap.inverse();
32 44  
33 45 Long t = System.currentTimeMillis();
34 46 ScheduleRealInfo sch;
  47 +
  48 + GpsRealData gps;
35 49 for(String nbbm : keys){
36   - list = ScheduleBuffer.carSchListMap.get(nbbm);
37   -
38   - if(list.size() == 0)
39   - continue;
40   -
41   - sch = list.get(0);
42   -
43   - if(sch.getStatus() == 0 && sch.getFcsjT() > t){
44   - directiveService.send60Dispatch(sch, 0);
  50 + gps = GpsRealDataBuffer.findByDeviceId(nbbmToDeviceMap.get(nbbm));
  51 + //如果设备在线
  52 + if(null != gps && gps.isOnline()){
  53 + list = ScheduleBuffer.carSchListMap.get(nbbm);
  54 +
  55 + if(list.size() == 0)
  56 + continue;
  57 +
  58 + sch = list.get(0);
  59 +
  60 + if(sch.getOpDirectiveState()!= 100
  61 + && sch.getStatus() == 0
  62 + && Math.abs(sch.getFcsjT() - t) < space){
  63 +
  64 + /*if(sch.getDirectiveState() == -1){
  65 + //发送调度指令
  66 + directiveService.send60Dispatch(sch, 0);
  67 + }*/
  68 + logger.info("切换首班运营状态, " + sch.getClZbh());
  69 + //切换营运状态
  70 + directiveService.send60Operation(sch.getClZbh()
  71 + , 0, Integer.parseInt(sch.getXlDir())
  72 + , sch);
  73 + }
45 74 }
46 75 }
47 76  
... ...
src/main/java/com/bsth/vehicle/gpsdata/GpsArrivalThread.java renamed to src/main/java/com/bsth/vehicle/gpsdata/ArrivalThread.java
... ... @@ -16,12 +16,11 @@ import org.slf4j.LoggerFactory;
16 16 import org.springframework.beans.factory.annotation.Autowired;
17 17 import org.springframework.stereotype.Component;
18 18  
19   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
20 19 import com.bsth.util.DateUtils;
21 20 import com.bsth.util.db.DBUtils_MS;
22 21 import com.bsth.vehicle.directive.service.DirectiveService;
23 22 import com.bsth.vehicle.gpsdata.arrival.MatchService;
24   -import com.bsth.vehicle.gpsdata.buffer.GpsArrivalDataBuffer;
  23 +import com.bsth.vehicle.gpsdata.buffer.ArrivalDataBuffer;
25 24 import com.bsth.vehicle.gpsdata.entity.ArrivalInfo;
26 25 import com.bsth.websocket.handler.RealControlSocketHandler;
27 26  
... ... @@ -34,7 +33,7 @@ import com.bsth.websocket.handler.RealControlSocketHandler;
34 33 *
35 34 */
36 35 @Component
37   -public class GpsArrivalThread extends Thread{
  36 +public class ArrivalThread extends Thread{
38 37  
39 38 Logger logger = LoggerFactory.getLogger(this.getClass());
40 39 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
... ... @@ -56,7 +55,7 @@ public class GpsArrivalThread extends Thread{
56 55 e.printStackTrace();
57 56 }
58 57 //缓存
59   - GpsArrivalDataBuffer.putAll(list);
  58 + ArrivalDataBuffer.putAll(list);
60 59  
61 60 //有新到离站数据的线路
62 61 Set<String> newSet = new HashSet<>();
... ... @@ -220,12 +219,13 @@ public class GpsArrivalThread extends Thread{
220 219 //周数,表分区字段
221 220 int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
222 221 //按时间标记增量加载
223   - if(null == GpsArrivalDataBuffer.markTime){
  222 + if(null == ArrivalDataBuffer.markTime){
224 223 //第一次从当天0点开始
225   - GpsArrivalDataBuffer.markTime = DateUtils.getTimesmorning() * 1000L;
  224 + ArrivalDataBuffer.markTime = DateUtils.getTimesmorning() * 1000L;
226 225 }
227 226  
228   - String sql = "select * from bsth_c_arrival_info where weeks_year=? and ts > ? order by ts";
  227 + Long t = System.currentTimeMillis();
  228 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and create_timestamp > ? and create_timestamp <=? order by create_date";
229 229  
230 230 List<ArrivalInfo> list = new ArrayList<>();
231 231 Connection conn = null;
... ... @@ -235,19 +235,21 @@ public class GpsArrivalThread extends Thread{
235 235 conn = DBUtils_MS.getConnection();
236 236 ps = conn.prepareStatement(sql);
237 237 ps.setInt(1, weeks_year/*30*/);
238   - ps.setLong(2, GpsArrivalDataBuffer.markTime/*1461361377000L*/);
  238 + ps.setLong(2, ArrivalDataBuffer.markTime/*1461361377000L*/);
  239 + ps.setLong(3, t/*30*/);
  240 +
239 241  
240   - Long t = System.currentTimeMillis();
241 242 rs = ps.executeQuery();
242 243  
243 244 while(rs.next()){
244 245 list.add(new ArrivalInfo(rs.getString("device_id"), rs.getLong("ts"), rs.getString("line_id")
245   - , rs.getInt("up_down"), rs.getString("stop_no"), rs.getInt("in_out"), rs.getDate("create_date"), rs.getInt("weeks_year")));
  246 + , rs.getInt("up_down"), rs.getString("stop_no"), rs.getInt("in_out"), rs.getLong("create_date")
  247 + , rs.getInt("weeks_year")));
246 248 }
247 249  
248   - System.out.println("数量:" + list.size() + " ,markTime:" + GpsArrivalDataBuffer.markTime);
249   - //重新打时间标记
250   - GpsArrivalDataBuffer.markTime = t;
  250 + logger.info("获取 到离站 数量:" + list.size() + ", st: " + ArrivalDataBuffer.markTime + " , et: " + t);
  251 + //时间戳标记
  252 + ArrivalDataBuffer.markTime = t;
251 253  
252 254 } catch (Exception e) {
253 255 logger.error("", e);
... ... @@ -264,10 +266,9 @@ public class GpsArrivalThread extends Thread{
264 266 * @Description: TODO(提取当前时间前后一小时的计划)
265 267 * @param @param allList
266 268 * @throws
267   - */
  269 +
268 270 public List<ScheduleRealInfo> extractSched(List<ScheduleRealInfo> allList){
269 271 List<ScheduleRealInfo> subList = new ArrayList<>();
270   - System.out.println("原计划:" + allList.size());
271 272 Long t = System.currentTimeMillis();
272 273 for(ScheduleRealInfo sch : allList){
273 274 if(Math.abs(sch.getFcsjT() - t) < rang
... ... @@ -275,7 +276,6 @@ public class GpsArrivalThread extends Thread{
275 276 subList.add(sch);
276 277 }
277 278 }
278   - System.out.println("按时间提取:" + subList.size());
279 279 return subList;
280   - }
  280 + } */
281 281 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/GpsArrivalStationThread_old.java
... ... @@ -23,7 +23,7 @@ import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
23 23 import com.bsth.util.DateUtils;
24 24 import com.bsth.util.db.DBUtils_MS;
25 25 import com.bsth.vehicle.directive.service.DirectiveService;
26   -import com.bsth.vehicle.gpsdata.buffer.GpsArrivalDataBuffer;
  26 +import com.bsth.vehicle.gpsdata.buffer.ArrivalDataBuffer;
27 27 import com.bsth.vehicle.gpsdata.entity.ArrivalInfo;
28 28 import com.bsth.websocket.handler.RealControlSocketHandler;
29 29  
... ... @@ -57,16 +57,16 @@ public class GpsArrivalStationThread_old extends Thread{
57 57 } catch (ParseException e) {
58 58 e.printStackTrace();
59 59 }
60   - GpsArrivalDataBuffer.putAll(list);
  60 + ArrivalDataBuffer.putAll(list);
61 61 //实际到离站和计划排班相匹配
62 62  
63   - Set<String> keySet = GpsArrivalDataBuffer.allMap.keySet();
  63 + Set<String> keySet = ArrivalDataBuffer.allMap.keySet();
64 64 System.out.println("开始...");
65 65 List<ScheduleRealInfo> schList;
66 66 for(String key : keySet){
67 67 schList = extractSched(ScheduleBuffer.carSchListMap.get(key));
68 68 if(null != schList)
69   - match(GpsArrivalDataBuffer.allMap.get(key), schList);
  69 + match(ArrivalDataBuffer.allMap.get(key), schList);
70 70 }
71 71 System.out.println("结束...");
72 72 }
... ... @@ -207,9 +207,9 @@ public class GpsArrivalStationThread_old extends Thread{
207 207 //周数,表分区字段
208 208 int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
209 209 //按时间标记增量加载
210   - if(null == GpsArrivalDataBuffer.markTime){
  210 + if(null == ArrivalDataBuffer.markTime){
211 211 //第一次从当天0点开始
212   - GpsArrivalDataBuffer.markTime = DateUtils.getTimesmorning() * 1000L;
  212 + ArrivalDataBuffer.markTime = DateUtils.getTimesmorning() * 1000L;
213 213 }
214 214  
215 215 String sql = "select * from bsth_c_arrival_info where weeks_year=? and create_date > ? order by ts";
... ... @@ -222,18 +222,18 @@ public class GpsArrivalStationThread_old extends Thread{
222 222 conn = DBUtils_MS.getConnection();
223 223 ps = conn.prepareStatement(sql);
224 224 ps.setInt(1, weeks_year);
225   - ps.setLong(2, GpsArrivalDataBuffer.markTime);
  225 + ps.setLong(2, ArrivalDataBuffer.markTime);
226 226  
227 227 Long t = System.currentTimeMillis();
228 228 rs = ps.executeQuery();
229 229  
230 230 while(rs.next()){
231 231 list.add(new ArrivalInfo(rs.getString("device_id"), rs.getLong("ts"), rs.getString("line_id")
232   - , rs.getInt("up_down"), rs.getString("stop_no"), rs.getInt("in_out"), rs.getDate("create_date"), rs.getInt("weeks_year")));
  232 + , rs.getInt("up_down"), rs.getString("stop_no"), rs.getInt("in_out"), rs.getLong("create_date"), rs.getInt("weeks_year")));
233 233 }
234 234  
235 235 //重新打时间标记
236   - GpsArrivalDataBuffer.markTime = t;
  236 + ArrivalDataBuffer.markTime = t;
237 237  
238 238 } catch (Exception e) {
239 239 logger.error("", e);
... ...
src/main/java/com/bsth/vehicle/gpsdata/GpsOfflineMonitorThread.java 0 → 100644
  1 +package com.bsth.vehicle.gpsdata;
  2 +
  3 +import java.util.Collection;
  4 +
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
  10 +import com.bsth.vehicle.gpsdata.entity.GpsRealData;
  11 +
  12 +/**
  13 + *
  14 + * @ClassName: GpsOfflineMonitorThread
  15 + * @Description: TODO(GPS 掉线监控)
  16 + * @author PanZhao
  17 + * @date 2016年7月29日 上午1:03:29
  18 + *
  19 + */
  20 +@Component
  21 +public class GpsOfflineMonitorThread extends Thread{
  22 +
  23 + Logger logger = LoggerFactory.getLogger(this.getClass());
  24 +
  25 + @Override
  26 + public void run() {
  27 +
  28 + long t = System.currentTimeMillis();
  29 + Collection<GpsRealData> allGps = GpsRealDataBuffer.allGps();
  30 +
  31 + for(GpsRealData gps : allGps){
  32 + if(t - gps.getTimestamp()
  33 + > GpsRealDataBuffer.OFFLINE_TIME){
  34 + gps.setOnline(false);
  35 + logger.info("设备:" + gps.getDeviceId() + " 掉线");
  36 + }
  37 + }
  38 + }
  39 +}
... ...
src/main/java/com/bsth/vehicle/gpsdata/GpsRefreshThread.java renamed to src/main/java/com/bsth/vehicle/gpsdata/GpsRealDataRefreshThread.java
... ... @@ -33,15 +33,15 @@ import com.google.common.collect.ImmutableMap;
33 33 *
34 34 */
35 35 @Component
36   -public class GpsRefreshThread extends Thread{
  36 +public class GpsRealDataRefreshThread extends Thread{
37 37  
38   - private static Logger logger = LoggerFactory.getLogger(GpsRefreshThread.class);
  38 + private static Logger logger = LoggerFactory.getLogger(GpsRealDataRefreshThread.class);
39 39  
40 40 //接口地址
41 41 private static String url;
42 42  
43 43  
44   - public GpsRefreshThread() {
  44 + public GpsRealDataRefreshThread() {
45 45 url = ConfigUtil.get("http.gps.real.url");
46 46 }
47 47  
... ... @@ -51,7 +51,7 @@ public class GpsRefreshThread extends Thread{
51 51 @Override
52 52 public void run() {
53 53 try{
54   - Long t = System.currentTimeMillis();
  54 + //Long t = System.currentTimeMillis();
55 55 List<GpsRealData> newList = getterRealGpsData();
56 56  
57 57 if(gpsBuffer.isNullEmpty())
... ... @@ -82,7 +82,7 @@ public class GpsRefreshThread extends Thread{
82 82 gpsBuffer.setLastUpdateTime(System.currentTimeMillis());
83 83 }
84 84  
85   - logger.info("本次刷新GPS实时数据耗时:" + (System.currentTimeMillis() - t) + "毫秒");
  85 + //logger.info("本次刷新GPS实时数据耗时:" + (System.currentTimeMillis() - t) + "毫秒");
86 86 }catch(Exception e){
87 87 //logger.error("", e);
88 88 logger.error("加载gps数据失败," + e.getMessage());
... ...
src/main/java/com/bsth/vehicle/gpsdata/arrival/ThreadPoolTask.java
... ... @@ -6,7 +6,7 @@ import java.util.Set;
6 6 import com.bsth.entity.realcontrol.ScheduleRealInfo;
7 7 import com.bsth.service.realcontrol.buffer.ScheduleBuffer;
8 8 import com.bsth.vehicle.gpsdata.arrival.match.ScheduleRealMatcher;
9   -import com.bsth.vehicle.gpsdata.buffer.GpsArrivalDataBuffer;
  9 +import com.bsth.vehicle.gpsdata.buffer.ArrivalDataBuffer;
10 10 import com.google.common.collect.ArrayListMultimap;
11 11  
12 12 public class ThreadPoolTask implements Runnable {
... ... @@ -34,8 +34,7 @@ public class ThreadPoolTask implements Runnable {
34 34 Set<String> ks = alMap.keySet();
35 35  
36 36 for(String nbbm : ks){
37   -
38   - srMatcher = new ScheduleRealMatcher(alMap.get(nbbm), GpsArrivalDataBuffer.pops(nbbm));
  37 + srMatcher = new ScheduleRealMatcher(alMap.get(nbbm), ArrivalDataBuffer.pops(nbbm));
39 38  
40 39 //在这里应用各种匹配规则
41 40 srMatcher
... ...
src/main/java/com/bsth/vehicle/gpsdata/arrival/match/ScheduleRealMatcher.java
... ... @@ -6,11 +6,11 @@ import java.util.Collections;
6 6 import java.util.Comparator;
7 7 import java.util.Date;
8 8 import java.util.HashMap;
9   -import java.util.HashSet;
10 9 import java.util.List;
11 10 import java.util.Map;
12   -import java.util.Set;
13 11  
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
14 14 import org.springframework.beans.BeansException;
15 15 import org.springframework.context.ApplicationContext;
16 16 import org.springframework.context.ApplicationContextAware;
... ... @@ -56,8 +56,10 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
56 56  
57 57 SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
58 58  
  59 + Logger logger = LoggerFactory.getLogger(ScheduleRealMatcher.class);
  60 +
59 61 //最大班次间隔
60   - int maxBcsj = 0;
  62 + //int maxBcsj = 0;
61 63  
62 64 public ScheduleRealMatcher(){}
63 65  
... ... @@ -68,7 +70,7 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
68 70 Collections.sort(schs, new Comparator<ScheduleRealInfo>() {
69 71 @Override
70 72 public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
71   - return (int) (s1.getFcsjT() - s2.getFcsjT());
  73 + return (int) (s1.getDfsjT() - s2.getDfsjT());
72 74 }
73 75 });
74 76  
... ... @@ -89,9 +91,9 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
89 91 }
90 92  
91 93 for(ScheduleRealInfo sch : schs){
92   - if(sch.getBcsj() != null && sch.getBcsj() > maxBcsj){
  94 + /*if(sch.getBcsj() != null && sch.getBcsj() > maxBcsj){
93 95 maxBcsj = sch.getBcsj();
94   - }
  96 + }*/
95 97  
96 98 if(sch.getSjfcModel() == null)
97 99 sch.setSjfcModel(new RealTimeModel(sch.getQdzCode(), 1));
... ... @@ -107,7 +109,7 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
107 109 * @throws
108 110 */
109 111 public ScheduleRealMatcher timeClosest(){
110   - TimeClosestGPS.match(schs, inArrivals, outArrivals, maxBcsj);
  112 + TimeClosestGPS.match(schs, inArrivals, outArrivals);
111 113 return this;
112 114 }
113 115  
... ... @@ -119,6 +121,7 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
119 121 */
120 122 public void matchEnd(){
121 123  
  124 + int finish , upDown;
122 125 for(ScheduleRealInfo sch : schs){
123 126 //按 RealTimeModel 的优先级赋予班次实际时间
124 127 //起点发出
... ... @@ -151,10 +154,19 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
151 154 sendFcsj(sch.getTwins());//推送到页面
152 155 }
153 156  
154   - int finish = ScheduleBuffer.getFinishSchNo(sch.getClZbh());
  157 + finish = ScheduleBuffer.getFinishSchNo(sch.getClZbh());
  158 + upDown = Integer.parseInt(sch.getXlDir());
155 159 if(nextSch != null){
156 160 //发送下一班次的调度指令
157 161 directiveService.send60Dispatch(nextSch, finish);
  162 + //切换下一个班次的走向
  163 + logger.info(sch.getClZbh() + " 切换下一班次走向");
  164 + directiveService.send60Operation(nextSch.getClZbh(), 0, upDown, nextSch);
  165 + }
  166 + else{
  167 + //没有下一个班次了,切换为非营运状态
  168 + logger.info(sch.getClZbh() + " 完成所有班次,切换为非营运状态");
  169 + directiveService.send60Operation(sch.getClZbh(), 1, upDown, sch);
158 170 }
159 171  
160 172 sendZdsj(sch, nextSch, finish);//推送到页面
... ... @@ -186,7 +198,8 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
186 198 try{
187 199 socketHandler.sendMessageToLine(Integer.parseInt(schedule.getXlBm()), mapper.writeValueAsString(map));
188 200 }catch(Exception e){
189   - e.printStackTrace();
  201 + //e.printStackTrace();
  202 + logger.error("", e);
190 203 }
191 204 }
192 205  
... ... @@ -218,7 +231,8 @@ public class ScheduleRealMatcher implements ApplicationContextAware{
218 231 try{
219 232 socketHandler.sendMessageToLine(Integer.parseInt(schedule.getXlBm()), mapper.writeValueAsString(map));
220 233 }catch(Exception e){
221   - e.printStackTrace();
  234 + //e.printStackTrace();
  235 + logger.error("", e);
222 236 }
223 237 }
224 238  
... ...
src/main/java/com/bsth/vehicle/gpsdata/arrival/match/TimeClosestGPS.java
... ... @@ -22,31 +22,36 @@ public class TimeClosestGPS {
22 22 static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
23 23  
24 24 public static void match(List<ScheduleRealInfo> schs,
25   - List<ArrivalInfo> inList, List<ArrivalInfo> outList, int maxBcsj) {
  25 + List<ArrivalInfo> inList, List<ArrivalInfo> outList/*, int maxBcsj*/) {
26 26  
27 27 //班次ID 和 离站数据 一对一映射
28 28 BiMap<Long, String> outBiMap = HashBiMap.create();
29 29 //班次ID 和 到站数据 一对一映射
30 30 BiMap<Long, String> inBiMap = HashBiMap.create();
31 31  
32   - Long spaceTime = maxBcsj * 60 * 1000 * 2L;
  32 + Long spaceTime = /*maxBcsj * 60 * 1000 * 2L*/ 1000 * 60 * 60 * 1L;
33 33  
34 34 RealTimeModel sjfcModel, sjddModel;
35 35 for(ScheduleRealInfo sch : schs){
36 36  
  37 + if(sch.getClZbh().equals("B-91163")){
  38 + System.out.println("debugger...");
  39 + }
  40 +
37 41 sjfcModel = sch.getSjfcModel();
38 42 sjddModel = sch.getSjddModel();
39 43  
40 44 //起点发出
41 45 for(ArrivalInfo outArr : outList){
42   - if(sjfcModel.getStation().equals(outArr.getStopNo())
  46 + if((sch.getQdzCode().equals(outArr.getStopNo())/* || sch.getQdzName().equals(outArr.getStopName())*/)
43 47 && Math.abs(sch.getFcsjT() - outArr.getTs()) < spaceTime){
44 48  
45 49 //如果这个实际发车已经被之前班次关联
46   - if(outBiMap.inverse().get(outArr.getId()) != null)
  50 + if(outBiMap.inverse().get(outArr.getId()) != null
  51 + || outBiMap.get(sch.getId()) != null)
47 52 continue;
48 53  
49   - //System.out.println("实际起点发出,计划时间:" + sch.getFcsj() + " -实际时间:" + sdf.format(new Date(outArr.getTs())) + " -" + outArr.getTs());
  54 +
50 55 sjfcModel.setGpsTime(outArr.getTs());
51 56 outBiMap.put(sch.getId(), outArr.getId());
52 57 }
... ... @@ -57,13 +62,13 @@ public class TimeClosestGPS {
57 62 continue;
58 63 //终点到达
59 64 for(ArrivalInfo inArr : inList){
60   - if(sjddModel.getStation().equals(inArr.getStopNo())
  65 + if((sch.getZdzCode().equals(inArr.getStopNo())/* || sch.getZdzName().equals(inArr.getStopName())*/)
61 66 && Math.abs(sch.getZdsjT() - inArr.getTs()) < spaceTime){
62 67 //如果这个实际发车已经被之前班次关联
63   - if(inBiMap.inverse().get(inArr.getId()) != null)
  68 + if(inBiMap.inverse().get(inArr.getId()) != null
  69 + || inBiMap.get(sch.getId()) != null)
64 70 continue;
65 71  
66   - //System.out.println("实际到达终点,计划时间:" + sch.getZdsj() + " -实际时间:" + sdf.format(new Date(inArr.getTs())) + " -" + inArr.getTs());
67 72 sjddModel.setGpsTime(inArr.getTs());
68 73 inBiMap.put(sch.getId(), inArr.getId());
69 74 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/buffer/GpsArrivalDataBuffer.java renamed to src/main/java/com/bsth/vehicle/gpsdata/buffer/ArrivalDataBuffer.java
... ... @@ -19,7 +19,7 @@ import com.google.common.collect.ArrayListMultimap;
19 19 * @date 2016年6月27日 下午1:08:35
20 20 *
21 21 */
22   -public class GpsArrivalDataBuffer {
  22 +public class ArrivalDataBuffer {
23 23  
24 24 /**
25 25 * 车辆 时间戳排序的实际进出站
... ... @@ -69,7 +69,7 @@ public class GpsArrivalDataBuffer {
69 69 Collections.sort(list, new Comparator<ArrivalInfo>() {
70 70 @Override
71 71 public int compare(ArrivalInfo o1, ArrivalInfo o2) {
72   - return (int) (o1.getTs() - o2.getTs());
  72 + return (int) (o1.getCreateDate() - o2.getCreateDate());
73 73 }
74 74 });
75 75  
... ... @@ -84,4 +84,15 @@ public class GpsArrivalDataBuffer {
84 84 allMap.put(nbbm, arrival);
85 85 }
86 86 }
  87 +
  88 + /**
  89 + *
  90 + * @Title: clear
  91 + * @Description: TODO(清除缓存)
  92 + * @throws
  93 + */
  94 + public static void clear(){
  95 + allMap = ArrayListMultimap.create();
  96 + markMap = new HashMap<>();
  97 + }
87 98 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/buffer/GpsRealDataBuffer.java
1 1 package com.bsth.vehicle.gpsdata.buffer;
2 2  
3 3 import java.util.ArrayList;
  4 +import java.util.Collection;
4 5 import java.util.HashMap;
5 6 import java.util.Iterator;
6 7 import java.util.List;
... ... @@ -49,6 +50,11 @@ public class GpsRealDataBuffer {
49 50 */
50 51 private static Long lastUpdateTime;
51 52  
  53 + /**
  54 + * 10分钟没有信号则认为掉线
  55 + */
  56 + public final static long OFFLINE_TIME = 1000 * 60 * 10;
  57 +
52 58  
53 59 public boolean isNullEmpty(){
54 60 return deviceGpsMap == null;
... ... @@ -93,9 +99,15 @@ public class GpsRealDataBuffer {
93 99 * @throws
94 100 */
95 101 public void updateBuffer(Set<Integer> upLines, List<GpsRealData> upGpsList){
  102 + long t = System.currentTimeMillis();
96 103  
97 104 //更新GPS点
98 105 for(GpsRealData newGps : upGpsList){
  106 + if(t - newGps.getTimestamp() < OFFLINE_TIME){
  107 + logger.info("设备:" + newGps.getDeviceId() + " 上线");
  108 + newGps.setOnline(true);
  109 + }
  110 +
99 111 deviceGpsMap.put(newGps.getDeviceId(), newGps);
100 112 }
101 113  
... ... @@ -143,16 +155,25 @@ public class GpsRealDataBuffer {
143 155 gpsData.setStationName(CommonMapped.stationCodeMap.get(gpsData.getStopNo()));
144 156  
145 157 current = ScheduleBuffer.findCurrent(nbbm);
146   - if(null == current){
  158 +
  159 + if(null != current){
  160 + gpsData.setCurrSchId(current.getId());
  161 +
  162 + next = ScheduleBuffer.getNext(current);
  163 + if(next != null)
  164 + gpsData.setNextSchId(next.getId());
  165 +
  166 + }
  167 + /*if(null == current){
147 168 next = ScheduleBuffer.getFirst(nbbm);
148 169 }
149 170 else
150   - next = ScheduleBuffer.getNext(current);
  171 + next = ScheduleBuffer.getNext(current);*/
151 172  
152   - if(current != null)
  173 + /*if(current != null)
153 174 gpsData.setCurrSchId(current.getId());
154 175 if(next != null)
155   - gpsData.setNextSchId(next.getId());
  176 + gpsData.setNextSchId(next.getId());*/
156 177 //gpsData.setCurrSchId(ScheduleBuffer.findCurrent(nbbm));
157 178 /*subList = ScheduleBuffer.vehSchListMap.get(nbbm);
158 179 if(subList.size() == 0)
... ... @@ -206,4 +227,12 @@ public class GpsRealDataBuffer {
206 227 public Long getLastUpdateTime(){
207 228 return lastUpdateTime;
208 229 }
  230 +
  231 + public static Collection<GpsRealData> allGps(){
  232 + return lineGpsMultimap.values();
  233 + }
  234 +
  235 + public static GpsRealData findByDeviceId(String deviceId){
  236 + return deviceGpsMap.get(deviceId);
  237 + }
209 238 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/controller/GpsDataController.java
... ... @@ -9,7 +9,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
9 9 import org.springframework.web.bind.annotation.RequestParam;
10 10 import org.springframework.web.bind.annotation.RestController;
11 11  
  12 +import com.bsth.vehicle.gpsdata.buffer.ArrivalDataBuffer;
12 13 import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
  14 +import com.bsth.vehicle.gpsdata.entity.ArrivalInfo;
13 15 import com.bsth.vehicle.gpsdata.entity.GpsRealData;
14 16 import com.bsth.vehicle.gpsdata.service.GpsDataService;
15 17 import com.google.common.base.Splitter;
... ... @@ -55,4 +57,9 @@ public class GpsDataController {
55 57 ,@RequestParam Long et){
56 58 return gpsDataService.history(nbbmArray, st, et);
57 59 }
  60 +
  61 + @RequestMapping(value = "/arrival/ram")
  62 + public List<ArrivalInfo> ramData(@RequestParam String nbbm){
  63 + return ArrivalDataBuffer.allMap.get(nbbm);
  64 + }
58 65 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/entity/ArrivalInfo.java
1 1 package com.bsth.vehicle.gpsdata.entity;
2 2  
3   -import java.text.SimpleDateFormat;
4   -import java.util.Date;
5   -
6   -import javax.persistence.Transient;
  3 +import com.bsth.vehicle.common.CommonMapped;
7 4  
8 5 /**
9 6 *
... ... @@ -15,21 +12,10 @@ import javax.persistence.Transient;
15 12 */
16 13 public class ArrivalInfo {
17 14  
18   - @Transient
19   - static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss")
20   - ,sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
21   -
22   -
23 15 public ArrivalInfo(String deviceId, Long ts, String lineCode, Integer upDown, String stopNo, Integer inOut,
24   - Date createDate, Integer weeksYear) {
  16 + Long createDate, Integer weeksYear) {
25 17 this.deviceId = deviceId;
26 18  
27   - //gps是2014年的数据,临时将ts拉到今天
28   - /*try {
29   - this.ts = sdf2.parse("2016-07-25 " + sdf.format(new Date(ts))).getTime();
30   - } catch (ParseException e) {
31   - e.printStackTrace();
32   - }*/
33 19 this.ts = ts;
34 20  
35 21 this.lineCode = lineCode;
... ... @@ -38,10 +24,11 @@ public class ArrivalInfo {
38 24 this.inOut = inOut;
39 25 this.createDate = createDate;
40 26 this.weeksYear = weeksYear;
  27 + this.stopName = CommonMapped.stationCodeMap.get(this.stopNo);
41 28 }
42 29  
43 30 public ArrivalInfo(String deviceId, Long ts, String lineCode, Integer upDown, String stopNo, Integer inOut,
44   - Date createDate, Integer weeksYear, String stopName) {
  31 + Long createDate, Integer weeksYear, String stopName) {
45 32 this.deviceId = deviceId;
46 33  
47 34 this.ts = ts;
... ... @@ -60,6 +47,9 @@ public class ArrivalInfo {
60 47 */
61 48 private String deviceId;
62 49  
  50 + /** 站点名称 */
  51 + private String stopName;
  52 +
63 53 /**
64 54 * 时间戳
65 55 */
... ... @@ -81,16 +71,11 @@ public class ArrivalInfo {
81 71 private String stopNo;
82 72  
83 73 /**
84   - * 站点名称
85   - */
86   - private String stopName;
87   -
88   - /**
89 74 * 0: 进 1:出
90 75 */
91 76 private Integer inOut;
92 77  
93   - private Date createDate;
  78 + private Long createDate;
94 79  
95 80 /**
96 81 * 分区字段,当年的第几周
... ... @@ -129,11 +114,11 @@ public class ArrivalInfo {
129 114 this.inOut = inOut;
130 115 }
131 116  
132   - public Date getCreateDate() {
  117 + public Long getCreateDate() {
133 118 return createDate;
134 119 }
135 120  
136   - public void setCreateDate(Date createDate) {
  121 + public void setCreateDate(Long createDate) {
137 122 this.createDate = createDate;
138 123 }
139 124  
... ...
src/main/java/com/bsth/vehicle/gpsdata/entity/ArrivalLinkedList.java 0 → 100644
  1 +package com.bsth.vehicle.gpsdata.entity;
  2 +
  3 +/**
  4 + *
  5 + * @ClassName: ArrivalLinkedList
  6 + * @Description: TODO(班次到离站链)
  7 + * @author PanZhao
  8 + * @date 2016年7月28日 下午2:47:52
  9 + *
  10 + */
  11 +public class ArrivalLinkedList {
  12 +
  13 + /** 车辆内部编码 */
  14 + private String nbbm;
  15 +
  16 + /** 线路编码 */
  17 + private Integer lineCode;
  18 +
  19 + /** 起始站点编码 */
  20 + private String startStation;
  21 +
  22 + /** 起点发出时间 (毫秒时间戳) */
  23 + private Long startTime;
  24 +
  25 + /** 终点到达时间 (毫秒时间戳) */
  26 + private Long endTime;
  27 +
  28 + /** 终点站点编码 */
  29 + private String endStation;
  30 +}
... ...
src/main/java/com/bsth/vehicle/gpsdata/entity/GpsRealData.java
... ... @@ -57,6 +57,9 @@ public class GpsRealData {
57 57  
58 58 //下一个班次ID
59 59 private Long nextSchId;
  60 +
  61 + /** 设备是否在线 */
  62 + private boolean online;
60 63  
61 64 public Integer getCompanyCode() {
62 65 return companyCode;
... ... @@ -185,4 +188,12 @@ public class GpsRealData {
185 188 public void setStationName(String stationName) {
186 189 this.stationName = stationName;
187 190 }
  191 +
  192 + public boolean isOnline() {
  193 + return online;
  194 + }
  195 +
  196 + public void setOnline(boolean online) {
  197 + this.online = online;
  198 + }
188 199 }
... ...
src/main/java/com/bsth/vehicle/gpsdata/service/GpsDataServiceImpl.java
... ... @@ -40,7 +40,7 @@ public class GpsDataServiceImpl implements GpsDataService{
40 40 @Override
41 41 public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) {
42 42 Calendar sCal = Calendar.getInstance();
43   - sCal.setTime(new Date(/*startTime*/));
  43 + sCal.setTime(new Date(startTime));
44 44  
45 45 Calendar eCal = Calendar.getInstance();
46 46 eCal.setTime(new Date(endTime));
... ... @@ -244,7 +244,6 @@ public class GpsDataServiceImpl implements GpsDataService{
244 244 return list;
245 245 }
246 246  
247   - //weekOfYear 算错了
248 247 public Map<String, ArrivalInfo> findArrivalByTs(int weekOfYear, Long st, Long et, String devicesInSql){
249 248 Map<String, ArrivalInfo> map = new HashMap<>();
250 249  
... ... @@ -261,7 +260,7 @@ public class GpsDataServiceImpl implements GpsDataService{
261 260 int inOut;
262 261 while (rs.next()) {
263 262 arr = new ArrivalInfo(rs.getString("DEVICE_ID"), rs.getLong("TS"), rs.getString("LINE_ID"), rs.getInt("UP_DOWN")
264   - , rs.getString("STOP_NO"), rs.getInt("IN_OUT"), rs.getDate("CREATE_DATE") , rs.getInt("WEEKS_YEAR")
  263 + , rs.getString("STOP_NO"), rs.getInt("IN_OUT"), rs.getLong("CREATE_DATE") , rs.getInt("WEEKS_YEAR")
265 264 , CommonMapped.stationCodeMap.get(rs.getString("STOP_NO")));
266 265  
267 266 //设备号_时间戳_进出状态 为key
... ... @@ -276,10 +275,4 @@ public class GpsDataServiceImpl implements GpsDataService{
276 275 }
277 276 return map;
278 277 }
279   -
280   - public static void main(String[] args) {
281   - Calendar weekCal = Calendar.getInstance();
282   - weekCal.setTime(new Date());
283   - System.out.println(weekCal.get(Calendar.WEEK_OF_YEAR));
284   - }
285 278 }
... ...
src/main/resources/static/assets/img/load_slow.gif 0 → 100644

3.42 KB

src/main/resources/static/gpsTest/test.html
... ... @@ -156,7 +156,7 @@ form .item select{
156 156  
157 157 //查询gps点
158 158 $.get('/gps/history/' + params.device, params, function(gpsArray){
159   - console.log(gpsArray);
  159 + console.log(stationCodeMap);
160 160 var marker, label, point, state, text;
161 161 $.each(gpsArray, function(){
162 162 point = new BMap.Point(this.lon, this.lat);
... ... @@ -165,12 +165,20 @@ form .item select{
165 165  
166 166 if(state == 0 || state == 1){
167 167 text = state == 0?'出':'进';
  168 +
  169 + console.log(stationCodeMap[this.stopNo], this);
168 170 marker.setIcon(new BMap.Icon(inOuts[this.inout_stop], new BMap.Size(25,25)));
169 171 label = new BMap.Label(
170   - stationCodeMap[this.stopNo] + '/' +moment(this.ts).format('HH:mm') + ' -'+text
  172 + stationCodeMap[this.stopNo] + '/' +moment(this.ts).format('HH:mm.ss') + ' -'+text
171 173 , {position: point, offset: new BMap.Size(-25,-18)});
172 174 marker.setLabel(label);
173 175 }
  176 + else{
  177 + label = new BMap.Label(moment(this.ts).format('HH:mm.ss')
  178 + , {position: point, offset: new BMap.Size(-25,-18)});
  179 + marker.setLabel(label);
  180 + }
  181 +
174 182 map.addOverlay(marker);
175 183 });
176 184 });
... ...
src/main/resources/static/index.html
... ... @@ -423,6 +423,7 @@ $(function(){
423 423 function activeLeftMenu(item){
424 424 $(item).parent('.nav-item').addClass('active').parent('.sub-menu').show().parent().addClass('open');
425 425 }
  426 +
426 427 </script>
427 428 </body>
428 429 </html>
429 430 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/child_pages/historyMessage.html 0 → 100644
  1 +<div id="historyMessagePanel" style="margin: 17px 5px 5px;">
  2 +
  3 + <form class="form-inline" >
  4 + <div class="form-group" style="margin: 18px;">
  5 + <label class="" for="directiveSelect">指令类型:</label>
  6 + <select class="form-control" id="directiveSelect" name="dType">
  7 + <option value="-1">全部</option>
  8 + <option value="0">调度指令</option>
  9 + <option value="1">运营指令</option>
  10 + <option value="2">线路切换指令</option>
  11 + <option value="3">消息短语</option>
  12 + </select>
  13 + </div>
  14 +
  15 + <div class="form-group" >
  16 + <label class="" for="carSelect">车辆:</label>
  17 + <select class="form-control" name="nbbm" id="carSelect" style="width: 170px;"></select>
  18 + </div>
  19 + </form>
  20 +
  21 + <div class="table-scrollable">
  22 + <table class="table table-hover" style="table-layout: fixed;">
  23 + <thead>
  24 + <tr>
  25 + <th width="9%">车辆</th>
  26 + <th width="9%">时间</th>
  27 + <th width="45%">内容</th>
  28 + <th width="8%">发送人</th>
  29 + <th width="15%">状态</th>
  30 + </tr>
  31 + </thead>
  32 + <tbody>
  33 + <tr>
  34 + <td>B-84256</td>
  35 + <td>11:32</td>
  36 + <td>
  37 + <div class="text-furl">已完成6个班次,下一发车时间19点05分,由兰坪路浦江路发往江南旅游服务有限公司浦西停车保养场</div>
  38 + </td>
  39 + <td>系统</td>
  40 + <td><span class="label label-sm label-success">
  41 + 设备收到,驾驶员确认 </span></td>
  42 + </tr>
  43 + <tr>
  44 + <td>B-84256</td>
  45 + <td>11:32</td>
  46 + <td>
  47 + <div class="text-furl">已完成6个班次,下一发车时间19点05分,由兰坪路浦江路发往江南旅游服务有限公司浦西停车保养场</div>
  48 + </td>
  49 + <td>系统</td>
  50 + <td><span class="label label-sm label-success">
  51 + 设备收到,驾驶员确认 </span></td>
  52 + </tr>
  53 + <tr>
  54 + <td>B-84256</td>
  55 + <td>11:32</td>
  56 + <td>
  57 + <div class="text-furl">已完成6个班次,下一发车时间19点05分,由兰坪路浦江路发往江南旅游服务有限公司浦西停车保养场</div>
  58 + </td>
  59 + <td>系统</td>
  60 + <td><span class="label label-sm label-warning">
  61 + 设备未响应 </span></td>
  62 + </tr>
  63 + <tr>
  64 + <td>B-84256</td>
  65 + <td>11:32</td>
  66 + <td>
  67 + <div class="text-furl">已完成6个班次,下一发车时间19点05分,由兰坪路浦江路发往江南旅游服务有限公司浦西停车保养场</div>
  68 + </td>
  69 + <td>系统</td>
  70 + <td><span class="label label-sm label-danger">
  71 + 网关通讯失败 </span> <i class="fa fa-link"></i></td>
  72 + </tr>
  73 + <tr>
  74 + <td>B-84256</td>
  75 + <td>11:32</td>
  76 + <td>
  77 + <div class="text-furl">运营指令 - 上行营运</div>
  78 + </td>
  79 + <td>系统</td>
  80 + <td><span class="label label-sm label-success">
  81 + 切换成功 </span></td>
  82 + </tr>
  83 +
  84 + <tr>
  85 + <td>B-84256</td>
  86 + <td>11:32</td>
  87 + <td>
  88 + <div class="text-furl">线路切换 - 778 路</div>
  89 + </td>
  90 + <td>系统</td>
  91 + <td><span class="label label-sm label-success">
  92 + 切换成功 </span></td>
  93 + </tr>
  94 + </tbody>
  95 + </table>
  96 + </div>
  97 +</div>
  98 +
  99 +<script>
  100 +!function(){
  101 + var $car = $('#historyMessagePanel #carSelect')
  102 + ,$dType = $('#historyMessagePanel #directiveSelect');
  103 + createVehSearch($car);
  104 +}();
  105 +</script>
0 106 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/css/lineControl.css
... ... @@ -1206,7 +1206,7 @@ height: 400px;
1206 1206 position: absolute;
1207 1207 right: 4px;
1208 1208 bottom: 4px;
1209   - color: #a6a6a6;
  1209 + color: #757474;
1210 1210 }
1211 1211  
1212 1212 .log-item-point{
... ... @@ -1231,7 +1231,8 @@ height: 400px;
1231 1231 }
1232 1232  
1233 1233 .log-item.handle{
1234   - height: 72px;
  1234 + height: 92px;
  1235 + background: #fdfdfd;
1235 1236 }
1236 1237  
1237 1238 .log-item-handle{
... ... @@ -1241,10 +1242,28 @@ height: 400px;
1241 1242 }
1242 1243  
1243 1244 .log-item-handle .btn-sm{
1244   - padding: 3px 7px;
  1245 + padding: 1px 5px;
1245 1246 margin-right: 3px;
1246 1247 }
1247 1248  
  1249 +.log-item-handle .dissent,
  1250 +.log-item-handle .msg-to-map{
  1251 + font-size: 12px;
  1252 + vertical-align: bottom;
  1253 + text-decoration: underline;
  1254 + color: #828282 !important;
  1255 +}
  1256 +
  1257 +.log-item-runing{
  1258 + position: absolute;
  1259 + bottom: 7px;
  1260 + left: 7px;
  1261 + width: 100%;
  1262 + height: 25px;
  1263 + background: #fdfdfd;
  1264 + display: none;
  1265 +}
  1266 +
1248 1267 .log-item.handle .log-item-point{
1249 1268 top: 8px;
1250 1269 }
... ... @@ -2324,4 +2343,18 @@ tr._tr_active.active-line-no .out-badge{
2324 2343 #tab_home .tab-pane .row.card_wrap:last-child .col-lg-2 {
2325 2344 border-bottom: 1px solid #DADADA;
2326 2345 border-bottom: 1px solid #DADADA;
  2346 +}
  2347 +
  2348 +.text-furl{
  2349 + width: 100%;
  2350 + display: block;
  2351 + white-space: nowrap;
  2352 + overflow: hidden;
  2353 + text-overflow: ellipsis;
  2354 +}
  2355 +
  2356 +#historyMessagePanel table .fa-link{
  2357 + margin-left: 5px;
  2358 + vertical-align: bottom;
  2359 + cursor: pointer;
2327 2360 }
2328 2361 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/index.html
... ... @@ -18,10 +18,11 @@
18 18 </div>
19 19 <div class="actions col_hide_1280" >
20 20 <div class="btn-group">
21   - <button type="button" class="btn btn-default" disabled>
22   - <i class="fa fa-calendar-check-o"></i> 计划排班</button>
23   - <button type="button" class="btn btn-default" disabled>
24   - <i class="fa fa-history"></i> 轨迹回放</button>
  21 + <button type="button" class="btn btn-default" id="deviceReport">
  22 + <i class="fa fa-code-fork"></i> 设备上报</button>
  23 +
  24 + <button type="button" class="btn btn-default" id="msgAndDirect">
  25 + <i class="fa fa-bell"></i> 调度指令</button>
25 26  
26 27 <div class="btn-group">
27 28 <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" disabled>
... ... @@ -181,7 +182,7 @@
181 182 <menu class="menu" id="homeMenu" style="display: none;">
182 183 <li class="menu-item disabled" id="menu-linename">
183 184 <button type="button" class="menu-btn">
184   - <span class="menu-text">--- W2B-102 ---</span>
  185 + <span class="menu-text">--- <span class="menu-title-nbbm"></span> ---</span>
185 186 </button>
186 187 </li>
187 188 <li class="menu-item" >
... ... @@ -227,8 +228,9 @@
227 228 <script src="/pages/control/line/js/homeMenu.js"></script>
228 229 <script src="/pages/control/line/js/alone.js"></script>
229 230 <script src="/pages/control/line/js/main.js"></script>
230   -<script src="/pages/control/line/js/console.js"></script>
  231 +<script src="/pages/control/line/js/messenger.js"></script>
231 232 <script src="/pages/control/line/js/keyboardListen.js"></script>
  233 +<script src="/pages/control/line/js/toolbarEvent.js"></script>
232 234 <script>
233 235  
234 236 var lineCodes = '' //全部线路编码字符串,由data.js初始化
... ... @@ -252,6 +254,13 @@ $.get(&#39;/user/currentUser&#39;, function(user){
252 254 //打个标记
253 255 storage.setItem('real_control_flag', 1);
254 256  
  257 +var reqCodeMap = {0xA1: '请求恢复运营', 0xA2: '申请调档', 0xA3: '出场请求', 0xA5: '进场请求', 0xA7: '加油请求', 0x50: '车辆故障', 0x70: '路阻报告', 0x60: '事故报告', 0x11: '扣证纠纷', 0x12 : '报警'};
  258 +
  259 +function _fadeOut($that){
  260 + $that.fadeOut('normal', function(){
  261 + $that.remove();
  262 + });
  263 +}
255 264 $(function() {
256 265 //主调和监控模式横幅颜色
257 266 if(operationMode == 0)
... ... @@ -264,7 +273,7 @@ $(function() {
264 273 getTemp('temps/tooltip_tp.html');
265 274 getTemp('temps/alone_tp.html');
266 275 getTemp('temps/child_task_case_tp.html');
267   - getTemp('temps/console.html');
  276 + getTemp('temps/messenger.html');
268 277  
269 278 function getTemp(url){
270 279 $.get(url, function(template){
... ... @@ -272,5 +281,14 @@ $(function() {
272 281 });
273 282 }
274 283 });
  284 +
  285 +//监控模式下拦截POST请求
  286 +function interceptPOST(e, xhr, t){
  287 + if(t && (t.method == 'POST' || t.type == 'POST')){
  288 + console.log(e, xhr, t);
  289 + xhr.abort();
  290 + layer.msg('监控模式!',{offset: 'ct', shift : 6});
  291 + }
  292 +}
275 293 </script>
276 294 <script src="/pages/control/line/js/webSocketHandle.js"></script>
277 295 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/js/alone.js
... ... @@ -37,13 +37,6 @@ var _alone = (function(){
37 37 }
38 38 //初始化备注弹层
39 39 initRemarksPop();
40   - //初始化信使
41   - initMessenger(lineCodes);
42   -
43   - //消息框滚动条
44   - $('.console-log .log-item-list').slimscroll({
45   - height: '100%'
46   - });
47 40  
48 41 cb && cb();
49 42 });
... ... @@ -151,13 +144,19 @@ var _alone = (function(){
151 144  
152 145 //定位到班次所在的行
153 146 function goToSch(sch){
154   - var table = getTableBySch(sch)
  147 + var table = getTableBySch(sch);
  148 + //如果table不可见
  149 + if(!table.is(":visible"))
  150 + return;
  151 +
  152 + var currTr = table.find('tr[data-id='+sch.id+']')
155 153 ,half = table.parents('._body').height() / 2
156   - ,currTr = table.find('tr[data-id='+sch.id+']')
157 154 ,top = parseInt(currTr.find('td[name=lineNo]').text()) * 37 - half;
158 155  
159 156 top = top>0?top:0;
160   - currTr.addClass('anim-delay animated flash');
  157 + currTr.addClass('anim-delay animated flash').one(animationend, function(){
  158 + $(this).removeClass('anim-delay animated flash');
  159 + });
161 160 currTr.parents('._body').slimScroll({ scrollTo: top + 'px' });
162 161 }
163 162  
... ... @@ -190,60 +189,6 @@ var _alone = (function(){
190 189 return rs;
191 190 }
192 191  
193   - //切换托管状态
194   - function changeTGStatus(){
195   - var status = $(this).data('status');
196   - if(status == 0)
197   - status = 1;
198   - else
199   - status = 0;
200   -
201   - $(this).data('status', status);
202   -
203   - var lineCode = $(this).data('linecode');
204   -
205   - $.post('/realSchedule/trustStatus/change', {lineCode: lineCode, status: status}
206   - ,function(rs){
207   - if(rs == 200){
208   - layer.msg('切换成功!');
209   - changeTgHtml(lineCode, status);
210   - }
211   - });
212   - }
213   -
214   - $('.portlet-fullscreen').on('click', '.tg_tools', changeTGStatus);
215   - var tgHtml = ['托管状态,计算机自动处理&nbsp;<i class="fa fa-question-circle tgQuestion" style="cursor: pointer;"></i>', '非托管状态,手动处理!'];
216   - var tgPopoverOps = {content: template('tg_question_info_temp', {}),html: true,placement: 'left',trigger: 'hover',container: '.portlet-fullscreen'};
217   - function initMessenger(lineCodes){
218   - //查询线路托管状态
219   - $.get('/realSchedule/trustStatus', {lineCodes: lineCodes},function(rs){
220   - for(var line in rs)
221   - changeTgHtml(line, rs[line]);
222   - });
223   - }
224   -
225   - function changeTgHtml(line, status){
226   - var tgTools = $('#tgTools_' + line);
227   -
228   - tgTools.html(tgHtml[status]).data('status', status);
229   - var array = $('#top-tabs-wrap a[data-id='+line+'] span zz');
230   -
231   - if(status == 0){
232   - //托管Question
233   - $('.tgQuestion', tgTools).popover(tgPopoverOps);
234   - tgTools.removeClass('hand');
235   -
236   - $(array[2]).text('托管');
237   - }
238   - else{
239   - tgTools.addClass('hand');
240   - $(array[2]).text('');
241   - }
242   -
243   - //tab 头改变
244   -
245   - }
246   -
247 192 function initRemarksPop(){
248 193 //备注POPOVER
249 194 $('.remarks-popover', '.pb-table').popover({trigger: 'hover',container: '.portlet-fullscreen',placement:'bottom'});
... ...
src/main/resources/static/pages/control/line/js/console.js deleted 100644 → 0
1   -/** 信使操作 */
2   -
3   -$('.portlet-fullscreen').on('click', '.log-item-handle a.log-close', function(){
4   - $(this).parents('.log-item').remove();
5   -});
6 0 \ No newline at end of file
src/main/resources/static/pages/control/line/js/homeMenu.js
1 1 var _home_menu = (function(){
2 2  
  3 + var gbNbbm;
  4 +
3 5 $('#homeMenu .menu-item button').on('click', function(){
4 6 var method = $(this).data('method');
5 7 if(!method)return;
6   - var nbbm = $('.vehicDataTable tr._home_tr_active').data('nbbm');
  8 + /*var nbbm = $('.vehicDataTable tr._home_tr_active').data('nbbm');
7 9  
8 10 if(!nbbm){
9 11 layer.alert('无法获取车辆自编号,请尝试刷新页面!', {icon: 2, title: '异常'});
10 12 return;
  13 + }*/
  14 + if(!gbNbbm){
  15 + layer.alert('无法获取车辆自编号,请尝试刷新页面!', {icon: 2, title: '异常'});
  16 + return;
11 17 }
12   - menuObject[method](nbbm);
  18 + menuObject[method](gbNbbm);
13 19 });
14 20  
15 21 //右键事件
16 22 $('.portlet-fullscreen').on('contextmenu', '.vehicDataTable tr td', function(e){
17 23 e.preventDefault();
18 24 $('.vehicDataTable tr._home_tr_active').removeClass('_home_tr_active');
19   - $(this).parent().addClass('_home_tr_active');
  25 +
  26 + var $tr = $(this).parent().addClass('_home_tr_active')
  27 + ,nbbm = $tr.data('nbbm');
  28 +
  29 + $('#homeMenu .menu-title-nbbm').text(nbbm);
  30 + gbNbbm = nbbm;
  31 +
20 32 showMenu(e.pageX, e.pageY + 3);
21 33 $(document).one('click', function() {
22 34 $('#homeMenu').removeClass('show-menu');
... ... @@ -47,7 +59,7 @@ var _home_menu = (function(){
47 59 var menuObject = {
48 60 //发送消息短语
49 61 sendPhrase: function(nbbm){
50   - layer.prompt({title: '请输入短语信息', formType: 2 , shift: 5
  62 + layer.prompt({title: '向 '+nbbm+' 发送短语信息', formType: 2 , shift: 5
51 63 }, function(space){
52 64 $.post('/directive/phrase', {nbbm: nbbm, text: space}, function(rs){
53 65 if(rs == 0)
... ...
src/main/resources/static/pages/control/line/js/main.js
1 1 !function(){
2   -
3   - $('#exitBtn').on('click', function(){
4   - layer.confirm('确定要退出系统?', {
5   - btn : [ '退出', '取消' ],
6   - icon : 3,
7   - skin : 'layui-layer-cfm-delete'
8   - }, function(){
9   - //清除标记
10   - storage.removeItem('real_control_flag');
11   - //解绑事件
12   - $(document).unbind('ajaxSend', interceptPOST);
13   - layer.closeAll();
14   - window.location.href = '/pages/control/lineallot/allot.html';
15   - });
16   - });
17   -
18 2 var gpsOff = 1000 * 60 * 5;
19 3  
20 4 var homeObject = {
... ... @@ -110,6 +94,8 @@ setTimeout(function(){
110 94  
111 95 //初始化单线路调度页面
112 96 _alone.init(function(){
  97 + //初始化信使
  98 + _messenger.init();
113 99 //初始化主页
114 100 homeObject.init();
115 101 });
... ... @@ -118,15 +104,7 @@ setTimeout(function(){
118 104 if(operationMode == 0){
119 105 $(document).on('ajaxSend', interceptPOST);
120 106 }
121   -}, 200)
122   -
123   - function interceptPOST(e, xhr, t){
124   - if(t && (t.method == 'POST' || t.type == 'POST')){
125   - console.log(e, xhr, t);
126   - xhr.abort();
127   - layer.msg('监控模式!',{offset: 'ct', shift : 6});
128   - }
129   - }
  107 +}, 300)
130 108  
131 109 function gpslistToMap(gpslist){
132 110 var map = {}
... ...
src/main/resources/static/pages/control/line/js/messenger.js 0 → 100644
  1 +var _messenger = (function(){
  2 +
  3 + //线路托管状态
  4 + var tgStateMap;
  5 +
  6 + //定时将托管状态下的信使清理掉(不包含80)
  7 + !function(){
  8 + var f = arguments.callee
  9 + ,ct = Date.parse(new Date()) / 1000
  10 + ,list, time;
  11 +
  12 + for(var code in tgStateMap){
  13 + if(tgStateMap[code] == 1)
  14 + continue;
  15 +
  16 + list = $('#messengerList' + code).find('.log-item.fache,.log-item.zhongdian');
  17 + $.each(list, function(){
  18 + time = parseInt($(this).data('time'));
  19 + if(ct - time >= 30)
  20 + _fadeOut($(this));
  21 + });
  22 + }
  23 +
  24 + setTimeout(f, 3000);
  25 + }();
  26 +
  27 +
  28 + /** 信使操作 */
  29 + $('.portlet-fullscreen').on('click', '.log-item-handle a.log-close', function(){
  30 + _fadeOut($(this).parents('.log-item'));
  31 + });
  32 +
  33 + //80上报事件处理
  34 + //同意
  35 + $('.portlet-fullscreen').on('click','.log-item-handle .confirm', function(){
  36 + send80Reply(this, 0);
  37 + });
  38 +
  39 + //不同意
  40 + $('.portlet-fullscreen').on('click','.log-item-handle .dissent', function(){
  41 + send80Reply(this, -1);
  42 + });
  43 +
  44 + function send80Reply(that, reply){
  45 + var $handle = $(that).parents('.log-item.handle');
  46 + var id = $handle.data('id');
  47 + var $run = $handle.find('.log-item-runing');
  48 + $run.show();
  49 +
  50 + $.post('/directive/reply80', {id: id, reply: reply}, function(rs){
  51 + if(rs.status == 'ERROR')
  52 + $run.hide();
  53 +
  54 + if(rs.msg)
  55 + layer.alert(rs.msg, {icon: 0});
  56 + });
  57 + }
  58 +
  59 +
  60 + var messengerObj = {
  61 + init: function(){
  62 + //初始化信使和驾驶员上报数据
  63 + initMessenger(lineCodes);
  64 + $.get('/directive/findNoCofm80', {lineCodes: lineCodes}
  65 + , function(rs){
  66 + //填充未确认的80数据
  67 + console.log(rs);
  68 + for(var lineCode in rs){
  69 + $.each(rs[lineCode], function(){
  70 + this.dateStr = moment(this.timestamp).format('HH:mm.ss');
  71 + this.text = reqCodeMap[this.data.requestCode];
  72 + });
  73 +
  74 + rs[lineCode].sort(function(a, b){
  75 + return b.timestamp - a.timestamp;
  76 + });
  77 +
  78 + var htmlStr = template('console_80_temp', {list: rs[lineCode]});
  79 + $('#messengerList' + lineCode).html(htmlStr);
  80 + }
  81 + });
  82 +
  83 + //消息框滚动条
  84 + $('.console-log .log-item-list').slimscroll({
  85 + height: '100%'
  86 + });
  87 + }
  88 + }
  89 +
  90 +
  91 + $('.portlet-fullscreen').on('click', '.tg_tools', changeTGStatus);
  92 + var tgHtml = ['托管状态,计算机自动处理&nbsp;<i class="fa fa-question-circle tgQuestion" style="cursor: pointer;"></i>', '非托管状态,手动处理!'];
  93 +
  94 + var tgDescHtml = '<table class="tg-question-table"> '+
  95 + ' <tr>'+
  96 + ' <td>出场请求</td>'+
  97 + ' <td class="font-blue">同意(切换营运状态)</td>'+
  98 + ' </tr>'+
  99 + ' <tr>'+
  100 + ' <td>恢复运营</td>'+
  101 + ' <td>不处理</td>'+
  102 + ' </tr>'+
  103 + ' <tr>'+
  104 + ' <td>申请调档</td>'+
  105 + ' <td>不处理</td>'+
  106 + ' </tr>'+
  107 + ' <tr>'+
  108 + ' <td>进场请求</td>'+
  109 + ' <td>不处理</td>'+
  110 + ' </tr>'+
  111 + ' <tr>'+
  112 + ' <td>加油请求</td>'+
  113 + ' <td>不处理</td>'+
  114 + ' </tr>'+
  115 + ' <tr>'+
  116 + ' <td>车辆故障</td>'+
  117 + ' <td>不处理</td>'+
  118 + ' </tr>'+
  119 + ' <tr>'+
  120 + ' <td>路阻报告</td>'+
  121 + ' <td>不处理</td>'+
  122 + ' </tr>'+
  123 + ' <tr>'+
  124 + ' <td>事故报告</td>'+
  125 + ' <td>不处理</td>'+
  126 + ' </tr>'+
  127 + ' <tr>'+
  128 + ' <td>扣证纠纷 </td>'+
  129 + ' <td>不处理</td>'+
  130 + ' </tr>'+
  131 + ' <tr>'+
  132 + ' <td>报警</td>'+
  133 + ' <td>不处理</td>'+
  134 + ' </tr>'+
  135 + ' </table>';
  136 + var tgPopoverOps = {content: tgDescHtml,html: true,placement: 'left',trigger: 'hover',container: '.portlet-fullscreen'};
  137 + function initMessenger(lineCodes){
  138 + //查询线路托管状态
  139 + $.get('/realSchedule/trustStatus', {lineCodes: lineCodes},function(rs){
  140 + tgStateMap = rs;
  141 + for(var line in rs)
  142 + changeTgHtml(line, rs[line]);
  143 + });
  144 + }
  145 +
  146 + function changeTgHtml(line, status){
  147 + var tgTools = $('#tgTools_' + line);
  148 +
  149 + tgTools.html(tgHtml[status]).data('status', status);
  150 + var array = $('#top-tabs-wrap a[data-id='+line+'] span zz');
  151 +
  152 + if(status == 0){
  153 + //托管Question
  154 + $('.tgQuestion', tgTools).popover(tgPopoverOps);
  155 + tgTools.removeClass('hand');
  156 +
  157 + $(array[2]).text('托管');
  158 + }
  159 + else{
  160 + tgTools.addClass('hand');
  161 + $(array[2]).text('');
  162 + }
  163 +
  164 + //tab 头改变
  165 +
  166 + }
  167 +
  168 + //切换托管状态
  169 + var runing;
  170 + function changeTGStatus(){
  171 + if(runing)
  172 + return;
  173 + runing = true;
  174 +
  175 + var status = $(this).data('status');
  176 + if(status == 0)
  177 + status = 1;
  178 + else
  179 + status = 0;
  180 +
  181 + $(this).data('status', status);
  182 +
  183 + var lineCode = $(this).data('linecode');
  184 +
  185 + $.post('/realSchedule/trustStatus/change', {lineCode: lineCode, status: status}
  186 + ,function(rs){
  187 + if(rs == 200){
  188 + tgStateMap[lineCode] = status;
  189 + layer.msg('切换成功!');
  190 + changeTgHtml(lineCode, status);
  191 + runing = false;
  192 +
  193 + //console.log(tgStateMap);
  194 + }
  195 + });
  196 + }
  197 +
  198 + return messengerObj;
  199 +})();
  200 +
  201 +
... ...
src/main/resources/static/pages/control/line/js/toolbarEvent.js 0 → 100644
  1 +!function(){
  2 + $('#exitBtn').on('click', function(){
  3 + layer.confirm('确定要退出系统?', {
  4 + btn : [ '退出', '取消' ],
  5 + icon : 3,
  6 + skin : 'layui-layer-cfm-delete'
  7 + }, function(){
  8 + //清除标记
  9 + storage.removeItem('real_control_flag');
  10 + //解绑事件
  11 + $(document).unbind('ajaxSend', interceptPOST);
  12 + layer.closeAll();
  13 + window.location.href = '/pages/control/lineallot/allot.html';
  14 + });
  15 + });
  16 + //调度指令
  17 + $('#msgAndDirect').on('click', function(){
  18 + layer.msg('功能测试中...稍后开放!');
  19 + /*$.get('/pages/control/line/child_pages/historyMessage.html', function(content){
  20 + layer.open({
  21 + type: 1,
  22 + area: '930px',
  23 + content: content,
  24 + title : false,
  25 + success: function(){
  26 + }
  27 + });
  28 + });*/
  29 + });
  30 +
  31 + //设备上报
  32 + $('#deviceReport').on('click', function(){
  33 + layer.msg('功能测试中...稍后开放!');
  34 + });
  35 +}();
0 36 \ No newline at end of file
... ...
src/main/resources/static/pages/control/line/js/webSocketHandle.js
1 1 /** web socket */
2 2 !function(){
3   -var reqCodeMap = {0xA1: '请求恢复运营', 0xA2: '申请调档', 0xA3: '出场请求', 0xA5: '进场请求', 0xA7: '加油请求', 0x50: '车辆故障', 0x70: '路阻报告', 0x60: '事故报告', 0x11: '扣证纠纷', 0x12 : '报警'};
4   -
5 3  
6 4 //将当前用户和线路绑定到后台
7 5 setTimeout(function(){
... ... @@ -31,20 +29,32 @@ var initWebSocket = function(){
31 29 console.log(e);
32 30 }
33 31 };
  32 +
  33 + //断开
  34 + msgSock.onclose = function(e) {
  35 + alert('和服务器连接断开....');
  36 + window.location.reload(true);
  37 + };
34 38 };
35 39  
36 40 var msgHandle = {
37   - //驾驶员80上报处理
  41 + //驾驶员80
38 42 report80: function(msg){
39   - msg.dateStr = moment(msg.timestamp).format('HH:mm');
  43 + msg.dateStr = moment(msg.timestamp).format('HH:mm.ss');
40 44 msg.text = reqCodeMap[msg.data.requestCode];
41 45  
42   - appendLogItem('console_80_temp', msg, msg.data.lineId);
  46 + console.log(msg);
  47 + appendLogItem('console_80_temp', {list: [msg]}, msg.data.lineId);
  48 + },
  49 + //驾驶员80被处理
  50 + d80Confirm: function(msg){
  51 + _fadeOut($('.log-item.handle[data-id='+msg.id+']'));
43 52 },
44 53 //车辆发出
45 54 faChe: function(msg){
46 55 //刷新数据
47 56 _alone.refreshSchedule(msg.t);
  57 + msg.jsTime = Date.parse(new Date()) / 1000;
48 58 //信使
49 59 appendLogItem('console_fache_temp', msg, msg.t.xlBm);
50 60 },
... ... @@ -53,6 +63,7 @@ var msgHandle = {
53 63 //刷新数据
54 64 _alone.refreshSchedule(msg.t);
55 65 _alone.refreshSchedule(msg.nt);
  66 + msg.jsTime = Date.parse(new Date()) / 1000;
56 67 //信使
57 68 appendLogItem('console_zhongdian_temp', msg, msg.t.xlBm);
58 69 },
... ... @@ -82,6 +93,13 @@ var msgHandle = {
82 93 break;
83 94 }
84 95 $tr.find('td[data-name=clZbh]').attr('class', clazz);
  96 + },
  97 + refresh: function(msg){
  98 + //刷新
  99 + layer.msg('正在切换到 ' + msg.dateStr + '数据', {icon: 16, shade: 0.6, time: 0});
  100 + setTimeout(function(){
  101 + window.location.reload(true);
  102 + }, 1000);
85 103 }
86 104 };
87 105  
... ...
src/main/resources/static/pages/control/line/temps/alone_tp.html
... ... @@ -87,7 +87,7 @@
87 87 <div class="col-md-2 panel-wrap" >
88 88 <div class="_panel">
89 89 <div class="console-log">
90   - <div class="log-item-list">
  90 + <div class="log-item-list" id="messengerList{{lineCode}}">
91 91 </div>
92 92 </div>
93 93 <div class="_panel_footer tg_tools" id="tgTools_{{lineCode}}" data-linecode="{{lineCode}}">
... ... @@ -180,48 +180,7 @@
180 180  
181 181 <!-- 托管状态描述 -->
182 182 <script id="tg_question_info_temp" type="text/html">
183   -<table class="tg-question-table">
184   - <tr>
185   - <td>出场请求</td>
186   - <td class="font-blue">同意(切换营运状态)</td>
187   - </tr>
188   - <tr>
189   - <td>恢复运营</td>
190   - <td>不处理</td>
191   - </tr>
192   - <tr>
193   - <td>申请调档</td>
194   - <td>不处理</td>
195   - </tr>
196   - <tr>
197   - <td>进场请求</td>
198   - <td>不处理</td>
199   - </tr>
200   - <tr>
201   - <td>加油请求</td>
202   - <td>不处理</td>
203   - </tr>
204   - <tr>
205   - <td>车辆故障</td>
206   - <td>不处理</td>
207   - </tr>
208   - <tr>
209   - <td>路阻报告</td>
210   - <td>不处理</td>
211   - </tr>
212   - <tr>
213   - <td>事故报告</td>
214   - <td>不处理</td>
215   - </tr>
216   - <tr>
217   - <td>扣证纠纷 </td>
218   - <td>不处理</td>
219   - </tr>
220   - <tr>
221   - <td>报警</td>
222   - <td>不处理</td>
223   - </tr>
224   -</table>
  183 +
225 184 </script>
226 185  
227 186 <!-- 待发调整 -->
... ...
src/main/resources/static/pages/control/line/temps/console.html renamed to src/main/resources/static/pages/control/line/temps/messenger.html
... ... @@ -3,35 +3,39 @@
3 3  
4 4 <!-- 80协议上报 -->
5 5 <script id="console_80_temp" type="text/html">
6   -<div class="log-item handle">
7   - <span class="log-item-text">{{data.nbbm}} {{text}}</span>
8   - <span class="log-item-time">{{dateStr}}</span>
  6 +{{each list as item i}}
  7 +<div class="log-item handle" data-id={{item.id}}>
  8 + <span style="margin: 0px 0 7px;display: block;">{{item.dateStr}}</span>
  9 + <span class="log-item-text">{{item.data.nbbm}} {{item.text}} </span>
9 10 <span class="log-item-handle">
10   - <!--<button type="button" class="btn blue btn-sm">同意</button>
11   - <button type="button" class="btn red btn-sm">不同意</button>-->
  11 + <button type="button" class="btn blue btn-sm confirm">同意</button>
  12 + <a href="javascript:;" class="dissent">不同意</a>
  13 + <!--<a href="javascript:;" class="msg-to-map">地图查看</a>-->
12 14 </span>
  15 + <span class="log-item-runing"><img src="/assets/img/load_slow.gif"> </span>
13 16 </div>
  17 +{{/each}}
14 18 </script>
15 19  
16   -<script id="console_fache_temp" type="text/html">
17   -<div class="log-item fache">
  20 +<script id="console_fache_temp" type="text/html" >
  21 +<div class="log-item fache" data-time={{jsTime}}>
18 22 <span class="log-item-text">{{t.fcsjActual}} {{t.clZbh}} 已由 {{t.qdzName}} 发出</span>
19 23 <span class="log-item-text">执行班次 {{t.fcsj}}</span>
20 24 <span class="log-item-time">{{dataStr}}</span>
21 25 <span class="log-item-handle">
22   - <!--<a href="javascript:;" class="font-blue-steel log-close">确定</a>
23   - <a href="javascript:;" class="font-red">地图</a>-->
  26 + <a href="javascript:;" class="font-blue-steel log-close">确定</a>
  27 + <!--<a href="javascript:;" class="font-red">地图</a>-->
24 28 </span>
25 29 </div>
26 30 </script>
27 31  
28 32 <script id="console_zhongdian_temp" type="text/html">
29   -<div class="log-item zhongdian">
  33 +<div class="log-item zhongdian" data-time={{jsTime}}>
30 34 <span class="log-item-text">{{t.zdsjActual}} {{t.clZbh}} 到达 {{t.zdzName}};已完成 {{finish}} 个班次;下一发车时间 {{nt.fcsj}};由{{nt.qdzName}} 发往 {{nt.zdzName}};应到{{nt.zdsj}}</span>
31 35 <span class="log-item-time">{{dataStr}}</span>
32 36 <span class="log-item-handle">
33   - <!--<a href="javascript:;" class="font-blue-steel log-close">确定</a>
34   - <a href="javascript:;" class="font-red">地图</a>-->
  37 + <a href="javascript:;" class="font-blue-steel log-close">确定</a>
  38 + <!--<a href="javascript:;" class="font-red">地图</a>-->
35 39 </span>
36 40 </div>
37 41 </script>
38 42 \ No newline at end of file
... ...
src/main/resources/static/pages/mapmonitor/real/js/playBack.js
... ... @@ -105,7 +105,7 @@ var playBack = (function() {
105 105 else{
106 106 markerMap[gps.nbbm] = getCurrMap().addHistoryMarker(gps);//添加marker
107 107 //定位到marker
108   - getCurrMap().markerToCenter(markerMap[gps.nbbm]);
  108 + //getCurrMap().markerToCenter(markerMap[gps.nbbm]);
109 109 }
110 110  
111 111 if(gps.inout_stop != -1){
... ...
src/main/resources/static/pages/mapmonitor/real/temps/vehicle.html
... ... @@ -81,7 +81,7 @@
81 81 <p class="banci-info">
82 82 开往
83 83 {{if currSch!=null}}{{currSch.zdzName}}{{/if}}
84   - ( 预计 未知时间 到达 )
  84 + ( 预计 ? 到达 )
85 85 </p>
86 86 <p class="banci-info">
87 87 {{if nextSch!=null}}
... ...