Commit cebafb2edccaef36381fc9c7625c96ea14236aa0
1 parent
c965d364
1、排班时,增加规则逻辑错误drool判定,添加相应的规则逻辑,和页面angular指令
2、治理规则代码,将drl文件以kBase1,kBase2,KBase3前缀命名,将所有drools的java代码移动至com.bsth.service.scedule.impl.plan中 3、drl文件名和com.bsth.service.schedule.impl.plan下的包名一级一级对应,前缀kBase1、kBase2、kBase3和MyDroolsConfiguration中的定义对应
Showing
54 changed files
with
2727 additions
and
1872 deletions
Too many changes to show.
To preserve performance only 54 of 63 files are displayed.
src/main/java/com/bsth/controller/schedule/core/SchedulePlanController.java
| ... | ... | @@ -57,4 +57,21 @@ public class SchedulePlanController extends BController<SchedulePlan, Long> { |
| 57 | 57 | return rtn; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | + /** | |
| 61 | + * 验证排班计划时间范围内规则的正确性。 | |
| 62 | + * @return | |
| 63 | + * @throws Exception | |
| 64 | + */ | |
| 65 | + @RequestMapping(value = "/valttrule/{xlid}/{from}/{to}", method = RequestMethod.GET) | |
| 66 | + public Map<String, Object> validateRule( | |
| 67 | + @PathVariable(value = "xlid") Integer xlid, | |
| 68 | + @PathVariable(value = "from") Date from, | |
| 69 | + @PathVariable(value = "to") Date to | |
| 70 | + ) throws Exception { | |
| 71 | + Map<String, Object> rtn = new HashMap<>(); | |
| 72 | + rtn.put("status", ResponseCode.SUCCESS); | |
| 73 | + rtn.put("data", schedulePlanService.validateRule(xlid, from, to)); | |
| 74 | + return rtn; | |
| 75 | + } | |
| 76 | + | |
| 60 | 77 | } | ... | ... |
src/main/java/com/bsth/entity/schedule/SchedulePlanInfo.java
| 1 | 1 | package com.bsth.entity.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Line; |
| 4 | -import com.bsth.service.schedule.rules.rerun.RerunRule_input; | |
| 5 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; | |
| 6 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type; | |
| 4 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input; | |
| 5 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResult_output; | |
| 6 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_Type; | |
| 7 | 7 | |
| 8 | 8 | import javax.persistence.*; |
| 9 | 9 | import java.sql.PreparedStatement; | ... | ... |
src/main/java/com/bsth/repository/schedule/GuideboardInfoRepository.java
| ... | ... | @@ -43,5 +43,7 @@ public interface GuideboardInfoRepository extends BaseRepository<GuideboardInfo, |
| 43 | 43 | |
| 44 | 44 | @Query(value = "SELECT g FROM GuideboardInfo g where g.xl =?1 and g.lpName = ?2 and g.lpNo = ?3 and lpType =?4 and isCancel = 0") |
| 45 | 45 | List<GuideboardInfo> validateLp(Line xl,String lpName , int lpNo,String lpType); |
| 46 | + | |
| 47 | + List<GuideboardInfo> findByXlId(Integer id); | |
| 46 | 48 | |
| 47 | 49 | } | ... | ... |
src/main/java/com/bsth/repository/schedule/TTInfoRepository.java
| ... | ... | @@ -48,4 +48,6 @@ public interface TTInfoRepository extends BaseRepository<TTInfo, Long> { |
| 48 | 48 | "from LineVersions lv where lv.line.id = ?1 and lv.status = ?2 ") |
| 49 | 49 | List<Map<String, Object>> findLineVersionDescs3(Integer lineId, Integer status); |
| 50 | 50 | |
| 51 | + List<TTInfo> findByXlId(Integer xlId); | |
| 52 | + | |
| 51 | 53 | } | ... | ... |
src/main/java/com/bsth/service/schedule/SchedulePlanService.java
| 1 | 1 | package com.bsth.service.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlan; |
| 4 | -import com.bsth.service.schedule.rules.ttinfo2.Result; | |
| 4 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult; | |
| 5 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.Result; | |
| 5 | 6 | |
| 6 | 7 | import java.util.Date; |
| 7 | 8 | |
| ... | ... | @@ -26,4 +27,13 @@ public interface SchedulePlanService extends BService<SchedulePlan, Long> { |
| 26 | 27 | * @return |
| 27 | 28 | */ |
| 28 | 29 | Result validateTTInfo(Integer xlid, Date from, Date to); |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 验证规则。 | |
| 33 | + * @param xlId 线路id | |
| 34 | + * @param from 排班计划开始时间 | |
| 35 | + * @param to 排班计划结束时间 | |
| 36 | + * @return | |
| 37 | + */ | |
| 38 | + ValidateRuleResult validateRule(Integer xlId, Date from, Date to); | |
| 29 | 39 | } |
| 30 | 40 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | +import com.bsth.entity.Line; | |
| 3 | 4 | import com.bsth.entity.schedule.SchedulePlan; |
| 4 | 5 | import com.bsth.entity.schedule.TTInfo; |
| 5 | 6 | import com.bsth.repository.BusinessRepository; |
| ... | ... | @@ -7,10 +8,11 @@ import com.bsth.repository.LineRepository; |
| 7 | 8 | import com.bsth.repository.schedule.*; |
| 8 | 9 | import com.bsth.service.schedule.SchedulePlanService; |
| 9 | 10 | import com.bsth.service.schedule.exception.ScheduleException; |
| 10 | -import com.bsth.service.schedule.plan.DroolsSchedulePlan; | |
| 11 | -import com.bsth.service.schedule.rules.ScheduleRuleService; | |
| 12 | -import com.bsth.service.schedule.rules.ttinfo2.CalcuParam; | |
| 13 | -import com.bsth.service.schedule.rules.ttinfo2.Result; | |
| 11 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult; | |
| 12 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.CalcuParam; | |
| 13 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.Result; | |
| 14 | +import com.bsth.service.schedule.impl.plan.DroolsSchedulePlan; | |
| 15 | +import com.bsth.service.schedule.impl.plan.ScheduleRuleService; | |
| 14 | 16 | import org.joda.time.DateTime; |
| 15 | 17 | import org.kie.api.KieBase; |
| 16 | 18 | import org.kie.api.runtime.KieSession; |
| ... | ... | @@ -42,6 +44,10 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 42 | 44 | private KieBase preKBase; |
| 43 | 45 | |
| 44 | 46 | @Autowired |
| 47 | + @Qualifier("KBase3") | |
| 48 | + private KieBase validateKBase; | |
| 49 | + | |
| 50 | + @Autowired | |
| 45 | 51 | private ScheduleRule1FlatRepository scheduleRule1FlatRepository; |
| 46 | 52 | @Autowired |
| 47 | 53 | private TTInfoRepository ttInfoRepository; |
| ... | ... | @@ -52,6 +58,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 52 | 58 | @Autowired |
| 53 | 59 | private CarConfigInfoRepository carConfigInfoRepository; |
| 54 | 60 | @Autowired |
| 61 | + private GuideboardInfoRepository guideboardInfoRepository; | |
| 62 | + @Autowired | |
| 55 | 63 | private EmployeeConfigInfoRepository employeeConfigInfoRepository; |
| 56 | 64 | @Autowired |
| 57 | 65 | private BusinessRepository businessRepository; |
| ... | ... | @@ -146,22 +154,25 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 146 | 154 | public Result validateTTInfo(Integer xlid, Date from, Date to) { |
| 147 | 155 | // 构造drools session->载入数据->启动规则->计算->销毁session |
| 148 | 156 | // 创建session,内部配置的是stateful |
| 149 | - KieSession session = coreKBase.newKieSession(); | |
| 157 | + KieSession session = validateKBase.newKieSession(); | |
| 150 | 158 | // 设置gloable对象,在drl中通过别名使用 |
| 151 | 159 | session.setGlobal("log", logger); |
| 152 | - session.setGlobal("lineRepository", lineRepository); | |
| 153 | 160 | session.setGlobal("tTInfoDetailRepository", ttInfoDetailRepository); |
| 154 | 161 | |
| 155 | 162 | Result rs = new Result(); // 输出gloable对象 |
| 156 | 163 | session.setGlobal("rs", rs); |
| 157 | 164 | |
| 158 | 165 | // 载入数据 |
| 166 | + Line line = lineRepository.findOne(xlid); | |
| 167 | + session.insert(line); | |
| 168 | + | |
| 159 | 169 | CalcuParam calcuParam = new CalcuParam( |
| 160 | 170 | new DateTime(from), new DateTime(to), xlid); |
| 161 | 171 | session.insert(calcuParam); |
| 162 | - List<TTInfo> ttInfos = (List<TTInfo>) ttInfoRepository.findAll(); | |
| 163 | - for (TTInfo ttInfo: ttInfos) | |
| 164 | - session.insert(ttInfo); | |
| 172 | + List<TTInfo> ttInfos = ttInfoRepository.findByXlId(xlid); | |
| 173 | + for (TTInfo ttInfo: ttInfos) { | |
| 174 | + session.insert(ttInfo); | |
| 175 | + } | |
| 165 | 176 | |
| 166 | 177 | // 执行rule |
| 167 | 178 | session.fireAllRules(); |
| ... | ... | @@ -171,4 +182,30 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im |
| 171 | 182 | |
| 172 | 183 | return rs; |
| 173 | 184 | } |
| 185 | + | |
| 186 | + @Override | |
| 187 | + public ValidateRuleResult validateRule(Integer xlId, Date from, Date to) { | |
| 188 | + KieSession session = validateKBase.newKieSession(); | |
| 189 | + session.setGlobal("LOG", logger); | |
| 190 | + session.setGlobal("ccRepo", carConfigInfoRepository); | |
| 191 | + session.setGlobal("lpRepo", guideboardInfoRepository); | |
| 192 | + session.setGlobal("ecRepo", employeeConfigInfoRepository); | |
| 193 | + session.setGlobal("ruleRepo", scheduleRule1FlatRepository); | |
| 194 | + | |
| 195 | + ValidateRuleResult result = new ValidateRuleResult(); | |
| 196 | + session.setGlobal("result", result); | |
| 197 | + | |
| 198 | + com.bsth.service.schedule.impl.plan.kBase3.validate.rule.CalcuParam calcuParam = | |
| 199 | + new com.bsth.service.schedule.impl.plan.kBase3.validate.rule.CalcuParam(); | |
| 200 | + calcuParam.setXlId(xlId); | |
| 201 | + calcuParam.setFromDate(new DateTime(from)); | |
| 202 | + calcuParam.setToDate(new DateTime(to)); | |
| 203 | + session.insert(calcuParam); | |
| 204 | + | |
| 205 | + session.fireAllRules(); | |
| 206 | + | |
| 207 | + session.dispose();; | |
| 208 | + | |
| 209 | + return result; | |
| 210 | + } | |
| 174 | 211 | } | ... | ... |
src/main/java/com/bsth/service/schedule/plan/DroolsSchedulePlan.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/DroolsSchedulePlan.java
| 1 | -package com.bsth.service.schedule.plan; | |
| 1 | +package com.bsth.service.schedule.impl.plan; | |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Line; |
| 4 | 4 | import com.bsth.entity.schedule.SchedulePlan; |
| ... | ... | @@ -8,17 +8,16 @@ import com.bsth.entity.schedule.rule.ScheduleRule1Flat; |
| 8 | 8 | import com.bsth.repository.BusinessRepository; |
| 9 | 9 | import com.bsth.repository.LineRepository; |
| 10 | 10 | import com.bsth.repository.schedule.*; |
| 11 | -import com.bsth.service.schedule.rules.ScheduleRuleService; | |
| 12 | -import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input; | |
| 13 | -import com.bsth.service.schedule.rules.plan.PlanResult; | |
| 14 | -import com.bsth.service.schedule.rules.rerun.RerunRule_input; | |
| 15 | -import com.bsth.service.schedule.rules.rerun.RerunRule_param; | |
| 16 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input; | |
| 17 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; | |
| 18 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; | |
| 19 | -import com.bsth.service.schedule.rules.ttinfo.*; | |
| 20 | -import com.bsth.service.schedule.rules.validate.ValidateParam; | |
| 21 | -import com.bsth.service.schedule.rules.validate.ValidateResults_output; | |
| 11 | +import com.bsth.service.schedule.impl.plan.kBase1.core.plan.PlanCalcuParam_input; | |
| 12 | +import com.bsth.service.schedule.impl.plan.kBase1.core.plan.PlanResult; | |
| 13 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input; | |
| 14 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_param; | |
| 15 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleCalcuParam_input; | |
| 16 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResults_output; | |
| 17 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_input; | |
| 18 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.*; | |
| 19 | +import com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidateParam; | |
| 20 | +import com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidateResults_output; | |
| 22 | 21 | import org.apache.commons.lang3.StringUtils; |
| 23 | 22 | import org.joda.time.DateTime; |
| 24 | 23 | import org.kie.api.KieBase; | ... | ... |
src/main/java/com/bsth/service/schedule/rules/MyDroolsConfiguration.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/MyDroolsConfiguration.java
| 1 | -package com.bsth.service.schedule.rules; | |
| 1 | +package com.bsth.service.schedule.impl.plan; | |
| 2 | 2 | |
| 3 | 3 | import org.kie.api.KieBase; |
| 4 | 4 | import org.kie.api.KieBaseConfiguration; |
| ... | ... | @@ -56,27 +56,24 @@ public class MyDroolsConfiguration { |
| 56 | 56 | // 3.2、写入drl(写法超多,有点混乱) |
| 57 | 57 | // 这里使用文件的形式写入,TODO:以后考虑从数据库中读drl写入 |
| 58 | 58 | // 注意kfs写的时候如果指定path,强制为src/main/resources/加上文件名,还有就是文件名不要重复否则会覆盖的 |
| 59 | - kfs.write("src/main/resources/functions.drl", kieServices.getResources() | |
| 59 | + kfs.write("src/main/resources/kBase1_core_shiftloop.drl", kieServices.getResources() | |
| 60 | 60 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 61 | - "/rules/functions.drl"), "UTF-8")); | |
| 62 | - kfs.write("src/main/resources/shiftloop_fb_2.drl", kieServices.getResources() | |
| 61 | + "/rules/kBase1_core_shiftloop.drl"), "UTF-8")); | |
| 62 | + kfs.write("src/main/resources/kBase1_core_ttinfo.drl", kieServices.getResources() | |
| 63 | 63 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 64 | - "/rules/shiftloop_fb_2.drl"), "UTF-8")); | |
| 65 | - kfs.write("src/main/resources/ttinfo.drl", kieServices.getResources() | |
| 64 | + "/rules/kBase1_core_ttinfo.drl"), "UTF-8")); | |
| 65 | + kfs.write("src/main/resources/kBase1_core_plan.drl", kieServices.getResources() | |
| 66 | 66 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 67 | - "/rules/ttinfo.drl"), "UTF-8")); | |
| 68 | - kfs.write("src/main/resources/ttinfo2.drl", kieServices.getResources() | |
| 67 | + "/rules/kBase1_core_plan.drl"), "UTF-8")); | |
| 68 | + kfs.write("src/main/resources/kBase1_core_rerun.drl", kieServices.getResources() | |
| 69 | 69 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 70 | - "/rules/ttinfo2.drl"), "UTF-8")); | |
| 71 | - kfs.write("src/main/resources/plan.drl", kieServices.getResources() | |
| 70 | + "/rules/kBase1_core_rerun.drl"), "UTF-8")); | |
| 71 | + kfs.write("src/main/resources/kBase1_core_validate.drl", kieServices.getResources() | |
| 72 | 72 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 73 | - "/rules/plan.drl"), "UTF-8")); | |
| 74 | - kfs.write("src/main/resources/rerun.drl", kieServices.getResources() | |
| 73 | + "/rules/kBase1_core_validate.drl"), "UTF-8")); | |
| 74 | + kfs.write("src/main/resources/kBase1_core_functions.drl", kieServices.getResources() | |
| 75 | 75 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 76 | - "/rules/rerun.drl"), "UTF-8")); | |
| 77 | - kfs.write("src/main/resources/validplan.drl", kieServices.getResources() | |
| 78 | - .newInputStreamResource(this.getClass().getResourceAsStream( | |
| 79 | - "/rules/validplan.drl"), "UTF-8")); | |
| 76 | + "/rules/kBase1_core_functions.drl"), "UTF-8")); | |
| 80 | 77 | // TODO:还有其他drl.... |
| 81 | 78 | |
| 82 | 79 | // 4、创建KieBuilder,使用KieFileSystem构建 |
| ... | ... | @@ -134,9 +131,9 @@ public class MyDroolsConfiguration { |
| 134 | 131 | // 这里使用文件的形式写入,TODO:以后考虑从数据库中读drl写入 |
| 135 | 132 | // 注意kfs写的时候如果指定path,强制为src/main/resources/加上文件名,还有就是文件名不要重复否则会覆盖的 |
| 136 | 133 | |
| 137 | - kfs.write("src/main/resources/ruleWrap.drl", kieServices.getResources() | |
| 134 | + kfs.write("src/main/resources/kBase2_wrap_rule.drl", kieServices.getResources() | |
| 138 | 135 | .newInputStreamResource(this.getClass().getResourceAsStream( |
| 139 | - "/rules/ruleWrap.drl"), "UTF-8")); | |
| 136 | + "/rules/kBase2_wrap_rule.drl"), "UTF-8")); | |
| 140 | 137 | |
| 141 | 138 | // TODO:还有其他drl.... |
| 142 | 139 | |
| ... | ... | @@ -161,4 +158,52 @@ public class MyDroolsConfiguration { |
| 161 | 158 | |
| 162 | 159 | return kieBase; |
| 163 | 160 | } |
| 161 | + | |
| 162 | + /** | |
| 163 | + * 验证相关的drl知识库。 | |
| 164 | + * @return | |
| 165 | + */ | |
| 166 | + @Bean(name = "KBase3") | |
| 167 | + public KieBase myKieBase3() { | |
| 168 | + KieServices kieServices = KieServices.Factory.get(); | |
| 169 | + KieModuleModel kieModuleModel = kieServices.newKieModuleModel(); | |
| 170 | + KieBaseModel kieBaseModel = kieModuleModel.newKieBaseModel("KBase3") | |
| 171 | + .setDefault(true) | |
| 172 | + .setEqualsBehavior(EqualityBehaviorOption.EQUALITY) | |
| 173 | + .setEventProcessingMode(EventProcessingOption.STREAM); | |
| 174 | + kieBaseModel.newKieSessionModel("KSession1") | |
| 175 | + .setDefault(true) | |
| 176 | + .setType(KieSessionModel.KieSessionType.STATEFUL) | |
| 177 | + .setClockType(ClockTypeOption.get("realtime")); | |
| 178 | + | |
| 179 | + KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); | |
| 180 | + kieFileSystem.writeKModuleXML(kieModuleModel.toXML()); | |
| 181 | + | |
| 182 | + kieFileSystem.write( | |
| 183 | + "src/main/resources/kBase3_validate_timetable.drl", | |
| 184 | + kieServices.getResources().newInputStreamResource( | |
| 185 | + this.getClass().getResourceAsStream("/rules/kBase3_validate_timetable.drl"), | |
| 186 | + "UTF-8")); | |
| 187 | + kieFileSystem.write( | |
| 188 | + "src/main/resources/kbase3_validate_rule.drl", | |
| 189 | + kieServices.getResources().newInputStreamResource( | |
| 190 | + this.getClass().getResourceAsStream("/rules/kBase3_validate_rule.drl"), | |
| 191 | + "UTF-8")); | |
| 192 | + | |
| 193 | + KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll(); | |
| 194 | + Results results = kieBuilder.getResults(); | |
| 195 | + if (results.hasMessages(Message.Level.ERROR)) { | |
| 196 | + throw new IllegalStateException("构建drools6错误:" + results.getMessages()); | |
| 197 | + } | |
| 198 | + | |
| 199 | + ReleaseId releaseId = kieServices.getRepository().getDefaultReleaseId(); | |
| 200 | + KieContainer kieContainer = kieServices.newKieContainer(releaseId); | |
| 201 | + | |
| 202 | + KieBaseConfiguration kieBaseConfiguration = kieServices.newKieBaseConfiguration(); | |
| 203 | + KieBase kieBase = kieContainer.newKieBase("KBase3", kieBaseConfiguration); | |
| 204 | + | |
| 205 | + return kieBase; | |
| 206 | + | |
| 207 | + } | |
| 208 | + | |
| 164 | 209 | } | ... | ... |
src/main/java/com/bsth/service/schedule/rules/ScheduleRuleService.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/ScheduleRuleService.java
| 1 | -package com.bsth.service.schedule.rules; | |
| 1 | +package com.bsth.service.schedule.impl.plan; | |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlan; |
| 4 | 4 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 5 | 5 | import com.bsth.entity.schedule.temp.SchedulePlanRuleResult; |
| 6 | -import com.bsth.service.schedule.rules.rerun.RerunRule_input; | |
| 6 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input; | |
| 7 | 7 | |
| 8 | 8 | import java.util.Date; |
| 9 | 9 | import java.util.List; | ... | ... |
src/main/java/com/bsth/service/schedule/rules/ScheduleRuleServiceImpl.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/ScheduleRuleServiceImpl.java
| 1 | -package com.bsth.service.schedule.rules; | |
| 1 | +package com.bsth.service.schedule.impl.plan; | |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlan; |
| 4 | 4 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 5 | 5 | import com.bsth.entity.schedule.temp.SchedulePlanRuleResult; |
| 6 | -import com.bsth.service.schedule.rules.rerun.RerunRule_input; | |
| 6 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input; | |
| 7 | 7 | import org.slf4j.Logger; |
| 8 | 8 | import org.slf4j.LoggerFactory; |
| 9 | 9 | import org.springframework.beans.factory.annotation.Autowired; | ... | ... |
src/main/java/com/bsth/service/schedule/rules/plan/PlanCalcuParam_input.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/plan/PlanCalcuParam_input.java
| 1 | -package com.bsth.service.schedule.rules.plan; | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.plan; | |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlan; |
| 4 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; | |
| 5 | -import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output; | |
| 4 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResults_output; | |
| 5 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfoResults_output; | |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * 排班规则-规则输入参数。 | ... | ... |
src/main/java/com/bsth/service/schedule/rules/plan/PlanResult.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/plan/PlanResult.java
src/main/java/com/bsth/service/schedule/rules/plan/readme.txt renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/plan/readme.txt
src/main/java/com/bsth/service/schedule/rules/rerun/RerunRule_input.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/rerun/RerunRule_input.java
src/main/java/com/bsth/service/schedule/rules/rerun/RerunRule_param.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/rerun/RerunRule_param.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/GidFbFcnoFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/GidFbFcnoFunction.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/GidFbTimeFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/GidFbTimeFunction.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/GidsCountFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/GidsCountFunction.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleCalcuParam_input.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/ScheduleCalcuParam_input.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResult_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/ScheduleResult_output.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResults_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/ScheduleResults_output.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_Type.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/ScheduleRule_Type.java
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_input.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/shiftloop/ScheduleRule_input.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/LpInfoResult_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/LpInfoResult_output.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/LpInfoResultsFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/LpInfoResultsFunction.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/LpInfoResults_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/LpInfoResults_output.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/MinRuleQyrqFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/MinRuleQyrqFunction.java
| 1 | -package com.bsth.service.schedule.rules.ttinfo; | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo; | |
| 2 | 2 | |
| 3 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; | |
| 3 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_input; | |
| 4 | 4 | import org.joda.time.DateTime; |
| 5 | 5 | import org.kie.api.runtime.rule.AccumulateFunction; |
| 6 | 6 | ... | ... |
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfoCalcuParam_input.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/TTInfoCalcuParam_input.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfoResult_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/TTInfoResult_output.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfoResults_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/TTInfoResults_output.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfo_input.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/TTInfo_input.java
src/main/java/com/bsth/service/schedule/rules/ttinfo/readme.txt renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/ttinfo/readme.txt
src/main/java/com/bsth/service/schedule/rules/validate/ValidRepeatBcFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/validate/ValidRepeatBcFunction.java
src/main/java/com/bsth/service/schedule/rules/validate/ValidWantLpFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/validate/ValidWantLpFunction.java
| 1 | -package com.bsth.service.schedule.rules.validate; | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.validate; | |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 4 | -import com.bsth.service.schedule.rules.ttinfo.LpInfoResult_output; | |
| 4 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResult_output; | |
| 5 | 5 | import org.kie.api.runtime.rule.AccumulateFunction; |
| 6 | 6 | |
| 7 | 7 | import java.io.*; | ... | ... |
src/main/java/com/bsth/service/schedule/rules/validate/ValidWholeRerunBcFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/validate/ValidWholeRerunBcFunction.java
src/main/java/com/bsth/service/schedule/rules/validate/ValidateParam.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/validate/ValidateParam.java
src/main/java/com/bsth/service/schedule/rules/validate/ValidateResource.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/validate/ValidateResource.java
| 1 | -package com.bsth.service.schedule.rules.validate; | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.validate; | |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| 4 | -import com.bsth.service.schedule.rules.ttinfo.LpInfoResult_output; | |
| 4 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResult_output; | |
| 5 | 5 | |
| 6 | 6 | import java.util.Date; |
| 7 | 7 | import java.util.List; | ... | ... |
src/main/java/com/bsth/service/schedule/rules/validate/ValidateResults_output.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase1/core/validate/ValidateResults_output.java
src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/rule/CalcuParam.java
0 → 100644
| 1 | +package com.bsth.service.schedule.impl.plan.kBase3.validate.rule; | |
| 2 | + | |
| 3 | +import org.joda.time.DateTime; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 计算用参数。 | |
| 7 | + */ | |
| 8 | +public class CalcuParam { | |
| 9 | + /** 线路Id */ | |
| 10 | + private Integer xlId; | |
| 11 | + | |
| 12 | + /** 计划开始计算日期 */ | |
| 13 | + private DateTime fromDate; | |
| 14 | + /** 计划结束计算日期 */ | |
| 15 | + private DateTime toDate; | |
| 16 | + | |
| 17 | + public Integer getXlId() { | |
| 18 | + return xlId; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public void setXlId(Integer xlId) { | |
| 22 | + this.xlId = xlId; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public DateTime getFromDate() { | |
| 26 | + return fromDate; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public void setFromDate(DateTime fromDate) { | |
| 30 | + this.fromDate = fromDate; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public DateTime getToDate() { | |
| 34 | + return toDate; | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void setToDate(DateTime toDate) { | |
| 38 | + this.toDate = toDate; | |
| 39 | + } | |
| 40 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/rule/ErrorInfoFunction.java
0 → 100644
| 1 | +package com.bsth.service.schedule.impl.plan.kBase3.validate.rule; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.bsth.entity.schedule.EmployeeConfigInfo; | |
| 5 | +import com.bsth.entity.schedule.GuideboardInfo; | |
| 6 | +import org.apache.commons.lang3.StringUtils; | |
| 7 | +import org.apache.commons.lang3.math.NumberUtils; | |
| 8 | +import org.kie.api.runtime.rule.AccumulateFunction; | |
| 9 | + | |
| 10 | +import java.io.*; | |
| 11 | +import java.util.HashMap; | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 查找错误函数。 | |
| 16 | + */ | |
| 17 | +public class ErrorInfoFunction implements AccumulateFunction { | |
| 18 | + @Override | |
| 19 | + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | |
| 20 | + | |
| 21 | + } | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + public void writeExternal(ObjectOutput out) throws IOException { | |
| 25 | + | |
| 26 | + } | |
| 27 | + | |
| 28 | + protected static class ErrorInfoContext implements Externalizable { | |
| 29 | + /** 错误数量 */ | |
| 30 | + public Integer errorCount = 0; | |
| 31 | + /** 错误Map,Map<规则id,errorInfo> */ | |
| 32 | + public Map<Long, ValidateRuleResult.ErrorInfo> errorInfoMap = new HashMap<>(); | |
| 33 | + | |
| 34 | + public ErrorInfoContext() { | |
| 35 | + | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | |
| 40 | + errorCount = in.readInt(); | |
| 41 | + errorInfoMap = (Map<Long, ValidateRuleResult.ErrorInfo>) in.readObject(); | |
| 42 | + | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public void writeExternal(ObjectOutput out) throws IOException { | |
| 47 | + out.writeInt(errorCount); | |
| 48 | + out.writeObject(errorInfoMap); | |
| 49 | + } | |
| 50 | + | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public Serializable createContext() { | |
| 55 | + return new ErrorInfoContext(); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void init(Serializable serializable) throws Exception { | |
| 60 | + ErrorInfoContext errorInfoContext = (ErrorInfoContext) serializable; | |
| 61 | + errorInfoContext.errorCount = 0; | |
| 62 | + errorInfoContext.errorInfoMap = new HashMap<>(); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @Override | |
| 66 | + public void accumulate(Serializable serializable, Object o) { | |
| 67 | + ErrorInfoContext errorInfoContext = (ErrorInfoContext) serializable; | |
| 68 | + WrapInput wrapInput = (WrapInput) o; | |
| 69 | + | |
| 70 | + ValidateRuleResult.ErrorInfo errorInfo = new ValidateRuleResult.ErrorInfo(); | |
| 71 | + errorInfo.setRuleId(wrapInput.getRuleId()); | |
| 72 | + errorInfo.setClZbh(wrapInput.getClZbh()); | |
| 73 | + errorInfo.setQyrq(wrapInput.getQyrq()); | |
| 74 | + | |
| 75 | + // 1、车辆配置验证 | |
| 76 | + if (StringUtils.isNotEmpty(wrapInput.getClZbh())) { // 自编号不能为空 | |
| 77 | + if (wrapInput.getCcInfos().get(wrapInput.getClZbh()) == null) { // 车辆配置不在当前线路上 | |
| 78 | + errorInfo.getErrorDescList().add("车辆配置不在当前线路,请重新编辑保存!"); | |
| 79 | + } | |
| 80 | + } else { | |
| 81 | + errorInfo.getErrorDescList().add("自编号不能为空,请重新编辑保存!"); | |
| 82 | + } | |
| 83 | + | |
| 84 | + // 2、路牌id,路牌名字,路牌起始索引验证 | |
| 85 | + if (StringUtils.isNotEmpty(wrapInput.getLpIds()) && | |
| 86 | + StringUtils.isNotEmpty(wrapInput.getLpNames())) { // 冗余的路牌id和路牌名字都不能为空 | |
| 87 | + String[] lpIds = wrapInput.getLpIds().split(","); | |
| 88 | + String[] lpNames = wrapInput.getLpNames().split(","); | |
| 89 | + if (lpIds.length == lpNames.length) { // 路牌id和路牌名字个数一致 | |
| 90 | + for (int i = 0; i < lpIds.length; i++) { | |
| 91 | + if (!NumberUtils.isDigits(lpIds[i])) { // 冗余路牌id必须是数字 | |
| 92 | + errorInfo.getErrorDescList().add("冗余路牌id必须是数字,请重新编辑保存!"); | |
| 93 | + break; | |
| 94 | + } | |
| 95 | + | |
| 96 | + GuideboardInfo lpInfo = wrapInput.getLpInfos().get(NumberUtils.toLong(lpIds[i])); | |
| 97 | + if (lpInfo == null) { // 路牌不在当前线路上 | |
| 98 | + errorInfo.getErrorDescList().add("路牌不在当前线路上,请重新编辑保存!"); | |
| 99 | + } else { | |
| 100 | + if (StringUtils.isEmpty(lpNames[i]) || | |
| 101 | + !(lpNames[i].equals(lpInfo.getLpName()))) { // 路牌id和路牌名字不对应 | |
| 102 | + errorInfo.getErrorDescList().add("路牌id和路牌名字不对应,请重新编辑保存!"); | |
| 103 | + break; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + if (wrapInput.getLpStartIndex() < 1 || | |
| 109 | + wrapInput.getLpStartIndex() > lpIds.length) { // 路牌起始索引溢出 | |
| 110 | + errorInfo.getErrorDescList().add("路牌起始索引溢出,请重新编辑保存!"); | |
| 111 | + } | |
| 112 | + } else { | |
| 113 | + errorInfo.getErrorDescList().add("路牌id和路牌名字个数不一致,请重新编辑保存!"); | |
| 114 | + } | |
| 115 | + } else { | |
| 116 | + errorInfo.getErrorDescList().add("冗余的路牌id和路牌名字都不能为空,请重新编辑保存!"); | |
| 117 | + } | |
| 118 | + | |
| 119 | + // 3、人员配置,搭班编码,人员起始索引验证 | |
| 120 | + if (StringUtils.isNotEmpty(wrapInput.getEcIds()) && | |
| 121 | + StringUtils.isNotEmpty(wrapInput.getEcDbbms())) { // 冗余的人员配置id和人员搭班编码都不能为空 | |
| 122 | + String[] ecIds = wrapInput.getEcIds().split(","); | |
| 123 | + String[] ecDbbms = wrapInput.getEcDbbms().split(","); | |
| 124 | + if (ecIds.length == ecDbbms.length) { // 人员配置id和搭班编码个数一致 | |
| 125 | + for (int i = 0; i < ecIds.length; i++) { | |
| 126 | + if (ecIds[i].contains("-")) { // 分班标识 | |
| 127 | + String[] fb_ecIds = ecIds[i].split("-"); | |
| 128 | + String[] fb_ecDbbms = ecDbbms[i].split("-"); | |
| 129 | + if (fb_ecIds.length != 2 || fb_ecDbbms.length != 2) { // 只能早晚分班 | |
| 130 | + errorInfo.getErrorDescList().add("只能早晚分班,请重新编辑保存!"); | |
| 131 | + break; | |
| 132 | + } else { | |
| 133 | + EmployeeConfigInfo fb_ecInfo1 = wrapInput.getEcInfos().get(NumberUtils.toLong(fb_ecIds[0])); | |
| 134 | + EmployeeConfigInfo fb_ecInfo2 = wrapInput.getEcInfos().get(NumberUtils.toLong(fb_ecIds[1])); | |
| 135 | + if (fb_ecInfo1 == null || fb_ecInfo2 == null) { // 分班的人员配置不在当前线路 | |
| 136 | + errorInfo.getErrorDescList().add("分班的人员配置不在当前线路,请重新编辑保存!"); | |
| 137 | + break; | |
| 138 | + } else { | |
| 139 | + if (StringUtils.isEmpty(fb_ecDbbms[0]) || | |
| 140 | + StringUtils.isEmpty(fb_ecDbbms[1]) || | |
| 141 | + !(fb_ecDbbms[0].equals(fb_ecInfo1.getDbbm())) || | |
| 142 | + !(fb_ecDbbms[1].equals(fb_ecInfo2.getDbbm()))) { // 分班人员配置id和搭班编码不对应 | |
| 143 | + errorInfo.getErrorDescList().add("分班人员配置id和搭班编码不对应,请重新编辑保存!"); | |
| 144 | + break; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + } else { | |
| 150 | + if (!NumberUtils.isDigits(ecIds[i])) { // 冗余的人员配置id必须是数字 | |
| 151 | + errorInfo.getErrorDescList().add("冗余的人员配置id必须是数字,请重新编辑保存!"); | |
| 152 | + break; | |
| 153 | + } | |
| 154 | + | |
| 155 | + EmployeeConfigInfo ecInfo = wrapInput.getEcInfos().get(NumberUtils.toLong(ecIds[i])); | |
| 156 | + if (ecInfo == null) { // 人员配置不在当前线路 | |
| 157 | + errorInfo.getErrorDescList().add("人员配置不在当前线路,请重新编辑保存!"); | |
| 158 | + break; | |
| 159 | + } else { | |
| 160 | + if (StringUtils.isEmpty(ecDbbms[i]) || | |
| 161 | + !(ecDbbms[i].equals(ecInfo.getDbbm()))) { // 人员配置id和搭班编码不对应 | |
| 162 | + errorInfo.getErrorDescList().add("人员配置id和搭班编码不对应,请重新编辑保存!"); | |
| 163 | + break; | |
| 164 | + } | |
| 165 | + } | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 169 | + if (wrapInput.getEcStartIndex() < 1 || | |
| 170 | + wrapInput.getEcStartIndex() > ecIds.length) { // 人员起始索引溢出 | |
| 171 | + errorInfo.getErrorDescList().add("人员起始索引溢出,请重新编辑保存!"); | |
| 172 | + } | |
| 173 | + } else { | |
| 174 | + errorInfo.getErrorDescList().add("人员配置id和搭班编码个数不一致,请重新编辑保存!"); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + | |
| 178 | + if (errorInfo.getErrorDescList().size() > 0) { | |
| 179 | + errorInfoContext.errorCount ++; | |
| 180 | + errorInfoContext.errorInfoMap.put(wrapInput.getRuleId(), errorInfo); | |
| 181 | + } | |
| 182 | + | |
| 183 | + } | |
| 184 | + | |
| 185 | + @Override | |
| 186 | + public void reverse(Serializable serializable, Object o) throws Exception { | |
| 187 | + ErrorInfoContext errorInfoContext = (ErrorInfoContext) serializable; | |
| 188 | + WrapInput wrapInput = (WrapInput) o; | |
| 189 | + | |
| 190 | + if (errorInfoContext.errorInfoMap.get(wrapInput.getRuleId()) != null) { | |
| 191 | + errorInfoContext.errorInfoMap.remove(wrapInput.getRuleId()); | |
| 192 | + errorInfoContext.errorCount --; | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 196 | + @Override | |
| 197 | + public Object getResult(Serializable serializable) throws Exception { | |
| 198 | + ErrorInfoContext errorInfoContext = (ErrorInfoContext) serializable; | |
| 199 | + return errorInfoContext.errorInfoMap; | |
| 200 | + } | |
| 201 | + | |
| 202 | + @Override | |
| 203 | + public boolean supportsReverse() { | |
| 204 | + return true; | |
| 205 | + } | |
| 206 | + | |
| 207 | + @Override | |
| 208 | + public Class<?> getResultType() { | |
| 209 | + return Map.class; | |
| 210 | + } | |
| 211 | + | |
| 212 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/rule/ValidateRuleResult.java
0 → 100644
| 1 | +package com.bsth.service.schedule.impl.plan.kBase3.validate.rule; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.Date; | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 输出结果值。 | |
| 9 | + */ | |
| 10 | +public class ValidateRuleResult { | |
| 11 | + /** 线路id */ | |
| 12 | + private Integer xlId; | |
| 13 | + /** 规则总数量 */ | |
| 14 | + private Integer count; | |
| 15 | + /** 启用的规则数量 */ | |
| 16 | + private Integer qyCount; | |
| 17 | + /** 启用规则中的错误数量 */ | |
| 18 | + private Integer qyErrorCount; | |
| 19 | + /** 错误列表 */ | |
| 20 | + private List<ErrorInfo> errorInfos = new ArrayList<>(); | |
| 21 | + | |
| 22 | + public Integer getXlId() { | |
| 23 | + return xlId; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public void setXlId(Integer xlId) { | |
| 27 | + this.xlId = xlId; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public Integer getCount() { | |
| 31 | + return count; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public void setCount(Integer count) { | |
| 35 | + this.count = count; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public Integer getQyCount() { | |
| 39 | + return qyCount; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void setQyCount(Integer qyCount) { | |
| 43 | + this.qyCount = qyCount; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public Integer getQyErrorCount() { | |
| 47 | + return qyErrorCount; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setQyErrorCount(Integer qyErrorCount) { | |
| 51 | + this.qyErrorCount = qyErrorCount; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public List<ErrorInfo> getErrorInfos() { | |
| 55 | + return errorInfos; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setErrorInfos(List<ErrorInfo> errorInfos) { | |
| 59 | + this.errorInfos = errorInfos; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public static class ErrorInfo { | |
| 63 | + /** 规则id */ | |
| 64 | + private Long ruleId; | |
| 65 | + /** 车辆自编号 */ | |
| 66 | + private String clZbh; | |
| 67 | + /** 启用日期 */ | |
| 68 | + private Date qyrq; | |
| 69 | + /** 错误描述 */ | |
| 70 | + private List<String> errorDescList = new ArrayList<>(); | |
| 71 | + | |
| 72 | + public Long getRuleId() { | |
| 73 | + return ruleId; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public void setRuleId(Long ruleId) { | |
| 77 | + this.ruleId = ruleId; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public String getClZbh() { | |
| 81 | + return clZbh; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public void setClZbh(String clZbh) { | |
| 85 | + this.clZbh = clZbh; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public Date getQyrq() { | |
| 89 | + return qyrq; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public void setQyrq(Date qyrq) { | |
| 93 | + this.qyrq = qyrq; | |
| 94 | + } | |
| 95 | + | |
| 96 | + public List<String> getErrorDescList() { | |
| 97 | + return errorDescList; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public void setErrorDescList(List<String> errorDescList) { | |
| 101 | + this.errorDescList = errorDescList; | |
| 102 | + } | |
| 103 | + } | |
| 104 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/rule/WrapInput.java
0 → 100644
| 1 | +package com.bsth.service.schedule.impl.plan.kBase3.validate.rule; | |
| 2 | + | |
| 3 | +import com.bsth.entity.schedule.CarConfigInfo; | |
| 4 | +import com.bsth.entity.schedule.EmployeeConfigInfo; | |
| 5 | +import com.bsth.entity.schedule.GuideboardInfo; | |
| 6 | +import com.bsth.entity.schedule.rule.ScheduleRule1Flat; | |
| 7 | +import org.springframework.util.CollectionUtils; | |
| 8 | + | |
| 9 | +import java.util.*; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 聚合输入的待判定数据。 | |
| 13 | + */ | |
| 14 | +public class WrapInput { | |
| 15 | + /** 线路Id */ | |
| 16 | + private Integer xlId; | |
| 17 | + /** 车辆自编号 */ | |
| 18 | + private String clZbh; | |
| 19 | + /** 路牌id列表 */ | |
| 20 | + private String lpIds; | |
| 21 | + /** 路牌名字列表 */ | |
| 22 | + private String lpNames; | |
| 23 | + /** 人员配置列表 */ | |
| 24 | + private String ecIds; | |
| 25 | + /** 人员搭班编码列表 */ | |
| 26 | + private String ecDbbms; | |
| 27 | + /** 路牌循环起始索引 */ | |
| 28 | + private Integer lpStartIndex; | |
| 29 | + /** 人员循环起始索引 */ | |
| 30 | + private Integer ecStartIndex; | |
| 31 | + /** 规则id */ | |
| 32 | + private Long ruleId; | |
| 33 | + /** 启用日期 */ | |
| 34 | + private Date qyrq; | |
| 35 | + | |
| 36 | + private Map<String, CarConfigInfo> ccInfos = new HashMap<>(); | |
| 37 | + private Map<Long, GuideboardInfo> lpInfos = new HashMap<>(); | |
| 38 | + private Map<Long, EmployeeConfigInfo> ecInfos = new HashMap<>(); | |
| 39 | + | |
| 40 | + public WrapInput(ScheduleRule1Flat r, | |
| 41 | + Map<String, CarConfigInfo> cc, | |
| 42 | + Map<Long, GuideboardInfo> lp, | |
| 43 | + Map<Long, EmployeeConfigInfo> ec) { | |
| 44 | + this.xlId = r.getXl().getId(); | |
| 45 | + this.clZbh = r.getCarConfigInfo().getCl().getInsideCode(); | |
| 46 | + this.lpIds = r.getLpIds(); | |
| 47 | + this.lpNames = r.getLpNames(); | |
| 48 | + this.ecIds = r.getRyConfigIds(); | |
| 49 | + this.ecDbbms = r.getRyDbbms(); | |
| 50 | + this.lpStartIndex = r.getLpStart(); | |
| 51 | + this.ecStartIndex = r.getRyStart(); | |
| 52 | + this.ruleId = r.getId(); | |
| 53 | + this.qyrq = r.getQyrq(); | |
| 54 | + | |
| 55 | + if (!CollectionUtils.isEmpty(cc)) { | |
| 56 | + this.ccInfos.putAll(cc); | |
| 57 | + } | |
| 58 | + if (!CollectionUtils.isEmpty(lp)) { | |
| 59 | + this.lpInfos.putAll(lp); | |
| 60 | + } | |
| 61 | + if (!CollectionUtils.isEmpty(ec)) { | |
| 62 | + this.ecInfos.putAll(ec); | |
| 63 | + } | |
| 64 | + | |
| 65 | + } | |
| 66 | + | |
| 67 | + public Integer getXlId() { | |
| 68 | + return xlId; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public void setXlId(Integer xlId) { | |
| 72 | + this.xlId = xlId; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public String getClZbh() { | |
| 76 | + return clZbh; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public void setClZbh(String clZbh) { | |
| 80 | + this.clZbh = clZbh; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public String getLpIds() { | |
| 84 | + return lpIds; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public void setLpIds(String lpIds) { | |
| 88 | + this.lpIds = lpIds; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public String getLpNames() { | |
| 92 | + return lpNames; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public void setLpNames(String lpNames) { | |
| 96 | + this.lpNames = lpNames; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public String getEcIds() { | |
| 100 | + return ecIds; | |
| 101 | + } | |
| 102 | + | |
| 103 | + public void setEcIds(String ecIds) { | |
| 104 | + this.ecIds = ecIds; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public String getEcDbbms() { | |
| 108 | + return ecDbbms; | |
| 109 | + } | |
| 110 | + | |
| 111 | + public void setEcDbbms(String ecDbbms) { | |
| 112 | + this.ecDbbms = ecDbbms; | |
| 113 | + } | |
| 114 | + | |
| 115 | + public Integer getLpStartIndex() { | |
| 116 | + return lpStartIndex; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void setLpStartIndex(Integer lpStartIndex) { | |
| 120 | + this.lpStartIndex = lpStartIndex; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public Integer getEcStartIndex() { | |
| 124 | + return ecStartIndex; | |
| 125 | + } | |
| 126 | + | |
| 127 | + public void setEcStartIndex(Integer ecStartIndex) { | |
| 128 | + this.ecStartIndex = ecStartIndex; | |
| 129 | + } | |
| 130 | + | |
| 131 | + public Long getRuleId() { | |
| 132 | + return ruleId; | |
| 133 | + } | |
| 134 | + | |
| 135 | + public void setRuleId(Long ruleId) { | |
| 136 | + this.ruleId = ruleId; | |
| 137 | + } | |
| 138 | + | |
| 139 | + public Date getQyrq() { | |
| 140 | + return qyrq; | |
| 141 | + } | |
| 142 | + | |
| 143 | + public void setQyrq(Date qyrq) { | |
| 144 | + this.qyrq = qyrq; | |
| 145 | + } | |
| 146 | + | |
| 147 | + public Map<String, CarConfigInfo> getCcInfos() { | |
| 148 | + return ccInfos; | |
| 149 | + } | |
| 150 | + | |
| 151 | + public void setCcInfos(Map<String, CarConfigInfo> ccInfos) { | |
| 152 | + this.ccInfos = ccInfos; | |
| 153 | + } | |
| 154 | + | |
| 155 | + public Map<Long, GuideboardInfo> getLpInfos() { | |
| 156 | + return lpInfos; | |
| 157 | + } | |
| 158 | + | |
| 159 | + public void setLpInfos(Map<Long, GuideboardInfo> lpInfos) { | |
| 160 | + this.lpInfos = lpInfos; | |
| 161 | + } | |
| 162 | + | |
| 163 | + public Map<Long, EmployeeConfigInfo> getEcInfos() { | |
| 164 | + return ecInfos; | |
| 165 | + } | |
| 166 | + | |
| 167 | + public void setEcInfos(Map<Long, EmployeeConfigInfo> ecInfos) { | |
| 168 | + this.ecInfos = ecInfos; | |
| 169 | + } | |
| 170 | +} | ... | ... |
src/main/java/com/bsth/service/schedule/rules/ttinfo2/CalcuParam.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/timetable/CalcuParam.java
src/main/java/com/bsth/service/schedule/rules/ttinfo2/ErrorBcCountFunction.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/timetable/ErrorBcCountFunction.java
src/main/java/com/bsth/service/schedule/rules/ttinfo2/Result.java renamed to src/main/java/com/bsth/service/schedule/impl/plan/kBase3/validate/timetable/Result.java
src/main/resources/rules/functions.drl deleted
100644 → 0
| 1 | -package com.bsth.service.schedule; | |
| 2 | - | |
| 3 | -import accumulate com.bsth.service.schedule.rules.ttinfo2.ErrorBcCountFunction ecount; | |
| 4 | -import accumulate com.bsth.service.schedule.rules.shiftloop.GidsCountFunction gidscount; | |
| 5 | -import accumulate com.bsth.service.schedule.rules.shiftloop.GidFbTimeFunction gidfbtime; | |
| 6 | -import accumulate com.bsth.service.schedule.rules.shiftloop.GidFbFcnoFunction gidfbfcno; | |
| 7 | -import accumulate com.bsth.service.schedule.rules.ttinfo.LpInfoResultsFunction lpinforesult; | |
| 8 | -import accumulate com.bsth.service.schedule.rules.ttinfo.MinRuleQyrqFunction minruleqyrq; | |
| 9 | -import accumulate com.bsth.service.schedule.rules.validate.ValidRepeatBcFunction vrb; | |
| 10 | -import accumulate com.bsth.service.schedule.rules.validate.ValidWholeRerunBcFunction vwrb; | |
| 11 | -import accumulate com.bsth.service.schedule.rules.validate.ValidWantLpFunction vwlp; |
src/main/resources/rules/kBase1_core_functions.drl
0 → 100644
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core; | |
| 2 | + | |
| 3 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.GidsCountFunction gidscount; | |
| 4 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.GidFbTimeFunction gidfbtime; | |
| 5 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.GidFbFcnoFunction gidfbfcno; | |
| 6 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResultsFunction lpinforesult; | |
| 7 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.MinRuleQyrqFunction minruleqyrq; | |
| 8 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidRepeatBcFunction vrb; | |
| 9 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidWholeRerunBcFunction vwrb; | |
| 10 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidWantLpFunction vwlp; | ... | ... |
src/main/resources/rules/plan.drl renamed to src/main/resources/rules/kBase1_core_plan.drl
| 1 | -package com.bsth.service.schedule.plan; | |
| 2 | - | |
| 3 | -import org.joda.time.*; | |
| 4 | -import java.util.*; | |
| 5 | - | |
| 6 | -import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input; | |
| 7 | -import com.bsth.service.schedule.rules.plan.PlanResult; | |
| 8 | - | |
| 9 | -import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 10 | -import com.bsth.repository.schedule.CarConfigInfoRepository; | |
| 11 | -import com.bsth.repository.schedule.EmployeeConfigInfoRepository; | |
| 12 | -import com.bsth.repository.LineRepository; | |
| 13 | -import com.bsth.repository.BusinessRepository; | |
| 14 | - | |
| 15 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; | |
| 16 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; | |
| 17 | -import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output; | |
| 18 | -import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output; | |
| 19 | -import com.bsth.entity.Line; | |
| 20 | -import com.bsth.entity.Business; | |
| 21 | - | |
| 22 | -import com.bsth.entity.schedule.CarConfigInfo; | |
| 23 | -import com.bsth.entity.schedule.EmployeeConfigInfo; | |
| 24 | -import com.bsth.entity.schedule.TTInfo; | |
| 25 | -import com.bsth.entity.schedule.TTInfoDetail; | |
| 26 | -import com.bsth.entity.schedule.SchedulePlanInfo; | |
| 27 | - | |
| 28 | -import org.slf4j.Logger | |
| 29 | -import org.joda.time.format.DateTimeFormat | |
| 30 | -import org.apache.commons.lang3.StringUtils | |
| 31 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type; | |
| 32 | - | |
| 33 | - | |
| 34 | -// 全局日志类(一般使用调用此规则的service类) | |
| 35 | -global Logger log; | |
| 36 | - | |
| 37 | -global TTInfoDetailRepository tTInfoDetailRepository; | |
| 38 | -global CarConfigInfoRepository carConfigInfoRepository; | |
| 39 | -global EmployeeConfigInfoRepository employeeConfigInfoRepository; | |
| 40 | -global LineRepository lineRepository; | |
| 41 | -global BusinessRepository businessRepository; | |
| 42 | - | |
| 43 | -// 输出 | |
| 44 | -global PlanResult planResult; | |
| 45 | - | |
| 46 | -function Map xlidParams(String xlid) { | |
| 47 | - Map param = new HashMap(); | |
| 48 | - param.put("xl.id_eq", Integer.valueOf(xlid)); | |
| 49 | - return param; | |
| 50 | -} | |
| 51 | - | |
| 52 | -function List ecList(EmployeeConfigInfoRepository repo, String ecids) { | |
| 53 | - List<String> ids = Arrays.asList(ecids.split("-")); | |
| 54 | - List rst = new ArrayList(); | |
| 55 | - for (int i = 0; i < ids.size(); i++) { | |
| 56 | - rst.add(repo.findOne(Long.parseLong(ids.get(i)))); | |
| 57 | - } | |
| 58 | - return rst; | |
| 59 | -} | |
| 60 | - | |
| 61 | -function LocalTime fcsjTime(String fcsj) { | |
| 62 | - if ("NULL".equals(fcsj)) { | |
| 63 | - return null; | |
| 64 | - } | |
| 65 | - return LocalTime.parse(fcsj, DateTimeFormat.forPattern("HH:mm")); | |
| 66 | -} | |
| 67 | - | |
| 68 | -function String ttInfoId_sd(Map map, DateTime sd) { | |
| 69 | - TTInfoResult_output ttInfoResult_output = (TTInfoResult_output) map.get(sd); | |
| 70 | - return ttInfoResult_output.getTtInfoId(); | |
| 71 | -} | |
| 72 | - | |
| 73 | -function Map gsMap(List gses) { | |
| 74 | - Map gsMap = new HashMap(); | |
| 75 | - for (int i = 0; i < gses.size(); i++) { | |
| 76 | - Business gs = (Business) gses.get(i); | |
| 77 | - if (StringUtils.isNotEmpty(gs.getBusinessCode())) { | |
| 78 | - if ("88".equals(gs.getUpCode())) { // 浦东公交 | |
| 79 | - gsMap.put(gs.getBusinessCode(), gs); | |
| 80 | - } | |
| 81 | - if (gs.getBusinessCode().equals(gs.getUpCode())) { // 闵行,青浦 | |
| 82 | - gsMap.put(gs.getBusinessCode(), gs); | |
| 83 | - } | |
| 84 | - } | |
| 85 | - } | |
| 86 | - return gsMap; | |
| 87 | -} | |
| 88 | - | |
| 89 | -function Map fgsMap(List gses) { | |
| 90 | - // 这里简单将 businessCode和upCode合并 | |
| 91 | - Map fgsMap = new HashMap(); | |
| 92 | - for (int i = 0; i < gses.size(); i++) { | |
| 93 | - Business gs = (Business) gses.get(i); | |
| 94 | - if (StringUtils.isNotEmpty(gs.getBusinessCode()) && StringUtils.isNotEmpty(gs.getUpCode())) { | |
| 95 | - fgsMap.put(gs.getUpCode() + "_" + gs.getBusinessCode(), gs); | |
| 96 | - } | |
| 97 | - } | |
| 98 | - return fgsMap; | |
| 99 | -} | |
| 100 | - | |
| 101 | -/* | |
| 102 | - 规则说明: | |
| 103 | - 根据循环规则输出,时刻表选择规则输出,组合计算排班明细 | |
| 104 | -*/ | |
| 105 | - | |
| 106 | -//-------------------- 第一阶段、计算迭代数据 -----------------// | |
| 107 | -declare Loop_result | |
| 108 | - xlId: String // 线路id | |
| 109 | - | |
| 110 | - ruleLoop: List // 每天分配的规则 List<ScheduleResult_output> | |
| 111 | - | |
| 112 | - ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>> | |
| 113 | - ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output> | |
| 114 | - ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output> | |
| 115 | -end | |
| 116 | - | |
| 117 | -rule "calcu_step1_Loop_result" | |
| 118 | - salience 1000 | |
| 119 | - when | |
| 120 | - $param: PlanCalcuParam_input($xlId: xlId) | |
| 121 | - then | |
| 122 | - Loop_result loop_result = new Loop_result(); | |
| 123 | - loop_result.setXlId($xlId); | |
| 124 | - loop_result.setRuleLoop($param.getScheduleResults_output().getResults()); | |
| 125 | - | |
| 126 | - loop_result.setTtInfoMapLoop(new HashMap()); | |
| 127 | - loop_result.setTtInfoMap(new HashMap()); | |
| 128 | - | |
| 129 | - com.google.common.collect.Multimap ttInfoMap_temp = | |
| 130 | - (com.google.common.collect.Multimap) | |
| 131 | - $param.getTtInfoResults_output().getResults().get( | |
| 132 | - String.valueOf($xlId)); | |
| 133 | - | |
| 134 | - loop_result.setTtInfoMapLoop_temp(ttInfoMap_temp.asMap()); | |
| 135 | - | |
| 136 | - insert(loop_result); | |
| 137 | - | |
| 138 | -// log.info("calcu_step1_Loop_result"); | |
| 139 | -end | |
| 140 | - | |
| 141 | -rule "calcu_step2_loop_result" | |
| 142 | - salience 1000 | |
| 143 | - no-loop | |
| 144 | - when | |
| 145 | - $param: PlanCalcuParam_input($xlId: xlId) | |
| 146 | - $lr: Loop_result(xlId == $xlId) | |
| 147 | - $sd: DateTime() from $lr.ttInfoMapLoop_temp.keySet() | |
| 148 | - then | |
| 149 | - // 当天时刻表只取第一张 TODO: | |
| 150 | - Collection col = (Collection) $lr.getTtInfoMapLoop_temp().get($sd); | |
| 151 | - Iterator iter = col.iterator(); | |
| 152 | - TTInfoResult_output ttInfo_result = (TTInfoResult_output) iter.next(); | |
| 153 | - $lr.getTtInfoMapLoop().put($sd, ttInfo_result); | |
| 154 | - | |
| 155 | - // 总共使用的时刻表 | |
| 156 | - $lr.getTtInfoMap().put(ttInfo_result.getTtInfoId(), ttInfo_result); | |
| 157 | - | |
| 158 | - update($lr); | |
| 159 | - | |
| 160 | -// log.info("calcu_step2_Loop_result"); | |
| 161 | -end | |
| 162 | - | |
| 163 | -//-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------// | |
| 164 | - | |
| 165 | -//--------------- 车辆配置信息载入 -------------// | |
| 166 | -declare CarConfig_Wraps | |
| 167 | - xlId: String // 线路Id | |
| 168 | - ccMap: Map // 车辆配置Map Map<id, CarConfigInfo> | |
| 169 | -end | |
| 170 | - | |
| 171 | -rule "calcu_CarConfig_Wraps" | |
| 172 | - salience 800 | |
| 173 | - when | |
| 174 | - $lr: Loop_result($xlId: xlId) | |
| 175 | - then | |
| 176 | - List carConfigInfos = carConfigInfoRepository.findByXlId(Integer.parseInt($xlId)); | |
| 177 | - | |
| 178 | - CarConfig_Wraps carConfig_wraps = new CarConfig_Wraps(); | |
| 179 | - carConfig_wraps.setXlId($xlId); | |
| 180 | - carConfig_wraps.setCcMap(new HashMap()); | |
| 181 | - | |
| 182 | - for (int i = 0; i < carConfigInfos.size(); i++) { | |
| 183 | - CarConfigInfo carConfigInfo = (CarConfigInfo) carConfigInfos.get(i); | |
| 184 | - carConfig_wraps.getCcMap().put(carConfigInfo.getId().toString(), carConfigInfo); | |
| 185 | - } | |
| 186 | - | |
| 187 | - insert(carConfig_wraps); | |
| 188 | - | |
| 189 | - log.info("calcu_CarConfig_Wrap"); | |
| 190 | -end | |
| 191 | - | |
| 192 | -//--------------- 人员配置信息载入 --------------// | |
| 193 | -declare EmployeeConfig_Wraps | |
| 194 | - xlId: String // 线路Id | |
| 195 | - ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo> | |
| 196 | -end | |
| 197 | - | |
| 198 | -rule "calcu_EmployeeConfig_Wraps" | |
| 199 | - salience 800 | |
| 200 | - when | |
| 201 | - $lr: Loop_result($xlId: xlId) | |
| 202 | - then | |
| 203 | - List employeeConfigInfos = employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId)); | |
| 204 | - | |
| 205 | - EmployeeConfig_Wraps employeeConfig_wraps = new EmployeeConfig_Wraps(); | |
| 206 | - employeeConfig_wraps.setXlId($xlId); | |
| 207 | - employeeConfig_wraps.setEcMap(new HashMap()); | |
| 208 | - | |
| 209 | - for (int i = 0; i < employeeConfigInfos.size(); i++) { | |
| 210 | - EmployeeConfigInfo employeeConfigInfo = (EmployeeConfigInfo) employeeConfigInfos.get(i); | |
| 211 | - employeeConfig_wraps.getEcMap().put(employeeConfigInfo.getId().toString(), employeeConfigInfo); | |
| 212 | - } | |
| 213 | - | |
| 214 | - insert(employeeConfig_wraps); | |
| 215 | - | |
| 216 | - log.info("calcu_EmployeeConfig_Wrap"); | |
| 217 | -end | |
| 218 | - | |
| 219 | -//----------------- 时刻表班次信息载入 -----------------// | |
| 220 | -declare TTInfo_gid_stat | |
| 221 | - xlId: String // 线路id(cast字符串-方便比较) | |
| 222 | - ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 223 | - gid: String // 路牌id(cast字符串-方便比较) | |
| 224 | - | |
| 225 | - maxFcno: Integer // 最大发车顺序号 | |
| 226 | - | |
| 227 | - fbTime: LocalTime // 分班时间 | |
| 228 | - fbfcno: Integer // 分班发车顺序号 | |
| 229 | -end | |
| 230 | - | |
| 231 | -rule "calcu_TTInfo_gid_stat" | |
| 232 | - salience 800 | |
| 233 | - when | |
| 234 | - $lr: Loop_result($xlId: xlId) | |
| 235 | - $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 236 | - $gids: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidscount($ttd)) | |
| 237 | - $gid: String() from $gids | |
| 238 | - $fbtime_str: String() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidfbtime($ttd)) | |
| 239 | - $fbfcno: Integer() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidfbfcno($ttd)) | |
| 240 | - $maxfcno: Double() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), max($ttd.getFcno())) | |
| 241 | - then | |
| 242 | - TTInfo_gid_stat ttInfo_gid_stat = new TTInfo_gid_stat(); | |
| 243 | - ttInfo_gid_stat.setXlId($xlId); | |
| 244 | - ttInfo_gid_stat.setTtInfoId($ttInfoId); | |
| 245 | - ttInfo_gid_stat.setGid($gid); | |
| 246 | - | |
| 247 | - ttInfo_gid_stat.setMaxFcno($maxfcno.intValue()); | |
| 248 | - ttInfo_gid_stat.setFbTime(fcsjTime($fbtime_str)); | |
| 249 | - ttInfo_gid_stat.setFbfcno($fbfcno); | |
| 250 | - | |
| 251 | - insert(ttInfo_gid_stat); | |
| 252 | - | |
| 253 | -// log.info("xlid={},ttid={},gid={},maxfcno={},fbtime={},fbfcno={}", | |
| 254 | -// $xlId, $ttInfoId, $gid, ttInfo_gid_stat.getMaxFcno(), ttInfo_gid_stat.getFbTime(), ttInfo_gid_stat.getFbfcno()); | |
| 255 | - | |
| 256 | -end | |
| 257 | - | |
| 258 | -declare TTInfoDetail_Wrap | |
| 259 | - isFirstBc: Boolean = false // 是否是当前路牌的第一个班次 | |
| 260 | - isLastBc: Boolean = false // 是否是当前路牌的最后一个班次 | |
| 261 | - isFb: Boolean = false // 是否分班 | |
| 262 | - | |
| 263 | - self: TTInfoDetail // 原始数据 | |
| 264 | -end | |
| 265 | - | |
| 266 | -declare TTInfoDetail_Wraps | |
| 267 | - xlId: String // 线路id(cast字符串-方便比较) | |
| 268 | - ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 269 | - | |
| 270 | - detailsMap: Map // 明细Map,Map<路牌id, List<TTInfoDetail_Wrap>> | |
| 271 | -end | |
| 272 | - | |
| 273 | -rule "calcu_TTInfoDetail_Wraps" | |
| 274 | - salience 700 | |
| 275 | - when | |
| 276 | - $lr: Loop_result($xlId: xlId) | |
| 277 | - $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 278 | - $ttInfoStatList: List(size > 0) from collect (TTInfo_gid_stat(ttInfoId == $ttInfoId)) | |
| 279 | - then | |
| 280 | - TTInfoDetail_Wraps ttInfoDetail_wraps = new TTInfoDetail_Wraps(); | |
| 281 | - ttInfoDetail_wraps.setXlId($xlId); | |
| 282 | - ttInfoDetail_wraps.setTtInfoId($ttInfoId); | |
| 283 | - ttInfoDetail_wraps.setDetailsMap(new HashMap()); | |
| 284 | - | |
| 285 | - // 将list的形式变成 Map<路牌id, TTInfo_gid_stat> | |
| 286 | - Map statMap = new HashMap(); | |
| 287 | - for (int i = 0; i < $ttInfoStatList.size(); i++) { | |
| 288 | - TTInfo_gid_stat ttInfo_gid_stat = (TTInfo_gid_stat) $ttInfoStatList.get(i); | |
| 289 | - statMap.put(ttInfo_gid_stat.getGid(), ttInfo_gid_stat); | |
| 290 | - } | |
| 291 | - | |
| 292 | - // 迭代ttinfodetail,拼装 TTInfoDetail_Wraps | |
| 293 | - List detaillist = tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)); | |
| 294 | - for (int j = 0; j < detaillist.size(); j++) { | |
| 295 | - TTInfoDetail ttInfoDetail = (TTInfoDetail) detaillist.get(j); | |
| 296 | - String gid = String.valueOf(ttInfoDetail.getLp().getId()); | |
| 297 | - | |
| 298 | - if (ttInfoDetail_wraps.getDetailsMap().get(gid) == null) { | |
| 299 | - ttInfoDetail_wraps.getDetailsMap().put(gid, new ArrayList()); | |
| 300 | - } | |
| 301 | - | |
| 302 | - // 获取stat | |
| 303 | - TTInfo_gid_stat ttInfo_gid_stat = (TTInfo_gid_stat) statMap.get(gid); | |
| 304 | - | |
| 305 | - TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap(); | |
| 306 | - ttInfoDetail_wrap.setIsFirstBc(1 == ttInfoDetail.getFcno()); | |
| 307 | - ttInfoDetail_wrap.setIsLastBc(ttInfo_gid_stat.getMaxFcno() == ttInfoDetail.getFcno()); | |
| 308 | - | |
| 309 | - LocalTime fcsj = fcsjTime(ttInfoDetail.getFcsj()); | |
| 310 | - LocalTime fbsj = ttInfo_gid_stat.getFbTime(); | |
| 311 | - Integer fbfcno = ttInfo_gid_stat.getFbfcno(); | |
| 312 | - // 不用时间判定,因为有的路牌,后面的班次都是凌晨的,时间反而比分班时间早,不合理,所以使用发车顺序号做第二次比较 | |
| 313 | -// ttInfoDetail_wrap.setIsFb(fbsj == null ? false : (fcsj.isEqual(fbsj) || fcsj.isAfter(fbsj))); | |
| 314 | - ttInfoDetail_wrap.setIsFb(fbsj == null ? false : ttInfoDetail.getFcno() >= fbfcno); | |
| 315 | - | |
| 316 | - ttInfoDetail_wrap.setSelf(ttInfoDetail); | |
| 317 | - | |
| 318 | - ((List) ttInfoDetail_wraps.getDetailsMap().get(gid)).add(ttInfoDetail_wrap); | |
| 319 | - | |
| 320 | - } | |
| 321 | - | |
| 322 | - | |
| 323 | - insert(ttInfoDetail_wraps); | |
| 324 | - | |
| 325 | - log.info("xlid={}, ttinfoid={}, lpstatCount={}, detailLpCount={}", | |
| 326 | - $xlId, $ttInfoId, $ttInfoStatList.size(), ttInfoDetail_wraps.getDetailsMap().keySet().size()); | |
| 327 | - | |
| 328 | - | |
| 329 | -end | |
| 330 | - | |
| 331 | -declare TTInfoDetail_Wraps_map | |
| 332 | - xlId: String // 线路id(cast字符串-方便比较) | |
| 333 | - | |
| 334 | - wrapsMap: Map // 明细Map,Map<时刻表Id, TTInfoDetail_Wraps> | |
| 335 | -end | |
| 336 | - | |
| 337 | -rule "calcu_TTInfoDetail_Wraps_toMap" | |
| 338 | - salience 600 | |
| 339 | - when | |
| 340 | - $lr: Loop_result($xlId: xlId) | |
| 341 | - $wrapsList: List(size > 0) from collect (TTInfoDetail_Wraps(xlId == $xlId)) | |
| 342 | - then | |
| 343 | - // 转换成Map | |
| 344 | - TTInfoDetail_Wraps_map all = new TTInfoDetail_Wraps_map(); | |
| 345 | - all.setXlId($xlId); | |
| 346 | - all.setWrapsMap(new HashMap()); | |
| 347 | - | |
| 348 | - for (int i = 0; i < $wrapsList.size(); i++) { | |
| 349 | - TTInfoDetail_Wraps ttInfoDetail_wraps = (TTInfoDetail_Wraps) $wrapsList.get(i); | |
| 350 | - all.getWrapsMap().put(ttInfoDetail_wraps.getTtInfoId(), ttInfoDetail_wraps); | |
| 351 | - } | |
| 352 | - | |
| 353 | - insert(all); | |
| 354 | -end | |
| 355 | - | |
| 356 | - | |
| 357 | - | |
| 358 | - | |
| 359 | -//-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------// | |
| 360 | - | |
| 361 | - | |
| 362 | -rule "Calcu_SchedulePlanInfo" | |
| 363 | - salience 500 | |
| 364 | - when | |
| 365 | - $param: PlanCalcuParam_input($xlId: xlId) | |
| 366 | - $lr: Loop_result(xlId == $xlId) | |
| 367 | - $ccs: CarConfig_Wraps(xlId == $xlId) | |
| 368 | - $ecs: EmployeeConfig_Wraps(xlId == $xlId) | |
| 369 | - $tts: TTInfoDetail_Wraps_map(xlId == $xlId) | |
| 370 | - then | |
| 371 | - // 线路 | |
| 372 | - Line xl = lineRepository.findOne(Integer.parseInt($xlId)); | |
| 373 | - | |
| 374 | - // 查找公司 | |
| 375 | - List gses = (List) businessRepository.findAll(); | |
| 376 | - // 构造公司代码对应map | |
| 377 | - Map gsMap = gsMap(gses); | |
| 378 | - // 构造分公司对应的map | |
| 379 | - Map fgsMap = fgsMap(gses); | |
| 380 | - | |
| 381 | - for (int i = 0; i < $lr.getRuleLoop().size(); i++) { | |
| 382 | - ScheduleResult_output sro = (ScheduleResult_output) $lr.getRuleLoop().get(i); | |
| 383 | - | |
| 384 | - // 日期 | |
| 385 | - DateTime sd = sro.getSd(); | |
| 386 | - // 路牌 | |
| 387 | - String gid = sro.getGuideboardId(); | |
| 388 | - // 车辆配置 | |
| 389 | - CarConfigInfo carConfigInfo = sro.getsType() == ScheduleRule_Type.NORMAL ? | |
| 390 | - (CarConfigInfo) $ccs.getCcMap().get(sro.getCarConfigId()) : null; | |
| 391 | - // 人员配置 | |
| 392 | - List eclist = sro.getsType() == ScheduleRule_Type.NORMAL ? | |
| 393 | - ecList(employeeConfigInfoRepository, sro.getEmployeeConfigId()) : null; | |
| 394 | - | |
| 395 | - // 时刻表id | |
| 396 | - String ttInfoId = ttInfoId_sd($lr.getTtInfoMapLoop(), sd); | |
| 397 | - TTInfoDetail_Wraps ttInfoDetail_wraps = (TTInfoDetail_Wraps) $tts.getWrapsMap().get(ttInfoId); | |
| 398 | - if (ttInfoDetail_wraps == null) { | |
| 399 | - // 时刻表为空,直接跳过 | |
| 400 | - // 如1118路,周末不开,此是时刻表指定一个空表 | |
| 401 | - // TODO:这个以后要改的,选时刻表的规则要修正,没有默认的时刻表 | |
| 402 | - continue; | |
| 403 | - } | |
| 404 | - | |
| 405 | - List detaillist = (List) ttInfoDetail_wraps.getDetailsMap().get(gid); | |
| 406 | - if (detaillist == null) { | |
| 407 | - // 这里翻到的路牌时刻表里可能没有, | |
| 408 | - // 因为没有考虑翻班格式(就是做几休几) | |
| 409 | - // 所有翻班格式全由时刻表决定,即时刻表有的路牌就做,没有不做 | |
| 410 | - continue; | |
| 411 | - } | |
| 412 | - | |
| 413 | - for (int j = 0; j < detaillist.size(); j++) { | |
| 414 | - TTInfoDetail_Wrap wrap = (TTInfoDetail_Wrap) detaillist.get(j); | |
| 415 | - | |
| 416 | - SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( | |
| 417 | - xl, | |
| 418 | - sro, | |
| 419 | - wrap.getSelf(), | |
| 420 | - wrap.getIsFb(), | |
| 421 | - carConfigInfo, | |
| 422 | - eclist, | |
| 423 | - $param.getSchedulePlan(), | |
| 424 | - wrap.getIsFirstBc(), | |
| 425 | - wrap.getIsLastBc(), | |
| 426 | - sro.getsType() | |
| 427 | - ); | |
| 428 | - | |
| 429 | - // 获取公司,分公司信息 | |
| 430 | - String gsbm = xl.getCompany(); | |
| 431 | - String fgsbm = xl.getBrancheCompany(); | |
| 432 | - Business gs = null; | |
| 433 | - Business fgs = null; | |
| 434 | - | |
| 435 | - if (StringUtils.isNotEmpty(gsbm)) { | |
| 436 | - gs = (Business) gsMap.get(gsbm); | |
| 437 | - } | |
| 438 | - if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) { | |
| 439 | - fgs = (Business) fgsMap.get(gsbm + "_" + fgsbm); | |
| 440 | - } | |
| 441 | - | |
| 442 | - if (gs != null) { | |
| 443 | - schedulePlanInfo.setGsBm(gs.getBusinessCode()); | |
| 444 | - schedulePlanInfo.setGsName(gs.getBusinessName()); | |
| 445 | - } | |
| 446 | - if (fgs != null) { | |
| 447 | - schedulePlanInfo.setFgsBm(fgs.getBusinessCode()); | |
| 448 | - schedulePlanInfo.setFgsName(fgs.getBusinessName()); | |
| 449 | - } | |
| 450 | - | |
| 451 | - // 操作人,操作时间 | |
| 452 | - schedulePlanInfo.setCreateBy($param.getSchedulePlan().getCreateBy()); | |
| 453 | - schedulePlanInfo.setCreateDate($param.getSchedulePlan().getCreateDate()); | |
| 454 | - schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy()); | |
| 455 | - schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate()); | |
| 456 | - | |
| 457 | - // result 输出 | |
| 458 | - planResult.getSchedulePlanInfos().add(schedulePlanInfo); | |
| 459 | - | |
| 460 | - } | |
| 461 | - | |
| 462 | - } | |
| 463 | - | |
| 464 | - log.info("xlid={} plan ok!", $xlId); | |
| 465 | - | |
| 466 | -end | |
| 467 | - | |
| 468 | - | |
| 469 | - | |
| 470 | - | |
| 471 | - | |
| 472 | - | |
| 473 | - | |
| 474 | - | |
| 475 | - | |
| 476 | - | |
| 477 | - | |
| 478 | - | |
| 479 | - | |
| 480 | - | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.plan; | |
| 2 | + | |
| 3 | +import org.joda.time.*; | |
| 4 | +import java.util.*; | |
| 5 | + | |
| 6 | +import com.bsth.service.schedule.impl.plan.kBase1.core.plan.PlanCalcuParam_input; | |
| 7 | +import com.bsth.service.schedule.impl.plan.kBase1.core.plan.PlanResult; | |
| 8 | + | |
| 9 | +import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 10 | +import com.bsth.repository.schedule.CarConfigInfoRepository; | |
| 11 | +import com.bsth.repository.schedule.EmployeeConfigInfoRepository; | |
| 12 | +import com.bsth.repository.LineRepository; | |
| 13 | +import com.bsth.repository.BusinessRepository; | |
| 14 | + | |
| 15 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResult_output; | |
| 16 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResults_output; | |
| 17 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfoResult_output; | |
| 18 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfoResults_output; | |
| 19 | +import com.bsth.entity.Line; | |
| 20 | +import com.bsth.entity.Business; | |
| 21 | + | |
| 22 | +import com.bsth.entity.schedule.CarConfigInfo; | |
| 23 | +import com.bsth.entity.schedule.EmployeeConfigInfo; | |
| 24 | +import com.bsth.entity.schedule.TTInfo; | |
| 25 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 26 | +import com.bsth.entity.schedule.SchedulePlanInfo; | |
| 27 | + | |
| 28 | +import org.slf4j.Logger | |
| 29 | +import org.joda.time.format.DateTimeFormat | |
| 30 | +import org.apache.commons.lang3.StringUtils | |
| 31 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_Type; | |
| 32 | + | |
| 33 | + | |
| 34 | +// 全局日志类(一般使用调用此规则的service类) | |
| 35 | +global Logger log; | |
| 36 | + | |
| 37 | +global TTInfoDetailRepository tTInfoDetailRepository; | |
| 38 | +global CarConfigInfoRepository carConfigInfoRepository; | |
| 39 | +global EmployeeConfigInfoRepository employeeConfigInfoRepository; | |
| 40 | +global LineRepository lineRepository; | |
| 41 | +global BusinessRepository businessRepository; | |
| 42 | + | |
| 43 | +// 输出 | |
| 44 | +global PlanResult planResult; | |
| 45 | + | |
| 46 | +function Map xlidParams(String xlid) { | |
| 47 | + Map param = new HashMap(); | |
| 48 | + param.put("xl.id_eq", Integer.valueOf(xlid)); | |
| 49 | + return param; | |
| 50 | +} | |
| 51 | + | |
| 52 | +function List ecList(EmployeeConfigInfoRepository repo, String ecids) { | |
| 53 | + List<String> ids = Arrays.asList(ecids.split("-")); | |
| 54 | + List rst = new ArrayList(); | |
| 55 | + for (int i = 0; i < ids.size(); i++) { | |
| 56 | + rst.add(repo.findOne(Long.parseLong(ids.get(i)))); | |
| 57 | + } | |
| 58 | + return rst; | |
| 59 | +} | |
| 60 | + | |
| 61 | +function LocalTime fcsjTime(String fcsj) { | |
| 62 | + if ("NULL".equals(fcsj)) { | |
| 63 | + return null; | |
| 64 | + } | |
| 65 | + return LocalTime.parse(fcsj, DateTimeFormat.forPattern("HH:mm")); | |
| 66 | +} | |
| 67 | + | |
| 68 | +function String ttInfoId_sd(Map map, DateTime sd) { | |
| 69 | + TTInfoResult_output ttInfoResult_output = (TTInfoResult_output) map.get(sd); | |
| 70 | + return ttInfoResult_output.getTtInfoId(); | |
| 71 | +} | |
| 72 | + | |
| 73 | +function Map gsMap(List gses) { | |
| 74 | + Map gsMap = new HashMap(); | |
| 75 | + for (int i = 0; i < gses.size(); i++) { | |
| 76 | + Business gs = (Business) gses.get(i); | |
| 77 | + if (StringUtils.isNotEmpty(gs.getBusinessCode())) { | |
| 78 | + if ("88".equals(gs.getUpCode())) { // 浦东公交 | |
| 79 | + gsMap.put(gs.getBusinessCode(), gs); | |
| 80 | + } | |
| 81 | + if (gs.getBusinessCode().equals(gs.getUpCode())) { // 闵行,青浦 | |
| 82 | + gsMap.put(gs.getBusinessCode(), gs); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + } | |
| 86 | + return gsMap; | |
| 87 | +} | |
| 88 | + | |
| 89 | +function Map fgsMap(List gses) { | |
| 90 | + // 这里简单将 businessCode和upCode合并 | |
| 91 | + Map fgsMap = new HashMap(); | |
| 92 | + for (int i = 0; i < gses.size(); i++) { | |
| 93 | + Business gs = (Business) gses.get(i); | |
| 94 | + if (StringUtils.isNotEmpty(gs.getBusinessCode()) && StringUtils.isNotEmpty(gs.getUpCode())) { | |
| 95 | + fgsMap.put(gs.getUpCode() + "_" + gs.getBusinessCode(), gs); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + return fgsMap; | |
| 99 | +} | |
| 100 | + | |
| 101 | +/* | |
| 102 | + 规则说明: | |
| 103 | + 根据循环规则输出,时刻表选择规则输出,组合计算排班明细 | |
| 104 | +*/ | |
| 105 | + | |
| 106 | +//-------------------- 第一阶段、计算迭代数据 -----------------// | |
| 107 | +declare Loop_result | |
| 108 | + xlId: String // 线路id | |
| 109 | + | |
| 110 | + ruleLoop: List // 每天分配的规则 List<ScheduleResult_output> | |
| 111 | + | |
| 112 | + ttInfoMapLoop_temp: Map // 每天分配的时刻表 Map<DataTime, Collection<TTInfoResult_output>> | |
| 113 | + ttInfoMapLoop: Map // 每天分配的时刻表 Map<DataTime, TTInfoResult_output> | |
| 114 | + ttInfoMap: Map // 总共用到的时刻表 Map<id, TTInfoResult_output> | |
| 115 | +end | |
| 116 | + | |
| 117 | +rule "calcu_step1_Loop_result" | |
| 118 | + salience 1000 | |
| 119 | + when | |
| 120 | + $param: PlanCalcuParam_input($xlId: xlId) | |
| 121 | + then | |
| 122 | + Loop_result loop_result = new Loop_result(); | |
| 123 | + loop_result.setXlId($xlId); | |
| 124 | + loop_result.setRuleLoop($param.getScheduleResults_output().getResults()); | |
| 125 | + | |
| 126 | + loop_result.setTtInfoMapLoop(new HashMap()); | |
| 127 | + loop_result.setTtInfoMap(new HashMap()); | |
| 128 | + | |
| 129 | + com.google.common.collect.Multimap ttInfoMap_temp = | |
| 130 | + (com.google.common.collect.Multimap) | |
| 131 | + $param.getTtInfoResults_output().getResults().get( | |
| 132 | + String.valueOf($xlId)); | |
| 133 | + | |
| 134 | + loop_result.setTtInfoMapLoop_temp(ttInfoMap_temp.asMap()); | |
| 135 | + | |
| 136 | + insert(loop_result); | |
| 137 | + | |
| 138 | +// log.info("calcu_step1_Loop_result"); | |
| 139 | +end | |
| 140 | + | |
| 141 | +rule "calcu_step2_loop_result" | |
| 142 | + salience 1000 | |
| 143 | + no-loop | |
| 144 | + when | |
| 145 | + $param: PlanCalcuParam_input($xlId: xlId) | |
| 146 | + $lr: Loop_result(xlId == $xlId) | |
| 147 | + $sd: DateTime() from $lr.ttInfoMapLoop_temp.keySet() | |
| 148 | + then | |
| 149 | + // 当天时刻表只取第一张 TODO: | |
| 150 | + Collection col = (Collection) $lr.getTtInfoMapLoop_temp().get($sd); | |
| 151 | + Iterator iter = col.iterator(); | |
| 152 | + TTInfoResult_output ttInfo_result = (TTInfoResult_output) iter.next(); | |
| 153 | + $lr.getTtInfoMapLoop().put($sd, ttInfo_result); | |
| 154 | + | |
| 155 | + // 总共使用的时刻表 | |
| 156 | + $lr.getTtInfoMap().put(ttInfo_result.getTtInfoId(), ttInfo_result); | |
| 157 | + | |
| 158 | + update($lr); | |
| 159 | + | |
| 160 | +// log.info("calcu_step2_Loop_result"); | |
| 161 | +end | |
| 162 | + | |
| 163 | +//-------------------- 第二阶段、将时刻表班次,车辆配置,人员配置信息载入 -----------------// | |
| 164 | + | |
| 165 | +//--------------- 车辆配置信息载入 -------------// | |
| 166 | +declare CarConfig_Wraps | |
| 167 | + xlId: String // 线路Id | |
| 168 | + ccMap: Map // 车辆配置Map Map<id, CarConfigInfo> | |
| 169 | +end | |
| 170 | + | |
| 171 | +rule "calcu_CarConfig_Wraps" | |
| 172 | + salience 800 | |
| 173 | + when | |
| 174 | + $lr: Loop_result($xlId: xlId) | |
| 175 | + then | |
| 176 | + List carConfigInfos = carConfigInfoRepository.findByXlId(Integer.parseInt($xlId)); | |
| 177 | + | |
| 178 | + CarConfig_Wraps carConfig_wraps = new CarConfig_Wraps(); | |
| 179 | + carConfig_wraps.setXlId($xlId); | |
| 180 | + carConfig_wraps.setCcMap(new HashMap()); | |
| 181 | + | |
| 182 | + for (int i = 0; i < carConfigInfos.size(); i++) { | |
| 183 | + CarConfigInfo carConfigInfo = (CarConfigInfo) carConfigInfos.get(i); | |
| 184 | + carConfig_wraps.getCcMap().put(carConfigInfo.getId().toString(), carConfigInfo); | |
| 185 | + } | |
| 186 | + | |
| 187 | + insert(carConfig_wraps); | |
| 188 | + | |
| 189 | + log.info("calcu_CarConfig_Wrap"); | |
| 190 | +end | |
| 191 | + | |
| 192 | +//--------------- 人员配置信息载入 --------------// | |
| 193 | +declare EmployeeConfig_Wraps | |
| 194 | + xlId: String // 线路Id | |
| 195 | + ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo> | |
| 196 | +end | |
| 197 | + | |
| 198 | +rule "calcu_EmployeeConfig_Wraps" | |
| 199 | + salience 800 | |
| 200 | + when | |
| 201 | + $lr: Loop_result($xlId: xlId) | |
| 202 | + then | |
| 203 | + List employeeConfigInfos = employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId)); | |
| 204 | + | |
| 205 | + EmployeeConfig_Wraps employeeConfig_wraps = new EmployeeConfig_Wraps(); | |
| 206 | + employeeConfig_wraps.setXlId($xlId); | |
| 207 | + employeeConfig_wraps.setEcMap(new HashMap()); | |
| 208 | + | |
| 209 | + for (int i = 0; i < employeeConfigInfos.size(); i++) { | |
| 210 | + EmployeeConfigInfo employeeConfigInfo = (EmployeeConfigInfo) employeeConfigInfos.get(i); | |
| 211 | + employeeConfig_wraps.getEcMap().put(employeeConfigInfo.getId().toString(), employeeConfigInfo); | |
| 212 | + } | |
| 213 | + | |
| 214 | + insert(employeeConfig_wraps); | |
| 215 | + | |
| 216 | + log.info("calcu_EmployeeConfig_Wrap"); | |
| 217 | +end | |
| 218 | + | |
| 219 | +//----------------- 时刻表班次信息载入 -----------------// | |
| 220 | +declare TTInfo_gid_stat | |
| 221 | + xlId: String // 线路id(cast字符串-方便比较) | |
| 222 | + ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 223 | + gid: String // 路牌id(cast字符串-方便比较) | |
| 224 | + | |
| 225 | + maxFcno: Integer // 最大发车顺序号 | |
| 226 | + | |
| 227 | + fbTime: LocalTime // 分班时间 | |
| 228 | + fbfcno: Integer // 分班发车顺序号 | |
| 229 | +end | |
| 230 | + | |
| 231 | +rule "calcu_TTInfo_gid_stat" | |
| 232 | + salience 800 | |
| 233 | + when | |
| 234 | + $lr: Loop_result($xlId: xlId) | |
| 235 | + $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 236 | + $gids: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidscount($ttd)) | |
| 237 | + $gid: String() from $gids | |
| 238 | + $fbtime_str: String() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidfbtime($ttd)) | |
| 239 | + $fbfcno: Integer() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidfbfcno($ttd)) | |
| 240 | + $maxfcno: Double() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), max($ttd.getFcno())) | |
| 241 | + then | |
| 242 | + TTInfo_gid_stat ttInfo_gid_stat = new TTInfo_gid_stat(); | |
| 243 | + ttInfo_gid_stat.setXlId($xlId); | |
| 244 | + ttInfo_gid_stat.setTtInfoId($ttInfoId); | |
| 245 | + ttInfo_gid_stat.setGid($gid); | |
| 246 | + | |
| 247 | + ttInfo_gid_stat.setMaxFcno($maxfcno.intValue()); | |
| 248 | + ttInfo_gid_stat.setFbTime(fcsjTime($fbtime_str)); | |
| 249 | + ttInfo_gid_stat.setFbfcno($fbfcno); | |
| 250 | + | |
| 251 | + insert(ttInfo_gid_stat); | |
| 252 | + | |
| 253 | +// log.info("xlid={},ttid={},gid={},maxfcno={},fbtime={},fbfcno={}", | |
| 254 | +// $xlId, $ttInfoId, $gid, ttInfo_gid_stat.getMaxFcno(), ttInfo_gid_stat.getFbTime(), ttInfo_gid_stat.getFbfcno()); | |
| 255 | + | |
| 256 | +end | |
| 257 | + | |
| 258 | +declare TTInfoDetail_Wrap | |
| 259 | + isFirstBc: Boolean = false // 是否是当前路牌的第一个班次 | |
| 260 | + isLastBc: Boolean = false // 是否是当前路牌的最后一个班次 | |
| 261 | + isFb: Boolean = false // 是否分班 | |
| 262 | + | |
| 263 | + self: TTInfoDetail // 原始数据 | |
| 264 | +end | |
| 265 | + | |
| 266 | +declare TTInfoDetail_Wraps | |
| 267 | + xlId: String // 线路id(cast字符串-方便比较) | |
| 268 | + ttInfoId: String // 时刻表id(cast字符串-方便比较) | |
| 269 | + | |
| 270 | + detailsMap: Map // 明细Map,Map<路牌id, List<TTInfoDetail_Wrap>> | |
| 271 | +end | |
| 272 | + | |
| 273 | +rule "calcu_TTInfoDetail_Wraps" | |
| 274 | + salience 700 | |
| 275 | + when | |
| 276 | + $lr: Loop_result($xlId: xlId) | |
| 277 | + $ttInfoId: String() from $lr.getTtInfoMap().keySet() | |
| 278 | + $ttInfoStatList: List(size > 0) from collect (TTInfo_gid_stat(ttInfoId == $ttInfoId)) | |
| 279 | + then | |
| 280 | + TTInfoDetail_Wraps ttInfoDetail_wraps = new TTInfoDetail_Wraps(); | |
| 281 | + ttInfoDetail_wraps.setXlId($xlId); | |
| 282 | + ttInfoDetail_wraps.setTtInfoId($ttInfoId); | |
| 283 | + ttInfoDetail_wraps.setDetailsMap(new HashMap()); | |
| 284 | + | |
| 285 | + // 将list的形式变成 Map<路牌id, TTInfo_gid_stat> | |
| 286 | + Map statMap = new HashMap(); | |
| 287 | + for (int i = 0; i < $ttInfoStatList.size(); i++) { | |
| 288 | + TTInfo_gid_stat ttInfo_gid_stat = (TTInfo_gid_stat) $ttInfoStatList.get(i); | |
| 289 | + statMap.put(ttInfo_gid_stat.getGid(), ttInfo_gid_stat); | |
| 290 | + } | |
| 291 | + | |
| 292 | + // 迭代ttinfodetail,拼装 TTInfoDetail_Wraps | |
| 293 | + List detaillist = tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)); | |
| 294 | + for (int j = 0; j < detaillist.size(); j++) { | |
| 295 | + TTInfoDetail ttInfoDetail = (TTInfoDetail) detaillist.get(j); | |
| 296 | + String gid = String.valueOf(ttInfoDetail.getLp().getId()); | |
| 297 | + | |
| 298 | + if (ttInfoDetail_wraps.getDetailsMap().get(gid) == null) { | |
| 299 | + ttInfoDetail_wraps.getDetailsMap().put(gid, new ArrayList()); | |
| 300 | + } | |
| 301 | + | |
| 302 | + // 获取stat | |
| 303 | + TTInfo_gid_stat ttInfo_gid_stat = (TTInfo_gid_stat) statMap.get(gid); | |
| 304 | + | |
| 305 | + TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap(); | |
| 306 | + ttInfoDetail_wrap.setIsFirstBc(1 == ttInfoDetail.getFcno()); | |
| 307 | + ttInfoDetail_wrap.setIsLastBc(ttInfo_gid_stat.getMaxFcno() == ttInfoDetail.getFcno()); | |
| 308 | + | |
| 309 | + LocalTime fcsj = fcsjTime(ttInfoDetail.getFcsj()); | |
| 310 | + LocalTime fbsj = ttInfo_gid_stat.getFbTime(); | |
| 311 | + Integer fbfcno = ttInfo_gid_stat.getFbfcno(); | |
| 312 | + // 不用时间判定,因为有的路牌,后面的班次都是凌晨的,时间反而比分班时间早,不合理,所以使用发车顺序号做第二次比较 | |
| 313 | +// ttInfoDetail_wrap.setIsFb(fbsj == null ? false : (fcsj.isEqual(fbsj) || fcsj.isAfter(fbsj))); | |
| 314 | + ttInfoDetail_wrap.setIsFb(fbsj == null ? false : ttInfoDetail.getFcno() >= fbfcno); | |
| 315 | + | |
| 316 | + ttInfoDetail_wrap.setSelf(ttInfoDetail); | |
| 317 | + | |
| 318 | + ((List) ttInfoDetail_wraps.getDetailsMap().get(gid)).add(ttInfoDetail_wrap); | |
| 319 | + | |
| 320 | + } | |
| 321 | + | |
| 322 | + | |
| 323 | + insert(ttInfoDetail_wraps); | |
| 324 | + | |
| 325 | + log.info("xlid={}, ttinfoid={}, lpstatCount={}, detailLpCount={}", | |
| 326 | + $xlId, $ttInfoId, $ttInfoStatList.size(), ttInfoDetail_wraps.getDetailsMap().keySet().size()); | |
| 327 | + | |
| 328 | + | |
| 329 | +end | |
| 330 | + | |
| 331 | +declare TTInfoDetail_Wraps_map | |
| 332 | + xlId: String // 线路id(cast字符串-方便比较) | |
| 333 | + | |
| 334 | + wrapsMap: Map // 明细Map,Map<时刻表Id, TTInfoDetail_Wraps> | |
| 335 | +end | |
| 336 | + | |
| 337 | +rule "calcu_TTInfoDetail_Wraps_toMap" | |
| 338 | + salience 600 | |
| 339 | + when | |
| 340 | + $lr: Loop_result($xlId: xlId) | |
| 341 | + $wrapsList: List(size > 0) from collect (TTInfoDetail_Wraps(xlId == $xlId)) | |
| 342 | + then | |
| 343 | + // 转换成Map | |
| 344 | + TTInfoDetail_Wraps_map all = new TTInfoDetail_Wraps_map(); | |
| 345 | + all.setXlId($xlId); | |
| 346 | + all.setWrapsMap(new HashMap()); | |
| 347 | + | |
| 348 | + for (int i = 0; i < $wrapsList.size(); i++) { | |
| 349 | + TTInfoDetail_Wraps ttInfoDetail_wraps = (TTInfoDetail_Wraps) $wrapsList.get(i); | |
| 350 | + all.getWrapsMap().put(ttInfoDetail_wraps.getTtInfoId(), ttInfoDetail_wraps); | |
| 351 | + } | |
| 352 | + | |
| 353 | + insert(all); | |
| 354 | +end | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | +//-------------------- 第三阶段、合并计算SchedulePlanInfo -----------------// | |
| 360 | + | |
| 361 | + | |
| 362 | +rule "Calcu_SchedulePlanInfo" | |
| 363 | + salience 500 | |
| 364 | + when | |
| 365 | + $param: PlanCalcuParam_input($xlId: xlId) | |
| 366 | + $lr: Loop_result(xlId == $xlId) | |
| 367 | + $ccs: CarConfig_Wraps(xlId == $xlId) | |
| 368 | + $ecs: EmployeeConfig_Wraps(xlId == $xlId) | |
| 369 | + $tts: TTInfoDetail_Wraps_map(xlId == $xlId) | |
| 370 | + then | |
| 371 | + // 线路 | |
| 372 | + Line xl = lineRepository.findOne(Integer.parseInt($xlId)); | |
| 373 | + | |
| 374 | + // 查找公司 | |
| 375 | + List gses = (List) businessRepository.findAll(); | |
| 376 | + // 构造公司代码对应map | |
| 377 | + Map gsMap = gsMap(gses); | |
| 378 | + // 构造分公司对应的map | |
| 379 | + Map fgsMap = fgsMap(gses); | |
| 380 | + | |
| 381 | + for (int i = 0; i < $lr.getRuleLoop().size(); i++) { | |
| 382 | + ScheduleResult_output sro = (ScheduleResult_output) $lr.getRuleLoop().get(i); | |
| 383 | + | |
| 384 | + // 日期 | |
| 385 | + DateTime sd = sro.getSd(); | |
| 386 | + // 路牌 | |
| 387 | + String gid = sro.getGuideboardId(); | |
| 388 | + // 车辆配置 | |
| 389 | + CarConfigInfo carConfigInfo = sro.getsType() == ScheduleRule_Type.NORMAL ? | |
| 390 | + (CarConfigInfo) $ccs.getCcMap().get(sro.getCarConfigId()) : null; | |
| 391 | + // 人员配置 | |
| 392 | + List eclist = sro.getsType() == ScheduleRule_Type.NORMAL ? | |
| 393 | + ecList(employeeConfigInfoRepository, sro.getEmployeeConfigId()) : null; | |
| 394 | + | |
| 395 | + // 时刻表id | |
| 396 | + String ttInfoId = ttInfoId_sd($lr.getTtInfoMapLoop(), sd); | |
| 397 | + TTInfoDetail_Wraps ttInfoDetail_wraps = (TTInfoDetail_Wraps) $tts.getWrapsMap().get(ttInfoId); | |
| 398 | + if (ttInfoDetail_wraps == null) { | |
| 399 | + // 时刻表为空,直接跳过 | |
| 400 | + // 如1118路,周末不开,此是时刻表指定一个空表 | |
| 401 | + // TODO:这个以后要改的,选时刻表的规则要修正,没有默认的时刻表 | |
| 402 | + continue; | |
| 403 | + } | |
| 404 | + | |
| 405 | + List detaillist = (List) ttInfoDetail_wraps.getDetailsMap().get(gid); | |
| 406 | + if (detaillist == null) { | |
| 407 | + // 这里翻到的路牌时刻表里可能没有, | |
| 408 | + // 因为没有考虑翻班格式(就是做几休几) | |
| 409 | + // 所有翻班格式全由时刻表决定,即时刻表有的路牌就做,没有不做 | |
| 410 | + continue; | |
| 411 | + } | |
| 412 | + | |
| 413 | + for (int j = 0; j < detaillist.size(); j++) { | |
| 414 | + TTInfoDetail_Wrap wrap = (TTInfoDetail_Wrap) detaillist.get(j); | |
| 415 | + | |
| 416 | + SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( | |
| 417 | + xl, | |
| 418 | + sro, | |
| 419 | + wrap.getSelf(), | |
| 420 | + wrap.getIsFb(), | |
| 421 | + carConfigInfo, | |
| 422 | + eclist, | |
| 423 | + $param.getSchedulePlan(), | |
| 424 | + wrap.getIsFirstBc(), | |
| 425 | + wrap.getIsLastBc(), | |
| 426 | + sro.getsType() | |
| 427 | + ); | |
| 428 | + | |
| 429 | + // 获取公司,分公司信息 | |
| 430 | + String gsbm = xl.getCompany(); | |
| 431 | + String fgsbm = xl.getBrancheCompany(); | |
| 432 | + Business gs = null; | |
| 433 | + Business fgs = null; | |
| 434 | + | |
| 435 | + if (StringUtils.isNotEmpty(gsbm)) { | |
| 436 | + gs = (Business) gsMap.get(gsbm); | |
| 437 | + } | |
| 438 | + if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) { | |
| 439 | + fgs = (Business) fgsMap.get(gsbm + "_" + fgsbm); | |
| 440 | + } | |
| 441 | + | |
| 442 | + if (gs != null) { | |
| 443 | + schedulePlanInfo.setGsBm(gs.getBusinessCode()); | |
| 444 | + schedulePlanInfo.setGsName(gs.getBusinessName()); | |
| 445 | + } | |
| 446 | + if (fgs != null) { | |
| 447 | + schedulePlanInfo.setFgsBm(fgs.getBusinessCode()); | |
| 448 | + schedulePlanInfo.setFgsName(fgs.getBusinessName()); | |
| 449 | + } | |
| 450 | + | |
| 451 | + // 操作人,操作时间 | |
| 452 | + schedulePlanInfo.setCreateBy($param.getSchedulePlan().getCreateBy()); | |
| 453 | + schedulePlanInfo.setCreateDate($param.getSchedulePlan().getCreateDate()); | |
| 454 | + schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy()); | |
| 455 | + schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate()); | |
| 456 | + | |
| 457 | + // result 输出 | |
| 458 | + planResult.getSchedulePlanInfos().add(schedulePlanInfo); | |
| 459 | + | |
| 460 | + } | |
| 461 | + | |
| 462 | + } | |
| 463 | + | |
| 464 | + log.info("xlid={} plan ok!", $xlId); | |
| 465 | + | |
| 466 | +end | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | ... | ... |
src/main/resources/rules/rerun.drl renamed to src/main/resources/rules/kBase1_core_rerun.drl
| 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($dylpxlid)); | |
| 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($dylpxlid)); | |
| 80 | - | |
| 81 | - Dylp_EmployeeConfig_Wraps employeeConfig_wraps = new Dylp_EmployeeConfig_Wraps(); | |
| 82 | - employeeConfig_wraps.setXlId($dylpxlid); | |
| 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: List // 使用的人员配置 List<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 | - | |
| 120 | - List ecs = new ArrayList(); | |
| 121 | - String[] ecids = $sr.getEmployeeConfigId().split("-"); // 分班的人 | |
| 122 | - for (int i = 0; i < ecids.length; i++) { | |
| 123 | - ecs.add($ecmap.get(ecids[i])); | |
| 124 | - } | |
| 125 | - wrap.setEc(ecs); | |
| 126 | - | |
| 127 | -// log.info("xlid = {}", $xlId); | |
| 128 | - | |
| 129 | - insert(wrap); | |
| 130 | -end | |
| 131 | - | |
| 132 | -//-------------------- 第三阶段、套跑线路,替换班次的车辆,人员 --------------------// | |
| 133 | -rule "calcu_Dylp_rerun_update_dylp" | |
| 134 | - salience 800 | |
| 135 | -// no-loop | |
| 136 | - when | |
| 137 | - $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo) | |
| 138 | - $ri: RerunRule_input( | |
| 139 | - type == "dylp", | |
| 140 | - xl == $xlid.toString(), | |
| 141 | - ttinfo == $ttinfo.toString(), | |
| 142 | - lp == $lp.toString(), | |
| 143 | - fcsj == $fcsj, | |
| 144 | - $sxl: s_xl, $slp: s_lp, $type: usetype, $hrtype: userhrtype | |
| 145 | - ) | |
| 146 | - $dsro: Dylp_ScheduleResult_output_wrap( | |
| 147 | - xlId == $sxl, | |
| 148 | - lp == $slp, | |
| 149 | - sd.getMillis() == $sd.getTime() | |
| 150 | - ) | |
| 151 | - then | |
| 152 | -// log.info("TODO:测试 {}", $fcsj); | |
| 153 | - | |
| 154 | - $spi.setRerunInfoDylp($dsro.getCc(), $dsro.getEc(), $type, $hrtype); | |
| 155 | - | |
| 156 | -end | |
| 157 | - | |
| 158 | -rule "calcu_Dylp_rerun_update_dybc" | |
| 159 | - salience 700 | |
| 160 | - when | |
| 161 | - $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo) | |
| 162 | - $ri: RerunRule_input( | |
| 163 | - type == "dybc", | |
| 164 | - xl == $xlid.toString(), | |
| 165 | - ttinfo == $ttinfo.toString(), | |
| 166 | - lp == $lp.toString(), | |
| 167 | - fcsj == $fcsj | |
| 168 | - ) | |
| 169 | - | |
| 170 | - then | |
| 171 | - | |
| 172 | - $spi.setRerunInfoDybc($ri); | |
| 173 | - | |
| 174 | - | |
| 175 | -end | |
| 176 | - | |
| 177 | - | |
| 178 | - | |
| 179 | - | |
| 180 | - | |
| 181 | - | |
| 182 | - | |
| 183 | - | |
| 184 | - | |
| 185 | - | |
| 186 | - | |
| 187 | - | |
| 188 | - | |
| 189 | - | |
| 190 | - | |
| 191 | - | |
| 192 | - | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.rerun; | |
| 2 | + | |
| 3 | +import org.joda.time.*; | |
| 4 | +import java.util.*; | |
| 5 | + | |
| 6 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResult_output; | |
| 7 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResults_output; | |
| 8 | + | |
| 9 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input; | |
| 10 | +import com.bsth.service.schedule.impl.plan.kBase1.core.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($dylpxlid)); | |
| 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($dylpxlid)); | |
| 80 | + | |
| 81 | + Dylp_EmployeeConfig_Wraps employeeConfig_wraps = new Dylp_EmployeeConfig_Wraps(); | |
| 82 | + employeeConfig_wraps.setXlId($dylpxlid); | |
| 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: List // 使用的人员配置 List<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 | + | |
| 120 | + List ecs = new ArrayList(); | |
| 121 | + String[] ecids = $sr.getEmployeeConfigId().split("-"); // 分班的人 | |
| 122 | + for (int i = 0; i < ecids.length; i++) { | |
| 123 | + ecs.add($ecmap.get(ecids[i])); | |
| 124 | + } | |
| 125 | + wrap.setEc(ecs); | |
| 126 | + | |
| 127 | +// log.info("xlid = {}", $xlId); | |
| 128 | + | |
| 129 | + insert(wrap); | |
| 130 | +end | |
| 131 | + | |
| 132 | +//-------------------- 第三阶段、套跑线路,替换班次的车辆,人员 --------------------// | |
| 133 | +rule "calcu_Dylp_rerun_update_dylp" | |
| 134 | + salience 800 | |
| 135 | +// no-loop | |
| 136 | + when | |
| 137 | + $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo) | |
| 138 | + $ri: RerunRule_input( | |
| 139 | + type == "dylp", | |
| 140 | + xl == $xlid.toString(), | |
| 141 | + ttinfo == $ttinfo.toString(), | |
| 142 | + lp == $lp.toString(), | |
| 143 | + fcsj == $fcsj, | |
| 144 | + $sxl: s_xl, $slp: s_lp, $type: usetype, $hrtype: userhrtype | |
| 145 | + ) | |
| 146 | + $dsro: Dylp_ScheduleResult_output_wrap( | |
| 147 | + xlId == $sxl, | |
| 148 | + lp == $slp, | |
| 149 | + sd.getMillis() == $sd.getTime() | |
| 150 | + ) | |
| 151 | + then | |
| 152 | +// log.info("TODO:测试 {}", $fcsj); | |
| 153 | + | |
| 154 | + $spi.setRerunInfoDylp($dsro.getCc(), $dsro.getEc(), $type, $hrtype); | |
| 155 | + | |
| 156 | +end | |
| 157 | + | |
| 158 | +rule "calcu_Dylp_rerun_update_dybc" | |
| 159 | + salience 700 | |
| 160 | + when | |
| 161 | + $spi: SchedulePlanInfo($xlid: xl, $sd: scheduleDate, $lp: lp, $fcsj: fcsj, $ttinfo: ttInfo) | |
| 162 | + $ri: RerunRule_input( | |
| 163 | + type == "dybc", | |
| 164 | + xl == $xlid.toString(), | |
| 165 | + ttinfo == $ttinfo.toString(), | |
| 166 | + lp == $lp.toString(), | |
| 167 | + fcsj == $fcsj | |
| 168 | + ) | |
| 169 | + | |
| 170 | + then | |
| 171 | + | |
| 172 | + $spi.setRerunInfoDybc($ri); | |
| 173 | + | |
| 174 | + | |
| 175 | +end | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | ... | ... |
src/main/resources/rules/shiftloop_fb_2.drl renamed to src/main/resources/rules/kBase1_core_shiftloop.drl
| 1 | -package com.bsth.service.schedule.shiftloop; | |
| 2 | - | |
| 3 | -import org.joda.time.*; | |
| 4 | -import java.util.*; | |
| 5 | - | |
| 6 | -import com.bsth.service.schedule.rules.ttinfo.LpInfoResult_output; | |
| 7 | - | |
| 8 | -import com.bsth.service.schedule.utils.Md5Util; | |
| 9 | - | |
| 10 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input; | |
| 11 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; | |
| 12 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type; | |
| 13 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; | |
| 14 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; | |
| 15 | - | |
| 16 | -import com.bsth.entity.schedule.temp.SchedulePlanRuleResult; | |
| 17 | - | |
| 18 | -import com.bsth.entity.schedule.SchedulePlan; | |
| 19 | - | |
| 20 | -import com.bsth.service.schedule.rules.ScheduleRuleService; | |
| 21 | - | |
| 22 | -import org.slf4j.Logger; | |
| 23 | - | |
| 24 | -global Logger log; | |
| 25 | -global ScheduleResults_output scheduleResult; | |
| 26 | -global ScheduleRuleService scheduleRuleService; | |
| 27 | - | |
| 28 | -/* | |
| 29 | - 存在(翻班格式) | |
| 30 | -*/ | |
| 31 | - | |
| 32 | -//------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------// | |
| 33 | - | |
| 34 | -declare Calcu_days_result_pre | |
| 35 | - ruleId: String // 规则Id | |
| 36 | - ruleMd5: String // 规则md5 | |
| 37 | - ruleEcCount: Integer // 人员范围个数 | |
| 38 | - | |
| 39 | - calcu_index_lp : Integer // 计算之后路牌的起始索引 | |
| 40 | - calcu_index_ry : Integer // 计算之后人员的起始索引 | |
| 41 | - | |
| 42 | - fbtype: Integer // 翻班type,0:时刻表type 1:翻班格式type | |
| 43 | - fbweeks: List // 翻班格式,如:1111001111001 | |
| 44 | - fbgs_index: Integer // 翻班格式起始索引(从0开始) | |
| 45 | - | |
| 46 | - // 1、第一部分循环需要用到的数据(当开始日期大于启用日期的时候才有) | |
| 47 | - calcu_start_date_1: DateTime // 第一部分开始计算日期 | |
| 48 | - calcu_end_date_1: DateTime // 第一部分结束计算日期 | |
| 49 | - | |
| 50 | - // 2、第二部分循环需要用到的数据 | |
| 51 | - sdays : Integer // 总共需要排班的天数 | |
| 52 | - calcu_start_date_2 : DateTime // 开始计算日期 | |
| 53 | - calcu_end_date_2 : DateTime // 结束计算日期 | |
| 54 | - | |
| 55 | -end | |
| 56 | - | |
| 57 | -/* | |
| 58 | - 计算启用日期,开始计算日期,结束计算日期,相差天数 | |
| 59 | - 1、规则启用日期小于开始计算日期 | |
| 60 | - 2、规则启用日期大于等于开始日期,小于等于结束日期 | |
| 61 | -*/ | |
| 62 | -// 1、启用日期 < 开始日期 | |
| 63 | -rule "calcu_days_1_" | |
| 64 | - salience 1000 | |
| 65 | - when | |
| 66 | - ScheduleCalcuParam_input( | |
| 67 | - fromDate.isBefore(toDate) || fromDate.isEqual(toDate), | |
| 68 | - $fromDate : fromDate, | |
| 69 | - $toDate : toDate, | |
| 70 | - $xlId: xlId | |
| 71 | - ) | |
| 72 | - $sri: ScheduleRule_input( | |
| 73 | - $ruleId : ruleId, $qyrq : qyrq, | |
| 74 | - $lpindex : startGbdIndex, $ryindex: startEIndex) | |
| 75 | - eval($qyrq.isBefore($fromDate)) | |
| 76 | - then | |
| 77 | - scheduleResult.setXlid($xlId); | |
| 78 | - | |
| 79 | - // 构造Calcu_days_result_pre,用于路牌 | |
| 80 | - Calcu_days_result_pre cdrp = new Calcu_days_result_pre(); | |
| 81 | - cdrp.setRuleId($ruleId); | |
| 82 | - cdrp.setCalcu_index_lp($lpindex); | |
| 83 | - cdrp.setCalcu_index_ry($ryindex); | |
| 84 | - cdrp.setCalcu_start_date_1($qyrq); | |
| 85 | - cdrp.setCalcu_end_date_1($fromDate); | |
| 86 | - Period p2 = new Period($fromDate, $toDate, PeriodType.days()); | |
| 87 | - cdrp.setSdays(p2.getDays() + 1); | |
| 88 | - cdrp.setCalcu_start_date_2($fromDate); | |
| 89 | - cdrp.setCalcu_end_date_2($toDate); | |
| 90 | - | |
| 91 | - // 翻班相关 | |
| 92 | - cdrp.setFbtype($sri.getFbtype()); | |
| 93 | - cdrp.setFbgs_index(0); | |
| 94 | - cdrp.setFbweeks($sri.getWeekdays()); | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * 规则md5值(不使用id判定,使用md5判定) | |
| 98 | - * 使用,启用日期,路牌范围,结合生成md5编码 | |
| 99 | - */ | |
| 100 | - String ruleMd5 = Md5Util.getMd5( | |
| 101 | - String.valueOf($qyrq.getMillis()) + | |
| 102 | - "_" + | |
| 103 | - $sri.getSelf().getLpIds() + | |
| 104 | - "_" + | |
| 105 | - $sri.getSelf().getLpStart().toString() | |
| 106 | - ); | |
| 107 | - cdrp.setRuleMd5(ruleMd5); | |
| 108 | - // 人员范围个数 | |
| 109 | - cdrp.setRuleEcCount($sri.getEmployeeConfigIds().size()); | |
| 110 | - | |
| 111 | - insert(cdrp); | |
| 112 | - | |
| 113 | -// log.info("总共需要排班的天数 sdays={} ruleId={} from={} to={}", (p2.getDays() + 1), $ruleId, $fromDate, $toDate); | |
| 114 | - | |
| 115 | -end | |
| 116 | - | |
| 117 | -// 启用日期 属于 [开始日期,结束日期] | |
| 118 | -rule "calcu_days_2_" | |
| 119 | - salience 1000 | |
| 120 | - when | |
| 121 | - ScheduleCalcuParam_input( | |
| 122 | - fromDate.isBefore(toDate) || fromDate.isEqual(toDate), | |
| 123 | - $fromDate : fromDate, | |
| 124 | - $toDate : toDate, | |
| 125 | - $xlId: xlId | |
| 126 | - ) | |
| 127 | - $sri: ScheduleRule_input( | |
| 128 | - $ruleId : ruleId, $qyrq : qyrq, | |
| 129 | - $lpindex : startGbdIndex, $ryindex: startEIndex) | |
| 130 | - eval((!$qyrq.isBefore($fromDate)) && (!$qyrq.isAfter($toDate))) | |
| 131 | - then | |
| 132 | - scheduleResult.setXlid($xlId); | |
| 133 | - | |
| 134 | - // 构造Calcu_days_result_pre,用于路牌 | |
| 135 | - Calcu_days_result_pre cdrp = new Calcu_days_result_pre(); | |
| 136 | - cdrp.setRuleId($ruleId); | |
| 137 | - cdrp.setCalcu_index_lp($lpindex); | |
| 138 | - cdrp.setCalcu_index_ry($ryindex); | |
| 139 | - cdrp.setCalcu_start_date_1($qyrq); | |
| 140 | - cdrp.setCalcu_end_date_1($qyrq); | |
| 141 | - Period p2 = new Period($qyrq, $toDate, PeriodType.days()); | |
| 142 | - cdrp.setSdays(p2.getDays() + 1); | |
| 143 | - cdrp.setCalcu_start_date_2($qyrq); | |
| 144 | - cdrp.setCalcu_end_date_2($toDate); | |
| 145 | - | |
| 146 | - // 翻班相关 | |
| 147 | - cdrp.setFbtype($sri.getFbtype()); | |
| 148 | - cdrp.setFbgs_index(0); | |
| 149 | - cdrp.setFbweeks($sri.getWeekdays()); | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * 规则md5值(不使用id判定,使用md5判定) | |
| 153 | - * 使用,启用日期,路牌范围,结合生成md5编码 | |
| 154 | - */ | |
| 155 | - String ruleMd5 = Md5Util.getMd5( | |
| 156 | - String.valueOf($qyrq.getMillis()) + | |
| 157 | - "_" + | |
| 158 | - $sri.getSelf().getLpIds() + | |
| 159 | - "_" + | |
| 160 | - $sri.getSelf().getLpStart().toString() | |
| 161 | - ); | |
| 162 | - cdrp.setRuleMd5(ruleMd5); | |
| 163 | - // 人员范围个数 | |
| 164 | - cdrp.setRuleEcCount($sri.getEmployeeConfigIds().size()); | |
| 165 | - | |
| 166 | - insert(cdrp); | |
| 167 | - | |
| 168 | -// log.info("总共需要排班的天数 sdays={} ruleId={} from={} to={}", (p2.getDays() + 1), $ruleId, $qyrq, $toDate); | |
| 169 | - | |
| 170 | -end | |
| 171 | - | |
| 172 | -// 使用已经排过班的数据修正Calcu_days_result_pre | |
| 173 | -// 1、避免每次从规则的启用日期开始算 | |
| 174 | -// 2、时刻表会不停的修正,如果每次都从规则启用日期开始算,会出错 | |
| 175 | - | |
| 176 | -declare SchedulePlanRuleResult_wrap | |
| 177 | - ruleId: String // 规则Id | |
| 178 | - ruleMd5: String // 规则md5编码 | |
| 179 | - scheduleDate: DateTime // 排班日期 | |
| 180 | - | |
| 181 | - isUsed: Boolean = false // 是否被使用过 | |
| 182 | - | |
| 183 | - self: SchedulePlanRuleResult; // 原始对象数据 | |
| 184 | -end | |
| 185 | - | |
| 186 | -rule "Calcu_SchedulePlanRuleResult_wrap" | |
| 187 | - salience 950 | |
| 188 | - when | |
| 189 | - ScheduleCalcuParam_input( | |
| 190 | - fromDate.isBefore(toDate) || fromDate.isEqual(toDate), | |
| 191 | - $fromDate : fromDate, | |
| 192 | - $toDate : toDate, | |
| 193 | - $xlId: xlId, | |
| 194 | - $self: schedulePlan | |
| 195 | - ) | |
| 196 | - eval($self.getIsHistoryPlanFirst() == true) // 是否使用历史排班标识 | |
| 197 | - $sprr: SchedulePlanRuleResult() from scheduleRuleService.findLastByXl($xlId, $fromDate.toDate()) | |
| 198 | - eval($sprr.getQyrq() != null) | |
| 199 | - | |
| 200 | - then | |
| 201 | - // 创建班序历史结果数据 | |
| 202 | - SchedulePlanRuleResult_wrap schedulePlanRuleResult_wrap = new SchedulePlanRuleResult_wrap(); | |
| 203 | - schedulePlanRuleResult_wrap.setRuleId($sprr.getRuleId()); | |
| 204 | - schedulePlanRuleResult_wrap.setScheduleDate(new DateTime($sprr.getScheduleDate())); | |
| 205 | - schedulePlanRuleResult_wrap.setSelf($sprr); | |
| 206 | - | |
| 207 | - // 规则Md5编码 | |
| 208 | - String md5 = Md5Util.getMd5( | |
| 209 | - String.valueOf($sprr.getQyrq().getTime()) + | |
| 210 | - "_" + | |
| 211 | - $sprr.getGids() + | |
| 212 | - "_" + | |
| 213 | - $sprr.getOrigingidindex() | |
| 214 | - ); | |
| 215 | - | |
| 216 | -// System.out.println("修改后的md5:" + md5 + "车辆:" + $sprr.getCcZbh()); | |
| 217 | - | |
| 218 | - schedulePlanRuleResult_wrap.setRuleMd5(md5); | |
| 219 | - | |
| 220 | - insert(schedulePlanRuleResult_wrap); | |
| 221 | -end | |
| 222 | - | |
| 223 | - | |
| 224 | -// 1、启用日期 < 开始日期 | |
| 225 | -// 2、如果最近的排班规则历史时间在 (启用日期,开始日期) 之间,需要重新修正预处理数据 | |
| 226 | -rule "calcu_days_1_with_result" | |
| 227 | - no-loop | |
| 228 | - salience 960 | |
| 229 | - when | |
| 230 | - $cdrp: Calcu_days_result_pre( | |
| 231 | - calcu_start_date_1.isBefore(calcu_start_date_2), | |
| 232 | - $ruleId: ruleId, | |
| 233 | - $ruleMd5: ruleMd5, | |
| 234 | - $ruleEcCount: ruleEcCount | |
| 235 | - ) | |
| 236 | - $srrr_wrap: SchedulePlanRuleResult_wrap( | |
| 237 | -// ruleId == $ruleId, | |
| 238 | - ruleMd5 == $ruleMd5, | |
| 239 | - scheduleDate.isAfter($cdrp.calcu_start_date_1), | |
| 240 | - scheduleDate.isBefore($cdrp.calcu_start_date_2), | |
| 241 | - isUsed == false, | |
| 242 | - $scheduleDate: scheduleDate, | |
| 243 | - $self: self | |
| 244 | - ) | |
| 245 | - then | |
| 246 | - // 修正排班数据 | |
| 247 | -// log.info("准备修正 ruleId={} historyDate={}", $ruleId, $scheduleDate); | |
| 248 | - | |
| 249 | - // 路牌范围起始index使用历史数据 | |
| 250 | - $cdrp.setCalcu_index_lp(Integer.valueOf($self.getGidindex())); | |
| 251 | - // 人员范围起始index,需要判定,如果长度都是一样的,使用历史的,否则不更新,使用最新的 | |
| 252 | - String history_ecids = $self.getEcids(); | |
| 253 | - if ($ruleEcCount == history_ecids.split(",").length) { | |
| 254 | - $cdrp.setCalcu_index_ry(Integer.valueOf($self.getEcindex())); | |
| 255 | - } | |
| 256 | - | |
| 257 | - // 翻班格式利用路牌的历史index更新 | |
| 258 | - int fb_temp = Integer.valueOf($self.getGidindex()) % $cdrp.getFbweeks().size(); | |
| 259 | - $cdrp.setFbgs_index(fb_temp); | |
| 260 | - | |
| 261 | - $cdrp.setCalcu_start_date_1($scheduleDate); | |
| 262 | - update($cdrp); | |
| 263 | - | |
| 264 | - $srrr_wrap.setIsUsed(true); | |
| 265 | - update($srrr_wrap); | |
| 266 | - | |
| 267 | -end | |
| 268 | - | |
| 269 | - | |
| 270 | - | |
| 271 | -//------------------------- 第二阶段、计算规则准备数据2(第一组循环) ----------------------------// | |
| 272 | - | |
| 273 | -function void calcu_loop1_fb(Calcu_days_result_pre $cdrp, ScheduleRule_input $sri, Logger log) { | |
| 274 | - Integer $lpindex = $cdrp.getCalcu_index_lp(); | |
| 275 | - Integer $lprangesize = $sri.getGuideboardIds().size(); | |
| 276 | - Integer $ryindex = $cdrp.getCalcu_index_ry(); | |
| 277 | - Integer $ryrangesize = $sri.getEmployeeConfigIds().size(); | |
| 278 | - Integer $fbindex = $cdrp.getFbgs_index(); | |
| 279 | - Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 280 | - DateTime $csd1 = $cdrp.getCalcu_start_date_1(); | |
| 281 | - DateTime $ced1 = $cdrp.getCalcu_end_date_1(); | |
| 282 | - | |
| 283 | - String $ruleId = $cdrp.getRuleId(); | |
| 284 | - | |
| 285 | - $cdrp.setCalcu_index_lp(($lpindex + 1) % $lprangesize); | |
| 286 | - $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize); | |
| 287 | - | |
| 288 | - $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 289 | - $cdrp.setCalcu_start_date_1($csd1.plusDays(1)); | |
| 290 | - | |
| 291 | -// log.info("calcu_loop1_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 292 | -// $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd1, $ced1); | |
| 293 | - | |
| 294 | -} | |
| 295 | -function void calcu_loop1_not_fb(Calcu_days_result_pre $cdrp, ScheduleRule_input $sri, Logger log) { | |
| 296 | - DateTime $csd1 = $cdrp.getCalcu_start_date_1(); | |
| 297 | - DateTime $ced1 = $cdrp.getCalcu_end_date_1(); | |
| 298 | - Integer $fbindex = $cdrp.getFbgs_index(); | |
| 299 | - Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 300 | - | |
| 301 | - $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 302 | - $cdrp.setCalcu_start_date_1($csd1.plusDays(1)); | |
| 303 | - | |
| 304 | -// log.info("calcu_loop1_not_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 305 | -// $cdrp.getRuleId(), $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd1, $ced1); | |
| 306 | -} | |
| 307 | - | |
| 308 | - | |
| 309 | -rule "Calcu_loop1_fbtype_with_0_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是false,就跳过 | |
| 310 | - salience 900 | |
| 311 | - when | |
| 312 | - $cdrp: Calcu_days_result_pre( | |
| 313 | - calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 314 | - $ruleId: ruleId, | |
| 315 | - fbtype == "1", | |
| 316 | - $fbindex : fbgs_index | |
| 317 | - ) | |
| 318 | - $sri: ScheduleRule_input( | |
| 319 | - ruleId == $ruleId, | |
| 320 | - weekdays[$fbindex] == false | |
| 321 | - ) | |
| 322 | - then | |
| 323 | - calcu_loop1_not_fb($cdrp, $sri, log); | |
| 324 | - update($cdrp); | |
| 325 | -end | |
| 326 | - | |
| 327 | -rule "Calcu_loop1_fbtype_with_1_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里存在指定路牌,就翻 | |
| 328 | - salience 900 | |
| 329 | - when | |
| 330 | - $cdrp: Calcu_days_result_pre( | |
| 331 | - calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 332 | - $csd1: calcu_start_date_1, | |
| 333 | - $ruleId: ruleId, | |
| 334 | - fbtype == "1", | |
| 335 | - $lpindex: calcu_index_lp, | |
| 336 | - $fbindex : fbgs_index | |
| 337 | - ) | |
| 338 | - $sri: ScheduleRule_input( | |
| 339 | - ruleId == $ruleId, | |
| 340 | - $gids: guideboardIds, | |
| 341 | - weekdays[$fbindex] == true | |
| 342 | - ) | |
| 343 | - $liro: LpInfoResult_output( | |
| 344 | - dateTime.isEqual($csd1), | |
| 345 | - $gids[$lpindex] == lpId | |
| 346 | - ) | |
| 347 | - then | |
| 348 | - calcu_loop1_fb($cdrp, $sri, log); | |
| 349 | - update($cdrp); | |
| 350 | - | |
| 351 | -end | |
| 352 | - | |
| 353 | -rule "Calcu_loop1_fbtype_with_1_no_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里不存在指定路牌,就跳过 | |
| 354 | - salience 900 | |
| 355 | - when | |
| 356 | - $cdrp: Calcu_days_result_pre( | |
| 357 | - calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 358 | - $csd1: calcu_start_date_1, | |
| 359 | - $ruleId: ruleId, | |
| 360 | - fbtype == "1", | |
| 361 | - $fbindex : fbgs_index | |
| 362 | - ) | |
| 363 | - $sri: ScheduleRule_input( | |
| 364 | - ruleId == $ruleId, | |
| 365 | - weekdays[$fbindex] == true | |
| 366 | - ) | |
| 367 | - then | |
| 368 | - calcu_loop1_not_fb($cdrp, $sri, log); | |
| 369 | - update($cdrp); | |
| 370 | -end | |
| 371 | - | |
| 372 | - | |
| 373 | -rule "Calcu_loop1_timetabletype_with_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中存在,就翻 | |
| 374 | - salience 900 | |
| 375 | - when | |
| 376 | - $cdrp: Calcu_days_result_pre( | |
| 377 | - calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 378 | - $csd1: calcu_start_date_1, | |
| 379 | - $ruleId: ruleId, | |
| 380 | - fbtype == "0", | |
| 381 | - $lpindex: calcu_index_lp | |
| 382 | - ) | |
| 383 | - $sri: ScheduleRule_input( | |
| 384 | - ruleId == $ruleId, | |
| 385 | - $gids: guideboardIds | |
| 386 | - ) | |
| 387 | - $liro: LpInfoResult_output( | |
| 388 | - dateTime.isEqual($csd1), | |
| 389 | - $gids[$lpindex] == lpId | |
| 390 | - ) | |
| 391 | - then | |
| 392 | - calcu_loop1_fb($cdrp, $sri, log); | |
| 393 | - update($cdrp); | |
| 394 | -end | |
| 395 | - | |
| 396 | -rule "Calcu_loop1_timetabletype_with_no_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中不存在,就跳过 | |
| 397 | - salience 900 | |
| 398 | - when | |
| 399 | - $cdrp: Calcu_days_result_pre( | |
| 400 | - calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 401 | - $csd1: calcu_start_date_1, | |
| 402 | - $ruleId: ruleId, | |
| 403 | - fbtype == "0" | |
| 404 | - ) | |
| 405 | - $sri: ScheduleRule_input( | |
| 406 | - ruleId == $ruleId | |
| 407 | - ) | |
| 408 | - then | |
| 409 | - calcu_loop1_not_fb($cdrp, $sri, log); | |
| 410 | - update($cdrp); | |
| 411 | -end | |
| 412 | - | |
| 413 | -//------------------------- 第三阶段、计算规则准备数据2(第二组循环) ----------------------------// | |
| 414 | - | |
| 415 | -function void calcu_loop2_fb( | |
| 416 | - SchedulePlan $sp, | |
| 417 | - Calcu_days_result_pre $cdrp, | |
| 418 | - ScheduleRule_input $sri, | |
| 419 | - LpInfoResult_output $liro, | |
| 420 | - ScheduleResults_output rs, | |
| 421 | - Logger log) { | |
| 422 | - String $ruleId = $cdrp.getRuleId(); | |
| 423 | - DateTime $csd2 = $cdrp.getCalcu_start_date_2(); | |
| 424 | - DateTime $ced2 = $cdrp.getCalcu_end_date_2(); | |
| 425 | - Integer $lpindex = $cdrp.getCalcu_index_lp(); | |
| 426 | - List $gids = $sri.getGuideboardIds(); | |
| 427 | - Integer $lprangesize = $sri.getGuideboardIds().size(); | |
| 428 | - Integer $ryindex = $cdrp.getCalcu_index_ry(); | |
| 429 | - List $eids = $sri.getEmployeeConfigIds(); | |
| 430 | - Integer $ryrangesize = $sri.getEmployeeConfigIds().size(); | |
| 431 | - Integer $fbindex = $cdrp.getFbgs_index(); | |
| 432 | - Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 433 | - String $cid = $sri.getCarConfigId(); | |
| 434 | - String $xlid = $sri.getXlId(); | |
| 435 | - | |
| 436 | - com.bsth.entity.schedule.rule.ScheduleRule1Flat $srf = $sri.getSelf(); | |
| 437 | - | |
| 438 | - String $ttinfoId = $liro.getTtInfoId(); | |
| 439 | - String $ttinfoName = $liro.getTtInfoName(); | |
| 440 | - | |
| 441 | - ScheduleResult_output ro = new ScheduleResult_output(); | |
| 442 | - ro.setRuleId($ruleId); | |
| 443 | - ro.setSd($csd2); | |
| 444 | - ro.setGuideboardId(String.valueOf($gids.get($lpindex))); | |
| 445 | - ro.setEmployeeConfigId(String.valueOf($eids.get($ryindex))); | |
| 446 | - ro.setCarConfigId($cid); | |
| 447 | - ro.setXlId($xlid); | |
| 448 | - | |
| 449 | - // 类型 | |
| 450 | - ro.setsType($sri.getsType()); | |
| 451 | - | |
| 452 | - rs.getResults().add(ro); | |
| 453 | - | |
| 454 | -// log.info("gogoogogogogo"); | |
| 455 | - | |
| 456 | - $cdrp.setCalcu_index_lp(($lpindex + 1) % $lprangesize); | |
| 457 | - $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize); | |
| 458 | - | |
| 459 | - $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 460 | - $cdrp.setCalcu_start_date_2($csd2.plusDays(1)); | |
| 461 | - | |
| 462 | - if ($sri.getsType() == ScheduleRule_Type.NORMAL) { | |
| 463 | - // 保存排班规则循环结果 --> SchedulePlanRuleResult | |
| 464 | - SchedulePlanRuleResult schedulePlanRuleResult = new SchedulePlanRuleResult($sp); | |
| 465 | -// schedulePlanRuleResult.setXlId(String.valueOf($srf.getXl().getId())); | |
| 466 | - schedulePlanRuleResult.setXlId($srf.getXl().getId()); | |
| 467 | - schedulePlanRuleResult.setXlName($srf.getXl().getName()); | |
| 468 | - schedulePlanRuleResult.setRuleId($ruleId); | |
| 469 | - schedulePlanRuleResult.setCcId($cid); | |
| 470 | - schedulePlanRuleResult.setCcZbh($srf.getCarConfigInfo().getCl().getInsideCode()); | |
| 471 | - schedulePlanRuleResult.setGids($srf.getLpIds()); // 参与md5计算 | |
| 472 | - schedulePlanRuleResult.setGnames($srf.getLpNames()); | |
| 473 | - schedulePlanRuleResult.setGidindex(String.valueOf($lpindex)); | |
| 474 | - schedulePlanRuleResult.setEcids($srf.getRyConfigIds()); | |
| 475 | - schedulePlanRuleResult.setEcdbbms($srf.getRyDbbms()); | |
| 476 | - schedulePlanRuleResult.setEcindex(String.valueOf($ryindex)); | |
| 477 | - schedulePlanRuleResult.setScheduleDate($csd2.toDate()); | |
| 478 | - schedulePlanRuleResult.setTtinfoId($ttinfoId); | |
| 479 | - schedulePlanRuleResult.setTtinfoName($ttinfoName); | |
| 480 | - schedulePlanRuleResult.setQyrq($sri.getQyrq().toDate()); // 参与md5计算 | |
| 481 | - schedulePlanRuleResult.setOrigingidindex(String.valueOf($sri.getSelf().getLpStart())); // 参与md5计算 | |
| 482 | - | |
| 483 | - rs.getSchedulePlanRuleResults().add(schedulePlanRuleResult); | |
| 484 | - } | |
| 485 | - | |
| 486 | - | |
| 487 | - | |
| 488 | -// log.info("calcu_loop2_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 489 | -// $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2); | |
| 490 | - | |
| 491 | -} | |
| 492 | - | |
| 493 | -function void calcu_loop2_not_fb( | |
| 494 | - Calcu_days_result_pre $cdrp, | |
| 495 | - ScheduleRule_input $sri, | |
| 496 | - ScheduleResults_output rs, | |
| 497 | - Logger log) { | |
| 498 | - | |
| 499 | - String $ruleId = $cdrp.getRuleId(); | |
| 500 | - DateTime $csd2 = $cdrp.getCalcu_start_date_2(); | |
| 501 | - DateTime $ced2 = $cdrp.getCalcu_end_date_2(); | |
| 502 | - Integer $lpindex = $cdrp.getCalcu_index_lp(); | |
| 503 | - List $gids = $sri.getGuideboardIds(); | |
| 504 | - Integer $ryindex = $cdrp.getCalcu_index_ry(); | |
| 505 | - List $eids = $sri.getEmployeeConfigIds(); | |
| 506 | - Integer $fbindex = $cdrp.getFbgs_index(); | |
| 507 | - Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 508 | - String $cid = $sri.getCarConfigId(); | |
| 509 | - String $xlid = $sri.getXlId(); | |
| 510 | - | |
| 511 | - ScheduleResult_output ro = new ScheduleResult_output(); | |
| 512 | - ro.setRuleId($ruleId); | |
| 513 | - ro.setSd($csd2); | |
| 514 | -// ro.setGuideboardId(String.valueOf($gids.get($lpindex))); | |
| 515 | - ro.setGuideboardId("not_fb_lp"); // 不翻班,路牌id用假的,后面会过滤 | |
| 516 | - ro.setEmployeeConfigId(String.valueOf($eids.get($ryindex))); | |
| 517 | - ro.setCarConfigId($cid); | |
| 518 | - ro.setXlId($xlid); | |
| 519 | - | |
| 520 | - // 类型 | |
| 521 | - ro.setsType($sri.getsType()); | |
| 522 | - | |
| 523 | - rs.getResults().add(ro); | |
| 524 | - | |
| 525 | - $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 526 | - $cdrp.setCalcu_start_date_2($csd2.plusDays(1)); | |
| 527 | - | |
| 528 | -// log.info("calcu_loop2_not_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 529 | -// $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2); | |
| 530 | - | |
| 531 | -} | |
| 532 | - | |
| 533 | -rule "Calcu_loop2_fbtype_with_0_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是false,就跳过 | |
| 534 | - salience 800 | |
| 535 | - when | |
| 536 | - ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 537 | - $cdrp: Calcu_days_result_pre( | |
| 538 | - calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 539 | - calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 540 | - $ruleId: ruleId, | |
| 541 | - fbtype == "1", | |
| 542 | - $fbindex : fbgs_index | |
| 543 | - ) | |
| 544 | - $sri: ScheduleRule_input( | |
| 545 | - ruleId == $ruleId, | |
| 546 | - weekdays[$fbindex] == false | |
| 547 | - ) | |
| 548 | - then | |
| 549 | - calcu_loop2_not_fb($cdrp, $sri, scheduleResult, log); | |
| 550 | - update($cdrp); | |
| 551 | - | |
| 552 | -end | |
| 553 | - | |
| 554 | -rule "Calcu_loop2_fbtype_with_1_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里存在指定路牌,就翻 | |
| 555 | - salience 800 | |
| 556 | - when | |
| 557 | - ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 558 | - $cdrp: Calcu_days_result_pre( | |
| 559 | - calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 560 | - calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 561 | - $csd2: calcu_start_date_2, | |
| 562 | - $ruleId: ruleId, | |
| 563 | - fbtype == "1", | |
| 564 | - $lpindex: calcu_index_lp, | |
| 565 | - $fbindex : fbgs_index | |
| 566 | - ) | |
| 567 | - $sri: ScheduleRule_input( | |
| 568 | - ruleId == $ruleId, | |
| 569 | - $gids: guideboardIds, | |
| 570 | - weekdays[$fbindex] == true | |
| 571 | - ) | |
| 572 | - $liro: LpInfoResult_output( | |
| 573 | - dateTime.isEqual($csd2), | |
| 574 | - $gids[$lpindex] == lpId | |
| 575 | - ) | |
| 576 | - then | |
| 577 | - calcu_loop2_fb($sp, $cdrp, $sri, $liro, scheduleResult, log); | |
| 578 | - update($cdrp); | |
| 579 | -end | |
| 580 | - | |
| 581 | -rule "Calcu_loop2_fbtype_with_1_no_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里不存在指定路牌,就跳过 | |
| 582 | - salience 800 | |
| 583 | - when | |
| 584 | - ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 585 | - $cdrp: Calcu_days_result_pre( | |
| 586 | - calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 587 | - calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 588 | - $ruleId: ruleId, | |
| 589 | - fbtype == "1", | |
| 590 | - $fbindex : fbgs_index | |
| 591 | - ) | |
| 592 | - $sri: ScheduleRule_input( | |
| 593 | - ruleId == $ruleId, | |
| 594 | - weekdays[$fbindex] == true | |
| 595 | - ) | |
| 596 | - then | |
| 597 | - calcu_loop2_not_fb($cdrp, $sri, scheduleResult, log); | |
| 598 | - update($cdrp); | |
| 599 | - | |
| 600 | -end | |
| 601 | - | |
| 602 | -rule "Calcu_loop2_timetabletype_with_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中存在,就翻 | |
| 603 | - salience 800 | |
| 604 | - when | |
| 605 | - ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 606 | - $cdrp: Calcu_days_result_pre( | |
| 607 | - calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 608 | - calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 609 | - $csd2: calcu_start_date_2, | |
| 610 | - $ruleId: ruleId, | |
| 611 | - fbtype == "0", | |
| 612 | - $lpindex: calcu_index_lp, | |
| 613 | - $fbindex : fbgs_index | |
| 614 | - ) | |
| 615 | - $sri: ScheduleRule_input( | |
| 616 | - ruleId == $ruleId, | |
| 617 | - $gids: guideboardIds | |
| 618 | - ) | |
| 619 | - $liro: LpInfoResult_output( | |
| 620 | - dateTime.isEqual($csd2), | |
| 621 | - $gids[$lpindex] == lpId | |
| 622 | - ) | |
| 623 | - then | |
| 624 | - calcu_loop2_fb($sp, $cdrp, $sri, $liro, scheduleResult, log); | |
| 625 | - update($cdrp); | |
| 626 | - | |
| 627 | -end | |
| 628 | - | |
| 629 | -rule "Calcu_loop2_timetabletype_with_no_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中不存在,就跳过 | |
| 630 | - salience 800 | |
| 631 | - when | |
| 632 | - ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 633 | - $cdrp: Calcu_days_result_pre( | |
| 634 | - calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 635 | - calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 636 | - $ruleId: ruleId, | |
| 637 | - fbtype == "0" | |
| 638 | - ) | |
| 639 | - $sri: ScheduleRule_input( | |
| 640 | - ruleId == $ruleId | |
| 641 | - ) | |
| 642 | - then | |
| 643 | - calcu_loop2_not_fb($cdrp, $sri, scheduleResult, log); | |
| 644 | - update($cdrp); | |
| 645 | -end | |
| 646 | - | |
| 647 | - | |
| 648 | - | |
| 649 | - | |
| 650 | - | |
| 651 | - | |
| 652 | - | |
| 653 | - | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop; | |
| 2 | + | |
| 3 | +import org.joda.time.*; | |
| 4 | +import java.util.*; | |
| 5 | + | |
| 6 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResult_output; | |
| 7 | + | |
| 8 | +import com.bsth.service.schedule.utils.Md5Util; | |
| 9 | + | |
| 10 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleCalcuParam_input; | |
| 11 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_input; | |
| 12 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_Type; | |
| 13 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResult_output; | |
| 14 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleResults_output; | |
| 15 | + | |
| 16 | +import com.bsth.entity.schedule.temp.SchedulePlanRuleResult; | |
| 17 | + | |
| 18 | +import com.bsth.entity.schedule.SchedulePlan; | |
| 19 | + | |
| 20 | +import com.bsth.service.schedule.impl.plan.ScheduleRuleService; | |
| 21 | + | |
| 22 | +import org.slf4j.Logger; | |
| 23 | + | |
| 24 | +global Logger log; | |
| 25 | +global ScheduleResults_output scheduleResult; | |
| 26 | +global ScheduleRuleService scheduleRuleService; | |
| 27 | + | |
| 28 | +/* | |
| 29 | + 存在(翻班格式) | |
| 30 | +*/ | |
| 31 | + | |
| 32 | +//------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------// | |
| 33 | + | |
| 34 | +declare Calcu_days_result_pre | |
| 35 | + ruleId: String // 规则Id | |
| 36 | + ruleMd5: String // 规则md5 | |
| 37 | + ruleEcCount: Integer // 人员范围个数 | |
| 38 | + | |
| 39 | + calcu_index_lp : Integer // 计算之后路牌的起始索引 | |
| 40 | + calcu_index_ry : Integer // 计算之后人员的起始索引 | |
| 41 | + | |
| 42 | + fbtype: Integer // 翻班type,0:时刻表type 1:翻班格式type | |
| 43 | + fbweeks: List // 翻班格式,如:1111001111001 | |
| 44 | + fbgs_index: Integer // 翻班格式起始索引(从0开始) | |
| 45 | + | |
| 46 | + // 1、第一部分循环需要用到的数据(当开始日期大于启用日期的时候才有) | |
| 47 | + calcu_start_date_1: DateTime // 第一部分开始计算日期 | |
| 48 | + calcu_end_date_1: DateTime // 第一部分结束计算日期 | |
| 49 | + | |
| 50 | + // 2、第二部分循环需要用到的数据 | |
| 51 | + sdays : Integer // 总共需要排班的天数 | |
| 52 | + calcu_start_date_2 : DateTime // 开始计算日期 | |
| 53 | + calcu_end_date_2 : DateTime // 结束计算日期 | |
| 54 | + | |
| 55 | +end | |
| 56 | + | |
| 57 | +/* | |
| 58 | + 计算启用日期,开始计算日期,结束计算日期,相差天数 | |
| 59 | + 1、规则启用日期小于开始计算日期 | |
| 60 | + 2、规则启用日期大于等于开始日期,小于等于结束日期 | |
| 61 | +*/ | |
| 62 | +// 1、启用日期 < 开始日期 | |
| 63 | +rule "calcu_days_1_" | |
| 64 | + salience 1000 | |
| 65 | + when | |
| 66 | + ScheduleCalcuParam_input( | |
| 67 | + fromDate.isBefore(toDate) || fromDate.isEqual(toDate), | |
| 68 | + $fromDate : fromDate, | |
| 69 | + $toDate : toDate, | |
| 70 | + $xlId: xlId | |
| 71 | + ) | |
| 72 | + $sri: ScheduleRule_input( | |
| 73 | + $ruleId : ruleId, $qyrq : qyrq, | |
| 74 | + $lpindex : startGbdIndex, $ryindex: startEIndex) | |
| 75 | + eval($qyrq.isBefore($fromDate)) | |
| 76 | + then | |
| 77 | + scheduleResult.setXlid($xlId); | |
| 78 | + | |
| 79 | + // 构造Calcu_days_result_pre,用于路牌 | |
| 80 | + Calcu_days_result_pre cdrp = new Calcu_days_result_pre(); | |
| 81 | + cdrp.setRuleId($ruleId); | |
| 82 | + cdrp.setCalcu_index_lp($lpindex); | |
| 83 | + cdrp.setCalcu_index_ry($ryindex); | |
| 84 | + cdrp.setCalcu_start_date_1($qyrq); | |
| 85 | + cdrp.setCalcu_end_date_1($fromDate); | |
| 86 | + Period p2 = new Period($fromDate, $toDate, PeriodType.days()); | |
| 87 | + cdrp.setSdays(p2.getDays() + 1); | |
| 88 | + cdrp.setCalcu_start_date_2($fromDate); | |
| 89 | + cdrp.setCalcu_end_date_2($toDate); | |
| 90 | + | |
| 91 | + // 翻班相关 | |
| 92 | + cdrp.setFbtype($sri.getFbtype()); | |
| 93 | + cdrp.setFbgs_index(0); | |
| 94 | + cdrp.setFbweeks($sri.getWeekdays()); | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * 规则md5值(不使用id判定,使用md5判定) | |
| 98 | + * 使用,启用日期,路牌范围,结合生成md5编码 | |
| 99 | + */ | |
| 100 | + String ruleMd5 = Md5Util.getMd5( | |
| 101 | + String.valueOf($qyrq.getMillis()) + | |
| 102 | + "_" + | |
| 103 | + $sri.getSelf().getLpIds() + | |
| 104 | + "_" + | |
| 105 | + $sri.getSelf().getLpStart().toString() | |
| 106 | + ); | |
| 107 | + cdrp.setRuleMd5(ruleMd5); | |
| 108 | + // 人员范围个数 | |
| 109 | + cdrp.setRuleEcCount($sri.getEmployeeConfigIds().size()); | |
| 110 | + | |
| 111 | + insert(cdrp); | |
| 112 | + | |
| 113 | +// log.info("总共需要排班的天数 sdays={} ruleId={} from={} to={}", (p2.getDays() + 1), $ruleId, $fromDate, $toDate); | |
| 114 | + | |
| 115 | +end | |
| 116 | + | |
| 117 | +// 启用日期 属于 [开始日期,结束日期] | |
| 118 | +rule "calcu_days_2_" | |
| 119 | + salience 1000 | |
| 120 | + when | |
| 121 | + ScheduleCalcuParam_input( | |
| 122 | + fromDate.isBefore(toDate) || fromDate.isEqual(toDate), | |
| 123 | + $fromDate : fromDate, | |
| 124 | + $toDate : toDate, | |
| 125 | + $xlId: xlId | |
| 126 | + ) | |
| 127 | + $sri: ScheduleRule_input( | |
| 128 | + $ruleId : ruleId, $qyrq : qyrq, | |
| 129 | + $lpindex : startGbdIndex, $ryindex: startEIndex) | |
| 130 | + eval((!$qyrq.isBefore($fromDate)) && (!$qyrq.isAfter($toDate))) | |
| 131 | + then | |
| 132 | + scheduleResult.setXlid($xlId); | |
| 133 | + | |
| 134 | + // 构造Calcu_days_result_pre,用于路牌 | |
| 135 | + Calcu_days_result_pre cdrp = new Calcu_days_result_pre(); | |
| 136 | + cdrp.setRuleId($ruleId); | |
| 137 | + cdrp.setCalcu_index_lp($lpindex); | |
| 138 | + cdrp.setCalcu_index_ry($ryindex); | |
| 139 | + cdrp.setCalcu_start_date_1($qyrq); | |
| 140 | + cdrp.setCalcu_end_date_1($qyrq); | |
| 141 | + Period p2 = new Period($qyrq, $toDate, PeriodType.days()); | |
| 142 | + cdrp.setSdays(p2.getDays() + 1); | |
| 143 | + cdrp.setCalcu_start_date_2($qyrq); | |
| 144 | + cdrp.setCalcu_end_date_2($toDate); | |
| 145 | + | |
| 146 | + // 翻班相关 | |
| 147 | + cdrp.setFbtype($sri.getFbtype()); | |
| 148 | + cdrp.setFbgs_index(0); | |
| 149 | + cdrp.setFbweeks($sri.getWeekdays()); | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * 规则md5值(不使用id判定,使用md5判定) | |
| 153 | + * 使用,启用日期,路牌范围,结合生成md5编码 | |
| 154 | + */ | |
| 155 | + String ruleMd5 = Md5Util.getMd5( | |
| 156 | + String.valueOf($qyrq.getMillis()) + | |
| 157 | + "_" + | |
| 158 | + $sri.getSelf().getLpIds() + | |
| 159 | + "_" + | |
| 160 | + $sri.getSelf().getLpStart().toString() | |
| 161 | + ); | |
| 162 | + cdrp.setRuleMd5(ruleMd5); | |
| 163 | + // 人员范围个数 | |
| 164 | + cdrp.setRuleEcCount($sri.getEmployeeConfigIds().size()); | |
| 165 | + | |
| 166 | + insert(cdrp); | |
| 167 | + | |
| 168 | +// log.info("总共需要排班的天数 sdays={} ruleId={} from={} to={}", (p2.getDays() + 1), $ruleId, $qyrq, $toDate); | |
| 169 | + | |
| 170 | +end | |
| 171 | + | |
| 172 | +// 使用已经排过班的数据修正Calcu_days_result_pre | |
| 173 | +// 1、避免每次从规则的启用日期开始算 | |
| 174 | +// 2、时刻表会不停的修正,如果每次都从规则启用日期开始算,会出错 | |
| 175 | + | |
| 176 | +declare SchedulePlanRuleResult_wrap | |
| 177 | + ruleId: String // 规则Id | |
| 178 | + ruleMd5: String // 规则md5编码 | |
| 179 | + scheduleDate: DateTime // 排班日期 | |
| 180 | + | |
| 181 | + isUsed: Boolean = false // 是否被使用过 | |
| 182 | + | |
| 183 | + self: SchedulePlanRuleResult; // 原始对象数据 | |
| 184 | +end | |
| 185 | + | |
| 186 | +rule "Calcu_SchedulePlanRuleResult_wrap" | |
| 187 | + salience 950 | |
| 188 | + when | |
| 189 | + ScheduleCalcuParam_input( | |
| 190 | + fromDate.isBefore(toDate) || fromDate.isEqual(toDate), | |
| 191 | + $fromDate : fromDate, | |
| 192 | + $toDate : toDate, | |
| 193 | + $xlId: xlId, | |
| 194 | + $self: schedulePlan | |
| 195 | + ) | |
| 196 | + eval($self.getIsHistoryPlanFirst() == true) // 是否使用历史排班标识 | |
| 197 | + $sprr: SchedulePlanRuleResult() from scheduleRuleService.findLastByXl($xlId, $fromDate.toDate()) | |
| 198 | + eval($sprr.getQyrq() != null) | |
| 199 | + | |
| 200 | + then | |
| 201 | + // 创建班序历史结果数据 | |
| 202 | + SchedulePlanRuleResult_wrap schedulePlanRuleResult_wrap = new SchedulePlanRuleResult_wrap(); | |
| 203 | + schedulePlanRuleResult_wrap.setRuleId($sprr.getRuleId()); | |
| 204 | + schedulePlanRuleResult_wrap.setScheduleDate(new DateTime($sprr.getScheduleDate())); | |
| 205 | + schedulePlanRuleResult_wrap.setSelf($sprr); | |
| 206 | + | |
| 207 | + // 规则Md5编码 | |
| 208 | + String md5 = Md5Util.getMd5( | |
| 209 | + String.valueOf($sprr.getQyrq().getTime()) + | |
| 210 | + "_" + | |
| 211 | + $sprr.getGids() + | |
| 212 | + "_" + | |
| 213 | + $sprr.getOrigingidindex() | |
| 214 | + ); | |
| 215 | + | |
| 216 | +// System.out.println("修改后的md5:" + md5 + "车辆:" + $sprr.getCcZbh()); | |
| 217 | + | |
| 218 | + schedulePlanRuleResult_wrap.setRuleMd5(md5); | |
| 219 | + | |
| 220 | + insert(schedulePlanRuleResult_wrap); | |
| 221 | +end | |
| 222 | + | |
| 223 | + | |
| 224 | +// 1、启用日期 < 开始日期 | |
| 225 | +// 2、如果最近的排班规则历史时间在 (启用日期,开始日期) 之间,需要重新修正预处理数据 | |
| 226 | +rule "calcu_days_1_with_result" | |
| 227 | + no-loop | |
| 228 | + salience 960 | |
| 229 | + when | |
| 230 | + $cdrp: Calcu_days_result_pre( | |
| 231 | + calcu_start_date_1.isBefore(calcu_start_date_2), | |
| 232 | + $ruleId: ruleId, | |
| 233 | + $ruleMd5: ruleMd5, | |
| 234 | + $ruleEcCount: ruleEcCount | |
| 235 | + ) | |
| 236 | + $srrr_wrap: SchedulePlanRuleResult_wrap( | |
| 237 | +// ruleId == $ruleId, | |
| 238 | + ruleMd5 == $ruleMd5, | |
| 239 | + scheduleDate.isAfter($cdrp.calcu_start_date_1), | |
| 240 | + scheduleDate.isBefore($cdrp.calcu_start_date_2), | |
| 241 | + isUsed == false, | |
| 242 | + $scheduleDate: scheduleDate, | |
| 243 | + $self: self | |
| 244 | + ) | |
| 245 | + then | |
| 246 | + // 修正排班数据 | |
| 247 | +// log.info("准备修正 ruleId={} historyDate={}", $ruleId, $scheduleDate); | |
| 248 | + | |
| 249 | + // 路牌范围起始index使用历史数据 | |
| 250 | + $cdrp.setCalcu_index_lp(Integer.valueOf($self.getGidindex())); | |
| 251 | + // 人员范围起始index,需要判定,如果长度都是一样的,使用历史的,否则不更新,使用最新的 | |
| 252 | + String history_ecids = $self.getEcids(); | |
| 253 | + if ($ruleEcCount == history_ecids.split(",").length) { | |
| 254 | + $cdrp.setCalcu_index_ry(Integer.valueOf($self.getEcindex())); | |
| 255 | + } | |
| 256 | + | |
| 257 | + // 翻班格式利用路牌的历史index更新 | |
| 258 | + int fb_temp = Integer.valueOf($self.getGidindex()) % $cdrp.getFbweeks().size(); | |
| 259 | + $cdrp.setFbgs_index(fb_temp); | |
| 260 | + | |
| 261 | + $cdrp.setCalcu_start_date_1($scheduleDate); | |
| 262 | + update($cdrp); | |
| 263 | + | |
| 264 | + $srrr_wrap.setIsUsed(true); | |
| 265 | + update($srrr_wrap); | |
| 266 | + | |
| 267 | +end | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | +//------------------------- 第二阶段、计算规则准备数据2(第一组循环) ----------------------------// | |
| 272 | + | |
| 273 | +function void calcu_loop1_fb(Calcu_days_result_pre $cdrp, ScheduleRule_input $sri, Logger log) { | |
| 274 | + Integer $lpindex = $cdrp.getCalcu_index_lp(); | |
| 275 | + Integer $lprangesize = $sri.getGuideboardIds().size(); | |
| 276 | + Integer $ryindex = $cdrp.getCalcu_index_ry(); | |
| 277 | + Integer $ryrangesize = $sri.getEmployeeConfigIds().size(); | |
| 278 | + Integer $fbindex = $cdrp.getFbgs_index(); | |
| 279 | + Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 280 | + DateTime $csd1 = $cdrp.getCalcu_start_date_1(); | |
| 281 | + DateTime $ced1 = $cdrp.getCalcu_end_date_1(); | |
| 282 | + | |
| 283 | + String $ruleId = $cdrp.getRuleId(); | |
| 284 | + | |
| 285 | + $cdrp.setCalcu_index_lp(($lpindex + 1) % $lprangesize); | |
| 286 | + $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize); | |
| 287 | + | |
| 288 | + $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 289 | + $cdrp.setCalcu_start_date_1($csd1.plusDays(1)); | |
| 290 | + | |
| 291 | +// log.info("calcu_loop1_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 292 | +// $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd1, $ced1); | |
| 293 | + | |
| 294 | +} | |
| 295 | +function void calcu_loop1_not_fb(Calcu_days_result_pre $cdrp, ScheduleRule_input $sri, Logger log) { | |
| 296 | + DateTime $csd1 = $cdrp.getCalcu_start_date_1(); | |
| 297 | + DateTime $ced1 = $cdrp.getCalcu_end_date_1(); | |
| 298 | + Integer $fbindex = $cdrp.getFbgs_index(); | |
| 299 | + Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 300 | + | |
| 301 | + $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 302 | + $cdrp.setCalcu_start_date_1($csd1.plusDays(1)); | |
| 303 | + | |
| 304 | +// log.info("calcu_loop1_not_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 305 | +// $cdrp.getRuleId(), $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd1, $ced1); | |
| 306 | +} | |
| 307 | + | |
| 308 | + | |
| 309 | +rule "Calcu_loop1_fbtype_with_0_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是false,就跳过 | |
| 310 | + salience 900 | |
| 311 | + when | |
| 312 | + $cdrp: Calcu_days_result_pre( | |
| 313 | + calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 314 | + $ruleId: ruleId, | |
| 315 | + fbtype == "1", | |
| 316 | + $fbindex : fbgs_index | |
| 317 | + ) | |
| 318 | + $sri: ScheduleRule_input( | |
| 319 | + ruleId == $ruleId, | |
| 320 | + weekdays[$fbindex] == false | |
| 321 | + ) | |
| 322 | + then | |
| 323 | + calcu_loop1_not_fb($cdrp, $sri, log); | |
| 324 | + update($cdrp); | |
| 325 | +end | |
| 326 | + | |
| 327 | +rule "Calcu_loop1_fbtype_with_1_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里存在指定路牌,就翻 | |
| 328 | + salience 900 | |
| 329 | + when | |
| 330 | + $cdrp: Calcu_days_result_pre( | |
| 331 | + calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 332 | + $csd1: calcu_start_date_1, | |
| 333 | + $ruleId: ruleId, | |
| 334 | + fbtype == "1", | |
| 335 | + $lpindex: calcu_index_lp, | |
| 336 | + $fbindex : fbgs_index | |
| 337 | + ) | |
| 338 | + $sri: ScheduleRule_input( | |
| 339 | + ruleId == $ruleId, | |
| 340 | + $gids: guideboardIds, | |
| 341 | + weekdays[$fbindex] == true | |
| 342 | + ) | |
| 343 | + $liro: LpInfoResult_output( | |
| 344 | + dateTime.isEqual($csd1), | |
| 345 | + $gids[$lpindex] == lpId | |
| 346 | + ) | |
| 347 | + then | |
| 348 | + calcu_loop1_fb($cdrp, $sri, log); | |
| 349 | + update($cdrp); | |
| 350 | + | |
| 351 | +end | |
| 352 | + | |
| 353 | +rule "Calcu_loop1_fbtype_with_1_no_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里不存在指定路牌,就跳过 | |
| 354 | + salience 900 | |
| 355 | + when | |
| 356 | + $cdrp: Calcu_days_result_pre( | |
| 357 | + calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 358 | + $csd1: calcu_start_date_1, | |
| 359 | + $ruleId: ruleId, | |
| 360 | + fbtype == "1", | |
| 361 | + $fbindex : fbgs_index | |
| 362 | + ) | |
| 363 | + $sri: ScheduleRule_input( | |
| 364 | + ruleId == $ruleId, | |
| 365 | + weekdays[$fbindex] == true | |
| 366 | + ) | |
| 367 | + then | |
| 368 | + calcu_loop1_not_fb($cdrp, $sri, log); | |
| 369 | + update($cdrp); | |
| 370 | +end | |
| 371 | + | |
| 372 | + | |
| 373 | +rule "Calcu_loop1_timetabletype_with_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中存在,就翻 | |
| 374 | + salience 900 | |
| 375 | + when | |
| 376 | + $cdrp: Calcu_days_result_pre( | |
| 377 | + calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 378 | + $csd1: calcu_start_date_1, | |
| 379 | + $ruleId: ruleId, | |
| 380 | + fbtype == "0", | |
| 381 | + $lpindex: calcu_index_lp | |
| 382 | + ) | |
| 383 | + $sri: ScheduleRule_input( | |
| 384 | + ruleId == $ruleId, | |
| 385 | + $gids: guideboardIds | |
| 386 | + ) | |
| 387 | + $liro: LpInfoResult_output( | |
| 388 | + dateTime.isEqual($csd1), | |
| 389 | + $gids[$lpindex] == lpId | |
| 390 | + ) | |
| 391 | + then | |
| 392 | + calcu_loop1_fb($cdrp, $sri, log); | |
| 393 | + update($cdrp); | |
| 394 | +end | |
| 395 | + | |
| 396 | +rule "Calcu_loop1_timetabletype_with_no_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中不存在,就跳过 | |
| 397 | + salience 900 | |
| 398 | + when | |
| 399 | + $cdrp: Calcu_days_result_pre( | |
| 400 | + calcu_start_date_1.isBefore(calcu_end_date_1), | |
| 401 | + $csd1: calcu_start_date_1, | |
| 402 | + $ruleId: ruleId, | |
| 403 | + fbtype == "0" | |
| 404 | + ) | |
| 405 | + $sri: ScheduleRule_input( | |
| 406 | + ruleId == $ruleId | |
| 407 | + ) | |
| 408 | + then | |
| 409 | + calcu_loop1_not_fb($cdrp, $sri, log); | |
| 410 | + update($cdrp); | |
| 411 | +end | |
| 412 | + | |
| 413 | +//------------------------- 第三阶段、计算规则准备数据2(第二组循环) ----------------------------// | |
| 414 | + | |
| 415 | +function void calcu_loop2_fb( | |
| 416 | + SchedulePlan $sp, | |
| 417 | + Calcu_days_result_pre $cdrp, | |
| 418 | + ScheduleRule_input $sri, | |
| 419 | + LpInfoResult_output $liro, | |
| 420 | + ScheduleResults_output rs, | |
| 421 | + Logger log) { | |
| 422 | + String $ruleId = $cdrp.getRuleId(); | |
| 423 | + DateTime $csd2 = $cdrp.getCalcu_start_date_2(); | |
| 424 | + DateTime $ced2 = $cdrp.getCalcu_end_date_2(); | |
| 425 | + Integer $lpindex = $cdrp.getCalcu_index_lp(); | |
| 426 | + List $gids = $sri.getGuideboardIds(); | |
| 427 | + Integer $lprangesize = $sri.getGuideboardIds().size(); | |
| 428 | + Integer $ryindex = $cdrp.getCalcu_index_ry(); | |
| 429 | + List $eids = $sri.getEmployeeConfigIds(); | |
| 430 | + Integer $ryrangesize = $sri.getEmployeeConfigIds().size(); | |
| 431 | + Integer $fbindex = $cdrp.getFbgs_index(); | |
| 432 | + Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 433 | + String $cid = $sri.getCarConfigId(); | |
| 434 | + String $xlid = $sri.getXlId(); | |
| 435 | + | |
| 436 | + com.bsth.entity.schedule.rule.ScheduleRule1Flat $srf = $sri.getSelf(); | |
| 437 | + | |
| 438 | + String $ttinfoId = $liro.getTtInfoId(); | |
| 439 | + String $ttinfoName = $liro.getTtInfoName(); | |
| 440 | + | |
| 441 | + ScheduleResult_output ro = new ScheduleResult_output(); | |
| 442 | + ro.setRuleId($ruleId); | |
| 443 | + ro.setSd($csd2); | |
| 444 | + ro.setGuideboardId(String.valueOf($gids.get($lpindex))); | |
| 445 | + ro.setEmployeeConfigId(String.valueOf($eids.get($ryindex))); | |
| 446 | + ro.setCarConfigId($cid); | |
| 447 | + ro.setXlId($xlid); | |
| 448 | + | |
| 449 | + // 类型 | |
| 450 | + ro.setsType($sri.getsType()); | |
| 451 | + | |
| 452 | + rs.getResults().add(ro); | |
| 453 | + | |
| 454 | +// log.info("gogoogogogogo"); | |
| 455 | + | |
| 456 | + $cdrp.setCalcu_index_lp(($lpindex + 1) % $lprangesize); | |
| 457 | + $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize); | |
| 458 | + | |
| 459 | + $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 460 | + $cdrp.setCalcu_start_date_2($csd2.plusDays(1)); | |
| 461 | + | |
| 462 | + if ($sri.getsType() == ScheduleRule_Type.NORMAL) { | |
| 463 | + // 保存排班规则循环结果 --> SchedulePlanRuleResult | |
| 464 | + SchedulePlanRuleResult schedulePlanRuleResult = new SchedulePlanRuleResult($sp); | |
| 465 | +// schedulePlanRuleResult.setXlId(String.valueOf($srf.getXl().getId())); | |
| 466 | + schedulePlanRuleResult.setXlId($srf.getXl().getId()); | |
| 467 | + schedulePlanRuleResult.setXlName($srf.getXl().getName()); | |
| 468 | + schedulePlanRuleResult.setRuleId($ruleId); | |
| 469 | + schedulePlanRuleResult.setCcId($cid); | |
| 470 | + schedulePlanRuleResult.setCcZbh($srf.getCarConfigInfo().getCl().getInsideCode()); | |
| 471 | + schedulePlanRuleResult.setGids($srf.getLpIds()); // 参与md5计算 | |
| 472 | + schedulePlanRuleResult.setGnames($srf.getLpNames()); | |
| 473 | + schedulePlanRuleResult.setGidindex(String.valueOf($lpindex)); | |
| 474 | + schedulePlanRuleResult.setEcids($srf.getRyConfigIds()); | |
| 475 | + schedulePlanRuleResult.setEcdbbms($srf.getRyDbbms()); | |
| 476 | + schedulePlanRuleResult.setEcindex(String.valueOf($ryindex)); | |
| 477 | + schedulePlanRuleResult.setScheduleDate($csd2.toDate()); | |
| 478 | + schedulePlanRuleResult.setTtinfoId($ttinfoId); | |
| 479 | + schedulePlanRuleResult.setTtinfoName($ttinfoName); | |
| 480 | + schedulePlanRuleResult.setQyrq($sri.getQyrq().toDate()); // 参与md5计算 | |
| 481 | + schedulePlanRuleResult.setOrigingidindex(String.valueOf($sri.getSelf().getLpStart())); // 参与md5计算 | |
| 482 | + | |
| 483 | + rs.getSchedulePlanRuleResults().add(schedulePlanRuleResult); | |
| 484 | + } | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | +// log.info("calcu_loop2_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 489 | +// $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2); | |
| 490 | + | |
| 491 | +} | |
| 492 | + | |
| 493 | +function void calcu_loop2_not_fb( | |
| 494 | + Calcu_days_result_pre $cdrp, | |
| 495 | + ScheduleRule_input $sri, | |
| 496 | + ScheduleResults_output rs, | |
| 497 | + Logger log) { | |
| 498 | + | |
| 499 | + String $ruleId = $cdrp.getRuleId(); | |
| 500 | + DateTime $csd2 = $cdrp.getCalcu_start_date_2(); | |
| 501 | + DateTime $ced2 = $cdrp.getCalcu_end_date_2(); | |
| 502 | + Integer $lpindex = $cdrp.getCalcu_index_lp(); | |
| 503 | + List $gids = $sri.getGuideboardIds(); | |
| 504 | + Integer $ryindex = $cdrp.getCalcu_index_ry(); | |
| 505 | + List $eids = $sri.getEmployeeConfigIds(); | |
| 506 | + Integer $fbindex = $cdrp.getFbgs_index(); | |
| 507 | + Integer $fbfangesize = $sri.getWeekdays().size(); | |
| 508 | + String $cid = $sri.getCarConfigId(); | |
| 509 | + String $xlid = $sri.getXlId(); | |
| 510 | + | |
| 511 | + ScheduleResult_output ro = new ScheduleResult_output(); | |
| 512 | + ro.setRuleId($ruleId); | |
| 513 | + ro.setSd($csd2); | |
| 514 | +// ro.setGuideboardId(String.valueOf($gids.get($lpindex))); | |
| 515 | + ro.setGuideboardId("not_fb_lp"); // 不翻班,路牌id用假的,后面会过滤 | |
| 516 | + ro.setEmployeeConfigId(String.valueOf($eids.get($ryindex))); | |
| 517 | + ro.setCarConfigId($cid); | |
| 518 | + ro.setXlId($xlid); | |
| 519 | + | |
| 520 | + // 类型 | |
| 521 | + ro.setsType($sri.getsType()); | |
| 522 | + | |
| 523 | + rs.getResults().add(ro); | |
| 524 | + | |
| 525 | + $cdrp.setFbgs_index(($fbindex + 1) % $fbfangesize); | |
| 526 | + $cdrp.setCalcu_start_date_2($csd2.plusDays(1)); | |
| 527 | + | |
| 528 | +// log.info("calcu_loop2_not_fb ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", | |
| 529 | +// $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2); | |
| 530 | + | |
| 531 | +} | |
| 532 | + | |
| 533 | +rule "Calcu_loop2_fbtype_with_0_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是false,就跳过 | |
| 534 | + salience 800 | |
| 535 | + when | |
| 536 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 537 | + $cdrp: Calcu_days_result_pre( | |
| 538 | + calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 539 | + calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 540 | + $ruleId: ruleId, | |
| 541 | + fbtype == "1", | |
| 542 | + $fbindex : fbgs_index | |
| 543 | + ) | |
| 544 | + $sri: ScheduleRule_input( | |
| 545 | + ruleId == $ruleId, | |
| 546 | + weekdays[$fbindex] == false | |
| 547 | + ) | |
| 548 | + then | |
| 549 | + calcu_loop2_not_fb($cdrp, $sri, scheduleResult, log); | |
| 550 | + update($cdrp); | |
| 551 | + | |
| 552 | +end | |
| 553 | + | |
| 554 | +rule "Calcu_loop2_fbtype_with_1_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里存在指定路牌,就翻 | |
| 555 | + salience 800 | |
| 556 | + when | |
| 557 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 558 | + $cdrp: Calcu_days_result_pre( | |
| 559 | + calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 560 | + calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 561 | + $csd2: calcu_start_date_2, | |
| 562 | + $ruleId: ruleId, | |
| 563 | + fbtype == "1", | |
| 564 | + $lpindex: calcu_index_lp, | |
| 565 | + $fbindex : fbgs_index | |
| 566 | + ) | |
| 567 | + $sri: ScheduleRule_input( | |
| 568 | + ruleId == $ruleId, | |
| 569 | + $gids: guideboardIds, | |
| 570 | + weekdays[$fbindex] == true | |
| 571 | + ) | |
| 572 | + $liro: LpInfoResult_output( | |
| 573 | + dateTime.isEqual($csd2), | |
| 574 | + $gids[$lpindex] == lpId | |
| 575 | + ) | |
| 576 | + then | |
| 577 | + calcu_loop2_fb($sp, $cdrp, $sri, $liro, scheduleResult, log); | |
| 578 | + update($cdrp); | |
| 579 | +end | |
| 580 | + | |
| 581 | +rule "Calcu_loop2_fbtype_with_1_no_lp_" // 翻班模式为 type=1 使用翻班格式翻,当天翻班格式是true,并且当天时刻表里不存在指定路牌,就跳过 | |
| 582 | + salience 800 | |
| 583 | + when | |
| 584 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 585 | + $cdrp: Calcu_days_result_pre( | |
| 586 | + calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 587 | + calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 588 | + $ruleId: ruleId, | |
| 589 | + fbtype == "1", | |
| 590 | + $fbindex : fbgs_index | |
| 591 | + ) | |
| 592 | + $sri: ScheduleRule_input( | |
| 593 | + ruleId == $ruleId, | |
| 594 | + weekdays[$fbindex] == true | |
| 595 | + ) | |
| 596 | + then | |
| 597 | + calcu_loop2_not_fb($cdrp, $sri, scheduleResult, log); | |
| 598 | + update($cdrp); | |
| 599 | + | |
| 600 | +end | |
| 601 | + | |
| 602 | +rule "Calcu_loop2_timetabletype_with_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中存在,就翻 | |
| 603 | + salience 800 | |
| 604 | + when | |
| 605 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 606 | + $cdrp: Calcu_days_result_pre( | |
| 607 | + calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 608 | + calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 609 | + $csd2: calcu_start_date_2, | |
| 610 | + $ruleId: ruleId, | |
| 611 | + fbtype == "0", | |
| 612 | + $lpindex: calcu_index_lp, | |
| 613 | + $fbindex : fbgs_index | |
| 614 | + ) | |
| 615 | + $sri: ScheduleRule_input( | |
| 616 | + ruleId == $ruleId, | |
| 617 | + $gids: guideboardIds | |
| 618 | + ) | |
| 619 | + $liro: LpInfoResult_output( | |
| 620 | + dateTime.isEqual($csd2), | |
| 621 | + $gids[$lpindex] == lpId | |
| 622 | + ) | |
| 623 | + then | |
| 624 | + calcu_loop2_fb($sp, $cdrp, $sri, $liro, scheduleResult, log); | |
| 625 | + update($cdrp); | |
| 626 | + | |
| 627 | +end | |
| 628 | + | |
| 629 | +rule "Calcu_loop2_timetabletype_with_no_lp_" // 翻班模式为 type=0 使用时刻表格式翻,路牌在时刻表中不存在,就跳过 | |
| 630 | + salience 800 | |
| 631 | + when | |
| 632 | + ScheduleCalcuParam_input($sp: schedulePlan, $xlid: xlId) | |
| 633 | + $cdrp: Calcu_days_result_pre( | |
| 634 | + calcu_start_date_1.isEqual(calcu_end_date_1), | |
| 635 | + calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), | |
| 636 | + $ruleId: ruleId, | |
| 637 | + fbtype == "0" | |
| 638 | + ) | |
| 639 | + $sri: ScheduleRule_input( | |
| 640 | + ruleId == $ruleId | |
| 641 | + ) | |
| 642 | + then | |
| 643 | + calcu_loop2_not_fb($cdrp, $sri, scheduleResult, log); | |
| 644 | + update($cdrp); | |
| 645 | +end | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | ... | ... |
src/main/resources/rules/ttinfo.drl renamed to src/main/resources/rules/kBase1_core_ttinfo.drl
| 1 | -package com.bsth.service.schedule.ttinfo; | |
| 2 | - | |
| 3 | -import org.joda.time.*; | |
| 4 | -import java.util.*; | |
| 5 | - | |
| 6 | -import com.bsth.service.schedule.rules.ttinfo.TTInfoCalcuParam_input; | |
| 7 | -import com.bsth.service.schedule.rules.ttinfo.TTInfo_input; | |
| 8 | -import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output; | |
| 9 | -import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output; | |
| 10 | -import com.bsth.service.schedule.rules.ttinfo.LpInfoResult_output; | |
| 11 | -import com.bsth.service.schedule.rules.ttinfo.LpInfoResults_output; | |
| 12 | - | |
| 13 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; | |
| 14 | - | |
| 15 | -import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 16 | - | |
| 17 | -import com.bsth.entity.schedule.TTInfo; | |
| 18 | -import com.bsth.entity.schedule.TTInfoDetail; | |
| 19 | - | |
| 20 | -import org.slf4j.Logger | |
| 21 | - | |
| 22 | -// 全局日志 | |
| 23 | -global Logger log; | |
| 24 | -// repostory | |
| 25 | -global TTInfoDetailRepository tTInfoDetailRepository; | |
| 26 | -// return输出 | |
| 27 | -global TTInfoResults_output results | |
| 28 | -global LpInfoResults_output lpInfoResults_output | |
| 29 | - | |
| 30 | -function Long ttidParams(List ttinfolist) { | |
| 31 | - // 获取第一张时刻表id | |
| 32 | - TTInfo_input ttInfo_input = (TTInfo_input) ttinfolist.get(0); | |
| 33 | - return Long.parseLong(ttInfo_input.getTtInfoId()); | |
| 34 | -} | |
| 35 | - | |
| 36 | -/* | |
| 37 | - TODO:规则说明,以后待说明 | |
| 38 | -*/ | |
| 39 | - | |
| 40 | -//----------------- pre 预处理 param对象 -----------------------// | |
| 41 | - | |
| 42 | -rule "pre_calcu_TTInfoCalcuParam_input" | |
| 43 | - no-loop | |
| 44 | - salience 1000 | |
| 45 | - when | |
| 46 | - $ttp: TTInfoCalcuParam_input($xlId : xlId) | |
| 47 | - $minqyrq: DateTime() from accumulate ($sri: ScheduleRule_input(xlId == $xlId), minruleqyrq($sri)) | |
| 48 | - then | |
| 49 | - $ttp.setFromDate($minqyrq); | |
| 50 | - update($ttp); | |
| 51 | -end | |
| 52 | - | |
| 53 | -//----------------- 第一阶段、计算规则准备数据(天数)----------------// | |
| 54 | - | |
| 55 | -declare Calcu_days_result | |
| 56 | - calcu_day : Integer // 该计算第几天 | |
| 57 | - calcu_weekday : Integer // 星期几(1到7) | |
| 58 | - calcu_date : DateTime // 该计算的具体日期 | |
| 59 | - calcu_days : Integer // 总共需要计算的天数 | |
| 60 | - calcu_start_date : DateTime // 开始计算日期 | |
| 61 | - calcu_end_date : DateTime // 结束计算日期 | |
| 62 | - xlId : String // 线路Id | |
| 63 | -end | |
| 64 | - | |
| 65 | -rule "calcu_days" | |
| 66 | - when | |
| 67 | - TTInfoCalcuParam_input( | |
| 68 | - $fromDate : fromDate, | |
| 69 | - $toDate : toDate, | |
| 70 | - $xlId : xlId, | |
| 71 | - $fromDate.isBefore($toDate) || $fromDate.isEqual($toDate)) | |
| 72 | - then | |
| 73 | - // 构造Calcu_days_result对象,进行下一阶段计算 | |
| 74 | - Calcu_days_result cdr = new Calcu_days_result(); | |
| 75 | - Period p = new Period($fromDate, $toDate, PeriodType.days()); | |
| 76 | - | |
| 77 | - cdr.setCalcu_day(1); | |
| 78 | - cdr.setCalcu_date($fromDate); | |
| 79 | - cdr.setCalcu_days(p.getDays() + 1); | |
| 80 | - cdr.setCalcu_weekday($fromDate.getDayOfWeek()); | |
| 81 | - cdr.setCalcu_start_date($fromDate); | |
| 82 | - cdr.setCalcu_end_date(($toDate)); | |
| 83 | - cdr.setXlId($xlId); | |
| 84 | - | |
| 85 | -// log.info("总共需要计算的天数 calcu_days={} 之后的计算从第1天开始 ", p.getDays() + 1); | |
| 86 | - | |
| 87 | - insert(cdr); // 插入fact数据,进入下一个阶段 | |
| 88 | -end | |
| 89 | - | |
| 90 | -//----------------- 第二阶段、判定时刻表是否启用 ----------------// | |
| 91 | - | |
| 92 | -declare Calcu_ttinfo_enable_result | |
| 93 | - xlId : String // 线路id | |
| 94 | - ttInfo_input_list : ArrayList // 可用时刻表列表 | |
| 95 | - calcu_date : DateTime // 计算日期 | |
| 96 | -end | |
| 97 | - | |
| 98 | -rule "calcu_ttinfo_enable" | |
| 99 | - salience 900 | |
| 100 | - when | |
| 101 | - $calcu_days_result : Calcu_days_result($calcu_date : calcu_date, calcu_day <= calcu_days, $xlId : xlId) | |
| 102 | - $ttInfo_input_list : ArrayList(size >= 1) from collect (TTInfo_input(xlId == $xlId, isEnable == true)) | |
| 103 | - then | |
| 104 | - // 构造Calcu_ttinfo_enable_result对象,进行下一步计算 | |
| 105 | - Calcu_ttinfo_enable_result cter = new Calcu_ttinfo_enable_result(); | |
| 106 | - cter.setXlId($xlId); | |
| 107 | - cter.setTtInfo_input_list($ttInfo_input_list); | |
| 108 | - cter.setCalcu_date($calcu_date); | |
| 109 | - | |
| 110 | -// log.info("启用的时刻表:xlId={} 时刻表个数={}", $xlId, $ttInfo_input_list.size()); | |
| 111 | - | |
| 112 | - insert (cter); | |
| 113 | - | |
| 114 | -end | |
| 115 | - | |
| 116 | -//----------------- 第三阶段、时刻表的日期匹配 -------------------// | |
| 117 | - | |
| 118 | -rule "calcu_ttinfo_special_day" // 特殊日期匹配 | |
| 119 | - salience 800 | |
| 120 | - when | |
| 121 | - $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list) | |
| 122 | - $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day) | |
| 123 | - $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays contains $calcu_date) from $ttInfo_input_list) | |
| 124 | - $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd)) | |
| 125 | - then | |
| 126 | - // 更新Calcu_days_result对象 | |
| 127 | - int new_calcu_day = $calcu_day + 1; | |
| 128 | - $calcu_days_result.setCalcu_day(new_calcu_day); | |
| 129 | - DateTime new_calcu_date = $calcu_date.plusDays(1); | |
| 130 | - $calcu_days_result.setCalcu_date(new_calcu_date); | |
| 131 | - $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek()); | |
| 132 | - | |
| 133 | -// log.info("启用特殊日期时刻表:xlId={} 时刻表个数={} 特殊日期={}", $xlId, $ttinfolist.size(), $calcu_date); | |
| 134 | - | |
| 135 | - // $ttinfolist按时间倒排序,result输出 | |
| 136 | - Collections.sort($ttinfolist); | |
| 137 | - results.addXlTTInfos($xlId, $calcu_date, $ttinfolist); | |
| 138 | - | |
| 139 | - // lp输出 | |
| 140 | - for (int i = 0; i < $lpInfoResults.size(); i++) { | |
| 141 | - LpInfoResult_output lpInfoResult_output = (LpInfoResult_output) $lpInfoResults.get(i); | |
| 142 | - lpInfoResult_output.setDateTime($calcu_date); // 设定时间 | |
| 143 | - lpInfoResults_output.getLpInfoResult_outputs().add(lpInfoResult_output); | |
| 144 | - } | |
| 145 | - | |
| 146 | - update($calcu_days_result); | |
| 147 | -end | |
| 148 | - | |
| 149 | -rule "calcu_ttinfo_normal_day" // 平日匹配 | |
| 150 | - salience 700 | |
| 151 | - when | |
| 152 | - $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list) | |
| 153 | - $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday) | |
| 154 | - $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == true) from $ttInfo_input_list) | |
| 155 | - $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd)) | |
| 156 | - then | |
| 157 | - // 更新Calcu_days_result对象 | |
| 158 | - int new_calcu_day = $calcu_day + 1; | |
| 159 | - $calcu_days_result.setCalcu_day(new_calcu_day); | |
| 160 | - DateTime new_calcu_date = $calcu_date.plusDays(1); | |
| 161 | - $calcu_days_result.setCalcu_date(new_calcu_date); | |
| 162 | - $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek()); | |
| 163 | - | |
| 164 | -// log.info("启用常规日期时刻表:xlId={} 时刻表个数={} 常规日期={} 星期几={} 路牌size={}", $xlId, $ttinfolist.size(), $calcu_date, $calcu_weekday, $lpInfoResults.size()); | |
| 165 | - | |
| 166 | - // $ttinfolist按时间倒排序,result输出 | |
| 167 | - Collections.sort($ttinfolist); | |
| 168 | - results.addXlTTInfos($xlId, $calcu_date, $ttinfolist); | |
| 169 | - | |
| 170 | - // lp输出 | |
| 171 | - for (int i = 0; i < $lpInfoResults.size(); i++) { | |
| 172 | - LpInfoResult_output lpInfoResult_output = (LpInfoResult_output) $lpInfoResults.get(i); | |
| 173 | - lpInfoResult_output.setDateTime($calcu_date); // 设定时间 | |
| 174 | - lpInfoResults_output.getLpInfoResult_outputs().add(lpInfoResult_output); | |
| 175 | - } | |
| 176 | - | |
| 177 | - update($calcu_days_result); | |
| 178 | -end | |
| 179 | - | |
| 180 | -rule "calcu_ttinfo_other_day" // 都没有的情况下,匹配 | |
| 181 | - salience 500 | |
| 182 | - when | |
| 183 | - $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list) | |
| 184 | - $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday) | |
| 185 | - $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == false) from $ttInfo_input_list) | |
| 186 | - $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd)) | |
| 187 | - then | |
| 188 | - // 更新Calcu_days_result对象 | |
| 189 | - int new_calcu_day = $calcu_day + 1; | |
| 190 | - $calcu_days_result.setCalcu_day(new_calcu_day); | |
| 191 | - DateTime new_calcu_date = $calcu_date.plusDays(1); | |
| 192 | - $calcu_days_result.setCalcu_date(new_calcu_date); | |
| 193 | - $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek()); | |
| 194 | - | |
| 195 | -// log.info("启用默认日期时刻表:xlId={} 时刻表个数={} 常规日期={} 星期几={}", $xlId, $ttinfolist.size(), $calcu_date, $calcu_weekday); | |
| 196 | - | |
| 197 | - // $ttinfolist按时间倒排序,result输出 | |
| 198 | - Collections.sort($ttinfolist); | |
| 199 | - results.addXlTTInfos($xlId, $calcu_date, $ttinfolist); | |
| 200 | - | |
| 201 | - // lp输出 | |
| 202 | - for (int i = 0; i < $lpInfoResults.size(); i++) { | |
| 203 | - LpInfoResult_output lpInfoResult_output = (LpInfoResult_output) $lpInfoResults.get(i); | |
| 204 | - lpInfoResult_output.setDateTime($calcu_date); // 设定时间 | |
| 205 | - lpInfoResults_output.getLpInfoResult_outputs().add(lpInfoResult_output); | |
| 206 | - } | |
| 207 | - | |
| 208 | - update($calcu_days_result); | |
| 209 | - | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo; | |
| 2 | + | |
| 3 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.GidsCountFunction gidscount; | |
| 4 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.GidFbTimeFunction gidfbtime; | |
| 5 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.GidFbFcnoFunction gidfbfcno; | |
| 6 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResultsFunction lpinforesult; | |
| 7 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.MinRuleQyrqFunction minruleqyrq; | |
| 8 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidRepeatBcFunction vrb; | |
| 9 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidWholeRerunBcFunction vwrb; | |
| 10 | +import accumulate com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidWantLpFunction vwlp; | |
| 11 | + | |
| 12 | +import org.joda.time.*; | |
| 13 | +import java.util.*; | |
| 14 | + | |
| 15 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfoCalcuParam_input; | |
| 16 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfo_input; | |
| 17 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfoResult_output; | |
| 18 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.TTInfoResults_output; | |
| 19 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResult_output; | |
| 20 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResults_output; | |
| 21 | + | |
| 22 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_input; | |
| 23 | + | |
| 24 | +import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 25 | + | |
| 26 | +import com.bsth.entity.schedule.TTInfo; | |
| 27 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 28 | + | |
| 29 | +import org.slf4j.Logger | |
| 30 | + | |
| 31 | +// 全局日志 | |
| 32 | +global Logger log; | |
| 33 | +// repostory | |
| 34 | +global TTInfoDetailRepository tTInfoDetailRepository; | |
| 35 | +// return输出 | |
| 36 | +global TTInfoResults_output results | |
| 37 | +global LpInfoResults_output lpInfoResults_output | |
| 38 | + | |
| 39 | +function Long ttidParams(List ttinfolist) { | |
| 40 | + // 获取第一张时刻表id | |
| 41 | + TTInfo_input ttInfo_input = (TTInfo_input) ttinfolist.get(0); | |
| 42 | + return Long.parseLong(ttInfo_input.getTtInfoId()); | |
| 43 | +} | |
| 44 | + | |
| 45 | +/* | |
| 46 | + TODO:规则说明,以后待说明 | |
| 47 | +*/ | |
| 48 | + | |
| 49 | +//----------------- pre 预处理 param对象 -----------------------// | |
| 50 | + | |
| 51 | +rule "pre_calcu_TTInfoCalcuParam_input" | |
| 52 | + no-loop | |
| 53 | + salience 1000 | |
| 54 | + when | |
| 55 | + $ttp: TTInfoCalcuParam_input($xlId : xlId) | |
| 56 | + $minqyrq: DateTime() from accumulate ($sri: ScheduleRule_input(xlId == $xlId), minruleqyrq($sri)) | |
| 57 | + then | |
| 58 | + $ttp.setFromDate($minqyrq); | |
| 59 | + update($ttp); | |
| 60 | +end | |
| 61 | + | |
| 62 | +//----------------- 第一阶段、计算规则准备数据(天数)----------------// | |
| 63 | + | |
| 64 | +declare Calcu_days_result | |
| 65 | + calcu_day : Integer // 该计算第几天 | |
| 66 | + calcu_weekday : Integer // 星期几(1到7) | |
| 67 | + calcu_date : DateTime // 该计算的具体日期 | |
| 68 | + calcu_days : Integer // 总共需要计算的天数 | |
| 69 | + calcu_start_date : DateTime // 开始计算日期 | |
| 70 | + calcu_end_date : DateTime // 结束计算日期 | |
| 71 | + xlId : String // 线路Id | |
| 72 | +end | |
| 73 | + | |
| 74 | +rule "calcu_days" | |
| 75 | + when | |
| 76 | + TTInfoCalcuParam_input( | |
| 77 | + $fromDate : fromDate, | |
| 78 | + $toDate : toDate, | |
| 79 | + $xlId : xlId, | |
| 80 | + $fromDate.isBefore($toDate) || $fromDate.isEqual($toDate)) | |
| 81 | + then | |
| 82 | + // 构造Calcu_days_result对象,进行下一阶段计算 | |
| 83 | + Calcu_days_result cdr = new Calcu_days_result(); | |
| 84 | + Period p = new Period($fromDate, $toDate, PeriodType.days()); | |
| 85 | + | |
| 86 | + cdr.setCalcu_day(1); | |
| 87 | + cdr.setCalcu_date($fromDate); | |
| 88 | + cdr.setCalcu_days(p.getDays() + 1); | |
| 89 | + cdr.setCalcu_weekday($fromDate.getDayOfWeek()); | |
| 90 | + cdr.setCalcu_start_date($fromDate); | |
| 91 | + cdr.setCalcu_end_date(($toDate)); | |
| 92 | + cdr.setXlId($xlId); | |
| 93 | + | |
| 94 | +// log.info("总共需要计算的天数 calcu_days={} 之后的计算从第1天开始 ", p.getDays() + 1); | |
| 95 | + | |
| 96 | + insert(cdr); // 插入fact数据,进入下一个阶段 | |
| 97 | +end | |
| 98 | + | |
| 99 | +//----------------- 第二阶段、判定时刻表是否启用 ----------------// | |
| 100 | + | |
| 101 | +declare Calcu_ttinfo_enable_result | |
| 102 | + xlId : String // 线路id | |
| 103 | + ttInfo_input_list : ArrayList // 可用时刻表列表 | |
| 104 | + calcu_date : DateTime // 计算日期 | |
| 105 | +end | |
| 106 | + | |
| 107 | +rule "calcu_ttinfo_enable" | |
| 108 | + salience 900 | |
| 109 | + when | |
| 110 | + $calcu_days_result : Calcu_days_result($calcu_date : calcu_date, calcu_day <= calcu_days, $xlId : xlId) | |
| 111 | + $ttInfo_input_list : ArrayList(size >= 1) from collect (TTInfo_input(xlId == $xlId, isEnable == true)) | |
| 112 | + then | |
| 113 | + // 构造Calcu_ttinfo_enable_result对象,进行下一步计算 | |
| 114 | + Calcu_ttinfo_enable_result cter = new Calcu_ttinfo_enable_result(); | |
| 115 | + cter.setXlId($xlId); | |
| 116 | + cter.setTtInfo_input_list($ttInfo_input_list); | |
| 117 | + cter.setCalcu_date($calcu_date); | |
| 118 | + | |
| 119 | +// log.info("启用的时刻表:xlId={} 时刻表个数={}", $xlId, $ttInfo_input_list.size()); | |
| 120 | + | |
| 121 | + insert (cter); | |
| 122 | + | |
| 123 | +end | |
| 124 | + | |
| 125 | +//----------------- 第三阶段、时刻表的日期匹配 -------------------// | |
| 126 | + | |
| 127 | +rule "calcu_ttinfo_special_day" // 特殊日期匹配 | |
| 128 | + salience 800 | |
| 129 | + when | |
| 130 | + $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list) | |
| 131 | + $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day) | |
| 132 | + $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays contains $calcu_date) from $ttInfo_input_list) | |
| 133 | + $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd)) | |
| 134 | + then | |
| 135 | + // 更新Calcu_days_result对象 | |
| 136 | + int new_calcu_day = $calcu_day + 1; | |
| 137 | + $calcu_days_result.setCalcu_day(new_calcu_day); | |
| 138 | + DateTime new_calcu_date = $calcu_date.plusDays(1); | |
| 139 | + $calcu_days_result.setCalcu_date(new_calcu_date); | |
| 140 | + $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek()); | |
| 141 | + | |
| 142 | +// log.info("启用特殊日期时刻表:xlId={} 时刻表个数={} 特殊日期={}", $xlId, $ttinfolist.size(), $calcu_date); | |
| 143 | + | |
| 144 | + // $ttinfolist按时间倒排序,result输出 | |
| 145 | + Collections.sort($ttinfolist); | |
| 146 | + results.addXlTTInfos($xlId, $calcu_date, $ttinfolist); | |
| 147 | + | |
| 148 | + // lp输出 | |
| 149 | + for (int i = 0; i < $lpInfoResults.size(); i++) { | |
| 150 | + LpInfoResult_output lpInfoResult_output = (LpInfoResult_output) $lpInfoResults.get(i); | |
| 151 | + lpInfoResult_output.setDateTime($calcu_date); // 设定时间 | |
| 152 | + lpInfoResults_output.getLpInfoResult_outputs().add(lpInfoResult_output); | |
| 153 | + } | |
| 154 | + | |
| 155 | + update($calcu_days_result); | |
| 156 | +end | |
| 157 | + | |
| 158 | +rule "calcu_ttinfo_normal_day" // 平日匹配 | |
| 159 | + salience 700 | |
| 160 | + when | |
| 161 | + $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list) | |
| 162 | + $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday) | |
| 163 | + $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == true) from $ttInfo_input_list) | |
| 164 | + $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd)) | |
| 165 | + then | |
| 166 | + // 更新Calcu_days_result对象 | |
| 167 | + int new_calcu_day = $calcu_day + 1; | |
| 168 | + $calcu_days_result.setCalcu_day(new_calcu_day); | |
| 169 | + DateTime new_calcu_date = $calcu_date.plusDays(1); | |
| 170 | + $calcu_days_result.setCalcu_date(new_calcu_date); | |
| 171 | + $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek()); | |
| 172 | + | |
| 173 | +// log.info("启用常规日期时刻表:xlId={} 时刻表个数={} 常规日期={} 星期几={} 路牌size={}", $xlId, $ttinfolist.size(), $calcu_date, $calcu_weekday, $lpInfoResults.size()); | |
| 174 | + | |
| 175 | + // $ttinfolist按时间倒排序,result输出 | |
| 176 | + Collections.sort($ttinfolist); | |
| 177 | + results.addXlTTInfos($xlId, $calcu_date, $ttinfolist); | |
| 178 | + | |
| 179 | + // lp输出 | |
| 180 | + for (int i = 0; i < $lpInfoResults.size(); i++) { | |
| 181 | + LpInfoResult_output lpInfoResult_output = (LpInfoResult_output) $lpInfoResults.get(i); | |
| 182 | + lpInfoResult_output.setDateTime($calcu_date); // 设定时间 | |
| 183 | + lpInfoResults_output.getLpInfoResult_outputs().add(lpInfoResult_output); | |
| 184 | + } | |
| 185 | + | |
| 186 | + update($calcu_days_result); | |
| 187 | +end | |
| 188 | + | |
| 189 | +rule "calcu_ttinfo_other_day" // 都没有的情况下,匹配 | |
| 190 | + salience 500 | |
| 191 | + when | |
| 192 | + $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list) | |
| 193 | + $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday) | |
| 194 | + $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == false) from $ttInfo_input_list) | |
| 195 | + $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd)) | |
| 196 | + then | |
| 197 | + // 更新Calcu_days_result对象 | |
| 198 | + int new_calcu_day = $calcu_day + 1; | |
| 199 | + $calcu_days_result.setCalcu_day(new_calcu_day); | |
| 200 | + DateTime new_calcu_date = $calcu_date.plusDays(1); | |
| 201 | + $calcu_days_result.setCalcu_date(new_calcu_date); | |
| 202 | + $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek()); | |
| 203 | + | |
| 204 | +// log.info("启用默认日期时刻表:xlId={} 时刻表个数={} 常规日期={} 星期几={}", $xlId, $ttinfolist.size(), $calcu_date, $calcu_weekday); | |
| 205 | + | |
| 206 | + // $ttinfolist按时间倒排序,result输出 | |
| 207 | + Collections.sort($ttinfolist); | |
| 208 | + results.addXlTTInfos($xlId, $calcu_date, $ttinfolist); | |
| 209 | + | |
| 210 | + // lp输出 | |
| 211 | + for (int i = 0; i < $lpInfoResults.size(); i++) { | |
| 212 | + LpInfoResult_output lpInfoResult_output = (LpInfoResult_output) $lpInfoResults.get(i); | |
| 213 | + lpInfoResult_output.setDateTime($calcu_date); // 设定时间 | |
| 214 | + lpInfoResults_output.getLpInfoResult_outputs().add(lpInfoResult_output); | |
| 215 | + } | |
| 216 | + | |
| 217 | + update($calcu_days_result); | |
| 218 | + | |
| 210 | 219 | end |
| 211 | 220 | \ No newline at end of file | ... | ... |
src/main/resources/rules/validplan.drl renamed to src/main/resources/rules/kBase1_core_validate.drl
| 1 | -package com.bsth.service.schedule.rules.validate; | |
| 2 | - | |
| 3 | -import com.bsth.entity.schedule.SchedulePlanInfo; | |
| 4 | -import com.bsth.service.schedule.rules.ttinfo.LpInfoResult_output; | |
| 5 | -import com.bsth.service.schedule.rules.validate.ValidateResource; | |
| 6 | - | |
| 7 | -import org.joda.time.*; | |
| 8 | -import java.util.*; | |
| 9 | - | |
| 10 | -import org.slf4j.Logger; | |
| 11 | - | |
| 12 | -// 全局日志类(一般使用调用此规则的service类) | |
| 13 | -global Logger log; | |
| 14 | - | |
| 15 | -// 输出 | |
| 16 | -global ValidateResults_output validResult; | |
| 17 | - | |
| 18 | -//------------------------- 第一阶段、构造验证源 ----------------------------// | |
| 19 | -rule "Calcu_validate_resource" | |
| 20 | - salience 2000 | |
| 21 | - when | |
| 22 | - $spi: SchedulePlanInfo($sd: scheduleDate) | |
| 23 | - $lpiList: ArrayList() from collect (LpInfoResult_output(dateTime.getMillis() == $sd.getTime())) | |
| 24 | - then | |
| 25 | - ValidateResource resource = new ValidateResource(); | |
| 26 | - resource.setSd($sd); | |
| 27 | - resource.setSpi($spi); | |
| 28 | - resource.setLpiList($lpiList); | |
| 29 | - | |
| 30 | - insert(resource); | |
| 31 | -end | |
| 32 | - | |
| 33 | -//------------------------- 第二阶段、构造循环体 ----------------------------// | |
| 34 | - | |
| 35 | -declare Loop_param | |
| 36 | - start_date: DateTime // 开始日期(这个要不停的更新迭代) | |
| 37 | - end_date: DateTime // 结束日期 | |
| 38 | - sdays: Integer // 总共循环的天数 | |
| 39 | -end | |
| 40 | - | |
| 41 | -rule "Calcu_Loop_param" | |
| 42 | - salience 1000 | |
| 43 | - when | |
| 44 | - ValidateParam( | |
| 45 | - $fd: fromDate, | |
| 46 | - $ed: toDate, | |
| 47 | - $days: days | |
| 48 | - ) | |
| 49 | - then | |
| 50 | - Loop_param p = new Loop_param(); | |
| 51 | - p.setStart_date($fd); | |
| 52 | - p.setEnd_date($ed); | |
| 53 | - p.setSdays($days); | |
| 54 | - | |
| 55 | - insert(p); | |
| 56 | -end | |
| 57 | - | |
| 58 | -//------------------------- 第三阶段、验证计算 ----------------------------// | |
| 59 | - | |
| 60 | - | |
| 61 | -rule "Valid_repeat_bc" // 验证是否存在重复班次,未套跑班次,未执行路牌 | |
| 62 | - salience 600 | |
| 63 | - when | |
| 64 | - $lp: Loop_param($sd: start_date, $ed: end_date) | |
| 65 | - eval($sd.isBefore($ed) || $sd.isEqual($ed)) | |
| 66 | - $vrList: ArrayList() from collect (ValidateResource(sd.getTime() == $sd.getMillis())) | |
| 67 | - $infos: ArrayList() from accumulate ($vr: ValidateResource() from $vrList, vrb($vr.getSpi())) | |
| 68 | - $infos2: ArrayList() from accumulate ($vr: ValidateResource() from $vrList, vwrb($vr.getSpi())) | |
| 69 | - $infos3: ArrayList() from accumulate ($vr: ValidateResource() from $vrList, vwlp($vr)) | |
| 70 | - then | |
| 71 | - // TODO: | |
| 72 | -// log.info("日期={},班次重复错误数={}", $sd, $infos.size()); | |
| 73 | - | |
| 74 | -// log.info("班次数={}", $vrList.size()); | |
| 75 | - | |
| 76 | - validResult.getInfos().addAll($infos); | |
| 77 | - validResult.getInfos().addAll($infos2); | |
| 78 | - validResult.getInfos().addAll($infos3); | |
| 79 | - | |
| 80 | - // 迭代 | |
| 81 | - $lp.setStart_date($sd.plusDays(1)); | |
| 82 | - update($lp); | |
| 83 | - | |
| 84 | -end | |
| 85 | - | |
| 86 | -// | |
| 87 | -//declare LpInfo_wrap | |
| 88 | -// sd: DateTime // 具体日期 | |
| 89 | -// lpId: Long // 路牌Id | |
| 90 | -// isPlan: Boolean = false // 是否排班 | |
| 91 | -//end | |
| 92 | -// | |
| 93 | -//rule "Calcu_LpInfo_wrap" | |
| 94 | -// salience 500 | |
| 95 | -// when | |
| 96 | -// $lp: LpInfoResult_output() | |
| 97 | -// then | |
| 98 | -// LpInfo_wrap ll = new LpInfo_wrap(); | |
| 99 | -// ll.setSd($lp.getDateTime()); | |
| 100 | -// ll.setLpId(Long.parseLong($lp.getLpId())); | |
| 101 | -// | |
| 102 | -// insert(ll); | |
| 103 | -//end | |
| 104 | -// | |
| 105 | -//rule "Valid_Lp_plan" // 查看路牌是否被排班 | |
| 106 | -// salience 400 | |
| 107 | -// no-loop | |
| 108 | -// when | |
| 109 | -// $sp: SchedulePlanInfo($lp: lp) | |
| 110 | -// $ll: LpInfo_wrap(lpId == $lp) | |
| 111 | -// then | |
| 112 | -// $ll.setIsPlan(true); | |
| 113 | -// update($ll); | |
| 114 | -//end | |
| 115 | -// | |
| 116 | -//// TODO: | |
| 117 | - | |
| 118 | - | |
| 119 | - | |
| 120 | - | |
| 121 | - | |
| 122 | - | |
| 123 | - | |
| 124 | - | |
| 125 | - | |
| 126 | - | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase1.core.validate; | |
| 2 | + | |
| 3 | +import com.bsth.entity.schedule.SchedulePlanInfo; | |
| 4 | +import com.bsth.service.schedule.impl.plan.kBase1.core.ttinfo.LpInfoResult_output; | |
| 5 | +import com.bsth.service.schedule.impl.plan.kBase1.core.validate.ValidateResource; | |
| 6 | + | |
| 7 | +import org.joda.time.*; | |
| 8 | +import java.util.*; | |
| 9 | + | |
| 10 | +import org.slf4j.Logger; | |
| 11 | + | |
| 12 | +// 全局日志类(一般使用调用此规则的service类) | |
| 13 | +global Logger log; | |
| 14 | + | |
| 15 | +// 输出 | |
| 16 | +global ValidateResults_output validResult; | |
| 17 | + | |
| 18 | +//------------------------- 第一阶段、构造验证源 ----------------------------// | |
| 19 | +rule "Calcu_validate_resource" | |
| 20 | + salience 2000 | |
| 21 | + when | |
| 22 | + $spi: SchedulePlanInfo($sd: scheduleDate) | |
| 23 | + $lpiList: ArrayList() from collect (LpInfoResult_output(dateTime.getMillis() == $sd.getTime())) | |
| 24 | + then | |
| 25 | + ValidateResource resource = new ValidateResource(); | |
| 26 | + resource.setSd($sd); | |
| 27 | + resource.setSpi($spi); | |
| 28 | + resource.setLpiList($lpiList); | |
| 29 | + | |
| 30 | + insert(resource); | |
| 31 | +end | |
| 32 | + | |
| 33 | +//------------------------- 第二阶段、构造循环体 ----------------------------// | |
| 34 | + | |
| 35 | +declare Loop_param | |
| 36 | + start_date: DateTime // 开始日期(这个要不停的更新迭代) | |
| 37 | + end_date: DateTime // 结束日期 | |
| 38 | + sdays: Integer // 总共循环的天数 | |
| 39 | +end | |
| 40 | + | |
| 41 | +rule "Calcu_Loop_param" | |
| 42 | + salience 1000 | |
| 43 | + when | |
| 44 | + ValidateParam( | |
| 45 | + $fd: fromDate, | |
| 46 | + $ed: toDate, | |
| 47 | + $days: days | |
| 48 | + ) | |
| 49 | + then | |
| 50 | + Loop_param p = new Loop_param(); | |
| 51 | + p.setStart_date($fd); | |
| 52 | + p.setEnd_date($ed); | |
| 53 | + p.setSdays($days); | |
| 54 | + | |
| 55 | + insert(p); | |
| 56 | +end | |
| 57 | + | |
| 58 | +//------------------------- 第三阶段、验证计算 ----------------------------// | |
| 59 | + | |
| 60 | + | |
| 61 | +rule "Valid_repeat_bc" // 验证是否存在重复班次,未套跑班次,未执行路牌 | |
| 62 | + salience 600 | |
| 63 | + when | |
| 64 | + $lp: Loop_param($sd: start_date, $ed: end_date) | |
| 65 | + eval($sd.isBefore($ed) || $sd.isEqual($ed)) | |
| 66 | + $vrList: ArrayList() from collect (ValidateResource(sd.getTime() == $sd.getMillis())) | |
| 67 | + $infos: ArrayList() from accumulate ($vr: ValidateResource() from $vrList, vrb($vr.getSpi())) | |
| 68 | + $infos2: ArrayList() from accumulate ($vr: ValidateResource() from $vrList, vwrb($vr.getSpi())) | |
| 69 | + $infos3: ArrayList() from accumulate ($vr: ValidateResource() from $vrList, vwlp($vr)) | |
| 70 | + then | |
| 71 | + // TODO: | |
| 72 | +// log.info("日期={},班次重复错误数={}", $sd, $infos.size()); | |
| 73 | + | |
| 74 | +// log.info("班次数={}", $vrList.size()); | |
| 75 | + | |
| 76 | + validResult.getInfos().addAll($infos); | |
| 77 | + validResult.getInfos().addAll($infos2); | |
| 78 | + validResult.getInfos().addAll($infos3); | |
| 79 | + | |
| 80 | + // 迭代 | |
| 81 | + $lp.setStart_date($sd.plusDays(1)); | |
| 82 | + update($lp); | |
| 83 | + | |
| 84 | +end | |
| 85 | + | |
| 86 | +// | |
| 87 | +//declare LpInfo_wrap | |
| 88 | +// sd: DateTime // 具体日期 | |
| 89 | +// lpId: Long // 路牌Id | |
| 90 | +// isPlan: Boolean = false // 是否排班 | |
| 91 | +//end | |
| 92 | +// | |
| 93 | +//rule "Calcu_LpInfo_wrap" | |
| 94 | +// salience 500 | |
| 95 | +// when | |
| 96 | +// $lp: LpInfoResult_output() | |
| 97 | +// then | |
| 98 | +// LpInfo_wrap ll = new LpInfo_wrap(); | |
| 99 | +// ll.setSd($lp.getDateTime()); | |
| 100 | +// ll.setLpId(Long.parseLong($lp.getLpId())); | |
| 101 | +// | |
| 102 | +// insert(ll); | |
| 103 | +//end | |
| 104 | +// | |
| 105 | +//rule "Valid_Lp_plan" // 查看路牌是否被排班 | |
| 106 | +// salience 400 | |
| 107 | +// no-loop | |
| 108 | +// when | |
| 109 | +// $sp: SchedulePlanInfo($lp: lp) | |
| 110 | +// $ll: LpInfo_wrap(lpId == $lp) | |
| 111 | +// then | |
| 112 | +// $ll.setIsPlan(true); | |
| 113 | +// update($ll); | |
| 114 | +//end | |
| 115 | +// | |
| 116 | +//// TODO: | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | ... | ... |
src/main/resources/rules/ruleWrap.drl renamed to src/main/resources/rules/kBase2_wrap_rule.drl
| 1 | -package com.bsth.service.schedule.rulewrap; | |
| 2 | - | |
| 3 | -import org.joda.time.*; | |
| 4 | -import java.util.*; | |
| 5 | -import org.slf4j.Logger; | |
| 6 | - | |
| 7 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input; | |
| 8 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; | |
| 9 | -import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type; | |
| 10 | - | |
| 11 | -import com.bsth.repository.schedule.RerunRuleRepository; | |
| 12 | -import com.bsth.repository.schedule.ScheduleRule1FlatRepository; | |
| 13 | - | |
| 14 | -import com.bsth.service.schedule.rules.rerun.RerunRule_input; | |
| 15 | -import com.bsth.service.schedule.rules.ScheduleRuleService; | |
| 16 | - | |
| 17 | -import com.bsth.entity.Line; | |
| 18 | -import com.bsth.entity.schedule.CarConfigInfo | |
| 19 | -import com.bsth.entity.schedule.EmployeeConfigInfo | |
| 20 | -import javax.print.attribute.standard.DateTimeAtCompleted; | |
| 21 | - | |
| 22 | -// 全局日志类(一般使用调用此规则的service类) | |
| 23 | -global Logger log; | |
| 24 | - | |
| 25 | -global ScheduleRule1FlatRepository srf; | |
| 26 | -global RerunRuleRepository rrr; | |
| 27 | -global ScheduleRuleService srservice; | |
| 28 | -global List sriList; | |
| 29 | - | |
| 30 | - | |
| 31 | -declare Sri_Wrap | |
| 32 | - xlId : String // 线路id | |
| 33 | - lpIds : List // 路牌id | |
| 34 | - srf : Object // ScheduleRule1Flat类型 | |
| 35 | - sri : ScheduleRule_input; // ScheduleRule_input输入 | |
| 36 | -end | |
| 37 | - | |
| 38 | -rule "rw1" | |
| 39 | - salience 1000 | |
| 40 | - when | |
| 41 | - ScheduleCalcuParam_input( | |
| 42 | - $fromDate : fromDate, | |
| 43 | - $toDate : toDate, | |
| 44 | - $xlId: xlId | |
| 45 | - ) | |
| 46 | - $srf : Object() from srf.findByXlId(Integer.parseInt($xlId)) | |
| 47 | - then | |
| 48 | - // 创建Sri_Wrap | |
| 49 | - Sri_Wrap sw = new Sri_Wrap(); | |
| 50 | - sw.setXlId($xlId); | |
| 51 | - sw.setSrf($srf); | |
| 52 | - ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()); | |
| 53 | - sw.setSri(sri); | |
| 54 | - sw.setLpIds(sri.getGuideboardIds()); | |
| 55 | - | |
| 56 | - insert(sw); | |
| 57 | - | |
| 58 | -end | |
| 59 | - | |
| 60 | -rule "rw2" | |
| 61 | - salience 800 | |
| 62 | - no-loop | |
| 63 | - when | |
| 64 | - ScheduleCalcuParam_input( | |
| 65 | - $fromDate : fromDate, | |
| 66 | - $toDate : toDate, | |
| 67 | - $xlId: xlId | |
| 68 | - ) | |
| 69 | - $reu : RerunRule_input($lpId : lp) from srservice.findRerunrule(Integer.parseInt($xlId)) | |
| 70 | - not Sri_Wrap(xlId == $xlId, lpIds contains $lpId) | |
| 71 | - then | |
| 72 | - // 套跑中有规则,主线路的路牌,主线路该路牌不存在,添加一个临时的,做处理 | |
| 73 | - Sri_Wrap sw = new Sri_Wrap(); | |
| 74 | - sw.setSrf(new com.bsth.entity.schedule.rule.ScheduleRule1Flat()); | |
| 75 | - // 线路 | |
| 76 | - Line xl = new Line(); | |
| 77 | - xl.setId(Integer.valueOf($xlId)); | |
| 78 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setXl(xl); | |
| 79 | - // id,使用当前日期作为原始值加上路牌id最为临时id值 | |
| 80 | - DateTime dt = new DateTime(new Date()); | |
| 81 | - DateTime dt2 = new DateTime(dt.year().get(), dt.monthOfYear().get(), dt.dayOfMonth().get(), 0, 0, 0); | |
| 82 | - long id = (dt2.toDate().getTime() + Long.parseLong($lpId)); | |
| 83 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setId(id); | |
| 84 | - // 启用日期 | |
| 85 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setQyrq($fromDate.toDate()); | |
| 86 | - // 车辆配置 | |
| 87 | - CarConfigInfo cci = new CarConfigInfo(); | |
| 88 | - cci.setId(new Date().getTime()); | |
| 89 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setCarConfigInfo(cci); | |
| 90 | - // 人员配置 | |
| 91 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyConfigIds("TEMP"); | |
| 92 | - // 人员搭班编码 | |
| 93 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyDbbms("TEMP"); | |
| 94 | - // 起始人员 | |
| 95 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyStart(1); | |
| 96 | - // 路牌id | |
| 97 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpIds($lpId); | |
| 98 | - // 起始路牌 | |
| 99 | - ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpStart(1); | |
| 100 | - | |
| 101 | - ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()); | |
| 102 | - sri.setsType(ScheduleRule_Type.RERUN); | |
| 103 | - sw.setSri(sri); | |
| 104 | - | |
| 105 | - sw.setXlId($xlId); | |
| 106 | - | |
| 107 | - List lpIds = new ArrayList(); | |
| 108 | - lpIds.add($lpId); | |
| 109 | - sw.setLpIds(lpIds); | |
| 110 | - | |
| 111 | - insert(sw); | |
| 112 | -end | |
| 113 | - | |
| 114 | -rule "rw3" | |
| 115 | - salience 600 | |
| 116 | - when | |
| 117 | - $sri_wrap : Sri_Wrap($sri : sri, $xlId: xlId, $lpIds : lpIds) | |
| 118 | - then | |
| 119 | - log.info("线路id={},type={},ruleId={},lpids={}", $xlId, $sri.getsType(), $sri.getRuleId(), $lpIds); | |
| 120 | - sriList.add($sri); | |
| 1 | +package com.bsth.service.schedule.impl.plan.kBase2.wrap.rule; | |
| 2 | + | |
| 3 | +import org.joda.time.*; | |
| 4 | +import java.util.*; | |
| 5 | +import org.slf4j.Logger; | |
| 6 | + | |
| 7 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleCalcuParam_input; | |
| 8 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_input; | |
| 9 | +import com.bsth.service.schedule.impl.plan.kBase1.core.shiftloop.ScheduleRule_Type; | |
| 10 | +import com.bsth.service.schedule.impl.plan.kBase1.core.rerun.RerunRule_input; | |
| 11 | + | |
| 12 | +import com.bsth.repository.schedule.RerunRuleRepository; | |
| 13 | +import com.bsth.repository.schedule.ScheduleRule1FlatRepository; | |
| 14 | + | |
| 15 | +import com.bsth.service.schedule.impl.plan.ScheduleRuleService; | |
| 16 | + | |
| 17 | +import com.bsth.entity.Line; | |
| 18 | +import com.bsth.entity.schedule.CarConfigInfo | |
| 19 | +import com.bsth.entity.schedule.EmployeeConfigInfo | |
| 20 | +import javax.print.attribute.standard.DateTimeAtCompleted; | |
| 21 | + | |
| 22 | +// 全局日志类(一般使用调用此规则的service类) | |
| 23 | +global Logger log; | |
| 24 | + | |
| 25 | +global ScheduleRule1FlatRepository srf; | |
| 26 | +global RerunRuleRepository rrr; | |
| 27 | +global ScheduleRuleService srservice; | |
| 28 | +global List sriList; | |
| 29 | + | |
| 30 | + | |
| 31 | +declare Sri_Wrap | |
| 32 | + xlId : String // 线路id | |
| 33 | + lpIds : List // 路牌id | |
| 34 | + srf : Object // ScheduleRule1Flat类型 | |
| 35 | + sri : ScheduleRule_input; // ScheduleRule_input输入 | |
| 36 | +end | |
| 37 | + | |
| 38 | +rule "rw1" | |
| 39 | + salience 1000 | |
| 40 | + when | |
| 41 | + ScheduleCalcuParam_input( | |
| 42 | + $fromDate : fromDate, | |
| 43 | + $toDate : toDate, | |
| 44 | + $xlId: xlId | |
| 45 | + ) | |
| 46 | + $srf : Object() from srf.findByXlId(Integer.parseInt($xlId)) | |
| 47 | + then | |
| 48 | + // 创建Sri_Wrap | |
| 49 | + Sri_Wrap sw = new Sri_Wrap(); | |
| 50 | + sw.setXlId($xlId); | |
| 51 | + sw.setSrf($srf); | |
| 52 | + ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()); | |
| 53 | + sw.setSri(sri); | |
| 54 | + sw.setLpIds(sri.getGuideboardIds()); | |
| 55 | + | |
| 56 | + insert(sw); | |
| 57 | + | |
| 58 | +end | |
| 59 | + | |
| 60 | +rule "rw2" | |
| 61 | + salience 800 | |
| 62 | + no-loop | |
| 63 | + when | |
| 64 | + ScheduleCalcuParam_input( | |
| 65 | + $fromDate : fromDate, | |
| 66 | + $toDate : toDate, | |
| 67 | + $xlId: xlId | |
| 68 | + ) | |
| 69 | + $reu : RerunRule_input($lpId : lp) from srservice.findRerunrule(Integer.parseInt($xlId)) | |
| 70 | + not Sri_Wrap(xlId == $xlId, lpIds contains $lpId) | |
| 71 | + then | |
| 72 | + // 套跑中有规则,主线路的路牌,主线路该路牌不存在,添加一个临时的,做处理 | |
| 73 | + Sri_Wrap sw = new Sri_Wrap(); | |
| 74 | + sw.setSrf(new com.bsth.entity.schedule.rule.ScheduleRule1Flat()); | |
| 75 | + // 线路 | |
| 76 | + Line xl = new Line(); | |
| 77 | + xl.setId(Integer.valueOf($xlId)); | |
| 78 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setXl(xl); | |
| 79 | + // id,使用当前日期作为原始值加上路牌id最为临时id值 | |
| 80 | + DateTime dt = new DateTime(new Date()); | |
| 81 | + DateTime dt2 = new DateTime(dt.year().get(), dt.monthOfYear().get(), dt.dayOfMonth().get(), 0, 0, 0); | |
| 82 | + long id = (dt2.toDate().getTime() + Long.parseLong($lpId)); | |
| 83 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setId(id); | |
| 84 | + // 启用日期 | |
| 85 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setQyrq($fromDate.toDate()); | |
| 86 | + // 车辆配置 | |
| 87 | + CarConfigInfo cci = new CarConfigInfo(); | |
| 88 | + cci.setId(new Date().getTime()); | |
| 89 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setCarConfigInfo(cci); | |
| 90 | + // 人员配置 | |
| 91 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyConfigIds("TEMP"); | |
| 92 | + // 人员搭班编码 | |
| 93 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyDbbms("TEMP"); | |
| 94 | + // 起始人员 | |
| 95 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyStart(1); | |
| 96 | + // 路牌id | |
| 97 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpIds($lpId); | |
| 98 | + // 起始路牌 | |
| 99 | + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpStart(1); | |
| 100 | + | |
| 101 | + ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()); | |
| 102 | + sri.setsType(ScheduleRule_Type.RERUN); | |
| 103 | + sw.setSri(sri); | |
| 104 | + | |
| 105 | + sw.setXlId($xlId); | |
| 106 | + | |
| 107 | + List lpIds = new ArrayList(); | |
| 108 | + lpIds.add($lpId); | |
| 109 | + sw.setLpIds(lpIds); | |
| 110 | + | |
| 111 | + insert(sw); | |
| 112 | +end | |
| 113 | + | |
| 114 | +rule "rw3" | |
| 115 | + salience 600 | |
| 116 | + when | |
| 117 | + $sri_wrap : Sri_Wrap($sri : sri, $xlId: xlId, $lpIds : lpIds) | |
| 118 | + then | |
| 119 | + log.info("线路id={},type={},ruleId={},lpids={}", $xlId, $sri.getsType(), $sri.getRuleId(), $lpIds); | |
| 120 | + sriList.add($sri); | |
| 121 | 121 | end |
| 122 | 122 | \ No newline at end of file | ... | ... |
src/main/resources/rules/kBase3_validate_rule.drl
0 → 100644
| 1 | +package com.bsth.service.schedule.impl.plan.kBase3.validate.rule; | |
| 2 | + | |
| 3 | +import accumulate com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ErrorInfoFunction srif; | |
| 4 | +import accumulate com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.ErrorBcCountFunction ecount; | |
| 5 | + | |
| 6 | +import org.joda.time.*; | |
| 7 | +import java.util.*; | |
| 8 | + | |
| 9 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.CalcuParam; | |
| 10 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult; | |
| 11 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult.ErrorInfo; | |
| 12 | +import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.WrapInput; | |
| 13 | + | |
| 14 | +import com.bsth.repository.schedule.ScheduleRule1FlatRepository | |
| 15 | +import com.bsth.repository.schedule.CarConfigInfoRepository; | |
| 16 | +import com.bsth.repository.schedule.GuideboardInfoRepository; | |
| 17 | +import com.bsth.repository.schedule.EmployeeConfigInfoRepository; | |
| 18 | + | |
| 19 | +import com.bsth.entity.schedule.rule.ScheduleRule1Flat; | |
| 20 | +import com.bsth.entity.schedule.CarConfigInfo; | |
| 21 | +import com.bsth.entity.schedule.GuideboardInfo; | |
| 22 | +import com.bsth.entity.schedule.EmployeeConfigInfo; | |
| 23 | + | |
| 24 | +import org.slf4j.Logger | |
| 25 | + | |
| 26 | +// 全局日志 | |
| 27 | +global Logger LOG; | |
| 28 | + | |
| 29 | +// repository查询 | |
| 30 | +global CarConfigInfoRepository ccRepo; | |
| 31 | +global GuideboardInfoRepository lpRepo; | |
| 32 | +global EmployeeConfigInfoRepository ecRepo; | |
| 33 | +global ScheduleRule1FlatRepository ruleRepo; | |
| 34 | + | |
| 35 | +// return输出 | |
| 36 | +global ValidateRuleResult result; | |
| 37 | + | |
| 38 | + | |
| 39 | +//------------------ 第一阶段、车辆信息,路牌信息,人员信息载入 -----------------// | |
| 40 | + | |
| 41 | +// 1、车辆信息载入 | |
| 42 | +declare CarConfig_Wraps | |
| 43 | + xlId: Integer // 线路Id | |
| 44 | + ccMap: Map // 车辆配置Map Map<车辆自编号, CarConfigInfo> | |
| 45 | +end | |
| 46 | + | |
| 47 | +rule "calcu_CarConfig_Wraps" | |
| 48 | + salience 800 | |
| 49 | + when | |
| 50 | + $param: CalcuParam($xlId: xlId) | |
| 51 | + then | |
| 52 | + List ccInfos = ccRepo.findByXlId($xlId); | |
| 53 | + | |
| 54 | + CarConfig_Wraps carConfig_wraps = new CarConfig_Wraps(); | |
| 55 | + carConfig_wraps.setXlId($xlId); | |
| 56 | + carConfig_wraps.setCcMap(new HashMap()); | |
| 57 | + | |
| 58 | + for (int i = 0; i < ccInfos.size(); i++) { | |
| 59 | + CarConfigInfo ccInfo = (CarConfigInfo) ccInfos.get(i); | |
| 60 | + if (!ccInfo.getIsCancel()) { | |
| 61 | + carConfig_wraps.getCcMap().put(ccInfo.getCl().getInsideCode(), ccInfo); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + insert(carConfig_wraps); | |
| 66 | + | |
| 67 | + LOG.info("第一阶段 --> 1、车辆信息载入 calcu_CarConfig_Wraps 有效配置车辆数={}", ccInfos.size()); | |
| 68 | +end | |
| 69 | + | |
| 70 | +// 2、路牌信息载入 | |
| 71 | +declare Lp_Wraps | |
| 72 | + xlId: Integer // 线路Id | |
| 73 | + lpMap: Map // 路牌Map Map<id, GuideboardInfo> | |
| 74 | +end | |
| 75 | + | |
| 76 | +rule "calcu_Lp_Wraps" | |
| 77 | + salience 800 | |
| 78 | + when | |
| 79 | + $param: CalcuParam($xlId: xlId) | |
| 80 | + then | |
| 81 | + List lpInfos = lpRepo.findByXlId($xlId); | |
| 82 | + Lp_Wraps lp_wraps = new Lp_Wraps(); | |
| 83 | + lp_wraps.setXlId($xlId); | |
| 84 | + lp_wraps.setLpMap(new HashMap()); | |
| 85 | + | |
| 86 | + for (int i = 0; i < lpInfos.size(); i++) { | |
| 87 | + GuideboardInfo lpInfo = (GuideboardInfo) lpInfos.get(i); | |
| 88 | + if (!lpInfo.getIsCancel()) { | |
| 89 | + lp_wraps.getLpMap().put(lpInfo.getId(), lpInfo); | |
| 90 | + } | |
| 91 | + } | |
| 92 | + | |
| 93 | + insert(lp_wraps); | |
| 94 | + | |
| 95 | + LOG.info("第一阶段 --> 2、路牌信息载入 calcu_Lp_Wraps 有效路牌数={}", lpInfos.size()); | |
| 96 | + | |
| 97 | +end | |
| 98 | + | |
| 99 | +// 3、人员信息载入 | |
| 100 | +declare EmployeeConfig_Wraps | |
| 101 | + xlId: Integer // 线路Id | |
| 102 | + ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo> | |
| 103 | +end | |
| 104 | + | |
| 105 | +rule "calcu_EmployeeConfig_Wraps" | |
| 106 | + salience 800 | |
| 107 | + when | |
| 108 | + $param: CalcuParam($xlId: xlId) | |
| 109 | + then | |
| 110 | + List ecInfos = ecRepo.findByXlId($xlId); | |
| 111 | + | |
| 112 | + EmployeeConfig_Wraps employeeConfig_wraps = new EmployeeConfig_Wraps(); | |
| 113 | + employeeConfig_wraps.setXlId($xlId); | |
| 114 | + employeeConfig_wraps.setEcMap(new HashMap()); | |
| 115 | + | |
| 116 | + for (int i = 0; i < ecInfos.size(); i++) { | |
| 117 | + EmployeeConfigInfo ecInfo = (EmployeeConfigInfo) ecInfos.get(i); | |
| 118 | + if (!ecInfo.getIsCancel()) { | |
| 119 | + employeeConfig_wraps.getEcMap().put(ecInfo.getId(), ecInfo); | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | + insert(employeeConfig_wraps); | |
| 124 | + | |
| 125 | + LOG.info("第一阶段 --> 3、人员信息载入 calcu_EmployeeConfig_Wraps 有效人员配置数={}", ecInfos.size()); | |
| 126 | +end | |
| 127 | + | |
| 128 | +//------------------ 第二阶段、规则载入,计算相关数量 -----------------// | |
| 129 | + | |
| 130 | +declare Rule_Wraps | |
| 131 | + xlId: Integer // 线路Id | |
| 132 | + qyrq: Date // 启用日期 | |
| 133 | + rule: ScheduleRule1Flat // ScheduleRule1Flat规则 | |
| 134 | +end | |
| 135 | + | |
| 136 | +rule "calcu_schedule_rule_wrap" | |
| 137 | + salience 700 | |
| 138 | + when | |
| 139 | + $param: CalcuParam($xlId: xlId) | |
| 140 | + $rule: ScheduleRule1Flat($qyrq: qyrq) from ruleRepo.findByXlId($xlId) | |
| 141 | + then | |
| 142 | + Rule_Wraps rw = new Rule_Wraps(); | |
| 143 | + rw.setXlId($xlId); | |
| 144 | + rw.setQyrq($qyrq); | |
| 145 | + rw.setRule($rule); | |
| 146 | + insert(rw); | |
| 147 | +end | |
| 148 | + | |
| 149 | +rule "calcu_all_rule_count" | |
| 150 | + salience 600 | |
| 151 | + when | |
| 152 | + $param: CalcuParam($xlId: xlId, $fd: fromDate, $td: toDate) | |
| 153 | + $allList: ArrayList() from collect(Rule_Wraps(xlId == $xlId)) | |
| 154 | + then | |
| 155 | + result.setXlId($xlId); | |
| 156 | + result.setCount($allList.size()); | |
| 157 | + | |
| 158 | + LOG.info("第二阶段 --> 规则总数={}", $allList.size()); | |
| 159 | +end | |
| 160 | + | |
| 161 | +rule "calcu_all_qy_rule_count" | |
| 162 | + salience 500 | |
| 163 | + when | |
| 164 | + $param: CalcuParam($xlId: xlId, $fd: fromDate, $td: toDate) | |
| 165 | + $qyList: ArrayList() from collect( | |
| 166 | + Rule_Wraps(xlId == $xlId, qyrq.getTime() <= $td.getMillis())) | |
| 167 | + then | |
| 168 | + result.setXlId($xlId); | |
| 169 | + result.setQyCount($qyList.size()); | |
| 170 | + | |
| 171 | + LOG.info("第二阶段 --> 启用规则数={}", $qyList.size()); | |
| 172 | + | |
| 173 | +end | |
| 174 | + | |
| 175 | +//------------------ 第三阶段、规则判定 -----------------// | |
| 176 | + | |
| 177 | +rule "calcu_Wrap_input" | |
| 178 | + salience 400 | |
| 179 | + when | |
| 180 | + $param: CalcuParam($xlId: xlId, $fd: fromDate, $td: toDate) | |
| 181 | + $qy_rule: Rule_Wraps(xlId == $xlId, qyrq.getTime() <= $td.getMillis()) | |
| 182 | + $cc: CarConfig_Wraps(xlId == $xlId) | |
| 183 | + $lp: Lp_Wraps(xlId == $xlId) | |
| 184 | + $ec: EmployeeConfig_Wraps(xlId == $xlId) | |
| 185 | + then | |
| 186 | + WrapInput wr = new WrapInput( | |
| 187 | + $qy_rule.getRule(), | |
| 188 | + $cc.getCcMap(), | |
| 189 | + $lp.getLpMap(), | |
| 190 | + $ec.getEcMap() | |
| 191 | + ); | |
| 192 | + insert(wr); | |
| 193 | +end | |
| 194 | + | |
| 195 | +rule "calcu_error_info" | |
| 196 | + salience 300 | |
| 197 | + when | |
| 198 | + $param: CalcuParam($xlId: xlId) | |
| 199 | + $errorMap: Map() from accumulate ($wr: WrapInput(xlId == $xlId), srif($wr)) | |
| 200 | + then | |
| 201 | + result.setQyErrorCount($errorMap.size()); | |
| 202 | + result.getErrorInfos().addAll($errorMap.values()); | |
| 203 | + | |
| 204 | + LOG.info("第三阶段 --> 规则总数={}, 启用规则数={}, 错误的启用规则数={}", | |
| 205 | + result.getCount(), result.getQyCount(), result.getQyErrorCount()); | |
| 206 | + | |
| 207 | +end | |
| 208 | + | |
| 209 | + | ... | ... |