Commit 5bb98a8701a1894073cf994c41b47270048d58a4

Authored by 潘钊
2 parents b55a1acd 4413865a

Merge branch 'pudong' of http://222.66.0.204:8090/panzhaov5/bsth_control into pudong

src/main/java/com/bsth/data/gpsdata_v2/handlers/InStationProcess.java
1   -package com.bsth.data.gpsdata_v2.handlers;
2   -
3   -import com.bsth.data.LineConfigData;
4   -import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
5   -import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
6   -import com.bsth.data.gpsdata_v2.entity.GpsEntity;
7   -import com.bsth.data.gpsdata_v2.entity.StationRoute;
8   -import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
9   -import com.bsth.data.gpsdata_v2.utils.GeoUtils;
10   -import com.bsth.data.msg_queue.DirectivePushQueue;
11   -import com.bsth.data.schedule.DayOfSchedule;
12   -import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
13   -import com.bsth.entity.realcontrol.LineConfig;
14   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
15   -import com.bsth.websocket.handler.SendUtils;
16   -import org.apache.commons.lang3.StringUtils;
17   -import org.slf4j.Logger;
18   -import org.slf4j.LoggerFactory;
19   -import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.stereotype.Component;
21   -
22   -import java.util.List;
23   -
24   -/**
25   - * 车辆到站处理程序
26   - * Created by panzhao on 2017/11/16.
27   - */
28   -@Component
29   -public class InStationProcess {
30   -
31   - @Autowired
32   - DayOfSchedule dayOfSchedule;
33   -
34   - @Autowired
35   - LineConfigData lineConfigData;
36   -
37   - @Autowired
38   - SendUtils sendUtils;
39   -
40   - @Autowired
41   - GpsStatusManager gpsStatusManager;
42   -
43   - Logger logger = LoggerFactory.getLogger(this.getClass());
44   -
45   - public void process(GpsEntity gps) {
46   - //自动执行的班次信号,滚蛋
47   - LineConfig config = lineConfigData.get(gps.getLineId());
48   - if(null != config && config.isAutoExec())
49   - return;
50   -
51   - GpsEntity prev = GpsCacheData.getPrev(gps);
52   -
53   - if(null == prev)
54   - return;
55   -
56   - //从站外到站内
57   - if(prev.getInstation() == 0 && gps.getInstation() > 0){
58   - inStation(gps, prev);
59   - }
60   -
61   - //从站内到另一个站内
62   - if(prev.getInstation() == 1 && gps.getInstation() == 1
63   - && !prev.getStopNo().equals(gps.getStopNo())
64   - && !prev.getStation().getName().equals(gps.getStation().getName()))
65   - inStation(gps, prev);
66   -
67   - //从场内到站内
68   - if(prev.getInstation() == 2 && gps.getInstation() == 1){
69   - inStation(gps, prev);
70   - }
71   -
72   - //被起点站覆盖的情况下进场
73   - if(isInPark(gps, prev))
74   - inStation(gps, prev);
75   - }
76   -
77   - /**
78   - * 进站
79   - *
80   - * @param gps
81   - * @param prev
82   - */
83   - private void inStation(GpsEntity gps, GpsEntity prev) {
84   - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
85   - boolean flow = true;
86   - //要经过2个中途站才能进
87   - int count = GpsCacheData.lastInTrailsSize(gps);
88   - List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown());
89   - if (null != sch && isNormalSch(sch) && gps.getInstation() == 1 && routes.size() > 4
90   - && count < 2) {
91   - logger.info("没有进中途站,拒绝进站... -" + gps.getNbbm() + " -time:" + gps.getTimestamp());
92   - flow = false;
93   - }
94   -
95   - boolean isEnd = false;
96   -
97   - //进终点
98   - if (flow && null != sch &&
99   - ((sch.getZdzCode().equals(gps.getStopNo()) && gps.getInstation()>0) || sch.getZdzCode().equals(gps.getCarparkNo()))) {
100   - inEndStation(sch, gps);
101   - isEnd = true;
102   - }
103   -
104   - GpsCacheData.in(gps, isEnd);
105   - }
106   -
107   - private boolean isNormalSch(ScheduleRealInfo sch) {
108   - return sch.getBcType().equals("normal");
109   - }
110   -
111   - private boolean isNotInOut(ScheduleRealInfo sch) {
112   - return !sch.getBcType().equals("in") && !sch.getBcType().equals("out");
113   - }
114   -
115   - /**
116   - * 进班次终点
117   - *
118   - * @param gps
119   - */
120   - private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) {
121   - String nbbm = sch.getClZbh();
122   - //校验进站前置约束
123   - if (!validInPremise(gps))
124   - return;
125   -
126   - //实达时间不覆盖
127   - if (StringUtils.isNotEmpty(sch.getZdsjActual()))
128   - return;
129   -
130   - //应用到离站缓冲区设置参数
131   - long rsT = lineConfigData.applyIn(sch, gps.getTimestamp());
132   -
133   - sch.setZdsjActualAll(rsT);
134   - sch.setSiginCompate(2);
135   - //通知误点停靠程序,有车辆到站
136   - LateAdjustHandle.carArrive(gps);
137   -
138   - //持久化
139   - dayOfSchedule.save(sch);
140   -
141   - //车辆的下一个班次
142   - ScheduleRealInfo next = dayOfSchedule.next(sch);
143   - if (next != null) {
144   - dayOfSchedule.addExecPlan(next);
145   - inStationAndInPark(sch, next);//进站既进场
146   - }
147   -
148   - //路牌的下一个班次,页面显示起点实际到达时间
149   - ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
150   - if (lpNext != null) {
151   - lpNext.setQdzArrDatesj(sch.getZdsjActual());
152   - }
153   -
154   - //已完成班次数
155   - int doneSum = dayOfSchedule.doneSum(nbbm);
156   - //webSocket
157   - sendUtils.sendZdsj(sch, lpNext, doneSum);
158   -
159   - logger.info("车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual());
160   -
161   - //清除车辆误点调整监听
162   - LateAdjustHandle.remove(nbbm);
163   -
164   - //将gps转换成下一个班次走向的站内信号(应对只有一个站内信号 即 发出时)
165   - transformUpDown(gps, next);
166   -
167   - //下发调度指令
168   - DirectivePushQueue.put6002(next, doneSum, "到站@系统");
169   -
170   - //套跑 -下发线路切换指令
171   - if (null != next && !next.getXlBm().equals(sch.getXlBm())) {
172   - gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统");
173   - }
174   -
175   -
176   - if (null == next && gps.isService())
177   - nonService(sch, "结束@系统");//班次结束
178   - else if (null != next && dayOfSchedule.emptyService(next))
179   - nonService(sch, "空驶@系统");//下一班非营运
180   - }
181   -
182   - /**
183   - * 校验进站前置约束
184   - *
185   - * @param gps
186   - * @return
187   - */
188   - private boolean validInPremise(GpsEntity gps) {
189   - StationRoute sr = gps.getStation();
190   - if (null == sr || !sr.isPremise())
191   - return true;
192   -
193   - String premiseCode = gps.getPremiseCode();
194   -
195   - if (StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())) {
196   - logger.info("满足前置进站约束 " + premiseCode);
197   - return true;
198   - } else {
199   - logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode);
200   - }
201   - return false;
202   - }
203   -
204   - /**
205   - * 进站既进场
206   - *
207   - * @param sch
208   - */
209   - private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next) {
210   - LineConfig config = lineConfigData.get(sch.getXlBm());
211   - //限定出站既出场的停车场
212   - String park = config.getTwinsPark();
213   - boolean limitPark = StringUtils.isNotEmpty(park);
214   -
215   -
216   - if (next.getBcType().equals("in") && config.getOutConfig() == 2 && isEmptyMileage(next)
217   - && (!limitPark || park.equals(next.getZdzCode()))) {
218   -
219   - endSch(next, sch.getZdsjActualTime());
220   -
221   - sendUtils.refreshSch(next);
222   - dayOfSchedule.save(next);
223   -
224   - //分班的时候,需要再跳过1个班次
225   - next = dayOfSchedule.next(next);
226   - if (next != null)
227   - dayOfSchedule.addExecPlan(next);
228   -
229   - //进场,切换成非营运状态
230   - nonService(sch, "进场@系统");
231   - }
232   - }
233   -
234   -
235   - private boolean isEmptyMileage(ScheduleRealInfo sch) {
236   - return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0;
237   - }
238   -
239   -
240   - /**
241   - * 切换为非营运状态
242   - *
243   - * @param sch
244   - * @param sender
245   - */
246   - private void nonService(ScheduleRealInfo sch, String sender) {
247   - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);
248   - }
249   -
250   - private void endSch(ScheduleRealInfo sch, Long t) {
251   - sch.setFcsjActualAll(t);
252   - sch.setZdsjActualAll(t);
253   - }
254   -
255   - private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) {
256   - if (null == sch)
257   - return;
258   - byte upDown = Byte.parseByte(sch.getXlDir());
259   - //gps 切换走向
260   - gps.setUpDown(upDown);
261   - gps.setPremiseCode(null);
262   -
263   - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown);
264   - StationRoute station = GeoUtils.gpsInStation(gps, srs);
265   - if (station != null) {
266   - gps.setStopNo(station.getCode());
267   - }
268   - }
269   -
270   - private boolean isInPark(GpsEntity gps, GpsEntity prve){
271   - if(StringUtils.isNotEmpty(gps.getCarparkNo()) && StringUtils.isEmpty(prve.getCarparkNo()))
272   - return true;
273   - return false;
274   - }
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  5 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  6 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  7 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  8 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  9 +import com.bsth.data.gpsdata_v2.utils.GeoUtils;
  10 +import com.bsth.data.msg_queue.DirectivePushQueue;
  11 +import com.bsth.data.schedule.DayOfSchedule;
  12 +import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
  13 +import com.bsth.entity.realcontrol.LineConfig;
  14 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  15 +import com.bsth.websocket.handler.SendUtils;
  16 +import org.apache.commons.lang3.StringUtils;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.stereotype.Component;
  21 +
  22 +import java.util.List;
  23 +
  24 +/**
  25 + * 车辆到站处理程序
  26 + * Created by panzhao on 2017/11/16.
  27 + */
  28 +@Component
  29 +public class InStationProcess {
  30 +
  31 + @Autowired
  32 + DayOfSchedule dayOfSchedule;
  33 +
  34 + @Autowired
  35 + LineConfigData lineConfigData;
  36 +
  37 + @Autowired
  38 + SendUtils sendUtils;
  39 +
  40 + @Autowired
  41 + GpsStatusManager gpsStatusManager;
  42 +
  43 + Logger logger = LoggerFactory.getLogger(this.getClass());
  44 +
  45 + public void process(GpsEntity gps) {
  46 + //自动执行的班次信号,滚蛋
  47 + LineConfig config = lineConfigData.get(gps.getLineId());
  48 + if(null != config && config.isAutoExec())
  49 + return;
  50 +
  51 + GpsEntity prev = GpsCacheData.getPrev(gps);
  52 +
  53 + if(null == prev)
  54 + return;
  55 +
  56 + //从站外到站内
  57 + if(prev.getInstation() == 0 && gps.getInstation() > 0){
  58 + inStation(gps, prev);
  59 + }
  60 +
  61 + //从站内到另一个站内
  62 + if(prev.getInstation() == 1 && gps.getInstation() == 1
  63 + && !prev.getStopNo().equals(gps.getStopNo())
  64 + && !prev.getStation().getName().equals(gps.getStation().getName()))
  65 + inStation(gps, prev);
  66 +
  67 + //从场内到站内
  68 + if(prev.getInstation() == 2 && gps.getInstation() == 1){
  69 + inStation(gps, prev);
  70 + }
  71 +
  72 + //被起点站覆盖的情况下进场
  73 + if(isInPark(gps, prev))
  74 + inStation(gps, prev);
  75 + }
  76 +
  77 + /**
  78 + * 进站
  79 + *
  80 + * @param gps
  81 + * @param prev
  82 + */
  83 + private void inStation(GpsEntity gps, GpsEntity prev) {
  84 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  85 + boolean flow = true;
  86 + //要经过2个中途站才能进
  87 + int count = GpsCacheData.lastInTrailsSize(gps);
  88 + List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown());
  89 + if (null != sch && isNormalSch(sch) && gps.getInstation() == 1 && routes.size() > 4
  90 + && count < 2) {
  91 + logger.info("没有进中途站,拒绝进站... -" + gps.getNbbm() + " -time:" + gps.getTimestamp());
  92 + flow = false;
  93 + }
  94 +
  95 + boolean isEnd = false;
  96 +
  97 + //进终点
  98 + if (flow && null != sch &&
  99 + ((sch.getZdzCode().equals(gps.getStopNo()) && gps.getInstation()>0) || sch.getZdzCode().equals(gps.getCarparkNo()))) {
  100 + inEndStation(sch, gps);
  101 + isEnd = true;
  102 + }
  103 +
  104 + GpsCacheData.in(gps, isEnd);
  105 + }
  106 +
  107 + private boolean isNormalSch(ScheduleRealInfo sch) {
  108 + return sch.getBcType().equals("normal");
  109 + }
  110 +
  111 + private boolean isNotInOut(ScheduleRealInfo sch) {
  112 + return !sch.getBcType().equals("in") && !sch.getBcType().equals("out");
  113 + }
  114 +
  115 + /**
  116 + * 进班次终点
  117 + *
  118 + * @param gps
  119 + */
  120 + private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) {
  121 + String nbbm = sch.getClZbh();
  122 + //校验进站前置约束
  123 + if (!validInPremise(gps))
  124 + return;
  125 +
  126 + //实达时间不覆盖
  127 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
  128 + return;
  129 +
  130 + //应用到离站缓冲区设置参数
  131 + long rsT = lineConfigData.applyIn(sch, gps.getTimestamp());
  132 +
  133 + sch.setZdsjActualAll(rsT);
  134 + sch.setSiginCompate(2);
  135 + //通知误点停靠程序,有车辆到站
  136 + LateAdjustHandle.carArrive(gps);
  137 +
  138 + //持久化
  139 + dayOfSchedule.save(sch);
  140 +
  141 + //车辆的下一个班次
  142 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  143 + if (next != null) {
  144 + dayOfSchedule.addExecPlan(next);
  145 + inStationAndInPark(sch, next);//进站既进场
  146 + }
  147 +
  148 + //路牌的下一个班次,页面显示起点实际到达时间
  149 + ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
  150 + if (lpNext != null) {
  151 + lpNext.setQdzArrDatesj(sch.getZdsjActual());
  152 + }
  153 +
  154 + //已完成班次数
  155 + int doneSum = dayOfSchedule.doneSum(nbbm);
  156 + //webSocket
  157 + sendUtils.sendZdsj(sch, lpNext, doneSum);
  158 +
  159 + logger.info("车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual());
  160 +
  161 + //清除车辆误点调整监听
  162 + LateAdjustHandle.remove(nbbm);
  163 +
  164 + //将gps转换成下一个班次走向的站内信号(应对只有一个站内信号 即 发出时)
  165 + transformUpDown(gps, next);
  166 +
  167 + //下发调度指令
  168 + DirectivePushQueue.put6002(next, doneSum, "到站@系统");
  169 +
  170 + //套跑 -下发线路切换指令
  171 + if (null != next && !next.getXlBm().equals(sch.getXlBm())) {
  172 + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统");
  173 + }
  174 +
  175 +
  176 + if (null == next && gps.isService())
  177 + nonService(sch, "结束@系统");//班次结束
  178 + else if (null != next && dayOfSchedule.emptyService(next))
  179 + nonService(sch, "空驶@系统");//下一班非营运
  180 + }
  181 +
  182 + /**
  183 + * 校验进站前置约束
  184 + *
  185 + * @param gps
  186 + * @return
  187 + */
  188 + private boolean validInPremise(GpsEntity gps) {
  189 + StationRoute sr = gps.getStation();
  190 + if (null == sr || !sr.isPremise())
  191 + return true;
  192 +
  193 + String premiseCode = gps.getPremiseCode();
  194 +
  195 + if (StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())) {
  196 + logger.info("满足前置进站约束 " + premiseCode);
  197 + return true;
  198 + } else {
  199 + logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode);
  200 + }
  201 + return false;
  202 + }
  203 +
  204 + /**
  205 + * 进站既进场
  206 + *
  207 + * @param sch
  208 + */
  209 + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next) {
  210 + LineConfig config = lineConfigData.get(sch.getXlBm());
  211 + //限定出站既出场的停车场
  212 + String park = config.getTwinsPark();
  213 + boolean limitPark = StringUtils.isNotEmpty(park);
  214 +
  215 +
  216 + if (next.getBcType().equals("in") && config.getOutConfig() == 2 && isEmptyMileage(next)
  217 + && (!limitPark || park.equals(next.getZdzCode()))) {
  218 +
  219 + endSch(next, sch.getZdsjActualTime());
  220 +
  221 + sendUtils.refreshSch(next);
  222 + dayOfSchedule.save(next);
  223 +
  224 + //分班的时候,需要再跳过1个班次
  225 + next = dayOfSchedule.next(next);
  226 + if (next != null)
  227 + dayOfSchedule.addExecPlan(next);
  228 +
  229 + //进场,切换成非营运状态
  230 + nonService(sch, "进场@系统");
  231 + }
  232 + }
  233 +
  234 +
  235 + private boolean isEmptyMileage(ScheduleRealInfo sch) {
  236 + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0;
  237 + }
  238 +
  239 +
  240 + /**
  241 + * 切换为非营运状态
  242 + *
  243 + * @param sch
  244 + * @param sender
  245 + */
  246 + private void nonService(ScheduleRealInfo sch, String sender) {
  247 + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);
  248 + }
  249 +
  250 + private void endSch(ScheduleRealInfo sch, Long t) {
  251 + sch.setFcsjActualAll(t);
  252 + sch.setZdsjActualAll(t);
  253 + }
  254 +
  255 + private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) {
  256 + if (null == sch)
  257 + return;
  258 + byte upDown = Byte.parseByte(sch.getXlDir());
  259 + //gps 切换走向
  260 + gps.setUpDown(upDown);
  261 + gps.setPremiseCode(null);
  262 +
  263 + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown);
  264 + StationRoute station = GeoUtils.gpsInStation(gps, srs);
  265 + if (station != null) {
  266 + gps.setStopNo(station.getCode());
  267 + }
  268 + }
  269 +
  270 + private boolean isInPark(GpsEntity gps, GpsEntity prve){
  271 + if(StringUtils.isNotEmpty(gps.getCarparkNo()) && StringUtils.isEmpty(prve.getCarparkNo()))
  272 + return true;
  273 + return false;
  274 + }
275 275 }
276 276 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata_v2/handlers/OutStationProcess.java
1   -package com.bsth.data.gpsdata_v2.handlers;
2   -
3   -import com.bsth.data.LineConfigData;
4   -import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
5   -import com.bsth.data.gpsdata_v2.entity.GpsEntity;
6   -import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
7   -import com.bsth.data.gpsdata_v2.utils.SignalSchPlanMatcher;
8   -import com.bsth.data.schedule.DayOfSchedule;
9   -import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
10   -import com.bsth.entity.realcontrol.LineConfig;
11   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
12   -import com.bsth.websocket.handler.SendUtils;
13   -import org.apache.commons.lang3.StringUtils;
14   -import org.slf4j.Logger;
15   -import org.slf4j.LoggerFactory;
16   -import org.springframework.beans.factory.annotation.Autowired;
17   -import org.springframework.stereotype.Component;
18   -
19   -/**
20   - * 车辆出站处理程序
21   - * Created by panzhao on 2017/11/16.
22   - */
23   -@Component
24   -public class OutStationProcess {
25   -
26   - @Autowired
27   - DayOfSchedule dayOfSchedule;
28   -
29   - Logger logger = LoggerFactory.getLogger(this.getClass());
30   -
31   - @Autowired
32   - LineConfigData lineConfigData;
33   -
34   - @Autowired
35   - SendUtils sendUtils;
36   -
37   - @Autowired
38   - SignalSchPlanMatcher signalSchPlanMatcher;
39   -
40   - @Autowired
41   - GpsStatusManager gpsStatusManager;
42   - private final static int MAX_BEFORE_TIME = 1000 * 60 * 120;
43   -
44   - public void process(GpsEntity gps) {
45   - //自动执行的班次信号,滚蛋
46   - LineConfig config = lineConfigData.get(gps.getLineId());
47   - if (null != config && config.isAutoExec())
48   - return;
49   -
50   - GpsEntity prev = GpsCacheData.getPrev(gps);
51   -
52   - if (null == prev)
53   - return;
54   -
55   - //从站内到站外
56   - if (prev.getInstation() > 0 && gps.getInstation() == 0)
57   - outStation(gps, prev);
58   -
59   - //从站内到另一个站内
60   - if (prev.getInstation() > 0 && gps.getInstation() > 0
61   - && !prev.getStopNo().equals(gps.getStopNo()))
62   - outStation(gps, prev);
63   -
64   - //在被起点站覆盖的情况下出场
65   - if (isOutPark(gps, prev))
66   - outStation(gps, prev);
67   - }
68   -
69   - /**
70   - * 出站
71   - *
72   - * @param gps
73   - */
74   - private void outStation(GpsEntity gps, GpsEntity prev) {
75   - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
76   -
77   - //起点发车
78   - if (null != sch &&
79   - ((sch.getQdzCode().equals(prev.getStopNo())
80   - && (gps.getInstation() == 0 || !gps.getStopNo().equals(prev.getStopNo())))
81   - || sch.getQdzCode().equals(prev.getCarparkNo()))) {
82   - //发车班次匹配
83   - if (!signalSchPlanMatcher.outMatch(gps, sch)) {
84   - outStation(gps, prev);
85   - return;
86   - }
87   -
88   - int diff = (int) (sch.getDfsjT() - gps.getTimestamp());
89   - //首班出场最多提前2小时
90   - if ((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2)
91   - return;
92   -
93   - gps.setPremiseCode(null);//清除前置围栏标记
94   -
95   - if (StringUtils.isNotEmpty(sch.getFcsjActual())
96   - && !outManyFit(gps, sch)) {
97   - return;//班次已经实发
98   - }
99   -
100   - //应用到离站缓冲区设置参数
101   - long rsT = lineConfigData.applyOut(sch, gps.getTimestamp());
102   - //实发时间
103   - sch.setFcsjActualAll(rsT);
104   - sch.setSiginCompate(1);
105   -
106   - //出站既出场
107   - outStationAndOutPark(sch);
108   -
109   - //webSocket
110   - sendUtils.sendFcsj(sch);
111   -
112   - //持久化
113   - dayOfSchedule.save(sch);
114   -
115   - //清理应发未发标记
116   - LateAdjustHandle.remove(sch.getClZbh());
117   -
118   - //发车的时候,同步一下状态
119   - if (!gps.isService() && !dayOfSchedule.emptyService(sch))
120   - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统");
121   -
122   - logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
123   - }
124   -
125   - GpsCacheData.out(gps);
126   - }
127   -
128   - /**
129   - * 是否是一个更合适的发车信号
130   - *
131   - * @param gps
132   - * @param sch
133   - * @return
134   - */
135   - private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) {
136   - LineConfig conf = lineConfigData.get(sch.getXlBm());
137   - if (null != conf && conf.isLockFirstOutTime())
138   - return false;
139   -
140   - if (StringUtils.isNotEmpty(sch.getZdsjActual()))
141   - return false;
142   -
143   - long t1 = sch.getFcsjActualTime();
144   - long t2 = gps.getTimestamp();
145   - long c = sch.getDfsjT();
146   -
147   - int threshold = 1000 * 60 * 5;
148   - if (Math.abs(t2 - c) < threshold && c - t1 > threshold) {
149   - return true;
150   - }
151   -
152   - if (c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1) {
153   - return true;
154   - }
155   - return false;
156   - }
157   -
158   - private void outStationAndOutPark(ScheduleRealInfo sch) {
159   - try {
160   - LineConfig config = lineConfigData.get(sch.getXlBm());
161   - //限定出站既出场的停车场
162   - String park = config.getTwinsPark();
163   - boolean limitPark = StringUtils.isNotEmpty(park);
164   -
165   - if (config != null && config.getOutConfig() == 2) {
166   - //出站既出场
167   - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
168   - if (isOut(schPrev) && isEmptyMileage(schPrev)
169   - && (!limitPark || park.equals(schPrev.getQdzCode()))) {
170   -
171   - endSch(schPrev, sch.getFcsjActualTime());
172   -
173   - //起点实到
174   - sch.setQdzArrDatesj(schPrev.getZdsjActual());
175   -
176   - sendUtils.refreshSch(schPrev);
177   - dayOfSchedule.save(schPrev);
178   - }
179   - }
180   - } catch (Exception e) {
181   - logger.error("", e);
182   - }
183   - }
184   -
185   - private boolean isEmptyMileage(ScheduleRealInfo sch) {
186   - return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0;
187   - }
188   -
189   - private boolean isOut(ScheduleRealInfo sch) {
190   - return sch != null && sch.getBcType().equals("out");
191   - }
192   -
193   - private void endSch(ScheduleRealInfo sch, Long t) {
194   - sch.setFcsjActualAll(t);
195   - sch.setZdsjActualAll(t);
196   - }
197   -
198   - private boolean isOutPark(GpsEntity gps, GpsEntity prve) {
199   - if (StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo()))
200   - return true;
201   - return false;
202   - }
  1 +package com.bsth.data.gpsdata_v2.handlers;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  7 +import com.bsth.data.gpsdata_v2.utils.SignalSchPlanMatcher;
  8 +import com.bsth.data.schedule.DayOfSchedule;
  9 +import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
  10 +import com.bsth.entity.realcontrol.LineConfig;
  11 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  12 +import com.bsth.websocket.handler.SendUtils;
  13 +import org.apache.commons.lang3.StringUtils;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.stereotype.Component;
  18 +
  19 +/**
  20 + * 车辆出站处理程序
  21 + * Created by panzhao on 2017/11/16.
  22 + */
  23 +@Component
  24 +public class OutStationProcess {
  25 +
  26 + @Autowired
  27 + DayOfSchedule dayOfSchedule;
  28 +
  29 + Logger logger = LoggerFactory.getLogger(this.getClass());
  30 +
  31 + @Autowired
  32 + LineConfigData lineConfigData;
  33 +
  34 + @Autowired
  35 + SendUtils sendUtils;
  36 +
  37 + @Autowired
  38 + SignalSchPlanMatcher signalSchPlanMatcher;
  39 +
  40 + @Autowired
  41 + GpsStatusManager gpsStatusManager;
  42 + private final static int MAX_BEFORE_TIME = 1000 * 60 * 120;
  43 +
  44 + public void process(GpsEntity gps) {
  45 + //自动执行的班次信号,滚蛋
  46 + LineConfig config = lineConfigData.get(gps.getLineId());
  47 + if (null != config && config.isAutoExec())
  48 + return;
  49 +
  50 + GpsEntity prev = GpsCacheData.getPrev(gps);
  51 +
  52 + if (null == prev)
  53 + return;
  54 +
  55 + //从站内到站外
  56 + if (prev.getInstation() > 0 && gps.getInstation() == 0)
  57 + outStation(gps, prev);
  58 +
  59 + //从站内到另一个站内
  60 + if (prev.getInstation() > 0 && gps.getInstation() > 0
  61 + && !prev.getStopNo().equals(gps.getStopNo()))
  62 + outStation(gps, prev);
  63 +
  64 + //在被起点站覆盖的情况下出场
  65 + if (isOutPark(gps, prev))
  66 + outStation(gps, prev);
  67 + }
  68 +
  69 + /**
  70 + * 出站
  71 + *
  72 + * @param gps
  73 + */
  74 + private void outStation(GpsEntity gps, GpsEntity prev) {
  75 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm());
  76 +
  77 + //起点发车
  78 + if (null != sch &&
  79 + ((sch.getQdzCode().equals(prev.getStopNo())
  80 + && (gps.getInstation() == 0 || !gps.getStopNo().equals(prev.getStopNo())))
  81 + || sch.getQdzCode().equals(prev.getCarparkNo()))) {
  82 + //发车班次匹配
  83 + if (!signalSchPlanMatcher.outMatch(gps, sch)) {
  84 + outStation(gps, prev);
  85 + return;
  86 + }
  87 +
  88 + int diff = (int) (sch.getDfsjT() - gps.getTimestamp());
  89 + //首班出场最多提前2小时
  90 + if ((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2)
  91 + return;
  92 +
  93 + gps.setPremiseCode(null);//清除前置围栏标记
  94 +
  95 + if (StringUtils.isNotEmpty(sch.getFcsjActual())
  96 + && !outManyFit(gps, sch)) {
  97 + return;//班次已经实发
  98 + }
  99 +
  100 + //应用到离站缓冲区设置参数
  101 + long rsT = lineConfigData.applyOut(sch, gps.getTimestamp());
  102 + //实发时间
  103 + sch.setFcsjActualAll(rsT);
  104 + sch.setSiginCompate(1);
  105 +
  106 + //出站既出场
  107 + outStationAndOutPark(sch);
  108 +
  109 + //webSocket
  110 + sendUtils.sendFcsj(sch);
  111 +
  112 + //持久化
  113 + dayOfSchedule.save(sch);
  114 +
  115 + //清理应发未发标记
  116 + LateAdjustHandle.remove(sch.getClZbh());
  117 +
  118 + //发车的时候,同步一下状态
  119 + if (!gps.isService() && !dayOfSchedule.emptyService(sch))
  120 + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统");
  121 +
  122 + logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
  123 + }
  124 +
  125 + GpsCacheData.out(gps);
  126 + }
  127 +
  128 + /**
  129 + * 是否是一个更合适的发车信号
  130 + *
  131 + * @param gps
  132 + * @param sch
  133 + * @return
  134 + */
  135 + private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) {
  136 + LineConfig conf = lineConfigData.get(sch.getXlBm());
  137 + if (null != conf && conf.isLockFirstOutTime())
  138 + return false;
  139 +
  140 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
  141 + return false;
  142 +
  143 + long t1 = sch.getFcsjActualTime();
  144 + long t2 = gps.getTimestamp();
  145 + long c = sch.getDfsjT();
  146 +
  147 + int threshold = 1000 * 60 * 5;
  148 + if (Math.abs(t2 - c) < threshold && c - t1 > threshold) {
  149 + return true;
  150 + }
  151 +
  152 + if (c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1) {
  153 + return true;
  154 + }
  155 + return false;
  156 + }
  157 +
  158 + private void outStationAndOutPark(ScheduleRealInfo sch) {
  159 + try {
  160 + LineConfig config = lineConfigData.get(sch.getXlBm());
  161 + //限定出站既出场的停车场
  162 + String park = config.getTwinsPark();
  163 + boolean limitPark = StringUtils.isNotEmpty(park);
  164 +
  165 + if (config != null && config.getOutConfig() == 2) {
  166 + //出站既出场
  167 + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch);
  168 + if (isOut(schPrev) && isEmptyMileage(schPrev)
  169 + && (!limitPark || park.equals(schPrev.getQdzCode()))) {
  170 +
  171 + endSch(schPrev, sch.getFcsjActualTime());
  172 +
  173 + //起点实到
  174 + sch.setQdzArrDatesj(schPrev.getZdsjActual());
  175 +
  176 + sendUtils.refreshSch(schPrev);
  177 + dayOfSchedule.save(schPrev);
  178 + }
  179 + }
  180 + } catch (Exception e) {
  181 + logger.error("", e);
  182 + }
  183 + }
  184 +
  185 + private boolean isEmptyMileage(ScheduleRealInfo sch) {
  186 + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0;
  187 + }
  188 +
  189 + private boolean isOut(ScheduleRealInfo sch) {
  190 + return sch != null && sch.getBcType().equals("out");
  191 + }
  192 +
  193 + private void endSch(ScheduleRealInfo sch, Long t) {
  194 + sch.setFcsjActualAll(t);
  195 + sch.setZdsjActualAll(t);
  196 + }
  197 +
  198 + private boolean isOutPark(GpsEntity gps, GpsEntity prve) {
  199 + if (StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo()))
  200 + return true;
  201 + return false;
  202 + }
203 203 }
204 204 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata_v2/utils/GpsDataRecovery.java
1   -package com.bsth.data.gpsdata_v2.utils;
2   -
3   -import com.bsth.data.BasicData;
4   -import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
5   -import com.bsth.data.gpsdata_v2.entity.GpsEntity;
6   -import com.bsth.data.gpsdata_v2.handlers.*;
7   -import com.bsth.util.db.DBUtils_MS;
8   -import com.google.common.collect.ArrayListMultimap;
9   -import org.slf4j.Logger;
10   -import org.slf4j.LoggerFactory;
11   -import org.springframework.beans.BeansException;
12   -import org.springframework.context.ApplicationContext;
13   -import org.springframework.context.ApplicationContextAware;
14   -import org.springframework.jdbc.core.JdbcTemplate;
15   -import org.springframework.jdbc.core.RowMapper;
16   -import org.springframework.stereotype.Component;
17   -
18   -import java.sql.ResultSet;
19   -import java.sql.SQLException;
20   -import java.util.*;
21   -import java.util.concurrent.CountDownLatch;
22   -import java.util.concurrent.ExecutorService;
23   -import java.util.concurrent.Executors;
24   -
25   -/**
26   - * gps数据恢复
27   - * Created by panzhao on 2016/12/24.
28   - */
29   -@Component
30   -public class GpsDataRecovery implements ApplicationContextAware {
31   -
32   - static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class);
33   -
34   - public static boolean run;
35   -
36   - static ExecutorService threadPool = Executors.newFixedThreadPool(10);
37   -
38   - static GpsStateProcess gpsStateProcess;
39   - static StationInsideProcess stationInsideProcess;
40   - static InStationProcess inStationProcess;
41   - static OutStationProcess outStationProcess;
42   - static AbnormalStateProcess abnormalStateProcess;
43   - static ReverseRouteProcess reverseRouteProcess;
44   -
45   - public void recovery() {
46   - List<GpsEntity> list = loadData();
47   -
48   - //按线路分组数据
49   - ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create();
50   - for (GpsEntity gps : list) {
51   - if (gps.getNbbm() != null)
52   - listMap.put(gps.getNbbm(), gps);
53   - }
54   -
55   -
56   - Set<String> keys = listMap.keySet();
57   -
58   - CountDownLatch count = new CountDownLatch(keys.size());
59   - GpsComp comp = new GpsComp();
60   - for (String nbbm : keys) {
61   - Collections.sort(listMap.get(nbbm), comp);
62   - threadPool.submit(new RecoveryThread(listMap.get(nbbm), count));
63   - /*if(nbbm.equals("W1E-169"))
64   - new RecoveryThread(listMap.get(nbbm), count).run();*/
65   - /*if(lineId.equals("60028"))
66   - new RecoveryThread(listMap.get(lineId), count).run();*/
67   - }
68   -
69   - try {
70   - count.await();
71   - run = false;
72   - logger.info("数据恢复完成....");
73   - } catch (InterruptedException e) {
74   - logger.error("", e);
75   - }
76   - }
77   -
78   - /**
79   - * 加载当天的gps数据
80   - *
81   - * @return
82   - */
83   - public List<GpsEntity> loadData() {
84   - Calendar calendar = Calendar.getInstance();
85   - int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
86   -
87   - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE,SERVER_TS from bsth_c_gps_info where days_year=329"; //+ dayOfYear;
88   - JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
89   -
90   - List<GpsEntity> list =
91   - jdbcTemplate.query(sql, new RowMapper<GpsEntity>() {
92   - @Override
93   - public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
94   - GpsEntity gps = new GpsEntity();
95   -
96   - gps.setDeviceId(rs.getString("DEVICE_ID"));
97   - gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
98   - gps.setSpeed(rs.getFloat("SPEED_GPS"));
99   - gps.setLat(rs.getFloat("LAT"));
100   - gps.setLon(rs.getFloat("LON"));
101   - gps.setLineId(rs.getString("LINE_ID"));
102   - gps.setTimestamp(rs.getLong("TS"));
103   - gps.setUpDown((byte) getUpOrDown(rs.getLong("SERVICE_STATE")));
104   - gps.setServerTimestamp(rs.getLong("SERVER_TS"));
105   - return gps;
106   - }
107   - });
108   - return list;
109   - }
110   -
111   - /**
112   - * 王通 2016/6/29 9:23:24 获取车辆线路上下行
113   - *
114   - * @return -1无效 0上行 1下行
115   - */
116   - public static int getUpOrDown(long serviceState) {
117   - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
118   - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
119   - return -1;
120   - return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
121   - }
122   -
123   - @Override
124   - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
125   - gpsStateProcess = applicationContext.getBean(GpsStateProcess.class);
126   - stationInsideProcess = applicationContext.getBean(StationInsideProcess.class);
127   - inStationProcess = applicationContext.getBean(InStationProcess.class);
128   - outStationProcess = applicationContext.getBean(OutStationProcess.class);
129   - abnormalStateProcess = applicationContext.getBean(AbnormalStateProcess.class);
130   - reverseRouteProcess = applicationContext.getBean(ReverseRouteProcess.class);
131   - }
132   -
133   - public static class GpsComp implements Comparator<GpsEntity> {
134   -
135   - @Override
136   - public int compare(GpsEntity g1, GpsEntity g2) {
137   - return g1.getTimestamp().compareTo(g2.getTimestamp());
138   - }
139   - }
140   -
141   - public static class RecoveryThread implements Runnable {
142   - List<GpsEntity> list;
143   - CountDownLatch count;
144   -
145   - RecoveryThread(List<GpsEntity> list, CountDownLatch count) {
146   - this.list = list;
147   - this.count = count;
148   - }
149   -
150   - @Override
151   - public void run() {
152   - try {
153   - //循环gps恢复数据
154   - for (GpsEntity gps : list) {
155   - try {
156   -
157   - /*if(gps.getTimestamp() >= 1511569544000L)
158   - System.out.println("aaa");*/
159   -
160   - if(Math.abs(gps.getTimestamp() - gps.getServerTimestamp()) > 1000 * 60 * 20)
161   - continue;
162   -
163   - gpsStateProcess.process(gps);//状态处理
164   - stationInsideProcess.process(gps);//场站内外判定
165   - reverseRouteProcess.process(gps);//反向路由处理
166   -
167   - abnormalStateProcess.process(gps);//超速越界
168   -
169   - inStationProcess.process(gps);//进站
170   - outStationProcess.process(gps);//出站
171   -
172   - GpsCacheData.putGps(gps);//历史gps缓存
173   - } catch (Exception e) {
174   - logger.error("", e);
175   - }
176   - }
177   - } finally {
178   - count.countDown();
179   - }
180   - }
181   - }
  1 +package com.bsth.data.gpsdata_v2.utils;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.gpsdata_v2.handlers.*;
  7 +import com.bsth.util.db.DBUtils_MS;
  8 +import com.google.common.collect.ArrayListMultimap;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.BeansException;
  12 +import org.springframework.context.ApplicationContext;
  13 +import org.springframework.context.ApplicationContextAware;
  14 +import org.springframework.jdbc.core.JdbcTemplate;
  15 +import org.springframework.jdbc.core.RowMapper;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import java.sql.ResultSet;
  19 +import java.sql.SQLException;
  20 +import java.util.*;
  21 +import java.util.concurrent.CountDownLatch;
  22 +import java.util.concurrent.ExecutorService;
  23 +import java.util.concurrent.Executors;
  24 +
  25 +/**
  26 + * gps数据恢复
  27 + * Created by panzhao on 2016/12/24.
  28 + */
  29 +@Component
  30 +public class GpsDataRecovery implements ApplicationContextAware {
  31 +
  32 + static Logger logger = LoggerFactory.getLogger(GpsDataRecovery.class);
  33 +
  34 + public static boolean run;
  35 +
  36 + static ExecutorService threadPool = Executors.newFixedThreadPool(10);
  37 +
  38 + static GpsStateProcess gpsStateProcess;
  39 + static StationInsideProcess stationInsideProcess;
  40 + static InStationProcess inStationProcess;
  41 + static OutStationProcess outStationProcess;
  42 + static AbnormalStateProcess abnormalStateProcess;
  43 + static ReverseRouteProcess reverseRouteProcess;
  44 +
  45 + public void recovery() {
  46 + List<GpsEntity> list = loadData();
  47 +
  48 + //按线路分组数据
  49 + ArrayListMultimap<String, GpsEntity> listMap = ArrayListMultimap.create();
  50 + for (GpsEntity gps : list) {
  51 + if (gps.getNbbm() != null)
  52 + listMap.put(gps.getNbbm(), gps);
  53 + }
  54 +
  55 +
  56 + Set<String> keys = listMap.keySet();
  57 +
  58 + CountDownLatch count = new CountDownLatch(keys.size());
  59 + GpsComp comp = new GpsComp();
  60 + for (String nbbm : keys) {
  61 + Collections.sort(listMap.get(nbbm), comp);
  62 + threadPool.submit(new RecoveryThread(listMap.get(nbbm), count));
  63 + /*if(nbbm.equals("W1E-169"))
  64 + new RecoveryThread(listMap.get(nbbm), count).run();*/
  65 + /*if(lineId.equals("60028"))
  66 + new RecoveryThread(listMap.get(lineId), count).run();*/
  67 + }
  68 +
  69 + try {
  70 + count.await();
  71 + run = false;
  72 + logger.info("数据恢复完成....");
  73 + } catch (InterruptedException e) {
  74 + logger.error("", e);
  75 + }
  76 + }
  77 +
  78 + /**
  79 + * 加载当天的gps数据
  80 + *
  81 + * @return
  82 + */
  83 + public List<GpsEntity> loadData() {
  84 + Calendar calendar = Calendar.getInstance();
  85 + int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
  86 +
  87 + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE,SERVER_TS from bsth_c_gps_info where days_year=329"; //+ dayOfYear;
  88 + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  89 +
  90 + List<GpsEntity> list =
  91 + jdbcTemplate.query(sql, new RowMapper<GpsEntity>() {
  92 + @Override
  93 + public GpsEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
  94 + GpsEntity gps = new GpsEntity();
  95 +
  96 + gps.setDeviceId(rs.getString("DEVICE_ID"));
  97 + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps.getDeviceId()));
  98 + gps.setSpeed(rs.getFloat("SPEED_GPS"));
  99 + gps.setLat(rs.getFloat("LAT"));
  100 + gps.setLon(rs.getFloat("LON"));
  101 + gps.setLineId(rs.getString("LINE_ID"));
  102 + gps.setTimestamp(rs.getLong("TS"));
  103 + gps.setUpDown((byte) getUpOrDown(rs.getLong("SERVICE_STATE")));
  104 + gps.setServerTimestamp(rs.getLong("SERVER_TS"));
  105 + return gps;
  106 + }
  107 + });
  108 + return list;
  109 + }
  110 +
  111 + /**
  112 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  113 + *
  114 + * @return -1无效 0上行 1下行
  115 + */
  116 + public static int getUpOrDown(long serviceState) {
  117 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  118 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  119 + return -1;
  120 + return (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  121 + }
  122 +
  123 + @Override
  124 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  125 + gpsStateProcess = applicationContext.getBean(GpsStateProcess.class);
  126 + stationInsideProcess = applicationContext.getBean(StationInsideProcess.class);
  127 + inStationProcess = applicationContext.getBean(InStationProcess.class);
  128 + outStationProcess = applicationContext.getBean(OutStationProcess.class);
  129 + abnormalStateProcess = applicationContext.getBean(AbnormalStateProcess.class);
  130 + reverseRouteProcess = applicationContext.getBean(ReverseRouteProcess.class);
  131 + }
  132 +
  133 + public static class GpsComp implements Comparator<GpsEntity> {
  134 +
  135 + @Override
  136 + public int compare(GpsEntity g1, GpsEntity g2) {
  137 + return g1.getTimestamp().compareTo(g2.getTimestamp());
  138 + }
  139 + }
  140 +
  141 + public static class RecoveryThread implements Runnable {
  142 + List<GpsEntity> list;
  143 + CountDownLatch count;
  144 +
  145 + RecoveryThread(List<GpsEntity> list, CountDownLatch count) {
  146 + this.list = list;
  147 + this.count = count;
  148 + }
  149 +
  150 + @Override
  151 + public void run() {
  152 + try {
  153 + //循环gps恢复数据
  154 + for (GpsEntity gps : list) {
  155 + try {
  156 +
  157 + /*if(gps.getTimestamp() >= 1511569544000L)
  158 + System.out.println("aaa");*/
  159 +
  160 + if(Math.abs(gps.getTimestamp() - gps.getServerTimestamp()) > 1000 * 60 * 20)
  161 + continue;
  162 +
  163 + gpsStateProcess.process(gps);//状态处理
  164 + stationInsideProcess.process(gps);//场站内外判定
  165 + reverseRouteProcess.process(gps);//反向路由处理
  166 +
  167 + abnormalStateProcess.process(gps);//超速越界
  168 +
  169 + inStationProcess.process(gps);//进站
  170 + outStationProcess.process(gps);//出站
  171 +
  172 + GpsCacheData.putGps(gps);//历史gps缓存
  173 + } catch (Exception e) {
  174 + logger.error("", e);
  175 + }
  176 + }
  177 + } finally {
  178 + count.countDown();
  179 + }
  180 + }
  181 + }
182 182 }
183 183 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata_v2/utils/SignalSchPlanMatcher.java
1   -package com.bsth.data.gpsdata_v2.utils;
2   -
3   -import com.bsth.data.gpsdata_v2.entity.GpsEntity;
4   -import com.bsth.data.schedule.DayOfSchedule;
5   -import com.bsth.data.schedule.ScheduleComparator;
6   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
7   -import org.apache.commons.lang3.StringUtils;
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 java.util.Collections;
14   -import java.util.List;
15   -
16   -/**
17   - * 班次匹配器
18   - * Created by panzhao on 2016/12/31.
19   - */
20   -@Component
21   -public class SignalSchPlanMatcher {
22   -
23   - @Autowired
24   - DayOfSchedule dayOfSchedule;
25   -
26   - static ScheduleComparator.DFSJ schComp = new ScheduleComparator.DFSJ();
27   -
28   - Logger log = LoggerFactory.getLogger(this.getClass());
29   -
30   - /**
31   - * 发车信号匹配
32   - * @param gps
33   - * @param sch
34   - * @return
35   - */
36   - public boolean outMatch(GpsEntity gps, ScheduleRealInfo sch){
37   - long t = gps.getTimestamp();
38   - if(t < sch.getDfsjT())
39   - return true;
40   -
41   - try{
42   - //晚于待发时间 10 分钟 ,匹配一下最佳的班次
43   - if(t - sch.getDfsjT() > 1000 * 60 * 10){
44   - ScheduleRealInfo near = searchNearSch(gps, sch.getQdzCode());
45   -
46   - if(null != near && !near.getId().equals(sch.getId())){
47   -
48   - if(Math.abs(t - near.getDfsjT()) < Math.abs((t - sch.getDfsjT()))){
49   -
50   - dayOfSchedule.addExecPlan(near);
51   - return false;
52   - }
53   - }
54   - }
55   -
56   - }catch (Exception e){
57   - log.error("", e);
58   - }
59   - return true;
60   - /*try{
61   - //会不会是分班没有完成
62   - if(sch.getBcType().equals("in") && t - sch.getDfsjT() > 1000 * 60 * 20){
63   - ScheduleRealInfo fbFirst = dayOfSchedule.nextByBcType(sch, "normal");
64   -
65   - if(fbFirst == null || !fbFirst.getQdzCode().equals(gps.getStopNo()))
66   - return;
67   -
68   - long dt = fbFirst.getDfsjT();
69   - //晚于待发前4分钟 -执行分班的首个营运
70   - if(dt - t < 1000 * 60 * 4){
71   - dayOfSchedule.addExecPlan(fbFirst);
72   - return;
73   - }
74   - }
75   -
76   - //线路编码不匹配
77   - if("out".equals(sch.getBcType()) && !sch.getXlBm().equals(gps.getLineId())){
78   - ScheduleRealInfo nextOut = dayOfSchedule.nextByBcType(sch, "out");
79   - if(nextOut != null && nextOut.getXlBm().equals(gps.getLineId())
80   - && fcSpace(sch, gps) > fcSpace(nextOut, gps)){
81   - dayOfSchedule.addExecPlan(nextOut);
82   - return;
83   - }
84   - }
85   - }catch (Exception e){
86   - log.error("", e);
87   - }
88   -
89   - //下一个相同走向的班次
90   - ScheduleRealInfo next = dayOfSchedule.nextSame(sch);
91   - if(next == null || !next.getQdzCode().equals(sch.getQdzCode()))
92   - return;
93   -
94   - //晚于班次间隔百分之70,跳下一个班次
95   - double s = (int) (next.getDfsjT() - sch.getDfsjT());
96   - double r = (int) (t - sch.getDfsjT());
97   - if(r / s > 0.7){
98   - if(dayOfSchedule.addExecPlan(next))
99   - outMatch(gps, next);
100   - }*/
101   - }
102   -
103   - /**
104   - * 搜索一个离发车信号最近的班次
105   - * @param gps
106   - * @return
107   - */
108   - private ScheduleRealInfo searchNearSch(GpsEntity gps, String qdzCode) {
109   - List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(gps.getNbbm());
110   - //排序
111   - Collections.sort(list, schComp);
112   -
113   - ScheduleRealInfo near = null;
114   - int diff, minDiff=-1;
115   - for(ScheduleRealInfo sch : list){
116   - if(!sch.getQdzCode().equals(qdzCode))
117   - continue;
118   -
119   - if(StringUtils.isNotEmpty(sch.getFcsjActual()))
120   - continue;
121   -
122   - if(StringUtils.isNotEmpty(sch.getZdsjActual()))
123   - continue;
124   -
125   - diff = (int) Math.abs(gps.getTimestamp() - sch.getDfsjT());
126   - if(null == near || diff < minDiff){
127   - near = sch;
128   - minDiff = diff;
129   - }
130   - }
131   - return near;
132   - }
133   -}
  1 +package com.bsth.data.gpsdata_v2.utils;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.data.schedule.ScheduleComparator;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import org.apache.commons.lang3.StringUtils;
  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 java.util.Collections;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * 班次匹配器
  18 + * Created by panzhao on 2016/12/31.
  19 + */
  20 +@Component
  21 +public class SignalSchPlanMatcher {
  22 +
  23 + @Autowired
  24 + DayOfSchedule dayOfSchedule;
  25 +
  26 + static ScheduleComparator.DFSJ schComp = new ScheduleComparator.DFSJ();
  27 +
  28 + Logger log = LoggerFactory.getLogger(this.getClass());
  29 +
  30 + /**
  31 + * 发车信号匹配
  32 + * @param gps
  33 + * @param sch
  34 + * @return
  35 + */
  36 + public boolean outMatch(GpsEntity gps, ScheduleRealInfo sch){
  37 + long t = gps.getTimestamp();
  38 + if(t < sch.getDfsjT())
  39 + return true;
  40 +
  41 + try{
  42 + //晚于待发时间 10 分钟 ,匹配一下最佳的班次
  43 + if(t - sch.getDfsjT() > 1000 * 60 * 10){
  44 + ScheduleRealInfo near = searchNearSch(gps, sch.getQdzCode());
  45 +
  46 + if(null != near && !near.getId().equals(sch.getId())){
  47 +
  48 + if(Math.abs(t - near.getDfsjT()) < Math.abs((t - sch.getDfsjT()))){
  49 +
  50 + dayOfSchedule.addExecPlan(near);
  51 + return false;
  52 + }
  53 + }
  54 + }
  55 +
  56 + }catch (Exception e){
  57 + log.error("", e);
  58 + }
  59 + return true;
  60 + /*try{
  61 + //会不会是分班没有完成
  62 + if(sch.getBcType().equals("in") && t - sch.getDfsjT() > 1000 * 60 * 20){
  63 + ScheduleRealInfo fbFirst = dayOfSchedule.nextByBcType(sch, "normal");
  64 +
  65 + if(fbFirst == null || !fbFirst.getQdzCode().equals(gps.getStopNo()))
  66 + return;
  67 +
  68 + long dt = fbFirst.getDfsjT();
  69 + //晚于待发前4分钟 -执行分班的首个营运
  70 + if(dt - t < 1000 * 60 * 4){
  71 + dayOfSchedule.addExecPlan(fbFirst);
  72 + return;
  73 + }
  74 + }
  75 +
  76 + //线路编码不匹配
  77 + if("out".equals(sch.getBcType()) && !sch.getXlBm().equals(gps.getLineId())){
  78 + ScheduleRealInfo nextOut = dayOfSchedule.nextByBcType(sch, "out");
  79 + if(nextOut != null && nextOut.getXlBm().equals(gps.getLineId())
  80 + && fcSpace(sch, gps) > fcSpace(nextOut, gps)){
  81 + dayOfSchedule.addExecPlan(nextOut);
  82 + return;
  83 + }
  84 + }
  85 + }catch (Exception e){
  86 + log.error("", e);
  87 + }
  88 +
  89 + //下一个相同走向的班次
  90 + ScheduleRealInfo next = dayOfSchedule.nextSame(sch);
  91 + if(next == null || !next.getQdzCode().equals(sch.getQdzCode()))
  92 + return;
  93 +
  94 + //晚于班次间隔百分之70,跳下一个班次
  95 + double s = (int) (next.getDfsjT() - sch.getDfsjT());
  96 + double r = (int) (t - sch.getDfsjT());
  97 + if(r / s > 0.7){
  98 + if(dayOfSchedule.addExecPlan(next))
  99 + outMatch(gps, next);
  100 + }*/
  101 + }
  102 +
  103 + /**
  104 + * 搜索一个离发车信号最近的班次
  105 + * @param gps
  106 + * @return
  107 + */
  108 + private ScheduleRealInfo searchNearSch(GpsEntity gps, String qdzCode) {
  109 + List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(gps.getNbbm());
  110 + //排序
  111 + Collections.sort(list, schComp);
  112 +
  113 + ScheduleRealInfo near = null;
  114 + int diff, minDiff=-1;
  115 + for(ScheduleRealInfo sch : list){
  116 + if(!sch.getQdzCode().equals(qdzCode))
  117 + continue;
  118 +
  119 + if(StringUtils.isNotEmpty(sch.getFcsjActual()))
  120 + continue;
  121 +
  122 + if(StringUtils.isNotEmpty(sch.getZdsjActual()))
  123 + continue;
  124 +
  125 + diff = (int) Math.abs(gps.getTimestamp() - sch.getDfsjT());
  126 + if(null == near || diff < minDiff){
  127 + near = sch;
  128 + minDiff = diff;
  129 + }
  130 + }
  131 + return near;
  132 + }
  133 +}
... ...
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
... ... @@ -1153,7 +1153,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
1153 1153 Integer id =jsonObject.getInteger("id");
1154 1154 String nbbm =jsonObject.getString("nbbm");
1155 1155 String rq=jsonObject.getString("rq");
1156   - double yh = Arith.sub(Arith.add(czyl, jzl),sh);
  1156 + double yh = Arith.sub(Arith.add(czyl, jzl),jzyl);
1157 1157 if(yh<0){
1158 1158 yh=0.0;
1159 1159 }
... ...
src/main/java/com/bsth/service/oil/impl/YlxxbServiceImpl.java
... ... @@ -150,7 +150,7 @@ public class YlxxbServiceImpl extends BaseServiceImpl&lt;Ylxxb,Integer&gt; implements
150 150 ylxxbUpdate.setNbbm(ylxxb.getNbbm());
151 151 ylxxbUpdate.setYyrq(ylxxb.getYyrq());
152 152 ylxxbUpdate.setCreatetime(new Date());
153   - ylxxbUpdate.setTj(ylxxb.getNbbm()+"_"+ylxxb.getJsy()+"_"+ylxxb.getJzl());
  153 + ylxxbUpdate.setTj(ylxxb.getNbbm()+"_"+ylxxb.getJsy()+"_"+String.valueOf(ylxxb.getJzl()));
154 154 ylxxbUpdate.setZt(3);
155 155 updateRepository.save(ylxxbUpdate);
156 156 ylxxb.setJsy(jsy);
... ... @@ -250,7 +250,7 @@ public class YlxxbServiceImpl extends BaseServiceImpl&lt;Ylxxb,Integer&gt; implements
250 250 ylxxbUpdate.setNbbm(nbbm);
251 251 ylxxbUpdate.setYyrq(ylxxb.getYyrq());
252 252 ylxxbUpdate.setCreatetime(new Date());
253   - ylxxbUpdate.setTj(nbbm+"_"+ylxxb.getJsy()+"_"+ylxxb.getJzl());
  253 + ylxxbUpdate.setTj(nbbm+"_"+ylxxb.getJsy()+"_"+String.valueOf(ylxxb.getJzl()));
254 254 ylxxbUpdate.setZt(2);
255 255 updateRepository.save(ylxxbUpdate);
256 256 }
... ...