Commit cda28e3c2bc578fb9092446eb96891a3d984b9fc
1 parent
1fd0435d
匹配班次的程序加了点逻辑,,
Showing
1 changed file
with
55 additions
and
0 deletions
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
| @@ -198,6 +198,7 @@ public class SchAttrCalculator { | @@ -198,6 +198,7 @@ public class SchAttrCalculator { | ||
| 198 | public ScheduleRealInfo calcCurrentExecSch(List<ScheduleRealInfo> list){ | 198 | public ScheduleRealInfo calcCurrentExecSch(List<ScheduleRealInfo> list){ |
| 199 | String lineCode = list.get(0).getXlBm(); | 199 | String lineCode = list.get(0).getXlBm(); |
| 200 | LineConfig conf = lineConfigData.get(lineCode); | 200 | LineConfig conf = lineConfigData.get(lineCode); |
| 201 | + long t = System.currentTimeMillis(); | ||
| 201 | int outConfig = -1; | 202 | int outConfig = -1; |
| 202 | //限定出站既出场的停车场 | 203 | //限定出站既出场的停车场 |
| 203 | String park = null; | 204 | String park = null; |
| @@ -221,8 +222,62 @@ public class SchAttrCalculator { | @@ -221,8 +222,62 @@ public class SchAttrCalculator { | ||
| 221 | if(StringUtils.isNotEmpty(sch.getZdsjActual())) | 222 | if(StringUtils.isNotEmpty(sch.getZdsjActual())) |
| 222 | continue; | 223 | continue; |
| 223 | 224 | ||
| 225 | + if(Math.abs((t - sch.getDfsjT())) > 1000 * 60 * 60){ | ||
| 226 | + //差值较大,倒着找看有没有更合适的 | ||
| 227 | + ScheduleRealInfo schReverse = calcCurrentExecSchReverse(list, outConfig, limitPark, park); | ||
| 228 | + if(null != schReverse && !schReverse.getId().equals(sch.getId())){ | ||
| 229 | + logger.info("calc_current_exec_sch_reverse... -" + schReverse.getId()); | ||
| 230 | + return suitableExecSch(schReverse, sch, t); | ||
| 231 | + } | ||
| 232 | + } | ||
| 224 | return sch; | 233 | return sch; |
| 225 | } | 234 | } |
| 226 | return null; | 235 | return null; |
| 227 | } | 236 | } |
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * 反转匹配一个班次 | ||
| 240 | + * @param list | ||
| 241 | + * @param outConfig | ||
| 242 | + * @param limitPark | ||
| 243 | + * @param park | ||
| 244 | + * @return | ||
| 245 | + */ | ||
| 246 | + private ScheduleRealInfo calcCurrentExecSchReverse(List<ScheduleRealInfo> list, int outConfig, boolean limitPark, String park){ | ||
| 247 | + ScheduleRealInfo near = null; | ||
| 248 | + for(ScheduleRealInfo sch : list){ | ||
| 249 | + //如果是出站既出场,忽略出场班次 | ||
| 250 | + if(outConfig == 2 && isInout(sch) | ||
| 251 | + && (!limitPark || park.equals(sch.getQdzCode()) || park.equals(sch.getZdzCode()))) | ||
| 252 | + continue; | ||
| 253 | + | ||
| 254 | + //忽略烂班 | ||
| 255 | + if(sch.isDestroy()) | ||
| 256 | + continue; | ||
| 257 | + | ||
| 258 | + if(StringUtils.isNotEmpty(sch.getZdsjActual())){ | ||
| 259 | + near = null; | ||
| 260 | + continue; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + if(null == near) | ||
| 264 | + near = sch; | ||
| 265 | + } | ||
| 266 | + return near; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + /** | ||
| 270 | + * 比较2个班次,谁是指定时间更合适执行的 | ||
| 271 | + * @param schReverse | ||
| 272 | + * @param sch | ||
| 273 | + * @param t | ||
| 274 | + * @return | ||
| 275 | + */ | ||
| 276 | + private ScheduleRealInfo suitableExecSch(ScheduleRealInfo schReverse, ScheduleRealInfo sch, long t){ | ||
| 277 | + return Math.abs(t - schReverse.getDfsjT()) > Math.abs(t - sch.getDfsjT())?sch: schReverse; | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + private boolean isInout(ScheduleRealInfo sch){ | ||
| 281 | + return sch.getBcType().equals("out") || sch.getBcType().equals("in"); | ||
| 282 | + } | ||
| 228 | } | 283 | } |