Commit 9f59ace82460710abd083a15f2c4dfd48820cdd8

Authored by 徐烜
1 parent fdc4287f

Update

src/main/java/com/bsth/entity/schedule/temp/SchedulePlanRuleResult.java 0 → 100644
  1 +package com.bsth.entity.schedule.temp;
  2 +
  3 +import com.bsth.entity.schedule.SchedulePlan;
  4 +
  5 +import javax.persistence.Entity;
  6 +import javax.persistence.GeneratedValue;
  7 +import javax.persistence.Id;
  8 +import javax.persistence.Table;
  9 +import java.util.Date;
  10 +
  11 +/**
  12 + * 排班的中间结果数据,记录每次排班后规则的变化。
  13 + */
  14 +@Entity
  15 +@Table(name = "bsth_c_s_sp_rule_rst")
  16 +public class SchedulePlanRuleResult {
  17 + /** 主键Id */
  18 + @Id
  19 + @GeneratedValue
  20 + private Long id;
  21 +
  22 + /** 排班规则id */
  23 + private String ruleId;
  24 + /** 车辆配置id */
  25 + private String ccId;
  26 + /** 车辆自编号 */
  27 + private String ccZbh;
  28 +
  29 + /** 路牌id列表字符串 */
  30 + private String gids;
  31 + /** 路牌名字列表字符串 */
  32 + private String gnames;
  33 + /** 翻到哪个路牌索引 */
  34 + private String gidindex;
  35 + /** 人员配置id列表字符串 */
  36 + private String ecids;
  37 + /** 人员配置搭班编码列表字符串 */
  38 + private String ecdbbms;
  39 + /** 翻到哪个人员配置索引 */
  40 + private String ecindex;
  41 +
  42 + /** 排班日期 */
  43 + private Date scheduleDate;
  44 +
  45 + /** 操作人员id */
  46 + private String sysuserId;
  47 + /** 操作人员姓名 */
  48 + private String sysuserName;
  49 + /** 操作时间 */
  50 + private Date createDate;
  51 +
  52 + public SchedulePlanRuleResult() {
  53 +
  54 + }
  55 + public SchedulePlanRuleResult(SchedulePlan schedulePlan) {
  56 + this.sysuserId = schedulePlan.getCreateBy().getId().toString();
  57 + this.sysuserName = schedulePlan.getCreateBy().getName();
  58 + this.createDate = schedulePlan.getCreateDate();
  59 + }
  60 +
  61 + public Long getId() {
  62 + return id;
  63 + }
  64 +
  65 + public void setId(Long id) {
  66 + this.id = id;
  67 + }
  68 +
  69 + public String getRuleId() {
  70 + return ruleId;
  71 + }
  72 +
  73 + public void setRuleId(String ruleId) {
  74 + this.ruleId = ruleId;
  75 + }
  76 +
  77 + public String getCcId() {
  78 + return ccId;
  79 + }
  80 +
  81 + public void setCcId(String ccId) {
  82 + this.ccId = ccId;
  83 + }
  84 +
  85 + public String getCcZbh() {
  86 + return ccZbh;
  87 + }
  88 +
  89 + public void setCcZbh(String ccZbh) {
  90 + this.ccZbh = ccZbh;
  91 + }
  92 +
  93 + public String getGids() {
  94 + return gids;
  95 + }
  96 +
  97 + public void setGids(String gids) {
  98 + this.gids = gids;
  99 + }
  100 +
  101 + public String getGnames() {
  102 + return gnames;
  103 + }
  104 +
  105 + public void setGnames(String gnames) {
  106 + this.gnames = gnames;
  107 + }
  108 +
  109 + public String getGidindex() {
  110 + return gidindex;
  111 + }
  112 +
  113 + public void setGidindex(String gidindex) {
  114 + this.gidindex = gidindex;
  115 + }
  116 +
  117 + public String getEcids() {
  118 + return ecids;
  119 + }
  120 +
  121 + public void setEcids(String ecids) {
  122 + this.ecids = ecids;
  123 + }
  124 +
  125 + public String getEcdbbms() {
  126 + return ecdbbms;
  127 + }
  128 +
  129 + public void setEcdbbms(String ecdbbms) {
  130 + this.ecdbbms = ecdbbms;
  131 + }
  132 +
  133 + public String getEcindex() {
  134 + return ecindex;
  135 + }
  136 +
  137 + public void setEcindex(String ecindex) {
  138 + this.ecindex = ecindex;
  139 + }
  140 +
  141 + public Date getScheduleDate() {
  142 + return scheduleDate;
  143 + }
  144 +
  145 + public void setScheduleDate(Date scheduleDate) {
  146 + this.scheduleDate = scheduleDate;
  147 + }
  148 +
  149 + public String getSysuserId() {
  150 + return sysuserId;
  151 + }
  152 +
  153 + public void setSysuserId(String sysuserId) {
  154 + this.sysuserId = sysuserId;
  155 + }
  156 +
  157 + public String getSysuserName() {
  158 + return sysuserName;
  159 + }
  160 +
  161 + public void setSysuserName(String sysuserName) {
  162 + this.sysuserName = sysuserName;
  163 + }
  164 +
  165 + public Date getCreateDate() {
  166 + return createDate;
  167 + }
  168 +
  169 + public void setCreateDate(Date createDate) {
  170 + this.createDate = createDate;
  171 + }
  172 +}
src/main/java/com/bsth/repository/schedule/SchedulePlanRuleResultRepository.java 0 → 100644
  1 +package com.bsth.repository.schedule;
  2 +
  3 +import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
  4 +import com.bsth.repository.BaseRepository;
  5 +import org.springframework.stereotype.Repository;
  6 +
  7 +/**
  8 + * Created by xu on 17/3/29.
  9 + */
  10 +@Repository
  11 +public interface SchedulePlanRuleResultRepository extends BaseRepository<SchedulePlanRuleResult, Long> {
  12 +}
src/main/java/com/bsth/service/schedule/SchedulePlanRuleResultService.java 0 → 100644
  1 +package com.bsth.service.schedule;
  2 +
  3 +import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
  4 +
  5 +/**
  6 + * Created by xu on 17/3/29.
  7 + */
  8 +public interface SchedulePlanRuleResultService extends BService<SchedulePlanRuleResult, Long> {
  9 +}
src/main/java/com/bsth/service/schedule/impl/SchedulePlanRuleResultServiceImpl.java 0 → 100644
  1 +package com.bsth.service.schedule.impl;
  2 +
  3 +import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
  4 +import com.bsth.service.schedule.SchedulePlanRuleResultService;
  5 +import org.springframework.stereotype.Service;
  6 +
  7 +/**
  8 + * Created by xu on 17/3/29.
  9 + */
  10 +@Service
  11 +public class SchedulePlanRuleResultServiceImpl extends BServiceImpl<SchedulePlanRuleResult, Long> implements SchedulePlanRuleResultService {
  12 +}
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
@@ -6,6 +6,7 @@ import com.bsth.entity.schedule.rule.ScheduleRule1Flat; @@ -6,6 +6,7 @@ import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
6 import com.bsth.repository.BusinessRepository; 6 import com.bsth.repository.BusinessRepository;
7 import com.bsth.repository.LineRepository; 7 import com.bsth.repository.LineRepository;
8 import com.bsth.repository.schedule.*; 8 import com.bsth.repository.schedule.*;
  9 +import com.bsth.service.schedule.SchedulePlanRuleResultService;
9 import com.bsth.service.schedule.SchedulePlanService; 10 import com.bsth.service.schedule.SchedulePlanService;
10 import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input; 11 import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
11 import com.bsth.service.schedule.rules.plan.PlanResult; 12 import com.bsth.service.schedule.rules.plan.PlanResult;
@@ -51,6 +52,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im @@ -51,6 +52,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
51 private EmployeeConfigInfoRepository employeeConfigInfoRepository; 52 private EmployeeConfigInfoRepository employeeConfigInfoRepository;
52 @Autowired 53 @Autowired
53 private BusinessRepository businessRepository; 54 private BusinessRepository businessRepository;
  55 + @Autowired
  56 + private SchedulePlanRuleResultService schedulePlanRuleResultService;
54 57
55 /** 日志记录器 */ 58 /** 日志记录器 */
56 private Logger logger = LoggerFactory.getLogger(SchedulePlanServiceImpl.class); 59 private Logger logger = LoggerFactory.getLogger(SchedulePlanServiceImpl.class);
@@ -229,6 +232,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im @@ -229,6 +232,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
229 schedulePlan.getSchedulePlanInfoList().addAll(planResult.getSchedulePlanInfos()); 232 schedulePlan.getSchedulePlanInfoList().addAll(planResult.getSchedulePlanInfos());
230 super.save(schedulePlan); 233 super.save(schedulePlan);
231 234
  235 + schedulePlanRuleResultService.bulkSave(scheduleResults_output.getSchedulePlanRuleResults());
  236 +
232 return new SchedulePlan(); 237 return new SchedulePlan();
233 } 238 }
234 239
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleCalcuParam_input.java
@@ -12,11 +12,16 @@ public class ScheduleCalcuParam_input { @@ -12,11 +12,16 @@ public class ScheduleCalcuParam_input {
12 /** 结束计算日期 */ 12 /** 结束计算日期 */
13 private DateTime toDate; 13 private DateTime toDate;
14 14
  15 + /** 排班计划实体 */
  16 + private SchedulePlan schedulePlan;
  17 +
15 public ScheduleCalcuParam_input() {} 18 public ScheduleCalcuParam_input() {}
16 19
17 public ScheduleCalcuParam_input(SchedulePlan schedulePlan) { 20 public ScheduleCalcuParam_input(SchedulePlan schedulePlan) {
18 this.fromDate = new DateTime((schedulePlan.getScheduleFromTime())); 21 this.fromDate = new DateTime((schedulePlan.getScheduleFromTime()));
19 this.toDate = new DateTime((schedulePlan.getScheduleToTime())); 22 this.toDate = new DateTime((schedulePlan.getScheduleToTime()));
  23 +
  24 + this.schedulePlan = schedulePlan;
20 } 25 }
21 26
22 public DateTime getFromDate() { 27 public DateTime getFromDate() {
@@ -35,4 +40,11 @@ public class ScheduleCalcuParam_input { @@ -35,4 +40,11 @@ public class ScheduleCalcuParam_input {
35 this.toDate = toDate; 40 this.toDate = toDate;
36 } 41 }
37 42
  43 + public SchedulePlan getSchedulePlan() {
  44 + return schedulePlan;
  45 + }
  46 +
  47 + public void setSchedulePlan(SchedulePlan schedulePlan) {
  48 + this.schedulePlan = schedulePlan;
  49 + }
38 } 50 }
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResults_output.java
1 package com.bsth.service.schedule.rules.shiftloop; 1 package com.bsth.service.schedule.rules.shiftloop;
2 2
  3 +import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
3 import org.apache.commons.lang3.StringUtils; 4 import org.apache.commons.lang3.StringUtils;
4 5
5 import java.util.*; 6 import java.util.*;
@@ -11,6 +12,17 @@ public class ScheduleResults_output { @@ -11,6 +12,17 @@ public class ScheduleResults_output {
11 /** 输出列表 */ 12 /** 输出列表 */
12 private List<ScheduleResult_output> results = new ArrayList<>(); 13 private List<ScheduleResult_output> results = new ArrayList<>();
13 14
  15 + /** 排班规则结果保存数据 */
  16 + private List<SchedulePlanRuleResult> schedulePlanRuleResults = new ArrayList<>();
  17 +
  18 + public List<SchedulePlanRuleResult> getSchedulePlanRuleResults() {
  19 + return schedulePlanRuleResults;
  20 + }
  21 +
  22 + public void setSchedulePlanRuleResults(List<SchedulePlanRuleResult> schedulePlanRuleResults) {
  23 + this.schedulePlanRuleResults = schedulePlanRuleResults;
  24 + }
  25 +
14 public List<ScheduleResult_output> getResults() { 26 public List<ScheduleResult_output> getResults() {
15 return results; 27 return results;
16 } 28 }
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_input.java
@@ -36,6 +36,9 @@ public class ScheduleRule_input { @@ -36,6 +36,9 @@ public class ScheduleRule_input {
36 /** 车辆翻版(周一到周日是否启用) */ 36 /** 车辆翻版(周一到周日是否启用) */
37 private List<Boolean> weekdays = new ArrayList<>(); 37 private List<Boolean> weekdays = new ArrayList<>();
38 38
  39 + /** 关联的原始规则 */
  40 + private ScheduleRule1Flat self;
  41 +
39 public ScheduleRule_input() {} 42 public ScheduleRule_input() {}
40 43
41 public ScheduleRule_input(ScheduleRule1Flat scheduleRule1Flat) { 44 public ScheduleRule_input(ScheduleRule1Flat scheduleRule1Flat) {
@@ -74,6 +77,8 @@ public class ScheduleRule_input { @@ -74,6 +77,8 @@ public class ScheduleRule_input {
74 weekdays.add(false); 77 weekdays.add(false);
75 } 78 }
76 } 79 }
  80 +
  81 + this.self = scheduleRule1Flat;
77 } 82 }
78 83
79 public String getRuleId() { 84 public String getRuleId() {
@@ -147,4 +152,12 @@ public class ScheduleRule_input { @@ -147,4 +152,12 @@ public class ScheduleRule_input {
147 public void setXlId(String xlId) { 152 public void setXlId(String xlId) {
148 this.xlId = xlId; 153 this.xlId = xlId;
149 } 154 }
  155 +
  156 + public ScheduleRule1Flat getSelf() {
  157 + return self;
  158 + }
  159 +
  160 + public void setSelf(ScheduleRule1Flat self) {
  161 + this.self = self;
  162 + }
150 } 163 }
src/main/resources/logback.xml
@@ -155,6 +155,10 @@ @@ -155,6 +155,10 @@
155 <appender-ref ref="DATATOOLS" /> 155 <appender-ref ref="DATATOOLS" />
156 </logger> 156 </logger>
157 157
  158 + <!--<logger name="org.hibernate.SQL" level="TRACE">-->
  159 + <!--<appender-ref ref="STDOUT" />-->
  160 + <!--</logger>-->
  161 +
158 <!-- 日志输出级别 --> 162 <!-- 日志输出级别 -->
159 <root level="info"> 163 <root level="info">
160 <appender-ref ref="STDOUT" /> 164 <appender-ref ref="STDOUT" />
src/main/resources/rules/shiftloop_fb_2.drl
@@ -10,6 +10,8 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; @@ -10,6 +10,8 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
10 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; 10 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
11 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; 11 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
12 12
  13 +import com.bsth.entity.schedule.temp.SchedulePlanRuleResult;
  14 +
13 import org.slf4j.Logger; 15 import org.slf4j.Logger;
14 16
15 global Logger log; 17 global Logger log;
@@ -167,6 +169,7 @@ end @@ -167,6 +169,7 @@ end
167 rule "Calcu_loop2_1_" // 路牌在时刻表中存在,就翻 169 rule "Calcu_loop2_1_" // 路牌在时刻表中存在,就翻
168 salience 800 170 salience 800
169 when 171 when
  172 + ScheduleCalcuParam_input($sp: schedulePlan)
170 $cdrp: Calcu_days_result_pre( 173 $cdrp: Calcu_days_result_pre(
171 calcu_start_date_1.isEqual(calcu_end_date_1), 174 calcu_start_date_1.isEqual(calcu_end_date_1),
172 calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), 175 calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2),
@@ -182,7 +185,8 @@ rule &quot;Calcu_loop2_1_&quot; // 路牌在时刻表中存在,就翻 @@ -182,7 +185,8 @@ rule &quot;Calcu_loop2_1_&quot; // 路牌在时刻表中存在,就翻
182 $gids: guideboardIds, 185 $gids: guideboardIds,
183 $eids: employeeConfigIds, 186 $eids: employeeConfigIds,
184 $lprangesize : guideboardIds.size(), 187 $lprangesize : guideboardIds.size(),
185 - $ryrangesize: employeeConfigIds.size() 188 + $ryrangesize: employeeConfigIds.size(),
  189 + $srf: self
186 ) 190 )
187 $liro: LpInfoResult_output( 191 $liro: LpInfoResult_output(
188 dateTime.isEqual($csd2), 192 dateTime.isEqual($csd2),
@@ -203,6 +207,22 @@ rule &quot;Calcu_loop2_1_&quot; // 路牌在时刻表中存在,就翻 @@ -203,6 +207,22 @@ rule &quot;Calcu_loop2_1_&quot; // 路牌在时刻表中存在,就翻
203 $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize); 207 $cdrp.setCalcu_index_ry(($ryindex + 1) % $ryrangesize);
204 $cdrp.setCalcu_start_date_2($csd2.plusDays(1)); 208 $cdrp.setCalcu_start_date_2($csd2.plusDays(1));
205 209
  210 + // 保存排班规则循环结果 --> SchedulePlanRuleResult
  211 + SchedulePlanRuleResult schedulePlanRuleResult = new SchedulePlanRuleResult($sp);
  212 + schedulePlanRuleResult.setRuleId($ruleId);
  213 + schedulePlanRuleResult.setCcId($cid);
  214 + schedulePlanRuleResult.setCcZbh($srf.getCarConfigInfo().getCl().getInsideCode());
  215 + schedulePlanRuleResult.setGids($srf.getLpIds());
  216 + schedulePlanRuleResult.setGnames($srf.getLpNames());
  217 + schedulePlanRuleResult.setGidindex(String.valueOf($lpindex));
  218 + schedulePlanRuleResult.setEcids($srf.getRyConfigIds());
  219 + schedulePlanRuleResult.setEcdbbms($srf.getRyDbbms());
  220 + schedulePlanRuleResult.setEcindex(String.valueOf($ryindex));
  221 + schedulePlanRuleResult.setScheduleDate($csd2.toDate());
  222 +
  223 + scheduleResult.getSchedulePlanRuleResults().add(schedulePlanRuleResult);
  224 +
  225 +
206 log.info("Calcu_loop2_1_ ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", 226 log.info("Calcu_loop2_1_ ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}",
207 $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2); 227 $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2);
208 228
@@ -212,6 +232,7 @@ end @@ -212,6 +232,7 @@ end
212 rule "Calcu_loop2_2_" // 路牌在时刻表中不存在,就不翻 232 rule "Calcu_loop2_2_" // 路牌在时刻表中不存在,就不翻
213 salience 800 233 salience 800
214 when 234 when
  235 + ScheduleCalcuParam_input($sp: schedulePlan)
215 $cdrp: Calcu_days_result_pre( 236 $cdrp: Calcu_days_result_pre(
216 calcu_start_date_1.isEqual(calcu_end_date_1), 237 calcu_start_date_1.isEqual(calcu_end_date_1),
217 calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2), 238 calcu_start_date_2.isBefore(calcu_end_date_2) || calcu_start_date_2.isEqual(calcu_end_date_2),
@@ -225,8 +246,8 @@ rule &quot;Calcu_loop2_2_&quot; // 路牌在时刻表中不存在,就不翻 @@ -225,8 +246,8 @@ rule &quot;Calcu_loop2_2_&quot; // 路牌在时刻表中不存在,就不翻
225 ruleId == $ruleId, 246 ruleId == $ruleId,
226 $cid: carConfigId, 247 $cid: carConfigId,
227 $gids: guideboardIds, 248 $gids: guideboardIds,
228 - $eids: employeeConfigIds  
229 - 249 + $eids: employeeConfigIds,
  250 + $srf: self
230 ) 251 )
231 then 252 then
232 ScheduleResult_output ro = new ScheduleResult_output(); 253 ScheduleResult_output ro = new ScheduleResult_output();
@@ -240,6 +261,21 @@ rule &quot;Calcu_loop2_2_&quot; // 路牌在时刻表中不存在,就不翻 @@ -240,6 +261,21 @@ rule &quot;Calcu_loop2_2_&quot; // 路牌在时刻表中不存在,就不翻
240 261
241 $cdrp.setCalcu_start_date_2($csd2.plusDays(1)); 262 $cdrp.setCalcu_start_date_2($csd2.plusDays(1));
242 263
  264 + // 保存排班规则循环结果 --> SchedulePlanRuleResult
  265 + SchedulePlanRuleResult schedulePlanRuleResult = new SchedulePlanRuleResult($sp);
  266 + schedulePlanRuleResult.setRuleId($ruleId);
  267 + schedulePlanRuleResult.setCcId($cid);
  268 + schedulePlanRuleResult.setCcZbh($srf.getCarConfigInfo().getCl().getInsideCode());
  269 + schedulePlanRuleResult.setGids($srf.getLpIds());
  270 + schedulePlanRuleResult.setGnames($srf.getLpNames());
  271 + schedulePlanRuleResult.setGidindex(String.valueOf($lpindex));
  272 + schedulePlanRuleResult.setEcids($srf.getRyConfigIds());
  273 + schedulePlanRuleResult.setEcdbbms($srf.getRyDbbms());
  274 + schedulePlanRuleResult.setEcindex(String.valueOf($ryindex));
  275 + schedulePlanRuleResult.setScheduleDate($csd2.toDate());
  276 +
  277 + scheduleResult.getSchedulePlanRuleResults().add(schedulePlanRuleResult);
  278 +
243 log.info("Calcu_loop2_2_ ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}", 279 log.info("Calcu_loop2_2_ ruleId={}, calcu_index_lp/ry={}/{}, from={}, to={}",
244 $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2); 280 $ruleId, $cdrp.getCalcu_index_lp(), $cdrp.getCalcu_index_ry(), $csd2, $ced2);
245 281
src/main/resources/test.txt 0 → 100644