Commit 4c3bc719be678b9eb59e98c485c45dd2f2e9b490

Authored by 徐烜
1 parent f16d9dec

Update

src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
... ... @@ -436,7 +436,7 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im
436 436 Line xl = lineRepository.findOne(schedulePlan.getXl().getId());
437 437 logger.info("<--- 排班master线路 id={}, name={}, 开始排班", xl.getId(), xl.getName());
438 438  
439   - // 2、确定主线路排班(无套跑规则
  439 + // 2、确定主线路排班(包含完全套跑路牌规则,所谓完全套跑路牌规则指整个路牌的班次都是套跑规则指定的
440 440 PlanResult planResult = schedulePlanWithOutRerun(schedulePlan);
441 441  
442 442 // 3、确定套跑规则
... ... @@ -445,6 +445,15 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
445 445 // TODO:3-1、验证排班结果
446 446 validPlanResult(planResult, schedulePlan);
447 447  
  448 + // TODO:3-2、去除完全套跑遗漏班次(以后放到规则中执行)
  449 + Iterator<SchedulePlanInfo> infoIterator = planResult.getSchedulePlanInfos().iterator();
  450 + while (infoIterator.hasNext()) {
  451 + SchedulePlanInfo schedulePlanInfo = infoIterator.next();
  452 + if (schedulePlanInfo.getCl() == null) {
  453 + infoIterator.remove();
  454 + }
  455 + }
  456 +
448 457 // 4、保存数据(jdbcTemplate 批量插入)
449 458 Date start4 = new Date();
450 459 scheduleRuleService.generateSchedulePlan(schedulePlan, planResult.getSchedulePlanInfos());
... ...
src/main/java/com/bsth/service/schedule/rules/validate/ValidWholeRerunBcFunction.java 0 → 100644
  1 +package com.bsth.service.schedule.rules.validate;
  2 +
  3 +import com.bsth.entity.schedule.SchedulePlanInfo;
  4 +import org.kie.api.runtime.rule.AccumulateFunction;
  5 +
  6 +import java.io.*;
  7 +import java.text.SimpleDateFormat;
  8 +import java.util.ArrayList;
  9 +import java.util.HashMap;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 验证完全套跑路牌班次正确性。
  15 + * 完全套跑路牌班次指此路牌下的所有班次由其他线路完成。
  16 + * 记录漏掉的班次,并给出警告信息。
  17 + */
  18 +public class ValidWholeRerunBcFunction implements AccumulateFunction {
  19 + @Override
  20 + public void writeExternal(ObjectOutput out) throws IOException {
  21 + }
  22 +
  23 + @Override
  24 + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  25 +
  26 + }
  27 +
  28 + protected static class RerunBcInfo implements Externalizable {
  29 + /** 错误描述 */
  30 + public List<ValidateResults_output.ValidInfo> validInfoList = new ArrayList<>();
  31 + /** 内部计数Map,key:{路牌Id}_{发车时间},value:个数 */
  32 + public Map<String, Integer> lpBcFcsjCount = new HashMap<>();
  33 +
  34 + public RerunBcInfo() {
  35 + }
  36 +
  37 + @Override
  38 + public void writeExternal(ObjectOutput out) throws IOException {
  39 + out.writeObject(validInfoList);
  40 + }
  41 +
  42 + @Override
  43 + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  44 + validInfoList = (List<ValidateResults_output.ValidInfo>) in.readObject();
  45 + }
  46 + }
  47 +
  48 + @Override
  49 + public Serializable createContext() {
  50 +// System.out.println("create");
  51 + return new RerunBcInfo();
  52 + }
  53 +
  54 + @Override
  55 + public void init(Serializable serializable) throws Exception {
  56 + // TODO:
  57 +// System.out.println("init");
  58 + }
  59 +
  60 + @Override
  61 + public void accumulate(Serializable context, Object o) {
  62 + RerunBcInfo rerunBcInfo = (RerunBcInfo) context;
  63 + SchedulePlanInfo schedulePlanInfo = (SchedulePlanInfo) o;
  64 +
  65 + String key = schedulePlanInfo.getLp() + "_" + schedulePlanInfo.getFcsj();
  66 + SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日");
  67 + String infoformat = "日期(%s),路牌(%s)完全套跑,班次(%s),在套跑规则中未指定";
  68 +
  69 + if (schedulePlanInfo.getCl() == null) {
  70 + rerunBcInfo.lpBcFcsjCount.put(key, 1);
  71 +
  72 + ValidateResults_output.ValidInfo validInfo = new ValidateResults_output.ValidInfo();
  73 + validInfo.setSd(schedulePlanInfo.getScheduleDate());
  74 + validInfo.setDesc(String.format(
  75 + infoformat,
  76 + sf.format(schedulePlanInfo.getScheduleDate()),
  77 + schedulePlanInfo.getLpName(),
  78 + schedulePlanInfo.getFcsj(),
  79 + 1));
  80 +
  81 + rerunBcInfo.validInfoList.add(validInfo);
  82 + }
  83 + }
  84 +
  85 + @Override
  86 + public boolean supportsReverse() {
  87 + return true;
  88 + }
  89 +
  90 + @Override
  91 + public void reverse(Serializable context, Object o) throws Exception {
  92 + RerunBcInfo rerunBcInfo = (RerunBcInfo) context;
  93 + SchedulePlanInfo schedulePlanInfo = (SchedulePlanInfo) o;
  94 +
  95 + String key = schedulePlanInfo.getLp() + "_" + schedulePlanInfo.getFcsj();
  96 + rerunBcInfo.lpBcFcsjCount.remove(key);
  97 +
  98 + if (!rerunBcInfo.validInfoList.isEmpty()) { // 全部清空
  99 + rerunBcInfo.validInfoList.clear();
  100 + }
  101 + }
  102 +
  103 + @Override
  104 + public Class<?> getResultType() {
  105 + return List.class;
  106 + }
  107 +
  108 + @Override
  109 + public Object getResult(Serializable context) throws Exception {
  110 + RerunBcInfo rerunBcInfo = (RerunBcInfo) context;
  111 + return rerunBcInfo.validInfoList;
  112 + }
  113 +}
... ...
src/main/resources/rules/functions.drl
... ... @@ -6,4 +6,5 @@ import accumulate com.bsth.service.schedule.rules.shiftloop.GidFbTimeFunction gi
6 6 import accumulate com.bsth.service.schedule.rules.shiftloop.GidFbFcnoFunction gidfbfcno;
7 7 import accumulate com.bsth.service.schedule.rules.ttinfo.LpInfoResultsFunction lpinforesult;
8 8 import accumulate com.bsth.service.schedule.rules.ttinfo.MinRuleQyrqFunction minruleqyrq;
9   -import accumulate com.bsth.service.schedule.rules.validate.ValidRepeatBcFunction vrb;
10 9 \ No newline at end of file
  10 +import accumulate com.bsth.service.schedule.rules.validate.ValidRepeatBcFunction vrb;
  11 +import accumulate com.bsth.service.schedule.rules.validate.ValidWholeRerunBcFunction vwrb;
... ...
src/main/resources/rules/ruleWrap.drl
... ... @@ -16,7 +16,8 @@ import com.bsth.service.schedule.rules.ScheduleRuleService;
16 16  
17 17 import com.bsth.entity.Line;
18 18 import com.bsth.entity.schedule.CarConfigInfo
19   -import com.bsth.entity.schedule.EmployeeConfigInfo;
  19 +import com.bsth.entity.schedule.EmployeeConfigInfo
  20 +import javax.print.attribute.standard.DateTimeAtCompleted;
20 21  
21 22 // 全局日志类(一般使用调用此规则的service类)
22 23 global Logger log;
... ... @@ -75,8 +76,10 @@ rule &quot;rw2&quot;
75 76 Line xl = new Line();
76 77 xl.setId(Integer.valueOf($xlId));
77 78 ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setXl(xl);
78   - // id
79   - long id = ((new Date()).getTime() + Long.parseLong($lpId));
  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));
80 83 ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setId(id);
81 84 // 启用日期
82 85 ((com.bsth.entity.schedule.rule.ScheduleRule1Flat) sw.getSrf()).setQyrq($fromDate.toDate());
... ... @@ -113,6 +116,6 @@ rule &quot;rw3&quot;
113 116 when
114 117 $sri_wrap : Sri_Wrap($sri : sri, $xlId: xlId, $lpIds : lpIds)
115 118 then
116   -// log.info("线路id={},type={},ruleId={},lpids={}", $xlId, $sri.getsType(), $sri.getRuleId(), $lpIds);
  119 + log.info("线路id={},type={},ruleId={},lpids={}", $xlId, $sri.getsType(), $sri.getRuleId(), $lpIds);
117 120 sriList.add($sri);
118 121 end
119 122 \ No newline at end of file
... ...
src/main/resources/rules/validplan.drl
... ... @@ -49,11 +49,13 @@ rule &quot;Valid_repeat_bc&quot; // 验证是否存在重复班次
49 49 eval($sd.isBefore($ed) || $sd.isEqual($ed))
50 50 $spiList: ArrayList() from collect (SchedulePlanInfo(scheduleDate.getTime() == $sd.getMillis()))
51 51 $infos: ArrayList() from accumulate ($spi: SchedulePlanInfo() from $spiList, vrb($spi))
  52 + $infos2: ArrayList() from accumulate ($spi: SchedulePlanInfo() from $spiList, vwrb($spi))
52 53 then
53 54 // TODO:
54   - log.info("日期={},班次重复错误数={}", $sd, $infos.size());
  55 +// log.info("日期={},班次重复错误数={}", $sd, $infos.size());
55 56  
56 57 validResult.getInfos().addAll($infos);
  58 + validResult.getInfos().addAll($infos2);
57 59  
58 60 // 迭代
59 61 $lp.setStart_date($sd.plusDays(1));
... ...