Commit d05f876d32e7af6a282ba5858ea7fee825813386

Authored by 王通
1 parent 5e2c8d54

1.调度抓取网关数据提前

2.调度现在不按班次去修正上下行状态
src/main/java/com/bsth/XDApplication.java
1   -package com.bsth;
2   -
3   -import com.bsth.data.BasicData;
4   -import com.bsth.data.LineVersionsData;
5   -import com.bsth.data.ThreadMonotor;
6   -import com.bsth.data.car_out_info.UpdateDBThread;
7   -import com.bsth.data.directive.DirectivesPstThread;
8   -import com.bsth.data.forecast.SampleTimeDataLoader;
9   -import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
10   -import com.bsth.data.gpsdata_v2.thread.OfflineMonitorThread;
11   -import com.bsth.data.msg_queue.DirectivePushQueue;
12   -import com.bsth.data.msg_queue.WebSocketPushQueue;
13   -import com.bsth.data.safe_driv.SafeDrivDataLoadThread;
14   -import com.bsth.data.schedule.DayOfSchedule;
15   -import com.bsth.data.schedule.auto_exec.AutoExecScanThread;
16   -import com.bsth.data.schedule.e_state_check.thread.FixedCheckStationCodeThread;
17   -import com.bsth.data.schedule.edit_logs.SeiPstThread;
18   -import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
19   -import com.bsth.data.schedule.signal.SchSiginUpdateDBThread;
20   -import com.bsth.data.schedule.thread.CalcOilThread;
21   -import com.bsth.data.schedule.thread.SchedulePstThread;
22   -import com.bsth.data.schedule.thread.ScheduleRefreshThread;
23   -import com.bsth.data.schedule.thread.SubmitToTrafficManage;
24   -import com.bsth.util.DateUtils;
25   -import com.bsth.util.Tools;
26   -import org.slf4j.Logger;
27   -import org.slf4j.LoggerFactory;
28   -import org.springframework.beans.factory.annotation.Autowired;
29   -import org.springframework.boot.CommandLineRunner;
30   -import org.springframework.stereotype.Component;
31   -
32   -import java.util.concurrent.ScheduledExecutorService;
33   -import java.util.concurrent.TimeUnit;
34   -
35   -/**
36   - * 线调大部分服务都在这里启动
37   - * Created by panzhao on 2017/5/14.
38   - */
39   -@Component
40   -public class XDApplication implements CommandLineRunner {
41   -
42   - Logger log = LoggerFactory.getLogger(this.getClass());
43   -
44   - @Autowired
45   - BasicData.BasicDataLoader basicDataLoader;
46   - @Autowired
47   - UpdateDBThread fcxxUpdateThread;
48   - @Autowired
49   - ScheduleRefreshThread scheduleRefreshThread;
50   - @Autowired
51   - SchedulePstThread schedulePstThread;
52   - @Autowired
53   - ScheduleLateThread scheduleLateThread;
54   - @Autowired
55   - SubmitToTrafficManage submitToTrafficManage;
56   - @Autowired
57   - CalcOilThread calcOilThread;
58   - @Autowired
59   - DirectivesPstThread directivesPstThread;
60   - @Autowired
61   - ThreadMonotor threadMonotor;
62   - @Autowired
63   - SeiPstThread seiPstThread;
64   - @Autowired
65   - SampleTimeDataLoader sampleTimeDataLoader;
66   - @Autowired
67   - SchSiginUpdateDBThread schSiginUpdateDBThread;
68   - @Autowired
69   - AutoExecScanThread autoExecScanThread;
70   -
71   - @Autowired
72   - GpsDataLoaderThread gpsDataLoader;
73   -
74   - @Autowired
75   - OfflineMonitorThread offlineMonitorThread;
76   -
77   - @Autowired
78   - LineVersionsData lineVersionsData;
79   -
80   - /*@Autowired
81   - FixedEnableVerionsThread fixedEnableVerionsThread;*/
82   -
83   - @Autowired
84   - SafeDrivDataLoadThread safeDrivDataLoadThread;
85   -
86   - @Autowired
87   - FixedCheckStationCodeThread fixedCheckStationCodeThread;
88   -
89   - private static long timeDiff;
90   - private static long timeDiffTraffic;
91   -
92   - static {
93   - // 早上2:20
94   - timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
95   - if (timeDiff < 0)
96   - timeDiff += (1000 * 60 * 60 * 24);
97   - // 早上07:00
98   - timeDiffTraffic = (DateUtils.getTimestamp() + 1000 * 60 * 60 * 7) - System.currentTimeMillis();
99   - if (timeDiffTraffic < 0)
100   - timeDiffTraffic += (1000 * 60 * 60 * 24);
101   - }
102   -
103   - @Override
104   - public void run(String... strings) throws Exception {
105   - try {
106   - Tools tools = new Tools("application.properties");
107   - String environment = tools.getValue("spring.profiles.active");
108   - //预先加载基础的对照数据
109   - basicDataLoader.loadAllData();
110   - switch (environment){
111   - case "dev":
112   - devInit();
113   - break;
114   - case "prod":
115   - prodInit();
116   - break;
117   - }
118   - }catch (Exception e){
119   - log.error("线调后台启动出现异常!!", e);
120   - System.exit(1);
121   - }
122   - }
123   -
124   - @Autowired
125   - DayOfSchedule dayOfSchedule;
126   - public void devInit(){
127   - log.info("devInit...");
128   - ScheduledExecutorService sexec = Application.mainServices;
129   - //抓取GPS数据
130   - GpsDataLoaderThread.setFlag(-1);
131   - //dayOfSchedule.dataRecovery();
132   - //sexec.scheduleWithFixedDelay(gpsDataLoader, 60, 4, TimeUnit.SECONDS);
133   - //实际排班更新线程
134   - //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
135   - //sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 30, TimeUnit.SECONDS);//检查班次误点
136   - //sexec.scheduleWithFixedDelay(autoExecScanThread, 100, 50, TimeUnit.SECONDS);//班次自动执行
137   - //WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
138   -
139   - //sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 50, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
140   - //实际排班延迟入库线程
141   - //sexec.scheduleWithFixedDelay(schedulePstThread, 60, 15, TimeUnit.SECONDS);
142   - //班次修正日志延迟入库
143   - //sexec.scheduleWithFixedDelay(seiPstThread, 60, 30, TimeUnit.SECONDS);
144   - //调度指令延迟入库
145   - //sexec.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS);
146   - //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
147   - //sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
148   -
149   - //安全驾驶
150   - //sexec.scheduleWithFixedDelay(safeDrivDataLoadThread, 40, 30, TimeUnit.SECONDS);
151   -
152   - //sexec.scheduleWithFixedDelay(fixedEnableVerionsThread, 20, 60 * 2 , TimeUnit.SECONDS);
153   - }
154   -
155   - public void prodInit(){
156   - log.info("prodInit...");
157   - ScheduledExecutorService sexec = Application.mainServices;
158   - //安全驾驶
159   - //sexec.scheduleWithFixedDelay(safeDrivDataLoadThread, 180, 10, TimeUnit.SECONDS);
160   -
161   - /** 线调业务 */
162   - sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
163   - sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
164   - GpsDataLoaderThread.setFlag(-1);
165   - sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据
166   - sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
167   -
168   - sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
169   - sexec.scheduleWithFixedDelay(schedulePstThread, 180, 10, TimeUnit.SECONDS);//班次延迟入库线程
170   - sexec.scheduleWithFixedDelay(seiPstThread, 180, 60, TimeUnit.SECONDS);//班次修正日志入库
171   - sexec.scheduleWithFixedDelay(directivesPstThread, 120, 60, TimeUnit.SECONDS);//调度指令延迟入库
172   - //sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
173   - sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 140, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
174   - sexec.scheduleWithFixedDelay(basicDataLoader, 1, 1, TimeUnit.HOURS);//基础数据更新
175   - sexec.scheduleWithFixedDelay(autoExecScanThread, 180, 50, TimeUnit.SECONDS);//班次自动执行
176   - DirectivePushQueue.start();//消息队列 -指令,系统下发的
177   - WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
178   -
179   - /** 线调为其他程序提供的数据 --写入数据库 */
180   - sexec.scheduleWithFixedDelay(fcxxUpdateThread, 160, 30, TimeUnit.SECONDS);//发车信息(发车屏、信息发布)
181   - //线路首末班数据(网关用,班次更新时写入)
182   - //com.bsth.data.schedule.f_a_l.FirstAndLastHandler
183   - sexec.scheduleWithFixedDelay(schSiginUpdateDBThread, 160, 60 * 30, TimeUnit.SECONDS);//无法自动完成的班次信息(网关用,补信号)
184   -
185   - //运管处静态数据提交
186   - log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处");
187   - sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiffTraffic / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
188   - //计算油、公里加注
189   - sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
190   -
191   - //线路版本更新
192   - sexec.scheduleWithFixedDelay(lineVersionsData, 60 * 5, 60 * 15, TimeUnit.SECONDS);
193   -
194   - //线路版本更新
195   - //sexec.scheduleWithFixedDelay(fixedEnableVerionsThread, 60 * 4, 60 * 2 , TimeUnit.SECONDS);
196   - }
197   -}
  1 +package com.bsth;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.LineVersionsData;
  5 +import com.bsth.data.ThreadMonotor;
  6 +import com.bsth.data.car_out_info.UpdateDBThread;
  7 +import com.bsth.data.directive.DirectivesPstThread;
  8 +import com.bsth.data.forecast.SampleTimeDataLoader;
  9 +import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
  10 +import com.bsth.data.gpsdata_v2.thread.OfflineMonitorThread;
  11 +import com.bsth.data.msg_queue.DirectivePushQueue;
  12 +import com.bsth.data.msg_queue.WebSocketPushQueue;
  13 +import com.bsth.data.safe_driv.SafeDrivDataLoadThread;
  14 +import com.bsth.data.schedule.DayOfSchedule;
  15 +import com.bsth.data.schedule.auto_exec.AutoExecScanThread;
  16 +import com.bsth.data.schedule.e_state_check.thread.FixedCheckStationCodeThread;
  17 +import com.bsth.data.schedule.edit_logs.SeiPstThread;
  18 +import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
  19 +import com.bsth.data.schedule.signal.SchSiginUpdateDBThread;
  20 +import com.bsth.data.schedule.thread.CalcOilThread;
  21 +import com.bsth.data.schedule.thread.SchedulePstThread;
  22 +import com.bsth.data.schedule.thread.ScheduleRefreshThread;
  23 +import com.bsth.data.schedule.thread.SubmitToTrafficManage;
  24 +import com.bsth.util.DateUtils;
  25 +import com.bsth.util.Tools;
  26 +import org.slf4j.Logger;
  27 +import org.slf4j.LoggerFactory;
  28 +import org.springframework.beans.factory.annotation.Autowired;
  29 +import org.springframework.boot.CommandLineRunner;
  30 +import org.springframework.stereotype.Component;
  31 +
  32 +import java.util.concurrent.ScheduledExecutorService;
  33 +import java.util.concurrent.TimeUnit;
  34 +
  35 +/**
  36 + * 线调大部分服务都在这里启动
  37 + * Created by panzhao on 2017/5/14.
  38 + */
  39 +@Component
  40 +public class XDApplication implements CommandLineRunner {
  41 +
  42 + Logger log = LoggerFactory.getLogger(this.getClass());
  43 +
  44 + @Autowired
  45 + BasicData.BasicDataLoader basicDataLoader;
  46 + @Autowired
  47 + UpdateDBThread fcxxUpdateThread;
  48 + @Autowired
  49 + ScheduleRefreshThread scheduleRefreshThread;
  50 + @Autowired
  51 + SchedulePstThread schedulePstThread;
  52 + @Autowired
  53 + ScheduleLateThread scheduleLateThread;
  54 + @Autowired
  55 + SubmitToTrafficManage submitToTrafficManage;
  56 + @Autowired
  57 + CalcOilThread calcOilThread;
  58 + @Autowired
  59 + DirectivesPstThread directivesPstThread;
  60 + @Autowired
  61 + ThreadMonotor threadMonotor;
  62 + @Autowired
  63 + SeiPstThread seiPstThread;
  64 + @Autowired
  65 + SampleTimeDataLoader sampleTimeDataLoader;
  66 + @Autowired
  67 + SchSiginUpdateDBThread schSiginUpdateDBThread;
  68 + @Autowired
  69 + AutoExecScanThread autoExecScanThread;
  70 +
  71 + @Autowired
  72 + GpsDataLoaderThread gpsDataLoader;
  73 +
  74 + @Autowired
  75 + OfflineMonitorThread offlineMonitorThread;
  76 +
  77 + @Autowired
  78 + LineVersionsData lineVersionsData;
  79 +
  80 + /*@Autowired
  81 + FixedEnableVerionsThread fixedEnableVerionsThread;*/
  82 +
  83 + @Autowired
  84 + SafeDrivDataLoadThread safeDrivDataLoadThread;
  85 +
  86 + @Autowired
  87 + FixedCheckStationCodeThread fixedCheckStationCodeThread;
  88 +
  89 + private static long timeDiff;
  90 + private static long timeDiffTraffic;
  91 +
  92 + static {
  93 + // 早上2:20
  94 + timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
  95 + if (timeDiff < 0)
  96 + timeDiff += (1000 * 60 * 60 * 24);
  97 + // 早上07:00
  98 + timeDiffTraffic = (DateUtils.getTimestamp() + 1000 * 60 * 60 * 7) - System.currentTimeMillis();
  99 + if (timeDiffTraffic < 0)
  100 + timeDiffTraffic += (1000 * 60 * 60 * 24);
  101 + }
  102 +
  103 + @Override
  104 + public void run(String... strings) throws Exception {
  105 + try {
  106 + Tools tools = new Tools("application.properties");
  107 + String environment = tools.getValue("spring.profiles.active");
  108 + //预先加载基础的对照数据
  109 + basicDataLoader.loadAllData();
  110 + switch (environment){
  111 + case "dev":
  112 + devInit();
  113 + break;
  114 + case "prod":
  115 + prodInit();
  116 + break;
  117 + }
  118 + }catch (Exception e){
  119 + log.error("线调后台启动出现异常!!", e);
  120 + System.exit(1);
  121 + }
  122 + }
  123 +
  124 + @Autowired
  125 + DayOfSchedule dayOfSchedule;
  126 + public void devInit(){
  127 + log.info("devInit...");
  128 + ScheduledExecutorService sexec = Application.mainServices;
  129 + //抓取GPS数据
  130 + GpsDataLoaderThread.setFlag(-1);
  131 + //dayOfSchedule.dataRecovery();
  132 + //sexec.scheduleWithFixedDelay(gpsDataLoader, 60, 4, TimeUnit.SECONDS);
  133 + //实际排班更新线程
  134 + //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  135 + //sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 30, TimeUnit.SECONDS);//检查班次误点
  136 + //sexec.scheduleWithFixedDelay(autoExecScanThread, 100, 50, TimeUnit.SECONDS);//班次自动执行
  137 + //WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
  138 +
  139 + //sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 50, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
  140 + //实际排班延迟入库线程
  141 + //sexec.scheduleWithFixedDelay(schedulePstThread, 60, 15, TimeUnit.SECONDS);
  142 + //班次修正日志延迟入库
  143 + //sexec.scheduleWithFixedDelay(seiPstThread, 60, 30, TimeUnit.SECONDS);
  144 + //调度指令延迟入库
  145 + //sexec.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS);
  146 + //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
  147 + //sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
  148 +
  149 + //安全驾驶
  150 + //sexec.scheduleWithFixedDelay(safeDrivDataLoadThread, 40, 30, TimeUnit.SECONDS);
  151 +
  152 + //sexec.scheduleWithFixedDelay(fixedEnableVerionsThread, 20, 60 * 2 , TimeUnit.SECONDS);
  153 + }
  154 +
  155 + public void prodInit(){
  156 + log.info("prodInit...");
  157 + ScheduledExecutorService sexec = Application.mainServices;
  158 + //安全驾驶
  159 + //sexec.scheduleWithFixedDelay(safeDrivDataLoadThread, 180, 10, TimeUnit.SECONDS);
  160 +
  161 + /** 线调业务 */
  162 + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
  163 + sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
  164 + GpsDataLoaderThread.setFlag(-1);
  165 + sexec.scheduleWithFixedDelay(gpsDataLoader, 10, 2, TimeUnit.SECONDS);//抓取GPS数据
  166 + sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
  167 +
  168 + sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
  169 + sexec.scheduleWithFixedDelay(schedulePstThread, 180, 10, TimeUnit.SECONDS);//班次延迟入库线程
  170 + sexec.scheduleWithFixedDelay(seiPstThread, 180, 60, TimeUnit.SECONDS);//班次修正日志入库
  171 + sexec.scheduleWithFixedDelay(directivesPstThread, 120, 60, TimeUnit.SECONDS);//调度指令延迟入库
  172 + //sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
  173 + sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 140, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
  174 + sexec.scheduleWithFixedDelay(basicDataLoader, 1, 1, TimeUnit.HOURS);//基础数据更新
  175 + sexec.scheduleWithFixedDelay(autoExecScanThread, 180, 50, TimeUnit.SECONDS);//班次自动执行
  176 + DirectivePushQueue.start();//消息队列 -指令,系统下发的
  177 + WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
  178 +
  179 + /** 线调为其他程序提供的数据 --写入数据库 */
  180 + sexec.scheduleWithFixedDelay(fcxxUpdateThread, 160, 30, TimeUnit.SECONDS);//发车信息(发车屏、信息发布)
  181 + //线路首末班数据(网关用,班次更新时写入)
  182 + //com.bsth.data.schedule.f_a_l.FirstAndLastHandler
  183 + sexec.scheduleWithFixedDelay(schSiginUpdateDBThread, 160, 60 * 30, TimeUnit.SECONDS);//无法自动完成的班次信息(网关用,补信号)
  184 +
  185 + //运管处静态数据提交
  186 + log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处");
  187 + sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiffTraffic / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  188 + //计算油、公里加注
  189 + sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  190 +
  191 + //线路版本更新
  192 + sexec.scheduleWithFixedDelay(lineVersionsData, 60 * 5, 60 * 15, TimeUnit.SECONDS);
  193 +
  194 + //线路版本更新
  195 + //sexec.scheduleWithFixedDelay(fixedEnableVerionsThread, 60 * 4, 60 * 2 , TimeUnit.SECONDS);
  196 + }
  197 +}
... ...
src/main/java/com/bsth/data/gpsdata_v2/handlers/GpsStateProcess.java
1   -package com.bsth.data.gpsdata_v2.handlers;
2   -
3   -import com.bsth.data.gpsdata_v2.entity.GpsEntity;
4   -import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
5   -import com.bsth.data.schedule.DayOfSchedule;
6   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
7   -import org.springframework.beans.factory.annotation.Autowired;
8   -import org.springframework.stereotype.Component;
9   -
10   -import java.util.concurrent.ConcurrentHashMap;
11   -import java.util.concurrent.ConcurrentMap;
12   -
13   -/**
14   - * GPS 状态处理
15   - * Created by panzhao on 2017/11/15.
16   - */
17   -@Component
18   -public class GpsStateProcess {
19   -
20   - @Autowired
21   - DayOfSchedule dayOfSchedule;
22   -
23   - @Autowired
24   - GpsStatusManager gpsStatusManager;
25   -
26   - /**
27   - * 设置状态差异连续次数
28   - */
29   - private static ConcurrentMap<String, Integer> stateDiffMap = new ConcurrentHashMap<>();
30   -
31   - private final static int CHANGE_THRESHOLD = 2;
32   -
33   - public void process(GpsEntity gps) {
34   - //在执行的任务
35   - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
36   -
37   - if (null == sch)
38   - return;
39   -
40   - int upDown = Integer.parseInt(sch.getXlDir());
41   - int schState = dayOfSchedule.emptyService(sch)?1:0;
42   - String device = gps.getDeviceId();
43   - /**
44   - * 网关在进终点的时候,会直接将当前点位状态改变
45   - * 为避免出现单个点的状态跳动,设置一下切换阈值
46   - */
47   - if(gps.getState() != schState || gps.getUpDown() != upDown){
48   - Integer count = 0;
49   - if(stateDiffMap.containsKey(device))
50   - count = stateDiffMap.get(device);
51   -
52   - count ++;
53   -
54   - if(count >= CHANGE_THRESHOLD){
55   - //下发指令纠正车载的 营运状态 和 走向
56   - gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, schState, "同步@系统");
57   - count = 0;
58   - }
59   -
60   - stateDiffMap.put(device, count);
61   -
62   - //记录原始设备状态
63   - gps.setOrigStateStr(gps.getUpDown() + "_" + gps.getState());
64   - }
65   - else
66   - stateDiffMap.put(device, 0);
67   -
68   - if (gps.getUpDown() != upDown) {
69   - gps.setUpDown((byte) upDown);//修正走向
70   - }
71   -
72   - if(gps.getState() != schState){
73   - gps.setState(schState);//修正营运状态
74   - }
75   -
76   - if (!sch.getXlBm().equals(gps.getLineId())) {
77   - //切换车载的 线路编码
78   - gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统");
79   - }
80   - }
81   -}
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  4 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  5 +import com.bsth.data.schedule.DayOfSchedule;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Component;
  9 +
  10 +import java.util.concurrent.ConcurrentHashMap;
  11 +import java.util.concurrent.ConcurrentMap;
  12 +
  13 +/**
  14 + * GPS 状态处理
  15 + * Created by panzhao on 2017/11/15.
  16 + */
  17 +@Component
  18 +public class GpsStateProcess {
  19 +
  20 + @Autowired
  21 + DayOfSchedule dayOfSchedule;
  22 +
  23 + @Autowired
  24 + GpsStatusManager gpsStatusManager;
  25 +
  26 + /**
  27 + * 设置状态差异连续次数
  28 + */
  29 + private static ConcurrentMap<String, Integer> stateDiffMap = new ConcurrentHashMap<>();
  30 +
  31 + private final static int CHANGE_THRESHOLD = 2;
  32 +
  33 + public void process(GpsEntity gps) {
  34 + //在执行的任务
  35 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  36 +
  37 + if (null == sch)
  38 + return;
  39 +
  40 + int upDown = Integer.parseInt(sch.getXlDir());
  41 + int schState = dayOfSchedule.emptyService(sch)?1:0;
  42 + String device = gps.getDeviceId();
  43 + /**
  44 + * 网关在进终点的时候,会直接将当前点位状态改变
  45 + * 为避免出现单个点的状态跳动,设置一下切换阈值
  46 + */
  47 + if(gps.getState() != schState || gps.getUpDown() != upDown){
  48 + Integer count = 0;
  49 + if(stateDiffMap.containsKey(device))
  50 + count = stateDiffMap.get(device);
  51 +
  52 + count ++;
  53 +
  54 + if(count >= CHANGE_THRESHOLD){
  55 + //下发指令纠正车载的 营运状态 和 走向
  56 + gpsStatusManager.changeServiceState(gps.getNbbm(), upDown, schState, "同步@系统");
  57 + count = 0;
  58 + }
  59 +
  60 + stateDiffMap.put(device, count);
  61 +
  62 + //记录原始设备状态
  63 + gps.setOrigStateStr(gps.getUpDown() + "_" + gps.getState());
  64 + }
  65 + else
  66 + stateDiffMap.put(device, 0);
  67 +
  68 +// if (gps.getUpDown() != upDown) {
  69 +// gps.setUpDown((byte) upDown);//修正走向
  70 +// }
  71 +
  72 + if(gps.getState() != schState){
  73 + gps.setState(schState);//修正营运状态
  74 + }
  75 +
  76 + if (!sch.getXlBm().equals(gps.getLineId())) {
  77 + //切换车载的 线路编码
  78 + gpsStatusManager.changeLine(gps.getNbbm(), sch.getXlBm(), "同步@系统");
  79 + }
  80 + }
  81 +}
... ...