Commit 514010492398d5b8f92250aab9e7bcffc8e7524a
1 parent
e38abc75
Update
Showing
12 changed files
with
432 additions
and
32 deletions
src/main/java/com/bsth/entity/schedule/SchedulePlanInfo.java
| ... | ... | @@ -164,6 +164,42 @@ public class SchedulePlanInfo { |
| 164 | 164 | |
| 165 | 165 | public SchedulePlanInfo() {} |
| 166 | 166 | |
| 167 | + public void setRerunInfo(CarConfigInfo cc, EmployeeConfigInfo ec) { | |
| 168 | + // 关联的车辆信息 | |
| 169 | + this.cl = cc.getCl().getId(); // 车辆id | |
| 170 | + this.clZbh = cc.getCl().getInsideCode(); // 自编号/内部编号 | |
| 171 | + | |
| 172 | + // 关联的驾驶员 | |
| 173 | + EmployeeConfigInfo employeeConfigInfo = ec; | |
| 174 | + | |
| 175 | + this.j = employeeConfigInfo.getJsy().getId(); | |
| 176 | +// this.jGh = employeeConfigInfo.getJsy().getJobCode(); | |
| 177 | + if (StringUtils.isNotEmpty(employeeConfigInfo.getJsy().getJobCode())) { | |
| 178 | + String[] jsy_temp = employeeConfigInfo.getJsy().getJobCode().split("-"); | |
| 179 | + if (jsy_temp.length > 1) { | |
| 180 | + this.jGh = jsy_temp[1]; | |
| 181 | + } else { | |
| 182 | + this.jGh = jsy_temp[0]; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + this.jName = employeeConfigInfo.getJsy().getPersonnelName(); | |
| 186 | + // 关联的售票员 | |
| 187 | + if (employeeConfigInfo.getSpy() != null) { | |
| 188 | + this.s = employeeConfigInfo.getSpy().getId(); | |
| 189 | +// this.sGh = employeeConfigInfo.getSpy().getJobCode(); | |
| 190 | + if (StringUtils.isNotEmpty(employeeConfigInfo.getSpy().getJobCode())) { | |
| 191 | + String[] spy_temp = employeeConfigInfo.getSpy().getJobCode().split("-"); | |
| 192 | + if (spy_temp.length > 1) { | |
| 193 | + this.sGh = spy_temp[1]; | |
| 194 | + } else { | |
| 195 | + this.sGh = spy_temp[0]; | |
| 196 | + } | |
| 197 | + } | |
| 198 | + | |
| 199 | + this.sName = employeeConfigInfo.getSpy().getPersonnelName(); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + | |
| 167 | 203 | public SchedulePlanInfo( |
| 168 | 204 | Line xl, |
| 169 | 205 | ScheduleResult_output scheduleResult_output, | ... | ... |
src/main/java/com/bsth/entity/schedule/temp/SchedulePlanRuleResult.java
| ... | ... | @@ -3,6 +3,8 @@ package com.bsth.entity.schedule.temp; |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlan; |
| 4 | 4 | |
| 5 | 5 | import javax.persistence.*; |
| 6 | +import java.sql.PreparedStatement; | |
| 7 | +import java.sql.SQLException; | |
| 6 | 8 | import java.util.Date; |
| 7 | 9 | |
| 8 | 10 | /** |
| ... | ... | @@ -72,6 +74,38 @@ public class SchedulePlanRuleResult { |
| 72 | 74 | this.createDate = new Date(); |
| 73 | 75 | } |
| 74 | 76 | |
| 77 | + public static String generateInsertSql() { | |
| 78 | + String sql = "insert into bsth_c_s_sp_rule_rst" + | |
| 79 | + "(xl_id,xl_name,rule_id,cc_id,cc_zbh," + | |
| 80 | + "gids,gnames,gidindex,ecids,ecdbbms,ecindex," + | |
| 81 | + "ttinfo_id,ttinfo_name,schedule_date," + | |
| 82 | + "sysuser_id,sysuser_name,create_date) " + | |
| 83 | + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; | |
| 84 | + | |
| 85 | + return sql; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void preparedStatementSet(PreparedStatement ps) throws SQLException { | |
| 89 | + ps.setInt(1, this.getXlId()); | |
| 90 | + ps.setString(2, this.getXlName()); | |
| 91 | + ps.setString(3, this.getRuleId()); | |
| 92 | + ps.setString(4, this.getCcId()); | |
| 93 | + ps.setString(5, this.getCcZbh()); | |
| 94 | + ps.setString(6, this.getGids()); | |
| 95 | + ps.setString(7, this.getGnames()); | |
| 96 | + ps.setString(8, this.getGidindex()); | |
| 97 | + ps.setString(9, this.getEcids()); | |
| 98 | + ps.setString(10, this.getEcdbbms()); | |
| 99 | + ps.setString(11, this.getEcindex()); | |
| 100 | + ps.setString(12, this.getTtinfoId()); | |
| 101 | + ps.setString(13, this.getTtinfoName()); | |
| 102 | + ps.setDate(14, new java.sql.Date(this.getScheduleDate().getTime())); | |
| 103 | + ps.setString(15, this.getSysuserId()); | |
| 104 | + ps.setString(16, this.getSysuserName()); | |
| 105 | + ps.setTimestamp(17, new java.sql.Timestamp(this.getCreateDate().getTime())); | |
| 106 | + | |
| 107 | + } | |
| 108 | + | |
| 75 | 109 | public Long getId() { |
| 76 | 110 | return id; |
| 77 | 111 | } | ... | ... |
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
| ... | ... | @@ -2,6 +2,7 @@ package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Line; |
| 4 | 4 | import com.bsth.entity.schedule.SchedulePlan; |
| 5 | +import com.bsth.entity.schedule.SchedulePlanInfo; | |
| 5 | 6 | import com.bsth.entity.schedule.TTInfo; |
| 6 | 7 | import com.bsth.entity.schedule.rule.ScheduleRule1Flat; |
| 7 | 8 | import com.bsth.repository.BusinessRepository; |
| ... | ... | @@ -13,6 +14,7 @@ import com.bsth.service.schedule.rules.ScheduleRuleService; |
| 13 | 14 | import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input; |
| 14 | 15 | import com.bsth.service.schedule.rules.plan.PlanResult; |
| 15 | 16 | import com.bsth.service.schedule.rules.rerun.RerunRule_input; |
| 17 | +import com.bsth.service.schedule.rules.rerun.RerunRule_param; | |
| 16 | 18 | import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input; |
| 17 | 19 | import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; |
| 18 | 20 | import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; |
| ... | ... | @@ -102,6 +104,9 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 102 | 104 | // 执行完毕销毁,有日志的也要关闭 |
| 103 | 105 | session.dispose(); |
| 104 | 106 | |
| 107 | + // 保存循环规则结果数据 | |
| 108 | + scheduleRuleService.generateRuleResult(scheduleResults_output.getSchedulePlanRuleResults()); | |
| 109 | + | |
| 105 | 110 | // logger.info("循环规则输出={}", scheduleResults_output.showGuideboardDesc1()); |
| 106 | 111 | |
| 107 | 112 | return scheduleResults_output; |
| ... | ... | @@ -217,15 +222,7 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 217 | 222 | * @param schedulePlan |
| 218 | 223 | * @return |
| 219 | 224 | */ |
| 220 | - private PlanResult SchedulePlanWithOutRerun(SchedulePlan schedulePlan) { | |
| 221 | - // pre、如果排班的数据之前已经有了,删除之前的数据 | |
| 222 | - Date startpre = new Date(); | |
| 223 | - scheduleRuleService.deelteSchedulePlanInfo( | |
| 224 | - schedulePlan.getXl().getId(), | |
| 225 | - schedulePlan.getScheduleFromTime(), | |
| 226 | - schedulePlan.getScheduleToTime()); | |
| 227 | - Date endpre = new Date(); | |
| 228 | - | |
| 225 | + private PlanResult schedulePlanWithOutRerun(SchedulePlan schedulePlan) { | |
| 229 | 226 | // 1、时刻表数据及每日路牌数据计算 |
| 230 | 227 | Date start1 = new Date(); |
| 231 | 228 | Object[] ttInfoRets = ttInfoOutput(schedulePlan); |
| ... | ... | @@ -241,8 +238,7 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 241 | 238 | PlanResult planResult = planResultOutput(schedulePlan, scheduleResults_output, ttInfoResults_output); |
| 242 | 239 | Date end3 = new Date(); |
| 243 | 240 | |
| 244 | - logger.info("删除数据 {} ms,drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms", | |
| 245 | - endpre.getTime() - startpre.getTime(), | |
| 241 | + logger.info("drool时刻表每日路牌计算 {} ms,drool循环规则计算 {} ms,drool计划数据 {} ms", | |
| 246 | 242 | end1.getTime() - start1.getTime(), |
| 247 | 243 | end2.getTime() - start2.getTime(), |
| 248 | 244 | end3.getTime() - start3.getTime()); |
| ... | ... | @@ -250,24 +246,99 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 250 | 246 | return planResult; |
| 251 | 247 | } |
| 252 | 248 | |
| 249 | + /** | |
| 250 | + * 套跑计划排班数据。 | |
| 251 | + * @param planResult | |
| 252 | + */ | |
| 253 | + private void rerunPlanResult(PlanResult planResult, SchedulePlan schedulePlan) { | |
| 254 | + List<RerunRule_input> rerunRule_inputs = scheduleRuleService.findRerunrule(Integer.parseInt(planResult.getXlId())); | |
| 255 | + logger.info("套跑数量 {} 组", rerunRule_inputs.size()); | |
| 256 | + | |
| 257 | + if (rerunRule_inputs.size() > 0) { | |
| 258 | + // 找出是对应路牌类型的线路,计算循环规则输出 | |
| 259 | + Set<String> xlids = new HashSet<>(); | |
| 260 | + for (RerunRule_input rerunRule_input: rerunRule_inputs) { | |
| 261 | + if ("dylp".equals(rerunRule_input.getType())) { | |
| 262 | + xlids.add(rerunRule_input.getXl()); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + | |
| 266 | + List<ScheduleResults_output> scheduleResults_outputs = new ArrayList<>(); | |
| 267 | + Date start1 = new Date(); | |
| 268 | + for (String xlid: xlids) { | |
| 269 | + schedulePlan.getXl().setId(Integer.parseInt(xlid)); // 套跑的线路默认跟着主线路设定走 | |
| 270 | + // 获取套跑线路的循环规则计算输出 | |
| 271 | + Object[] ttInfoRets = ttInfoOutput(schedulePlan); | |
| 272 | + LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1]; | |
| 273 | + ScheduleResults_output scheduleResults_output = loopRuleOutput(schedulePlan, lpInfoResults_output); | |
| 274 | + scheduleResults_outputs.add(scheduleResults_output); | |
| 275 | + } | |
| 276 | + | |
| 277 | + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session | |
| 278 | + // 创建session,内部配置的是stateful | |
| 279 | + KieSession session = kieBase.newKieSession(); | |
| 280 | + | |
| 281 | + // 设置gloable对象,在drl中通过别名使用 | |
| 282 | + session.setGlobal("planResult", planResult); | |
| 283 | + session.setGlobal("log", logger); // 设置日志 | |
| 284 | + | |
| 285 | + session.setGlobal("carConfigInfoRepository", carConfigInfoRepository); | |
| 286 | + session.setGlobal("employeeConfigInfoRepository", employeeConfigInfoRepository); | |
| 287 | + | |
| 288 | + // 载入数据 | |
| 289 | + RerunRule_param rerunRule_param = new RerunRule_param(); | |
| 290 | + rerunRule_param.setMxlid(planResult.getXlId()); | |
| 291 | + rerunRule_param.setXlIds_dylp(xlids); | |
| 292 | + session.insert(rerunRule_param); | |
| 293 | + for (RerunRule_input rri: rerunRule_inputs) { | |
| 294 | + session.insert(rri); | |
| 295 | + } | |
| 296 | + for (SchedulePlanInfo spi: planResult.getSchedulePlanInfos()) { | |
| 297 | + session.insert(spi); | |
| 298 | + } | |
| 299 | + for (ScheduleResults_output sro: scheduleResults_outputs) { | |
| 300 | + session.insert(sro); | |
| 301 | + } | |
| 302 | + | |
| 303 | + // 执行rule | |
| 304 | + session.fireAllRules(); | |
| 305 | + | |
| 306 | + // 执行完毕销毁,有日志的也要关闭 | |
| 307 | + session.dispose(); | |
| 308 | + | |
| 309 | + Date end1 = new Date(); | |
| 310 | + logger.info("套跑规则计算,耗时 {} ms", end1.getTime() - start1.getTime()); | |
| 311 | + | |
| 312 | + } | |
| 313 | + | |
| 314 | + } | |
| 315 | + | |
| 253 | 316 | public SchedulePlan save(SchedulePlan schedulePlan) { |
| 317 | + // pre、如果排班的数据之前已经有了,删除之前的数据 | |
| 318 | + Date startpre = new Date(); | |
| 319 | + scheduleRuleService.deelteSchedulePlanInfo( | |
| 320 | + schedulePlan.getXl().getId(), | |
| 321 | + schedulePlan.getScheduleFromTime(), | |
| 322 | + schedulePlan.getScheduleToTime()); | |
| 323 | + Date endpre = new Date(); | |
| 324 | + | |
| 254 | 325 | // 1、查找线路,这是主线路 |
| 255 | 326 | Line xl = lineRepository.findOne(schedulePlan.getXl().getId()); |
| 256 | 327 | logger.info("<--- 排班master线路 id={}, name={}, 开始排班", xl.getId(), xl.getName()); |
| 257 | 328 | |
| 258 | 329 | // 2、确定主线路排班(无套跑规则) |
| 259 | - PlanResult planResult = SchedulePlanWithOutRerun(schedulePlan); | |
| 330 | + PlanResult planResult = schedulePlanWithOutRerun(schedulePlan); | |
| 260 | 331 | |
| 261 | - // TODO 3、确定套跑规则 | |
| 262 | - List<RerunRule_input> rerunRule_inputs = scheduleRuleService.findRerunrule(schedulePlan.getXl().getId()); | |
| 263 | - logger.info("套跑数量 {} 组", rerunRule_inputs.size()); | |
| 332 | + // 3、确定套跑规则 | |
| 333 | + rerunPlanResult(planResult, schedulePlan); | |
| 264 | 334 | |
| 265 | 335 | // 4、保存数据(jdbcTemplate 批量插入) |
| 266 | 336 | Date start4 = new Date(); |
| 267 | 337 | scheduleRuleService.generateSchedulePlan(schedulePlan, planResult.getSchedulePlanInfos()); |
| 268 | 338 | Date end4 = new Date(); |
| 269 | 339 | |
| 270 | - logger.info("保存主线路数据 {} 条 耗时 {} ms --->", | |
| 340 | + logger.info("删除数据 {} ms,保存主线路数据 {} 条 耗时 {} ms --->", | |
| 341 | + endpre.getTime() - startpre.getTime(), | |
| 271 | 342 | planResult.getSchedulePlanInfos().size(), |
| 272 | 343 | end4.getTime() - start4.getTime()); |
| 273 | 344 | ... | ... |
src/main/java/com/bsth/service/schedule/rules/MyDroolsConfiguration.java
| ... | ... | @@ -71,6 +71,9 @@ public class MyDroolsConfiguration { |
| 71 | 71 | kfs.write("src/main/resources/plan.drl", kieServices.getResources() |
| 72 | 72 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 73 | 73 | "/rules/plan.drl"), "UTF-8")); |
| 74 | + kfs.write("src/main/resources/rerun.drl", kieServices.getResources() | |
| 75 | + .newInputStreamResource(this.getClass().getResourceAsStream( | |
| 76 | + "/rules/rerun.drl"), "UTF-8")); | |
| 74 | 77 | // TODO:还有其他drl.... |
| 75 | 78 | |
| 76 | 79 | // 4、创建KieBuilder,使用KieFileSystem构建 | ... | ... |
src/main/java/com/bsth/service/schedule/rules/ScheduleRuleService.java
| ... | ... | @@ -31,6 +31,12 @@ public interface ScheduleRuleService { |
| 31 | 31 | void generateSchedulePlan(SchedulePlan schedulePlan, List<SchedulePlanInfo> schedulePlanInfos); |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | + * 生成排班规则结果。 | |
| 35 | + * @param schedulePlanRuleResults | |
| 36 | + */ | |
| 37 | + void generateRuleResult(List<SchedulePlanRuleResult> schedulePlanRuleResults); | |
| 38 | + | |
| 39 | + /** | |
| 34 | 40 | * 删除排班计划。 |
| 35 | 41 | * @param id 排班计划id |
| 36 | 42 | */ | ... | ... |
src/main/java/com/bsth/service/schedule/rules/ScheduleRuleServiceImpl.java
| ... | ... | @@ -71,10 +71,10 @@ public class ScheduleRuleServiceImpl implements ScheduleRuleService { |
| 71 | 71 | |
| 72 | 72 | rerunRule_input.setType(resultSet.getString("type")); |
| 73 | 73 | // 对应班次类型 |
| 74 | - if ("dybc".equals(resultSet.getString("type"))) { | |
| 74 | + if ("dylp".equals(resultSet.getString("type"))) { | |
| 75 | 75 | rerunRule_input.setS_xl(String.valueOf(resultSet.getInt("s_dylp_xl"))); |
| 76 | 76 | rerunRule_input.setS_lp(String.valueOf(resultSet.getLong("s_dylp_lp"))); |
| 77 | - } else if ("dylp".equals(resultSet.getString("type"))) { | |
| 77 | + } else if ("dybc".equals(resultSet.getString("type"))) { | |
| 78 | 78 | rerunRule_input.setCl(resultSet.getInt("s_dybc_cl")); |
| 79 | 79 | rerunRule_input.setZbh(resultSet.getString("s_dybc_clzbh")); |
| 80 | 80 | rerunRule_input.setJ(resultSet.getInt("s_dybc_j")); |
| ... | ... | @@ -94,15 +94,6 @@ public class ScheduleRuleServiceImpl implements ScheduleRuleService { |
| 94 | 94 | return rerunRule_inputs; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public void test() { | |
| 98 | - jdbcTemplate.query("", new RowCallbackHandler() { | |
| 99 | - @Override | |
| 100 | - public void processRow(ResultSet resultSet) throws SQLException { | |
| 101 | - | |
| 102 | - } | |
| 103 | - }); | |
| 104 | - } | |
| 105 | - | |
| 106 | 97 | @Override |
| 107 | 98 | public List<SchedulePlanRuleResult> findLastByXl(String xlid, Date from) { |
| 108 | 99 | String sql = "select * from bsth_c_s_sp_rule_rst a " + |
| ... | ... | @@ -142,6 +133,35 @@ public class ScheduleRuleServiceImpl implements ScheduleRuleService { |
| 142 | 133 | jdbcTemplate.update(sql, xlid, datefrom, dateto); |
| 143 | 134 | } |
| 144 | 135 | |
| 136 | + @Override | |
| 137 | + public void generateRuleResult(List<SchedulePlanRuleResult> schedulePlanRuleResults) { | |
| 138 | + // 、批量插入排班规则结果 | |
| 139 | + List<List<SchedulePlanRuleResult>> lists = new ArrayList<>(); | |
| 140 | + int batchSize = 2000; | |
| 141 | + int loopCount = schedulePlanRuleResults.size() / batchSize; | |
| 142 | + int otherCount = schedulePlanRuleResults.size() % batchSize; | |
| 143 | + for (int i = 0; i < loopCount; i++) { | |
| 144 | + lists.add(schedulePlanRuleResults.subList(i * batchSize, i * batchSize + batchSize)); | |
| 145 | + } | |
| 146 | + if (otherCount > 0) { | |
| 147 | + lists.add(schedulePlanRuleResults.subList(loopCount * batchSize, loopCount * batchSize + otherCount)); | |
| 148 | + } | |
| 149 | + | |
| 150 | + for (final List<SchedulePlanRuleResult> list : lists) { | |
| 151 | + jdbcTemplate.batchUpdate(SchedulePlanRuleResult.generateInsertSql(), new BatchPreparedStatementSetter() { | |
| 152 | + @Override | |
| 153 | + public void setValues(PreparedStatement preparedStatement, int i) throws SQLException { | |
| 154 | + SchedulePlanRuleResult schedulePlanRuleResult = list.get(i); | |
| 155 | + schedulePlanRuleResult.preparedStatementSet(preparedStatement); | |
| 156 | + } | |
| 157 | + @Override | |
| 158 | + public int getBatchSize() { | |
| 159 | + return list.size(); | |
| 160 | + } | |
| 161 | + }); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + | |
| 145 | 165 | @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) |
| 146 | 166 | @Override |
| 147 | 167 | public void generateSchedulePlan(final SchedulePlan schedulePlan, final List<SchedulePlanInfo> schedulePlanInfos) { | ... | ... |
src/main/java/com/bsth/service/schedule/rules/rerun/RerunRule_param.java
0 → 100644
| 1 | +package com.bsth.service.schedule.rules.rerun; | |
| 2 | + | |
| 3 | +import java.util.Set; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Created by xu on 17/4/27. | |
| 7 | + */ | |
| 8 | +public class RerunRule_param { | |
| 9 | + /** 主线路id */ | |
| 10 | + private String mxlid; | |
| 11 | + | |
| 12 | + /** 对应路牌的套跑线路 */ | |
| 13 | + private Set<String> xlIds_dylp; | |
| 14 | + | |
| 15 | + // TODO: | |
| 16 | + | |
| 17 | + | |
| 18 | + public Set<String> getXlIds_dylp() { | |
| 19 | + return xlIds_dylp; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public void setXlIds_dylp(Set<String> xlIds_dylp) { | |
| 23 | + this.xlIds_dylp = xlIds_dylp; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public String getMxlid() { | |
| 27 | + return mxlid; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void setMxlid(String mxlid) { | |
| 31 | + this.mxlid = mxlid; | |
| 32 | + } | |
| 33 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResult_output.java
| ... | ... | @@ -17,6 +17,9 @@ public class ScheduleResult_output { |
| 17 | 17 | /** 车辆配置id */ |
| 18 | 18 | private String carConfigId; |
| 19 | 19 | |
| 20 | + /** 线路id */ | |
| 21 | + private String xlId; | |
| 22 | + | |
| 20 | 23 | public DateTime getSd() { |
| 21 | 24 | return sd; |
| 22 | 25 | } |
| ... | ... | @@ -56,4 +59,12 @@ public class ScheduleResult_output { |
| 56 | 59 | public void setCarConfigId(String carConfigId) { |
| 57 | 60 | this.carConfigId = carConfigId; |
| 58 | 61 | } |
| 62 | + | |
| 63 | + public String getXlId() { | |
| 64 | + return xlId; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setXlId(String xlId) { | |
| 68 | + this.xlId = xlId; | |
| 69 | + } | |
| 59 | 70 | } | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResults_output.java
| ... | ... | @@ -9,6 +9,9 @@ import java.util.*; |
| 9 | 9 | * 输出结果集合。 |
| 10 | 10 | */ |
| 11 | 11 | public class ScheduleResults_output { |
| 12 | + /** 线路Id */ | |
| 13 | + private String xlid; | |
| 14 | + | |
| 12 | 15 | /** 输出列表 */ |
| 13 | 16 | private List<ScheduleResult_output> results = new ArrayList<>(); |
| 14 | 17 | |
| ... | ... | @@ -71,5 +74,13 @@ public class ScheduleResults_output { |
| 71 | 74 | return stringBuilder.toString(); |
| 72 | 75 | } |
| 73 | 76 | |
| 74 | - // TODO:人员输出 | |
| 77 | + public String getXlid() { | |
| 78 | + return xlid; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void setXlid(String xlid) { | |
| 82 | + this.xlid = xlid; | |
| 83 | + } | |
| 84 | + | |
| 85 | +// TODO:人员输出 | |
| 75 | 86 | } | ... | ... |
src/main/resources/rules/rerun.drl
0 → 100644
| 1 | +package com.bsth.service.schedule.rerun; | |
| 2 | + | |
| 3 | +import org.joda.time.*; | |
| 4 | +import java.util.*; | |
| 5 | + | |
| 6 | +import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; | |
| 7 | +import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; | |
| 8 | + | |
| 9 | +import com.bsth.service.schedule.rules.rerun.RerunRule_input; | |
| 10 | +import com.bsth.service.schedule.rules.rerun.RerunRule_param; | |
| 11 | + | |
| 12 | +import com.bsth.repository.schedule.CarConfigInfoRepository; | |
| 13 | +import com.bsth.repository.schedule.EmployeeConfigInfoRepository; | |
| 14 | + | |
| 15 | +import org.slf4j.Logger | |
| 16 | +import com.bsth.entity.schedule.CarConfigInfo | |
| 17 | +import java.util.HashMap | |
| 18 | +import com.bsth.entity.schedule.EmployeeConfigInfo | |
| 19 | +import com.bsth.entity.schedule.SchedulePlanInfo; | |
| 20 | + | |
| 21 | +// 全局日志类(一般使用调用此规则的service类) | |
| 22 | +global Logger log; | |
| 23 | + | |
| 24 | +global CarConfigInfoRepository carConfigInfoRepository; | |
| 25 | +global EmployeeConfigInfoRepository employeeConfigInfoRepository; | |
| 26 | + | |
| 27 | +// 输出 | |
| 28 | + | |
| 29 | + | |
| 30 | +/* | |
| 31 | + 规则说明: | |
| 32 | + 1、对应路牌规则:将对应路牌的车辆,人员替换指定的套跑班次已有的配置 | |
| 33 | + 2、对应班车规则:直接使用指定的人员,车辆替换指定的套跑班次已有的配置 | |
| 34 | +*/ | |
| 35 | + | |
| 36 | +//-------------------- 第一阶段、计算对应路牌套跑的车辆配置,人员配置数据 -----------------// | |
| 37 | + | |
| 38 | +//--------------- 车辆配置信息载入 -------------// | |
| 39 | +declare Dylp_CarConfig_Wraps | |
| 40 | + xlId: String // 线路Id | |
| 41 | + ccMap: Map // 车辆配置Map Map<id, CarConfigInfo> | |
| 42 | +end | |
| 43 | + | |
| 44 | +rule "calcu_Dylp_CarConfig_Wraps" | |
| 45 | + salience 1000 | |
| 46 | + when | |
| 47 | + $rp: RerunRule_param($xlId: mxlid) | |
| 48 | + $dylpxlid: String() from $rp.getXlIds_dylp() | |
| 49 | + then | |
| 50 | + List carConfigInfos = carConfigInfoRepository.findByXlId(Integer.parseInt($xlId)); | |
| 51 | + | |
| 52 | + Dylp_CarConfig_Wraps carConfig_wraps = new Dylp_CarConfig_Wraps(); | |
| 53 | + carConfig_wraps.setXlId($dylpxlid); | |
| 54 | + carConfig_wraps.setCcMap(new HashMap()); | |
| 55 | + | |
| 56 | + for (int i = 0; i < carConfigInfos.size(); i++) { | |
| 57 | + CarConfigInfo carConfigInfo = (CarConfigInfo) carConfigInfos.get(i); | |
| 58 | + carConfig_wraps.getCcMap().put(carConfigInfo.getId().toString(), carConfigInfo); | |
| 59 | + } | |
| 60 | + | |
| 61 | + insert(carConfig_wraps); | |
| 62 | + | |
| 63 | + log.info("calcu_Dylp_CarConfig_Wraps"); | |
| 64 | + | |
| 65 | +end | |
| 66 | + | |
| 67 | +//--------------- 人员配置信息载入 --------------// | |
| 68 | +declare Dylp_EmployeeConfig_Wraps | |
| 69 | + xlId: String // 线路Id | |
| 70 | + ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo> | |
| 71 | +end | |
| 72 | + | |
| 73 | +rule "calcu_Dylp_EmployeeConfig_Wraps" | |
| 74 | + salience 1000 | |
| 75 | + when | |
| 76 | + $rp: RerunRule_param($xlId: mxlid) | |
| 77 | + $dylpxlid: String() from $rp.getXlIds_dylp() | |
| 78 | + then | |
| 79 | + List employeeConfigInfos = employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId)); | |
| 80 | + | |
| 81 | + Dylp_EmployeeConfig_Wraps employeeConfig_wraps = new Dylp_EmployeeConfig_Wraps(); | |
| 82 | + employeeConfig_wraps.setXlId($xlId); | |
| 83 | + employeeConfig_wraps.setEcMap(new HashMap()); | |
| 84 | + | |
| 85 | + for (int i = 0; i < employeeConfigInfos.size(); i++) { | |
| 86 | + EmployeeConfigInfo employeeConfigInfo = (EmployeeConfigInfo) employeeConfigInfos.get(i); | |
| 87 | + employeeConfig_wraps.getEcMap().put(employeeConfigInfo.getId().toString(), employeeConfigInfo); | |
| 88 | + } | |
| 89 | + | |
| 90 | + insert(employeeConfig_wraps); | |
| 91 | + | |
| 92 | + log.info("calcu_Dylp_EmployeeConfig_Wraps"); | |
| 93 | + | |
| 94 | +end | |
| 95 | + | |
| 96 | +//-------------------- 第二阶段、包装对应路牌的循环规则输出 -----------------// | |
| 97 | + | |
| 98 | +declare Dylp_ScheduleResult_output_wrap | |
| 99 | + xlId: String // 线路 | |
| 100 | + sd: DateTime // 日期 | |
| 101 | + lp: String // 路牌 | |
| 102 | + cc: CarConfigInfo // 使用的车辆配置 | |
| 103 | + ec: EmployeeConfigInfo // 使用的人员配置 | |
| 104 | +end | |
| 105 | + | |
| 106 | +rule "calcu_Dylp_ScheduleResult_output_wrap" | |
| 107 | + salience 900 | |
| 108 | + when | |
| 109 | + $sro: ScheduleResults_output($xlId: xlid) | |
| 110 | + $sr: ScheduleResult_output() from $sro.getResults() | |
| 111 | + Dylp_CarConfig_Wraps(xlId == $xlId, $ccmap: ccMap) | |
| 112 | + Dylp_EmployeeConfig_Wraps(xlId == $xlId, $ecmap: ecMap) | |
| 113 | + then | |
| 114 | + Dylp_ScheduleResult_output_wrap wrap = new Dylp_ScheduleResult_output_wrap(); | |
| 115 | + wrap.setXlId($xlId); | |
| 116 | + wrap.setSd($sr.getSd()); | |
| 117 | + wrap.setLp($sr.getGuideboardId()); | |
| 118 | + wrap.setCc((CarConfigInfo) $ccmap.get($sr.getCarConfigId())); | |
| 119 | + wrap.setEc((EmployeeConfigInfo) $ecmap.get($sr.getEmployeeConfigId())); | |
| 120 | + | |
| 121 | + insert(wrap); | |
| 122 | +end | |
| 123 | + | |
| 124 | +//-------------------- 第三阶段、套跑线路,替换班次的车辆,人员 --------------------// | |
| 125 | +rule "calcu_Dylp_rerun_update" | |
| 126 | + salience 800 | |
| 127 | +// no-loop | |
| 128 | + when | |
| 129 | + $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo) | |
| 130 | + $ri: RerunRule_input( | |
| 131 | + type == "dylp", | |
| 132 | + xl == $xlid.toString(), | |
| 133 | + ttinfo == $ttinfo.toString(), | |
| 134 | + lp == $lp.toString(), | |
| 135 | + fcsj == $fcsj, | |
| 136 | + $sxl: s_xl, $slp: s_lp | |
| 137 | + ) | |
| 138 | + $dsro: Dylp_ScheduleResult_output_wrap( | |
| 139 | + xlId == $sxl, | |
| 140 | + lp == $slp, | |
| 141 | + sd.getMillis() == $sd.getTime() | |
| 142 | + ) | |
| 143 | + then | |
| 144 | +// log.info("TODO:测试 {}", $fcsj); | |
| 145 | + | |
| 146 | + $spi.setRerunInfo($dsro.getCc(), $dsro.getEc()); | |
| 147 | + | |
| 148 | +end | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | ... | ... |
src/main/resources/rules/shiftloop_fb_2.drl
| ... | ... | @@ -55,13 +55,16 @@ rule "calcu_days_1_" |
| 55 | 55 | ScheduleCalcuParam_input( |
| 56 | 56 | fromDate.isBefore(toDate) || fromDate.isEqual(toDate), |
| 57 | 57 | $fromDate : fromDate, |
| 58 | - $toDate : toDate | |
| 58 | + $toDate : toDate, | |
| 59 | + $xlId: xlId | |
| 59 | 60 | ) |
| 60 | 61 | ScheduleRule_input( |
| 61 | 62 | $ruleId : ruleId, $qyrq : qyrq, |
| 62 | 63 | $lpindex : startGbdIndex, $ryindex: startEIndex) |
| 63 | 64 | eval($qyrq.isBefore($fromDate)) |
| 64 | 65 | then |
| 66 | + scheduleResult.setXlid($xlId); | |
| 67 | + | |
| 65 | 68 | // 构造Calcu_days_result_pre,用于路牌 |
| 66 | 69 | Calcu_days_result_pre cdrp = new Calcu_days_result_pre(); |
| 67 | 70 | cdrp.setRuleId($ruleId); |
| ... | ... | @@ -87,13 +90,16 @@ rule "calcu_days_2_" |
| 87 | 90 | ScheduleCalcuParam_input( |
| 88 | 91 | fromDate.isBefore(toDate) || fromDate.isEqual(toDate), |
| 89 | 92 | $fromDate : fromDate, |
| 90 | - $toDate : toDate | |
| 93 | + $toDate : toDate, | |
| 94 | + $xlId: xlId | |
| 91 | 95 | ) |
| 92 | 96 | ScheduleRule_input( |
| 93 | 97 | $ruleId : ruleId, $qyrq : qyrq, |
| 94 | 98 | $lpindex : startGbdIndex, $ryindex: startEIndex) |
| 95 | 99 | eval((!$qyrq.isBefore($fromDate)) && (!$qyrq.isAfter($toDate))) |
| 96 | 100 | then |
| 101 | + scheduleResult.setXlid($xlId); | |
| 102 | + | |
| 97 | 103 | // 构造Calcu_days_result_pre,用于路牌 |
| 98 | 104 | Calcu_days_result_pre cdrp = new Calcu_days_result_pre(); |
| 99 | 105 | cdrp.setRuleId($ruleId); |
| ... | ... | @@ -243,7 +249,7 @@ end |
| 243 | 249 | rule "Calcu_loop2_1_" // 路牌在时刻表中存在,就翻 |
| 244 | 250 | salience 800 |
| 245 | 251 | when |
| 246 | - ScheduleCalcuParam_input($sp: schedulePlan) | |
| 252 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 247 | 253 | $cdrp: Calcu_days_result_pre( |
| 248 | 254 | calcu_start_date_1.isEqual(calcu_end_date_1), |
| 249 | 255 | calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), |
| ... | ... | @@ -276,6 +282,7 @@ rule "Calcu_loop2_1_" // 路牌在时刻表中存在,就翻 |
| 276 | 282 | ro.setGuideboardId(String.valueOf($gids.get($lpindex))); |
| 277 | 283 | ro.setEmployeeConfigId(String.valueOf($eids.get($ryindex))); |
| 278 | 284 | ro.setCarConfigId($cid); |
| 285 | + ro.setXlId($xlid); | |
| 279 | 286 | |
| 280 | 287 | scheduleResult.getResults().add(ro); |
| 281 | 288 | |
| ... | ... | @@ -313,7 +320,7 @@ end |
| 313 | 320 | rule "Calcu_loop2_2_" // 路牌在时刻表中不存在,就不翻 |
| 314 | 321 | salience 800 |
| 315 | 322 | when |
| 316 | - ScheduleCalcuParam_input($sp: schedulePlan) | |
| 323 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 317 | 324 | $cdrp: Calcu_days_result_pre( |
| 318 | 325 | calcu_start_date_1.isEqual(calcu_end_date_1), |
| 319 | 326 | calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), |
| ... | ... | @@ -337,6 +344,7 @@ rule "Calcu_loop2_2_" // 路牌在时刻表中不存在,就不翻 |
| 337 | 344 | ro.setGuideboardId(String.valueOf($gids.get($lpindex))); |
| 338 | 345 | ro.setEmployeeConfigId(String.valueOf($eids.get($ryindex))); |
| 339 | 346 | ro.setCarConfigId($cid); |
| 347 | + ro.setXlId($xlid); | |
| 340 | 348 | |
| 341 | 349 | scheduleResult.getResults().add(ro); |
| 342 | 350 | ... | ... |