Commit a1cbd9570c551d8e229d0bb7f7c48d681f21ac9f
1 parent
5c6ff814
update...
Showing
7 changed files
with
329 additions
and
293 deletions
src/main/java/com/bsth/data/schedule/SchAttrCalculator.java
| ... | ... | @@ -17,273 +17,290 @@ import java.util.Collections; |
| 17 | 17 | import java.util.List; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * | |
| 20 | + * @author PanZhao | |
| 21 | 21 | * @ClassName: SchAttrCalculator |
| 22 | 22 | * @Description: TODO(班次相关属性计算器) |
| 23 | - * @author PanZhao | |
| 24 | 23 | * @date 2016年8月15日 下午4:40:26 |
| 25 | - * | |
| 26 | 24 | */ |
| 27 | 25 | @Component |
| 28 | 26 | public class SchAttrCalculator { |
| 29 | 27 | |
| 30 | - @Autowired | |
| 31 | - LineConfigData lineConfigData; | |
| 32 | - | |
| 33 | - private final static long DAY_TIME = 1000 * 60 * 60 * 24L; | |
| 34 | - | |
| 35 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 36 | - | |
| 37 | - private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd") | |
| 38 | - ,fmtHHmm = DateTimeFormat.forPattern("HH:mm") | |
| 39 | - ,fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"); | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * @Title: calcRealDate | |
| 43 | - * @Description: TODO(计算班次的真实执行日期) | |
| 44 | - */ | |
| 45 | - public SchAttrCalculator calcRealDate(ScheduleRealInfo sch) { | |
| 46 | - LineConfig conf = lineConfigData.get(sch.getXlBm()); | |
| 47 | - | |
| 48 | - try { | |
| 49 | - if (null == sch.getFcsjT()) | |
| 50 | - calcFcsjTime(sch); | |
| 51 | - | |
| 52 | - //计发時間 | |
| 53 | - if(sch.getFcsj().compareTo(conf.getStartOpt()) < 0){ | |
| 54 | - sch.setFcsjAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr()+sch.getFcsj()) + DAY_TIME); | |
| 55 | - } | |
| 56 | - | |
| 57 | - //待发時間 | |
| 58 | - if(sch.getDfsj().compareTo(conf.getStartOpt()) < 0){ | |
| 59 | - sch.setDfsjAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr()+sch.getDfsj()) + DAY_TIME); | |
| 60 | - } | |
| 61 | - else | |
| 62 | - sch.setDfsjAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr()+sch.getDfsj())); | |
| 63 | - | |
| 64 | - //实发時間 | |
| 65 | - if(StringUtils.isNotEmpty(sch.getFcsjActual()) && | |
| 66 | - sch.getFcsjActual().compareTo(conf.getStartOpt()) < 0){ | |
| 67 | - sch.setFcsjActualAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr()+sch.getFcsjActual()) + DAY_TIME); | |
| 68 | - } | |
| 69 | - | |
| 70 | - //实际终点時間 | |
| 71 | - if(StringUtils.isNotEmpty(sch.getZdsjActual()) && | |
| 72 | - sch.getZdsjActual().compareTo(conf.getStartOpt()) < 0){ | |
| 73 | - sch.setZdsjActualAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr()+sch.getZdsjActual()) + DAY_TIME); | |
| 74 | - } | |
| 75 | - | |
| 76 | - sch.setRealExecDate(fmtyyyyMMdd.print(sch.getFcsjT())); | |
| 77 | - } catch (Exception e) { | |
| 78 | - logger.error("", e); | |
| 79 | - } | |
| 80 | - return this; | |
| 81 | - } | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * | |
| 85 | - * @Title: calcAllTimeByFcsj | |
| 86 | - * @Description: TODO(根据发车时间字符串计算 (计发时间,终点时间,待发时间)) | |
| 87 | - */ | |
| 88 | - public SchAttrCalculator calcAllTimeByFcsj(ScheduleRealInfo sch) { | |
| 89 | - try { | |
| 90 | - // 生成时间戳 | |
| 91 | - calcTimestamp(sch); | |
| 92 | - | |
| 93 | - // 计划终点时间 | |
| 94 | - if (sch.getBcsj() != null) { | |
| 95 | - sch.setZdsjT(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000)); | |
| 96 | - sch.setZdsj(fmtHHmm.print(sch.getZdsjT())); | |
| 97 | - } | |
| 98 | - } catch (ParseException e) { | |
| 99 | - logger.error("", e); | |
| 100 | - } | |
| 101 | - return this; | |
| 102 | - } | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * | |
| 106 | - * @Title: calcQdzTimePlan | |
| 107 | - * @Description: TODO(计算班次的起点应到时间) | |
| 108 | - */ | |
| 109 | - public void calcQdzTimePlan(List<ScheduleRealInfo> list){ | |
| 110 | - Collections.sort(list, new ScheduleComparator.FCSJ()); | |
| 111 | - | |
| 112 | - int len = list.size(); | |
| 113 | - if(len == 0) | |
| 114 | - return; | |
| 115 | - | |
| 116 | - ScheduleRealInfo prve = list.get(0), curr; | |
| 117 | - for(int i = 1; i < len; i ++){ | |
| 118 | - curr = list.get(i); | |
| 119 | - | |
| 120 | - if(isJoin(prve, curr)){ | |
| 121 | - curr.setQdzArrDatejh(prve.getZdsj()); | |
| 122 | - if(StringUtils.isNotEmpty(prve.getZdsjActual())) | |
| 123 | - curr.setQdzArrDatesj(prve.getZdsjActual()); | |
| 124 | - } | |
| 125 | - prve = curr; | |
| 126 | - } | |
| 127 | - } | |
| 128 | - | |
| 129 | - private boolean isJoin(ScheduleRealInfo prve, ScheduleRealInfo curr) { | |
| 130 | - return prve.getZdzName().equals(curr.getQdzName())//名称相等 | |
| 131 | - || prve.getZdzCode().equals(curr.getQdzCode())//编码相等 | |
| 132 | - || prve.getZdzName().startsWith(curr.getQdzName())//起始包括 | |
| 133 | - || curr.getQdzName().startsWith(prve.getZdzName());//起始包括 | |
| 134 | - } | |
| 135 | - | |
| 136 | - /** | |
| 137 | - * | |
| 138 | - * @Title: updateQdzTimePlan | |
| 139 | - * @Description: TODO(更新班次的起点应到时间) 并返回被更新的班次 | |
| 140 | - */ | |
| 141 | - public List<ScheduleRealInfo> updateQdzTimePlan(List<ScheduleRealInfo> list){ | |
| 142 | - Collections.sort(list, new ScheduleComparator.FCSJ()); | |
| 143 | - | |
| 144 | - List<ScheduleRealInfo> updateList = new ArrayList<>(); | |
| 145 | - int len = list.size(); | |
| 146 | - if(len == 0) | |
| 147 | - return updateList; | |
| 148 | - | |
| 149 | - ScheduleRealInfo prve = list.get(0), curr; | |
| 150 | - for(int i = 1; i < len; i ++){ | |
| 151 | - curr = list.get(i); | |
| 152 | - | |
| 153 | - if(prve.getZdzName().equals(curr.getQdzName()) | |
| 154 | - || prve.getZdzCode().equals(curr.getQdzCode())){ | |
| 155 | - | |
| 156 | - if(curr.getQdzArrDatejh() != null && prve.getZdsj().equals(curr.getQdzArrDatejh())){ | |
| 157 | - prve = curr; | |
| 158 | - continue; | |
| 159 | - } | |
| 160 | - | |
| 161 | - curr.setQdzArrDatejh(prve.getZdsj()); | |
| 162 | - updateList.add(curr); | |
| 163 | - } | |
| 164 | - else{ | |
| 165 | - curr.setQdzArrDatejh(null); | |
| 166 | - updateList.add(curr); | |
| 167 | - } | |
| 168 | - prve = curr; | |
| 169 | - } | |
| 170 | - | |
| 171 | - return updateList; | |
| 172 | - } | |
| 173 | - | |
| 174 | - public SchAttrCalculator calcFcsjTime(ScheduleRealInfo sch) throws ParseException { | |
| 175 | - sch.setFcsjT(fmtyyyyMMddHHmm.parseMillis(sch.getRealExecDate() + sch.getFcsj())); | |
| 176 | - return this; | |
| 177 | - } | |
| 178 | - | |
| 179 | - public void calcTimestamp(ScheduleRealInfo sch) throws ParseException{ | |
| 180 | - //计发时间 | |
| 181 | - if(sch.getFcsjT() == null) | |
| 182 | - calcFcsjTime(sch); | |
| 183 | - | |
| 184 | - //待发时间 | |
| 185 | - if(sch.getDfsj() == null) | |
| 186 | - sch.setDfsjAll(sch.getFcsjT()); | |
| 187 | - if(sch.getDfsjT() == null) | |
| 188 | - sch.setDfsjAll(sch.getDfsj()); | |
| 189 | - | |
| 190 | - //实发时间戳 | |
| 191 | - if(sch.getFcsjActualTime() == null && sch.getFcsjActual() != null) | |
| 192 | - sch.setFcsjActualAll(sch.getFcsjActual()); | |
| 193 | - | |
| 194 | - //实达时间戳 | |
| 195 | - if(sch.getZdsjActualTime() == null && sch.getZdsjActual() != null) | |
| 196 | - sch.setZdsjActualAll(sch.getZdsjActual()); | |
| 197 | - } | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * 计算当前要执行的班次 | |
| 201 | - * @param list | |
| 202 | - * @return | |
| 203 | - */ | |
| 204 | - public ScheduleRealInfo calcCurrentExecSch(List<ScheduleRealInfo> list){ | |
| 205 | - String lineCode = list.get(0).getXlBm(); | |
| 206 | - LineConfig conf = lineConfigData.get(lineCode); | |
| 207 | - long t = System.currentTimeMillis(); | |
| 208 | - int outConfig = -1; | |
| 209 | - //限定出站既出场的停车场 | |
| 210 | - String park = null; | |
| 211 | - if(conf != null){ | |
| 212 | - outConfig = conf.getOutConfig(); | |
| 213 | - park = conf.getTwinsPark(); | |
| 214 | - } | |
| 215 | - boolean limitPark = StringUtils.isNotEmpty(park); | |
| 216 | - | |
| 217 | - for(ScheduleRealInfo sch : list){ | |
| 218 | - //如果是出站既出场,忽略出场班次 | |
| 219 | - if(outConfig == 2 && sch.getBcType().equals("out") | |
| 220 | - && (!limitPark || park.equals(sch.getQdzCode()))) | |
| 221 | - continue; | |
| 222 | - | |
| 223 | - //忽略烂班 | |
| 224 | - if(sch.isDestroy()) | |
| 225 | - continue; | |
| 226 | - | |
| 227 | - //已执行 | |
| 228 | - if(StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 229 | - continue; | |
| 230 | - | |
| 231 | - if(Math.abs((t - sch.getDfsjT())) > 1000 * 60 * 60){ | |
| 232 | - //差值较大,倒着找看有没有更合适的 | |
| 233 | - ScheduleRealInfo schReverse = calcCurrentExecSchReverse(list, outConfig, limitPark, park); | |
| 234 | - if(null != schReverse && !schReverse.getId().equals(sch.getId())){ | |
| 235 | - logger.info("calc_current_exec_sch_reverse... -" + schReverse.getId()); | |
| 236 | - return suitableExecSch(schReverse, sch, t); | |
| 237 | - } | |
| 238 | - } | |
| 239 | - return sch; | |
| 240 | - } | |
| 241 | - return null; | |
| 242 | - } | |
| 243 | - | |
| 244 | - /** | |
| 245 | - * 反转匹配一个班次 | |
| 246 | - * @param list | |
| 247 | - * @param outConfig | |
| 248 | - * @param limitPark | |
| 249 | - * @param park | |
| 250 | - * @return | |
| 251 | - */ | |
| 252 | - private ScheduleRealInfo calcCurrentExecSchReverse(List<ScheduleRealInfo> list, int outConfig, boolean limitPark, String park){ | |
| 253 | - ScheduleRealInfo near = null; | |
| 254 | - for(ScheduleRealInfo sch : list){ | |
| 255 | - //如果是出站既出场,忽略出场班次 | |
| 256 | - if(outConfig == 2 && isInout(sch) | |
| 257 | - && (!limitPark || park.equals(sch.getQdzCode()) || park.equals(sch.getZdzCode()))) | |
| 258 | - continue; | |
| 259 | - | |
| 260 | - //忽略烂班 | |
| 261 | - if(sch.isDestroy()) | |
| 262 | - continue; | |
| 263 | - | |
| 264 | - if(StringUtils.isNotEmpty(sch.getZdsjActual())){ | |
| 265 | - near = null; | |
| 266 | - continue; | |
| 267 | - } | |
| 268 | - | |
| 269 | - if(null == near) | |
| 270 | - near = sch; | |
| 271 | - } | |
| 272 | - return near; | |
| 273 | - } | |
| 274 | - | |
| 275 | - /** | |
| 276 | - * 比较2个班次,谁是指定时间更合适执行的 | |
| 277 | - * @param schReverse | |
| 278 | - * @param sch | |
| 279 | - * @param t | |
| 280 | - * @return | |
| 281 | - */ | |
| 282 | - private ScheduleRealInfo suitableExecSch(ScheduleRealInfo schReverse, ScheduleRealInfo sch, long t){ | |
| 283 | - return Math.abs(t - schReverse.getDfsjT()) > Math.abs(t - sch.getDfsjT())?sch: schReverse; | |
| 284 | - } | |
| 285 | - | |
| 286 | - private boolean isInout(ScheduleRealInfo sch){ | |
| 287 | - return sch.getBcType().equals("out") || sch.getBcType().equals("in"); | |
| 288 | - } | |
| 28 | + @Autowired | |
| 29 | + LineConfigData lineConfigData; | |
| 30 | + | |
| 31 | + private final static long DAY_TIME = 1000 * 60 * 60 * 24L; | |
| 32 | + | |
| 33 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 34 | + | |
| 35 | + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"), fmtHHmm = DateTimeFormat.forPattern("HH:mm"), fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"); | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @Title: calcRealDate | |
| 39 | + * @Description: TODO(计算班次的真实执行日期) | |
| 40 | + */ | |
| 41 | + public SchAttrCalculator calcRealDate(ScheduleRealInfo sch) { | |
| 42 | + LineConfig conf = lineConfigData.get(sch.getXlBm()); | |
| 43 | + | |
| 44 | + try { | |
| 45 | + if (null == sch.getFcsjT()) | |
| 46 | + calcFcsjTime(sch); | |
| 47 | + | |
| 48 | + String rq = sch.getScheduleDateStr(); | |
| 49 | + //计发時間 | |
| 50 | + sch.setFcsjAll(getTime(rq, sch.getFcsj(), conf)); | |
| 51 | + | |
| 52 | + //待发時間 | |
| 53 | + sch.setDfsjAll(getTime(rq, sch.getDfsj(), conf)); | |
| 54 | + /*if (sch.getDfsj().compareTo(conf.getStartOpt()) < 0) { | |
| 55 | + sch.setDfsjAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr() + sch.getDfsj()) + DAY_TIME); | |
| 56 | + } else | |
| 57 | + sch.setDfsjAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr() + sch.getDfsj()));*/ | |
| 58 | + | |
| 59 | + //实发時間 | |
| 60 | + sch.setFcsjActualAll(getTime(rq, sch.getFcsjActual(), conf)); | |
| 61 | + /*if (StringUtils.isNotEmpty(sch.getFcsjActual()) && | |
| 62 | + sch.getFcsjActual().compareTo(conf.getStartOpt()) < 0) { | |
| 63 | + sch.setFcsjActualAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr() + sch.getFcsjActual()) + DAY_TIME); | |
| 64 | + }*/ | |
| 65 | + | |
| 66 | + //实际终点時間 | |
| 67 | + sch.setZdsjActualAll(getTime(rq, sch.getZdsjActual(), conf)); | |
| 68 | + /*if (StringUtils.isNotEmpty(sch.getZdsjActual()) && | |
| 69 | + sch.getZdsjActual().compareTo(conf.getStartOpt()) < 0) { | |
| 70 | + sch.setZdsjActualAll(fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr() + sch.getZdsjActual()) + DAY_TIME); | |
| 71 | + }*/ | |
| 72 | + | |
| 73 | + sch.setRealExecDate(fmtyyyyMMdd.print(sch.getFcsjT())); | |
| 74 | + } catch (Exception e) { | |
| 75 | + logger.error("", e); | |
| 76 | + } | |
| 77 | + return this; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public Long getTime(String rq, String timeStr, LineConfig conf) { | |
| 81 | + long t = fmtyyyyMMddHHmm.parseMillis(rq + timeStr); | |
| 82 | + if (StringUtils.isNotEmpty(timeStr) | |
| 83 | + && timeStr.compareTo(conf.getStartOpt()) < 0) { | |
| 84 | + return t + DAY_TIME; | |
| 85 | + } | |
| 86 | + return t; | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * @Title: calcAllTimeByFcsj | |
| 91 | + * @Description: TODO(根据发车时间字符串计算 (计发时间,终点时间,待发时间)) | |
| 92 | + */ | |
| 93 | + public SchAttrCalculator calcAllTimeByFcsj(ScheduleRealInfo sch) { | |
| 94 | + try { | |
| 95 | + // 生成时间戳 | |
| 96 | + calcTimestamp(sch); | |
| 97 | + | |
| 98 | + // 计划终点时间 | |
| 99 | + if (sch.getBcsj() != null) { | |
| 100 | + sch.setZdsjT(sch.getDfsjT() + (sch.getBcsj() * 60 * 1000)); | |
| 101 | + sch.setZdsj(fmtHHmm.print(sch.getZdsjT())); | |
| 102 | + } | |
| 103 | + } catch (ParseException e) { | |
| 104 | + logger.error("", e); | |
| 105 | + } | |
| 106 | + return this; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * @Title: calcQdzTimePlan | |
| 111 | + * @Description: TODO(计算班次的起点应到时间) | |
| 112 | + */ | |
| 113 | + public void calcQdzTimePlan(List<ScheduleRealInfo> list) { | |
| 114 | + Collections.sort(list, new ScheduleComparator.FCSJ()); | |
| 115 | + | |
| 116 | + int len = list.size(); | |
| 117 | + if (len == 0) | |
| 118 | + return; | |
| 119 | + | |
| 120 | + ScheduleRealInfo prve = list.get(0), curr; | |
| 121 | + for (int i = 1; i < len; i++) { | |
| 122 | + curr = list.get(i); | |
| 123 | + | |
| 124 | + if (isJoin(prve, curr)) { | |
| 125 | + curr.setQdzArrDatejh(prve.getZdsj()); | |
| 126 | + if (StringUtils.isNotEmpty(prve.getZdsjActual())) | |
| 127 | + curr.setQdzArrDatesj(prve.getZdsjActual()); | |
| 128 | + } | |
| 129 | + prve = curr; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + private boolean isJoin(ScheduleRealInfo prve, ScheduleRealInfo curr) { | |
| 134 | + return prve.getZdzName().equals(curr.getQdzName())//名称相等 | |
| 135 | + || prve.getZdzCode().equals(curr.getQdzCode())//编码相等 | |
| 136 | + || prve.getZdzName().startsWith(curr.getQdzName())//起始包括 | |
| 137 | + || curr.getQdzName().startsWith(prve.getZdzName());//起始包括 | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * @Title: updateQdzTimePlan | |
| 142 | + * @Description: TODO(更新班次的起点应到时间) 并返回被更新的班次 | |
| 143 | + */ | |
| 144 | + public List<ScheduleRealInfo> updateQdzTimePlan(List<ScheduleRealInfo> list) { | |
| 145 | + Collections.sort(list, new ScheduleComparator.FCSJ()); | |
| 146 | + | |
| 147 | + List<ScheduleRealInfo> updateList = new ArrayList<>(); | |
| 148 | + int len = list.size(); | |
| 149 | + if (len == 0) | |
| 150 | + return updateList; | |
| 151 | + | |
| 152 | + ScheduleRealInfo prve = list.get(0), curr; | |
| 153 | + for (int i = 1; i < len; i++) { | |
| 154 | + curr = list.get(i); | |
| 155 | + | |
| 156 | + if (prve.getZdzName().equals(curr.getQdzName()) | |
| 157 | + || prve.getZdzCode().equals(curr.getQdzCode())) { | |
| 158 | + | |
| 159 | + if (curr.getQdzArrDatejh() != null && prve.getZdsj().equals(curr.getQdzArrDatejh())) { | |
| 160 | + prve = curr; | |
| 161 | + continue; | |
| 162 | + } | |
| 163 | + | |
| 164 | + curr.setQdzArrDatejh(prve.getZdsj()); | |
| 165 | + updateList.add(curr); | |
| 166 | + } else { | |
| 167 | + curr.setQdzArrDatejh(null); | |
| 168 | + updateList.add(curr); | |
| 169 | + } | |
| 170 | + prve = curr; | |
| 171 | + } | |
| 172 | + | |
| 173 | + return updateList; | |
| 174 | + } | |
| 175 | + | |
| 176 | + public SchAttrCalculator calcFcsjTime(ScheduleRealInfo sch) throws ParseException { | |
| 177 | + sch.setFcsjT(fmtyyyyMMddHHmm.parseMillis(sch.getRealExecDate() + sch.getFcsj())); | |
| 178 | + return this; | |
| 179 | + } | |
| 180 | + | |
| 181 | + public void calcTimestamp(ScheduleRealInfo sch) throws ParseException { | |
| 182 | + //计发时间 | |
| 183 | + if (sch.getFcsjT() == null) | |
| 184 | + calcFcsjTime(sch); | |
| 185 | + | |
| 186 | + //待发时间 | |
| 187 | + if (sch.getDfsj() == null) | |
| 188 | + sch.setDfsjAll(sch.getFcsjT()); | |
| 189 | + if (sch.getDfsjT() == null) | |
| 190 | + sch.setDfsjAll(sch.getDfsj()); | |
| 191 | + | |
| 192 | + //实发时间戳 | |
| 193 | + if (sch.getFcsjActualTime() == null && sch.getFcsjActual() != null) | |
| 194 | + sch.setFcsjActualAll(sch.getFcsjActual()); | |
| 195 | + | |
| 196 | + //实达时间戳 | |
| 197 | + if (sch.getZdsjActualTime() == null && sch.getZdsjActual() != null) | |
| 198 | + sch.setZdsjActualAll(sch.getZdsjActual()); | |
| 199 | + } | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * 计算当前要执行的班次 | |
| 203 | + * | |
| 204 | + * @param list | |
| 205 | + * @return | |
| 206 | + */ | |
| 207 | + public ScheduleRealInfo calcCurrentExecSch(List<ScheduleRealInfo> list) { | |
| 208 | + String lineCode = list.get(0).getXlBm(); | |
| 209 | + LineConfig conf = lineConfigData.get(lineCode); | |
| 210 | + long t = System.currentTimeMillis(); | |
| 211 | + int outConfig = -1; | |
| 212 | + //限定出站既出场的停车场 | |
| 213 | + String park = null; | |
| 214 | + if (conf != null) { | |
| 215 | + outConfig = conf.getOutConfig(); | |
| 216 | + park = conf.getTwinsPark(); | |
| 217 | + } | |
| 218 | + boolean limitPark = StringUtils.isNotEmpty(park); | |
| 219 | + | |
| 220 | + for (ScheduleRealInfo sch : list) { | |
| 221 | + //如果是出站既出场,忽略出场班次 | |
| 222 | + if (outConfig == 2 && sch.getBcType().equals("out") | |
| 223 | + && (!limitPark || park.equals(sch.getQdzCode()))) | |
| 224 | + continue; | |
| 225 | + | |
| 226 | + //忽略烂班 | |
| 227 | + if (sch.isDestroy()) | |
| 228 | + continue; | |
| 229 | + | |
| 230 | + //已执行 | |
| 231 | + if (StringUtils.isNotEmpty(sch.getZdsjActual())) | |
| 232 | + continue; | |
| 233 | + | |
| 234 | + if (Math.abs((t - sch.getDfsjT())) > 1000 * 60 * 60) { | |
| 235 | + //差值较大,倒着找看有没有更合适的 | |
| 236 | + ScheduleRealInfo schReverse = calcCurrentExecSchReverse(list, outConfig, limitPark, park); | |
| 237 | + if (null != schReverse && !schReverse.getId().equals(sch.getId())) { | |
| 238 | + logger.info("calc_current_exec_sch_reverse... -" + schReverse.getId()); | |
| 239 | + return suitableExecSch(schReverse, sch, t); | |
| 240 | + } | |
| 241 | + } | |
| 242 | + return sch; | |
| 243 | + } | |
| 244 | + return null; | |
| 245 | + } | |
| 246 | + | |
| 247 | + /** | |
| 248 | + * 反转匹配一个班次 | |
| 249 | + * | |
| 250 | + * @param list | |
| 251 | + * @param outConfig | |
| 252 | + * @param limitPark | |
| 253 | + * @param park | |
| 254 | + * @return | |
| 255 | + */ | |
| 256 | + private ScheduleRealInfo calcCurrentExecSchReverse(List<ScheduleRealInfo> list, int outConfig, boolean limitPark, String park) { | |
| 257 | + ScheduleRealInfo near = null; | |
| 258 | + for (ScheduleRealInfo sch : list) { | |
| 259 | + //如果是出站既出场,忽略出场班次 | |
| 260 | + if (outConfig == 2 && isInout(sch) | |
| 261 | + && (!limitPark || park.equals(sch.getQdzCode()) || park.equals(sch.getZdzCode()))) | |
| 262 | + continue; | |
| 263 | + | |
| 264 | + //忽略烂班 | |
| 265 | + if (sch.isDestroy()) | |
| 266 | + continue; | |
| 267 | + | |
| 268 | + if (StringUtils.isNotEmpty(sch.getZdsjActual())) { | |
| 269 | + near = null; | |
| 270 | + continue; | |
| 271 | + } | |
| 272 | + | |
| 273 | + if (null == near) | |
| 274 | + near = sch; | |
| 275 | + } | |
| 276 | + return near; | |
| 277 | + } | |
| 278 | + | |
| 279 | + /** | |
| 280 | + * 比较2个班次,谁是指定时间更合适执行的 | |
| 281 | + * | |
| 282 | + * @param schReverse | |
| 283 | + * @param sch | |
| 284 | + * @param t | |
| 285 | + * @return | |
| 286 | + */ | |
| 287 | + private ScheduleRealInfo suitableExecSch(ScheduleRealInfo schReverse, ScheduleRealInfo sch, long t) { | |
| 288 | + return Math.abs(t - schReverse.getDfsjT()) > Math.abs(t - sch.getDfsjT()) ? sch : schReverse; | |
| 289 | + } | |
| 290 | + | |
| 291 | + private boolean isInout(ScheduleRealInfo sch) { | |
| 292 | + return sch.getBcType().equals("out") || sch.getBcType().equals("in"); | |
| 293 | + } | |
| 294 | + | |
| 295 | + /** | |
| 296 | + * | |
| 297 | + * @param fcsjT | |
| 298 | + * @param zdsjT | |
| 299 | + */ | |
| 300 | + public boolean isValid(Long fcsjT, Long zdsjT) { | |
| 301 | + if(null != fcsjT && null != zdsjT) | |
| 302 | + return fcsjT < zdsjT; | |
| 303 | + | |
| 304 | + return true; | |
| 305 | + } | |
| 289 | 306 | } | ... | ... |
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
| ... | ... | @@ -259,7 +259,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | //调整班次类型 |
| 262 | - if (StringUtils.isNotEmpty(bcType)) { | |
| 262 | + if (StringUtils.isNotEmpty(bcType) && !bcType.equals(schedule.getBcType())) { | |
| 263 | + if((schedule.getBcType().equals("major") | |
| 264 | + || schedule.getBcType().equals("venting")) | |
| 265 | + && bcType.equals("normal")){ | |
| 266 | + //清空备注 | |
| 267 | + schedule.setRemarks(""); | |
| 268 | + } | |
| 263 | 269 | schedule.setBcType(bcType); |
| 264 | 270 | } |
| 265 | 271 | |
| ... | ... | @@ -1271,8 +1277,8 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1271 | 1277 | @Override |
| 1272 | 1278 | public Map<String, Object> spaceAdjust(Long[] ids, Integer space) { |
| 1273 | 1279 | |
| 1274 | - List<ScheduleRealInfo> list = new ArrayList<>(), updateList = new ArrayList<>(); | |
| 1275 | - Map<String, Object> rs = new HashMap<>(); | |
| 1280 | + List<ScheduleRealInfo> list = new ArrayList<>(), ts = new ArrayList<>(), tempTs = null; | |
| 1281 | + Map<String, Object> rs = new HashMap<>(), tempRs = new HashMap<>(); | |
| 1276 | 1282 | try { |
| 1277 | 1283 | ScheduleRealInfo sch, next; |
| 1278 | 1284 | for (Long id : ids) { |
| ... | ... | @@ -1297,12 +1303,17 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1297 | 1303 | sch = list.get(i); |
| 1298 | 1304 | |
| 1299 | 1305 | //调整待发 |
| 1300 | - outgoAdjust(sch.getId(), null, fmtHHmm.print(st), null, "3"); | |
| 1306 | + tempRs = outgoAdjust(sch.getId(), null, fmtHHmm.print(st), null, "3"); | |
| 1307 | + | |
| 1308 | + if(null != tempRs && tempRs.get("ts") != null) | |
| 1309 | + tempTs = (List<ScheduleRealInfo>) tempRs.get("ts"); | |
| 1310 | + | |
| 1311 | + ts.addAll(tempTs); | |
| 1301 | 1312 | } |
| 1302 | 1313 | |
| 1303 | 1314 | rs.put("status", ResponseCode.SUCCESS); |
| 1304 | 1315 | //返回最后一个班次,页面会全量刷新 |
| 1305 | - rs.put("t", sch); | |
| 1316 | + rs.put("ts", ts); | |
| 1306 | 1317 | } |
| 1307 | 1318 | |
| 1308 | 1319 | } catch (Exception e) { |
| ... | ... | @@ -1393,6 +1404,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1393 | 1404 | sch.setsName(""); |
| 1394 | 1405 | } |
| 1395 | 1406 | |
| 1407 | + LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 1396 | 1408 | /** |
| 1397 | 1409 | * 调整实发 |
| 1398 | 1410 | */ |
| ... | ... | @@ -1400,13 +1412,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1400 | 1412 | if (StringUtils.isNotBlank(fcsjActual) |
| 1401 | 1413 | && !fcsjActual.equals(sch.getFcsjActual())) { |
| 1402 | 1414 | |
| 1403 | - LineConfig config = lineConfigData.get(sch.getXlBm()); | |
| 1404 | - long t = 0L; | |
| 1415 | + //long t = 0L; | |
| 1405 | 1416 | //小于线路开始运营时间,则默认跨过24点 |
| 1406 | - if (fcsjActual.compareTo(config.getStartOpt()) < 0) | |
| 1417 | + long t = schAttrCalculator.getTime(sch.getScheduleDateStr(), fcsjActual, config); | |
| 1418 | + /* if (fcsjActual.compareTo(config.getStartOpt()) < 0) | |
| 1407 | 1419 | t = fmtyyyyMMddHHmm.parseMillis(fmtyyyyMMdd.print(sch.getScheduleDate().getTime() + DAY_TIME) + fcsjActual); |
| 1408 | 1420 | else |
| 1409 | - t = fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr() + fcsjActual); | |
| 1421 | + t = fmtyyyyMMddHHmm.parseMillis(sch.getScheduleDateStr() + fcsjActual);*/ | |
| 1410 | 1422 | |
| 1411 | 1423 | fLog.log("调整实发时间", sch.getFcsjActual(), fcsjActual); |
| 1412 | 1424 | sch.setFcsjActualAll(t); |
| ... | ... | @@ -1430,7 +1442,9 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1430 | 1442 | |
| 1431 | 1443 | //调整实达 |
| 1432 | 1444 | fLog.log("调整实达时间", sch.getZdsjActual(), zdsjActual); |
| 1433 | - sch.setZdsjActualAll(zdsjActual); | |
| 1445 | + | |
| 1446 | + long t = schAttrCalculator.getTime(sch.getScheduleDateStr(), zdsjActual, config); | |
| 1447 | + sch.setZdsjActualAll(t); | |
| 1434 | 1448 | //路牌下一班起点到达时间 |
| 1435 | 1449 | ScheduleRealInfo next = dayOfSchedule.nextByLp2(sch); |
| 1436 | 1450 | if (null != next) { |
| ... | ... | @@ -1439,15 +1453,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl<ScheduleRealInf |
| 1439 | 1453 | ts.add(next); |
| 1440 | 1454 | } |
| 1441 | 1455 | |
| 1442 | -/* try{ | |
| 1443 | - //车辆下一个要执行的班次 | |
| 1444 | - ScheduleRealInfo carNext = dayOfSchedule.next(sch); | |
| 1445 | - if(carNext != null && !carNext.getXlBm().equals(sch.getXlBm())){ | |
| 1446 | - DirectivePushQueue.put64(carNext.getClZbh(), carNext.getXlBm(), "套跑@系统"); | |
| 1447 | - fLog.log("下发线路切换指令", sch.getXlName(), carNext.getXlName()); | |
| 1448 | - } | |
| 1449 | - }catch (Exception e){logger.error("", e);}*/ | |
| 1450 | - | |
| 1451 | 1456 | //重新计算车辆执行班次 |
| 1452 | 1457 | dayOfSchedule.reCalcExecPlan(sch.getClZbh()); |
| 1453 | 1458 | } else if(StringUtils.isNotEmpty(sch.getZdsjActual()) && StringUtils.isEmpty(zdsjActual)){ | ... | ... |
src/main/resources/static/real_control_v2/css/main.css
| ... | ... | @@ -1663,4 +1663,9 @@ ul.left_tabs_lg li{ |
| 1663 | 1663 | |
| 1664 | 1664 | #schedule-tzrc-modal dl.active input[type=checkbox]:before{ |
| 1665 | 1665 | color: #ffffff; |
| 1666 | +} | |
| 1667 | + | |
| 1668 | +.sch-search-autocom input{ | |
| 1669 | + padding: 0 !important; | |
| 1670 | + height: 100% !important; | |
| 1666 | 1671 | } |
| 1667 | 1672 | \ No newline at end of file | ... | ... |
src/main/resources/static/real_control_v2/fragments/line_schedule/context_menu/bc_type_major.html
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | <div class="uk-form-row"> |
| 42 | 42 | <div class="uk-form-controls" style="margin-left: 0;"> |
| 43 | 43 | <label style="color: #827f7f;font-size: 13px;"> |
| 44 | - <input class="i-cbox" type="checkbox" name="sendDirective" checked> | |
| 44 | + <input class="i-cbox" type="checkbox" name="sendDirective" > | |
| 45 | 45 | 下发调度指令 |
| 46 | 46 | </label> |
| 47 | 47 | </div> |
| ... | ... | @@ -50,7 +50,7 @@ |
| 50 | 50 | </div> |
| 51 | 51 | <div class="uk-modal-footer uk-text-right" style="margin-bottom: -20px;"> |
| 52 | 52 | <button type="button" class="uk-button uk-modal-close">取消</button> |
| 53 | - <button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-send"></i> 确认调整并下发指令 | |
| 53 | + <button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-send"></i> 确认调整 | |
| 54 | 54 | </button> |
| 55 | 55 | </div> |
| 56 | 56 | </form> |
| ... | ... | @@ -183,7 +183,9 @@ |
| 183 | 183 | UIkit.modal(modal).hide(); |
| 184 | 184 | gb_schedule_table.updateSchedule(rs.t); |
| 185 | 185 | //触发父容器刷新事件 |
| 186 | - $(parentModal).trigger('init', {sch: rs.t}); | |
| 186 | + //$(parentModal).trigger('init', {sch: rs.t}); | |
| 187 | + //关闭 | |
| 188 | + UIkit.modal(parentModal).hide(); | |
| 187 | 189 | notify_succ('调整放站成功'); |
| 188 | 190 | }); |
| 189 | 191 | } | ... | ... |
src/main/resources/static/real_control_v2/fragments/line_schedule/context_menu/bc_type_venting.html
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | <div class="uk-form-row"> |
| 42 | 42 | <div class="uk-form-controls" style="margin-left: 0;"> |
| 43 | 43 | <label style="color: #827f7f;font-size: 13px;"> |
| 44 | - <input class="i-cbox" type="checkbox" name="sendDirective" checked> | |
| 44 | + <input class="i-cbox" type="checkbox" name="sendDirective" > | |
| 45 | 45 | 下发调度指令 |
| 46 | 46 | </label> |
| 47 | 47 | </div> |
| ... | ... | @@ -50,7 +50,7 @@ |
| 50 | 50 | </div> |
| 51 | 51 | <div class="uk-modal-footer uk-text-right" style="margin-bottom: -20px;"> |
| 52 | 52 | <button type="button" class="uk-button uk-modal-close">取消</button> |
| 53 | - <button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-send"></i> 确认调整并下发指令 | |
| 53 | + <button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-send"></i> 确认调整 | |
| 54 | 54 | </button> |
| 55 | 55 | </div> |
| 56 | 56 | </form> |
| ... | ... | @@ -180,7 +180,9 @@ |
| 180 | 180 | UIkit.modal(modal).hide(); |
| 181 | 181 | gb_schedule_table.updateSchedule(rs.t); |
| 182 | 182 | //触发父容器刷新事件 |
| 183 | - $(parentModal).trigger('init', {sch: rs.t}); | |
| 183 | + //$(parentModal).trigger('init', {sch: rs.t}); | |
| 184 | + //关闭 | |
| 185 | + UIkit.modal(parentModal).hide(); | |
| 184 | 186 | notify_succ('调整直发成功'); |
| 185 | 187 | }); |
| 186 | 188 | } | ... | ... |
src/main/resources/static/real_control_v2/fragments/line_schedule/context_menu/tzrc.html
| ... | ... | @@ -107,7 +107,7 @@ |
| 107 | 107 | <span class="uk-badge uk-badge-notification">{{sch.cTasks.length}}</span> |
| 108 | 108 | {{/if}} |
| 109 | 109 | </dd> |
| 110 | - <dd>{{sch.clZbh}}</dd> | |
| 110 | + <dd data-old="{{sch.clZbh}}">{{sch.clZbh}}</dd> | |
| 111 | 111 | <dd data-old="{{sch.jGh}}/{{sch.jName}}">{{sch.jGh}}/{{sch.jName}}</dd> |
| 112 | 112 | <dd data-old="{{sch.sGh}}/{{sch.sName}}">{{sch.sGh}}/{{sch.sName}}</dd> |
| 113 | 113 | <dd> |
| ... | ... | @@ -178,8 +178,10 @@ |
| 178 | 178 | //$(this).find('dd[data-old]').text() |
| 179 | 179 | var $jsyCell = $($($(this).find('dd')[2])); |
| 180 | 180 | var $spyCell = $($($(this).find('dd')[3])); |
| 181 | + var $clCell = $($($(this).find('dd')[1])); | |
| 181 | 182 | $jsyCell.text($jsyCell.data('old')); |
| 182 | 183 | $spyCell.text($spyCell.data('old')); |
| 184 | + $clCell.text($clCell.data('old')); | |
| 183 | 185 | } |
| 184 | 186 | }); |
| 185 | 187 | |
| ... | ... | @@ -247,7 +249,7 @@ |
| 247 | 249 | * 驾驶员/售票员文本框改变事件 |
| 248 | 250 | */ |
| 249 | 251 | var renderRunFlag; |
| 250 | - $('input[name=jsy],input[name=spy]', modal).on('input change', function () { | |
| 252 | + $('input[name=jsy],input[name=spy],input[name=clZbh]', modal).on('input change', function () { | |
| 251 | 253 | if(renderRunFlag) |
| 252 | 254 | return; |
| 253 | 255 | renderRunFlag = true; |
| ... | ... | @@ -262,11 +264,14 @@ |
| 262 | 264 | function renderCell() { |
| 263 | 265 | var jsy = $('input[name=jsy]', modal).val(); |
| 264 | 266 | var spy = $('input[name=spy]', modal).val(); |
| 267 | + var nbbm = $('input[name=clZbh]', modal).val(); | |
| 265 | 268 | $('.sch-tzrc-table .ct_table_body>dl.active').each(function () { |
| 266 | 269 | var jsyCell = $(this).find('dd')[2]; |
| 267 | 270 | var spyCell = $(this).find('dd')[3]; |
| 271 | + var clCell = $(this).find('dd')[1]; | |
| 268 | 272 | $(jsyCell).text(jsy); |
| 269 | 273 | $(spyCell).text(spy); |
| 274 | + $(clCell).text(nbbm); | |
| 270 | 275 | }); |
| 271 | 276 | } |
| 272 | 277 | ... | ... |
src/main/resources/static/real_control_v2/js/line_schedule/context_menu.js
| ... | ... | @@ -153,10 +153,10 @@ var gb_schedule_context_menu = (function () { |
| 153 | 153 | if (!isNaN(newValue) && newValue > 0) { |
| 154 | 154 | gb_common.$post_arr('/realSchedule/spaceAdjust', {ids: idArr, space: newValue}, function (rs) { |
| 155 | 155 | //刷新数据 |
| 156 | - if(rs.t){ | |
| 157 | - gb_schedule_table.reLoadAndRefresh(rs.t.xlBm); | |
| 158 | - } | |
| 159 | - //gb_schedule_table.updateSchedule(rs.ts); | |
| 156 | + //if(rs.t){ | |
| 157 | + // gb_schedule_table.reLoadAndRefresh(rs.t.xlBm); | |
| 158 | + //} | |
| 159 | + gb_schedule_table.updateSchedule(rs.ts); | |
| 160 | 160 | notify_succ('调整间隔成功!'); |
| 161 | 161 | }); |
| 162 | 162 | } else | ... | ... |