Commit 749d6e3b91b6c9cf9917aa8a8ec469942cb496b9

Authored by 徐烜
1 parent de846074

Update

src/main/java/com/bsth/entity/schedule/SchedulePlanInfo.java
... ... @@ -3,6 +3,7 @@ package com.bsth.entity.schedule;
3 3 import com.bsth.entity.Line;
4 4 import com.bsth.service.schedule.rules.rerun.RerunRule_input;
5 5 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
  6 +import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type;
6 7 import org.apache.commons.lang3.StringUtils;
7 8  
8 9 import javax.persistence.*;
... ... @@ -267,7 +268,8 @@ public class SchedulePlanInfo extends BEntity {
267 268 List<EmployeeConfigInfo> employeeConfigInfoList,
268 269 SchedulePlan schedulePlan,
269 270 boolean isFirstBc, // 是否第一个班次
270   - boolean isLastBc // 是否最后一个班次
  271 + boolean isLastBc, // 是否最后一个班次
  272 + ScheduleRule_Type sType // 类型
271 273 ) {
272 274  
273 275 // TODO:关联的公司名称
... ... @@ -294,47 +296,51 @@ public class SchedulePlanInfo extends BEntity {
294 296 this.lpName = ttInfoDetail.getLp().getLpName();
295 297  
296 298 // 关联的车辆信息
297   - this.cl = carConfigInfo.getCl().getId(); // 车辆id
298   - this.clZbh = carConfigInfo.getCl().getInsideCode(); // 自编号/内部编号
  299 + if (sType == ScheduleRule_Type.NORMAL) {
  300 + this.cl = carConfigInfo.getCl().getId(); // 车辆id
  301 + this.clZbh = carConfigInfo.getCl().getInsideCode(); // 自编号/内部编号
  302 + }
299 303  
300 304 // TODO:报道时间,出场时间没有
301 305 // 关联的驾驶员
302   - EmployeeConfigInfo employeeConfigInfo = null;
303   - if (isFb) {
304   - if (employeeConfigInfoList.size() > 1) {
305   - employeeConfigInfo = employeeConfigInfoList.get(1);
  306 + if (sType == ScheduleRule_Type.NORMAL) {
  307 + EmployeeConfigInfo employeeConfigInfo = null;
  308 + if (isFb) {
  309 + if (employeeConfigInfoList.size() > 1) {
  310 + employeeConfigInfo = employeeConfigInfoList.get(1);
  311 + } else {
  312 + employeeConfigInfo = employeeConfigInfoList.get(0);
  313 + }
306 314 } else {
307 315 employeeConfigInfo = employeeConfigInfoList.get(0);
308 316 }
309   - } else {
310   - employeeConfigInfo = employeeConfigInfoList.get(0);
311   - }
312 317  
313   - this.j = employeeConfigInfo.getJsy().getId();
  318 + this.j = employeeConfigInfo.getJsy().getId();
314 319 // this.jGh = employeeConfigInfo.getJsy().getJobCode();
315   - if (StringUtils.isNotEmpty(employeeConfigInfo.getJsy().getJobCode())) {
316   - String[] jsy_temp = employeeConfigInfo.getJsy().getJobCode().split("-");
317   - if (jsy_temp.length > 1) {
318   - this.jGh = jsy_temp[1];
319   - } else {
320   - this.jGh = jsy_temp[0];
321   - }
322   - }
323   - this.jName = employeeConfigInfo.getJsy().getPersonnelName();
324   - // 关联的售票员
325   - if (employeeConfigInfo.getSpy() != null) {
326   - this.s = employeeConfigInfo.getSpy().getId();
327   -// this.sGh = employeeConfigInfo.getSpy().getJobCode();
328   - if (StringUtils.isNotEmpty(employeeConfigInfo.getSpy().getJobCode())) {
329   - String[] spy_temp = employeeConfigInfo.getSpy().getJobCode().split("-");
330   - if (spy_temp.length > 1) {
331   - this.sGh = spy_temp[1];
  320 + if (StringUtils.isNotEmpty(employeeConfigInfo.getJsy().getJobCode())) {
  321 + String[] jsy_temp = employeeConfigInfo.getJsy().getJobCode().split("-");
  322 + if (jsy_temp.length > 1) {
  323 + this.jGh = jsy_temp[1];
332 324 } else {
333   - this.sGh = spy_temp[0];
  325 + this.jGh = jsy_temp[0];
334 326 }
335 327 }
  328 + this.jName = employeeConfigInfo.getJsy().getPersonnelName();
  329 + // 关联的售票员
  330 + if (employeeConfigInfo.getSpy() != null) {
  331 + this.s = employeeConfigInfo.getSpy().getId();
  332 +// this.sGh = employeeConfigInfo.getSpy().getJobCode();
  333 + if (StringUtils.isNotEmpty(employeeConfigInfo.getSpy().getJobCode())) {
  334 + String[] spy_temp = employeeConfigInfo.getSpy().getJobCode().split("-");
  335 + if (spy_temp.length > 1) {
  336 + this.sGh = spy_temp[1];
  337 + } else {
  338 + this.sGh = spy_temp[0];
  339 + }
  340 + }
336 341  
337   - this.sName = employeeConfigInfo.getSpy().getPersonnelName();
  342 + this.sName = employeeConfigInfo.getSpy().getPersonnelName();
  343 + }
338 344 }
339 345  
340 346 // 时刻明细数据
... ... @@ -360,42 +366,44 @@ public class SchedulePlanInfo extends BEntity {
360 366 this.remark = ttInfoDetail.getRemark();
361 367  
362 368 // 使用车辆配置的停车场信息
363   - String pzType = carConfigInfo.getPzType(); // 配置类型
364   - if (pzType != null && !pzType.equals("BSY")) {
365   - if ("ZW".equals(pzType)) { // 只看早晚进出场
366   - if (isFirstBc) { // 第一个班次是出场
  369 + if (sType == ScheduleRule_Type.NORMAL) {
  370 + String pzType = carConfigInfo.getPzType(); // 配置类型
  371 + if (pzType != null && !pzType.equals("BSY")) {
  372 + if ("ZW".equals(pzType)) { // 只看早晚进出场
  373 + if (isFirstBc) { // 第一个班次是出场
367 374 // this.qdz = carConfigInfo.getTcc().getId(); // 起点站-停车场id
368   - this.qdzCode = carConfigInfo.getTcc().getParkCode(); // 起点站-停车场code
369   - this.qdzName = carConfigInfo.getTcc().getParkName(); // 起点站-停车场name
  375 + this.qdzCode = carConfigInfo.getTcc().getParkCode(); // 起点站-停车场code
  376 + this.qdzName = carConfigInfo.getTcc().getParkName(); // 起点站-停车场name
370 377  
371   - this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpOutLc() : carConfigInfo.getDownOutLc();
372   - this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpOutSj().intValue() : carConfigInfo.getDownOutSj().intValue();
  378 + this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpOutLc() : carConfigInfo.getDownOutLc();
  379 + this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpOutSj().intValue() : carConfigInfo.getDownOutSj().intValue();
373 380  
374   - } else if (isLastBc) { // 最后一个班次是进场
  381 + } else if (isLastBc) { // 最后一个班次是进场
375 382 // this.zdz = carConfigInfo.getTcc().getId(); // 终点站-停车场id
376   - this.zdzCode = carConfigInfo.getTcc().getParkCode(); // 终点站-停车场code
377   - this.zdzName = carConfigInfo.getTcc().getParkName(); // 终点站-停车场name
  383 + this.zdzCode = carConfigInfo.getTcc().getParkCode(); // 终点站-停车场code
  384 + this.zdzName = carConfigInfo.getTcc().getParkName(); // 终点站-停车场name
378 385  
379   - this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpInLc() : carConfigInfo.getDownInLc();
380   - this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpInSj().intValue() : carConfigInfo.getDownInSj().intValue();
381   - }
  386 + this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpInLc() : carConfigInfo.getDownInLc();
  387 + this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpInSj().intValue() : carConfigInfo.getDownInSj().intValue();
  388 + }
382 389  
383   - } else if ("FS".equals(pzType)) { // 所有进出场
384   - if ("out".equals(this.bcType)) { // 出场班次
  390 + } else if ("FS".equals(pzType)) { // 所有进出场
  391 + if ("out".equals(this.bcType)) { // 出场班次
385 392 // this.qdz = carConfigInfo.getTcc().getId(); // 起点站-停车场id
386   - this.qdzCode = carConfigInfo.getTcc().getParkCode(); // 起点站-停车场code
387   - this.qdzName = carConfigInfo.getTcc().getParkName(); // 起点站-停车场name
  393 + this.qdzCode = carConfigInfo.getTcc().getParkCode(); // 起点站-停车场code
  394 + this.qdzName = carConfigInfo.getTcc().getParkName(); // 起点站-停车场name
388 395  
389   - this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpOutLc() : carConfigInfo.getDownOutLc();
390   - this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpOutSj().intValue() : carConfigInfo.getDownOutSj().intValue();
  396 + this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpOutLc() : carConfigInfo.getDownOutLc();
  397 + this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpOutSj().intValue() : carConfigInfo.getDownOutSj().intValue();
391 398  
392   - } else if ("in".equals(this.bcType)) {
  399 + } else if ("in".equals(this.bcType)) {
393 400 // this.zdz = carConfigInfo.getTcc().getId(); // 终点站-停车场id
394   - this.zdzCode = carConfigInfo.getTcc().getParkCode(); // 终点站-停车场code
395   - this.zdzName = carConfigInfo.getTcc().getParkName(); // 终点站-停车场name
  401 + this.zdzCode = carConfigInfo.getTcc().getParkCode(); // 终点站-停车场code
  402 + this.zdzName = carConfigInfo.getTcc().getParkName(); // 终点站-停车场name
396 403  
397   - this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpInLc() : carConfigInfo.getDownInLc();
398   - this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpInSj().intValue() : carConfigInfo.getDownInSj().intValue();
  404 + this.jhlc = "0".equals(this.xlDir) ? carConfigInfo.getUpInLc() : carConfigInfo.getDownInLc();
  405 + this.bcsj = "0".equals(this.xlDir) ? carConfigInfo.getUpInSj().intValue() : carConfigInfo.getDownInSj().intValue();
  406 + }
399 407 }
400 408 }
401 409 }
... ...
src/main/java/com/bsth/repository/schedule/ScheduleRule1FlatRepository.java
... ... @@ -29,4 +29,6 @@ public interface ScheduleRule1FlatRepository extends BaseRepository&lt;ScheduleRule
29 29 ScheduleRule1Flat findOneExtend(Long aLong);
30 30  
31 31 List<ScheduleRule1Flat> findByXl(Line line);
  32 +
  33 + List<ScheduleRule1Flat> findByXlId(Integer id);
32 34 }
... ...
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
... ... @@ -30,6 +30,7 @@ import org.kie.api.runtime.KieSession;
30 30 import org.slf4j.Logger;
31 31 import org.slf4j.LoggerFactory;
32 32 import org.springframework.beans.factory.annotation.Autowired;
  33 +import org.springframework.beans.factory.annotation.Qualifier;
33 34 import org.springframework.stereotype.Service;
34 35 import org.springframework.transaction.annotation.Isolation;
35 36 import org.springframework.transaction.annotation.Propagation;
... ... @@ -43,7 +44,13 @@ import java.util.*;
43 44 @Service
44 45 public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> implements SchedulePlanService {
45 46 @Autowired
  47 + @Qualifier("kb1")
46 48 private KieBase kieBase;
  49 +
  50 + @Autowired
  51 + @Qualifier("kb2")
  52 + private KieBase kieBase2;
  53 +
47 54 @Autowired
48 55 private ScheduleRule1FlatRepository scheduleRule1FlatRepository;
49 56 @Autowired
... ... @@ -60,11 +67,49 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
60 67 private BusinessRepository businessRepository;
61 68 @Autowired
62 69 private ScheduleRuleService scheduleRuleService;
  70 + @Autowired
  71 + private RerunRuleRepository rerunRuleRepository;
63 72  
64 73 /** 日志记录器 */
65 74 private Logger logger = LoggerFactory.getLogger(SchedulePlanServiceImpl.class);
66 75  
67 76 /**
  77 + * 计算规则输入。
  78 + * @param schedulePlan
  79 + * @return
  80 + */
  81 + private List<ScheduleRule_input> calcuSrfList(SchedulePlan schedulePlan) {
  82 + // 1-1、构造drools规则输入数据,输出数据
  83 + // 全局计算参数
  84 + ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
  85 +
  86 + // 规则输出数据
  87 + List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>();
  88 +
  89 + // 1-2、构造drools session->载入数据->启动规则->计算->销毁session
  90 + // 创建session,内部配置的是stateful
  91 + KieSession session = kieBase2.newKieSession();
  92 + // 设置gloable对象,在drl中通过别名使用
  93 + session.setGlobal("sriList", scheduleRule_inputs);
  94 + session.setGlobal("log", logger); // 设置日志
  95 +
  96 + session.setGlobal("srf", scheduleRule1FlatRepository);
  97 + session.setGlobal("rrr", rerunRuleRepository);
  98 + session.setGlobal("srservice", scheduleRuleService);
  99 +
  100 + // 载入数据
  101 + session.insert(scheduleCalcuParam_input);
  102 +
  103 + // 执行rule
  104 + session.fireAllRules();
  105 +
  106 + // 执行完毕销毁,有日志的也要关闭
  107 + session.dispose();
  108 +
  109 + return scheduleRule_inputs;
  110 + }
  111 +
  112 + /**
68 113 * 循环规则输出。
69 114 * @param schedulePlan 排班计划对象
70 115 * @param lpInfoResults_output 时刻表每日路牌的情况
... ... @@ -76,13 +121,7 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
76 121 // 全局计算参数
77 122 ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
78 123 // 每个规则对应的输入参数
79   - List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>();
80   - List<ScheduleRule1Flat> scheduleRule1Flats = scheduleRule1FlatRepository.findByXl(schedulePlan.getXl());
81   -
82   - for (ScheduleRule1Flat scheduleRule1Flat: scheduleRule1Flats) {
83   - ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat);
84   - scheduleRule_inputs.add(scheduleRule_input);
85   - }
  124 + List<ScheduleRule_input> scheduleRule_inputs = calcuSrfList(schedulePlan);
86 125  
87 126 // 规则输出数据
88 127 ScheduleResults_output scheduleResults_output = new ScheduleResults_output();
... ...
src/main/java/com/bsth/service/schedule/rules/MyDroolsConfiguration.java
... ... @@ -28,7 +28,7 @@ public class MyDroolsConfiguration {
28 28 * 返回一个kiebase知识库,直接冲文件系统读入drl规则文件,
29 29 * TODO:以后需要从数据库读入规则文件,并重新创建kbase知识库。
30 30 */
31   - @Bean
  31 + @Bean(name = "kb1")
32 32 public KieBase myKieBase() {
33 33 // Drools 6开始引入kie统一接口(jboss的jbpm工作流也使用kie接口了),整个定义方式和5差别很大
34 34 // 这里使用全api方式创建知识库对象,不使用xml的方式,提供最大的灵活性
... ... @@ -100,4 +100,65 @@ public class MyDroolsConfiguration {
100 100  
101 101 return kieBase;
102 102 }
  103 +
  104 + /**
  105 + * 返回一个kiebase知识库,直接冲文件系统读入drl规则文件,
  106 + * TODO:以后需要从数据库读入规则文件,并重新创建kbase知识库。
  107 + */
  108 + @Bean(name = "kb2")
  109 + public KieBase myKieBase2() {
  110 + // Drools 6开始引入kie统一接口(jboss的jbpm工作流也使用kie接口了),整个定义方式和5差别很大
  111 + // 这里使用全api方式创建知识库对象,不使用xml的方式,提供最大的灵活性
  112 +
  113 + // 1、创建kieservices
  114 + KieServices kieServices = KieServices.Factory.get();
  115 + // 2、创建KieModuleModel,默认是由kmodule.xml的方式创建,这里使用api方式闯将
  116 + KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
  117 + // 2.1、创建KieBaseModel,类似kmodule.xml中的kbase标签
  118 + KieBaseModel kieBaseModel1 = kieModuleModel.newKieBaseModel("KBase2")
  119 + .setDefault(true)
  120 + .setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
  121 + .setEventProcessingMode(EventProcessingOption.STREAM);
  122 + // 2.2、创建与kbase关联的KieSessionModel,类似kmodule.xml中的kbase内的ksession标签
  123 + kieBaseModel1.newKieSessionModel("KSession1")
  124 + .setDefault(true)
  125 + .setType(KieSessionModel.KieSessionType.STATEFUL)
  126 + .setClockType(ClockTypeOption.get("realtime"));
  127 +
  128 + // 3、创建KieFileSystem,将模型xml,drl等写入,TODO:以后考虑从数据库中获取
  129 + KieFileSystem kfs = kieServices.newKieFileSystem();
  130 + // 3.1、写入KieBaseModel(内部包含了KieSessionModel的内容了,注意之前的KieSessionModel的创建方式)
  131 + kfs.writeKModuleXML(kieModuleModel.toXML());
  132 +
  133 + // 3.2、写入drl(写法超多,有点混乱)
  134 + // 这里使用文件的形式写入,TODO:以后考虑从数据库中读drl写入
  135 + // 注意kfs写的时候如果指定path,强制为src/main/resources/加上文件名,还有就是文件名不要重复否则会覆盖的
  136 +
  137 + kfs.write("src/main/resources/ruleWrap.drl", kieServices.getResources()
  138 + .newInputStreamResource(this.getClass().getResourceAsStream(
  139 + "/rules/ruleWrap.drl"), "UTF-8"));
  140 +
  141 + // TODO:还有其他drl....
  142 +
  143 + // 4、创建KieBuilder,使用KieFileSystem构建
  144 + KieBuilder kieBuilder = kieServices.newKieBuilder(kfs).buildAll();
  145 + Results results = kieBuilder.getResults();
  146 + if (results.hasMessages(Message.Level.ERROR))
  147 + throw new IllegalStateException("构建drools6错误:" + results.getMessages());
  148 +// if (results.hasMessages(Message.Level.ERROR)) {
  149 +// logger.info("构建drools6错误:" + results.getMessages());
  150 +// return null;
  151 +// }
  152 +
  153 + // 5、获取KieContainer
  154 + // TODO:ReleaseId用处很大,以后再议
  155 + ReleaseId releaseId = kieServices.getRepository().getDefaultReleaseId();
  156 + KieContainer kieContainer = kieServices.newKieContainer(releaseId);
  157 +
  158 + // 6、创建kbase
  159 + KieBaseConfiguration kieBaseConfiguration = kieServices.newKieBaseConfiguration();
  160 + KieBase kieBase = kieContainer.newKieBase("KBase2", kieBaseConfiguration);
  161 +
  162 + return kieBase;
  163 + }
103 164 }
... ...
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResult_output.java
... ... @@ -20,6 +20,9 @@ public class ScheduleResult_output {
20 20 /** 线路id */
21 21 private String xlId;
22 22  
  23 + /** 排班输入规则类型 */
  24 + private ScheduleRule_Type sType = ScheduleRule_Type.NORMAL;
  25 +
23 26 public DateTime getSd() {
24 27 return sd;
25 28 }
... ... @@ -67,4 +70,12 @@ public class ScheduleResult_output {
67 70 public void setXlId(String xlId) {
68 71 this.xlId = xlId;
69 72 }
  73 +
  74 + public ScheduleRule_Type getsType() {
  75 + return sType;
  76 + }
  77 +
  78 + public void setsType(ScheduleRule_Type sType) {
  79 + this.sType = sType;
  80 + }
70 81 }
... ...
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_Type.java 0 → 100644
  1 +package com.bsth.service.schedule.rules.shiftloop;
  2 +
  3 +/**
  4 + * 排班规则_输入_输出_类型。
  5 + */
  6 +public enum ScheduleRule_Type {
  7 + NORMAL, // 正常类型
  8 + // 套跑类型,使用套跑规则当作实际规则。
  9 + // 有的线路所有路牌都没有规则,或者只有部份规则,
  10 + // 则需要先补充temp规则,路牌id,人员配置id,车辆配置id都设为'NULL'
  11 + // 最后套跑规则重新排班覆盖temp规则
  12 + RERUN
  13 +}
... ...
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_input.java
... ... @@ -37,6 +37,9 @@ public class ScheduleRule_input {
37 37 /** 车辆翻版(周一到周日是否启用) */
38 38 private List<Boolean> weekdays = new ArrayList<>();
39 39  
  40 + /** 排班输入规则类型 */
  41 + private ScheduleRule_Type sType = ScheduleRule_Type.NORMAL;
  42 +
40 43 /** 关联的原始规则 */
41 44 private ScheduleRule1Flat self;
42 45  
... ... @@ -164,4 +167,11 @@ public class ScheduleRule_input {
164 167 this.self = self;
165 168 }
166 169  
  170 + public ScheduleRule_Type getsType() {
  171 + return sType;
  172 + }
  173 +
  174 + public void setsType(ScheduleRule_Type sType) {
  175 + this.sType = sType;
  176 + }
167 177 }
... ...
src/main/resources/rules/plan.drl
... ... @@ -27,7 +27,8 @@ import com.bsth.entity.schedule.SchedulePlanInfo;
27 27  
28 28 import org.slf4j.Logger
29 29 import org.joda.time.format.DateTimeFormat
30   -import org.apache.commons.lang3.StringUtils;
  30 +import org.apache.commons.lang3.StringUtils
  31 +import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type;
31 32  
32 33  
33 34 // 全局日志类(一般使用调用此规则的service类)
... ... @@ -385,9 +386,11 @@ rule &quot;Calcu_SchedulePlanInfo&quot;
385 386 // 路牌
386 387 String gid = sro.getGuideboardId();
387 388 // 车辆配置
388   - CarConfigInfo carConfigInfo = (CarConfigInfo) $ccs.getCcMap().get(sro.getCarConfigId());
  389 + CarConfigInfo carConfigInfo = sro.getsType() == ScheduleRule_Type.NORMAL ?
  390 + (CarConfigInfo) $ccs.getCcMap().get(sro.getCarConfigId()) : null;
389 391 // 人员配置
390   - List eclist = ecList(employeeConfigInfoRepository, sro.getEmployeeConfigId());
  392 + List eclist = sro.getsType() == ScheduleRule_Type.NORMAL ?
  393 + ecList(employeeConfigInfoRepository, sro.getEmployeeConfigId()) : null;
391 394  
392 395 // 时刻表id
393 396 String ttInfoId = ttInfoId_sd($lr.getTtInfoMapLoop(), sd);
... ... @@ -419,7 +422,8 @@ rule &quot;Calcu_SchedulePlanInfo&quot;
419 422 eclist,
420 423 $param.getSchedulePlan(),
421 424 wrap.getIsFirstBc(),
422   - wrap.getIsLastBc()
  425 + wrap.getIsLastBc(),
  426 + sro.getsType()
423 427 );
424 428  
425 429 // 获取公司,分公司信息
... ...
src/main/resources/rules/ruleWrap.drl 0 → 100644
  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 +
  21 +// 全局日志类(一般使用调用此规则的service类)
  22 +global Logger log;
  23 +
  24 +global ScheduleRule1FlatRepository srf;
  25 +global RerunRuleRepository rrr;
  26 +global ScheduleRuleService srservice;
  27 +global List sriList;
  28 +
  29 +
  30 +declare Sri_Wrap
  31 + xlId : String // 线路id
  32 + lpIds : List // 路牌id
  33 + srf : Object // ScheduleRule1Flat类型
  34 + sri : ScheduleRule_input; // ScheduleRule_input输入
  35 +end
  36 +
  37 +rule "rw1"
  38 + salience 1000
  39 + when
  40 + ScheduleCalcuParam_input(
  41 + $fromDate : fromDate,
  42 + $toDate : toDate,
  43 + $xlId: xlId
  44 + )
  45 + $srf : Object() from srf.findByXlId(Integer.parseInt($xlId))
  46 + then
  47 + // 创建Sri_Wrap
  48 + Sri_Wrap sw = new Sri_Wrap();
  49 + sw.setXlId($xlId);
  50 + sw.setSrf($srf);
  51 + ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf());
  52 + sw.setSri(sri);
  53 + sw.setLpIds(sri.getGuideboardIds());
  54 +
  55 + insert(sw);
  56 +
  57 +end
  58 +
  59 +rule "rw2"
  60 + salience 800
  61 + no-loop
  62 + when
  63 + ScheduleCalcuParam_input(
  64 + $fromDate : fromDate,
  65 + $toDate : toDate,
  66 + $xlId: xlId
  67 + )
  68 + $reu : RerunRule_input($lpId : lp) from srservice.findRerunrule(Integer.parseInt($xlId))
  69 + not Sri_Wrap(xlId == $xlId, lpIds contains $lpId)
  70 + then
  71 + // 套跑中有规则,主线路的路牌,主线路该路牌不存在,添加一个临时的,做处理
  72 + Sri_Wrap sw = new Sri_Wrap();
  73 + sw.setSrf(new com.bsth.entity.schedule.rule.ScheduleRule1Flat());
  74 + // 线路
  75 + Line xl = new Line();
  76 + xl.setId(Integer.valueOf($xlId));
  77 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setXl(xl);
  78 + // id
  79 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setId((new Date()).getTime());
  80 + // 启用日期
  81 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setQyrq($fromDate.toDate());
  82 + // 车辆配置
  83 + CarConfigInfo cci = new CarConfigInfo();
  84 + cci.setId(new Date().getTime());
  85 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setCarConfigInfo(cci);
  86 + // 人员配置
  87 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyConfigIds("TEMP");
  88 + // 人员搭班编码
  89 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyDbbms("TEMP");
  90 + // 起始人员
  91 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setRyStart(1);
  92 + // 路牌id
  93 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpIds($lpId);
  94 + // 起始路牌
  95 + ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setLpStart(1);
  96 +
  97 + ScheduleRule_input sri = new ScheduleRule_input((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf());
  98 + sri.setsType(ScheduleRule_Type.RERUN);
  99 + sw.setSri(sri);
  100 +
  101 + sw.setXlId($xlId);
  102 +
  103 + List lpIds = new ArrayList();
  104 + lpIds.add($lpId);
  105 + sw.setLpIds(lpIds);
  106 +
  107 + insert(sw);
  108 +end
  109 +
  110 +rule "rw3"
  111 + salience 600
  112 + when
  113 + $sri_wrap : Sri_Wrap($sri : sri, $xlId: xlId, $lpIds : lpIds)
  114 + then
  115 + log.info("线路id={},lpids={}", $xlId, $lpIds);
  116 + sriList.add($sri);
  117 +end
0 118 \ No newline at end of file
... ...
src/main/resources/rules/shiftloop_fb_2.drl
... ... @@ -9,6 +9,7 @@ import com.bsth.service.schedule.utils.Md5Util;
9 9  
10 10 import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
11 11 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
  12 +import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_Type;
12 13 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
13 14 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
14 15  
... ... @@ -342,33 +343,41 @@ rule &quot;Calcu_loop2_1_&quot; // 路牌在时刻表中存在,就翻
342 343 ro.setCarConfigId($cid);
343 344 ro.setXlId($xlid);
344 345  
  346 + // 类型
  347 + ro.setsType($sri.getsType());
  348 +
345 349 scheduleResult.getResults().add(ro);
346 350  
  351 +// log.info("gogoogogogogo");
  352 +
347 353 $cdrp.setCalcu_index_lp(($lpindex + 1) % $lprangesize);
348 354 $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize);
349 355 $cdrp.setCalcu_start_date_2($csd2.plusDays(1));
350 356  
351   - // 保存排班规则循环结果 --> SchedulePlanRuleResult
352   - SchedulePlanRuleResult schedulePlanRuleResult = new SchedulePlanRuleResult($sp);
  357 + if ($sri.getsType() == ScheduleRule_Type.NORMAL) {
  358 + // 保存排班规则循环结果 --> SchedulePlanRuleResult
  359 + SchedulePlanRuleResult schedulePlanRuleResult = new SchedulePlanRuleResult($sp);
353 360 // schedulePlanRuleResult.setXlId(String.valueOf($srf.getXl().getId()));
354   - schedulePlanRuleResult.setXlId($srf.getXl().getId());
355   - schedulePlanRuleResult.setXlName($srf.getXl().getName());
356   - schedulePlanRuleResult.setRuleId($ruleId);
357   - schedulePlanRuleResult.setCcId($cid);
358   - schedulePlanRuleResult.setCcZbh($srf.getCarConfigInfo().getCl().getInsideCode());
359   - schedulePlanRuleResult.setGids($srf.getLpIds()); // 参与md5计算
360   - schedulePlanRuleResult.setGnames($srf.getLpNames());
361   - schedulePlanRuleResult.setGidindex(String.valueOf($lpindex));
362   - schedulePlanRuleResult.setEcids($srf.getRyConfigIds());
363   - schedulePlanRuleResult.setEcdbbms($srf.getRyDbbms());
364   - schedulePlanRuleResult.setEcindex(String.valueOf($ryindex));
365   - schedulePlanRuleResult.setScheduleDate($csd2.toDate());
366   - schedulePlanRuleResult.setTtinfoId($ttinfoId);
367   - schedulePlanRuleResult.setTtinfoName($ttinfoName);
368   - schedulePlanRuleResult.setQyrq($sri.getQyrq().toDate()); // 参与md5计算
369   - schedulePlanRuleResult.setOrigingidindex(String.valueOf($sri.getSelf().getLpStart())); // 参与md5计算
370   -
371   - scheduleResult.getSchedulePlanRuleResults().add(schedulePlanRuleResult);
  361 + schedulePlanRuleResult.setXlId($srf.getXl().getId());
  362 + schedulePlanRuleResult.setXlName($srf.getXl().getName());
  363 + schedulePlanRuleResult.setRuleId($ruleId);
  364 + schedulePlanRuleResult.setCcId($cid);
  365 + schedulePlanRuleResult.setCcZbh($srf.getCarConfigInfo().getCl().getInsideCode());
  366 + schedulePlanRuleResult.setGids($srf.getLpIds()); // 参与md5计算
  367 + schedulePlanRuleResult.setGnames($srf.getLpNames());
  368 + schedulePlanRuleResult.setGidindex(String.valueOf($lpindex));
  369 + schedulePlanRuleResult.setEcids($srf.getRyConfigIds());
  370 + schedulePlanRuleResult.setEcdbbms($srf.getRyDbbms());
  371 + schedulePlanRuleResult.setEcindex(String.valueOf($ryindex));
  372 + schedulePlanRuleResult.setScheduleDate($csd2.toDate());
  373 + schedulePlanRuleResult.setTtinfoId($ttinfoId);
  374 + schedulePlanRuleResult.setTtinfoName($ttinfoName);
  375 + schedulePlanRuleResult.setQyrq($sri.getQyrq().toDate()); // 参与md5计算
  376 + schedulePlanRuleResult.setOrigingidindex(String.valueOf($sri.getSelf().getLpStart())); // 参与md5计算
  377 +
  378 + scheduleResult.getSchedulePlanRuleResults().add(schedulePlanRuleResult);
  379 + }
  380 +
372 381  
373 382  
374 383 // log.info("Calcu_loop2_1_ ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}",
... ... @@ -406,6 +415,9 @@ rule &quot;Calcu_loop2_2_&quot; // 路牌在时刻表中不存在,就不翻
406 415 ro.setCarConfigId($cid);
407 416 ro.setXlId($xlid);
408 417  
  418 + // 类型
  419 + ro.setsType($sri.getsType());
  420 +
409 421 scheduleResult.getResults().add(ro);
410 422  
411 423 $cdrp.setCalcu_start_date_2($csd2.plusDays(1));
... ...