Commit 469daeb56ca815004720338e4003568c97f70d16
1 parent
56c50c1c
update...
Showing
1 changed file
with
55 additions
and
41 deletions
src/main/java/com/bsth/data/schedule/late_adjust/LateAdjustHandle.java
| @@ -22,12 +22,12 @@ import java.util.List; | @@ -22,12 +22,12 @@ import java.util.List; | ||
| 22 | 22 | ||
| 23 | /** | 23 | /** |
| 24 | * 误点自动调整待发 处理程序 | 24 | * 误点自动调整待发 处理程序 |
| 25 | - * | 25 | + * <p> |
| 26 | * 注意 :这里的误点是指应发未到 | 26 | * 注意 :这里的误点是指应发未到 |
| 27 | * Created by panzhao on 2017/4/16. | 27 | * Created by panzhao on 2017/4/16. |
| 28 | */ | 28 | */ |
| 29 | @Component | 29 | @Component |
| 30 | -public class LateAdjustHandle implements ApplicationContextAware{ | 30 | +public class LateAdjustHandle implements ApplicationContextAware { |
| 31 | 31 | ||
| 32 | static LineConfigData lineConfigData; | 32 | static LineConfigData lineConfigData; |
| 33 | static SendUtils sendUtils; | 33 | static SendUtils sendUtils; |
| @@ -36,7 +36,7 @@ public class LateAdjustHandle implements ApplicationContextAware{ | @@ -36,7 +36,7 @@ public class LateAdjustHandle implements ApplicationContextAware{ | ||
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | * 应发未到车辆 和 班次 | 38 | * 应发未到车辆 和 班次 |
| 39 | - * | 39 | + * <p> |
| 40 | * 起点相同的,保留最后一个班次 | 40 | * 起点相同的,保留最后一个班次 |
| 41 | */ | 41 | */ |
| 42 | private static ArrayListMultimap lateSchMaps; | 42 | private static ArrayListMultimap lateSchMaps; |
| @@ -48,55 +48,57 @@ public class LateAdjustHandle implements ApplicationContextAware{ | @@ -48,55 +48,57 @@ public class LateAdjustHandle implements ApplicationContextAware{ | ||
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | * 新增一个误点班次 | 50 | * 新增一个误点班次 |
| 51 | + * | ||
| 51 | * @param sch | 52 | * @param sch |
| 52 | */ | 53 | */ |
| 53 | - public static void putLate(ScheduleRealInfo sch){ | ||
| 54 | - try{ | 54 | + public static void putLate(ScheduleRealInfo sch) { |
| 55 | + try { | ||
| 55 | //线路配置 | 56 | //线路配置 |
| 56 | LineConfig config = lineConfigData.get(sch.getXlBm()); | 57 | LineConfig config = lineConfigData.get(sch.getXlBm()); |
| 57 | - if(sch.getLateMinute() == 0){ | ||
| 58 | - if(!config.isEnableYjtk()) | 58 | + if (sch.getLateMinute() == 0) { |
| 59 | + if (!config.isEnableYjtk()) | ||
| 59 | return; | 60 | return; |
| 60 | 61 | ||
| 61 | - sch.setLateMinute(sch.getXlDir().equals("0")?config.getUpStopMinute():config.getDownStopMinute()); | 62 | + sch.setLateMinute(sch.getXlDir().equals("0") ? config.getUpStopMinute() : config.getDownStopMinute()); |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | - if(sch.getDfsj().compareTo(config.getYjtkStart()) > 0 | ||
| 65 | - && sch.getDfsj().compareTo(config.getYjtkEnd()) <= 0){ | 65 | + if (sch.getDfsj().compareTo(config.getYjtkStart()) > 0 |
| 66 | + && sch.getDfsj().compareTo(config.getYjtkEnd()) <= 0) { | ||
| 66 | 67 | ||
| 67 | ScheduleRealInfo old = popLateSch(sch); | 68 | ScheduleRealInfo old = popLateSch(sch); |
| 68 | 69 | ||
| 69 | //班次被压入 | 70 | //班次被压入 |
| 70 | - if(lateSchMaps.containsEntry(sch.getClZbh(), sch)){ | 71 | + if (lateSchMaps.containsEntry(sch.getClZbh(), sch)) { |
| 71 | 72 | ||
| 72 | - logger.info("【应发未到 -多个("+lateSchMaps.get(sch.getClZbh()).size()+")】班次 " + sch.getClZbh() + " -" + sch.getDfsj() + " -id: " + sch.getId() + " -加入误点调整!"); | 73 | + logger.info("【应发未到 -多个(" + lateSchMaps.get(sch.getClZbh()).size() + ")】班次 " + sch.getClZbh() + " -" + sch.getDfsj() + " -id: " + sch.getId() + " -加入误点调整!"); |
| 73 | //通知客户端 | 74 | //通知客户端 |
| 74 | sch.setLate2(true); | 75 | sch.setLate2(true); |
| 75 | sendUtils.sendAutoWdtz(sch, old); | 76 | sendUtils.sendAutoWdtz(sch, old); |
| 76 | } | 77 | } |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | - }catch (Exception e){ | 80 | + } catch (Exception e) { |
| 80 | logger.error("", e); | 81 | logger.error("", e); |
| 81 | } | 82 | } |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | /** | 85 | /** |
| 85 | * 压入新的误点班次 | 86 | * 压入新的误点班次 |
| 87 | + * | ||
| 86 | * @param sch | 88 | * @param sch |
| 87 | * @return 返回被移除的误点班次 | 89 | * @return 返回被移除的误点班次 |
| 88 | */ | 90 | */ |
| 89 | private static ScheduleRealInfo popLateSch(ScheduleRealInfo sch) { | 91 | private static ScheduleRealInfo popLateSch(ScheduleRealInfo sch) { |
| 90 | List<ScheduleRealInfo> list = lateSchMaps.get(sch.getClZbh()); | 92 | List<ScheduleRealInfo> list = lateSchMaps.get(sch.getClZbh()); |
| 91 | 93 | ||
| 92 | - if(null == list || list.size() == 0) | 94 | + if (null == list || list.size() == 0) |
| 93 | lateSchMaps.put(sch.getClZbh(), sch); | 95 | lateSchMaps.put(sch.getClZbh(), sch); |
| 94 | else { | 96 | else { |
| 95 | - ScheduleRealInfo old = findExistQdz(list, sch.getQdzCode(), sch.getQdzName()); | 97 | + ScheduleRealInfo old = findExistQdz(list, sch.getQdzCode(), sch.getQdzName(), ""); |
| 96 | 98 | ||
| 97 | - if(null == old) | 99 | + if (null == old) |
| 98 | lateSchMaps.put(sch.getClZbh(), sch); | 100 | lateSchMaps.put(sch.getClZbh(), sch); |
| 99 | - else if(old.getDfsjT() < sch.getDfsjT()){ | 101 | + else if (old.getDfsjT() < sch.getDfsjT()) { |
| 100 | //同一个起点,保留时间最大的班次 | 102 | //同一个起点,保留时间最大的班次 |
| 101 | lateSchMaps.remove(old.getClZbh(), old); | 103 | lateSchMaps.remove(old.getClZbh(), old); |
| 102 | lateSchMaps.put(sch.getClZbh(), sch); | 104 | lateSchMaps.put(sch.getClZbh(), sch); |
| @@ -111,13 +113,15 @@ public class LateAdjustHandle implements ApplicationContextAware{ | @@ -111,13 +113,15 @@ public class LateAdjustHandle implements ApplicationContextAware{ | ||
| 111 | 113 | ||
| 112 | /** | 114 | /** |
| 113 | * 搜索同样起点的班次 | 115 | * 搜索同样起点的班次 |
| 116 | + * | ||
| 114 | * @param list | 117 | * @param list |
| 115 | * @return | 118 | * @return |
| 116 | */ | 119 | */ |
| 117 | - private static ScheduleRealInfo findExistQdz(List<ScheduleRealInfo> list, String qdzCode, String qdzName) { | ||
| 118 | - for(ScheduleRealInfo item : list){ | ||
| 119 | - if(item.getQdzCode().equals(qdzCode) | ||
| 120 | - || item.getQdzName().equals(qdzName)) | 120 | + private static ScheduleRealInfo findExistQdz(List<ScheduleRealInfo> list, String qdzCode, String nam1, String name2) { |
| 121 | + for (ScheduleRealInfo item : list) { | ||
| 122 | + if (item.getQdzCode().equals(qdzCode) | ||
| 123 | + || item.getQdzName().equals(nam1) | ||
| 124 | + || item.getQdzName().equals(name2)) | ||
| 121 | return item; | 125 | return item; |
| 122 | } | 126 | } |
| 123 | return null; | 127 | return null; |
| @@ -126,15 +130,16 @@ public class LateAdjustHandle implements ApplicationContextAware{ | @@ -126,15 +130,16 @@ public class LateAdjustHandle implements ApplicationContextAware{ | ||
| 126 | 130 | ||
| 127 | /** | 131 | /** |
| 128 | * 获取所有应发未到的班次 | 132 | * 获取所有应发未到的班次 |
| 133 | + * | ||
| 129 | * @return | 134 | * @return |
| 130 | */ | 135 | */ |
| 131 | - public static Collection<ScheduleRealInfo> allLateSch(){ | 136 | + public static Collection<ScheduleRealInfo> allLateSch() { |
| 132 | return lateSchMaps.values(); | 137 | return lateSchMaps.values(); |
| 133 | } | 138 | } |
| 134 | 139 | ||
| 135 | - public static void remove(ScheduleRealInfo sch){ | 140 | + public static void remove(ScheduleRealInfo sch) { |
| 136 | try { | 141 | try { |
| 137 | - if(lateSchMaps.containsEntry(sch.getClZbh(), sch)){ | 142 | + if (lateSchMaps.containsEntry(sch.getClZbh(), sch)) { |
| 138 | lateSchMaps.remove(sch.getClZbh(), sch); | 143 | lateSchMaps.remove(sch.getClZbh(), sch); |
| 139 | 144 | ||
| 140 | sch.setLate2(false); | 145 | sch.setLate2(false); |
| @@ -143,46 +148,55 @@ public class LateAdjustHandle implements ApplicationContextAware{ | @@ -143,46 +148,55 @@ public class LateAdjustHandle implements ApplicationContextAware{ | ||
| 143 | 148 | ||
| 144 | logger.info("移除误点调整 -" + sch.getClZbh() + " -time: " + sch.getDfsj() + " -id: " + sch.getId()); | 149 | logger.info("移除误点调整 -" + sch.getClZbh() + " -time: " + sch.getDfsj() + " -id: " + sch.getId()); |
| 145 | } | 150 | } |
| 146 | - }catch (Exception e){ | 151 | + } catch (Exception e) { |
| 147 | logger.error("", e); | 152 | logger.error("", e); |
| 148 | } | 153 | } |
| 149 | } | 154 | } |
| 150 | 155 | ||
| 151 | /** | 156 | /** |
| 152 | * 车辆到站 | 157 | * 车辆到站 |
| 158 | + * | ||
| 153 | * @param gps | 159 | * @param gps |
| 154 | */ | 160 | */ |
| 155 | - public static void carArrive(GpsEntity gps){ | ||
| 156 | - try{ | 161 | + public static void carArrive(GpsEntity gps) { |
| 162 | + try { | ||
| 163 | + if (gps.getInstation() <= 0) { | ||
| 164 | + return; | ||
| 165 | + } | ||
| 166 | + | ||
| 157 | List<ScheduleRealInfo> list = lateSchMaps.get(gps.getNbbm()); | 167 | List<ScheduleRealInfo> list = lateSchMaps.get(gps.getNbbm()); |
| 158 | 168 | ||
| 159 | - if(null == list || list.size() == 0) | 169 | + if (null == list || list.size() == 0) |
| 160 | return; | 170 | return; |
| 161 | 171 | ||
| 162 | - String key = gps.getStopNo(); | ||
| 163 | - if(gps.getInstation()>0){ | ||
| 164 | - if(StringUtils.isNotEmpty(gps.getCarparkNo())) | ||
| 165 | - key = gps.getCarparkNo();//停车场名称 | ||
| 166 | - else | ||
| 167 | - key = gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo();//站点名称 | 172 | + |
| 173 | + String key = gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo() | ||
| 174 | + , name1 = BasicData.stationCode2NameMap.get(key)//站点名称 | ||
| 175 | + , name2 = null; | ||
| 176 | + if (StringUtils.isNotEmpty(gps.getCarparkNo())) { | ||
| 177 | + name2 = BasicData.stationCode2NameMap.get(gps.getCarparkNo()); | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + if (gps.getInstation() == 2) { | ||
| 181 | + name1 = name2;//进场,没有站 | ||
| 168 | } | 182 | } |
| 169 | 183 | ||
| 170 | - gps.setStationName(BasicData.stationCode2NameMap.get(key)); | 184 | + gps.setStationName(name1); |
| 171 | //根据起点站获取误点班次 | 185 | //根据起点站获取误点班次 |
| 172 | - ScheduleRealInfo sch = findExistQdz(list, gps.getStopNo(), gps.getStationName()); | 186 | + ScheduleRealInfo sch = findExistQdz(list, gps.getStopNo(), name1, name2); |
| 173 | 187 | ||
| 174 | - if(null == sch) | 188 | + if (null == sch) |
| 175 | return; | 189 | return; |
| 176 | 190 | ||
| 177 | //可能是延迟信号,gps时间没有误点 | 191 | //可能是延迟信号,gps时间没有误点 |
| 178 | - if(gps.getTimestamp() <= sch.getDfsjT()){ | 192 | + if (gps.getTimestamp() <= sch.getDfsjT()) { |
| 179 | sch.setLate2(false); | 193 | sch.setLate2(false); |
| 180 | lateSchMaps.remove(sch.getClZbh(), sch); | 194 | lateSchMaps.remove(sch.getClZbh(), sch); |
| 181 | return; | 195 | return; |
| 182 | } | 196 | } |
| 183 | 197 | ||
| 184 | - if(gps.getStationName().equals(sch.getQdzName()) | ||
| 185 | - || gps.getStopNo().equals(sch.getQdzCode())){ | 198 | + if (gps.getStationName().equals(sch.getQdzName()) |
| 199 | + || gps.getStopNo().equals(sch.getQdzCode())) { | ||
| 186 | 200 | ||
| 187 | //自动调整待发 到达时间 + 停靠时间 | 201 | //自动调整待发 到达时间 + 停靠时间 |
| 188 | long dt = Arith.addLong(gps.getTimestamp(), (sch.getLateMinute() * 60 * 1000)); | 202 | long dt = Arith.addLong(gps.getTimestamp(), (sch.getLateMinute() * 60 * 1000)); |
| @@ -195,7 +209,7 @@ public class LateAdjustHandle implements ApplicationContextAware{ | @@ -195,7 +209,7 @@ public class LateAdjustHandle implements ApplicationContextAware{ | ||
| 195 | lateSchMaps.remove(sch.getClZbh(), sch); | 209 | lateSchMaps.remove(sch.getClZbh(), sch); |
| 196 | logger.info("【应发未到】车辆到站 " + sch.getClZbh() + " -" + sch.getDfsj() + " -到站时间:" + gps.getTimestamp() + " -停靠时间:" + sch.getLateMinute() + " -自动设置的待发时间:" + dt); | 210 | logger.info("【应发未到】车辆到站 " + sch.getClZbh() + " -" + sch.getDfsj() + " -到站时间:" + gps.getTimestamp() + " -停靠时间:" + sch.getLateMinute() + " -自动设置的待发时间:" + dt); |
| 197 | } | 211 | } |
| 198 | - }catch (Exception e){ | 212 | + } catch (Exception e) { |
| 199 | e.printStackTrace(); | 213 | e.printStackTrace(); |
| 200 | logger.error("late2 car arrive", e); | 214 | logger.error("late2 car arrive", e); |
| 201 | } | 215 | } |