Commit 72a310c6f3429a8a0ce60b650c4412064237b8f5
1 parent
8cc146af
update...
Showing
6 changed files
with
129 additions
and
53 deletions
src/main/java/com/bsth/XDApplication.java
| @@ -86,11 +86,14 @@ public class XDApplication implements CommandLineRunner { | @@ -86,11 +86,14 @@ public class XDApplication implements CommandLineRunner { | ||
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | + //@Autowired | ||
| 90 | + //DayOfSchedule dayOfSchedule; | ||
| 89 | public void devInit(){ | 91 | public void devInit(){ |
| 90 | log.info("devInit..."); | 92 | log.info("devInit..."); |
| 91 | ScheduledExecutorService sexec = Application.mainServices; | 93 | ScheduledExecutorService sexec = Application.mainServices; |
| 92 | //抓取GPS数据 | 94 | //抓取GPS数据 |
| 93 | gpsDataLoader.setFlag(-1); | 95 | gpsDataLoader.setFlag(-1); |
| 96 | + //dayOfSchedule.dataRecovery(); | ||
| 94 | //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); | 97 | //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); |
| 95 | //实际排班更新线程 | 98 | //实际排班更新线程 |
| 96 | //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); | 99 | //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); |
src/main/java/com/bsth/data/gpsdata/arrival/GpsRealAnalyse.java
| @@ -117,29 +117,31 @@ public class GpsRealAnalyse { | @@ -117,29 +117,31 @@ public class GpsRealAnalyse { | ||
| 117 | try { | 117 | try { |
| 118 | Collections.sort(list, comp); | 118 | Collections.sort(list, comp); |
| 119 | for (GpsEntity gps : list) { | 119 | for (GpsEntity gps : list) { |
| 120 | - //是否有任务 | ||
| 121 | - boolean task; | ||
| 122 | - CircleQueue<GpsEntity> prevs = GeoCacheData.getGps(gps.getNbbm()); | ||
| 123 | - //掉线处理 | ||
| 124 | - offlineSignalHandle.handle(gps, prevs); | ||
| 125 | - //状态处理 | ||
| 126 | - task = correctSignalHandle.handle(gps, prevs); | ||
| 127 | - //场,站内外判断 | ||
| 128 | - stationInsideHandle.handle(gps, prevs); | ||
| 129 | - //异常判定(越界/超速) | ||
| 130 | - abnormalStateHandle.handle(gps, prevs); | ||
| 131 | - | ||
| 132 | - if (!task) | ||
| 133 | - continue; //无任务的,到这里就结束 | ||
| 134 | - | ||
| 135 | - //反向处理 | ||
| 136 | - reverseSignalHandle.handle(gps, prevs); | ||
| 137 | - //进出站动作处理 | ||
| 138 | - inOutStationSignalHandle.handle(gps, prevs); | ||
| 139 | - GeoCacheData.putGps(gps); | 120 | + try { |
| 121 | + //是否有任务 | ||
| 122 | + boolean task; | ||
| 123 | + CircleQueue<GpsEntity> prevs = GeoCacheData.getGps(gps.getNbbm()); | ||
| 124 | + //掉线处理 | ||
| 125 | + offlineSignalHandle.handle(gps, prevs); | ||
| 126 | + //状态处理 | ||
| 127 | + task = correctSignalHandle.handle(gps, prevs); | ||
| 128 | + //场,站内外判断 | ||
| 129 | + stationInsideHandle.handle(gps, prevs); | ||
| 130 | + //异常判定(越界/超速) | ||
| 131 | + abnormalStateHandle.handle(gps, prevs); | ||
| 132 | + | ||
| 133 | + if (!task) | ||
| 134 | + continue; //无任务的,到这里就结束 | ||
| 135 | + | ||
| 136 | + //反向处理 | ||
| 137 | + reverseSignalHandle.handle(gps, prevs); | ||
| 138 | + //进出站动作处理 | ||
| 139 | + inOutStationSignalHandle.handle(gps, prevs); | ||
| 140 | + GeoCacheData.putGps(gps); | ||
| 141 | + }catch (Exception e){ | ||
| 142 | + logger.error("", e); | ||
| 143 | + } | ||
| 140 | } | 144 | } |
| 141 | - } catch (Exception e) { | ||
| 142 | - logger.error("", e); | ||
| 143 | } finally { | 145 | } finally { |
| 144 | if (count != null) | 146 | if (count != null) |
| 145 | count.countDown(); | 147 | count.countDown(); |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/InOutStationSignalHandle.java
| @@ -46,7 +46,7 @@ public class InOutStationSignalHandle extends SignalHandle{ | @@ -46,7 +46,7 @@ public class InOutStationSignalHandle extends SignalHandle{ | ||
| 46 | @Autowired | 46 | @Autowired |
| 47 | SignalSchPlanMatcher signalSchPlanMatcher; | 47 | SignalSchPlanMatcher signalSchPlanMatcher; |
| 48 | 48 | ||
| 49 | - private final static int MAX_BEFORE_TIME = 1000 * 60 * 72; | 49 | + private final static int MAX_BEFORE_TIME = 1000 * 60 * 120; |
| 50 | 50 | ||
| 51 | //最大的班次时间差,防止异常的GPS时间打乱数据 | 51 | //最大的班次时间差,防止异常的GPS时间打乱数据 |
| 52 | private final static int MAX_NORMAL_DIFF = 1000 * 60 * 60 * 12; | 52 | private final static int MAX_NORMAL_DIFF = 1000 * 60 * 60 * 12; |
| @@ -113,8 +113,8 @@ public class InOutStationSignalHandle extends SignalHandle{ | @@ -113,8 +113,8 @@ public class InOutStationSignalHandle extends SignalHandle{ | ||
| 113 | 113 | ||
| 114 | int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); | 114 | int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); |
| 115 | 115 | ||
| 116 | - //首班出场最多提前1.2小时 | ||
| 117 | - if(dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) | 116 | + //首班出场最多提前2小时 |
| 117 | + if((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2) | ||
| 118 | return; | 118 | return; |
| 119 | 119 | ||
| 120 | //正常班次最大时间差 | 120 | //正常班次最大时间差 |
| @@ -129,9 +129,11 @@ public class InOutStationSignalHandle extends SignalHandle{ | @@ -129,9 +129,11 @@ public class InOutStationSignalHandle extends SignalHandle{ | ||
| 129 | signalSchPlanMatcher.outMatch(gps, sch); | 129 | signalSchPlanMatcher.outMatch(gps, sch); |
| 130 | sch = dayOfSchedule.executeCurr(gps.getNbbm()); | 130 | sch = dayOfSchedule.executeCurr(gps.getNbbm()); |
| 131 | 131 | ||
| 132 | - //实发时间不覆盖 | ||
| 133 | - if(StringUtils.isNotEmpty(sch.getFcsjActual())) | 132 | + //班次已经实发 |
| 133 | + if(StringUtils.isNotEmpty(sch.getFcsjActual()) | ||
| 134 | + && !outManyFit(gps, sch)){ | ||
| 134 | return; | 135 | return; |
| 136 | + } | ||
| 135 | 137 | ||
| 136 | //应用到离站缓冲区设置参数 | 138 | //应用到离站缓冲区设置参数 |
| 137 | long rsT = lineConfigData.applyOut(sch, gps.getTimestamp()); | 139 | long rsT = lineConfigData.applyOut(sch, gps.getTimestamp()); |
| @@ -185,6 +187,26 @@ public class InOutStationSignalHandle extends SignalHandle{ | @@ -185,6 +187,26 @@ public class InOutStationSignalHandle extends SignalHandle{ | ||
| 185 | } | 187 | } |
| 186 | } | 188 | } |
| 187 | 189 | ||
| 190 | + /** | ||
| 191 | + * 是否是一个更合适的发车信号 | ||
| 192 | + * @param gps | ||
| 193 | + * @param sch | ||
| 194 | + * @return | ||
| 195 | + */ | ||
| 196 | + private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) { | ||
| 197 | + if(StringUtils.isNotEmpty(sch.getZdsjActual())) | ||
| 198 | + return false; | ||
| 199 | + | ||
| 200 | + long t1 = sch.getFcsjActualTime(); | ||
| 201 | + long t2 = gps.getTimestamp(); | ||
| 202 | + long c = sch.getDfsjT(); | ||
| 203 | + | ||
| 204 | + if(c - t1 > 1000 * 60 * 15 && Math.abs(t2 - c) < 1000 * 60 * 5){ | ||
| 205 | + return true; | ||
| 206 | + } | ||
| 207 | + return false; | ||
| 208 | + } | ||
| 209 | + | ||
| 188 | 210 | ||
| 189 | private void outStationAndOutPark(ScheduleRealInfo sch){ | 211 | private void outStationAndOutPark(ScheduleRealInfo sch){ |
| 190 | LineConfig config = lineConfigData.get(sch.getXlBm()); | 212 | LineConfig config = lineConfigData.get(sch.getXlBm()); |
| @@ -230,7 +252,7 @@ public class InOutStationSignalHandle extends SignalHandle{ | @@ -230,7 +252,7 @@ public class InOutStationSignalHandle extends SignalHandle{ | ||
| 230 | logger.info("NullPointerException " + sch.getXlName() + " 有班次无班次历时,,,检查一下是否需要出站既出场。"); | 252 | logger.info("NullPointerException " + sch.getXlName() + " 有班次无班次历时,,,检查一下是否需要出站既出场。"); |
| 231 | } | 253 | } |
| 232 | //进场最多提前1.2小时 | 254 | //进场最多提前1.2小时 |
| 233 | - if(sch.getBcType().equals("in") && diff > MAX_BEFORE_TIME) | 255 | + if((sch.getBcType().equals("in") && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME/2) |
| 234 | return; | 256 | return; |
| 235 | 257 | ||
| 236 | //正常班次最大时间差 | 258 | //正常班次最大时间差 |
src/main/java/com/bsth/data/gpsdata/arrival/utils/SignalSchPlanMatcher.java
| @@ -3,6 +3,8 @@ package com.bsth.data.gpsdata.arrival.utils; | @@ -3,6 +3,8 @@ package com.bsth.data.gpsdata.arrival.utils; | ||
| 3 | import com.bsth.data.gpsdata.GpsEntity; | 3 | import com.bsth.data.gpsdata.GpsEntity; |
| 4 | import com.bsth.data.schedule.DayOfSchedule; | 4 | import com.bsth.data.schedule.DayOfSchedule; |
| 5 | import com.bsth.entity.realcontrol.ScheduleRealInfo; | 5 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 8 | 10 | ||
| @@ -16,6 +18,8 @@ public class SignalSchPlanMatcher { | @@ -16,6 +18,8 @@ public class SignalSchPlanMatcher { | ||
| 16 | @Autowired | 18 | @Autowired |
| 17 | DayOfSchedule dayOfSchedule; | 19 | DayOfSchedule dayOfSchedule; |
| 18 | 20 | ||
| 21 | + Logger log = LoggerFactory.getLogger(this.getClass()); | ||
| 22 | + | ||
| 19 | /** | 23 | /** |
| 20 | * 发车信号匹配 | 24 | * 发车信号匹配 |
| 21 | * @param outSigal | 25 | * @param outSigal |
| @@ -27,6 +31,25 @@ public class SignalSchPlanMatcher { | @@ -27,6 +31,25 @@ public class SignalSchPlanMatcher { | ||
| 27 | if(t < sch.getDfsjT()) | 31 | if(t < sch.getDfsjT()) |
| 28 | return; | 32 | return; |
| 29 | 33 | ||
| 34 | + try{ | ||
| 35 | + //会不会是分班没有完成 | ||
| 36 | + if(sch.getBcType().equals("in")){ | ||
| 37 | + ScheduleRealInfo fbFirst = dayOfSchedule.nextByBcType(sch, "normal"); | ||
| 38 | + | ||
| 39 | + if(fbFirst == null) | ||
| 40 | + return; | ||
| 41 | + | ||
| 42 | + long dt = fbFirst.getDfsjT(); | ||
| 43 | + //前5后10 -执行分班的首个营运 | ||
| 44 | + if(dt - t < 1000 * 60 * 5 || t - dt < 1000 * 60 * 10){ | ||
| 45 | + dayOfSchedule.addExecPlan(fbFirst); | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + }catch (Exception e){ | ||
| 50 | + log.error("", e); | ||
| 51 | + } | ||
| 52 | + | ||
| 30 | //下一个相同走向的班次 | 53 | //下一个相同走向的班次 |
| 31 | ScheduleRealInfo next = dayOfSchedule.nextSame(sch); | 54 | ScheduleRealInfo next = dayOfSchedule.nextSame(sch); |
| 32 | if(next == null || !next.getQdzCode().equals(sch.getQdzCode())) | 55 | if(next == null || !next.getQdzCode().equals(sch.getQdzCode())) |
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
| @@ -60,8 +60,10 @@ public class GpsDataRecovery implements ApplicationContextAware { | @@ -60,8 +60,10 @@ public class GpsDataRecovery implements ApplicationContextAware { | ||
| 60 | for (String lineId : keys) { | 60 | for (String lineId : keys) { |
| 61 | Collections.sort(listMap.get(lineId), comp); | 61 | Collections.sort(listMap.get(lineId), comp); |
| 62 | threadPool.execute(new RecoveryThread(listMap.get(lineId), count)); | 62 | threadPool.execute(new RecoveryThread(listMap.get(lineId), count)); |
| 63 | - /*if(nbbm.equals("W7C-001")) | 63 | + /*if(nbbm.equals("W7E-016")) |
| 64 | new RecoveryThread(listMap.get(nbbm), count).run();*/ | 64 | new RecoveryThread(listMap.get(nbbm), count).run();*/ |
| 65 | + /*if(lineId.equals("60028")) | ||
| 66 | + new RecoveryThread(listMap.get(lineId), count).run();*/ | ||
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | try { | 69 | try { |
| @@ -82,7 +84,7 @@ public class GpsDataRecovery implements ApplicationContextAware { | @@ -82,7 +84,7 @@ public class GpsDataRecovery implements ApplicationContextAware { | ||
| 82 | Calendar calendar = Calendar.getInstance(); | 84 | Calendar calendar = Calendar.getInstance(); |
| 83 | int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); | 85 | int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); |
| 84 | 86 | ||
| 85 | - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear; | 87 | + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=143";// + dayOfYear; |
| 86 | JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); | 88 | JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); |
| 87 | 89 | ||
| 88 | List<GpsEntity> list = | 90 | List<GpsEntity> list = |
| @@ -150,30 +152,34 @@ public class GpsDataRecovery implements ApplicationContextAware { | @@ -150,30 +152,34 @@ public class GpsDataRecovery implements ApplicationContextAware { | ||
| 150 | CircleQueue<GpsEntity> prevs; | 152 | CircleQueue<GpsEntity> prevs; |
| 151 | boolean task; | 153 | boolean task; |
| 152 | for (GpsEntity gps : list) { | 154 | for (GpsEntity gps : list) { |
| 153 | - | ||
| 154 | - //是否有任务 | ||
| 155 | - | ||
| 156 | - prevs = GeoCacheData.getGps(gps.getNbbm()); | ||
| 157 | - //掉线处理 | ||
| 158 | - offlineSignalHandle.handle(gps, prevs); | ||
| 159 | - //状态处理 | ||
| 160 | - task = correctSignalHandle.handle(gps, prevs); | ||
| 161 | - //场,站内外判断 | ||
| 162 | - stationInsideHandle.handle(gps, prevs); | ||
| 163 | - //异常判定(越界/超速) | ||
| 164 | - //abnormalStateHandle.handle(gps, prevs); | ||
| 165 | - | ||
| 166 | - if(!task) | ||
| 167 | - continue; //无任务的,到这里就结束 | ||
| 168 | - | ||
| 169 | - //反向处理 | ||
| 170 | - reverseSignalHandle.handle(gps, prevs); | ||
| 171 | - //进出站动作处理 | ||
| 172 | - inOutStationSignalHandle.handle(gps, prevs); | ||
| 173 | - GeoCacheData.putGps(gps); | 155 | + try { |
| 156 | + /*if(gps.getTimestamp() >= 1495512240000L){ | ||
| 157 | + System.out.println("debugger..."); | ||
| 158 | + }*/ | ||
| 159 | + //是否有任务 | ||
| 160 | + | ||
| 161 | + prevs = GeoCacheData.getGps(gps.getNbbm()); | ||
| 162 | + //掉线处理 | ||
| 163 | + offlineSignalHandle.handle(gps, prevs); | ||
| 164 | + //状态处理 | ||
| 165 | + task = correctSignalHandle.handle(gps, prevs); | ||
| 166 | + //场,站内外判断 | ||
| 167 | + stationInsideHandle.handle(gps, prevs); | ||
| 168 | + //异常判定(越界/超速) | ||
| 169 | + //abnormalStateHandle.handle(gps, prevs); | ||
| 170 | + | ||
| 171 | + if (!task) | ||
| 172 | + continue; //无任务的,到这里就结束 | ||
| 173 | + | ||
| 174 | + //反向处理 | ||
| 175 | + reverseSignalHandle.handle(gps, prevs); | ||
| 176 | + //进出站动作处理 | ||
| 177 | + inOutStationSignalHandle.handle(gps, prevs); | ||
| 178 | + GeoCacheData.putGps(gps); | ||
| 179 | + } catch (Exception e) { | ||
| 180 | + logger.error("", e); | ||
| 181 | + } | ||
| 174 | } | 182 | } |
| 175 | - } catch (Exception e) { | ||
| 176 | - logger.error("", e); | ||
| 177 | } finally { | 183 | } finally { |
| 178 | count.countDown(); | 184 | count.countDown(); |
| 179 | } | 185 | } |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| @@ -781,6 +781,26 @@ public class DayOfSchedule { | @@ -781,6 +781,26 @@ public class DayOfSchedule { | ||
| 781 | } | 781 | } |
| 782 | 782 | ||
| 783 | /** | 783 | /** |
| 784 | + * @Title: nextByBcType | ||
| 785 | + * @Description: TODO(获取下一个指定班次类型的班次) | ||
| 786 | + */ | ||
| 787 | + public ScheduleRealInfo nextByBcType(ScheduleRealInfo sch, String bcType) { | ||
| 788 | + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); | ||
| 789 | + Collections.sort(list, schFCSJComparator); | ||
| 790 | + | ||
| 791 | + boolean flag = false; | ||
| 792 | + for(ScheduleRealInfo temp : list){ | ||
| 793 | + if(temp == sch){ | ||
| 794 | + flag = true; | ||
| 795 | + } | ||
| 796 | + | ||
| 797 | + if(flag && temp.getBcType().equals(bcType)) | ||
| 798 | + return temp; | ||
| 799 | + } | ||
| 800 | + return null; | ||
| 801 | + } | ||
| 802 | + | ||
| 803 | + /** | ||
| 784 | * 搜索离当前时间最近的一个指定类型的班次 | 804 | * 搜索离当前时间最近的一个指定类型的班次 |
| 785 | * @param nbbm | 805 | * @param nbbm |
| 786 | * @param bcType | 806 | * @param bcType |