Commit ff443d93358505bcbf68d758622810d18ca77637

Authored by 潘钊
1 parent 2a5a1f8e

大量更新....

Showing 35 changed files with 3188 additions and 1124 deletions

Too many changes to show.

To preserve performance only 35 of 136 files are displayed.

src/main/java/com/bsth/Application.java
@@ -2,6 +2,10 @@ package com.bsth; @@ -2,6 +2,10 @@ package com.bsth;
2 2
3 import com.fasterxml.jackson.databind.ObjectMapper; 3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.databind.SerializationFeature; 4 import com.fasterxml.jackson.databind.SerializationFeature;
  5 +
  6 +import java.util.concurrent.Executors;
  7 +import java.util.concurrent.ScheduledExecutorService;
  8 +
5 import org.springframework.boot.SpringApplication; 9 import org.springframework.boot.SpringApplication;
6 import org.springframework.boot.autoconfigure.SpringBootApplication; 10 import org.springframework.boot.autoconfigure.SpringBootApplication;
7 import org.springframework.boot.builder.SpringApplicationBuilder; 11 import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -11,6 +15,8 @@ import org.springframework.context.annotation.Primary; @@ -11,6 +15,8 @@ import org.springframework.context.annotation.Primary;
11 15
12 @SpringBootApplication 16 @SpringBootApplication
13 public class Application extends SpringBootServletInitializer { 17 public class Application extends SpringBootServletInitializer {
  18 +
  19 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(8);
14 20
15 @Override 21 @Override
16 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 22 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
src/main/java/com/bsth/StartCommand.java
1 package com.bsth; 1 package com.bsth;
2 2
3 3
4 -import com.bsth.repository.schedule.CarConfigInfoRepository;  
5 import com.bsth.security.SecurityMetadataSourceService; 4 import com.bsth.security.SecurityMetadataSourceService;
6 -import com.bsth.service.realcontrol.buffer.GetSchedulePlanThread;  
7 -import com.bsth.service.realcontrol.buffer.SchedulePersistenceThread;  
8 -import com.bsth.util.DateUtils;  
9 -import com.bsth.vehicle.common.CommonRefreshThread;  
10 -import com.bsth.vehicle.directive.buffer.DirectiveBuffer;  
11 -import com.bsth.vehicle.directive.service.DirectiveService;  
12 -import com.bsth.vehicle.directive.thread.DirectivePersistenceThread;  
13 -import com.bsth.vehicle.directive.thread.FirstScheduleIssuedThread;  
14 -import com.bsth.vehicle.gpsdata.ArrivalThread;  
15 -import com.bsth.vehicle.gpsdata.GpsOfflineMonitorThread;  
16 -import com.bsth.vehicle.gpsdata.GpsRealDataRefreshThread;  
17 5
18 import org.slf4j.Logger; 6 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory; 7 import org.slf4j.LoggerFactory;
@@ -21,9 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -21,9 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.boot.CommandLineRunner; 9 import org.springframework.boot.CommandLineRunner;
22 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
23 11
24 -import java.util.concurrent.Executors;  
25 -import java.util.concurrent.ScheduledExecutorService;  
26 -import java.util.concurrent.TimeUnit;  
27 12
28 /** 13 /**
29 * 随应用启动运行 14 * 随应用启动运行
@@ -38,9 +23,9 @@ public class StartCommand implements CommandLineRunner{ @@ -38,9 +23,9 @@ public class StartCommand implements CommandLineRunner{
38 @Autowired 23 @Autowired
39 SecurityMetadataSourceService invocationSecurityMetadataSourceService; 24 SecurityMetadataSourceService invocationSecurityMetadataSourceService;
40 25
41 - public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(8); 26 + //public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(8);
42 27
43 - @Autowired 28 + /*@Autowired
44 GpsRealDataRefreshThread gpsRefreshThread; 29 GpsRealDataRefreshThread gpsRefreshThread;
45 @Autowired 30 @Autowired
46 GetSchedulePlanThread getSchedulePlanThread; 31 GetSchedulePlanThread getSchedulePlanThread;
@@ -63,11 +48,11 @@ public class StartCommand implements CommandLineRunner{ @@ -63,11 +48,11 @@ public class StartCommand implements CommandLineRunner{
63 CarConfigInfoRepository carConfigInfoRepository; 48 CarConfigInfoRepository carConfigInfoRepository;
64 49
65 @Autowired 50 @Autowired
66 - GpsOfflineMonitorThread gpsOfflineMonitorThread; 51 + GpsOfflineMonitorThread gpsOfflineMonitorThread;*/
67 52
68 - final static Long HOUR_TIME = 1000 * 60 * 60L; 53 + /*final static Long HOUR_TIME = 1000 * 60 * 60L;
69 54
70 - final static int HOUR_SECOND = 60 * 60; 55 + final static int HOUR_SECOND = 60 * 60;*/
71 56
72 @Override 57 @Override
73 public void run(String... arg0){ 58 public void run(String... arg0){
@@ -78,61 +63,61 @@ public class StartCommand implements CommandLineRunner{ @@ -78,61 +63,61 @@ public class StartCommand implements CommandLineRunner{
78 63
79 /** 64 /**
80 * 车辆,设备,公司等常用的映射数据,每两小时刷新一次 65 * 车辆,设备,公司等常用的映射数据,每两小时刷新一次
81 - */ 66 + *//*
82 commonRefreshThread.start(); 67 commonRefreshThread.start();
83 scheduler.scheduleWithFixedDelay(commonRefreshThread, HOUR_SECOND * 2 , HOUR_SECOND * 2, TimeUnit.SECONDS); 68 scheduler.scheduleWithFixedDelay(commonRefreshThread, HOUR_SECOND * 2 , HOUR_SECOND * 2, TimeUnit.SECONDS);
84 //等映射数据加载完......睡一会吧 69 //等映射数据加载完......睡一会吧
85 Thread.sleep(4000); 70 Thread.sleep(4000);
86 71
87 - /** 72 + *//**
88 * GPS实时数据更新 线程 73 * GPS实时数据更新 线程
89 * 每8秒和网关HTTP接口同步一次 74 * 每8秒和网关HTTP接口同步一次
90 - */ 75 + *//*
91 scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 8, TimeUnit.SECONDS); 76 scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 8, TimeUnit.SECONDS);
92 77
93 - /** 78 + *//**
94 * GPS 监控设备掉线行为 79 * GPS 监控设备掉线行为
95 * 每分钟检测一次 80 * 每分钟检测一次
96 - */ 81 + *//*
97 scheduler.scheduleWithFixedDelay(gpsOfflineMonitorThread, 60, 60, TimeUnit.SECONDS); 82 scheduler.scheduleWithFixedDelay(gpsOfflineMonitorThread, 60, 60, TimeUnit.SECONDS);
98 83
99 84
100 - /** 85 + *//**
101 * 每天 凌晨 2 点 抓取当天实际排班 86 * 每天 凌晨 2 点 抓取当天实际排班
102 - */ 87 + *//*
103 //启动时先run一次 88 //启动时先run一次
104 getSchedulePlanThread.start(); 89 getSchedulePlanThread.start();
105 scheduler.scheduleAtFixedRate(getSchedulePlanThread 90 scheduler.scheduleAtFixedRate(getSchedulePlanThread
106 , ((DateUtils.getTimesnight2() + HOUR_TIME * 2) - System.currentTimeMillis()) / 1000 91 , ((DateUtils.getTimesnight2() + HOUR_TIME * 2) - System.currentTimeMillis()) / 1000
107 , 60 * 60 * 24, TimeUnit.SECONDS); 92 , 60 * 60 * 24, TimeUnit.SECONDS);
108 93
109 - /** 94 + *//**
110 * 调度指令两分钟入库一次 95 * 调度指令两分钟入库一次
111 * 指令会缓存在内存,直到收到所有响应再入库 96 * 指令会缓存在内存,直到收到所有响应再入库
112 - */ 97 + *//*
113 //从数据库恢复初始数据 98 //从数据库恢复初始数据
114 directiveBuffer.recovery(); 99 directiveBuffer.recovery();
115 scheduler.scheduleWithFixedDelay(directivePersistenceThread, 20, 60 * 2, TimeUnit.SECONDS); 100 scheduler.scheduleWithFixedDelay(directivePersistenceThread, 20, 60 * 2, TimeUnit.SECONDS);
116 101
117 - /** 102 + *//**
118 * 每分钟将有变更的班次入库(不包括子任务) 103 * 每分钟将有变更的班次入库(不包括子任务)
119 * 单纯为了提高 线调操作 的响应速度 104 * 单纯为了提高 线调操作 的响应速度
120 - */ 105 + *//*
121 scheduler.scheduleWithFixedDelay(SchedulePersistenceThread, 60 * 1, 60 * 1, TimeUnit.SECONDS); 106 scheduler.scheduleWithFixedDelay(SchedulePersistenceThread, 60 * 1, 60 * 1, TimeUnit.SECONDS);
122 107
123 - /** 108 + *//**
124 * 每15秒从数据库抓取到离站信息和班次匹配 109 * 每15秒从数据库抓取到离站信息和班次匹配
125 * (网关生成的到离站数据也是延迟批量入库,所以缩短该线程执行周期并不会提高 “实际到离站” 的实时性) 110 * (网关生成的到离站数据也是延迟批量入库,所以缩短该线程执行周期并不会提高 “实际到离站” 的实时性)
126 - */ 111 + *//*
127 scheduler.scheduleWithFixedDelay(gpsArrivalStationThread, 35, 15, TimeUnit.SECONDS); 112 scheduler.scheduleWithFixedDelay(gpsArrivalStationThread, 35, 15, TimeUnit.SECONDS);
128 113
129 - /** 114 + *//**
130 * 首个调度指令下发(2分钟运行一次) 115 * 首个调度指令下发(2分钟运行一次)
131 * 每辆车的第一个调度指令由该线程下发 116 * 每辆车的第一个调度指令由该线程下发
132 * 后续班次由 “实际终点到达” 事件触发指令下发 117 * 后续班次由 “实际终点到达” 事件触发指令下发
133 - */ 118 + *//*
134 scheduler.scheduleWithFixedDelay(firstScheduleIssuedThread, 60 , 60 * 2, TimeUnit.SECONDS); 119 scheduler.scheduleWithFixedDelay(firstScheduleIssuedThread, 60 , 60 * 2, TimeUnit.SECONDS);
135 - 120 + */
136 121
137 /* new Timer().schedule(new TimerTask() { 122 /* new Timer().schedule(new TimerTask() {
138 123
src/main/java/com/bsth/WebAppConfiguration.java
@@ -65,6 +65,6 @@ public class WebAppConfiguration extends WebMvcConfigurerAdapter implements WebS @@ -65,6 +65,6 @@ public class WebAppConfiguration extends WebMvcConfigurerAdapter implements WebS
65 public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 65 public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
66 //线调webSocket 66 //线调webSocket
67 registry.addHandler(new RealControlSocketHandler(), "/sockjs/realcontrol").addInterceptors(new WebSocketHandshakeInterceptor()) 67 registry.addHandler(new RealControlSocketHandler(), "/sockjs/realcontrol").addInterceptors(new WebSocketHandshakeInterceptor())
68 - .withSockJS(); 68 + .withSockJS();
69 } 69 }
70 } 70 }
src/main/java/com/bsth/vehicle/directive/controller/DirectiveController.java renamed to src/main/java/com/bsth/controller/directive/DirectiveController.java
1 -package com.bsth.vehicle.directive.controller; 1 +package com.bsth.controller.directive;
2 2
3 import java.util.List; 3 import java.util.List;
4 import java.util.Map; 4 import java.util.Map;
@@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RequestMethod; @@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
13 import org.springframework.web.bind.annotation.RequestParam; 13 import org.springframework.web.bind.annotation.RequestParam;
14 import org.springframework.web.bind.annotation.RestController; 14 import org.springframework.web.bind.annotation.RestController;
15 15
  16 +import com.bsth.entity.directive.D80;
16 import com.bsth.entity.sys.SysUser; 17 import com.bsth.entity.sys.SysUser;
17 import com.bsth.security.util.SecurityUtils; 18 import com.bsth.security.util.SecurityUtils;
18 -import com.bsth.vehicle.directive.entity.Directive80;  
19 -import com.bsth.vehicle.directive.service.DirectiveService; 19 +import com.bsth.service.directive.DirectiveService;
20 20
21 /** 21 /**
22 * 22 *
@@ -93,12 +93,12 @@ public class DirectiveController { @@ -93,12 +93,12 @@ public class DirectiveController {
93 * @throws 93 * @throws
94 */ 94 */
95 @RequestMapping(value = "/findNoCofm80", method = RequestMethod.GET) 95 @RequestMapping(value = "/findNoCofm80", method = RequestMethod.GET)
96 - public Map<String, List<Directive80>> findNoCofm80(@RequestParam String lineCodes){ 96 + public Map<String, List<D80>> findNoCofm80(@RequestParam String lineCodes){
97 return directiveService.findNoCofm80(lineCodes); 97 return directiveService.findNoCofm80(lineCodes);
98 } 98 }
99 99
100 @RequestMapping(value = "/findAll80", method = RequestMethod.GET) 100 @RequestMapping(value = "/findAll80", method = RequestMethod.GET)
101 - public Page<Directive80> findAll80(@RequestParam Map<String, Object> map, 101 + public Page<D80> findAll80(@RequestParam Map<String, Object> map,
102 @RequestParam(defaultValue = "0") int page, 102 @RequestParam(defaultValue = "0") int page,
103 @RequestParam(defaultValue = "12") int size){ 103 @RequestParam(defaultValue = "12") int size){
104 104
src/main/java/com/bsth/vehicle/UpstreamEntrance.java renamed to src/main/java/com/bsth/controller/directive/UpstreamEntrance.java
1 -package com.bsth.vehicle; 1 +package com.bsth.controller.directive;
2 2
3 import org.slf4j.Logger; 3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
@@ -10,9 +10,10 @@ import org.springframework.web.bind.annotation.RestController; @@ -10,9 +10,10 @@ import org.springframework.web.bind.annotation.RestController;
10 10
11 import com.alibaba.fastjson.JSON; 11 import com.alibaba.fastjson.JSON;
12 import com.alibaba.fastjson.JSONObject; 12 import com.alibaba.fastjson.JSONObject;
13 -import com.bsth.vehicle.directive.buffer.DirectiveBuffer;  
14 -import com.bsth.vehicle.directive.entity.DirectiveReply;  
15 -import com.bsth.vehicle.directive.entity.Directive80; 13 +import com.bsth.data.directive.DayOfDirectives;
  14 +import com.bsth.data.pilot80.PilotReport;
  15 +import com.bsth.entity.directive.D80;
  16 +import com.bsth.entity.directive.DirectiveReponse;
16 17
17 /** 18 /**
18 * 19 *
@@ -29,7 +30,10 @@ public class UpstreamEntrance { @@ -29,7 +30,10 @@ public class UpstreamEntrance {
29 Logger logger = LoggerFactory.getLogger(this.getClass()); 30 Logger logger = LoggerFactory.getLogger(this.getClass());
30 31
31 @Autowired 32 @Autowired
32 - DirectiveBuffer directiveBuffer; 33 + DayOfDirectives dayOfDirectives;
  34 +
  35 + @Autowired
  36 + PilotReport pilotReport;
33 37
34 @RequestMapping(value = "/upstream", method = RequestMethod.POST) 38 @RequestMapping(value = "/upstream", method = RequestMethod.POST)
35 public String main(@RequestParam String json) { 39 public String main(@RequestParam String json) {
@@ -37,29 +41,29 @@ public class UpstreamEntrance { @@ -37,29 +41,29 @@ public class UpstreamEntrance {
37 try { 41 try {
38 JSONObject jsonParam = JSONObject.parseObject(json); 42 JSONObject jsonParam = JSONObject.parseObject(json);
39 43
40 - // 46和47 调度指令确认 44 + // 60协议回复
41 if (jsonParam.getInteger("operCode") == null && jsonParam.getInteger("status") != null) { 45 if (jsonParam.getInteger("operCode") == null && jsonParam.getInteger("status") != null) {
42 try { 46 try {
43 - DirectiveReply reply = JSON.toJavaObject(jsonParam, DirectiveReply.class);  
44 - directiveBuffer.reply(reply); 47 + DirectiveReponse reply = JSON.toJavaObject(jsonParam, DirectiveReponse.class);
  48 + dayOfDirectives.reply(reply);
45 } catch (NumberFormatException e) { 49 } catch (NumberFormatException e) {
46 logger.error("NumberFormatException ,,,,一般是老数据,msgId太大"); 50 logger.error("NumberFormatException ,,,,一般是老数据,msgId太大");
47 } 51 }
48 } 52 }
49 - // 80协议 53 + // 80协议上报
50 else if (jsonParam.getInteger("operCode") == 0X80) { 54 else if (jsonParam.getInteger("operCode") == 0X80) {
51 try { 55 try {
52 - Directive80 report = JSON.toJavaObject(jsonParam, Directive80.class); 56 + D80 d80 = JSON.toJavaObject(jsonParam, D80.class);
53 // 驾驶员上报 57 // 驾驶员上报
54 - if (report.getData().getOperCode2() == 0x26)  
55 - directiveBuffer.jsyReport(report); 58 + if (d80.getData().getOperCode2() == 0x26)
  59 + pilotReport.report(d80);
56 } catch (Exception e) { 60 } catch (Exception e) {
57 logger.error("", e); 61 logger.error("", e);
58 } 62 }
59 } 63 }
60 // 64协议 线路切换回复 64 // 64协议 线路切换回复
61 else if (jsonParam.getInteger("operCode") == 0X64) { 65 else if (jsonParam.getInteger("operCode") == 0X64) {
62 - directiveBuffer.reply64(jsonParam); 66 + dayOfDirectives.reply64(jsonParam);
63 } else 67 } else
64 logger.warn("未知的上行数据,p: " + json); 68 logger.warn("未知的上行数据,p: " + json);
65 69
src/main/java/com/bsth/controller/gps/GpsController.java 0 → 100644
  1 +package com.bsth.controller.gps;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.PathVariable;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import com.bsth.data.BasicData;
  13 +import com.bsth.data.gpsdata.GpsEntity;
  14 +import com.bsth.data.gpsdata.GpsRealData;
  15 +import com.bsth.service.gps.GpsService;
  16 +import com.google.common.base.Splitter;
  17 +
  18 +@RestController
  19 +@RequestMapping("gps")
  20 +public class GpsController {
  21 +
  22 + @Autowired
  23 + GpsRealData gpsRealData;
  24 +
  25 + @Autowired
  26 + GpsService gpsService;
  27 +
  28 + @RequestMapping(value = "/real/line/{lineCode}")
  29 + public List<GpsEntity> findByLineCode(@PathVariable("lineCode") Integer lineCode) {
  30 + return gpsRealData.get(lineCode);
  31 + }
  32 +
  33 + @RequestMapping(value = "/real/line")
  34 + public List<GpsEntity> findByLineCode(@RequestParam String lineCodes) {
  35 + return gpsRealData.get(Splitter.on(",").splitToList(lineCodes));
  36 + }
  37 +
  38 + /**
  39 + *
  40 + * @Title: history @Description: TODO(这个方法给测试页面用) @throws
  41 + */
  42 + @RequestMapping(value = "/history/{device}")
  43 + public List<Map<String, Object>> history(@PathVariable("device") String device, @RequestParam Long startTime,
  44 + @RequestParam Long endTime, @RequestParam int directions) {
  45 +
  46 + return gpsService.history(device, startTime, endTime, directions);
  47 + }
  48 +
  49 + @RequestMapping(value = "/gpsHistory/multiple")
  50 + public List<Map<String, Object>> gpsHistory(@RequestParam String[] nbbmArray, @RequestParam Long st,
  51 + @RequestParam Long et) {
  52 + return gpsService.history(nbbmArray, st, et);
  53 + }
  54 +
  55 + /*@RequestMapping(value = "/arrival/ram")
  56 + public List<ArrivalInfo> ramData(@RequestParam String nbbm) {
  57 + return ArrivalDataBuffer.allMap.get(nbbm);
  58 + }*/
  59 +
  60 + @RequestMapping(value = "/Car2DeviceId")
  61 + public Map<String, String> findCarDeviceIdMap() {
  62 + return BasicData.deviceId2NbbmMap.inverse();
  63 + }
  64 +}
src/main/java/com/bsth/controller/realcontrol/LineConfigController.java 0 → 100644
  1 +package com.bsth.controller.realcontrol;
  2 +
  3 +import java.util.Map;
  4 +
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.PathVariable;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import com.bsth.controller.BaseController;
  13 +import com.bsth.entity.realcontrol.LineConfig;
  14 +import com.bsth.service.realcontrol.LineConfigService;
  15 +
  16 +@RestController
  17 +@RequestMapping("/lineConfig")
  18 +public class LineConfigController extends BaseController<LineConfig, Integer>{
  19 +
  20 + @Autowired
  21 + LineConfigService lineConfigService;
  22 +
  23 + @RequestMapping("/check")
  24 + public Map<String, Object> check(@RequestParam Integer[] codeArray){
  25 + return lineConfigService.check(codeArray);
  26 + }
  27 +
  28 + @RequestMapping("/init/{lineCode}")
  29 + public Integer init(@PathVariable("lineCode") Integer lineCode) throws Exception{
  30 + return lineConfigService.inti(lineCode);
  31 + }
  32 +
  33 + @RequestMapping(value = "/editTime", method = RequestMethod.POST)
  34 + public Map<String, Object> editStartOptTime(@RequestParam String time,@RequestParam String lineCode){
  35 + return lineConfigService.editStartOptTime(time, lineCode);
  36 + }
  37 +}
src/main/java/com/bsth/controller/realcontrol/ScheduleRealInfoController.java
@@ -12,23 +12,25 @@ import org.springframework.web.bind.annotation.RequestParam; @@ -12,23 +12,25 @@ import org.springframework.web.bind.annotation.RequestParam;
12 import org.springframework.web.bind.annotation.RestController; 12 import org.springframework.web.bind.annotation.RestController;
13 13
14 import com.bsth.controller.BaseController; 14 import com.bsth.controller.BaseController;
  15 +import com.bsth.data.BasicData;
  16 +import com.bsth.data.schedule.DayOfSchedule;
15 import com.bsth.entity.realcontrol.ScheduleRealInfo; 17 import com.bsth.entity.realcontrol.ScheduleRealInfo;
16 import com.bsth.security.util.SecurityUtils; 18 import com.bsth.security.util.SecurityUtils;
17 import com.bsth.service.realcontrol.ScheduleRealInfoService; 19 import com.bsth.service.realcontrol.ScheduleRealInfoService;
18 -import com.bsth.service.realcontrol.buffer.GetSchedulePlanThread;  
19 -import com.bsth.service.realcontrol.buffer.ScheduleBuffer;  
20 -import com.bsth.vehicle.common.CommonMapped;  
21 import com.google.common.base.Splitter; 20 import com.google.common.base.Splitter;
22 21
23 @RestController 22 @RestController
24 @RequestMapping("/realSchedule") 23 @RequestMapping("/realSchedule")
25 public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, Long> { 24 public class ScheduleRealInfoController extends BaseController<ScheduleRealInfo, Long> {
26 25
27 - @Autowired  
28 - GetSchedulePlanThread getSchedulePlanThread; 26 + /*@Autowired
  27 + GetSchedulePlanThread getSchedulePlanThread;*/
29 28
30 @Autowired 29 @Autowired
31 ScheduleRealInfoService scheduleRealInfoService; 30 ScheduleRealInfoService scheduleRealInfoService;
  31 +
  32 + @Autowired
  33 + DayOfSchedule dayOfSchedule;
32 34
33 @RequestMapping(value = "/lines") 35 @RequestMapping(value = "/lines")
34 public Map<String, Collection<ScheduleRealInfo>> findByLines(@RequestParam String lines) { 36 public Map<String, Collection<ScheduleRealInfo>> findByLines(@RequestParam String lines) {
@@ -47,10 +49,10 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -47,10 +49,10 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
47 String userName = SecurityUtils.getCurrentUser().getUserName(); 49 String userName = SecurityUtils.getCurrentUser().getUserName();
48 // 注销之前的绑定 50 // 注销之前的绑定
49 for (String line : list) 51 for (String line : list)
50 - CommonMapped.lineUserMap.get(Integer.parseInt(line)).remove(userName); 52 + BasicData.lineCode2SocketUserMap.get(line).remove(userName);
51 // 重新绑定 53 // 重新绑定
52 for (String line : list) 54 for (String line : list)
53 - CommonMapped.lineUserMap.put(Integer.parseInt(line), userName); 55 + BasicData.lineCode2SocketUserMap.put(line, userName);
54 56
55 return 0; 57 return 0;
56 } 58 }
@@ -84,7 +86,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -84,7 +86,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
84 */ 86 */
85 @RequestMapping(value = "/carDeviceMapp", method = RequestMethod.GET) 87 @RequestMapping(value = "/carDeviceMapp", method = RequestMethod.GET)
86 public Map<String, String> carDeviceMapp() { 88 public Map<String, String> carDeviceMapp() {
87 - return CommonMapped.vehicDeviceBiMap.inverse(); 89 + return BasicData.deviceId2NbbmMap.inverse();
88 } 90 }
89 91
90 /** 92 /**
@@ -231,7 +233,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -231,7 +233,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
231 */ 233 */
232 @RequestMapping(value = "/trustStatus/change", method = RequestMethod.POST) 234 @RequestMapping(value = "/trustStatus/change", method = RequestMethod.POST)
233 public int changeTrustStatus(@RequestParam Integer lineCode, @RequestParam Integer status) { 235 public int changeTrustStatus(@RequestParam Integer lineCode, @RequestParam Integer status) {
234 - ScheduleBuffer.trustMap.put(lineCode, status); 236 + //ScheduleBuffer.trustMap.put(lineCode, status);
235 return 200; 237 return 200;
236 } 238 }
237 239
@@ -243,8 +245,8 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -243,8 +245,8 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
243 * @param @param upDown 245 * @param @param upDown
244 */ 246 */
245 @RequestMapping(value = "/findByLineAndUpDown") 247 @RequestMapping(value = "/findByLineAndUpDown")
246 - public List<ScheduleRealInfo> findByLineAndUpDown(@RequestParam Integer line,@RequestParam Integer upDown){  
247 - return ScheduleBuffer.findByLineAndUpDown(line, upDown); 248 + public List<ScheduleRealInfo> findByLineAndUpDown(@RequestParam String line,@RequestParam Integer upDown){
  249 + return dayOfSchedule.findByLineAndUpDown(line, upDown);
248 } 250 }
249 251
250 /** 252 /**
@@ -261,7 +263,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -261,7 +263,7 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
261 263
262 @RequestMapping(value = "/test/getSch") 264 @RequestMapping(value = "/test/getSch")
263 public int getSch(){ 265 public int getSch(){
264 - getSchedulePlanThread.start(); 266 + //getSchedulePlanThread.start();
265 return 1; 267 return 1;
266 } 268 }
267 269
@@ -285,7 +287,8 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo, @@ -285,7 +287,8 @@ public class ScheduleRealInfoController extends BaseController&lt;ScheduleRealInfo,
285 */ 287 */
286 @RequestMapping(value = "/lineCode/{lineCode}") 288 @RequestMapping(value = "/lineCode/{lineCode}")
287 public List<ScheduleRealInfo> findByLineCode(@PathVariable("lineCode") String lineCode){ 289 public List<ScheduleRealInfo> findByLineCode(@PathVariable("lineCode") String lineCode){
288 - return ScheduleBuffer.realSchedulListMap.get(lineCode); 290 + //return ScheduleBuffer.realSchedulListMap.get(lineCode);
  291 + return dayOfSchedule.findByLineCode(lineCode);
289 } 292 }
290 293
291 @RequestMapping(value = "/queryUserInfo") 294 @RequestMapping(value = "/queryUserInfo")
src/main/java/com/bsth/controller/sys/UserController.java
1 package com.bsth.controller.sys; 1 package com.bsth.controller.sys;
2 2
3 import javax.servlet.http.HttpServletRequest; 3 import javax.servlet.http.HttpServletRequest;
4 -import javax.servlet.http.HttpServletResponse;  
5 import javax.servlet.http.HttpSession; 4 import javax.servlet.http.HttpSession;
6 5
7 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.security.authentication.BadCredentialsException; 7 import org.springframework.security.authentication.BadCredentialsException;
9 -import org.springframework.security.core.Authentication;  
10 -import org.springframework.security.core.context.SecurityContextHolder;  
11 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 8 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12 -import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;  
13 import org.springframework.security.web.authentication.session.SessionAuthenticationException; 9 import org.springframework.security.web.authentication.session.SessionAuthenticationException;
14 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RequestParam; 11 import org.springframework.web.bind.annotation.RequestParam;
16 import org.springframework.web.bind.annotation.RestController; 12 import org.springframework.web.bind.annotation.RestController;
17 -import org.springframework.web.servlet.ModelAndView;  
18 13
19 import com.bsth.controller.BaseController; 14 import com.bsth.controller.BaseController;
20 import com.bsth.entity.sys.SysUser; 15 import com.bsth.entity.sys.SysUser;
@@ -51,23 +46,6 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt;{ @@ -51,23 +46,6 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt;{
51 return msg; 46 return msg;
52 } 47 }
53 48
54 - /**  
55 - *  
56 - * @Title: logout  
57 - * @Description: TODO(注销吧皮卡丘)  
58 - * @param @param request  
59 - * @return ModelAndView 返回类型  
60 - * @throws  
61 - */  
62 - @RequestMapping("/logout")  
63 - public ModelAndView logout(HttpServletRequest request, HttpServletResponse response){  
64 - Authentication auth = SecurityContextHolder.getContext().getAuthentication();  
65 - if (auth != null){  
66 - new SecurityContextLogoutHandler().logout(request, response, auth);  
67 - }  
68 - return new ModelAndView("/");  
69 - }  
70 -  
71 @RequestMapping("/currentUser") 49 @RequestMapping("/currentUser")
72 public SysUser currentUser(){ 50 public SysUser currentUser(){
73 return SecurityUtils.getCurrentUser(); 51 return SecurityUtils.getCurrentUser();
src/main/java/com/bsth/data/BasicData.java
1 -//package com.bsth.data;  
2 -//  
3 -//import java.util.HashMap;  
4 -//import java.util.Iterator;  
5 -//import java.util.Map;  
6 -//  
7 -//import org.slf4j.Logger;  
8 -//import org.slf4j.LoggerFactory;  
9 -//import org.springframework.beans.factory.annotation.Autowired;  
10 -//import org.springframework.stereotype.Component;  
11 -//  
12 -//import com.bsth.entity.CarPark;  
13 -//import com.bsth.entity.Cars;  
14 -//import com.bsth.entity.Line;  
15 -//import com.bsth.entity.Station;  
16 -//import com.bsth.entity.schedule.CarConfigInfo;  
17 -//import com.bsth.repository.CarParkRepository;  
18 -//import com.bsth.repository.CarsRepository;  
19 -//import com.bsth.repository.LineRepository;  
20 -//import com.bsth.repository.StationRepository;  
21 -//import com.bsth.repository.schedule.CarConfigInfoRepository;  
22 -//import com.google.common.collect.BiMap;  
23 -//import com.google.common.collect.HashBiMap;  
24 -//import com.google.common.collect.TreeMultimap;  
25 -//  
26 -///**  
27 -// *  
28 -// * @ClassName: BasicData  
29 -// * @Description: TODO(基础的映射数据)  
30 -// * @author PanZhao  
31 -// * @date 2016年8月10日 下午3:27:45  
32 -// *  
33 -// */  
34 -//@Component  
35 -//public class BasicData {  
36 -//  
37 -// //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)  
38 -// public static BiMap<String, String> deviceId2NbbmMap;  
39 -//  
40 -// //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)  
41 -// public static Map<String, String> nbbm2CompanyCodeMap;  
42 -//  
43 -// //站点编码和名称对照,包括停车场 (K: 站点编码 ,V:站点名称)  
44 -// public static Map<String, String> stationCode2NameMap;  
45 -//  
46 -// //车辆和线路对照  
47 -// public static Map<String, Line> nbbm2LineMap;  
48 -//  
49 -// //线路和用户对照 用于webSocket定向推送消息(用户进入线调时写入数据)  
50 -// public static TreeMultimap<Integer, String> lineCode2SocketUserMap = TreeMultimap.create();  
51 -//  
52 -// //线路ID和code 对照  
53 -// public static BiMap<Integer, Integer> lineId2CodeMap;  
54 -//  
55 -// @Autowired  
56 -// BasicDataLoader basicDataLoader;  
57 -//  
58 -// Logger logger = LoggerFactory.getLogger(this.getClass());  
59 -//  
60 -// /**  
61 -// *  
62 -// * @Title: loadAllData  
63 -// * @Description: TODO(加载所有数据)  
64 -// * @throws  
65 -// */  
66 -// public int loadAllData(){  
67 -// try{  
68 -// basicDataLoader.loadDeviceInfo();  
69 -// basicDataLoader.loadStationInfo();  
70 -// basicDataLoader.loadLineInfo();  
71 -// basicDataLoader.loadNbbm2LineInfo();  
72 -// }catch(Exception e){  
73 -// logger.error("加载基础数据时出现异常," , e);  
74 -// }  
75 -// return 0;  
76 -// }  
77 -//  
78 -// @Component  
79 -// public class BasicDataLoader{  
80 -//  
81 -// @Autowired  
82 -// CarsRepository carsRepository;  
83 -//  
84 -// @Autowired  
85 -// StationRepository stationRepository;  
86 -//  
87 -// @Autowired  
88 -// CarParkRepository carParkRepository;  
89 -//  
90 -// @Autowired  
91 -// CarConfigInfoRepository carConfigInfoRepository;  
92 -//  
93 -// @Autowired  
94 -// LineRepository lineRepository;  
95 -//  
96 -// /**  
97 -// *  
98 -// * @Title: loadDeviceInfo  
99 -// * @Description: TODO(加载设备相关信息)  
100 -// * @throws  
101 -// */  
102 -// public void loadDeviceInfo(){  
103 -// BiMap<String, String> deviceId2Nbbm = HashBiMap.create();  
104 -// //车辆和公司代码对照  
105 -// Map<String, String> nbbm2CompanyCode = new HashMap<>();  
106 -// Iterator<Cars> carIterator = carsRepository.findAll().iterator();  
107 -// Cars car;  
108 -// while(carIterator.hasNext()){  
109 -// car = carIterator.next();  
110 -// deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());  
111 -// nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());  
112 -// }  
113 -//  
114 -// deviceId2NbbmMap = deviceId2Nbbm;  
115 -// nbbm2CompanyCodeMap = nbbm2CompanyCode;  
116 -// }  
117 -//  
118 -// /**  
119 -// *  
120 -// * @Title: loadStationInfo  
121 -// * @Description: TODO(加载站点信息)  
122 -// * @throws  
123 -// */  
124 -// public void loadStationInfo(){  
125 -// Map<String, String> stationCode2Name = new HashMap<>();  
126 -// Iterator<Station> iterator = stationRepository.findAll().iterator();  
127 -// //站点  
128 -// Station station;  
129 -// while(iterator.hasNext()){  
130 -// station = iterator.next();  
131 -// stationCode2Name.put(station.getStationCod(), station.getStationName());  
132 -// }  
133 -// //停车场  
134 -// Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();  
135 -// CarPark carPark;  
136 -// while(iterator2.hasNext()){  
137 -// carPark = iterator2.next();  
138 -// stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());  
139 -// }  
140 -//  
141 -// stationCode2NameMap = stationCode2Name;  
142 -// }  
143 -//  
144 -// /**  
145 -// *  
146 -// * @Title: loadNbbm2LineInfo  
147 -// * @Description: TODO(车辆和线路对照)  
148 -// * @throws  
149 -// */  
150 -// public void loadNbbm2LineInfo(){  
151 -// Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();  
152 -// Map<String, Line> ccMap = new HashMap<>();  
153 -//  
154 -// CarConfigInfo cci;  
155 -// while(allIterator.hasNext()){  
156 -// cci = allIterator.next();  
157 -// ccMap.put(cci.getCl().getInsideCode(), cci.getXl());  
158 -// }  
159 -// nbbm2LineMap = ccMap;  
160 -// }  
161 -//  
162 -// /**  
163 -// *  
164 -// * @Title: loadLineInfo  
165 -// * @Description: TODO(加载线路相关信息)  
166 -// * @throws  
167 -// */  
168 -// public void loadLineInfo(){  
169 -// Iterator<Line> iterator = lineRepository.findAll().iterator();  
170 -//  
171 -// Line line;  
172 -// BiMap<Integer, Integer> biMap = HashBiMap.create();  
173 -// while(iterator.hasNext()){  
174 -// line = iterator.next();  
175 -// biMap.put(line.getId(), Integer.parseInt(line.getLineCode()));  
176 -// }  
177 -//  
178 -// lineId2CodeMap = biMap;  
179 -// }  
180 -// }  
181 -//} 1 +package com.bsth.data;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.Iterator;
  5 +import java.util.Map;
  6 +import java.util.concurrent.TimeUnit;
  7 +
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.boot.CommandLineRunner;
  12 +import org.springframework.stereotype.Component;
  13 +
  14 +import com.bsth.Application;
  15 +import com.bsth.entity.CarPark;
  16 +import com.bsth.entity.Cars;
  17 +import com.bsth.entity.Line;
  18 +import com.bsth.entity.Station;
  19 +import com.bsth.entity.schedule.CarConfigInfo;
  20 +import com.bsth.repository.CarParkRepository;
  21 +import com.bsth.repository.CarsRepository;
  22 +import com.bsth.repository.LineRepository;
  23 +import com.bsth.repository.StationRepository;
  24 +import com.bsth.repository.schedule.CarConfigInfoRepository;
  25 +import com.google.common.collect.BiMap;
  26 +import com.google.common.collect.HashBiMap;
  27 +import com.google.common.collect.TreeMultimap;
  28 +
  29 +/**
  30 + *
  31 + * @ClassName: BasicData
  32 + * @Description: TODO(基础的映射数据)
  33 + * @author PanZhao
  34 + * @date 2016年8月10日 下午3:27:45
  35 + *
  36 + */
  37 +@Component
  38 +public class BasicData implements CommandLineRunner{
  39 +
  40 + //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)
  41 + public static BiMap<String, String> deviceId2NbbmMap;
  42 +
  43 + //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
  44 + public static Map<String, String> nbbm2CompanyCodeMap;
  45 +
  46 + //站点编码和名称对照,包括停车场 (K: 站点编码 ,V:站点名称)
  47 + public static Map<String, String> stationCode2NameMap;
  48 +
  49 + //车辆和线路对照
  50 + public static Map<String, Line> nbbm2LineMap;
  51 +
  52 + //线路和用户对照 用于webSocket定向推送消息(用户进入线调时写入数据)
  53 + public static TreeMultimap<String, String> lineCode2SocketUserMap = TreeMultimap.create();
  54 +
  55 + //线路ID和code 对照
  56 + public static BiMap<Integer, Integer> lineId2CodeMap;
  57 +
  58 + //线路编码和名称对照
  59 + public static Map<String, String> lineCode2NameMap;
  60 +
  61 + static Logger logger = LoggerFactory.getLogger(BasicData.class);
  62 +
  63 + @Autowired
  64 + BasicDataLoader dataLoader;
  65 +
  66 + @Override
  67 + public void run(String... arg0) throws Exception {
  68 + Application.mainServices.scheduleWithFixedDelay(dataLoader, 0, 2, TimeUnit.HOURS);
  69 + }
  70 +
  71 +
  72 + @Component
  73 + public static class BasicDataLoader extends Thread{
  74 +
  75 + @Autowired
  76 + CarsRepository carsRepository;
  77 +
  78 + @Autowired
  79 + StationRepository stationRepository;
  80 +
  81 + @Autowired
  82 + CarParkRepository carParkRepository;
  83 +
  84 + @Autowired
  85 + CarConfigInfoRepository carConfigInfoRepository;
  86 +
  87 + @Autowired
  88 + LineRepository lineRepository;
  89 +
  90 +
  91 + @Override
  92 + public void run() {
  93 + loadAllData();
  94 + }
  95 +
  96 + /**
  97 + * @Title: loadAllData
  98 + * @Description: TODO(加载所有数据)
  99 + */
  100 + public int loadAllData(){
  101 + try{
  102 + loadDeviceInfo();
  103 + loadStationInfo();
  104 + loadLineInfo();
  105 + loadNbbm2LineInfo();
  106 + }catch(Exception e){
  107 + logger.error("加载基础数据时出现异常," , e);
  108 + }
  109 + return 0;
  110 + }
  111 +
  112 +
  113 + /**
  114 + * @Title: loadDeviceInfo
  115 + * @Description: TODO(加载设备相关信息)
  116 + */
  117 + public void loadDeviceInfo(){
  118 + BiMap<String, String> deviceId2Nbbm = HashBiMap.create();
  119 + //车辆和公司代码对照
  120 + Map<String, String> nbbm2CompanyCode = new HashMap<>();
  121 + Iterator<Cars> carIterator = carsRepository.findAll().iterator();
  122 + Cars car;
  123 + while(carIterator.hasNext()){
  124 + car = carIterator.next();
  125 + deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());
  126 + nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());
  127 + }
  128 +
  129 + deviceId2NbbmMap = deviceId2Nbbm;
  130 + nbbm2CompanyCodeMap = nbbm2CompanyCode;
  131 + }
  132 +
  133 + /**
  134 + * @Title: loadStationInfo
  135 + * @Description: TODO(加载站点信息)
  136 + */
  137 + public void loadStationInfo(){
  138 + Map<String, String> stationCode2Name = new HashMap<>();
  139 + Iterator<Station> iterator = stationRepository.findAll().iterator();
  140 + //站点
  141 + Station station;
  142 + while(iterator.hasNext()){
  143 + station = iterator.next();
  144 + stationCode2Name.put(station.getStationCod(), station.getStationName());
  145 + }
  146 + //停车场
  147 + Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();
  148 + CarPark carPark;
  149 + while(iterator2.hasNext()){
  150 + carPark = iterator2.next();
  151 + stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());
  152 + }
  153 +
  154 + stationCode2NameMap = stationCode2Name;
  155 + }
  156 +
  157 + /**
  158 + * @Title: loadNbbm2LineInfo
  159 + * @Description: TODO(车辆和线路对照)
  160 + */
  161 + public void loadNbbm2LineInfo(){
  162 + Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
  163 + Map<String, Line> ccMap = new HashMap<>();
  164 +
  165 + CarConfigInfo cci;
  166 + while(allIterator.hasNext()){
  167 + cci = allIterator.next();
  168 + ccMap.put(cci.getCl().getInsideCode(), cci.getXl());
  169 + }
  170 + nbbm2LineMap = ccMap;
  171 + }
  172 +
  173 + /**
  174 + * @Title: loadLineInfo
  175 + * @Description: TODO(加载线路相关信息)
  176 + */
  177 + public void loadLineInfo(){
  178 + Iterator<Line> iterator = lineRepository.findAll().iterator();
  179 +
  180 + Line line;
  181 + BiMap<Integer, Integer> biMap = HashBiMap.create();
  182 + Map<String, String> code2name = new HashMap<>();
  183 +
  184 + while(iterator.hasNext()){
  185 + line = iterator.next();
  186 + biMap.put(line.getId(), Integer.parseInt(line.getLineCode()));
  187 + code2name.put(line.getLineCode(), line.getName());
  188 + }
  189 +
  190 + lineId2CodeMap = biMap;
  191 + lineCode2NameMap = code2name;
  192 + }
  193 + }
  194 +}
src/main/java/com/bsth/data/DirectiveData.java deleted 100644 → 0
1 -package com.bsth.data;  
2 -  
3 -/**  
4 - *  
5 - * @ClassName: DirectiveData  
6 - * @Description: TODO(指令数据)  
7 - * @author PanZhao  
8 - * @date 2016年8月10日 下午3:50:05  
9 - *  
10 - */  
11 -public class DirectiveData {  
12 -  
13 -  
14 -}  
src/main/java/com/bsth/data/GpsRealData.java deleted 100644 → 0
1 -package com.bsth.data;  
2 -  
3 -/**  
4 - *  
5 - * @ClassName: GpsRealData  
6 - * @Description: TODO(GPS实时数据)  
7 - * @author PanZhao  
8 - * @date 2016年8月10日 下午3:41:47  
9 - *  
10 - */  
11 -public class GpsRealData {  
12 -  
13 -}  
src/main/java/com/bsth/data/LineConfigData.java 0 → 100644
  1 +package com.bsth.data;
  2 +
  3 +import java.util.Collection;
  4 +import java.util.HashMap;
  5 +import java.util.Iterator;
  6 +import java.util.Map;
  7 +import java.util.Set;
  8 +
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.boot.CommandLineRunner;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import com.bsth.entity.Line;
  16 +import com.bsth.entity.realcontrol.D80ReplyTemp;
  17 +import com.bsth.entity.realcontrol.LineConfig;
  18 +import com.bsth.service.LineService;
  19 +import com.bsth.service.realcontrol.LineConfigService;
  20 +
  21 +/**
  22 + *
  23 + * @ClassName: LineConfigData
  24 + * @Description: TODO(线路配置数据管理)
  25 + * @author PanZhao
  26 + * @date 2016年8月15日 下午2:50:19
  27 + *
  28 + */
  29 +@Component
  30 +public class LineConfigData implements CommandLineRunner {
  31 +
  32 + Logger logger = LoggerFactory.getLogger(this.getClass());
  33 +
  34 + // 线路编码和配置
  35 + private Map<String, LineConfig> lineConfMap;
  36 +
  37 + @Autowired
  38 + LineConfigService lineConfigService;
  39 +
  40 + @Autowired
  41 + LineService lineService;
  42 +
  43 + @Override
  44 + public void run(String... arg0) throws Exception {
  45 + lineConfMap = new HashMap<>();
  46 +
  47 + Iterator<LineConfig> itr = lineConfigService.findAll().iterator();
  48 + while (itr.hasNext())
  49 + setBuffer(itr.next());
  50 + }
  51 +
  52 + public LineConfig get(String lineCode){
  53 + return lineConfMap.get(lineCode);
  54 + }
  55 +
  56 + public Collection<LineConfig> getAll(){
  57 + return lineConfMap.values();
  58 + }
  59 +
  60 + public void set(LineConfig conf){
  61 + lineConfigService.save(conf);
  62 + setBuffer(conf);
  63 + }
  64 +
  65 + public void setBuffer(LineConfig conf){
  66 + lineConfMap.put(conf.getLine().getLineCode(), conf);
  67 + }
  68 +
  69 + /**
  70 + *
  71 + * @Title: init
  72 + * @Description: TODO(初始化配置信息)
  73 + */
  74 + public void init(Integer lineCode) throws Exception{
  75 + LineConfig conf = new LineConfig();
  76 + //线路
  77 + Line line = lineService.findByLineCode(lineCode);
  78 + if(null == line)
  79 + throw new NullPointerException("异常的lineCode");
  80 +
  81 + conf.setLine(line);
  82 + //开始运营时间
  83 + conf.setStartOpt("02:00");
  84 + //托管状态
  85 + conf.setTrust(true);
  86 + //出场时间类型
  87 + conf.setOutConfig(1);
  88 + //进场时间类型
  89 + conf.setInConfig(1);
  90 + //短语模板
  91 + conf.setPhraseTemps("");
  92 + //调度指令模板
  93 + conf.setSchDirectiveTemp("");
  94 +
  95 + //80指令回复
  96 + D80ReplyTemp t50 = new D80ReplyTemp(conf, (short)0x50, "同意,回电详谈", "不同意,请回电")
  97 + ,t60 = new D80ReplyTemp(conf, (short)0x60, "同意,回电详谈", "不同意,请回电")
  98 + ,tA2 = new D80ReplyTemp(conf, (short)0xA2, "同意,回电详谈", "不同意,请回电")
  99 + ,t70 = new D80ReplyTemp(conf, (short)0x70, "同意,回电详谈", "不同意,请回电")
  100 + ,t11 = new D80ReplyTemp(conf, (short)0x11, "同意,回电详谈", "不同意,请回电");
  101 +
  102 + Set<D80ReplyTemp> temps = conf.getD80Temps();
  103 + temps.add(t50);
  104 + temps.add(t60);
  105 + temps.add(tA2);
  106 + temps.add(t70);
  107 + temps.add(t11);
  108 +
  109 + set(conf);
  110 + }
  111 +}
src/main/java/com/bsth/data/ScheduleData.java deleted 100644 → 0
1 -package com.bsth.data;  
2 -  
3 -/**  
4 - *  
5 - * @ClassName: ScheduleData  
6 - * @Description: TODO(排班数据)  
7 - * @author PanZhao  
8 - * @date 2016年8月10日 下午3:42:31  
9 - *  
10 - */  
11 -public class ScheduleData {  
12 -  
13 -}  
src/main/java/com/bsth/data/arrival/ArrivalComparator.java 0 → 100644
  1 +package com.bsth.data.arrival;
  2 +
  3 +import java.util.Comparator;
  4 +
  5 +public class ArrivalComparator implements Comparator<ArrivalEntity>{
  6 +
  7 + @Override
  8 + public int compare(ArrivalEntity a1, ArrivalEntity a2) {
  9 + return (int) (a1.getTs() - a2.getTs());
  10 + }
  11 +}
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java 0 → 100644
  1 +package com.bsth.data.arrival;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collection;
  5 +import java.util.HashMap;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +import java.util.Set;
  9 +import java.util.TreeSet;
  10 +import java.util.concurrent.TimeUnit;
  11 +
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.boot.CommandLineRunner;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import com.bsth.Application;
  19 +import com.bsth.data.match.Arrival2Schedule;
  20 +import com.bsth.data.schedule.DayOfSchedule;
  21 +import com.google.common.collect.ArrayListMultimap;
  22 +import com.google.common.collect.ListMultimap;
  23 +
  24 +/**
  25 + *
  26 + * @ClassName: ArrivalData_GPS
  27 + * @Description: TODO(这里用一句话描述这个类的作用)
  28 + * @author PanZhao
  29 + * @date 2016年8月18日 下午10:05:27
  30 + *
  31 + */
  32 +@Component
  33 +public class ArrivalData_GPS implements CommandLineRunner{
  34 +
  35 + //全部进出站数据(当日) K:线路编码
  36 + //private static ListMultimap<String, ArrivalEntity> allArrivals;
  37 +
  38 + // 起终点站进出数据 K:车辆编码
  39 + private static ListMultimap<String, ArrivalEntity> startAndEndMaps;
  40 +
  41 + private static Map<String, Integer> carIndexMap;
  42 +
  43 + static{
  44 + //allArrivals = ArrayListMultimap.create();
  45 + startAndEndMaps = ArrayListMultimap.create();
  46 +
  47 + carIndexMap = new HashMap<>();
  48 + }
  49 +
  50 + @Autowired
  51 + DataLoaderThread dataLoaderThread;
  52 +
  53 + static Logger logger = LoggerFactory.getLogger(ArrivalData_GPS.class);
  54 +
  55 + @Override
  56 + public void run(String... arg0) throws Exception {
  57 + Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 40, 45, TimeUnit.SECONDS);
  58 + }
  59 +
  60 + @Component
  61 + public static class DataLoaderThread extends Thread {
  62 +
  63 + @Autowired
  64 + DataLoader dataLoader;
  65 +
  66 + @Autowired
  67 + DayOfSchedule dayOfSchedule;
  68 +
  69 + @Override
  70 + public void run() {
  71 + Set<ArrivalEntity> arrSets = dataLoader.load();
  72 + //有起终点进出的车辆
  73 + Set<String> carSet = new TreeSet<>();
  74 + //按车辆起终点站过滤数据
  75 + String nbbm;
  76 + Set<String> seList;
  77 + for(ArrivalEntity arr : arrSets){
  78 + //allArrivals.put(arr.getLineCode(), arr);
  79 + nbbm = arr.getNbbm();
  80 +
  81 + seList = dayOfSchedule.getSEStationList(nbbm);
  82 + if(seList.contains(arr.getStopNo())){
  83 + startAndEndMaps.put(nbbm, arr);
  84 + carSet.add(nbbm);
  85 + }
  86 + }
  87 +
  88 + //System.out.println("起终点数据大小为:" + startAndEndMaps.size() + " -- 全量数据:" + allArrivals.size());
  89 + try{
  90 + Arrival2Schedule.start(carSet);
  91 + }catch(Exception e){
  92 + logger.error("", e);
  93 + }
  94 + }
  95 + }
  96 +
  97 + /**
  98 + *
  99 + * @Title: clearRAMData
  100 + * @Description: TODO(清理内存数据)
  101 + */
  102 + public void clearRAMData(String lineCode){
  103 + //allArrivals.removeAll(lineCode);
  104 + int count = 0;
  105 +
  106 + //车辆映射的进出站数据,遍历删除对应线路数据。
  107 + Collection<ArrivalEntity> seList = startAndEndMaps.values();
  108 + for(ArrivalEntity arr : seList){
  109 + if(arr.getLineCode().equals(lineCode)){
  110 + if(startAndEndMaps.remove(arr.getDeviceId(), arr)){
  111 + count ++;
  112 + }
  113 + }
  114 + }
  115 +
  116 + logger.info(lineCode + " 清除到离站数据 ," + count);
  117 + }
  118 +
  119 + public static List<ArrivalEntity> findByNbbm(String nbbm){
  120 + return startAndEndMaps.get(nbbm);
  121 + }
  122 +
  123 + public static List<ArrivalEntity> getIncrement(String nbbm){
  124 + Integer mark = null;
  125 + if (!carIndexMap.containsKey(nbbm))
  126 + mark = 0;
  127 + else
  128 + mark = carIndexMap.get(nbbm);
  129 +
  130 + List<ArrivalEntity> all = startAndEndMaps.get(nbbm);
  131 + int size = all.size();
  132 + if(size == 0)
  133 + return new ArrayList<>(0);
  134 +
  135 + List<ArrivalEntity> rs = all.subList(mark, size);
  136 + carIndexMap.put(nbbm, size);
  137 + return rs;
  138 + }
  139 +}
src/main/java/com/bsth/vehicle/gpsdata/entity/ArrivalInfo.java renamed to src/main/java/com/bsth/data/arrival/ArrivalEntity.java
1 -package com.bsth.vehicle.gpsdata.entity;  
2 -  
3 -import com.bsth.vehicle.common.CommonMapped; 1 +package com.bsth.data.arrival;
4 2
5 /** 3 /**
6 * 4 *
7 - * @ClassName: ArrivalInfo  
8 - * @Description: TODO(到离站信息)  
9 - * @author PanZhao  
10 - * @date 2016年6月27日 上午9:53:19 5 + * @ClassName: ArrivalEntity
  6 + * @Description: TODO(进出站实体)
  7 + * @author PanZhao
  8 + * @date 2016年8月19日 上午9:32:20
11 * 9 *
12 */ 10 */
13 -public class ArrivalInfo {  
14 -  
15 - public ArrivalInfo(String deviceId, Long ts, String lineCode, Integer upDown, String stopNo, Integer inOut,  
16 - Long createDate, Integer weeksYear) {  
17 - this.deviceId = deviceId;  
18 -  
19 - this.ts = ts;  
20 -  
21 - this.lineCode = lineCode;  
22 - this.upDown = upDown;  
23 - this.stopNo = stopNo;  
24 - this.inOut = inOut;  
25 - this.createDate = createDate;  
26 - this.weeksYear = weeksYear;  
27 - this.stopName = CommonMapped.stationCodeMap.get(this.stopNo);  
28 - } 11 +public class ArrivalEntity {
29 12
30 - public ArrivalInfo(String deviceId, Long ts, String lineCode, Integer upDown, String stopNo, Integer inOut,  
31 - Long createDate, Integer weeksYear, String stopName) {  
32 - this.deviceId = deviceId;  
33 -  
34 - this.ts = ts;  
35 -  
36 - this.lineCode = lineCode;  
37 - this.upDown = upDown;  
38 - this.stopNo = stopNo;  
39 - this.inOut = inOut;  
40 - this.createDate = createDate;  
41 - this.weeksYear = weeksYear;  
42 - this.stopName = stopName;  
43 - }  
44 -  
45 - /**  
46 - * 设备号  
47 - */ 13 + /** 设备号*/
48 private String deviceId; 14 private String deviceId;
49 15
  16 + private String nbbm;
  17 +
50 /** 站点名称 */ 18 /** 站点名称 */
51 private String stopName; 19 private String stopName;
52 20
53 - /**  
54 - * 时间戳  
55 - */ 21 + /** 时间戳*/
56 private Long ts; 22 private Long ts;
57 23
58 - /**  
59 - * 线路编码  
60 - */ 24 + /** 线路编码*/
61 private String lineCode; 25 private String lineCode;
62 26
63 - /**  
64 - * 上下行  
65 - */ 27 + /** 上下行*/
66 private Integer upDown; 28 private Integer upDown;
67 29
68 - /**  
69 - * 站点编码  
70 - */ 30 + /**站点编码*/
71 private String stopNo; 31 private String stopNo;
72 32
73 - /**  
74 - * 0: 进 1:出  
75 - */ 33 + /** 0: 进 1:出*/
76 private Integer inOut; 34 private Integer inOut;
77 35
78 private Long createDate; 36 private Long createDate;
79 -  
80 - /**  
81 - * 分区字段,当年的第几周  
82 - */ 37 +
  38 + /**分区字段,当年的第几周*/
83 private Integer weeksYear; 39 private Integer weeksYear;
  40 +
  41 + //5分钟内不允许多次进同一个站,出同一个站。 忽略走向
  42 + private final static int EQ_RANGE = 1000 * 60 * 5;
  43 +
  44 + public ArrivalEntity(){}
  45 +
  46 + public ArrivalEntity(String deviceId, long ts, String lineCode, int upDown, String stopNo, int inOut, long createDate,
  47 + int weeksYear, String stopName) {
  48 +
  49 + this.deviceId = deviceId;
  50 + this.ts = ts;
  51 + this.lineCode = lineCode;
  52 + this.upDown = upDown;
  53 + this.stopNo = stopNo;
  54 + this.stopName = stopName;
  55 + this.inOut = inOut;
  56 + this.createDate = createDate;
  57 + }
  58 +
  59 + @Override
  60 + public boolean equals(Object obj) {
  61 + ArrivalEntity a2 = (ArrivalEntity)obj;
  62 +
  63 + return this.toString().equals(a2.toString())
  64 + && Math.abs(this.ts - a2.ts) < EQ_RANGE;
  65 + }
  66 +
  67 + @Override
  68 + public int hashCode() {
  69 + return this.toString().hashCode();
  70 + }
  71 +
  72 +
  73 + @Override
  74 + public String toString() {
  75 + return this.deviceId + "_" + this.inOut + "_" + this.stopName;
  76 + }
84 77
85 public String getLineCode() { 78 public String getLineCode() {
86 return lineCode; 79 return lineCode;
@@ -157,4 +150,13 @@ public class ArrivalInfo { @@ -157,4 +150,13 @@ public class ArrivalInfo {
157 public String getId(){ 150 public String getId(){
158 return this.deviceId + "_" + this.ts; 151 return this.deviceId + "_" + this.ts;
159 } 152 }
  153 +
  154 + public String getNbbm() {
  155 + return nbbm;
  156 + }
  157 +
  158 + public void setNbbm(String nbbm) {
  159 + this.nbbm = nbbm;
  160 + }
  161 +
160 } 162 }
src/main/java/com/bsth/data/arrival/DataLoader.java 0 → 100644
  1 +package com.bsth.data.arrival;
  2 +
  3 +import java.sql.Connection;
  4 +import java.sql.PreparedStatement;
  5 +import java.sql.ResultSet;
  6 +import java.sql.SQLException;
  7 +import java.util.Calendar;
  8 +import java.util.Collection;
  9 +import java.util.Date;
  10 +import java.util.HashSet;
  11 +import java.util.Set;
  12 +
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import com.bsth.data.BasicData;
  19 +import com.bsth.data.LineConfigData;
  20 +import com.bsth.entity.realcontrol.LineConfig;
  21 +import com.bsth.util.DateUtils;
  22 +import com.bsth.util.db.DBUtils_MS;
  23 +
  24 +/**
  25 + *
  26 + * @ClassName: DataLoader
  27 + * @Description: TODO(从数据库加载进出站数据)
  28 + * @author PanZhao
  29 + * @date 2016年8月19日 上午9:59:21
  30 + *
  31 + */
  32 +@Component
  33 +public class DataLoader {
  34 +
  35 + private static Long prveLoadTime;
  36 +
  37 + private final static long DAY_TIME = 1000 * 60 * 60 * 24;
  38 +
  39 + private Logger logger = LoggerFactory.getLogger(this.getClass());
  40 +
  41 + @Autowired
  42 + LineConfigData lineConfigData;
  43 +
  44 + /**
  45 + *
  46 + * @Title: load
  47 + * @Description: TODO(根据上次加载时间,查询之后的增量数据)
  48 + */
  49 + public Set<ArrivalEntity> load(){
  50 + Set<ArrivalEntity> set = null;
  51 +
  52 + if(null == prveLoadTime)
  53 + set = recovery();
  54 + else{
  55 + Calendar cal = Calendar.getInstance();
  56 + //周数,表分区字段
  57 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  58 +
  59 + Connection conn = null;
  60 + PreparedStatement ps = null;
  61 + ResultSet rs = null;
  62 +
  63 + String sql = "select * from bsth_c_arrival_info where weeks_year=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  64 + try{
  65 + long t = System.currentTimeMillis() /*prveLoadTime + (1000 * 60 * 60)*/;
  66 +
  67 + conn = DBUtils_MS.getConnection();
  68 + ps = conn.prepareStatement(sql);
  69 + ps.setInt(1, weeks_year);
  70 + ps.setLong(2, prveLoadTime);
  71 + ps.setLong(3, t);
  72 + rs = ps.executeQuery();
  73 +
  74 + set = resultSet2Set(rs);
  75 +
  76 + prveLoadTime = t;
  77 + }catch(Exception e){
  78 + logger.error("", e);
  79 + }finally {
  80 + DBUtils_MS.close(rs, ps, conn);
  81 + }
  82 + }
  83 + return set;
  84 + }
  85 +
  86 + /**
  87 + *
  88 + * @Title: recovery
  89 + * @Description: TODO(从数据库恢复数据,按照线路的开始运营时间恢复)
  90 + */
  91 + public Set<ArrivalEntity> recovery(){
  92 + Collection<LineConfig> confs = lineConfigData.getAll();
  93 + long t = System.currentTimeMillis()
  94 + ,st;
  95 +
  96 + Set<ArrivalEntity> all = new HashSet<>();
  97 + for(LineConfig conf : confs){
  98 + st = conf.getCurrStartTime();
  99 + if(t < st)
  100 + st = st - DAY_TIME;
  101 +
  102 + all.addAll(loadByLineAndTime(conf.getLine().getLineCode(), st, t));
  103 + }
  104 +
  105 + prveLoadTime = t;
  106 + return all;
  107 + }
  108 +
  109 + /**
  110 + *
  111 + * @Title: loadByLineAndStartTime
  112 + * @Description: TODO(根据线路和时间戳加载数据)
  113 + */
  114 + public Set<ArrivalEntity> loadByLineAndTime(String lineCode, long st, long et){
  115 + Calendar cal = Calendar.getInstance();
  116 + cal.setTimeInMillis(st);
  117 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  118 +
  119 + Connection conn = null;
  120 + PreparedStatement ps = null;
  121 + ResultSet rs = null;
  122 +
  123 + Set<ArrivalEntity> set = new HashSet<>();
  124 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  125 + try{
  126 + conn = DBUtils_MS.getConnection();
  127 + ps = conn.prepareStatement(sql);
  128 + ps.setInt(1, weeks_year);
  129 + ps.setString(2, lineCode);
  130 + ps.setLong(3, st);
  131 + ps.setLong(4, et);
  132 + rs = ps.executeQuery();
  133 +
  134 + set = resultSet2Set(rs);
  135 +
  136 + System.out.println("加载 " + BasicData.lineCode2NameMap.get(lineCode) + DateUtils.sdfyyyyMMddHHmm.format(new Date(st))
  137 + + "至" + DateUtils.sdfyyyyMMddHHmm.format(new Date(et)) + " 数据,共:" + set.size());
  138 + }catch(Exception e){
  139 + logger.error("", e);
  140 + }finally {
  141 + DBUtils_MS.close(rs, ps, conn);
  142 + }
  143 + return set;
  144 + }
  145 +
  146 + public Set<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{
  147 + Set<ArrivalEntity> set = new HashSet<>();
  148 +
  149 + ArrivalEntity arr;
  150 + while(rs.next()){
  151 + arr = new ArrivalEntity();
  152 + arr.setDeviceId(rs.getString("device_id"));
  153 + arr.setNbbm(BasicData.deviceId2NbbmMap.get(arr.getDeviceId()));
  154 + if(null == arr.getNbbm()){
  155 + logger.warn("未注册的设备号," + arr.getDeviceId());
  156 + continue;
  157 + }
  158 +
  159 + arr.setTs(rs.getLong("ts"));
  160 + arr.setLineCode(rs.getString("line_id"));
  161 + arr.setUpDown(rs.getInt("up_down"));
  162 + arr.setStopNo(rs.getString("stop_no"));
  163 + arr.setStopName(BasicData.stationCode2NameMap.get(arr.getStopNo()));
  164 + arr.setInOut(rs.getInt("in_out"));
  165 + arr.setCreateDate(rs.getLong("create_timestamp"));
  166 + arr.setWeeksYear(rs.getInt("weeks_year"));
  167 +
  168 + set.add(arr);
  169 + }
  170 + return set;
  171 + }
  172 +
  173 + public static void setPrveLoadTime(long t){
  174 + prveLoadTime = t;
  175 + }
  176 +}
src/main/java/com/bsth/data/directive/DayOfDirectives.java 0 → 100644
  1 +package com.bsth.data.directive;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collection;
  5 +import java.util.Comparator;
  6 +import java.util.HashMap;
  7 +import java.util.List;
  8 +import java.util.Map;
  9 +
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import com.alibaba.fastjson.JSONObject;
  16 +import com.bsth.data.LineConfigData;
  17 +import com.bsth.entity.directive.D60;
  18 +import com.bsth.entity.directive.D64;
  19 +import com.bsth.entity.directive.Directive;
  20 +import com.bsth.entity.directive.DirectiveReponse;
  21 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  22 +import com.bsth.service.directive.DirectiveService;
  23 +import com.bsth.websocket.handler.SendUtils;
  24 +
  25 +/**
  26 + *
  27 + * @ClassName: CurrDayDirectives
  28 + * @Description: TODO(当天指令数据)
  29 + * @author PanZhao
  30 + * @date 2016年8月14日 下午5:23:59
  31 + *
  32 + */
  33 +@Component
  34 +public class DayOfDirectives {
  35 +
  36 + // 当日60指令缓存
  37 + private static Map<Integer, D60> d60Map;
  38 +
  39 + // 线路切换指令 64
  40 + public static Map<String, D64> d64Map;
  41 +
  42 + @Autowired
  43 + DirectiveService directiveService;
  44 +
  45 + @Autowired
  46 + SendUtils sendUtils;
  47 +
  48 + @Autowired
  49 + LineConfigData lineConfigData;
  50 +
  51 + static Logger logger = LoggerFactory.getLogger(DayOfDirectives.class);
  52 +
  53 +
  54 + static{
  55 + d60Map = new HashMap<>();
  56 + d64Map = new HashMap<>();
  57 + }
  58 +
  59 + public void put60(D60 d60) {
  60 + d60Map.put(d60.getMsgId(), d60);
  61 + }
  62 +
  63 + public void put64(D64 d64) {
  64 + d64Map.put(d64.getKey(), d64);
  65 + }
  66 +
  67 + /**
  68 + *
  69 + * @Title: reply @Description: TODO(指令 46,47 响应) @throws
  70 + */
  71 + public void reply(DirectiveReponse res) {
  72 + Integer msgId = res.getMsgId();
  73 + if (msgId == null) {
  74 + logger.error("reply error , msgId is null.");
  75 + return;
  76 + }
  77 +
  78 + D60 d60 = d60Map.get(msgId);
  79 +
  80 + if (null == d60) {
  81 + logger.error("找不到msgId: " + msgId + " 对应的指令数据");
  82 + return;
  83 + }
  84 +
  85 + switch (res.getStatus()) {
  86 + case 0:
  87 + d60.setReply46((short) -1);// 失败
  88 + break;
  89 + case 1:
  90 + d60.setReply46((short) 0);// 发送成功
  91 + break;
  92 + case 2:
  93 + d60.setReply47((short) 0);// 驾驶员阅读
  94 + break;
  95 + }
  96 + // 入库
  97 + saveD60(d60);
  98 +
  99 + ScheduleRealInfo sch = d60.getSch();
  100 + if (null == sch)
  101 + return;
  102 +
  103 + if (d60.isDispatch()) {
  104 + // 更新班次状态
  105 + sch.setDirectiveState(res.getStatus() * 100);
  106 + // 通知页面
  107 + sendUtils.sendDirectiveToPage(sch);
  108 + }
  109 + }
  110 +
  111 + /**
  112 + *
  113 + * @Title: reply64 @Description: TODO(64 协议响应) @throws
  114 + */
  115 + public void reply64(JSONObject json) {
  116 + String key = json.getString("deviceId") + "_" + json.getString("timestamp");
  117 +
  118 + D64 d64 = d64Map.get(key);
  119 +
  120 + if (null == d64)
  121 + logger.warn("64响应 -找不到请求源,json: " + json);
  122 + else {
  123 + JSONObject data = json.getJSONObject("data");
  124 +
  125 + if (null == data)
  126 + logger.warn("64响应 data is null ,json: " + json);
  127 + else {
  128 + d64.setRespAck(data.getShort("requestAck"));
  129 + // 响应入库
  130 + directiveService.save64(d64);
  131 + }
  132 + }
  133 + }
  134 +
  135 + private void saveD60(D60 d60) {
  136 + // 调度指令等47再入库
  137 + if (d60.isDispatch() && d60.getReply47() == null)
  138 + return;
  139 +
  140 + directiveService.save(d60);
  141 + }
  142 +
  143 + public void clear(String device){
  144 + int c60 = 0, c64 = 0;
  145 + //清除60
  146 + Collection<D60> d60s = d60Map.values();
  147 + for(D60 d60 : d60s){
  148 + if(d60.getDeviceId().equals(device)){
  149 + directiveService.save(d60);
  150 + if(null != d60Map.remove(d60.getMsgId()))
  151 + c60 ++;
  152 + }
  153 + }
  154 + logger.info("清除60数据 ," + c60);
  155 +
  156 + //清除64
  157 + Collection<D64> d64s = d64Map.values();
  158 + for(D64 d64 : d64s){
  159 + if(d64.getDeviceId().equals(device)){
  160 + directiveService.save64(d64);
  161 + if(null != d64Map.remove(d64.getKey()))
  162 + c64 ++;
  163 + }
  164 + }
  165 +
  166 + logger.info("清除64数据 ," + c64);
  167 + }
  168 +
  169 + public Collection<D60> all60(){
  170 + return d60Map.values();
  171 + }
  172 +
  173 + public Collection<D64> all64(){
  174 + return d64Map.values();
  175 + }
  176 +
  177 + public Collection<Directive> all(){
  178 + List<Directive> all = new ArrayList<>();
  179 + all.addAll(d60Map.values());
  180 + all.addAll(d64Map.values());
  181 +
  182 + return all;
  183 + }
  184 +
  185 + public static class DComparator implements Comparator<Directive>{
  186 +
  187 + @Override
  188 + public int compare(Directive d1, Directive d2) {
  189 + return (int) (d2.getTimestamp() - d1.getTimestamp());
  190 + }
  191 + }
  192 + }
src/main/java/com/bsth/vehicle/directive/util/DirectiveDataFactory.java renamed to src/main/java/com/bsth/data/directive/DirectiveCreator.java
1 -package com.bsth.vehicle.directive.util; 1 +package com.bsth.data.directive;
2 2
3 import java.text.SimpleDateFormat; 3 import java.text.SimpleDateFormat;
4 import java.util.Date; 4 import java.util.Date;
@@ -9,30 +9,26 @@ import org.slf4j.Logger; @@ -9,30 +9,26 @@ import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
10 10
11 import com.alibaba.fastjson.JSON; 11 import com.alibaba.fastjson.JSON;
12 -import com.bsth.vehicle.common.CommonMapped;  
13 -import com.bsth.vehicle.directive.Consts;  
14 -import com.bsth.vehicle.directive.MsgIdGenerator;  
15 -import com.bsth.vehicle.directive.entity.Directive60;  
16 -import com.bsth.vehicle.directive.entity.Directive64;  
17 -import com.bsth.vehicle.directive.entity.Directive60.DirectiveData;  
18 -import com.bsth.vehicle.directive.entity.Directive64.LineChangeData; 12 +import com.bsth.data.BasicData;
  13 +import com.bsth.entity.directive.D60;
  14 +import com.bsth.entity.directive.D60.D60Data;
  15 +import com.bsth.entity.directive.D64;
  16 +import com.bsth.entity.directive.D64.D64Data;
19 17
20 /** 18 /**
21 * 19 *
22 - * @ClassName: DirectiveDataFactory  
23 - * @Description: TODO(生成调度指令数据) 20 + * @ClassName: DirectiveCreator
  21 + * @Description: TODO(指令数据生成)
24 * @author PanZhao 22 * @author PanZhao
25 - * @date 2016年8月3日 下午3:32:27 23 + * @date 2016年8月14日 下午9:57:07
26 * 24 *
27 */ 25 */
28 -public class DirectiveDataFactory { 26 +public class DirectiveCreator {
29 27
30 - private DirectiveDataFactory() {}  
31 -  
32 // 城市代码 28 // 城市代码
33 static final short cityCode = 22; 29 static final short cityCode = 22;
34 30
35 - static Logger logger = LoggerFactory.getLogger(DirectiveDataFactory.class); 31 + static Logger logger = LoggerFactory.getLogger(DirectiveCreator.class);
36 32
37 /** 33 /**
38 * 34 *
@@ -47,16 +43,16 @@ public class DirectiveDataFactory { @@ -47,16 +43,16 @@ public class DirectiveDataFactory {
47 * @return Directive60 返回类型 43 * @return Directive60 返回类型
48 * @throws 44 * @throws
49 */ 45 */
50 - public static Directive60 createDirective60(String nbbm, String text, Short dispatchInstruct, int upDown, int state) { 46 + public static D60 createD60(String nbbm, String text, Short dispatchInstruct, int upDown, int state) {
51 Long timestamp = System.currentTimeMillis(); 47 Long timestamp = System.currentTimeMillis();
52 48
53 - Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm));  
54 - String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); 49 + Short company = Short.parseShort(BasicData.nbbm2CompanyCodeMap.get(nbbm));
  50 + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
55 51
56 int msgId = MsgIdGenerator.getMsgId(); 52 int msgId = MsgIdGenerator.getMsgId();
57 53
58 - Directive60 directive = new Directive60();  
59 - DirectiveData data = new DirectiveData(); 54 + D60 directive = new D60();
  55 + D60Data data = new D60Data();
60 // 一级协议 56 // 一级协议
61 directive.setOperCode((short) 0x60); 57 directive.setOperCode((short) 0x60);
62 // 设备号 58 // 设备号
@@ -86,16 +82,16 @@ public class DirectiveDataFactory { @@ -86,16 +82,16 @@ public class DirectiveDataFactory {
86 82
87 83
88 static SimpleDateFormat sdfMMddHHmm = new SimpleDateFormat("MMddHHmm"); 84 static SimpleDateFormat sdfMMddHHmm = new SimpleDateFormat("MMddHHmm");
89 - public static Directive60 createDirective6002(String nbbm, String text, Short dispatchInstruct, int upDown, int state, Date alarmTime){ 85 + public static D60 createD60_02(String nbbm, String text, int upDown, int state, Date alarmTime){
90 Long timestamp = System.currentTimeMillis(); 86 Long timestamp = System.currentTimeMillis();
91 87
92 - Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm));  
93 - String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); 88 + Short company = Short.parseShort(BasicData.nbbm2CompanyCodeMap.get(nbbm));
  89 + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
94 90
95 int msgId = MsgIdGenerator.getMsgId(); 91 int msgId = MsgIdGenerator.getMsgId();
96 92
97 - Directive60 directive = new Directive60();  
98 - DirectiveData data = new DirectiveData(); 93 + D60 directive = new D60();
  94 + D60Data data = new D60Data();
99 // 一级协议 95 // 一级协议
100 directive.setOperCode((short) 0x60); 96 directive.setOperCode((short) 0x60);
101 // 设备号 97 // 设备号
@@ -105,7 +101,7 @@ public class DirectiveDataFactory { @@ -105,7 +101,7 @@ public class DirectiveDataFactory {
105 directive.setMsgId(msgId); 101 directive.setMsgId(msgId);
106 // 构造数据 102 // 构造数据
107 data.setDeviceId(deviceId); 103 data.setDeviceId(deviceId);
108 - data.setDispatchInstruct(dispatchInstruct); 104 + data.setDispatchInstruct((short) 0x02);
109 data.setTimestamp(timestamp); 105 data.setTimestamp(timestamp);
110 data.setCompanyCode(company); 106 data.setCompanyCode(company);
111 data.setMsgId(msgId); 107 data.setMsgId(msgId);
@@ -132,19 +128,19 @@ public class DirectiveDataFactory { @@ -132,19 +128,19 @@ public class DirectiveDataFactory {
132 * @param @param t 时间戳 128 * @param @param t 时间戳
133 * @throws 129 * @throws
134 */ 130 */
135 - public static Directive64 createDirective64(String nbbm, Integer lineCode, long t){  
136 - String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); 131 + public static D64 createD64(String nbbm, Integer lineCode, long t){
  132 + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
137 133
138 - Directive64 change = new Directive64();  
139 - LineChangeData data = new LineChangeData(); 134 + D64 change = new D64();
  135 + D64Data data = new D64Data();
140 data.setCityCode(cityCode); 136 data.setCityCode(cityCode);
141 data.setDeviceId(deviceId); 137 data.setDeviceId(deviceId);
142 //线路编码补满6位数 138 //线路编码补满6位数
143 - if(lineCode > 99999){ 139 + if(lineCode > 999999){
144 logger.error("线路编码不能超过6位,code:" + lineCode); 140 logger.error("线路编码不能超过6位,code:" + lineCode);
145 return null; 141 return null;
146 } 142 }
147 - String lineCodeStr = String.format("%06d", lineCode.toString()); 143 + String lineCodeStr = String.format("%06d", lineCode);
148 data.setLineId(lineCodeStr); 144 data.setLineId(lineCodeStr);
149 145
150 change.setDeviceId(deviceId); 146 change.setDeviceId(deviceId);
@@ -163,24 +159,36 @@ public class DirectiveDataFactory { @@ -163,24 +159,36 @@ public class DirectiveDataFactory {
163 * @param @param lineId 线路ID 159 * @param @param lineId 线路ID
164 * @throws 160 * @throws
165 */ 161 */
166 - public static String createDeviceRefreshData(String deviceId, Integer lineId) { 162 + public static String createDeviceRefreshData(String deviceId, Integer lineCode) {
167 Long t = System.currentTimeMillis(); 163 Long t = System.currentTimeMillis();
168 - Map<String, Object> param = new HashMap<String, Object>(); 164 + Map<String, Object> param = new HashMap<>();
169 param.put("deviceId", deviceId); 165 param.put("deviceId", deviceId);
170 param.put("timestamp", t); 166 param.put("timestamp", t);
171 param.put("operCode", 0Xc0); 167 param.put("operCode", 0Xc0);
172 168
173 - Map<String, Object> data = new HashMap<String, Object>(); 169 + Map<String, Object> data = new HashMap<>();
174 data.put("operCode2", 0xa1); 170 data.put("operCode2", 0xa1);
175 data.put("cityCode", cityCode); 171 data.put("cityCode", cityCode);
176 data.put("deviceId", deviceId); 172 data.put("deviceId", deviceId);
177 data.put("timestamp", t); 173 data.put("timestamp", t);
178 data.put("centerId", 1); 174 data.put("centerId", 1);
179 - data.put("lineId", lineId); 175 +
  176 + //线路编码补满6位数
  177 + if(lineCode > 999999){
  178 + logger.error("线路编码不能超过6位,code:" + lineCode);
  179 + return null;
  180 + }
  181 + String lineCodeStr = String.format("%06d", lineCode);
  182 +
  183 + data.put("lineId", lineCodeStr);
180 data.put("lineVersion", 0); 184 data.put("lineVersion", 0);
181 data.put("carparkDataVersion", 0); 185 data.put("carparkDataVersion", 0);
182 param.put("data", data); 186 param.put("data", data);
183 187
184 return JSON.toJSONString(param); 188 return JSON.toJSONString(param);
185 } 189 }
  190 +
  191 + public static void main(String[] args) {
  192 + System.out.println(String.format("%06d", "1025"));
  193 + }
186 } 194 }
src/main/java/com/bsth/vehicle/directive/util/HttpUtils.java renamed to src/main/java/com/bsth/data/directive/GatewayHttpUtils.java
1 -package com.bsth.vehicle.directive.util; 1 +package com.bsth.data.directive;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 4
@@ -17,15 +17,14 @@ import com.bsth.util.ConfigUtil; @@ -17,15 +17,14 @@ import com.bsth.util.ConfigUtil;
17 17
18 /** 18 /**
19 * 19 *
20 - * @ClassName: HttpUtils 20 + * @ClassName: GatewayHttpUtils
21 * @Description: TODO(和网关HTTP通讯工具类) 21 * @Description: TODO(和网关HTTP通讯工具类)
22 * @author PanZhao 22 * @author PanZhao
23 - * @date 2016年7月8日 上午10:38:10 23 + * @date 2016年8月14日 下午9:50:46
24 * 24 *
25 */ 25 */
26 -public class HttpUtils {  
27 -  
28 - static Logger logger = LoggerFactory.getLogger(HttpUtils.class); 26 +public class GatewayHttpUtils {
  27 + static Logger logger = LoggerFactory.getLogger(GatewayHttpUtils.class);
29 28
30 static String url; 29 static String url;
31 30
src/main/java/com/bsth/data/gpsdata/GpsRealEntity.java renamed to src/main/java/com/bsth/data/gpsdata/GpsEntity.java
@@ -8,7 +8,7 @@ package com.bsth.data.gpsdata; @@ -8,7 +8,7 @@ package com.bsth.data.gpsdata;
8 * @date 2016年5月11日 下午4:32:07 8 * @date 2016年5月11日 下午4:32:07
9 * 9 *
10 */ 10 */
11 -public class GpsRealEntity { 11 +public class GpsEntity {
12 12
13 /** 公司代码 */ 13 /** 公司代码 */
14 private Integer companyCode; 14 private Integer companyCode;
src/main/java/com/bsth/data/gpsdata/GpsRealData.java 0 → 100644
  1 +package com.bsth.data.gpsdata;
  2 +
  3 +import java.io.BufferedReader;
  4 +import java.io.InputStreamReader;
  5 +import java.util.ArrayList;
  6 +import java.util.HashMap;
  7 +import java.util.List;
  8 +import java.util.Map;
  9 +import java.util.NavigableSet;
  10 +
  11 +import org.apache.http.HttpEntity;
  12 +import org.apache.http.client.methods.CloseableHttpResponse;
  13 +import org.apache.http.client.methods.HttpGet;
  14 +import org.apache.http.impl.client.CloseableHttpClient;
  15 +import org.apache.http.impl.client.HttpClients;
  16 +import org.slf4j.Logger;
  17 +import org.slf4j.LoggerFactory;
  18 +import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.boot.CommandLineRunner;
  20 +import org.springframework.stereotype.Component;
  21 +
  22 +import com.alibaba.fastjson.JSON;
  23 +import com.alibaba.fastjson.JSONObject;
  24 +import com.bsth.data.BasicData;
  25 +import com.bsth.util.ConfigUtil;
  26 +import com.google.common.collect.TreeMultimap;
  27 +
  28 +/**
  29 + *
  30 + * @ClassName: GpsRealEntityBuffer
  31 + * @Description: TODO(实时GPS数据集合)
  32 + * @author PanZhao
  33 + * @date 2016年8月12日 下午2:04:41
  34 + *
  35 + */
  36 +@Component
  37 +public class GpsRealData implements CommandLineRunner{
  38 +
  39 + static Logger logger = LoggerFactory.getLogger(GpsRealData.class);
  40 +
  41 + private static Map<String, GpsEntity> gpsMap;
  42 +
  43 + //按线路分组设备号
  44 + private static TreeMultimap<Integer, String> lineCode2Devices;
  45 +
  46 + // 网关数据接口地址
  47 + private static String url;
  48 +
  49 + @Autowired
  50 + GpsDataLoader gpsDataLoader;
  51 +
  52 + /**
  53 + * 构造函数
  54 + */
  55 + public GpsRealData(){
  56 + gpsMap = new HashMap<>();
  57 + lineCode2Devices = TreeMultimap.create();
  58 + url = ConfigUtil.get("http.gps.real.url");
  59 + }
  60 +
  61 + @Override
  62 + public void run(String... arg0) throws Exception {
  63 + //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 8, TimeUnit.SECONDS);
  64 + }
  65 +
  66 + public static GpsEntity add(GpsEntity gps) {
  67 + String device = gps.getDeviceId();
  68 + gpsMap.put(device, gps);
  69 + lineCode2Devices.put(gps.getLineId(), device);
  70 + return gps;
  71 + }
  72 +
  73 + /**
  74 + *
  75 + * @Title: get @Description: TODO(设备号获取GPS)
  76 + */
  77 + public GpsEntity get(String deviceId) {
  78 + return gpsMap.get(deviceId);
  79 + }
  80 +
  81 + /**
  82 + *
  83 + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
  84 + */
  85 + public List<GpsEntity> get(Integer lineCode) {
  86 + NavigableSet<String> set = lineCode2Devices.get(lineCode);
  87 +
  88 + List<GpsEntity> rs = new ArrayList<>();
  89 + for(String device : set){
  90 + rs.add(gpsMap.get(device));
  91 + }
  92 +
  93 + return rs;
  94 + }
  95 +
  96 + public List<GpsEntity> get(List<String> pArray){
  97 + List<GpsEntity> list = new ArrayList<>();
  98 +
  99 + for(String code : pArray)
  100 + list.addAll(get(Integer.parseInt(code)));
  101 + return list;
  102 + }
  103 +
  104 + public GpsEntity findByDeviceId(String deviceId) {
  105 + return gpsMap.get(deviceId);
  106 + }
  107 +
  108 + @Component
  109 + public static class GpsDataLoader extends Thread{
  110 +
  111 + Logger logger = LoggerFactory.getLogger(GpsDataLoader.class);
  112 +
  113 + @Override
  114 + public void run() {
  115 + try{
  116 + load();
  117 + }catch(Exception e){
  118 + logger.error("", e);
  119 + }
  120 + }
  121 +
  122 + public void load() throws Exception {
  123 + List<GpsEntity> list = new ArrayList<>();
  124 + CloseableHttpClient httpClient = null;
  125 + CloseableHttpResponse response = null;
  126 + try {
  127 + httpClient = HttpClients.createDefault();
  128 + HttpGet get = new HttpGet(url);
  129 +
  130 + response = httpClient.execute(get);
  131 +
  132 + HttpEntity entity = response.getEntity();
  133 + if (null != entity) {
  134 + // 返回数据量比较大,建议以流的形式读取
  135 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  136 + StringBuffer stringBuffer = new StringBuffer();
  137 + String str = "";
  138 + while ((str = br.readLine()) != null)
  139 + stringBuffer.append(str);
  140 +
  141 + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
  142 +
  143 + if (jsonObj != null)
  144 + list = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
  145 +
  146 + //附加车辆内部编码
  147 + for(GpsEntity gps : list){
  148 + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
  149 + gps.setStationName(BasicData.stationCode2NameMap.get(gps.getStopNo()));
  150 + add(gps);
  151 + }
  152 + } else
  153 + logger.error("result is null");
  154 + } finally {
  155 + if (null != httpClient)
  156 + httpClient.close();
  157 + if(null != response)
  158 + response.close();
  159 + }
  160 + }
  161 + }
  162 +}
src/main/java/com/bsth/data/gpsdata/GpsRealDataList.java deleted 100644 → 0
1 -//package com.bsth.data.gpsdata;  
2 -//  
3 -//import java.io.BufferedReader;  
4 -//import java.io.InputStreamReader;  
5 -//import java.util.ArrayList;  
6 -//import java.util.HashMap;  
7 -//import java.util.List;  
8 -//import java.util.Map;  
9 -//import java.util.NavigableSet;  
10 -//  
11 -//import org.apache.http.HttpEntity;  
12 -//import org.apache.http.client.methods.CloseableHttpResponse;  
13 -//import org.apache.http.client.methods.HttpGet;  
14 -//import org.apache.http.impl.client.CloseableHttpClient;  
15 -//import org.apache.http.impl.client.HttpClients;  
16 -//import org.slf4j.Logger;  
17 -//import org.slf4j.LoggerFactory;  
18 -//  
19 -//import com.alibaba.fastjson.JSON;  
20 -//import com.alibaba.fastjson.JSONObject;  
21 -//import com.bsth.data.BasicData;  
22 -//import com.bsth.util.ConfigUtil;  
23 -//import com.bsth.vehicle.gpsdata.entity.GpsRealData;  
24 -//import com.google.common.collect.TreeMultimap;  
25 -//  
26 -///**  
27 -// *  
28 -// * @ClassName: GpsRealDataBuffer  
29 -// * @Description: TODO(实时GPS数据集合)  
30 -// * @author PanZhao  
31 -// * @date 2016年8月12日 下午2:04:41  
32 -// *  
33 -// */  
34 -//public class GpsRealDataList {  
35 -//  
36 -// private static Map<String, GpsRealData> gpsMap;  
37 -//  
38 -// private static TreeMultimap<Integer, String> lineCode2Devices;  
39 -//  
40 -// // 网关数据接口地址  
41 -// private static String url;  
42 -//  
43 -// static{  
44 -// gpsMap = new HashMap<>();  
45 -// lineCode2Devices = TreeMultimap.create();  
46 -// url = ConfigUtil.get("http.gps.real.url");  
47 -// }  
48 -//  
49 -// static Logger logger = LoggerFactory.getLogger(GpsRealDataList.class);  
50 -//  
51 -// public static GpsRealData add(GpsRealData gps) {  
52 -// String device = gps.getDeviceId();  
53 -// gpsMap.put(device, gps);  
54 -// lineCode2Devices.put(gps.getLineId(), device);  
55 -// return gps;  
56 -// }  
57 -//  
58 -// /**  
59 -// *  
60 -// * @Title: get @Description: TODO(设备号获取GPS) @param @param deviceId @throws  
61 -// */  
62 -// public static GpsRealData get(String deviceId) {  
63 -// return gpsMap.get(deviceId);  
64 -// }  
65 -//  
66 -// /**  
67 -// *  
68 -// * @Title: get @Description: TODO(线路编码获取GPS集合) @throws  
69 -// */  
70 -// public static List<GpsRealData> get(Integer lineCode) {  
71 -// NavigableSet<String> set = lineCode2Devices.get(lineCode);  
72 -//  
73 -// List<GpsRealData> rs = new ArrayList<>();  
74 -// for(String device : set){  
75 -// rs.add(gpsMap.get(device));  
76 -// }  
77 -//  
78 -// return rs;  
79 -// }  
80 -//  
81 -// public static void LoadGpsRealData() throws Exception {  
82 -// List<GpsRealData> list = new ArrayList<>();  
83 -// CloseableHttpClient httpClient = null;  
84 -//  
85 -// try {  
86 -// httpClient = HttpClients.createDefault();  
87 -// HttpGet get = new HttpGet(url);  
88 -//  
89 -// CloseableHttpResponse response = httpClient.execute(get);  
90 -//  
91 -// try {  
92 -// HttpEntity entity = response.getEntity();  
93 -// if (null != entity) {  
94 -// // 返回数据量比较大,建议以流的形式读取  
95 -// BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));  
96 -// StringBuffer stringBuffer = new StringBuffer();  
97 -// String str = "";  
98 -// while ((str = br.readLine()) != null)  
99 -// stringBuffer.append(str);  
100 -//  
101 -// JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());  
102 -//  
103 -// if (jsonObj != null)  
104 -// list = JSON.parseArray(jsonObj.getString("data"), GpsRealData.class);  
105 -//  
106 -// for(GpsRealData gps : list){  
107 -// gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps));  
108 -// add(gps);  
109 -// }  
110 -// } else  
111 -// logger.error("result is null");  
112 -// } finally {  
113 -// response.close();  
114 -// }  
115 -//  
116 -// } finally {  
117 -// if (null != httpClient)  
118 -// httpClient.close();  
119 -// }  
120 -// }  
121 -//}  
src/main/java/com/bsth/data/match/Arrival2Schedule.java 0 → 100644
  1 +package com.bsth.data.match;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collections;
  5 +import java.util.List;
  6 +import java.util.Set;
  7 +
  8 +import org.springframework.beans.BeansException;
  9 +import org.springframework.context.ApplicationContext;
  10 +import org.springframework.context.ApplicationContextAware;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import com.bsth.data.arrival.ArrivalComparator;
  14 +import com.bsth.data.arrival.ArrivalData_GPS;
  15 +import com.bsth.data.arrival.ArrivalEntity;
  16 +import com.bsth.data.schedule.DayOfSchedule;
  17 +import com.bsth.data.schedule.ScheduleComparator;
  18 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  19 +import com.bsth.service.directive.DirectiveService;
  20 +import com.bsth.websocket.handler.SendUtils;
  21 +
  22 +/**
  23 + *
  24 + * @ClassName: Arrival2Schedule
  25 + * @Description: TODO(进出数据匹配班次)
  26 + * @author PanZhao
  27 + * @date 2016年8月10日 下午2:26:22
  28 + *
  29 + */
  30 +@Component
  31 +public class Arrival2Schedule implements ApplicationContextAware{
  32 +
  33 + private static ScheduleComparator.FCSJ schComparator;
  34 + private static ArrivalComparator arrComparator;
  35 + private static SendUtils sendUtils;
  36 + private static DayOfSchedule dayOfSchedule;
  37 + private static DirectiveService directiveService;
  38 +
  39 + private final static long MAX_RANGE = 1000 * 60 * 60 * 4L;
  40 +
  41 + static{
  42 + schComparator = new ScheduleComparator.FCSJ();
  43 + arrComparator = new ArrivalComparator();
  44 + }
  45 +
  46 + /**
  47 + *
  48 + * @Title: start
  49 + * @Description: TODO(开始)
  50 + * @param @param cars 需要匹配的车辆集合
  51 + */
  52 + public static void start(Set<String> cars){
  53 +
  54 + for(String car : cars){
  55 + new GpsMatchThread(car).start();
  56 + }
  57 + }
  58 +
  59 + public static class GpsMatchThread extends Thread{
  60 +
  61 + String nbbm;
  62 + public GpsMatchThread(String nbbm){
  63 + this.nbbm = nbbm;
  64 + }
  65 +
  66 + @Override
  67 + public void run() {
  68 + //班次列表
  69 + List<ScheduleRealInfo> schList = dayOfSchedule.findByNbbm(nbbm);
  70 + //进出起终点数据
  71 + List<ArrivalEntity> arrList = ArrivalData_GPS.getIncrement(nbbm);
  72 + System.out.println("####匹配进出站增量数据 " + arrList.size());
  73 + //排序
  74 + Collections.sort(schList, schComparator);
  75 + Collections.sort(arrList, arrComparator);
  76 +
  77 + int si = lastMatchPoint(schList);
  78 + int ai = afterByTime(arrList, lastMatchTime(schList.get(si)));
  79 +
  80 + //按起始索引开始匹配
  81 + match(arrList, ai, schList, si);
  82 + }
  83 +
  84 + public void match(List<ArrivalEntity> arrList, int ai, List<ScheduleRealInfo> schList, int si){
  85 +
  86 + int sLen = schList.size();
  87 + for(; si < sLen; si ++)
  88 + match(arrList, ai, schList.get(si));
  89 + }
  90 +
  91 + public void match(List<ArrivalEntity> arrList, int ai, ScheduleRealInfo sch){
  92 + //烂班不参与
  93 + if(sch.isDestroy())
  94 + return;
  95 +
  96 + int aLen = arrList.size();
  97 +
  98 + List<MatchResult> inRsList = new ArrayList<>()
  99 + ,outRsList = new ArrayList<>();
  100 +
  101 + MatchResult mrs;
  102 + for(;ai < aLen; ai ++){
  103 + mrs = match(arrList.get(ai), sch);
  104 + if(!mrs.success)
  105 + continue;
  106 +
  107 + if(mrs.inOut == 0)
  108 + inRsList.add(mrs);
  109 + else if(mrs.inOut == 1)
  110 + outRsList.add(mrs);
  111 + }
  112 +
  113 + if(outRsList.size() > 0){
  114 + //排序后的第一个 就是最合适的匹配
  115 + Collections.sort(outRsList, new MatchResultComparator());
  116 + mrs = outRsList.get(0);
  117 +
  118 + mrs.sch.setFcsjActualAll(mrs.ts);
  119 + //通知客户端
  120 + sendUtils.sendFcsj(mrs.sch);
  121 + //持久化
  122 + dayOfSchedule.save(mrs.sch);
  123 + }
  124 +
  125 + if(inRsList.size() > 0){
  126 + //排序后的第一个 就是最合适的匹配
  127 + Collections.sort(inRsList, new MatchResultComparator());
  128 + mrs = inRsList.get(0);
  129 +
  130 + mrs.sch.setZdsjActualAll(mrs.ts);
  131 + int doneSum = dayOfSchedule.doneSum(mrs.sch.getClZbh());
  132 + ScheduleRealInfo next = dayOfSchedule.next(mrs.sch);
  133 + if(null != next){
  134 + next.setQdzArrDateSJ(mrs.sch.getZdsjActual());
  135 + //下发调度指令
  136 + //directiveService.send60Dispatch(next, doneSum, "系统");
  137 + }
  138 + else{
  139 + //下发文本指令(已结束运营)
  140 + directiveService.send60Phrase(nbbm, "到达终点 " + mrs.sch.getZdzName() + ",已完成当日所有排班。", "系统");
  141 + }
  142 + //通知客户端
  143 + sendUtils.sendZdsj(mrs.sch, next, doneSum);
  144 + //持久化
  145 + dayOfSchedule.save(mrs.sch);
  146 + }
  147 + }
  148 +
  149 + public MatchResult match(ArrivalEntity arr, ScheduleRealInfo sch){
  150 + MatchResult mrs = new MatchResult();
  151 + mrs.inOut = arr.getInOut();
  152 + mrs.sch = sch;
  153 + mrs.ts = arr.getTs();
  154 +
  155 + if(arr.getInOut() == 1){
  156 + if(sch.getFcsjActual() == null
  157 + && sch.getQdzName().equals(arr.getStopName())
  158 + && dayOfSchedule.validStartTime(sch, arr.getTs())){
  159 +
  160 + mrs.diff = arr.getTs() - sch.getDfsjT();
  161 + if(Math.abs(mrs.diff) < MAX_RANGE)
  162 + mrs.success = true;
  163 + }
  164 + }
  165 + else if(arr.getInOut() == 0 && sch.getZdsj() != null){
  166 + if(sch.getZdsjActual() == null
  167 + && sch.getZdzName().equals(arr.getStopName())
  168 + && dayOfSchedule.validEndTime(sch, arr.getTs())){
  169 +
  170 + mrs.diff = arr.getTs() - sch.getZdsjT();
  171 + if(Math.abs(mrs.diff) < MAX_RANGE)
  172 + mrs.success = true;
  173 + }
  174 + }
  175 +
  176 + return mrs;
  177 + }
  178 +
  179 + /**
  180 + *
  181 + * @Title: lastMatchPoint
  182 + * @Description: TODO(最后一个已实发的班次索引)
  183 + */
  184 + public int lastMatchPoint(List<ScheduleRealInfo> schList){
  185 + int len = schList.size()
  186 + ,rs = 0;
  187 +
  188 + ScheduleRealInfo sch;
  189 + for(int i = len - 2; i >= 0; i --){
  190 + sch = schList.get(i);
  191 + if(sch.getFcsjActual() != null){
  192 + rs = i;
  193 + if(sch.getStatus() == 2)
  194 + rs ++;
  195 + break;
  196 + }
  197 + }
  198 + return rs;
  199 + }
  200 +
  201 + public long lastMatchTime(ScheduleRealInfo sch){
  202 + Long t = 0L;
  203 + if(null != sch.getFcsjActualTime())
  204 + t = sch.getFcsjActualTime();
  205 + if(null != sch.getZdsjActualTime())
  206 + t = sch.getZdsjActualTime();
  207 + return t;
  208 + }
  209 +
  210 + /**
  211 + *
  212 + * @Title: afterByTime
  213 + * @Description: TODO(参数时间戳之后的起始索引)
  214 + */
  215 + public int afterByTime(List<ArrivalEntity> arrList, long t){
  216 + int len = arrList.size()
  217 + ,rs = len - 1;
  218 +
  219 + for(int i = 0; i < len; i ++){
  220 + if(arrList.get(i).getTs() > t){
  221 + rs = i;
  222 + break;
  223 + }
  224 + }
  225 + return rs;
  226 + }
  227 + }
  228 +
  229 + @Override
  230 + public void setApplicationContext(ApplicationContext arg0) throws BeansException {
  231 + sendUtils = arg0.getBean(SendUtils.class);
  232 + dayOfSchedule = arg0.getBean(DayOfSchedule.class);
  233 + directiveService = arg0.getBean(DirectiveService.class);
  234 + }
  235 +}
src/main/java/com/bsth/data/match/MatchResult.java 0 → 100644
  1 +package com.bsth.data.match;
  2 +
  3 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: MatchResult
  8 + * @Description: TODO(实际和计划匹配结果)
  9 + * @author PanZhao
  10 + * @date 2016年8月10日 下午3:55:48
  11 + *
  12 + */
  13 +public class MatchResult {
  14 +
  15 + /** 班次 */
  16 + public ScheduleRealInfo sch;
  17 +
  18 + /** 时间差 */
  19 + public long diff;
  20 +
  21 + /** 0 进 1 出 */
  22 + public int inOut;
  23 +
  24 + public long ts;
  25 +
  26 + /** 交配成功 */
  27 + public boolean success;
  28 +}
src/main/java/com/bsth/data/match/MatchResultComparator.java 0 → 100644
  1 +package com.bsth.data.match;
  2 +
  3 +import java.util.Comparator;
  4 +
  5 +public class MatchResultComparator implements Comparator<MatchResult>{
  6 +
  7 + @Override
  8 + public int compare(MatchResult o1, MatchResult o2) {
  9 + return (int) (Math.abs(o1.diff) - Math.abs(o2.diff));
  10 + }
  11 +}
src/main/java/com/bsth/data/pilot80/PilotReport.java 0 → 100644
  1 +package com.bsth.data.pilot80;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collection;
  5 +import java.util.List;
  6 +
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import com.bsth.data.BasicData;
  13 +import com.bsth.data.LineConfigData;
  14 +import com.bsth.data.gpsdata.GpsEntity;
  15 +import com.bsth.data.gpsdata.GpsRealData;
  16 +import com.bsth.data.schedule.DayOfSchedule;
  17 +import com.bsth.data.schedule.ScheduleComparator;
  18 +import com.bsth.entity.Line;
  19 +import com.bsth.entity.directive.D80;
  20 +import com.bsth.entity.realcontrol.D80ReplyTemp;
  21 +import com.bsth.entity.realcontrol.LineConfig;
  22 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  23 +import com.bsth.repository.directive.D80Repository;
  24 +import com.bsth.service.directive.DirectiveService;
  25 +import com.bsth.websocket.handler.SendUtils;
  26 +import com.google.common.collect.ArrayListMultimap;
  27 +
  28 +/**
  29 + *
  30 + * @ClassName: PilotReport
  31 + * @Description: TODO(驾驶员上报)
  32 + * @author PanZhao
  33 + * @date 2016年8月14日 下午11:37:51
  34 + *
  35 + */
  36 +@Component
  37 +public class PilotReport {
  38 +
  39 + @Autowired
  40 + D80Repository d80Repository;
  41 +
  42 + @Autowired
  43 + DayOfSchedule dayOfSchedule;
  44 +
  45 + @Autowired
  46 + LineConfigData lineConfigData;
  47 +
  48 + @Autowired
  49 + DirectiveService directiveService;
  50 +
  51 + @Autowired
  52 + GpsRealData gpsRealData;
  53 +
  54 + @Autowired
  55 + SendUtils sendUtils;
  56 +
  57 + //private static ScheduleComparator.FCNO schComp;
  58 +
  59 + private static ArrayListMultimap<Integer, D80> d80MultiMap;
  60 +
  61 + Logger logger = LoggerFactory.getLogger(PilotReport.class);
  62 +
  63 + static{
  64 + d80MultiMap = ArrayListMultimap.create();
  65 + //schComp = new ScheduleComparator.FCNO();
  66 + }
  67 +
  68 + public void report(D80 d80){
  69 + //入库
  70 + d80Repository.save(d80);
  71 + //入缓存
  72 + d80MultiMap.put(d80.getData().getLineId(), d80);
  73 +
  74 + String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
  75 + //处理
  76 + switch (d80.getData().getRequestCode()) {
  77 + case 0xA3:
  78 + //出场请求
  79 + ScheduleRealInfo outSch = dayOfSchedule.nextByBcType(nbbm, "out");
  80 + //如果有对应出场班次
  81 + if(outSch != null){
  82 + //下发调度指令
  83 + directiveService.send60Dispatch(outSch, dayOfSchedule.doneSum(nbbm), "系统");
  84 + //当前GPS位置
  85 + GpsEntity gps = gpsRealData.get(d80.getDeviceId());
  86 + d80.setRemarks("计划出场时间:" + outSch.getDfsj() + "<br> 位置:" + coordHtmlStr(gps));
  87 + }else
  88 + d80.setRemarks("没有出场计划");
  89 +
  90 + break;
  91 +
  92 + case 0xA5:
  93 + //进场请求
  94 + ScheduleRealInfo inSch = dayOfSchedule.nextByBcType(nbbm, "in");
  95 + //如果有对应出场班次
  96 + if(inSch != null){
  97 + //当前GPS位置
  98 + GpsEntity gps = gpsRealData.get(d80.getDeviceId());
  99 + d80.setRemarks("计划进场时间:" + inSch.getDfsj() + "<br> 位置:" + coordHtmlStr(gps));
  100 + }else
  101 + d80.setRemarks("没有进场计划");
  102 + break;
  103 + }
  104 +
  105 + //推送到页面
  106 + sendUtils.send80ToPage(d80);
  107 + }
  108 +
  109 + /**
  110 + *
  111 + * @Title: reply
  112 + * @Description: TODO(调度员回复)
  113 + */
  114 + public void reply(D80 d80){
  115 + String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
  116 + Short reqCode = d80.getData().getRequestCode();
  117 + //默认短语回复
  118 + defaultReply(nbbm, reqCode, d80.getConfirmRs() == 0?true:false);
  119 +
  120 + switch (reqCode) {
  121 + case 0xA3:
  122 + //出场请求回复
  123 + applyOutReply(d80);
  124 + break;
  125 + case 0xA5:
  126 + //进场请求回复
  127 + applyInReply(d80);
  128 + break;
  129 + }
  130 + }
  131 +
  132 + /**
  133 + *
  134 + * @Title: applyOutReply
  135 + * @Description: TODO(出场请求回复)
  136 + */
  137 + public void applyOutReply(D80 d80){
  138 + //同意
  139 + if(d80.getConfirmRs() == 0){
  140 + String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
  141 +
  142 + ScheduleRealInfo sch = dayOfSchedule.nextByBcType(nbbm, "out");
  143 + if(null == sch)
  144 + return;
  145 +
  146 + LineConfig conf = lineConfigData.get(sch.getXlBm());
  147 + if(conf.getOutConfig() == 1){
  148 + //为相关班次写入请求出场时间
  149 + sch.setFcsjActualAll(d80.getTimestamp());
  150 +
  151 + //通知页面
  152 + sendUtils.refreshSch(sch);
  153 + }
  154 + }
  155 + }
  156 +
  157 + /**
  158 + *
  159 + * @Title: applyInReply
  160 + * @Description: TODO(进场请求回复)
  161 + */
  162 + public void applyInReply(D80 d80){
  163 + //同意
  164 + if(d80.getConfirmRs() == 0){
  165 + String nbbm = BasicData.deviceId2NbbmMap.get(d80.getDeviceId());
  166 +
  167 + ScheduleRealInfo sch = dayOfSchedule.nextByBcType(nbbm, "in");
  168 + if(null == sch)
  169 + return;
  170 +
  171 + LineConfig conf = lineConfigData.get(sch.getXlBm());
  172 + if(conf.getInConfig() == 1){
  173 + //为相关班次写入进场时间
  174 + sch.setZdsjActualAll(d80.getTimestamp());
  175 +
  176 + //通知页面
  177 + sendUtils.refreshSch(sch);
  178 + }
  179 + }
  180 + }
  181 +
  182 + public void defaultReply(String nbbm, short requestCode, boolean agree){
  183 + Line line = BasicData.nbbm2LineMap.get(nbbm);
  184 + String lineCode = null;
  185 +
  186 + if(line != null)
  187 + lineCode = line.getLineCode();
  188 + else{
  189 + try{
  190 + lineCode = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)).getLineId().toString();
  191 + }catch(Exception e){
  192 + logger.error("", e);
  193 + }
  194 + }
  195 +
  196 + if(null == lineCode)
  197 + return;
  198 +
  199 + LineConfig conf = lineConfigData.get(lineCode);
  200 + D80ReplyTemp temp = conf.findByCode(requestCode);
  201 +
  202 + if(null == temp)
  203 + return;
  204 +
  205 + String text;
  206 + if(agree)
  207 + text = temp.getAgreeText();
  208 + else
  209 + text = temp.getRejectText();
  210 +
  211 + directiveService.send60Phrase(nbbm, text, "系统");
  212 + }
  213 +
  214 + /**
  215 + *
  216 + * @Title: resumeOperation
  217 + * @Description: TODO(恢复营运)
  218 + */
  219 + public void resumeOperation(D80 d80){
  220 +
  221 + }
  222 +
  223 + /**
  224 + *
  225 + * @Title: applyTiaodang
  226 + * @Description: TODO(申请调档)
  227 + */
  228 + public void applyTiaodang(D80 d80){
  229 +
  230 + }
  231 +
  232 + /**
  233 + *
  234 + * @Title: unconfirmed80
  235 + * @Description: TODO(根据lineCode 获取未处理的80数据)
  236 + */
  237 + public List<D80> unconfirmed80(Integer lineCode){
  238 + List<D80> lineAll = d80MultiMap.get(lineCode)
  239 + ,rs = new ArrayList<>();
  240 +
  241 + for(D80 d80 : lineAll)
  242 + if(!d80.isConfirm())
  243 + rs.add(d80);
  244 +
  245 + return rs;
  246 + }
  247 +
  248 + public D80 findById(int id){
  249 + Collection<D80> all = d80MultiMap.values();
  250 +
  251 + for(D80 d80 : all){
  252 + if(d80.getId() == id)
  253 + return d80;
  254 + }
  255 +
  256 + return null;
  257 + }
  258 +
  259 + public String coordHtmlStr(GpsEntity gps){
  260 +
  261 + return "<span class=\"nt-coord\" data-lon=\""+gps.getLon()+"\" data-lat=\""+gps.getLat()+"\"></span>";
  262 + }
  263 +}
src/main/java/com/bsth/data/schedule/DayOfSchedule.java 0 → 100644
  1 +package com.bsth.data.schedule;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collection;
  5 +import java.util.Collections;
  6 +import java.util.Date;
  7 +import java.util.HashMap;
  8 +import java.util.HashSet;
  9 +import java.util.Iterator;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +import java.util.Set;
  13 +import java.util.concurrent.TimeUnit;
  14 +
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.boot.CommandLineRunner;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import com.alibaba.fastjson.JSON;
  22 +import com.alibaba.fastjson.JSONArray;
  23 +import com.bsth.Application;
  24 +import com.bsth.data.LineConfigData;
  25 +import com.bsth.entity.realcontrol.LineConfig;
  26 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  27 +import com.bsth.entity.schedule.SchedulePlanInfo;
  28 +import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
  29 +import com.bsth.service.schedule.SchedulePlanInfoService;
  30 +import com.bsth.util.BatchSaveUtils;
  31 +import com.bsth.util.DateUtils;
  32 +import com.bsth.websocket.handler.SendUtils;
  33 +import com.google.common.collect.ArrayListMultimap;
  34 +import com.google.common.collect.TreeMultimap;
  35 +
  36 +/**
  37 + *
  38 + * @ClassName: DayOfSchedule
  39 + * @Description: TODO(当日实际排班)
  40 + * @author PanZhao
  41 + * @date 2016年8月15日 上午10:16:12
  42 + *
  43 + */
  44 +@Component
  45 +public class DayOfSchedule implements CommandLineRunner {
  46 +
  47 + Logger logger = LoggerFactory.getLogger(this.getClass());
  48 +
  49 + // 按车辆分组的班次数据
  50 + private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;
  51 +
  52 + // 班次主键映射
  53 + private static Map<Long, ScheduleRealInfo> id2SchedulMap;
  54 +
  55 + // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
  56 + private static TreeMultimap<String, String> nbbm2SEStationMap;
  57 +
  58 + // 持久化缓冲区
  59 + //private static LinkedList<ScheduleRealInfo> pstBuffer;
  60 +
  61 + // 排序器
  62 + private static ScheduleComparator.FCNO schNoComparator;
  63 + //private static ScheduleComparator.FCSJ schFcsjComparator;
  64 +
  65 + @Autowired
  66 + LineConfigData lineConfigData;
  67 +
  68 + /*@Autowired
  69 + ScheduleRealInfoService scheduleRealService;*/
  70 +
  71 + @Autowired
  72 + ScheduleRealInfoRepository schRepository;
  73 +
  74 + @Autowired
  75 + SchedulePlanInfoService schPlanService;
  76 +
  77 + @Autowired
  78 + SchAttrCalculator schAttrCalculator;
  79 +
  80 + @Autowired
  81 + SendUtils sendUtils;
  82 +
  83 + /** 线路当前使用的排班的日期 */
  84 + public static Map<String, String> currSchDateMap;
  85 +
  86 + static {
  87 + nbbmScheduleMap = ArrayListMultimap.create();
  88 + id2SchedulMap = new HashMap<>();
  89 + //pstBuffer = new LinkedList<>();
  90 + schNoComparator = new ScheduleComparator.FCNO();
  91 + currSchDateMap = new HashMap<>();
  92 + nbbm2SEStationMap = TreeMultimap.create();
  93 + }
  94 +
  95 + @Autowired
  96 + ScheduleRefreshThread scheduleRefreshThread;
  97 +
  98 + @Override
  99 + public void run(String... arg0) throws Exception {
  100 + //翻班线程
  101 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 20, 60, TimeUnit.SECONDS);
  102 + }
  103 +
  104 + public Map<String, String> getCurrSchDate() {
  105 + return currSchDateMap;
  106 + }
  107 +
  108 + /**
  109 + *
  110 + * @Title: calcSchDateB
  111 + * @Description: TODO(计算线路当前应该使用的排班日期)
  112 + */
  113 + public String calcSchDate(String lineCode) {
  114 + LineConfig conf = lineConfigData.get(lineCode);
  115 + long ct = System.currentTimeMillis();
  116 + String schDate = DateUtils.sdfyyyyMMdd.format(new Date(ct));
  117 + // 小于当天起始运营时间,则取前一天的排班
  118 + if (ct < conf.getCurrStartTime())
  119 + schDate = DateUtils.subtractDay(schDate, 1);
  120 +
  121 + return schDate;
  122 + }
  123 +
  124 + /**
  125 + * @Title: reloadSch
  126 + * @Title: reloadSch
  127 + * @Description: TODO(重新载入排班)
  128 + * @param @param
  129 + * lineCode 线路编码
  130 + * @param @param
  131 + * schDate 班次日期 yyyy-MM-dd
  132 + * @param @param
  133 + * forcePlan 强制从计划调度重新抓取
  134 + */
  135 + public int reloadSch(String lineCode, String schDate, boolean forcePlan) {
  136 + try {
  137 + List<ScheduleRealInfo> list;
  138 +
  139 + if (forcePlan)
  140 + removeRealSch(lineCode, schDate);
  141 + else
  142 + clearRAMData(lineCode);
  143 +
  144 + if (existRealSch(lineCode, schDate))
  145 + list = loadRealSch(lineCode, schDate);// 从实际排班表加载
  146 + else {
  147 + list = loadPlanSch(lineCode, schDate);// 从计划排班表加载
  148 + // 写入数据库
  149 + batchSave(list);
  150 + }
  151 +
  152 + //更新线路和班次日期对照
  153 + currSchDateMap.put(lineCode, schDate);
  154 + //添加到缓存
  155 + putAll(list);
  156 +
  157 + //计算“起点站应到”时间
  158 + Set<String> cars = searchAllCars(list);
  159 + for(String nbbm : cars)
  160 + schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
  161 +
  162 + // 页面 翻班通知
  163 + sendUtils.shiftSchedule(lineCode);
  164 + } catch (Exception e) {
  165 + logger.error("", e);
  166 + return -1;
  167 + }
  168 +
  169 + return 0;
  170 + }
  171 +
  172 + /**
  173 + *
  174 + * @Title: searchAllCars
  175 + * @Description: TODO(搜索班次集合中的车辆)
  176 + */
  177 + private Set<String> searchAllCars(List<ScheduleRealInfo> list) {
  178 + Set<String> cars = new HashSet<>();
  179 + for(ScheduleRealInfo sch : list)
  180 + cars.add(sch.getClZbh());
  181 +
  182 + return cars;
  183 + }
  184 +
  185 + private void putAll(List<ScheduleRealInfo> list) {
  186 + for (ScheduleRealInfo sch : list)
  187 + put(sch);
  188 + }
  189 +
  190 + /**
  191 + * @Title: removeRealSch
  192 + * @Description: TODO(清除实际排班,包括数据库和内存数据)
  193 + * @param @param
  194 + * lineCode 线路编码
  195 + * @param @param
  196 + * schDate 班次日期 yyyy-MM-dd
  197 + */
  198 + public void removeRealSch(String lineCode, String schDate) throws Exception {
  199 + try {
  200 + // 清理数据库数据
  201 + schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);
  202 +
  203 + // 清理内存数据
  204 + clearRAMData(lineCode + "");
  205 + } catch (Exception e) {
  206 + logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);
  207 + throw e;
  208 + }
  209 + }
  210 +
  211 + /**
  212 + *
  213 + * @Title: clearRAMData
  214 + * @Description: TODO(清理内存数据)
  215 + */
  216 + public void clearRAMData(String lineCode) {
  217 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  218 + for (ScheduleRealInfo sch : schs) {
  219 + if (sch.getXlBm().equals(lineCode))
  220 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  221 + }
  222 + }
  223 +
  224 + /**
  225 + * @Title: existRealSch
  226 + * @Description: TODO(实际排班是否已存在)
  227 + */
  228 + public boolean existRealSch(String lineCode, String schDate) {
  229 + int count = schRepository.countByLineCodeAndDate(lineCode, schDate);
  230 + return count > 0;
  231 + }
  232 +
  233 + /**
  234 + * @Title: loadRealSch
  235 + * @Description: TODO(从实际排班表加载数据)
  236 + */
  237 + public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {
  238 + return schRepository.findByLineCodeAndDate(lineCode, schDate);
  239 + }
  240 +
  241 + /**
  242 + * @Title: loadPlanSch
  243 + * @Description: TODO(从计划排班表加载数据)
  244 + */
  245 + public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {
  246 + List<ScheduleRealInfo> realList = new ArrayList<>();
  247 +
  248 + try {
  249 + Map<String, Object> data = new HashMap<>();
  250 + data.put("scheduleDate_eq", DateUtils.sdfyyyyMMdd.parse(schDate));
  251 + data.put("xlBm_eq", lineCode);
  252 +
  253 + // 查询计划排班
  254 + List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());
  255 +
  256 + // 转换为实际排班
  257 + realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
  258 +
  259 + for (ScheduleRealInfo sch : realList) {
  260 + sch.setScheduleDateStr(DateUtils.sdfyyyyMMdd.format(sch.getScheduleDate()));
  261 + sch.setRealExecDate(sch.getScheduleDateStr());
  262 + }
  263 + } catch (Exception e) {
  264 + logger.error("", e);
  265 + }
  266 + return realList;
  267 + }
  268 +
  269 + /**
  270 + * @Title: batchSave
  271 + * @Description: TODO(批量入库)
  272 + */
  273 + private void batchSave(List<ScheduleRealInfo> list) {
  274 + // 查询数据库最大ID
  275 + Long id = schRepository.getMaxId();
  276 + if (null == id)
  277 + id = 0L;
  278 + id++;
  279 +
  280 + for (ScheduleRealInfo item : list) {
  281 + item.setSpId(item.getId());// 保留原始的计划ID
  282 + item.setId(id++);// 设置ID
  283 + item.setScheduleDateStr(DateUtils.sdfyyyyMMdd.format(item.getScheduleDate()));
  284 + }
  285 +
  286 + // 入库
  287 + new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);
  288 + }
  289 +
  290 + private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
  291 + List<SchedulePlanInfo> list = new ArrayList<>();
  292 +
  293 + SchedulePlanInfo sp;
  294 + while (itrab.hasNext()) {
  295 + sp = itrab.next();
  296 + sp.setSchedulePlan(null);
  297 + list.add(sp);
  298 + }
  299 + return list;
  300 + }
  301 +
  302 + /**
  303 + *
  304 + * @Title: findByLineCode
  305 + * @Description: TODO(lineCode 获取班次)
  306 + */
  307 + public List<ScheduleRealInfo> findByLineCode(String lineCode) {
  308 + List<ScheduleRealInfo> rs = new ArrayList<>();
  309 +
  310 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  311 + for (ScheduleRealInfo sch : schs) {
  312 + if (sch.getXlBm().equals(lineCode))
  313 + rs.add(sch);
  314 + }
  315 + return rs;
  316 + }
  317 +
  318 + /**
  319 + *
  320 + * @Title: findCarByLineCode
  321 + * @Description: TODO(线路下运营的车辆)
  322 + */
  323 + public Set<String> findCarByLineCode(String lineCode){
  324 + Set<String> rs = new HashSet<>();
  325 +
  326 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  327 + for (ScheduleRealInfo sch : schs) {
  328 + if (sch.getXlBm().equals(lineCode))
  329 + rs.add(sch.getClZbh());
  330 + }
  331 +
  332 + return rs;
  333 + }
  334 +
  335 + public List<ScheduleRealInfo> findByNbbm(String nbbm) {
  336 + return nbbmScheduleMap.get(nbbm);
  337 + }
  338 +
  339 + /**
  340 + *
  341 + * @Title: findByLineAndUpDown
  342 + * @Description: TODO(lineCode 和走向获取班次)
  343 + */
  344 + public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {
  345 + List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();
  346 +
  347 + for (ScheduleRealInfo sch : list) {
  348 + if (sch.getXlDir().equals(upDown + ""))
  349 + rs.add(sch);
  350 + }
  351 + return rs;
  352 + }
  353 +
  354 + public ScheduleRealInfo get(long id) {
  355 + return id2SchedulMap.get(id);
  356 + }
  357 +
  358 + public Set<String> getSEStationList(String nbbm) {
  359 + return nbbm2SEStationMap.get(nbbm);
  360 + }
  361 +
  362 + /**
  363 + *
  364 + * @Title: next
  365 + * @Description: TODO(下一个班次)
  366 + */
  367 + public ScheduleRealInfo next(ScheduleRealInfo sch) {
  368 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  369 + // 排序
  370 + Collections.sort(list, schNoComparator);
  371 +
  372 + ScheduleRealInfo next = null;
  373 + for (int i = 0; i < list.size() - 1; i++) {
  374 + if (list.get(i).getId().equals(sch.getId()))
  375 + next = list.get(i + 1);
  376 +
  377 + }
  378 +
  379 + return next;
  380 + }
  381 +
  382 + /**
  383 + *
  384 + * @Title: prveRealSch
  385 + * @Description: TODO(获取上一个已实际发出的班次)
  386 + */
  387 + public ScheduleRealInfo prveSjfc(ScheduleRealInfo sch) {
  388 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  389 + // 排序
  390 + Collections.sort(list, schNoComparator);
  391 +
  392 + ScheduleRealInfo prve = null;
  393 +
  394 + int i = list.indexOf(sch);
  395 + for (; i >= 0; i--){
  396 + if (list.get(i).getFcsjActual() != null){
  397 + prve = list.get(i);
  398 + break;
  399 + }
  400 + }
  401 + return prve;
  402 + }
  403 +
  404 + public void put(ScheduleRealInfo sch) {
  405 + schAttrCalculator
  406 + .calcRealDate(sch)
  407 + .calcAllTimeByFcsj(sch);
  408 +
  409 + String nbbm = sch.getClZbh();
  410 + nbbmScheduleMap.put(nbbm, sch);
  411 + nbbm2SEStationMap.put(nbbm, sch.getQdzCode());
  412 + nbbm2SEStationMap.put(nbbm, sch.getZdzCode());
  413 +
  414 + //主键索引
  415 + id2SchedulMap.put(sch.getId(), sch);
  416 + }
  417 +
  418 + /**
  419 + *
  420 + * @Title: nextAll
  421 + * @Description: TODO(之后的所有班次)
  422 + */
  423 + public List<ScheduleRealInfo> nextAll(ScheduleRealInfo t) {
  424 + // TODO Auto-generated method stub
  425 + return null;
  426 + }
  427 +
  428 + /**
  429 + *
  430 + * @Title: doneSum
  431 + * @Description: TODO(已完成班次总数)
  432 + */
  433 + public int doneSum(String clZbh) {
  434 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);
  435 + int rs = 0;
  436 +
  437 + for(ScheduleRealInfo sch : list){
  438 + if(sch.getStatus() == 2)
  439 + rs ++;
  440 + }
  441 + return rs;
  442 + }
  443 +
  444 + /**
  445 + *
  446 + * @Title: validEndTime
  447 + * @Description: TODO(是否是有效的到达时间)
  448 + */
  449 + public boolean validEndTime(ScheduleRealInfo sch, Long ts) {
  450 + if (sch.getFcsjActualTime() != null)
  451 + return ts > sch.getFcsjActualTime();
  452 + else {
  453 + ScheduleRealInfo prve = prveSjfc(sch);
  454 + if (null != prve)
  455 + return ts > prve.getFcsjActualTime();
  456 + else
  457 + return true;
  458 + }
  459 + }
  460 +
  461 + /**
  462 + *
  463 + * @Title: validStartTime
  464 + * @Description: TODO(是否是有效的发车时间)
  465 + */
  466 + public boolean validStartTime(ScheduleRealInfo sch, Long ts) {
  467 + ScheduleRealInfo prve = prveSjfc(sch);
  468 + if(null != prve)
  469 + return ts > prve.getFcsjActualTime();
  470 + else
  471 + return true;
  472 + }
  473 +
  474 + public void save(ScheduleRealInfo sch){
  475 + schRepository.save(sch);
  476 + }
  477 +
  478 + /**
  479 + *
  480 + * @Title: outSch
  481 + * @Description: TODO(出场班次)
  482 + */
  483 +/* public List<ScheduleRealInfo> outSch(String nbbm){
  484 + List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)
  485 + ,outList = new ArrayList<>();
  486 +
  487 + for(ScheduleRealInfo sch : all){
  488 + if(sch.getBcType().equals("out"))
  489 + outList.add(sch);
  490 + }
  491 + return outList;
  492 + }
  493 +
  494 + public ScheduleRealInfo nextOut(String nbbm){
  495 + List<ScheduleRealInfo> list = outSch(nbbm);
  496 + Collections.sort(list, schNoComparator);
  497 + ScheduleRealInfo sch = null;
  498 + for(ScheduleRealInfo temp : list){
  499 + if(temp.getFcsjActual() == null)
  500 + sch = temp;
  501 + }
  502 +
  503 + return sch;
  504 + }*/
  505 +
  506 + /**
  507 + *
  508 + * @Title: nextByBcType
  509 + * @Description: TODO(获取下一个指定班次类型的班次)
  510 + */
  511 + public ScheduleRealInfo nextByBcType(String nbbm, String bcType){
  512 + List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);
  513 + Collections.sort(list, schNoComparator);
  514 + ScheduleRealInfo sch = null;
  515 + for(ScheduleRealInfo temp : list){
  516 + if(temp.getFcsjActual() == null)
  517 + sch = temp;
  518 + }
  519 +
  520 + return sch;
  521 + }
  522 +
  523 + public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType){
  524 + List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)
  525 + ,outList = new ArrayList<>();
  526 +
  527 + for(ScheduleRealInfo sch : all){
  528 + if(sch.getBcType().equals(bcType))
  529 + outList.add(sch);
  530 + }
  531 + return outList;
  532 + }
  533 +}
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java 0 → 100644
  1 +package com.bsth.data.schedule;
  2 +
  3 +import java.text.ParseException;
  4 +import java.util.Collections;
  5 +import java.util.Date;
  6 +import java.util.List;
  7 +
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import com.bsth.data.LineConfigData;
  14 +import com.bsth.entity.realcontrol.LineConfig;
  15 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  16 +import com.bsth.util.DateUtils;
  17 +
  18 +/**
  19 + *
  20 + * @ClassName: SchAttrCalculator
  21 + * @Description: TODO(班次相关属性计算器)
  22 + * @author PanZhao
  23 + * @date 2016年8月15日 下午4:40:26
  24 + *
  25 + */
  26 +@Component
  27 +public class SchAttrCalculator {
  28 +
  29 + @Autowired
  30 + LineConfigData lineConfigData;
  31 +
  32 + private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
  33 +
  34 + Logger logger = LoggerFactory.getLogger(this.getClass());
  35 +
  36 + /**
  37 + * @Title: calcRealDate
  38 + * @Description: TODO(计算班次的真实执行日期)
  39 + */
  40 + public SchAttrCalculator calcRealDate(ScheduleRealInfo sch) {
  41 + LineConfig conf = lineConfigData.get(sch.getXlBm());
  42 +
  43 + try {
  44 + if (null == sch.getFcsjT())
  45 + calcFcsjTime(sch);
  46 +
  47 + // 早于班次运营时间的 加一天
  48 + if (conf.getCurrStartTime() > sch.getFcsjT())
  49 + sch.setFcsjAll(sch.getFcsjT() + DAY_TIME);
  50 +
  51 + sch.setRealExecDate(DateUtils.sdfyyyyMMdd.format(new Date(sch.getFcsjT())));
  52 + } catch (Exception e) {
  53 + logger.error("", e);
  54 + }
  55 + return this;
  56 + }
  57 +
  58 + /**
  59 + *
  60 + * @Title: calcAllTimeByFcsj
  61 + * @Description: TODO(根据发车时间字符串计算 (计发时间,终点时间,待发时间))
  62 + */
  63 + public SchAttrCalculator calcAllTimeByFcsj(ScheduleRealInfo sch) {
  64 + try {
  65 + // 生成时间戳
  66 + calcTimestamp(sch);
  67 +
  68 + // 计划终点时间
  69 + if (sch.getBcsj() != null) {
  70 + Date zdDate = new Date(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000));
  71 + sch.setZdsjT(zdDate.getTime());
  72 + sch.setZdsj(DateUtils.sdfHHmm.format(zdDate));
  73 + }
  74 + } catch (ParseException e) {
  75 + logger.error("", e);
  76 + }
  77 + return this;
  78 + }
  79 +
  80 + /**
  81 + *
  82 + * @Title: calcQdzTimePlan
  83 + * @Description: TODO(计算班次的起点应到时间,list 必须是同一辆车的班次)
  84 + */
  85 + public void calcQdzTimePlan(List<ScheduleRealInfo> list){
  86 + Collections.sort(list, new ScheduleComparator.FCSJ());
  87 +
  88 + int len = list.size();
  89 + if(len == 0)
  90 + return;
  91 +
  92 + ScheduleRealInfo prve = list.get(0), curr;
  93 + for(int i = 1; i < len; i ++){
  94 + curr = list.get(i);
  95 + if(prve.getZdzName().equals(curr.getQdzName()))
  96 + curr.setQdzArrDateJH(prve.getZdsj());
  97 +
  98 + prve = curr;
  99 + }
  100 + }
  101 +
  102 + public SchAttrCalculator calcFcsjTime(ScheduleRealInfo sch) throws ParseException {
  103 + sch.setFcsjT(DateUtils.sdfyyyyMMddHHmm.parse(sch.getRealExecDate() + sch.getFcsj()).getTime());
  104 + return this;
  105 + }
  106 +
  107 + public void calcTimestamp(ScheduleRealInfo sch) throws ParseException{
  108 + //计发时间
  109 + if(sch.getFcsjT() == null)
  110 + calcFcsjTime(sch);
  111 +
  112 + //待发时间
  113 + if(sch.getDfsj() == null)
  114 + sch.setDfsjAll(sch.getFcsjT());
  115 + if(sch.getDfsjT() == null)
  116 + sch.setDfsjAll(sch.getDfsj());
  117 +
  118 + //实发时间戳
  119 + if(sch.getFcsjActualTime() == null && sch.getFcsjActual() != null)
  120 + sch.setFcsjActualAll(sch.getFcsjActual());
  121 +
  122 + //实达时间戳
  123 + if(sch.getZdsjActualTime() == null && sch.getZdsjActual() != null)
  124 + sch.setZdsjActualAll(sch.getZdsjActual());
  125 + }
  126 +}
src/main/java/com/bsth/data/schedule/ScheduleComparator.java 0 → 100644
  1 +package com.bsth.data.schedule;
  2 +
  3 +import java.util.Comparator;
  4 +
  5 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  6 +
  7 +/**
  8 + *
  9 + * @ClassName: ScheduleComparator
  10 + * @Description: TODO(实际班次排序器)
  11 + * @author PanZhao
  12 + * @date 2016年8月15日 下午1:53:28
  13 + *
  14 + */
  15 +public class ScheduleComparator {
  16 +
  17 + public static class FCNO implements Comparator<ScheduleRealInfo>{
  18 + @Override
  19 + public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
  20 + return s1.getFcno() - s2.getFcno();
  21 + }
  22 + }
  23 +
  24 + public static class FCSJ implements Comparator<ScheduleRealInfo>{
  25 +
  26 + @Override
  27 + public int compare(ScheduleRealInfo s1, ScheduleRealInfo s2) {
  28 + return (int) (s1.getFcsjT() - s2.getFcsjT());
  29 + }
  30 + }
  31 +}
src/main/java/com/bsth/data/schedule/ScheduleRefreshThread.java 0 → 100644
  1 +package com.bsth.data.schedule;
  2 +
  3 +import java.util.Collection;
  4 +import java.util.Set;
  5 +
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import com.bsth.data.BasicData;
  12 +import com.bsth.data.LineConfigData;
  13 +import com.bsth.data.arrival.ArrivalData_GPS;
  14 +import com.bsth.data.directive.DayOfDirectives;
  15 +import com.bsth.entity.realcontrol.LineConfig;
  16 +
  17 +/**
  18 + *
  19 + * @ClassName: refreshScheduleThread
  20 + * @Description: TODO(班次刷新线程,用于在营运开始时间切换到当日排班)
  21 + * @author PanZhao
  22 + * @date 2016年8月17日 下午1:23:34
  23 + *
  24 + */
  25 +@Component
  26 +public class ScheduleRefreshThread extends Thread{
  27 +
  28 + @Autowired
  29 + DayOfSchedule dayOfSchedule;
  30 +
  31 + @Autowired
  32 + ArrivalData_GPS arrivalData;
  33 +
  34 + @Autowired
  35 + LineConfigData lineConfs;
  36 +
  37 + @Autowired
  38 + DayOfDirectives dayOfDirectives;
  39 +
  40 + Logger logger = LoggerFactory.getLogger(ScheduleRefreshThread.class);
  41 +
  42 + @Override
  43 + public void run() {
  44 + Collection<LineConfig> confs = lineConfs.getAll();
  45 +
  46 + String currSchDate, oldSchDate;
  47 + String lineCode;
  48 + for(LineConfig conf : confs){
  49 + lineCode = conf.getLine().getLineCode();
  50 + oldSchDate = dayOfSchedule.getCurrSchDate().get(lineCode);
  51 + currSchDate = dayOfSchedule.calcSchDate(lineCode);
  52 +
  53 + if(oldSchDate == null || !oldSchDate.equals(currSchDate)){
  54 + logger.info(lineCode + "开始翻班, " + currSchDate);
  55 + //清除进出站数据
  56 + arrivalData.clearRAMData(lineCode);
  57 + //清除指令数据
  58 + Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode);
  59 + for(String car : cars)
  60 + dayOfDirectives.clear(BasicData.deviceId2NbbmMap.inverse().get(car));
  61 +
  62 + //重载排班数据
  63 + dayOfSchedule.reloadSch(lineCode, currSchDate, false);
  64 + logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size());
  65 + }
  66 + }
  67 + }
  68 +}
src/main/java/com/bsth/entity/directive/D60.java
1 -//package com.bsth.entity.directive;  
2 -//  
3 -//import javax.persistence.Embeddable;  
4 -//import javax.persistence.Entity;  
5 -//import javax.persistence.FetchType;  
6 -//import javax.persistence.GeneratedValue;  
7 -//import javax.persistence.Id;  
8 -//import javax.persistence.ManyToOne;  
9 -//import javax.persistence.NamedAttributeNode;  
10 -//import javax.persistence.NamedEntityGraph;  
11 -//import javax.persistence.NamedEntityGraphs;  
12 -//import javax.persistence.Table;  
13 -//import javax.persistence.Transient;  
14 -//  
15 -//import com.bsth.entity.realcontrol.ScheduleRealInfo;  
16 -//import com.fasterxml.jackson.annotation.JsonIgnore;  
17 -//  
18 -//  
19 -///**  
20 -// *  
21 -// * @ClassName: D60  
22 -// * @Description: TODO(调度指令)  
23 -// * @author PanZhao  
24 -// * @date 2016年6月7日 上午10:21:59  
25 -// *  
26 -// */  
27 -//@Entity  
28 -//@Table(name = "bsth_v_directive_60")  
29 -//@NamedEntityGraphs({  
30 -// @NamedEntityGraph(name = "directive60_sch", attributeNodes = {  
31 -// @NamedAttributeNode("sch")  
32 -// })  
33 -//})  
34 -//public class D60 extends Directive{  
35 -//  
36 -// @Id  
37 -// @GeneratedValue  
38 -// private Integer id;  
39 -//  
40 -// /**  
41 -// * 数据  
42 -// */  
43 -// private DirectiveData data;  
44 -//  
45 -// /**  
46 -// * 唯一标识  
47 -// */  
48 -// @Transient  
49 -// private Integer msgId;  
50 -//  
51 -// /**  
52 -// * 46上行  
53 -// */  
54 -// private Short reply46 = -1;  
55 -//  
56 -// /**  
57 -// * 47上行  
58 -// */  
59 -// private Short reply47 = -1;  
60 -//  
61 -// /**  
62 -// * 是否是调度指令  
63 -// * 目前调度指令和消息短语都是短语下发,所以从协议上无法区分  
64 -// */  
65 -// private boolean isDispatch;  
66 -//  
67 -// /**  
68 -// * 相关联的班次  
69 -// */  
70 -// @JsonIgnore  
71 -// @ManyToOne(fetch = FetchType.LAZY)  
72 -// private ScheduleRealInfo sch;  
73 -//  
74 -// @Embeddable  
75 -// public static class DirectiveData {  
76 -// // 公司代码  
77 -// private short companyCode;  
78 -//  
79 -// // 设备号  
80 -// @Transient  
81 -// private String deviceId;  
82 -//  
83 -// // 时间戳  
84 -// @Transient  
85 -// private Long timestamp;  
86 -//  
87 -// // 保留 默认0  
88 -// private short instructType = 0;  
89 -//  
90 -// /*  
91 -// * 调度指令 调度指令。  
92 -// * 0X00表示信息短语  
93 -// * 0X01表示取消上次指令+调度指令(闹钟有效)  
94 -// * 0x02表示为调度指令(闹钟有效)  
95 -// * 0x03表示运营状态指令(闹钟无效)  
96 -// * 0x04表示其他指令  
97 -// */  
98 -// private Short dispatchInstruct;  
99 -//  
100 -// // 唯一标识  
101 -// private int msgId;  
102 -//  
103 -// // 闹钟  
104 -// private Long alarmTime;  
105 -//  
106 -// // 多个运营状态字节  
107 -// private Long serviceState;  
108 -//  
109 -// // 消息文本  
110 -// private String txtContent;  
111 -//  
112 -// public short getCompanyCode() {  
113 -// return companyCode;  
114 -// }  
115 -//  
116 -// public void setCompanyCode(short companyCode) {  
117 -// this.companyCode = companyCode;  
118 -// }  
119 -//  
120 -// public String getDeviceId() {  
121 -// return deviceId;  
122 -// }  
123 -//  
124 -// public void setDeviceId(String deviceId) {  
125 -// this.deviceId = deviceId;  
126 -// }  
127 -//  
128 -// public Long getTimestamp() {  
129 -// return timestamp;  
130 -// }  
131 -//  
132 -// public void setTimestamp(Long timestamp) {  
133 -// this.timestamp = timestamp;  
134 -// }  
135 -//  
136 -// public short getInstructType() {  
137 -// return instructType;  
138 -// }  
139 -//  
140 -// public void setInstructType(short instructType) {  
141 -// this.instructType = instructType;  
142 -// }  
143 -//  
144 -// public Short getDispatchInstruct() {  
145 -// return dispatchInstruct;  
146 -// }  
147 -//  
148 -// public void setDispatchInstruct(Short dispatchInstruct) {  
149 -// this.dispatchInstruct = dispatchInstruct;  
150 -// }  
151 -//  
152 -// public int getMsgId() {  
153 -// return msgId;  
154 -// }  
155 -//  
156 -// public void setMsgId(int msgId) {  
157 -// this.msgId = msgId;  
158 -// }  
159 -//  
160 -// public Long getAlarmTime() {  
161 -// return alarmTime;  
162 -// }  
163 -//  
164 -// public void setAlarmTime(Long alarmTime) {  
165 -// this.alarmTime = alarmTime;  
166 -// }  
167 -//  
168 -// public Long getServiceState() {  
169 -// return serviceState;  
170 -// }  
171 -//  
172 -// public void setServiceState(Long serviceState) {  
173 -// this.serviceState = serviceState;  
174 -// }  
175 -//  
176 -// public String getTxtContent() {  
177 -// return txtContent;  
178 -// }  
179 -//  
180 -// public void setTxtContent(String txtContent) {  
181 -// this.txtContent = txtContent;  
182 -// }  
183 -// }  
184 -//  
185 -// public Integer getId() {  
186 -// return id;  
187 -// }  
188 -//  
189 -// public void setId(Integer id) {  
190 -// this.id = id;  
191 -// }  
192 -//  
193 -// public short getOperCode() {  
194 -// return operCode;  
195 -// }  
196 -//  
197 -// public void setOperCode(short operCode) {  
198 -// this.operCode = operCode;  
199 -// }  
200 -//  
201 -// public DirectiveData getData() {  
202 -// return data;  
203 -// }  
204 -//  
205 -// public void setData(DirectiveData data) {  
206 -// this.data = data;  
207 -// }  
208 -//  
209 -// public Integer getMsgId() {  
210 -// if(this.msgId != null)  
211 -// return this.msgId;  
212 -// else  
213 -// return this.getData().getMsgId();  
214 -// }  
215 -//  
216 -// public void setMsgId(Integer msgId) {  
217 -// this.msgId = msgId;  
218 -// }  
219 -//  
220 -// @Override  
221 -// public void setTimestamp(Long timestamp) {  
222 -// if(this.data != null)  
223 -// this.data.setTimestamp(timestamp);  
224 -//  
225 -// this.timestamp = timestamp;  
226 -// }  
227 -//  
228 -// @Override  
229 -// public void setDeviceId(String deviceId) {  
230 -// if(this.data != null)  
231 -// this.data.setDeviceId(deviceId);  
232 -//  
233 -// this.deviceId = deviceId;  
234 -// }  
235 -//  
236 -// public Short getReply46() {  
237 -// return reply46;  
238 -// }  
239 -//  
240 -// public void setReply46(Short reply46) {  
241 -// this.reply46 = reply46;  
242 -// }  
243 -//  
244 -// public Short getReply47() {  
245 -// return reply47;  
246 -// }  
247 -//  
248 -// public void setReply47(Short reply47) {  
249 -// this.reply47 = reply47;  
250 -// }  
251 -//  
252 -// public boolean isDispatch() {  
253 -// return isDispatch;  
254 -// }  
255 -//  
256 -// public void setDispatch(boolean isDispatch) {  
257 -// this.isDispatch = isDispatch;  
258 -// }  
259 -//  
260 -// public ScheduleRealInfo getSch() {  
261 -// return sch;  
262 -// }  
263 -//  
264 -// public void setSch(ScheduleRealInfo sch) {  
265 -// this.sch = sch;  
266 -// }  
267 -//} 1 +package com.bsth.entity.directive;
  2 +
  3 +import javax.persistence.Embeddable;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.FetchType;
  6 +import javax.persistence.GeneratedValue;
  7 +import javax.persistence.Id;
  8 +import javax.persistence.ManyToOne;
  9 +import javax.persistence.NamedAttributeNode;
  10 +import javax.persistence.NamedEntityGraph;
  11 +import javax.persistence.NamedEntityGraphs;
  12 +import javax.persistence.Table;
  13 +import javax.persistence.Transient;
  14 +
  15 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  16 +import com.fasterxml.jackson.annotation.JsonIgnore;
  17 +
  18 +
  19 +/**
  20 + *
  21 + * @ClassName: D60
  22 + * @Description: TODO(调度指令)
  23 + * @author PanZhao
  24 + * @date 2016年6月7日 上午10:21:59
  25 + *
  26 + */
  27 +@Entity
  28 +@Table(name = "bsth_v_directive_60")
  29 +@NamedEntityGraphs({
  30 + @NamedEntityGraph(name = "directive60_sch", attributeNodes = {
  31 + @NamedAttributeNode("sch")
  32 + })
  33 +})
  34 +public class D60 extends Directive{
  35 +
  36 + @Id
  37 + @GeneratedValue
  38 + private Integer id;
  39 +
  40 + /**
  41 + * 数据
  42 + */
  43 + private D60Data data;
  44 +
  45 + /**
  46 + * 唯一标识
  47 + */
  48 + @Transient
  49 + private Integer msgId;
  50 +
  51 + /**
  52 + * 46上行
  53 + */
  54 + private Short reply46 = -1;
  55 +
  56 + /**
  57 + * 47上行
  58 + */
  59 + private Short reply47 = -1;
  60 +
  61 + /**
  62 + * 是否是调度指令
  63 + * 目前调度指令和消息短语都是短语下发,所以从协议上无法区分
  64 + */
  65 + private boolean isDispatch;
  66 +
  67 + /**
  68 + * 相关联的班次
  69 + */
  70 + @JsonIgnore
  71 + @ManyToOne(fetch = FetchType.LAZY)
  72 + private ScheduleRealInfo sch;
  73 +
  74 + @Embeddable
  75 + public static class D60Data {
  76 + // 公司代码
  77 + private short companyCode;
  78 +
  79 + // 设备号
  80 + @Transient
  81 + private String deviceId;
  82 +
  83 + // 时间戳
  84 + @Transient
  85 + private Long timestamp;
  86 +
  87 + // 保留 默认0
  88 + private short instructType = 0;
  89 +
  90 + /*
  91 + * 调度指令 调度指令。
  92 + * 0X00表示信息短语
  93 + * 0X01表示取消上次指令+调度指令(闹钟有效)
  94 + * 0x02表示为调度指令(闹钟有效)
  95 + * 0x03表示运营状态指令(闹钟无效)
  96 + * 0x04表示其他指令
  97 + */
  98 + private Short dispatchInstruct;
  99 +
  100 + // 唯一标识
  101 + private int msgId;
  102 +
  103 + // 闹钟
  104 + private Long alarmTime;
  105 +
  106 + // 多个运营状态字节
  107 + private Long serviceState;
  108 +
  109 + // 消息文本
  110 + private String txtContent;
  111 +
  112 + public short getCompanyCode() {
  113 + return companyCode;
  114 + }
  115 +
  116 + public void setCompanyCode(short companyCode) {
  117 + this.companyCode = companyCode;
  118 + }
  119 +
  120 + public String getDeviceId() {
  121 + return deviceId;
  122 + }
  123 +
  124 + public void setDeviceId(String deviceId) {
  125 + this.deviceId = deviceId;
  126 + }
  127 +
  128 + public Long getTimestamp() {
  129 + return timestamp;
  130 + }
  131 +
  132 + public void setTimestamp(Long timestamp) {
  133 + this.timestamp = timestamp;
  134 + }
  135 +
  136 + public short getInstructType() {
  137 + return instructType;
  138 + }
  139 +
  140 + public void setInstructType(short instructType) {
  141 + this.instructType = instructType;
  142 + }
  143 +
  144 + public Short getDispatchInstruct() {
  145 + return dispatchInstruct;
  146 + }
  147 +
  148 + public void setDispatchInstruct(Short dispatchInstruct) {
  149 + this.dispatchInstruct = dispatchInstruct;
  150 + }
  151 +
  152 + public int getMsgId() {
  153 + return msgId;
  154 + }
  155 +
  156 + public void setMsgId(int msgId) {
  157 + this.msgId = msgId;
  158 + }
  159 +
  160 + public Long getAlarmTime() {
  161 + return alarmTime;
  162 + }
  163 +
  164 + public void setAlarmTime(Long alarmTime) {
  165 + this.alarmTime = alarmTime;
  166 + }
  167 +
  168 + public Long getServiceState() {
  169 + return serviceState;
  170 + }
  171 +
  172 + public void setServiceState(Long serviceState) {
  173 + this.serviceState = serviceState;
  174 + }
  175 +
  176 + public String getTxtContent() {
  177 + return txtContent;
  178 + }
  179 +
  180 + public void setTxtContent(String txtContent) {
  181 + this.txtContent = txtContent;
  182 + }
  183 + }
  184 +
  185 + public Integer getId() {
  186 + return id;
  187 + }
  188 +
  189 + public void setId(Integer id) {
  190 + this.id = id;
  191 + }
  192 +
  193 + public short getOperCode() {
  194 + return operCode;
  195 + }
  196 +
  197 + public void setOperCode(short operCode) {
  198 + this.operCode = operCode;
  199 + }
  200 +
  201 + public D60Data getData() {
  202 + return data;
  203 + }
  204 +
  205 + public void setData(D60Data data) {
  206 + this.data = data;
  207 + }
  208 +
  209 + public Integer getMsgId() {
  210 + if(this.msgId != null)
  211 + return this.msgId;
  212 + else
  213 + return this.getData().getMsgId();
  214 + }
  215 +
  216 + public void setMsgId(Integer msgId) {
  217 + this.msgId = msgId;
  218 + }
  219 +
  220 + @Override
  221 + public void setTimestamp(Long timestamp) {
  222 + if(this.data != null)
  223 + this.data.setTimestamp(timestamp);
  224 +
  225 + this.timestamp = timestamp;
  226 + }
  227 +
  228 + @Override
  229 + public void setDeviceId(String deviceId) {
  230 + if(this.data != null)
  231 + this.data.setDeviceId(deviceId);
  232 +
  233 + this.deviceId = deviceId;
  234 + }
  235 +
  236 + public Short getReply46() {
  237 + return reply46;
  238 + }
  239 +
  240 + public void setReply46(Short reply46) {
  241 + this.reply46 = reply46;
  242 + }
  243 +
  244 + public Short getReply47() {
  245 + return reply47;
  246 + }
  247 +
  248 + public void setReply47(Short reply47) {
  249 + this.reply47 = reply47;
  250 + }
  251 +
  252 + public boolean isDispatch() {
  253 + return isDispatch;
  254 + }
  255 +
  256 + public void setDispatch(boolean isDispatch) {
  257 + this.isDispatch = isDispatch;
  258 + }
  259 +
  260 + public ScheduleRealInfo getSch() {
  261 + return sch;
  262 + }
  263 +
  264 + public void setSch(ScheduleRealInfo sch) {
  265 + this.sch = sch;
  266 + }
  267 +}
src/main/java/com/bsth/entity/directive/D64.java
1 -//package com.bsth.entity.directive;  
2 -//  
3 -//import javax.persistence.Table;  
4 -//import javax.persistence.Transient;  
5 -//import javax.persistence.Embeddable;  
6 -//import javax.persistence.Entity;  
7 -//import javax.persistence.GeneratedValue;  
8 -//import javax.persistence.Id;  
9 -//  
10 -///**  
11 -// *  
12 -// * @ClassName: D64  
13 -// * @Description: TODO(线路切换指令)  
14 -// * @author PanZhao  
15 -// * @date 2016年6月8日 下午1:41:15  
16 -// *  
17 -// */  
18 -//@Entity  
19 -//@Table(name = "bsth_v_directive_64")  
20 -//public class D64 extends Directive{  
21 -//  
22 -// @Id  
23 -// @GeneratedValue  
24 -// private Integer id;  
25 -//  
26 -// /**  
27 -// * 设备响应应答字  
28 -// * 0x06同意 0x15不同意  
29 -// */  
30 -// private Short respAck;  
31 -//  
32 -// private LineChangeData data;  
33 -//  
34 -// @Embeddable  
35 -// public static class LineChangeData {  
36 -//  
37 -// private Short cityCode;  
38 -//  
39 -// @Transient  
40 -// private String deviceId;  
41 -//  
42 -// private String lineId;  
43 -//  
44 -// public Short getCityCode() {  
45 -// return cityCode;  
46 -// }  
47 -//  
48 -// public void setCityCode(Short cityCode) {  
49 -// this.cityCode = cityCode;  
50 -// }  
51 -//  
52 -// public String getDeviceId() {  
53 -// return deviceId;  
54 -// }  
55 -//  
56 -// public void setDeviceId(String deviceId) {  
57 -// this.deviceId = deviceId;  
58 -// }  
59 -//  
60 -// public String getLineId() {  
61 -// return lineId;  
62 -// }  
63 -//  
64 -// public void setLineId(String lineId) {  
65 -// this.lineId = lineId;  
66 -// }  
67 -// }  
68 -//  
69 -// public Integer getId() {  
70 -// return id;  
71 -// }  
72 -//  
73 -// public void setId(Integer id) {  
74 -// this.id = id;  
75 -// }  
76 -//  
77 -// public LineChangeData getData() {  
78 -// return data;  
79 -// }  
80 -//  
81 -// public void setData(LineChangeData data) {  
82 -// this.data = data;  
83 -// }  
84 -//  
85 -// public Short getRespAck() {  
86 -// return respAck;  
87 -// }  
88 -//  
89 -// public void setRespAck(Short respAck) {  
90 -// this.respAck = respAck;  
91 -// }  
92 -//  
93 -// @Override  
94 -// public void setDeviceId(String deviceId) {  
95 -// if(this.data != null)  
96 -// this.data.setDeviceId(deviceId);  
97 -//  
98 -// this.deviceId = deviceId;  
99 -// }  
100 -//} 1 +package com.bsth.entity.directive;
  2 +
  3 +import javax.persistence.Table;
  4 +import javax.persistence.Transient;
  5 +import javax.persistence.Embeddable;
  6 +import javax.persistence.Entity;
  7 +import javax.persistence.GeneratedValue;
  8 +import javax.persistence.Id;
  9 +
  10 +/**
  11 + *
  12 + * @ClassName: D64
  13 + * @Description: TODO(线路切换指令)
  14 + * @author PanZhao
  15 + * @date 2016年6月8日 下午1:41:15
  16 + *
  17 + */
  18 +@Entity
  19 +@Table(name = "bsth_v_directive_64")
  20 +public class D64 extends Directive{
  21 +
  22 + @Id
  23 + @GeneratedValue
  24 + private Integer id;
  25 +
  26 + /**
  27 + * 设备响应应答字
  28 + * 0x06同意 0x15不同意
  29 + */
  30 + private Short respAck;
  31 +
  32 + private D64Data data;
  33 +
  34 + @Embeddable
  35 + public static class D64Data {
  36 +
  37 + private Short cityCode;
  38 +
  39 + @Transient
  40 + private String deviceId;
  41 +
  42 + private String lineId;
  43 +
  44 + public Short getCityCode() {
  45 + return cityCode;
  46 + }
  47 +
  48 + public void setCityCode(Short cityCode) {
  49 + this.cityCode = cityCode;
  50 + }
  51 +
  52 + public String getDeviceId() {
  53 + return deviceId;
  54 + }
  55 +
  56 + public void setDeviceId(String deviceId) {
  57 + this.deviceId = deviceId;
  58 + }
  59 +
  60 + public String getLineId() {
  61 + return lineId;
  62 + }
  63 +
  64 + public void setLineId(String lineId) {
  65 + this.lineId = lineId;
  66 + }
  67 + }
  68 +
  69 + public Integer getId() {
  70 + return id;
  71 + }
  72 +
  73 + public void setId(Integer id) {
  74 + this.id = id;
  75 + }
  76 +
  77 + public D64Data getData() {
  78 + return data;
  79 + }
  80 +
  81 + public void setData(D64Data data) {
  82 + this.data = data;
  83 + }
  84 +
  85 + public Short getRespAck() {
  86 + return respAck;
  87 + }
  88 +
  89 + public void setRespAck(Short respAck) {
  90 + this.respAck = respAck;
  91 + }
  92 +
  93 + @Override
  94 + public void setDeviceId(String deviceId) {
  95 + if(this.data != null)
  96 + this.data.setDeviceId(deviceId);
  97 +
  98 + this.deviceId = deviceId;
  99 + }
  100 +
  101 + public String getKey(){
  102 + return deviceId + "_" + timestamp;
  103 + }
  104 +}
src/main/java/com/bsth/entity/directive/D80.java
1 -//package com.bsth.entity.directive;  
2 -//  
3 -//import java.util.Date;  
4 -//  
5 -//import javax.persistence.CascadeType;  
6 -//import javax.persistence.Embeddable;  
7 -//import javax.persistence.Entity;  
8 -//import javax.persistence.FetchType;  
9 -//import javax.persistence.GeneratedValue;  
10 -//import javax.persistence.Id;  
11 -//import javax.persistence.NamedAttributeNode;  
12 -//import javax.persistence.NamedEntityGraph;  
13 -//import javax.persistence.NamedEntityGraphs;  
14 -//import javax.persistence.OneToOne;  
15 -//import javax.persistence.Table;  
16 -//import javax.persistence.Transient;  
17 -//  
18 -///**  
19 -// *  
20 -// * @ClassName: D80  
21 -// * @Description: TODO(驾驶员上报)  
22 -// * @author PanZhao  
23 -// * @date 2016年6月8日 下午12:36:42  
24 -// *  
25 -// */  
26 -//@Entity  
27 -//@Table(name = "bsth_v_report_80")  
28 -//@NamedEntityGraphs({  
29 -// @NamedEntityGraph(name = "directive80_c0", attributeNodes = {  
30 -// @NamedAttributeNode("c0")  
31 -// })  
32 -//})  
33 -//public class D80 {  
34 -//  
35 -// @Id  
36 -// @GeneratedValue  
37 -// private Integer id;  
38 -//  
39 -// /**  
40 -// * 设备编号  
41 -// */  
42 -// private String deviceId;  
43 -//  
44 -// /**  
45 -// * 时间戳(ms)  
46 -// */  
47 -// private Long timestamp;  
48 -//  
49 -// /**  
50 -// * 一级协议 0xC0  
51 -// */  
52 -// private Short operCode;  
53 -//  
54 -// private DriverReportData data;  
55 -//  
56 -// /**  
57 -// * c0 回复  
58 -// */  
59 -// @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)  
60 -// private DC0 c0;  
61 -//  
62 -// /** 调度员是否确认 */  
63 -// private boolean confirm;  
64 -//  
65 -// /** 处理人 */  
66 -// private String handleUser;  
67 -//  
68 -// /** 处理结果 0:同意 -1:不同意 */  
69 -// private int confirmRs;  
70 -//  
71 -// /** 处理时间 */  
72 -// private Date handleTime;  
73 -//  
74 -// @Embeddable  
75 -// public static class DriverReportData {  
76 -//  
77 -// /**  
78 -// * 0x86  
79 -// */  
80 -// private Short operCode2;  
81 -//  
82 -// /**  
83 -// * 请求代码 0xa1 恢复运营 0xa2 申请调档 0xa3 出场请求 0xa5 进场请求 0xa7 加油请求 0x50 车辆故障 0x70  
84 -// * 路阻报告 0x60 事故报告 0x11 扣证纠纷 0x12 报警  
85 -// */  
86 -// private Short requestCode;  
87 -//  
88 -// /**  
89 -// * 线路编码  
90 -// */  
91 -// private Integer lineId;  
92 -//  
93 -// /**  
94 -// * 车辆内部编码  
95 -// */  
96 -// @Transient  
97 -// private String nbbm;  
98 -//  
99 -// public Short getOperCode2() {  
100 -// return operCode2;  
101 -// }  
102 -//  
103 -// public void setOperCode2(Short operCode2) {  
104 -// this.operCode2 = operCode2;  
105 -// }  
106 -//  
107 -// public Short getRequestCode() {  
108 -// return requestCode;  
109 -// }  
110 -//  
111 -// public void setRequestCode(Short requestCode) {  
112 -// this.requestCode = requestCode;  
113 -// }  
114 -//  
115 -// public Integer getLineId() {  
116 -// return lineId;  
117 -// }  
118 -//  
119 -// public void setLineId(Integer lineId) {  
120 -// this.lineId = lineId;  
121 -// }  
122 -//  
123 -// public String getNbbm() {  
124 -// return nbbm;  
125 -// }  
126 -//  
127 -// public void setNbbm(String nbbm) {  
128 -// this.nbbm = nbbm;  
129 -// }  
130 -// }  
131 -//  
132 -// @Transient  
133 -// private String timeStr;  
134 -//  
135 -// public Integer getId() {  
136 -// return id;  
137 -// }  
138 -//  
139 -// public void setId(Integer id) {  
140 -// this.id = id;  
141 -// }  
142 -//  
143 -// public String getDeviceId() {  
144 -// return deviceId;  
145 -// }  
146 -//  
147 -// public void setDeviceId(String deviceId) {  
148 -// this.deviceId = deviceId;  
149 -// }  
150 -//  
151 -// public Long getTimestamp() {  
152 -// return timestamp;  
153 -// }  
154 -//  
155 -// public void setTimestamp(Long timestamp) {  
156 -// this.timestamp = timestamp;  
157 -// }  
158 -//  
159 -// public Short getOperCode() {  
160 -// return operCode;  
161 -// }  
162 -//  
163 -// public void setOperCode(Short operCode) {  
164 -// this.operCode = operCode;  
165 -// }  
166 -//  
167 -// public DriverReportData getData() {  
168 -// return data;  
169 -// }  
170 -//  
171 -// public void setData(DriverReportData data) {  
172 -// this.data = data;  
173 -// }  
174 -//  
175 -// public DC0 getC0() {  
176 -// return c0;  
177 -// }  
178 -//  
179 -// public void setC0(DC0 c0) {  
180 -// this.c0 = c0;  
181 -// }  
182 -//  
183 -// public boolean isConfirm() {  
184 -// return confirm;  
185 -// }  
186 -//  
187 -// public void setConfirm(boolean confirm) {  
188 -// this.confirm = confirm;  
189 -// }  
190 -//  
191 -// public int getConfirmRs() {  
192 -// return confirmRs;  
193 -// }  
194 -//  
195 -// public void setConfirmRs(int confirmRs) {  
196 -// this.confirmRs = confirmRs;  
197 -// }  
198 -//  
199 -// public String getHandleUser() {  
200 -// return handleUser;  
201 -// }  
202 -//  
203 -// public void setHandleUser(String handleUser) {  
204 -// this.handleUser = handleUser;  
205 -// }  
206 -//  
207 -// public String getTimeStr() {  
208 -// return timeStr;  
209 -// }  
210 -//  
211 -// public void setTimeStr(String timeStr) {  
212 -// this.timeStr = timeStr;  
213 -// }  
214 -//  
215 -// public Date getHandleTime() {  
216 -// return handleTime;  
217 -// }  
218 -//  
219 -// public void setHandleTime(Date handleTime) {  
220 -// this.handleTime = handleTime;  
221 -// }  
222 -//} 1 +package com.bsth.entity.directive;
  2 +
  3 +import java.util.Date;
  4 +
  5 +import javax.persistence.CascadeType;
  6 +import javax.persistence.Embeddable;
  7 +import javax.persistence.Entity;
  8 +import javax.persistence.FetchType;
  9 +import javax.persistence.GeneratedValue;
  10 +import javax.persistence.Id;
  11 +import javax.persistence.NamedAttributeNode;
  12 +import javax.persistence.NamedEntityGraph;
  13 +import javax.persistence.NamedEntityGraphs;
  14 +import javax.persistence.OneToOne;
  15 +import javax.persistence.Table;
  16 +import javax.persistence.Transient;
  17 +
  18 +import com.bsth.entity.directive.DC0.DC0Data;
  19 +
  20 +/**
  21 + *
  22 + * @ClassName: D80
  23 + * @Description: TODO(驾驶员上报)
  24 + * @author PanZhao
  25 + * @date 2016年6月8日 下午12:36:42
  26 + *
  27 + */
  28 +@Entity
  29 +@Table(name = "bsth_v_report_80")
  30 +@NamedEntityGraphs({
  31 + @NamedEntityGraph(name = "directive80_c0", attributeNodes = {
  32 + @NamedAttributeNode("c0")
  33 + })
  34 +})
  35 +public class D80 {
  36 +
  37 + @Id
  38 + @GeneratedValue
  39 + private Integer id;
  40 +
  41 + /**
  42 + * 设备编号
  43 + */
  44 + private String deviceId;
  45 +
  46 + /**
  47 + * 时间戳(ms)
  48 + */
  49 + private Long timestamp;
  50 +
  51 + /**
  52 + * 一级协议 0xC0
  53 + */
  54 + private Short operCode;
  55 +
  56 + private D80Data data;
  57 +
  58 + /**
  59 + * c0 回复
  60 + */
  61 + @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
  62 + private DC0 c0;
  63 +
  64 + /** 调度员是否确认 */
  65 + private boolean confirm;
  66 +
  67 + /** 处理人 */
  68 + private String handleUser;
  69 +
  70 + /** 处理结果 0:同意 -1:不同意 */
  71 + private int confirmRs;
  72 +
  73 + /** 处理时间 */
  74 + private Date handleTime;
  75 +
  76 + private String remarks;
  77 +
  78 + @Embeddable
  79 + public static class D80Data {
  80 +
  81 + /**
  82 + * 0x86
  83 + */
  84 + private Short operCode2;
  85 +
  86 + /**
  87 + * 请求代码 0xa1 恢复运营 0xa2 申请调档 0xa3 出场请求 0xa5 进场请求 0xa7 加油请求 0x50 车辆故障 0x70
  88 + * 路阻报告 0x60 事故报告 0x11 扣证纠纷 0x12 报警
  89 + */
  90 + private Short requestCode;
  91 +
  92 + /**
  93 + * 线路编码
  94 + */
  95 + private Integer lineId;
  96 +
  97 + /**
  98 + * 车辆内部编码
  99 + */
  100 + @Transient
  101 + private String nbbm;
  102 +
  103 + public Short getOperCode2() {
  104 + return operCode2;
  105 + }
  106 +
  107 + public void setOperCode2(Short operCode2) {
  108 + this.operCode2 = operCode2;
  109 + }
  110 +
  111 + public Short getRequestCode() {
  112 + return requestCode;
  113 + }
  114 +
  115 + public void setRequestCode(Short requestCode) {
  116 + this.requestCode = requestCode;
  117 + }
  118 +
  119 + public Integer getLineId() {
  120 + return lineId;
  121 + }
  122 +
  123 + public void setLineId(Integer lineId) {
  124 + this.lineId = lineId;
  125 + }
  126 +
  127 + public String getNbbm() {
  128 + return nbbm;
  129 + }
  130 +
  131 + public void setNbbm(String nbbm) {
  132 + this.nbbm = nbbm;
  133 + }
  134 + }
  135 +
  136 + @Transient
  137 + private String timeStr;
  138 +
  139 + public Integer getId() {
  140 + return id;
  141 + }
  142 +
  143 + public void setId(Integer id) {
  144 + this.id = id;
  145 + }
  146 +
  147 + public String getDeviceId() {
  148 + return deviceId;
  149 + }
  150 +
  151 + public void setDeviceId(String deviceId) {
  152 + this.deviceId = deviceId;
  153 + }
  154 +
  155 + public Long getTimestamp() {
  156 + return timestamp;
  157 + }
  158 +
  159 + public void setTimestamp(Long timestamp) {
  160 + this.timestamp = timestamp;
  161 + }
  162 +
  163 + public Short getOperCode() {
  164 + return operCode;
  165 + }
  166 +
  167 + public void setOperCode(Short operCode) {
  168 + this.operCode = operCode;
  169 + }
  170 +
  171 + public D80Data getData() {
  172 + return data;
  173 + }
  174 +
  175 + public void setData(D80Data data) {
  176 + this.data = data;
  177 + }
  178 +
  179 + public DC0 getC0() {
  180 + return c0;
  181 + }
  182 +
  183 + public void setC0(DC0 c0) {
  184 + this.c0 = c0;
  185 + }
  186 +
  187 + public boolean isConfirm() {
  188 + return confirm;
  189 + }
  190 +
  191 + public void setConfirm(boolean confirm) {
  192 + this.confirm = confirm;
  193 + }
  194 +
  195 + public int getConfirmRs() {
  196 + return confirmRs;
  197 + }
  198 +
  199 + public void setConfirmRs(int confirmRs) {
  200 + this.confirmRs = confirmRs;
  201 + }
  202 +
  203 + public String getHandleUser() {
  204 + return handleUser;
  205 + }
  206 +
  207 + public void setHandleUser(String handleUser) {
  208 + this.handleUser = handleUser;
  209 + }
  210 +
  211 + public String getTimeStr() {
  212 + return timeStr;
  213 + }
  214 +
  215 + public void setTimeStr(String timeStr) {
  216 + this.timeStr = timeStr;
  217 + }
  218 +
  219 + public Date getHandleTime() {
  220 + return handleTime;
  221 + }
  222 +
  223 + public void setHandleTime(Date handleTime) {
  224 + this.handleTime = handleTime;
  225 + }
  226 +
  227 + public String getRemarks() {
  228 + return remarks;
  229 + }
  230 +
  231 + public void setRemarks(String remarks) {
  232 + this.remarks = remarks;
  233 + }
  234 +
  235 + public void addRemarks(String remarks) {
  236 + if(null == this.remarks)
  237 + setRemarks(remarks);
  238 + else
  239 + setRemarks(getRemarks() + remarks);
  240 + }
  241 +
  242 + public void setC0(int reply, String handleUser){
  243 + this.setConfirm(true);
  244 + this.setHandleUser(handleUser);
  245 + this.setConfirmRs(reply);
  246 + this.setHandleTime(new Date());
  247 + // 封装C0数据包并回复设备
  248 + DC0 c0 = new DC0();
  249 + c0.setDeviceId(this.getDeviceId());
  250 + c0.setTimestamp(this.getTimestamp());
  251 + c0.setOperCode((short) 0xC0);
  252 + DC0Data data = new DC0Data();
  253 + data.setOperCode2((short) 0x86);
  254 + data.setRequestAck((short) (reply == 0 ? 0x06 : 0x15));
  255 + c0.setData(data);
  256 + this.setC0(c0);
  257 + }
  258 +}