Commit c72c8e25564c96a0a781c5ea97cad078b67f8262
1 parent
52dc7079
1.进出站处理加入调试信息
Showing
2 changed files
with
503 additions
and
493 deletions
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 | - logger.info("进站记录(到达时间:" + gps.getArrTime() + " 进出站状态:" + gps.getInstation() + " 站点编号:" + gps.getStopNo() + " deviceId:" + gps.getDeviceId() + " nbbm:" + gps.getNbbm() + ")"); | ||
| 85 | - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | ||
| 86 | - boolean flow = true; | ||
| 87 | - //要经过2个中途站才能进 | ||
| 88 | - int count = GpsCacheData.lastInTrailsSize(gps); | ||
| 89 | - List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | ||
| 90 | - if (null != sch && isNormalSch(sch) && gps.getInstation() == 1 && routes.size() > 4 | ||
| 91 | - && count < 2) { | ||
| 92 | - logger.info("没有进中途站,拒绝进站... -" + gps.getNbbm() + " -time:" + gps.getTimestamp()); | ||
| 93 | - flow = false; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - boolean isEnd = false; | ||
| 97 | - | ||
| 98 | - //进终点 | ||
| 99 | - if (flow && null != sch && | ||
| 100 | - ((sch.getZdzCode().equals(gps.getStopNo()) && gps.getInstation() > 0) || sch.getZdzCode().equals(gps.getCarparkNo()))) { | ||
| 101 | - inEndStation(sch, gps); | ||
| 102 | - isEnd = true; | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - GpsCacheData.in(gps, isEnd); | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - private boolean isNormalSch(ScheduleRealInfo sch) { | ||
| 109 | - return sch.getBcType().equals("normal"); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - private boolean isNotInOut(ScheduleRealInfo sch) { | ||
| 113 | - return !sch.getBcType().equals("in") && !sch.getBcType().equals("out"); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | - * 进班次终点 | ||
| 118 | - * | ||
| 119 | - * @param gps | ||
| 120 | - */ | ||
| 121 | - private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) { | ||
| 122 | - String nbbm = sch.getClZbh(); | ||
| 123 | - //校验进站前置约束 | ||
| 124 | - if (!validInPremise(gps) && isNormalSch(sch)) | ||
| 125 | - return; | ||
| 126 | - | ||
| 127 | - //实达时间不覆盖 | ||
| 128 | - if (StringUtils.isNotEmpty(sch.getZdsjActual())) | ||
| 129 | - return; | ||
| 130 | - | ||
| 131 | - //应用到离站缓冲区设置参数 | ||
| 132 | - long rsT = lineConfigData.applyIn(sch, gps.getTimestamp()); | ||
| 133 | - | ||
| 134 | - sch.setZdsjActualAll(rsT); | ||
| 135 | - sch.setSiginCompate(2); | ||
| 136 | - | ||
| 137 | - //持久化 | ||
| 138 | - dayOfSchedule.save(sch); | ||
| 139 | - | ||
| 140 | - //车辆的下一个班次 | ||
| 141 | - ScheduleRealInfo next = dayOfSchedule.next(sch); | ||
| 142 | - if (next != null) { | ||
| 143 | - dayOfSchedule.addExecPlan(next); | ||
| 144 | - inStationAndInPark(sch, next);//进站既进场 | ||
| 145 | - } | ||
| 146 | - else | ||
| 147 | - dayOfSchedule.removeExecPlan(nbbm); | ||
| 148 | - | ||
| 149 | - //通知误点停靠程序,有车辆到站 | ||
| 150 | - LateAdjustHandle.carArrive(gps, next); | ||
| 151 | - //LateAdjustHandle.carArrive(gps); | ||
| 152 | - | ||
| 153 | - //路牌的下一个班次,页面显示起点实际到达时间 | ||
| 154 | - ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch); | ||
| 155 | - if (lpNext != null) { | ||
| 156 | - lpNext.setQdzArrDatesj(sch.getZdsjActual()); | ||
| 157 | - } | ||
| 158 | - | ||
| 159 | - //已完成班次数 | ||
| 160 | - int doneSum = dayOfSchedule.doneSum(nbbm); | ||
| 161 | - //webSocket | ||
| 162 | - sendUtils.sendZdsj(sch, lpNext, doneSum); | ||
| 163 | - | ||
| 164 | - logger.info("车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual() + " -stopNo: " + gps.getStopNo()); | ||
| 165 | - | ||
| 166 | - //清除车辆误点调整监听 | ||
| 167 | - LateAdjustHandle.remove(sch); | ||
| 168 | - | ||
| 169 | - //将gps转换成下一个班次走向的站内信号(应对只有一个站内信号 即 发出时) | ||
| 170 | - transformUpDown(gps, next); | ||
| 171 | - | ||
| 172 | - //套跑 -下发线路切换指令 | ||
| 173 | - if (null != next && !next.getXlBm().equals(sch.getXlBm())) { | ||
| 174 | - gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统"); | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - /** | ||
| 178 | - * 注意: | ||
| 179 | - * 要先发运营指令,再发调度指令 | ||
| 180 | - */ | ||
| 181 | - if(null == next && gps.isService()){ | ||
| 182 | - nonService(sch, "结束@系统");//营运结束 | ||
| 183 | - } | ||
| 184 | - | ||
| 185 | - /** | ||
| 186 | - * 下一班不是全程班次的时候,下发运营指令 | ||
| 187 | - * 全程班次时,由网关根据进出起终点,自动切换走向 | ||
| 188 | - | ||
| 189 | - if(null != next && !next.getBcType().equals("normal")) | ||
| 190 | - DirectivePushQueue.put6003(next, "到站@系统"); | ||
| 191 | - */ | ||
| 192 | - //下发调度指令 | ||
| 193 | - DirectivePushQueue.put6002(next, doneSum, "到站@系统", ""); | ||
| 194 | - } | ||
| 195 | - | ||
| 196 | - /** | ||
| 197 | - * 校验进站前置约束 | ||
| 198 | - * | ||
| 199 | - * @param gps | ||
| 200 | - * @return | ||
| 201 | - */ | ||
| 202 | - private boolean validInPremise(GpsEntity gps) { | ||
| 203 | - StationRoute sr = gps.getStation(); | ||
| 204 | - if (null == sr || !sr.isPremise()) | ||
| 205 | - return true; | ||
| 206 | - | ||
| 207 | - String premiseCode = gps.getPremiseCode(); | ||
| 208 | - | ||
| 209 | - if (StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())) { | ||
| 210 | - logger.info("满足前置进站约束 " + premiseCode); | ||
| 211 | - return true; | ||
| 212 | - } else { | ||
| 213 | - logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode); | ||
| 214 | - } | ||
| 215 | - return false; | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - /** | ||
| 219 | - * 进站既进场 | ||
| 220 | - * | ||
| 221 | - * @param sch | ||
| 222 | - */ | ||
| 223 | - private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next) { | ||
| 224 | - LineConfig config = lineConfigData.get(sch.getXlBm()); | ||
| 225 | - //限定出站既出场的停车场 | ||
| 226 | - List<String> parks = config.findTwinsParkList(); | ||
| 227 | - boolean limitPark = null != parks && parks.size() > 0; | ||
| 228 | - | ||
| 229 | - | ||
| 230 | - if (next.getBcType().equals("in") && config.getOutConfig() == 2 && isEmptyMileage(next) | ||
| 231 | - && (!limitPark || parks.contains(next.getZdzCode()))) { | ||
| 232 | - | ||
| 233 | - endSch(next, sch.getZdsjActualTime()); | ||
| 234 | - | ||
| 235 | - sendUtils.refreshSch(next); | ||
| 236 | - dayOfSchedule.save(next); | ||
| 237 | - | ||
| 238 | - //分班的时候,需要再跳过1个班次 | ||
| 239 | - next = dayOfSchedule.next(next); | ||
| 240 | - if (next != null) | ||
| 241 | - dayOfSchedule.addExecPlan(next); | ||
| 242 | - | ||
| 243 | - //进场,切换成非营运状态 | ||
| 244 | - nonService(sch, "进场@系统"); | ||
| 245 | - } | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - | ||
| 249 | - private boolean isEmptyMileage(ScheduleRealInfo sch) { | ||
| 250 | - return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0; | ||
| 251 | - } | ||
| 252 | - | ||
| 253 | - | ||
| 254 | - /** | ||
| 255 | - * 切换为非营运状态 | ||
| 256 | - * | ||
| 257 | - * @param sch | ||
| 258 | - * @param sender | ||
| 259 | - */ | ||
| 260 | - private void nonService(ScheduleRealInfo sch, String sender) { | ||
| 261 | - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender); | ||
| 262 | - } | ||
| 263 | - | ||
| 264 | - private void endSch(ScheduleRealInfo sch, Long t) { | ||
| 265 | - sch.setFcsjActualAll(t); | ||
| 266 | - sch.setZdsjActualAll(t); | ||
| 267 | - } | ||
| 268 | - | ||
| 269 | - private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) { | ||
| 270 | - if (null == sch) | ||
| 271 | - return; | ||
| 272 | - byte upDown = Byte.parseByte(sch.getXlDir()); | ||
| 273 | - //gps 切换走向 | ||
| 274 | - gps.setUpDown(upDown); | ||
| 275 | - gps.setPremiseCode(null); | ||
| 276 | - | ||
| 277 | - List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown); | ||
| 278 | - StationRoute station = GeoUtils.gpsInStation(gps, srs); | ||
| 279 | - if (station != null) { | ||
| 280 | - gps.setStopNo(station.getCode()); | ||
| 281 | - } | ||
| 282 | - } | ||
| 283 | - | ||
| 284 | - private boolean isInPark(GpsEntity gps, GpsEntity prve) { | ||
| 285 | - if (StringUtils.isNotEmpty(gps.getCarparkNo()) && StringUtils.isEmpty(prve.getCarparkNo())) | ||
| 286 | - return true; | ||
| 287 | - return false; | ||
| 288 | - } | 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 | + logger.info("进站记录(到达时间:" + gps.getArrTime() + " 进出站状态:" + gps.getInstation() + " 站点编号:" + gps.getStopNo() + " deviceId:" + gps.getDeviceId() + " nbbm:" + gps.getNbbm() + ")"); | ||
| 85 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | ||
| 86 | + boolean flow = true; | ||
| 87 | + //要经过2个中途站才能进 | ||
| 88 | + int count = GpsCacheData.lastInTrailsSize(gps); | ||
| 89 | + if (null != sch) | ||
| 90 | + logger.info("班次id: -" + sch.getId() + " count:" + count+" sch.getZdzCode(): "+sch.getZdzCode()+" sch.getZdzCode(): "+sch.getZdzCode()+" gps.getCarparkNo() :"+gps.getCarparkNo()); | ||
| 91 | + else | ||
| 92 | + logger.info("sch is null...."); | ||
| 93 | + List<StationRoute> routes = GeoCacheData.getStationRoute(gps.getLineId(), gps.getUpDown()); | ||
| 94 | + if (null != sch && isNormalSch(sch) && gps.getInstation() == 1 && routes.size() > 4 | ||
| 95 | + && count < 2) { | ||
| 96 | + logger.info("没有进中途站,拒绝进站... -" + gps.getNbbm() + " -time:" + gps.getTimestamp()); | ||
| 97 | + flow = false; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + boolean isEnd = false; | ||
| 101 | + | ||
| 102 | + //进终点 | ||
| 103 | + if (flow && null != sch && | ||
| 104 | + ((sch.getZdzCode().equals(gps.getStopNo()) && gps.getInstation() > 0) || sch.getZdzCode().equals(gps.getCarparkNo()))) { | ||
| 105 | + inEndStation(sch, gps); | ||
| 106 | + if (sch.getZdsjActualTime() != null) { | ||
| 107 | + isEnd = true; | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + GpsCacheData.in(gps, isEnd); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + private boolean isNormalSch(ScheduleRealInfo sch) { | ||
| 115 | + return sch.getBcType().equals("normal"); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + private boolean isNotInOut(ScheduleRealInfo sch) { | ||
| 119 | + return !sch.getBcType().equals("in") && !sch.getBcType().equals("out"); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 进班次终点 | ||
| 124 | + * | ||
| 125 | + * @param gps | ||
| 126 | + */ | ||
| 127 | + private void inEndStation(ScheduleRealInfo sch, GpsEntity gps) { | ||
| 128 | + String nbbm = sch.getClZbh(); | ||
| 129 | + //校验进站前置约束 | ||
| 130 | + if (!validInPremise(gps) && isNormalSch(sch)) | ||
| 131 | + return; | ||
| 132 | + | ||
| 133 | + //实达时间不覆盖 | ||
| 134 | + if (StringUtils.isNotEmpty(sch.getZdsjActual())) | ||
| 135 | + return; | ||
| 136 | + | ||
| 137 | + //应用到离站缓冲区设置参数 | ||
| 138 | + long rsT = lineConfigData.applyIn(sch, gps.getTimestamp()); | ||
| 139 | + | ||
| 140 | + sch.setZdsjActualAll(rsT); | ||
| 141 | + sch.setSiginCompate(2); | ||
| 142 | + | ||
| 143 | + //持久化 | ||
| 144 | + dayOfSchedule.save(sch); | ||
| 145 | + | ||
| 146 | + //车辆的下一个班次 | ||
| 147 | + ScheduleRealInfo next = dayOfSchedule.next(sch); | ||
| 148 | + if (next != null) { | ||
| 149 | + dayOfSchedule.addExecPlan(next); | ||
| 150 | + inStationAndInPark(sch, next);//进站既进场 | ||
| 151 | + } | ||
| 152 | + else | ||
| 153 | + dayOfSchedule.removeExecPlan(nbbm); | ||
| 154 | + | ||
| 155 | + //通知误点停靠程序,有车辆到站 | ||
| 156 | + LateAdjustHandle.carArrive(gps, next); | ||
| 157 | + //LateAdjustHandle.carArrive(gps); | ||
| 158 | + | ||
| 159 | + //路牌的下一个班次,页面显示起点实际到达时间 | ||
| 160 | + ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch); | ||
| 161 | + if (lpNext != null) { | ||
| 162 | + lpNext.setQdzArrDatesj(sch.getZdsjActual()); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + //已完成班次数 | ||
| 166 | + int doneSum = dayOfSchedule.doneSum(nbbm); | ||
| 167 | + //webSocket | ||
| 168 | + sendUtils.sendZdsj(sch, lpNext, doneSum); | ||
| 169 | + | ||
| 170 | + logger.info("车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual() + " -stopNo: " + gps.getStopNo()); | ||
| 171 | + | ||
| 172 | + //清除车辆误点调整监听 | ||
| 173 | + LateAdjustHandle.remove(sch); | ||
| 174 | + | ||
| 175 | + //将gps转换成下一个班次走向的站内信号(应对只有一个站内信号 即 发出时) | ||
| 176 | + //transformUpDown(gps, next); | ||
| 177 | + | ||
| 178 | + //套跑 -下发线路切换指令 | ||
| 179 | + if (null != next && !next.getXlBm().equals(sch.getXlBm())) { | ||
| 180 | + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统"); | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * 注意: | ||
| 185 | + * 要先发运营指令,再发调度指令 | ||
| 186 | + */ | ||
| 187 | + if(null == next && gps.isService()){ | ||
| 188 | + nonService(sch, "结束@系统");//营运结束 | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * 下一班不是全程班次的时候,下发运营指令 | ||
| 193 | + * 全程班次时,由网关根据进出起终点,自动切换走向 | ||
| 194 | + | ||
| 195 | + if(null != next && !next.getBcType().equals("normal")) | ||
| 196 | + DirectivePushQueue.put6003(next, "到站@系统"); | ||
| 197 | + */ | ||
| 198 | + //下发调度指令 | ||
| 199 | + DirectivePushQueue.put6002(next, doneSum, "到站@系统", ""); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + /** | ||
| 203 | + * 校验进站前置约束 | ||
| 204 | + * | ||
| 205 | + * @param gps | ||
| 206 | + * @return | ||
| 207 | + */ | ||
| 208 | + private boolean validInPremise(GpsEntity gps) { | ||
| 209 | + StationRoute sr = gps.getStation(); | ||
| 210 | + if (null == sr || !sr.isPremise()) | ||
| 211 | + return true; | ||
| 212 | + | ||
| 213 | + String premiseCode = gps.getPremiseCode(); | ||
| 214 | + | ||
| 215 | + if (StringUtils.isNotEmpty(premiseCode) && premiseCode.equals(gps.getStopNo())) { | ||
| 216 | + logger.info("满足前置进站约束 " + premiseCode); | ||
| 217 | + return true; | ||
| 218 | + } else { | ||
| 219 | + logger.info(gps.getNbbm() + " not premiseCode 不满足前置进站约束 " + premiseCode); | ||
| 220 | + } | ||
| 221 | + return false; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * 进站既进场 | ||
| 226 | + * | ||
| 227 | + * @param sch | ||
| 228 | + */ | ||
| 229 | + private void inStationAndInPark(ScheduleRealInfo sch, ScheduleRealInfo next) { | ||
| 230 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | ||
| 231 | + //限定出站既出场的停车场 | ||
| 232 | + List<String> parks = config.findTwinsParkList(); | ||
| 233 | + boolean limitPark = null != parks && parks.size() > 0; | ||
| 234 | + | ||
| 235 | + | ||
| 236 | + if (next.getBcType().equals("in") && config.getOutConfig() == 2 && isEmptyMileage(next) | ||
| 237 | + && (!limitPark || parks.contains(next.getZdzCode()))) { | ||
| 238 | + | ||
| 239 | + endSch(next, sch.getZdsjActualTime()); | ||
| 240 | + | ||
| 241 | + sendUtils.refreshSch(next); | ||
| 242 | + dayOfSchedule.save(next); | ||
| 243 | + | ||
| 244 | + //分班的时候,需要再跳过1个班次 | ||
| 245 | + next = dayOfSchedule.next(next); | ||
| 246 | + if (next != null) | ||
| 247 | + dayOfSchedule.addExecPlan(next); | ||
| 248 | + | ||
| 249 | + //进场,切换成非营运状态 | ||
| 250 | + nonService(sch, "进场@系统"); | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + | ||
| 254 | + | ||
| 255 | + private boolean isEmptyMileage(ScheduleRealInfo sch) { | ||
| 256 | + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0; | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + | ||
| 260 | + /** | ||
| 261 | + * 切换为非营运状态 | ||
| 262 | + * | ||
| 263 | + * @param sch | ||
| 264 | + * @param sender | ||
| 265 | + */ | ||
| 266 | + private void nonService(ScheduleRealInfo sch, String sender) { | ||
| 267 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender); | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + private void endSch(ScheduleRealInfo sch, Long t) { | ||
| 271 | + sch.setFcsjActualAll(t); | ||
| 272 | + sch.setZdsjActualAll(t); | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + private void transformUpDown(GpsEntity gps, ScheduleRealInfo sch) { | ||
| 276 | + if (null == sch) | ||
| 277 | + return; | ||
| 278 | + byte upDown = Byte.parseByte(sch.getXlDir()); | ||
| 279 | + //gps 切换走向 | ||
| 280 | + gps.setUpDown(upDown); | ||
| 281 | + gps.setPremiseCode(null); | ||
| 282 | + | ||
| 283 | + List<StationRoute> srs = GeoCacheData.getStationRoute(sch.getXlBm(), upDown); | ||
| 284 | + StationRoute station = GeoUtils.gpsInStation(gps, srs); | ||
| 285 | + if (station != null) { | ||
| 286 | + gps.setStopNo(station.getCode()); | ||
| 287 | + } | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + private boolean isInPark(GpsEntity gps, GpsEntity prve) { | ||
| 291 | + if (StringUtils.isNotEmpty(gps.getCarparkNo()) && StringUtils.isEmpty(prve.getCarparkNo())) | ||
| 292 | + return true; | ||
| 293 | + return false; | ||
| 294 | + } | ||
| 289 | } | 295 | } |
| 290 | \ No newline at end of file | 296 | \ 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 | -import java.util.List; | ||
| 20 | - | ||
| 21 | -/** | ||
| 22 | - * 车辆出站处理程序 | ||
| 23 | - * Created by panzhao on 2017/11/16. | ||
| 24 | - */ | ||
| 25 | -@Component | ||
| 26 | -public class OutStationProcess { | ||
| 27 | - | ||
| 28 | - @Autowired | ||
| 29 | - DayOfSchedule dayOfSchedule; | ||
| 30 | - | ||
| 31 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 32 | - | ||
| 33 | - @Autowired | ||
| 34 | - LineConfigData lineConfigData; | ||
| 35 | - | ||
| 36 | - @Autowired | ||
| 37 | - SendUtils sendUtils; | ||
| 38 | - | ||
| 39 | - @Autowired | ||
| 40 | - SignalSchPlanMatcher signalSchPlanMatcher; | ||
| 41 | - | ||
| 42 | - @Autowired | ||
| 43 | - GpsStatusManager gpsStatusManager; | ||
| 44 | - private final static int MAX_BEFORE_TIME = 1000 * 60 * 60 * 3; | ||
| 45 | - | ||
| 46 | - public void process(GpsEntity gps) { | ||
| 47 | - //自动执行的线路,滚蛋 | ||
| 48 | - LineConfig config = lineConfigData.get(gps.getLineId()); | ||
| 49 | - if (null != config && config.isAutoExec()) | ||
| 50 | - return; | ||
| 51 | - | ||
| 52 | - GpsEntity prev = GpsCacheData.getPrev(gps); | ||
| 53 | - | ||
| 54 | - if (null == prev) | ||
| 55 | - return; | ||
| 56 | - | ||
| 57 | - //从站内到站外 | ||
| 58 | - if (prev.getInstation() > 0 && gps.getInstation() == 0) | ||
| 59 | - outStation(gps, prev); | ||
| 60 | - | ||
| 61 | - //从站内到另一个站内 | ||
| 62 | - if (prev.getInstation() > 0 && gps.getInstation() > 0 | ||
| 63 | - && !prev.getStopNo().equals(gps.getStopNo())) | ||
| 64 | - outStation(gps, prev); | ||
| 65 | - | ||
| 66 | - //在被起点站覆盖的情况下出场 | ||
| 67 | - if (isOutPark(gps, prev)) | ||
| 68 | - outStation(gps, prev); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - /** | ||
| 72 | - * 出站 | ||
| 73 | - * | ||
| 74 | - * @param gps | ||
| 75 | - */ | ||
| 76 | - private void outStation(GpsEntity gps, GpsEntity prev) { | ||
| 77 | - logger.info("出站记录(到达时间:" + gps.getArrTime() + " 进出站状态:" + gps.getInstation() + " 站点编号:" + gps.getStopNo() + " deviceId:" + gps.getDeviceId() + " nbbm:" + gps.getNbbm() + ")"); | ||
| 78 | - ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | ||
| 79 | - | ||
| 80 | - //起点发车 | ||
| 81 | - if (null != sch && | ||
| 82 | - ((sch.getQdzCode().equals(prev.getStopNo()) | ||
| 83 | - && (gps.getInstation() == 0 || !gps.getStopNo().equals(prev.getStopNo()))) | ||
| 84 | - || sch.getQdzCode().equals(prev.getCarparkNo()))) { | ||
| 85 | - //发车班次匹配 | ||
| 86 | - if (!signalSchPlanMatcher.outMatch(gps, sch)) { | ||
| 87 | - outStation(gps, prev); | ||
| 88 | - return; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); | ||
| 92 | - //首班出场最多提前3小时 | ||
| 93 | - if (dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) | ||
| 94 | - return; | ||
| 95 | - | ||
| 96 | - gps.setPremiseCode(null);//清除前置围栏标记 | ||
| 97 | - | ||
| 98 | - if (StringUtils.isNotEmpty(sch.getFcsjActual()) | ||
| 99 | - && !outManyFit(gps, sch)) { | ||
| 100 | - return;//班次已经实发 | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - //应用到离站缓冲区设置参数 | ||
| 104 | - long rsT = lineConfigData.applyOut(sch, gps.getTimestamp()); | ||
| 105 | - //实发时间 | ||
| 106 | - sch.setFcsjActualAll(rsT); | ||
| 107 | - sch.setSiginCompate(1); | ||
| 108 | - | ||
| 109 | - //出站既出场 | ||
| 110 | - outStationAndOutPark(sch); | ||
| 111 | - | ||
| 112 | - //webSocket | ||
| 113 | - sendUtils.sendFcsj(sch); | ||
| 114 | - | ||
| 115 | - //持久化 | ||
| 116 | - dayOfSchedule.save(sch); | ||
| 117 | - | ||
| 118 | - //清理应发未发标记 | ||
| 119 | - LateAdjustHandle.remove(sch); | ||
| 120 | - | ||
| 121 | - //发车的时候,同步一下状态 | ||
| 122 | - /*if (!gps.isService() && !dayOfSchedule.emptyService(sch)) | ||
| 123 | - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统"); | ||
| 124 | -*/ | ||
| 125 | - logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | ||
| 126 | - } | ||
| 127 | - | ||
| 128 | - GpsCacheData.out(gps); | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | - /** | ||
| 132 | - * 是否是一个更合适的发车信号 | ||
| 133 | - * | ||
| 134 | - * @param gps | ||
| 135 | - * @param sch | ||
| 136 | - * @return | ||
| 137 | - */ | ||
| 138 | - private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) { | ||
| 139 | - LineConfig conf = lineConfigData.get(sch.getXlBm()); | ||
| 140 | - if (null != conf && conf.isLockFirstOutTime()) | ||
| 141 | - return false; | ||
| 142 | - | ||
| 143 | - if (StringUtils.isNotEmpty(sch.getZdsjActual())) | ||
| 144 | - return false; | ||
| 145 | - | ||
| 146 | - long t1 = sch.getFcsjActualTime(); | ||
| 147 | - long t2 = gps.getTimestamp(); | ||
| 148 | - long c = sch.getDfsjT(); | ||
| 149 | - | ||
| 150 | - int threshold = 1000 * 60 * 5; | ||
| 151 | - if (Math.abs(t2 - c) < threshold && c - t1 > threshold) { | ||
| 152 | - return true; | ||
| 153 | - } | ||
| 154 | - | ||
| 155 | - if (c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1) { | ||
| 156 | - return true; | ||
| 157 | - } | ||
| 158 | - return false; | ||
| 159 | - } | ||
| 160 | - | ||
| 161 | - private void outStationAndOutPark(ScheduleRealInfo sch) { | ||
| 162 | - try { | ||
| 163 | - LineConfig config = lineConfigData.get(sch.getXlBm()); | ||
| 164 | - //限定出站既出场的停车场 | ||
| 165 | - List<String> parks = config.findTwinsParkList(); | ||
| 166 | - boolean limitPark = null != parks && parks.size() > 0; | ||
| 167 | - | ||
| 168 | - if (config != null && config.getOutConfig() == 2) { | ||
| 169 | - //出站既出场 | ||
| 170 | - ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | ||
| 171 | - if (isOut(schPrev) && isEmptyMileage(schPrev) | ||
| 172 | - && (!limitPark || parks.contains(schPrev.getQdzCode()))) { | ||
| 173 | - | ||
| 174 | - endSch(schPrev, sch.getFcsjActualTime()); | ||
| 175 | - | ||
| 176 | - //起点实到 | ||
| 177 | - sch.setQdzArrDatesj(schPrev.getZdsjActual()); | ||
| 178 | - | ||
| 179 | - sendUtils.refreshSch(schPrev); | ||
| 180 | - dayOfSchedule.save(schPrev); | ||
| 181 | - } | ||
| 182 | - } | ||
| 183 | - } catch (Exception e) { | ||
| 184 | - logger.error("", e); | ||
| 185 | - } | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - private boolean isEmptyMileage(ScheduleRealInfo sch) { | ||
| 189 | - return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0; | ||
| 190 | - } | ||
| 191 | - | ||
| 192 | - private boolean isOut(ScheduleRealInfo sch) { | ||
| 193 | - return sch != null && sch.getBcType().equals("out"); | ||
| 194 | - } | ||
| 195 | - | ||
| 196 | - private void endSch(ScheduleRealInfo sch, Long t) { | ||
| 197 | - sch.setFcsjActualAll(t); | ||
| 198 | - sch.setZdsjActualAll(t); | ||
| 199 | - } | ||
| 200 | - | ||
| 201 | - private boolean isOutPark(GpsEntity gps, GpsEntity prve) { | ||
| 202 | - if (StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo())) | ||
| 203 | - return true; | ||
| 204 | - return false; | ||
| 205 | - } | 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 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * 车辆出站处理程序 | ||
| 23 | + * Created by panzhao on 2017/11/16. | ||
| 24 | + */ | ||
| 25 | +@Component | ||
| 26 | +public class OutStationProcess { | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + DayOfSchedule dayOfSchedule; | ||
| 30 | + | ||
| 31 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 32 | + | ||
| 33 | + @Autowired | ||
| 34 | + LineConfigData lineConfigData; | ||
| 35 | + | ||
| 36 | + @Autowired | ||
| 37 | + SendUtils sendUtils; | ||
| 38 | + | ||
| 39 | + @Autowired | ||
| 40 | + SignalSchPlanMatcher signalSchPlanMatcher; | ||
| 41 | + | ||
| 42 | + @Autowired | ||
| 43 | + GpsStatusManager gpsStatusManager; | ||
| 44 | + private final static int MAX_BEFORE_TIME = 1000 * 60 * 60 * 3; | ||
| 45 | + | ||
| 46 | + public void process(GpsEntity gps) { | ||
| 47 | + //自动执行的线路,滚蛋 | ||
| 48 | + LineConfig config = lineConfigData.get(gps.getLineId()); | ||
| 49 | + if (null != config && config.isAutoExec()) | ||
| 50 | + return; | ||
| 51 | + | ||
| 52 | + GpsEntity prev = GpsCacheData.getPrev(gps); | ||
| 53 | + | ||
| 54 | + if (null == prev) | ||
| 55 | + return; | ||
| 56 | + | ||
| 57 | + //从站内到站外 | ||
| 58 | + if (prev.getInstation() > 0 && gps.getInstation() == 0) | ||
| 59 | + outStation(gps, prev); | ||
| 60 | + | ||
| 61 | + //从站内到另一个站内 | ||
| 62 | + if (prev.getInstation() > 0 && gps.getInstation() > 0 | ||
| 63 | + && !prev.getStopNo().equals(gps.getStopNo())) | ||
| 64 | + outStation(gps, prev); | ||
| 65 | + | ||
| 66 | + //在被起点站覆盖的情况下出场 | ||
| 67 | + if (isOutPark(gps, prev)) | ||
| 68 | + outStation(gps, prev); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 出站 | ||
| 73 | + * | ||
| 74 | + * @param gps | ||
| 75 | + */ | ||
| 76 | + private void outStation(GpsEntity gps, GpsEntity prev) { | ||
| 77 | + logger.info("出站记录(到达时间:" + gps.getArrTime() + " 进出站状态:" + gps.getInstation() + " 站点编号:" + gps.getStopNo() + " deviceId:" + gps.getDeviceId() + " nbbm:" + gps.getNbbm() + ")"); | ||
| 78 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | ||
| 79 | + | ||
| 80 | + if (null != sch) | ||
| 81 | + logger.info("班次id: " + sch.getId() + " sch.getQdzCode():" + sch.getQdzCode() + " prev.getStopNo():" + prev.getStopNo() + " prev.getStopNo():" + prev.getStopNo() + " sch.getQdzCode():" + sch.getQdzCode() +" prev.getCarparkNo() :"+prev.getCarparkNo()+" diff :"+((int) (sch.getDfsjT() - gps.getTimestamp()))+" dayOfSchedule.isFirstOut(sch) && diff"+(dayOfSchedule.isFirstOut(sch))+" sch.getFcsjActual():"+sch.getFcsjActual()+" StringUtils.isNotEmpty(sch.getFcsjActual())&& !outManyFit(gps, sch) :"+(StringUtils.isNotEmpty(sch.getFcsjActual())&& !outManyFit(gps, sch))+ ")"); | ||
| 82 | + else | ||
| 83 | + logger.info("sch is null...."); | ||
| 84 | + //起点发车 | ||
| 85 | + if (null != sch && | ||
| 86 | + ((sch.getQdzCode().equals(prev.getStopNo()) | ||
| 87 | + && (gps.getInstation() == 0 || !gps.getStopNo().equals(prev.getStopNo()))) | ||
| 88 | + || sch.getQdzCode().equals(prev.getCarparkNo()))) { | ||
| 89 | + //发车班次匹配 | ||
| 90 | + if (!signalSchPlanMatcher.outMatch(gps, sch)) { | ||
| 91 | + outStation(gps, prev); | ||
| 92 | + return; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); | ||
| 96 | + //首班出场最多提前3小时 | ||
| 97 | + if (dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) | ||
| 98 | + return; | ||
| 99 | + | ||
| 100 | + gps.setPremiseCode(null);//清除前置围栏标记 | ||
| 101 | + | ||
| 102 | + if (StringUtils.isNotEmpty(sch.getFcsjActual()) | ||
| 103 | + && !outManyFit(gps, sch)) { | ||
| 104 | + return;//班次已经实发 | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + //应用到离站缓冲区设置参数 | ||
| 108 | + long rsT = lineConfigData.applyOut(sch, gps.getTimestamp()); | ||
| 109 | + //实发时间 | ||
| 110 | + sch.setFcsjActualAll(rsT); | ||
| 111 | + sch.setSiginCompate(1); | ||
| 112 | + | ||
| 113 | + //出站既出场 | ||
| 114 | + outStationAndOutPark(sch); | ||
| 115 | + | ||
| 116 | + //webSocket | ||
| 117 | + sendUtils.sendFcsj(sch); | ||
| 118 | + | ||
| 119 | + //持久化 | ||
| 120 | + dayOfSchedule.save(sch); | ||
| 121 | + | ||
| 122 | + //清理应发未发标记 | ||
| 123 | + LateAdjustHandle.remove(sch); | ||
| 124 | + | ||
| 125 | + //发车的时候,同步一下状态 | ||
| 126 | + /*if (!gps.isService() && !dayOfSchedule.emptyService(sch)) | ||
| 127 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统"); | ||
| 128 | +*/ | ||
| 129 | + logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + GpsCacheData.out(gps); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * 是否是一个更合适的发车信号 | ||
| 137 | + * | ||
| 138 | + * @param gps | ||
| 139 | + * @param sch | ||
| 140 | + * @return | ||
| 141 | + */ | ||
| 142 | + private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) { | ||
| 143 | + LineConfig conf = lineConfigData.get(sch.getXlBm()); | ||
| 144 | + if (null != conf && conf.isLockFirstOutTime()) | ||
| 145 | + return false; | ||
| 146 | + | ||
| 147 | + if (StringUtils.isNotEmpty(sch.getZdsjActual())) | ||
| 148 | + return false; | ||
| 149 | + | ||
| 150 | + long t1 = sch.getFcsjActualTime(); | ||
| 151 | + long t2 = gps.getTimestamp(); | ||
| 152 | + long c = sch.getDfsjT(); | ||
| 153 | + | ||
| 154 | + int threshold = 1000 * 60 * 5; | ||
| 155 | + if (Math.abs(t2 - c) < threshold && c - t1 > threshold) { | ||
| 156 | + return true; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + if (c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1) { | ||
| 160 | + return true; | ||
| 161 | + } | ||
| 162 | + return false; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + private void outStationAndOutPark(ScheduleRealInfo sch) { | ||
| 166 | + try { | ||
| 167 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | ||
| 168 | + //限定出站既出场的停车场 | ||
| 169 | + List<String> parks = config.findTwinsParkList(); | ||
| 170 | + boolean limitPark = null != parks && parks.size() > 0; | ||
| 171 | + | ||
| 172 | + if (config != null && config.getOutConfig() == 2) { | ||
| 173 | + //出站既出场 | ||
| 174 | + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | ||
| 175 | + if (isOut(schPrev) && isEmptyMileage(schPrev) | ||
| 176 | + && (!limitPark || parks.contains(schPrev.getQdzCode()))) { | ||
| 177 | + | ||
| 178 | + endSch(schPrev, sch.getFcsjActualTime()); | ||
| 179 | + | ||
| 180 | + //起点实到 | ||
| 181 | + sch.setQdzArrDatesj(schPrev.getZdsjActual()); | ||
| 182 | + | ||
| 183 | + sendUtils.refreshSch(schPrev); | ||
| 184 | + dayOfSchedule.save(schPrev); | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + } catch (Exception e) { | ||
| 188 | + logger.error("", e); | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + private boolean isEmptyMileage(ScheduleRealInfo sch) { | ||
| 193 | + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + private boolean isOut(ScheduleRealInfo sch) { | ||
| 197 | + return sch != null && sch.getBcType().equals("out"); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + private void endSch(ScheduleRealInfo sch, Long t) { | ||
| 201 | + sch.setFcsjActualAll(t); | ||
| 202 | + sch.setZdsjActualAll(t); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + private boolean isOutPark(GpsEntity gps, GpsEntity prve) { | ||
| 206 | + if (StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo())) | ||
| 207 | + return true; | ||
| 208 | + return false; | ||
| 209 | + } | ||
| 206 | } | 210 | } |
| 207 | \ No newline at end of file | 211 | \ No newline at end of file |