Commit 875e4f3b269bf1da8294fa131397bf088157ce00
1 parent
7b829e13
1.
Showing
1 changed file
with
207 additions
and
205 deletions
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(到达时间:{} 进出站状态:{} 站点编号:{} deviceId:{} nbbm:{})", gps.getArrTime(), gps.getInstation(), gps.getStopNo(), gps.getDeviceId(), gps.getNbbm()); | |
| 78 | + logger.info("prev(到达时间:{} 进出站状态:{} 站点编号:{} deviceId:{} nbbm:{})", prev.getArrTime(), prev.getInstation(), prev.getStopNo(), prev.getDeviceId(), prev.getNbbm()); | |
| 79 | + ScheduleRealInfo sch = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 80 | + logger.info("sch: {}", sch == null ? "null" : sch.getId()); | |
| 81 | + | |
| 82 | + //起点发车 | |
| 83 | + if (null != sch && | |
| 84 | + ((sch.getQdzCode().equals(prev.getStopNo()) | |
| 85 | + && (gps.getInstation() == 0 || !gps.getStopNo().equals(prev.getStopNo()))) | |
| 86 | + || sch.getQdzCode().equals(prev.getCarparkNo()))) { | |
| 87 | + //发车班次匹配 | |
| 88 | + if (!signalSchPlanMatcher.outMatch(gps, sch)) { | |
| 89 | + outStation(gps, prev); | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + | |
| 93 | + int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); | |
| 94 | + //首班出场最多提前3小时 | |
| 95 | + if (dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) | |
| 96 | + return; | |
| 97 | + | |
| 98 | + gps.setPremiseCode(null);//清除前置围栏标记 | |
| 99 | + | |
| 100 | + if (StringUtils.isNotEmpty(sch.getFcsjActual()) | |
| 101 | + && !outManyFit(gps, sch)) { | |
| 102 | + return;//班次已经实发 | |
| 103 | + } | |
| 104 | + | |
| 105 | + //应用到离站缓冲区设置参数 | |
| 106 | + long rsT = lineConfigData.applyOut(sch, gps.getTimestamp()); | |
| 107 | + //实发时间 | |
| 108 | + sch.setFcsjActualAll(rsT); | |
| 109 | + sch.setSiginCompate(1); | |
| 110 | + | |
| 111 | + //出站既出场 | |
| 112 | + outStationAndOutPark(sch); | |
| 113 | + | |
| 114 | + //webSocket | |
| 115 | + sendUtils.sendFcsj(sch); | |
| 116 | + | |
| 117 | + //持久化 | |
| 118 | + dayOfSchedule.save(sch); | |
| 119 | + | |
| 120 | + //清理应发未发标记 | |
| 121 | + LateAdjustHandle.remove(sch); | |
| 122 | + | |
| 123 | + //发车的时候,同步一下状态 | |
| 124 | + /*if (!gps.isService() && !dayOfSchedule.emptyService(sch)) | |
| 125 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统"); | |
| 126 | +*/ | |
| 127 | + logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); | |
| 128 | + } | |
| 129 | + | |
| 130 | + GpsCacheData.out(gps); | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * 是否是一个更合适的发车信号 | |
| 135 | + * | |
| 136 | + * @param gps | |
| 137 | + * @param sch | |
| 138 | + * @return | |
| 139 | + */ | |
| 140 | + private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) { | |
| 141 | + LineConfig conf = lineConfigData.get(sch.getXlBm()); | |
| 142 | + if (null != conf && conf.isLockFirstOutTime()) | |
| 143 | + return false; | |
| 144 | + | |
| 145 | + if (StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 146 | + return false; | |
| 147 | + | |
| 148 | + long t1 = sch.getFcsjActualTime(); | |
| 149 | + long t2 = gps.getTimestamp(); | |
| 150 | + long c = sch.getDfsjT(); | |
| 151 | + | |
| 152 | + int threshold = 1000 * 60 * 5; | |
| 153 | + if (Math.abs(t2 - c) < threshold && c - t1 > threshold) { | |
| 154 | + return true; | |
| 155 | + } | |
| 156 | + | |
| 157 | + if (c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1) { | |
| 158 | + return true; | |
| 159 | + } | |
| 160 | + return false; | |
| 161 | + } | |
| 162 | + | |
| 163 | + private void outStationAndOutPark(ScheduleRealInfo sch) { | |
| 164 | + try { | |
| 165 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 166 | + //限定出站既出场的停车场 | |
| 167 | + List<String> parks = config.findTwinsParkList(); | |
| 168 | + boolean limitPark = null != parks && parks.size() > 0; | |
| 169 | + | |
| 170 | + if (config != null && config.getOutConfig() == 2) { | |
| 171 | + //出站既出场 | |
| 172 | + ScheduleRealInfo schPrev = dayOfSchedule.prev(sch); | |
| 173 | + if (isOut(schPrev) && isEmptyMileage(schPrev) | |
| 174 | + && (!limitPark || parks.contains(schPrev.getQdzCode()))) { | |
| 175 | + | |
| 176 | + endSch(schPrev, sch.getFcsjActualTime()); | |
| 177 | + | |
| 178 | + //起点实到 | |
| 179 | + sch.setQdzArrDatesj(schPrev.getZdsjActual()); | |
| 180 | + | |
| 181 | + sendUtils.refreshSch(schPrev); | |
| 182 | + dayOfSchedule.save(schPrev); | |
| 183 | + } | |
| 184 | + } | |
| 185 | + } catch (Exception e) { | |
| 186 | + logger.error("", e); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + | |
| 190 | + private boolean isEmptyMileage(ScheduleRealInfo sch) { | |
| 191 | + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0; | |
| 192 | + } | |
| 193 | + | |
| 194 | + private boolean isOut(ScheduleRealInfo sch) { | |
| 195 | + return sch != null && sch.getBcType().equals("out"); | |
| 196 | + } | |
| 197 | + | |
| 198 | + private void endSch(ScheduleRealInfo sch, Long t) { | |
| 199 | + sch.setFcsjActualAll(t); | |
| 200 | + sch.setZdsjActualAll(t); | |
| 201 | + } | |
| 202 | + | |
| 203 | + private boolean isOutPark(GpsEntity gps, GpsEntity prve) { | |
| 204 | + if (StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo())) | |
| 205 | + return true; | |
| 206 | + return false; | |
| 207 | + } | |
| 206 | 208 | } |
| 207 | 209 | \ No newline at end of file | ... | ... |