Commit f0a0253ed9e9bf6be5b44b9c4c98b1dcb2c9aaee

Authored by 潘钊
2 parents afd7001d 2ba8743d

Merge branch 'minhang' of http://222.66.0.204:8800/panzhaov5/bsth_control into minhang

Showing 22 changed files with 944 additions and 283 deletions
src/main/java/com/bsth/controller/schedule/ScheduleRule1FlatController.java
@@ -55,11 +55,14 @@ public class ScheduleRule1FlatController extends BaseController<ScheduleRule1Fla @@ -55,11 +55,14 @@ public class ScheduleRule1FlatController extends BaseController<ScheduleRule1Fla
55 for (int i = 0; i < lpNames.length; i++) { 55 for (int i = 0; i < lpNames.length; i++) {
56 param1.put("lpName_eq", lpNames[i]); 56 param1.put("lpName_eq", lpNames[i]);
57 Iterable<GuideboardInfo> guideboardInfos = guideboardInfoService.list(param1); 57 Iterable<GuideboardInfo> guideboardInfos = guideboardInfoService.list(param1);
  58 + if (!guideboardInfos.iterator().hasNext()) {
  59 + throw new RuntimeException("路牌:" + lpNames[i] + "没有找到!");
  60 + }
58 lpIds[i] = guideboardInfos.iterator().next().getId().toString(); 61 lpIds[i] = guideboardInfos.iterator().next().getId().toString();
59 } 62 }
60 t.setLpIds(StringUtils.join(lpIds, ",")); 63 t.setLpIds(StringUtils.join(lpIds, ","));
61 64
62 - // 2、查找人员配置id 65 + // 2、查找人员配置id(这里要考虑分班的情况,先用-隔开,在用,隔开)
63 Map<String, Object> param2 = new HashMap<>(); 66 Map<String, Object> param2 = new HashMap<>();
64 param2.put("xl.id_eq", t.getXl().getId()); 67 param2.put("xl.id_eq", t.getXl().getId());
65 param2.put("dbbm_eq", null); 68 param2.put("dbbm_eq", null);
@@ -67,9 +70,34 @@ public class ScheduleRule1FlatController extends BaseController&lt;ScheduleRule1Fla @@ -67,9 +70,34 @@ public class ScheduleRule1FlatController extends BaseController&lt;ScheduleRule1Fla
67 String[] ryDbbms = t.getRyDbbms().split(","); 70 String[] ryDbbms = t.getRyDbbms().split(",");
68 String[] ryIds = new String[ryDbbms.length]; 71 String[] ryIds = new String[ryDbbms.length];
69 for (int j = 0; j < ryDbbms.length; j++) { 72 for (int j = 0; j < ryDbbms.length; j++) {
70 - param2.put("dbbm_eq", ryDbbms[j]);  
71 - Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);  
72 - ryIds[j] = employeeConfigInfos.iterator().next().getId().toString(); 73 + if (ryDbbms[j].indexOf("-") == -1) {
  74 + param2.put("dbbm_eq", ryDbbms[j]);
  75 + Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);
  76 + if (!employeeConfigInfos.iterator().hasNext()) {
  77 + throw new RuntimeException("搭班编码::" + ryDbbms[j] + "没有找到!");
  78 + }
  79 + ryIds[j] = employeeConfigInfos.iterator().next().getId().toString();
  80 + } else {
  81 + String[] fbRyDbbms = ryDbbms[j].split("-");
  82 + if (fbRyDbbms.length != 2) {
  83 + throw new RuntimeException("搭班编码:" + ryDbbms[j] + "错误!");
  84 + }
  85 + String[] fbRyIds = new String[2];
  86 + param2.put("dbbm_eq", fbRyDbbms[0]);
  87 + Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);
  88 + if (!employeeConfigInfos.iterator().hasNext()) {
  89 + throw new RuntimeException("搭班编码::" + fbRyDbbms[0] + "没有找到!");
  90 + }
  91 + fbRyIds[0] = employeeConfigInfos.iterator().next().getId().toString();
  92 + param2.put("dbbm_eq", fbRyDbbms[1]);
  93 + employeeConfigInfos = employeeConfigInfoService.list(param2);
  94 + if (!employeeConfigInfos.iterator().hasNext()) {
  95 + throw new RuntimeException("搭班编码::" + fbRyDbbms[1] + "没有找到!");
  96 + }
  97 + fbRyIds[1] = employeeConfigInfos.iterator().next().getId().toString();
  98 + ryIds[j] = StringUtils.join(fbRyIds, "-");
  99 + }
  100 +
73 } 101 }
74 t.setRyConfigIds(StringUtils.join(ryIds, ",")); 102 t.setRyConfigIds(StringUtils.join(ryIds, ","));
75 103
src/main/java/com/bsth/entity/schedule/SchedulePlanInfo.java
@@ -3,10 +3,10 @@ package com.bsth.entity.schedule; @@ -3,10 +3,10 @@ package com.bsth.entity.schedule;
3 import com.bsth.entity.Line; 3 import com.bsth.entity.Line;
4 import com.bsth.entity.sys.SysUser; 4 import com.bsth.entity.sys.SysUser;
5 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output; 5 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
6 -import com.fasterxml.jackson.annotation.JsonIgnore;  
7 6
8 import javax.persistence.*; 7 import javax.persistence.*;
9 import java.util.Date; 8 import java.util.Date;
  9 +import java.util.List;
10 10
11 /** 11 /**
12 * 排班计划明细。 12 * 排班计划明细。
@@ -150,7 +150,7 @@ public class SchedulePlanInfo { @@ -150,7 +150,7 @@ public class SchedulePlanInfo {
150 ScheduleResult_output scheduleResult_output, 150 ScheduleResult_output scheduleResult_output,
151 TTInfoDetail ttInfoDetail, 151 TTInfoDetail ttInfoDetail,
152 CarConfigInfo carConfigInfo, 152 CarConfigInfo carConfigInfo,
153 - EmployeeConfigInfo employeeConfigInfo, 153 + List<EmployeeConfigInfo> employeeConfigInfoList,
154 SchedulePlan schedulePlan) { 154 SchedulePlan schedulePlan) {
155 155
156 // TODO:关联的公司名称 156 // TODO:关联的公司名称
@@ -180,6 +180,17 @@ public class SchedulePlanInfo { @@ -180,6 +180,17 @@ public class SchedulePlanInfo {
180 180
181 // TODO:报道时间,出场时间没有 181 // TODO:报道时间,出场时间没有
182 // 关联的驾驶员 182 // 关联的驾驶员
  183 + EmployeeConfigInfo employeeConfigInfo = null;
  184 + if (ttInfoDetail.getIsFB()) {
  185 + if (employeeConfigInfoList.size() > 1) {
  186 + employeeConfigInfo = employeeConfigInfoList.get(1);
  187 + } else {
  188 + employeeConfigInfo = employeeConfigInfoList.get(0);
  189 + }
  190 + } else {
  191 + employeeConfigInfo = employeeConfigInfoList.get(0);
  192 + }
  193 +
183 this.j = employeeConfigInfo.getJsy().getId(); 194 this.j = employeeConfigInfo.getJsy().getId();
184 this.jGh = employeeConfigInfo.getJsy().getJobCode(); 195 this.jGh = employeeConfigInfo.getJsy().getJobCode();
185 this.jName = employeeConfigInfo.getJsy().getPersonnelName(); 196 this.jName = employeeConfigInfo.getJsy().getPersonnelName();
@@ -207,15 +218,13 @@ public class SchedulePlanInfo { @@ -207,15 +218,13 @@ public class SchedulePlanInfo {
207 this.zdz = ttInfoDetail.getTcc().getId(); // 终点站-停车场id 218 this.zdz = ttInfoDetail.getTcc().getId(); // 终点站-停车场id
208 this.zdzCode = ttInfoDetail.getTcc().getParkCode(); // 终点站-停车场code 219 this.zdzCode = ttInfoDetail.getTcc().getParkCode(); // 终点站-停车场code
209 this.zdzName = ttInfoDetail.getTcc().getParkName(); // 终点站-停车场name 220 this.zdzName = ttInfoDetail.getTcc().getParkName(); // 终点站-停车场name
210 - } else if ("normal".equals(this.bcType)) { // 正常班次 221 + } else { // 其他班次
211 this.qdz = ttInfoDetail.getQdz().getId(); // 起点站id 222 this.qdz = ttInfoDetail.getQdz().getId(); // 起点站id
212 this.qdzCode = ttInfoDetail.getQdz().getStationCod(); // 起点站code 223 this.qdzCode = ttInfoDetail.getQdz().getStationCod(); // 起点站code
213 this.qdzName = ttInfoDetail.getQdz().getStationName(); // 起点站name 224 this.qdzName = ttInfoDetail.getQdz().getStationName(); // 起点站name
214 this.zdz = ttInfoDetail.getZdz().getId(); // 终点站id 225 this.zdz = ttInfoDetail.getZdz().getId(); // 终点站id
215 this.zdzCode = ttInfoDetail.getZdz().getStationCod(); // 终点站code 226 this.zdzCode = ttInfoDetail.getZdz().getStationCod(); // 终点站code
216 this.zdzName = ttInfoDetail.getZdz().getStationName(); // 终点站name 227 this.zdzName = ttInfoDetail.getZdz().getStationName(); // 终点站name
217 - } else {  
218 - throw new RuntimeException("排班计划数据,未知班次类型:" + this.bcType);  
219 } 228 }
220 229
221 this.fcsj = ttInfoDetail.getFcsj(); // 发车时间 230 this.fcsj = ttInfoDetail.getFcsj(); // 发车时间
src/main/java/com/bsth/entity/schedule/rule/ScheduleRule1Flat.java
@@ -61,10 +61,10 @@ public class ScheduleRule1Flat { @@ -61,10 +61,10 @@ public class ScheduleRule1Flat {
61 /** 起始路牌(从0开始) */ 61 /** 起始路牌(从0开始) */
62 @NotNull 62 @NotNull
63 private Integer lpStart; 63 private Integer lpStart;
64 - /** 人员搭班编码s(用逗号隔开) */ 64 + /** 人员搭班编码s(用逗号隔开,如果分班,就先-隔开再逗号隔开) */
65 @NotNull 65 @NotNull
66 private String ryDbbms; 66 private String ryDbbms;
67 - /** 对应的人员配置ids(用逗号隔开) */ 67 + /** 对应的人员配置ids(用逗号隔开,如果分班,就先-隔开再逗号隔开) */
68 @NotNull 68 @NotNull
69 private String ryConfigIds; 69 private String ryConfigIds;
70 /** 起始人员(从0开始) */ 70 /** 起始人员(从0开始) */
src/main/java/com/bsth/service/BaseService.java
@@ -4,6 +4,7 @@ import org.springframework.data.domain.Page; @@ -4,6 +4,7 @@ import org.springframework.data.domain.Page;
4 import org.springframework.data.domain.Pageable; 4 import org.springframework.data.domain.Pageable;
5 5
6 import java.io.Serializable; 6 import java.io.Serializable;
  7 +import java.util.Collection;
7 import java.util.Map; 8 import java.util.Map;
8 9
9 /** 10 /**
@@ -70,4 +71,11 @@ public interface BaseService&lt;T, ID extends Serializable&gt; { @@ -70,4 +71,11 @@ public interface BaseService&lt;T, ID extends Serializable&gt; {
70 * @return {status:状态编码,msg:错误描述},状态编码 @see com.bsth.common.ResponseCode 71 * @return {status:状态编码,msg:错误描述},状态编码 @see com.bsth.common.ResponseCode
71 */ 72 */
72 Map<String, Object> validateEquale(Map<String, Object> params); 73 Map<String, Object> validateEquale(Map<String, Object> params);
  74 +
  75 + /**
  76 + * 批量保存。
  77 + * @param entities 实体列表
  78 + * @return 保存后的entities
  79 + */
  80 + <S extends T> Collection<S> bulkSave(Collection<S> entities);
73 } 81 }
src/main/java/com/bsth/service/impl/BaseServiceImpl.java
@@ -7,18 +7,23 @@ import com.bsth.service.BaseService; @@ -7,18 +7,23 @@ import com.bsth.service.BaseService;
7 import org.slf4j.Logger; 7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.beans.factory.annotation.Value;
10 import org.springframework.dao.DataIntegrityViolationException; 11 import org.springframework.dao.DataIntegrityViolationException;
11 import org.springframework.data.domain.Page; 12 import org.springframework.data.domain.Page;
12 import org.springframework.data.domain.Pageable; 13 import org.springframework.data.domain.Pageable;
13 14
  15 +import javax.persistence.EntityManager;
14 import java.io.Serializable; 16 import java.io.Serializable;
15 -import java.util.HashMap;  
16 -import java.util.Map; 17 +import java.util.*;
17 18
18 public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID>{ 19 public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID>{
19 20
20 @Autowired 21 @Autowired
21 private BaseRepository<T, ID> baseRepository; 22 private BaseRepository<T, ID> baseRepository;
  23 + @Autowired
  24 + private EntityManager entityManager;
  25 + @Value("${hibernate.jdbc.batch_size}")
  26 + private int batchSize;
22 27
23 Logger logger = LoggerFactory.getLogger(this.getClass()); 28 Logger logger = LoggerFactory.getLogger(this.getClass());
24 29
@@ -50,9 +55,25 @@ public class BaseServiceImpl&lt;T, ID extends Serializable&gt; implements BaseService&lt; @@ -50,9 +55,25 @@ public class BaseServiceImpl&lt;T, ID extends Serializable&gt; implements BaseService&lt;
50 } 55 }
51 return map; 56 return map;
52 } 57 }
53 -  
54 58
55 - @Override 59 + @Override
  60 + public <S extends T> Collection<S> bulkSave(Collection<S> entities) {
  61 + final List<S> savedEntities = new ArrayList<>(entities.size());
  62 + int i = 0;
  63 + for (S t : entities) {
  64 + entityManager.persist(t);
  65 + savedEntities.add(t);
  66 + i++;
  67 + if (i % batchSize == 0) {
  68 + entityManager.flush();
  69 + entityManager.clear();
  70 + }
  71 + }
  72 +
  73 + return savedEntities;
  74 + }
  75 +
  76 + @Override
56 public Iterable<T> findAll() { 77 public Iterable<T> findAll() {
57 return baseRepository.findAll(); 78 return baseRepository.findAll();
58 } 79 }
src/main/java/com/bsth/service/schedule/SchedulePlanServiceImpl.java
@@ -47,8 +47,8 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt; @@ -47,8 +47,8 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt;
47 // 1-1、查找线路具体信息 47 // 1-1、查找线路具体信息
48 Line xl = strategy.getLine(schedulePlan.getXl().getId()); 48 Line xl = strategy.getLine(schedulePlan.getXl().getId());
49 // 1-2、查出指定线路的所有规则 49 // 1-2、查出指定线路的所有规则
50 - TTInfo ttInfo = strategy.getTTInfo(xl.getId()); // 时刻表id  
51 - schedulePlan.setTtInfo(ttInfo); // 关联的时刻表 50 + TTInfo ttInfo = strategy.getTTInfo(xl.getId()).get(0); // 时刻表id
  51 + schedulePlan.setTtInfo(ttInfo); // TODO:关联的时刻表,之后改掉
52 52
53 // 2-1、构造drools规则输入数据,输出数据 53 // 2-1、构造drools规则输入数据,输出数据
54 // 全局计算参数 54 // 全局计算参数
@@ -89,7 +89,9 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt; @@ -89,7 +89,9 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt;
89 89
90 // 3、根据规则返回,组合最后的输出数据 90 // 3、根据规则返回,组合最后的输出数据
91 // 3-1、根据注入的策略服务,获取原始数据 91 // 3-1、根据注入的策略服务,获取原始数据
92 - Multimap<Long, TTInfoDetail> gbdTTinfoMaps = strategy.getGuideboardXlTTInfoDetailMaps(xl.getId()); // 路牌对应时刻明细 92 + Map<Date, Multimap<Long, TTInfoDetail>> gbdTTinfoMaps = strategy.getGuideboardXlTTInfoDetailMaps(
  93 + xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime());
  94 +
93 Map<Long, CarConfigInfo> carConfigMaps = strategy.getCarConfigMaps(xl.getId()); // 车辆配置对应车辆信息 95 Map<Long, CarConfigInfo> carConfigMaps = strategy.getCarConfigMaps(xl.getId()); // 车辆配置对应车辆信息
94 Map<Long, EmployeeConfigInfo> employeeConfigMaps = strategy.getEmployeeConfigMaps(xl.getId()); // 人员配置对应的人员信息 96 Map<Long, EmployeeConfigInfo> employeeConfigMaps = strategy.getEmployeeConfigMaps(xl.getId()); // 人员配置对应的人员信息
95 97
@@ -97,18 +99,23 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt; @@ -97,18 +99,23 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl&lt;SchedulePlan, Long&gt;
97 List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>(); 99 List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>();
98 for (ScheduleResult_output scheduleResult_output : scheduleResults_output.getResults()) { 100 for (ScheduleResult_output scheduleResult_output : scheduleResults_output.getResults()) {
99 // 车辆配置对应的车辆 101 // 车辆配置对应的车辆
100 - CarConfigInfo configInfo = carConfigMaps.get(scheduleResult_output.getCarConfigId());  
101 - // 人员配置对应的人员  
102 - EmployeeConfigInfo employeeConfigInfo = employeeConfigMaps.get(scheduleResult_output.getEmployeeConfigId()); 102 + CarConfigInfo configInfo = carConfigMaps.get(Long.valueOf(scheduleResult_output.getCarConfigId()));
  103 + // 人员配置对应的人员,这里需要分班处理的
  104 + List<EmployeeConfigInfo> employeeConfigInfoList = new ArrayList<>();
  105 + String[] eids = scheduleResult_output.getEmployeeConfigId().split("-");
  106 + for (String eid : eids) {
  107 + employeeConfigInfoList.add(employeeConfigMaps.get(Long.valueOf(eid)));
  108 + }
103 // 排班明细(这个要迭代的) 109 // 排班明细(这个要迭代的)
104 - Collection<TTInfoDetail> ttInfoDetails = gbdTTinfoMaps.get(scheduleResult_output.getGuideboardId()); 110 + Collection<TTInfoDetail> ttInfoDetails = gbdTTinfoMaps.get(scheduleResult_output.getSd().toDate()).get(
  111 + Long.parseLong(scheduleResult_output.getGuideboardId()));
105 for (TTInfoDetail ttInfoDetail : ttInfoDetails) { 112 for (TTInfoDetail ttInfoDetail : ttInfoDetails) {
106 SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( 113 SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo(
107 xl, 114 xl,
108 scheduleResult_output, 115 scheduleResult_output,
109 ttInfoDetail, 116 ttInfoDetail,
110 configInfo, 117 configInfo,
111 - employeeConfigInfo, 118 + employeeConfigInfoList,
112 schedulePlan); 119 schedulePlan);
113 schedulePlanInfos.add(schedulePlanInfo); 120 schedulePlanInfos.add(schedulePlanInfo);
114 } 121 }
src/main/java/com/bsth/service/schedule/rules/MyDroolsConfiguration.java
@@ -58,6 +58,9 @@ public class MyDroolsConfiguration { @@ -58,6 +58,9 @@ public class MyDroolsConfiguration {
58 kfs.write("src/main/resources/shiftloop.drl", kieServices.getResources() 58 kfs.write("src/main/resources/shiftloop.drl", kieServices.getResources()
59 .newInputStreamResource(this.getClass().getResourceAsStream( 59 .newInputStreamResource(this.getClass().getResourceAsStream(
60 "/rules/shiftloop.drl"), "UTF-8")); 60 "/rules/shiftloop.drl"), "UTF-8"));
  61 + kfs.write("src/main/resources/ttinfo.drl", kieServices.getResources()
  62 + .newInputStreamResource(this.getClass().getResourceAsStream(
  63 + "/rules/ttinfo.drl"), "UTF-8"));
61 // TODO:还有其他drl.... 64 // TODO:还有其他drl....
62 65
63 // 4、创建KieBuilder,使用KieFileSystem构建 66 // 4、创建KieBuilder,使用KieFileSystem构建
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleCalcuParam_input.java
@@ -11,15 +11,12 @@ public class ScheduleCalcuParam_input { @@ -11,15 +11,12 @@ public class ScheduleCalcuParam_input {
11 private DateTime fromDate; 11 private DateTime fromDate;
12 /** 结束计算日期 */ 12 /** 结束计算日期 */
13 private DateTime toDate; 13 private DateTime toDate;
14 - /** 时刻表id */  
15 - private Long ttinfoId;  
16 14
17 public ScheduleCalcuParam_input() {} 15 public ScheduleCalcuParam_input() {}
18 16
19 public ScheduleCalcuParam_input(SchedulePlan schedulePlan) { 17 public ScheduleCalcuParam_input(SchedulePlan schedulePlan) {
20 this.fromDate = new DateTime((schedulePlan.getScheduleFromTime())); 18 this.fromDate = new DateTime((schedulePlan.getScheduleFromTime()));
21 this.toDate = new DateTime((schedulePlan.getScheduleToTime())); 19 this.toDate = new DateTime((schedulePlan.getScheduleToTime()));
22 - this.ttinfoId = schedulePlan.getTtInfo().getId();  
23 } 20 }
24 21
25 public DateTime getFromDate() { 22 public DateTime getFromDate() {
@@ -38,11 +35,4 @@ public class ScheduleCalcuParam_input { @@ -38,11 +35,4 @@ public class ScheduleCalcuParam_input {
38 this.toDate = toDate; 35 this.toDate = toDate;
39 } 36 }
40 37
41 - public Long getTtinfoId() {  
42 - return ttinfoId;  
43 - }  
44 -  
45 - public void setTtinfoId(Long ttinfoId) {  
46 - this.ttinfoId = ttinfoId;  
47 - }  
48 } 38 }
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResult_output.java
@@ -9,13 +9,13 @@ public class ScheduleResult_output { @@ -9,13 +9,13 @@ public class ScheduleResult_output {
9 /** 具体日期 */ 9 /** 具体日期 */
10 private DateTime sd; 10 private DateTime sd;
11 /** 用的是哪一组rule */ 11 /** 用的是哪一组rule */
12 - private Long ruleId; 12 + private String ruleId;
13 /** 路牌id */ 13 /** 路牌id */
14 - private Long guideboardId; 14 + private String guideboardId;
15 /** 人员配置id */ 15 /** 人员配置id */
16 - private Long employeeConfigId; 16 + private String employeeConfigId;
17 /** 车辆配置id */ 17 /** 车辆配置id */
18 - private Long carConfigId; 18 + private String carConfigId;
19 19
20 public DateTime getSd() { 20 public DateTime getSd() {
21 return sd; 21 return sd;
@@ -25,36 +25,35 @@ public class ScheduleResult_output { @@ -25,36 +25,35 @@ public class ScheduleResult_output {
25 this.sd = sd; 25 this.sd = sd;
26 } 26 }
27 27
28 - public Long getGuideboardId() { 28 + public String getRuleId() {
  29 + return ruleId;
  30 + }
  31 +
  32 + public void setRuleId(String ruleId) {
  33 + this.ruleId = ruleId;
  34 + }
  35 +
  36 + public String getGuideboardId() {
29 return guideboardId; 37 return guideboardId;
30 } 38 }
31 39
32 - public void setGuideboardId(Long guideboardId) { 40 + public void setGuideboardId(String guideboardId) {
33 this.guideboardId = guideboardId; 41 this.guideboardId = guideboardId;
34 } 42 }
35 43
36 - public Long getEmployeeConfigId() { 44 + public String getEmployeeConfigId() {
37 return employeeConfigId; 45 return employeeConfigId;
38 } 46 }
39 47
40 - public void setEmployeeConfigId(Long employeeConfigId) { 48 + public void setEmployeeConfigId(String employeeConfigId) {
41 this.employeeConfigId = employeeConfigId; 49 this.employeeConfigId = employeeConfigId;
42 } 50 }
43 51
44 - public Long getCarConfigId() { 52 + public String getCarConfigId() {
45 return carConfigId; 53 return carConfigId;
46 } 54 }
47 55
48 - public void setCarConfigId(Long carConfigId) { 56 + public void setCarConfigId(String carConfigId) {
49 this.carConfigId = carConfigId; 57 this.carConfigId = carConfigId;
50 } 58 }
51 -  
52 - public Long getRuleId() {  
53 - return ruleId;  
54 - }  
55 -  
56 - public void setRuleId(Long ruleId) {  
57 - this.ruleId = ruleId;  
58 - }  
59 -  
60 } 59 }
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResults_output.java
@@ -25,7 +25,7 @@ public class ScheduleResults_output { @@ -25,7 +25,7 @@ public class ScheduleResults_output {
25 */ 25 */
26 public String showGuideboardDesc1() { 26 public String showGuideboardDesc1() {
27 StringBuilder stringBuilder = new StringBuilder(); 27 StringBuilder stringBuilder = new StringBuilder();
28 - Map<Long, List<ScheduleResult_output>> groupRuleIdGuideBoardMap = new HashMap<>(); 28 + Map<String, List<ScheduleResult_output>> groupRuleIdGuideBoardMap = new HashMap<>();
29 for (ScheduleResult_output s : results) { 29 for (ScheduleResult_output s : results) {
30 if (groupRuleIdGuideBoardMap.get(s.getRuleId()) == null) { 30 if (groupRuleIdGuideBoardMap.get(s.getRuleId()) == null) {
31 groupRuleIdGuideBoardMap.put(s.getRuleId(), new ArrayList<ScheduleResult_output>()); 31 groupRuleIdGuideBoardMap.put(s.getRuleId(), new ArrayList<ScheduleResult_output>());
@@ -33,7 +33,7 @@ public class ScheduleResults_output { @@ -33,7 +33,7 @@ public class ScheduleResults_output {
33 groupRuleIdGuideBoardMap.get(s.getRuleId()).add(s); 33 groupRuleIdGuideBoardMap.get(s.getRuleId()).add(s);
34 } 34 }
35 35
36 - for (Long ruleId : groupRuleIdGuideBoardMap.keySet()) { 36 + for (String ruleId : groupRuleIdGuideBoardMap.keySet()) {
37 Collections.sort(groupRuleIdGuideBoardMap.get(ruleId), new Comparator<ScheduleResult_output>() { 37 Collections.sort(groupRuleIdGuideBoardMap.get(ruleId), new Comparator<ScheduleResult_output>() {
38 @Override 38 @Override
39 public int compare(ScheduleResult_output o1, ScheduleResult_output o2) { 39 public int compare(ScheduleResult_output o1, ScheduleResult_output o2) {
@@ -41,8 +41,8 @@ public class ScheduleResults_output { @@ -41,8 +41,8 @@ public class ScheduleResults_output {
41 } 41 }
42 }); 42 });
43 43
44 - List<Long> gbids = new ArrayList<>();  
45 - List<Long> ecids = new ArrayList<>(); 44 + List<String> gbids = new ArrayList<>();
  45 + List<String> ecids = new ArrayList<>();
46 for (ScheduleResult_output so : groupRuleIdGuideBoardMap.get(ruleId)) { 46 for (ScheduleResult_output so : groupRuleIdGuideBoardMap.get(ruleId)) {
47 gbids.add(so.getGuideboardId()); 47 gbids.add(so.getGuideboardId());
48 ecids.add(so.getEmployeeConfigId()); 48 ecids.add(so.getEmployeeConfigId());
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_input.java
@@ -12,51 +12,52 @@ import java.util.List; @@ -12,51 +12,52 @@ import java.util.List;
12 */ 12 */
13 public class ScheduleRule_input { 13 public class ScheduleRule_input {
14 /** 规则Id */ 14 /** 规则Id */
15 - private Long ruleId; 15 + private String ruleId;
16 /** 规则启用日期 */ 16 /** 规则启用日期 */
17 private DateTime qyrq; 17 private DateTime qyrq;
18 18
19 /** 路牌范围 */ 19 /** 路牌范围 */
20 - private List<Long> guideboardIds = new ArrayList<>(); 20 + private List<String> guideboardIds = new ArrayList<>();
21 /** 起始路牌下标 */ 21 /** 起始路牌下标 */
22 private int startGbdIndex; 22 private int startGbdIndex;
23 23
24 /** 人员范围 */ 24 /** 人员范围 */
25 - private List<Long> employeeConfigIds = new ArrayList<>(); 25 + private List<String> employeeConfigIds = new ArrayList<>();
26 /** 起始人员下标 */ 26 /** 起始人员下标 */
27 private int startEIndex; 27 private int startEIndex;
28 28
29 /** 车辆配置id */ 29 /** 车辆配置id */
30 - private Long carConfigId; 30 + private String carConfigId;
31 31
32 // TODO:车辆翻班暂时不考虑进去 32 // TODO:车辆翻班暂时不考虑进去
33 33
34 public ScheduleRule_input() {} 34 public ScheduleRule_input() {}
35 35
36 public ScheduleRule_input(ScheduleRule1Flat scheduleRule1Flat) { 36 public ScheduleRule_input(ScheduleRule1Flat scheduleRule1Flat) {
37 - this.ruleId = scheduleRule1Flat.getId(); 37 + this.ruleId = String.valueOf(scheduleRule1Flat.getId());
38 this.qyrq = new DateTime(scheduleRule1Flat.getQyrq()); 38 this.qyrq = new DateTime(scheduleRule1Flat.getQyrq());
39 List<String> lpIds = Splitter.on(",").splitToList(scheduleRule1Flat.getLpIds()); 39 List<String> lpIds = Splitter.on(",").splitToList(scheduleRule1Flat.getLpIds());
40 - for (String lpId : lpIds) {  
41 - this.guideboardIds.add(Long.parseLong(lpId));  
42 - } 40 +// for (String lpId : lpIds) {
  41 +// this.guideboardIds.add(Long.parseLong(lpId));
  42 +// }
  43 + guideboardIds.addAll(lpIds);
43 // 路牌初始下标减1 44 // 路牌初始下标减1
44 this.startGbdIndex = scheduleRule1Flat.getLpStart() - 1; 45 this.startGbdIndex = scheduleRule1Flat.getLpStart() - 1;
45 List<String> ryCids = Splitter.on(",").splitToList(scheduleRule1Flat.getRyConfigIds()); 46 List<String> ryCids = Splitter.on(",").splitToList(scheduleRule1Flat.getRyConfigIds());
46 - for (String ryCid : ryCids) {  
47 - this.employeeConfigIds.add(Long.parseLong(ryCid));  
48 - } 47 +// for (String ryCid : ryCids) {
  48 +// this.employeeConfigIds.add(Long.parseLong(ryCid));
  49 +// }
  50 + employeeConfigIds.addAll(ryCids);
49 // 人员初始索引减1 51 // 人员初始索引减1
50 this.startEIndex = scheduleRule1Flat.getRyStart() - 1; 52 this.startEIndex = scheduleRule1Flat.getRyStart() - 1;
51 - this.carConfigId = scheduleRule1Flat.getCarConfigInfo().getId(); 53 + this.carConfigId = String.valueOf(scheduleRule1Flat.getCarConfigInfo().getId());
52 } 54 }
53 55
54 -  
55 - public Long getRuleId() { 56 + public String getRuleId() {
56 return ruleId; 57 return ruleId;
57 } 58 }
58 59
59 - public void setRuleId(Long ruleId) { 60 + public void setRuleId(String ruleId) {
60 this.ruleId = ruleId; 61 this.ruleId = ruleId;
61 } 62 }
62 63
@@ -68,11 +69,11 @@ public class ScheduleRule_input { @@ -68,11 +69,11 @@ public class ScheduleRule_input {
68 this.qyrq = qyrq; 69 this.qyrq = qyrq;
69 } 70 }
70 71
71 - public List<Long> getGuideboardIds() { 72 + public List<String> getGuideboardIds() {
72 return guideboardIds; 73 return guideboardIds;
73 } 74 }
74 75
75 - public void setGuideboardIds(List<Long> guideboardIds) { 76 + public void setGuideboardIds(List<String> guideboardIds) {
76 this.guideboardIds = guideboardIds; 77 this.guideboardIds = guideboardIds;
77 } 78 }
78 79
@@ -84,11 +85,11 @@ public class ScheduleRule_input { @@ -84,11 +85,11 @@ public class ScheduleRule_input {
84 this.startGbdIndex = startGbdIndex; 85 this.startGbdIndex = startGbdIndex;
85 } 86 }
86 87
87 - public List<Long> getEmployeeConfigIds() { 88 + public List<String> getEmployeeConfigIds() {
88 return employeeConfigIds; 89 return employeeConfigIds;
89 } 90 }
90 91
91 - public void setEmployeeConfigIds(List<Long> employeeConfigIds) { 92 + public void setEmployeeConfigIds(List<String> employeeConfigIds) {
92 this.employeeConfigIds = employeeConfigIds; 93 this.employeeConfigIds = employeeConfigIds;
93 } 94 }
94 95
@@ -100,11 +101,11 @@ public class ScheduleRule_input { @@ -100,11 +101,11 @@ public class ScheduleRule_input {
100 this.startEIndex = startEIndex; 101 this.startEIndex = startEIndex;
101 } 102 }
102 103
103 - public Long getCarConfigId() { 104 + public String getCarConfigId() {
104 return carConfigId; 105 return carConfigId;
105 } 106 }
106 107
107 - public void setCarConfigId(Long carConfigId) { 108 + public void setCarConfigId(String carConfigId) {
108 this.carConfigId = carConfigId; 109 this.carConfigId = carConfigId;
109 } 110 }
110 } 111 }
src/main/java/com/bsth/service/schedule/rules/strategy/IStrategy.java
1 -package com.bsth.service.schedule.rules.strategy;  
2 -  
3 -import com.bsth.entity.Line;  
4 -import com.bsth.entity.schedule.CarConfigInfo;  
5 -import com.bsth.entity.schedule.EmployeeConfigInfo;  
6 -import com.bsth.entity.schedule.TTInfo;  
7 -import com.bsth.entity.schedule.TTInfoDetail;  
8 -import com.bsth.entity.schedule.rule.ScheduleRule1Flat;  
9 -import com.google.common.collect.Multimap;  
10 -  
11 -import java.util.Map;  
12 -  
13 -/**  
14 - * 获取数据的策略。  
15 - */  
16 -public interface IStrategy {  
17 -  
18 - /**  
19 - * 获取线路信息。  
20 - * @param xlId 线路id  
21 - * @return  
22 - */  
23 - Line getLine(Integer xlId);  
24 -  
25 - /**  
26 - * 获取指定线路下,可用的时刻表。  
27 - * @param xlId 线路id  
28 - * @return 时刻表  
29 - */  
30 - TTInfo getTTInfo(Integer xlId);  
31 -  
32 - /**  
33 - * 获取指定线路下,可用的排班规则。  
34 - * @param xlId  
35 - * @return  
36 - */  
37 - Iterable<ScheduleRule1Flat> getScheduleRule(Integer xlId);  
38 -  
39 - /**  
40 - * 获取指定线路下,路牌与时刻明细对应的Map。  
41 - * @param xlId 线路id  
42 - * @return 路牌id为key,时刻明细 Collection<TTInfoDetail> 为value  
43 - */  
44 - Multimap<Long, TTInfoDetail> getGuideboardXlTTInfoDetailMaps(Integer xlId);  
45 -  
46 - /**  
47 - * 获取指定线路下,车辆配置与车辆信息对应的Map。  
48 - * @param xlId 线路id  
49 - * @return 车辆配置id为key,具体车辆配置信息为value。  
50 - */  
51 - Map<Long, CarConfigInfo> getCarConfigMaps(Integer xlId);  
52 -  
53 - /**  
54 - * 获取指定线路下,人员配置与人员对应的Map。  
55 - * @param xlId 线路id  
56 - * @return 人员配置id为key,具体人员配置信息为value。  
57 - */  
58 - Map<Long, EmployeeConfigInfo> getEmployeeConfigMaps(Integer xlId);  
59 -} 1 +package com.bsth.service.schedule.rules.strategy;
  2 +
  3 +import com.bsth.entity.Line;
  4 +import com.bsth.entity.schedule.CarConfigInfo;
  5 +import com.bsth.entity.schedule.EmployeeConfigInfo;
  6 +import com.bsth.entity.schedule.TTInfo;
  7 +import com.bsth.entity.schedule.TTInfoDetail;
  8 +import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
  9 +import com.google.common.collect.Multimap;
  10 +
  11 +import java.util.Date;
  12 +import java.util.List;
  13 +import java.util.Map;
  14 +
  15 +/**
  16 + * 获取数据的策略。
  17 + */
  18 +public interface IStrategy {
  19 +
  20 + /**
  21 + * 获取线路信息。
  22 + * @param xlId 线路id
  23 + * @return
  24 + */
  25 + Line getLine(Integer xlId);
  26 +
  27 + /**
  28 + * 获取指定线路下,可用的时刻表。
  29 + * @param xlId 线路id
  30 + * @return 时刻表
  31 + */
  32 + List<TTInfo> getTTInfo(Integer xlId);
  33 +
  34 + /**
  35 + * 获取指定线路的时刻表的明细。
  36 + * @param xlId 线路id
  37 + * @return
  38 + */
  39 + List<TTInfoDetail> getTTInfoDetail(Integer xlId);
  40 +
  41 + /**
  42 + * 获取指定线路下,可用的排班规则。
  43 + * @param xlId
  44 + * @return
  45 + */
  46 + Iterable<ScheduleRule1Flat> getScheduleRule(Integer xlId);
  47 +
  48 + /**
  49 + * 获取指定线路下,日期与路牌与时刻明细对应的Map。
  50 + * @param xlId 线路id
  51 + * @param fromDate 开始日期
  52 + * @param toDate 结束日期
  53 + * @return 路牌id为key,时刻明细 Collection<TTInfoDetail> 为value
  54 + */
  55 + Map<Date, Multimap<Long, TTInfoDetail>> getGuideboardXlTTInfoDetailMaps(Integer xlId, Date fromDate, Date toDate);
  56 +
  57 + /**
  58 + * 获取指定线路下,车辆配置与车辆信息对应的Map。
  59 + * @param xlId 线路id
  60 + * @return 车辆配置id为key,具体车辆配置信息为value。
  61 + */
  62 + Map<Long, CarConfigInfo> getCarConfigMaps(Integer xlId);
  63 +
  64 + /**
  65 + * 获取指定线路下,人员配置与人员对应的Map。
  66 + * @param xlId 线路id
  67 + * @return 人员配置id为key,具体人员配置信息为value。
  68 + */
  69 + Map<Long, EmployeeConfigInfo> getEmployeeConfigMaps(Integer xlId);
  70 +}
src/main/java/com/bsth/service/schedule/rules/strategy/IStrategyImpl.java
1 -package com.bsth.service.schedule.rules.strategy;  
2 -  
3 -import com.bsth.entity.Line;  
4 -import com.bsth.entity.schedule.CarConfigInfo;  
5 -import com.bsth.entity.schedule.EmployeeConfigInfo;  
6 -import com.bsth.entity.schedule.TTInfo;  
7 -import com.bsth.entity.schedule.TTInfoDetail;  
8 -import com.bsth.entity.schedule.rule.ScheduleRule1Flat;  
9 -import com.bsth.service.LineService;  
10 -import com.bsth.service.schedule.*;  
11 -import com.google.common.collect.ArrayListMultimap;  
12 -import com.google.common.collect.Multimap;  
13 -import org.springframework.beans.factory.annotation.Autowired;  
14 -import org.springframework.stereotype.Service;  
15 -  
16 -import java.util.HashMap;  
17 -import java.util.Iterator;  
18 -import java.util.Map;  
19 -  
20 -/**  
21 - * Created by xu on 16/7/10.  
22 - */  
23 -@Service  
24 -public class IStrategyImpl implements IStrategy {  
25 - @Autowired  
26 - private TTInfoService ttInfoService;  
27 - @Autowired  
28 - private CarConfigInfoService carConfigInfoService;  
29 - @Autowired  
30 - private EmployeeConfigInfoService employeeConfigInfoService;  
31 - @Autowired  
32 - private TTInfoDetailService ttInfoDetailService;  
33 - @Autowired  
34 - private LineService lineService;  
35 - @Autowired  
36 - private ScheduleRule1FlatService scheduleRule1FlatService;  
37 -  
38 - @Override  
39 - public Line getLine(Integer xlId) {  
40 - Line xl = lineService.findById(xlId); // 查找线路具体信息  
41 - return xl;  
42 - }  
43 -  
44 - @Override  
45 - public TTInfo getTTInfo(Integer xlId) {  
46 - // TODO:本来要使用规则判定到底使用哪张时刻表,这里选用第一张  
47 - Map<String, Object> param = new HashMap<>(); // 查询参数  
48 - param.clear();  
49 - param.put("xl.id_eq", xlId); // 线路id  
50 - param.put("isCancel_eq", false); // 没有作废  
51 - param.put("isEnableDisTemplate_eq", true); // 是否启用  
52 - Iterable<TTInfo> ttInfoIterable = ttInfoService.list(param);  
53 - Iterator<TTInfo> ttInfoIterator = ttInfoIterable.iterator();  
54 - if (!ttInfoIterator.hasNext())  
55 - throw new RuntimeException("线路id=" + xlId + ",下没有任何时刻表数据!");  
56 - return ttInfoIterator.next();  
57 - }  
58 -  
59 - @Override  
60 - public Iterable<ScheduleRule1Flat> getScheduleRule(Integer xlId) {  
61 - Map<String, Object> param = new HashMap<>(); // 查询参数  
62 - Line xl = lineService.findById(xlId); // 查找线路具体信息  
63 - param.clear();  
64 - param.put("xl.id_eq", xl.getId());  
65 - Iterable<ScheduleRule1Flat> scheduleRule1FlatIterable = scheduleRule1FlatService.list(param);  
66 - if (!scheduleRule1FlatIterable.iterator().hasNext())  
67 - throw new RuntimeException("线路:" + xl.getName() + " 没有配置规则!");  
68 -  
69 - return scheduleRule1FlatIterable;  
70 - }  
71 -  
72 - @Override  
73 - public Multimap<Long, TTInfoDetail> getGuideboardXlTTInfoDetailMaps(Integer xlId) {  
74 - TTInfo ttInfo = getTTInfo(xlId);  
75 - // 查询参数  
76 - Map<String, Object> param = new HashMap<>();  
77 - param.put("ttinfo.id_eq", ttInfo.getId());  
78 - Iterable<TTInfoDetail> ttInfoDetailIterable = ttInfoDetailService.list(param);  
79 - Iterator<TTInfoDetail> ttInfoDetailIterator = ttInfoDetailIterable.iterator();  
80 - if (!ttInfoDetailIterator.hasNext())  
81 - throw new RuntimeException("时刻表id=" + ttInfo.getId() + ",下没有明细数据!");  
82 -  
83 - Multimap<Long, TTInfoDetail> gtmaps = ArrayListMultimap.create();  
84 - while (ttInfoDetailIterator.hasNext()) {  
85 - TTInfoDetail ttInfoDetail = ttInfoDetailIterator.next();  
86 - gtmaps.put(ttInfoDetail.getLp().getId(), ttInfoDetail);  
87 - }  
88 -  
89 - return gtmaps;  
90 - }  
91 -  
92 - @Override  
93 - public Map<Long, CarConfigInfo> getCarConfigMaps(Integer xlId) {  
94 - // 查询参数  
95 - Map<String, Object> param = new HashMap<>();  
96 - param.put("xl.id_eq", xlId);  
97 - Iterable<CarConfigInfo> carConfigInfoIterable = carConfigInfoService.list(param);  
98 - Iterator<CarConfigInfo> carConfigInfoIterator = carConfigInfoIterable.iterator();  
99 - if (!carConfigInfoIterator.hasNext())  
100 - throw new RuntimeException("线路id=" + xlId + ",下没有车辆配置信息!");  
101 -  
102 - Map<Long, CarConfigInfo> carConfigInfoMap = new HashMap<>();  
103 - while (carConfigInfoIterator.hasNext()) {  
104 - CarConfigInfo carConfigInfo = carConfigInfoIterator.next();  
105 - carConfigInfoMap.put(carConfigInfo.getId(), carConfigInfo);  
106 - }  
107 - return carConfigInfoMap;  
108 - }  
109 -  
110 - @Override  
111 - public Map<Long, EmployeeConfigInfo> getEmployeeConfigMaps(Integer xlId) {  
112 - // 查询参数  
113 - Map<String, Object> param = new HashMap<>();  
114 - param.put("xl.id_eq", xlId);  
115 - Iterable<EmployeeConfigInfo> employeeConfigInfoIterable = employeeConfigInfoService.list(param);  
116 - Iterator<EmployeeConfigInfo> employeeConfigInfoIterator = employeeConfigInfoIterable.iterator();  
117 - if (!employeeConfigInfoIterator.hasNext())  
118 - throw new RuntimeException("线路id=" + xlId + ",下没有人员配置信息!");  
119 -  
120 - Map<Long, EmployeeConfigInfo> employeeConfigInfoMap = new HashMap<>();  
121 - while (employeeConfigInfoIterator.hasNext()) {  
122 - EmployeeConfigInfo employeeConfigInfo = employeeConfigInfoIterator.next();  
123 - employeeConfigInfoMap.put(employeeConfigInfo.getId(), employeeConfigInfo);  
124 - }  
125 - return employeeConfigInfoMap;  
126 - }  
127 -} 1 +package com.bsth.service.schedule.rules.strategy;
  2 +
  3 +import com.bsth.entity.Line;
  4 +import com.bsth.entity.schedule.CarConfigInfo;
  5 +import com.bsth.entity.schedule.EmployeeConfigInfo;
  6 +import com.bsth.entity.schedule.TTInfo;
  7 +import com.bsth.entity.schedule.TTInfoDetail;
  8 +import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
  9 +import com.bsth.service.LineService;
  10 +import com.bsth.service.schedule.*;
  11 +import com.bsth.service.schedule.rules.ttinfo.TTInfoCalcuParam_input;
  12 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResult_output;
  13 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
  14 +import com.bsth.service.schedule.rules.ttinfo.TTInfo_input;
  15 +import com.google.common.collect.ArrayListMultimap;
  16 +import com.google.common.collect.Multimap;
  17 +import org.joda.time.DateTime;
  18 +import org.kie.api.KieBase;
  19 +import org.kie.api.runtime.KieSession;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
  22 +import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.stereotype.Service;
  24 +
  25 +import java.util.*;
  26 +
  27 +/**
  28 + * Created by xu on 16/7/10.
  29 + */
  30 +@Service
  31 +public class IStrategyImpl implements IStrategy {
  32 + @Autowired
  33 + private TTInfoService ttInfoService;
  34 + @Autowired
  35 + private CarConfigInfoService carConfigInfoService;
  36 + @Autowired
  37 + private EmployeeConfigInfoService employeeConfigInfoService;
  38 + @Autowired
  39 + private TTInfoDetailService ttInfoDetailService;
  40 + @Autowired
  41 + private LineService lineService;
  42 + @Autowired
  43 + private ScheduleRule1FlatService scheduleRule1FlatService;
  44 +
  45 + /** 日志记录器 */
  46 + private Logger logger = LoggerFactory.getLogger(IStrategyImpl.class);
  47 +
  48 + @Autowired
  49 + private KieBase kieBase;
  50 +
  51 + @Override
  52 + public Line getLine(Integer xlId) {
  53 + Line xl = lineService.findById(xlId); // 查找线路具体信息
  54 + return xl;
  55 + }
  56 +
  57 + @Override
  58 + public List<TTInfo> getTTInfo(Integer xlId) {
  59 + // 查询参数
  60 + Map<String, Object> param = new HashMap<>();
  61 + param.put("xl.id_eq", xlId); // 线路Id
  62 + param.put("isCancel_eq", false); // 作废的过滤掉
  63 + Iterator<TTInfo> ttInfoIterator = ttInfoService.list(param).iterator();
  64 + if (!ttInfoIterator.hasNext()) {
  65 + throw new RuntimeException("线路id=" + xlId + " 没有时刻表!");
  66 + }
  67 + List<TTInfo> ttInfos = new ArrayList<>();
  68 + while (ttInfoIterator.hasNext()) {
  69 + TTInfo ttInfo = ttInfoIterator.next();
  70 + ttInfos.add(ttInfo);
  71 + }
  72 + return ttInfos;
  73 + }
  74 +
  75 + @Override
  76 + public List<TTInfoDetail> getTTInfoDetail(Integer xlId) {
  77 + List<TTInfoDetail> ttInfoDetails = new ArrayList<>();
  78 +
  79 + List<TTInfo> ttInfos = getTTInfo(xlId);
  80 + Map<String, Object> param = new HashMap<>();
  81 + for (TTInfo ttInfo : ttInfos) {
  82 + param.clear();
  83 + param.put("ttinfo.id_eq", ttInfo.getId());
  84 + Iterator<TTInfoDetail> ttInfoDetailIterator = ttInfoDetailService.list(param).iterator();
  85 + while (ttInfoDetailIterator.hasNext()) {
  86 + ttInfoDetails.add(ttInfoDetailIterator.next());
  87 + }
  88 + }
  89 +
  90 + return ttInfoDetails;
  91 + }
  92 +
  93 + @Override
  94 + public Iterable<ScheduleRule1Flat> getScheduleRule(Integer xlId) {
  95 + Map<String, Object> param = new HashMap<>(); // 查询参数
  96 + Line xl = lineService.findById(xlId); // 查找线路具体信息
  97 + param.clear();
  98 + param.put("xl.id_eq", xl.getId());
  99 + Iterable<ScheduleRule1Flat> scheduleRule1FlatIterable = scheduleRule1FlatService.list(param);
  100 + if (!scheduleRule1FlatIterable.iterator().hasNext())
  101 + throw new RuntimeException("线路:" + xl.getName() + " 没有配置规则!");
  102 +
  103 + return scheduleRule1FlatIterable;
  104 + }
  105 +
  106 + @Override
  107 + public Map<Date, Multimap<Long, TTInfoDetail>> getGuideboardXlTTInfoDetailMaps(
  108 + Integer xlId, Date fromDate, Date toDate) {
  109 + // 获取线路的所有时刻表
  110 + List<TTInfo> ttInfos = getTTInfo(xlId);
  111 +
  112 + // 执行规则,判定每天使用的时刻表
  113 + KieSession session = kieBase.newKieSession();
  114 +
  115 + session.setGlobal("log", logger);
  116 + TTInfoResults_output ttInfoResults_output = new TTInfoResults_output();
  117 + session.setGlobal("results", ttInfoResults_output);
  118 +
  119 + TTInfoCalcuParam_input ttInfoCalcuParam_input = new TTInfoCalcuParam_input(
  120 + new DateTime(fromDate), new DateTime(toDate), String.valueOf(xlId));
  121 + session.insert(ttInfoCalcuParam_input);
  122 + for (TTInfo ttInfo : ttInfos) {
  123 + TTInfo_input ttInfo_input = new TTInfo_input(ttInfo);
  124 + session.insert(ttInfo_input);
  125 + }
  126 +
  127 + session.fireAllRules();
  128 + session.dispose();
  129 +
  130 + // 获取ttinfoDetail
  131 + List<TTInfoDetail> ttInfoDetails = getTTInfoDetail(xlId);
  132 +
  133 + // 规则输出结果
  134 + Multimap<DateTime, TTInfoResult_output> outputMultimap =
  135 + ttInfoResults_output.getResults().get(String.valueOf(xlId));
  136 + // return结果输出
  137 + Map<Date, Multimap<Long, TTInfoDetail>> ttInfoDetailMultimap = new HashMap<>();
  138 +
  139 + Map<String, Object> param = new HashMap<>();
  140 + for (DateTime dateTime : outputMultimap.keySet()) {
  141 + Collection<TTInfoResult_output> ttInfoResult_outputs = outputMultimap.get(dateTime);
  142 + // 如果有多个,使用第一个
  143 + Iterator<TTInfoResult_output> ttInfoResult_outputIterator = ttInfoResult_outputs.iterator();
  144 + if (ttInfoResult_outputIterator.hasNext()) {
  145 + // 同一天,多张时刻表只取第一张
  146 + TTInfoResult_output ttInfoResult_output = ttInfoResult_outputIterator.next();
  147 + // 查找时刻表明细
  148 + Multimap<Long, TTInfoDetail> ttinfodetailMap2 = ArrayListMultimap.create();
  149 + for (TTInfoDetail ttInfoDetail : ttInfoDetails) {
  150 + if (ttInfoDetail.getTtinfo().getId() == Long.valueOf(ttInfoResult_output.getTtInfoId())) {
  151 + ttinfodetailMap2.put(ttInfoDetail.getLp().getId(), ttInfoDetail);
  152 + }
  153 + }
  154 +
  155 + ttInfoDetailMultimap.put(dateTime.toDate(), ttinfodetailMap2);
  156 + }
  157 + }
  158 +
  159 + return ttInfoDetailMultimap;
  160 + }
  161 +
  162 + @Override
  163 + public Map<Long, CarConfigInfo> getCarConfigMaps(Integer xlId) {
  164 + // 查询参数
  165 + Map<String, Object> param = new HashMap<>();
  166 + param.put("xl.id_eq", xlId);
  167 + Iterable<CarConfigInfo> carConfigInfoIterable = carConfigInfoService.list(param);
  168 + Iterator<CarConfigInfo> carConfigInfoIterator = carConfigInfoIterable.iterator();
  169 + if (!carConfigInfoIterator.hasNext())
  170 + throw new RuntimeException("线路id=" + xlId + ",下没有车辆配置信息!");
  171 +
  172 + Map<Long, CarConfigInfo> carConfigInfoMap = new HashMap<>();
  173 + while (carConfigInfoIterator.hasNext()) {
  174 + CarConfigInfo carConfigInfo = carConfigInfoIterator.next();
  175 + carConfigInfoMap.put(carConfigInfo.getId(), carConfigInfo);
  176 + }
  177 + return carConfigInfoMap;
  178 + }
  179 +
  180 + @Override
  181 + public Map<Long, EmployeeConfigInfo> getEmployeeConfigMaps(Integer xlId) {
  182 + // 查询参数
  183 + Map<String, Object> param = new HashMap<>();
  184 + param.put("xl.id_eq", xlId);
  185 + Iterable<EmployeeConfigInfo> employeeConfigInfoIterable = employeeConfigInfoService.list(param);
  186 + Iterator<EmployeeConfigInfo> employeeConfigInfoIterator = employeeConfigInfoIterable.iterator();
  187 + if (!employeeConfigInfoIterator.hasNext())
  188 + throw new RuntimeException("线路id=" + xlId + ",下没有人员配置信息!");
  189 +
  190 + Map<Long, EmployeeConfigInfo> employeeConfigInfoMap = new HashMap<>();
  191 + while (employeeConfigInfoIterator.hasNext()) {
  192 + EmployeeConfigInfo employeeConfigInfo = employeeConfigInfoIterator.next();
  193 + employeeConfigInfoMap.put(employeeConfigInfo.getId(), employeeConfigInfo);
  194 + }
  195 + return employeeConfigInfoMap;
  196 + }
  197 +}
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfoCalcuParam_input.java 0 → 100644
  1 +package com.bsth.service.schedule.rules.ttinfo;
  2 +
  3 +import org.joda.time.DateTime;
  4 +
  5 +/**
  6 + * 时刻表计算参数_输入。
  7 + */
  8 +public class TTInfoCalcuParam_input {
  9 + /** 开始计算日期 */
  10 + private DateTime fromDate;
  11 + /** 结束计算日期 */
  12 + private DateTime toDate;
  13 + /** 线路Id */
  14 + private String xlId;
  15 +
  16 + public TTInfoCalcuParam_input() {}
  17 +
  18 + public TTInfoCalcuParam_input(DateTime fromDate, DateTime toDate, String xlId) {
  19 + this.fromDate = fromDate;
  20 + this.toDate = toDate;
  21 + this.xlId = xlId;
  22 + }
  23 +
  24 + public DateTime getFromDate() {
  25 + return fromDate;
  26 + }
  27 +
  28 + public void setFromDate(DateTime fromDate) {
  29 + this.fromDate = fromDate;
  30 + }
  31 +
  32 + public DateTime getToDate() {
  33 + return toDate;
  34 + }
  35 +
  36 + public void setToDate(DateTime toDate) {
  37 + this.toDate = toDate;
  38 + }
  39 +
  40 + public String getXlId() {
  41 + return xlId;
  42 + }
  43 +
  44 + public void setXlId(String xlId) {
  45 + this.xlId = xlId;
  46 + }
  47 +}
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfoResult_output.java 0 → 100644
  1 +package com.bsth.service.schedule.rules.ttinfo;
  2 +
  3 +import org.joda.time.DateTime;
  4 +
  5 +/**
  6 + * 时刻表选择规则出的结果_输出。
  7 + */
  8 +public class TTInfoResult_output {
  9 + /** 具体日期 */
  10 + private DateTime dateTime;
  11 + /** 时刻表Id */
  12 + private String ttInfoId;
  13 + /** 线路Id */
  14 + private String xlId;
  15 +
  16 + public DateTime getDateTime() {
  17 + return dateTime;
  18 + }
  19 +
  20 + public void setDateTime(DateTime dateTime) {
  21 + this.dateTime = dateTime;
  22 + }
  23 +
  24 + public String getTtInfoId() {
  25 + return ttInfoId;
  26 + }
  27 +
  28 + public void setTtInfoId(String ttInfoId) {
  29 + this.ttInfoId = ttInfoId;
  30 + }
  31 +
  32 + public String getXlId() {
  33 + return xlId;
  34 + }
  35 +
  36 + public void setXlId(String xlId) {
  37 + this.xlId = xlId;
  38 + }
  39 +
  40 + @Override
  41 + public String toString() {
  42 + return String.format(
  43 + "<日期=%s 线路id=%s 时刻表id=%s>\n",
  44 + dateTime.toString("yyyy-MM-dd"),
  45 + xlId,
  46 + ttInfoId);
  47 + }
  48 +}
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfoResults_output.java 0 → 100644
  1 +package com.bsth.service.schedule.rules.ttinfo;
  2 +
  3 +import com.google.common.collect.ArrayListMultimap;
  4 +import com.google.common.collect.Multimap;
  5 +import org.joda.time.DateTime;
  6 +
  7 +import java.util.HashMap;
  8 +import java.util.List;
  9 +import java.util.Map;
  10 +
  11 +/**
  12 + * 输出结果集合。
  13 + */
  14 +public class TTInfoResults_output {
  15 +
  16 + /** 输出列表,key为线路id,value是key为日期,value为排序的时刻表output列表 */
  17 + private Map<String, Multimap<DateTime, TTInfoResult_output>> results = new HashMap<>();
  18 +
  19 + public Map<String, Multimap<DateTime, TTInfoResult_output>> getResults() {
  20 + return results;
  21 + }
  22 +
  23 + public void setResults(Map<String, Multimap<DateTime, TTInfoResult_output>> results) {
  24 + this.results = results;
  25 + }
  26 +
  27 + public void addXlTTInfos(String xlid, DateTime dt, List<TTInfo_input> ttInfo_inputList) {
  28 + Multimap<DateTime, TTInfoResult_output> map;
  29 + if (results.get(xlid) == null) {
  30 + map = ArrayListMultimap.create();
  31 + results.put(xlid, map);
  32 + } else {
  33 + map = results.get(xlid);
  34 + }
  35 +
  36 + for (TTInfo_input ttInfo_input : ttInfo_inputList) {
  37 + TTInfoResult_output ttInfoResult_output = new TTInfoResult_output();
  38 + ttInfoResult_output.setDateTime(dt);
  39 + ttInfoResult_output.setTtInfoId(ttInfo_input.getTtInfoId());
  40 + ttInfoResult_output.setXlId(xlid);
  41 + map.put(dt, ttInfoResult_output);
  42 + }
  43 + }
  44 +
  45 + /**
  46 + * 输出计算后的时刻表
  47 + * @return
  48 + */
  49 + public String showTTInfoDesc1() {
  50 + StringBuilder str = new StringBuilder();
  51 + for (String key : results.keySet()) {
  52 + str.append("线路id=" + key);
  53 + str.append("\n");
  54 + str.append("时刻表=" + results.get(key));
  55 + str.append("\n");
  56 + }
  57 +
  58 + return str.toString();
  59 + }
  60 +
  61 +}
src/main/java/com/bsth/service/schedule/rules/ttinfo/TTInfo_input.java 0 → 100644
  1 +package com.bsth.service.schedule.rules.ttinfo;
  2 +
  3 +import com.bsth.entity.schedule.TTInfo;
  4 +import org.joda.time.DateTime;
  5 +import org.joda.time.format.DateTimeFormat;
  6 +
  7 +import java.util.ArrayList;
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * 时刻表_输入
  12 + */
  13 +public class TTInfo_input implements Comparable<TTInfo_input> {
  14 + /** 时刻表id */
  15 + private String ttInfoId;
  16 + /** 线路Id */
  17 + private String xlId;
  18 + /** 周一到周日是否启用 */
  19 + private List<Boolean> weekdays = new ArrayList<>();
  20 + /** 特殊节假日 */
  21 + private List<DateTime> specialDays = new ArrayList<>();
  22 + /** 最新修改时间 */
  23 + private DateTime updateDate;
  24 + /** 是否启用 */
  25 + private Boolean isEnable;
  26 + /** 启用日期 */
  27 + private DateTime qyDate;
  28 +
  29 + public TTInfo_input() {
  30 +
  31 + }
  32 +
  33 + @Override
  34 + public int compareTo(TTInfo_input ttInfo_input) {
  35 + if (ttInfo_input != null) {
  36 + if (ttInfo_input.updateDate != null && this.updateDate != null)
  37 + return - this.updateDate.compareTo(ttInfo_input.updateDate);
  38 + }
  39 + return -1;
  40 + }
  41 +
  42 + public TTInfo_input(TTInfo ttInfo) {
  43 + this.ttInfoId = String.valueOf(ttInfo.getId());
  44 + this.xlId = String.valueOf(ttInfo.getXl().getId());
  45 + String[] days = ttInfo.getRule_days().split(",");
  46 + System.out.println(days.length);
  47 + for (int i = 0; i < 7; i++) {
  48 + if ("1".equals(days[i])) {
  49 + weekdays.add(true);
  50 + } else {
  51 + weekdays.add(false);
  52 + }
  53 + }
  54 + String[] sdays = ttInfo.getSpecial_days().split(",");
  55 + for (int i = 0; i < sdays.length; i++) {
  56 + specialDays.add(DateTimeFormat.forPattern("yyyy-MM-dd").
  57 + parseDateTime(sdays[i]));
  58 + }
  59 + this.updateDate = new DateTime(ttInfo.getUpdateDate());
  60 + this.isEnable = ttInfo.getIsEnableDisTemplate();
  61 + this.qyDate = new DateTime(ttInfo.getQyrq());
  62 +
  63 + }
  64 +
  65 + public String getTtInfoId() {
  66 + return ttInfoId;
  67 + }
  68 +
  69 + public void setTtInfoId(String ttInfoId) {
  70 + this.ttInfoId = ttInfoId;
  71 + }
  72 +
  73 + public String getXlId() {
  74 + return xlId;
  75 + }
  76 +
  77 + public void setXlId(String xlId) {
  78 + this.xlId = xlId;
  79 + }
  80 +
  81 + public List<Boolean> getWeekdays() {
  82 + return weekdays;
  83 + }
  84 +
  85 + public void setWeekdays(List<Boolean> weekdays) {
  86 + this.weekdays = weekdays;
  87 + }
  88 +
  89 + public List<DateTime> getSpecialDays() {
  90 + return specialDays;
  91 + }
  92 +
  93 + public void setSpecialDays(List<DateTime> specialDays) {
  94 + this.specialDays = specialDays;
  95 + }
  96 +
  97 + public DateTime getUpdateDate() {
  98 + return updateDate;
  99 + }
  100 +
  101 + public void setUpdateDate(DateTime updateDate) {
  102 + this.updateDate = updateDate;
  103 + }
  104 +
  105 + public Boolean getIsEnable() {
  106 + return isEnable;
  107 + }
  108 +
  109 + public void setIsEnable(Boolean isEnable) {
  110 + this.isEnable = isEnable;
  111 + }
  112 +
  113 + public DateTime getQyDate() {
  114 + return qyDate;
  115 + }
  116 +
  117 + public void setQyDate(DateTime qyDate) {
  118 + this.qyDate = qyDate;
  119 + }
  120 +}
src/main/java/com/bsth/service/schedule/rules/ttinfo/readme.txt 0 → 100644
  1 +时刻表选择规则,每天的时刻表都不一样
0 \ No newline at end of file 2 \ No newline at end of file
src/main/resources/application.properties
@@ -13,3 +13,6 @@ multipart.maxRequestSize = -1 @@ -13,3 +13,6 @@ multipart.maxRequestSize = -1
13 13
14 server.compression.enabled=true 14 server.compression.enabled=true
15 server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript 15 server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript
  16 +
  17 +# batch insert
  18 +hibernate.jdbc.batch_size = 50
src/main/resources/rules/shiftloop.drl
1 -package com.bsth.service.schedule; 1 +package com.bsth.service.schedule.shiftloop;
2 2
3 import org.joda.time.*; 3 import org.joda.time.*;
4 import java.util.*; 4 import java.util.*;
@@ -15,7 +15,7 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; @@ -15,7 +15,7 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
15 //------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------// 15 //------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------//
16 16
17 declare Calcu_days_result 17 declare Calcu_days_result
18 - ruleId : Long // 规则Id 18 + ruleId : String // 规则Id
19 qyrq_days : Integer // 开始日期离启用日期的天数 19 qyrq_days : Integer // 开始日期离启用日期的天数
20 sdays : Integer // 总共需要排班的天数 20 sdays : Integer // 总共需要排班的天数
21 calcu_start_date : DateTime // 开始计算日期 21 calcu_start_date : DateTime // 开始计算日期
@@ -104,18 +104,18 @@ end @@ -104,18 +104,18 @@ end
104 104
105 //----------------------- 路牌范围循环计算 ------------------------// 105 //----------------------- 路牌范围循环计算 ------------------------//
106 declare Calcu_guideboard_index_result 106 declare Calcu_guideboard_index_result
107 - ruleId : Long // 规则Id 107 + ruleId : String // 规则Id
108 calcu_index : Integer // 计算之后的起始索引 108 calcu_index : Integer // 计算之后的起始索引
109 end 109 end
110 declare Calcu_guideboard_index_param_1 110 declare Calcu_guideboard_index_param_1
111 - ruleId : Long // 规则Id 111 + ruleId : String // 规则Id
112 oindex : Integer // 原始起始索引 112 oindex : Integer // 原始起始索引
113 range_size : Integer // 范围大小 113 range_size : Integer // 范围大小
114 temp : Integer // 原始起始索引距离最后一个索引的大小 114 temp : Integer // 原始起始索引距离最后一个索引的大小
115 days_temp : Integer // 开始日期离启用日期的天数 - temp 115 days_temp : Integer // 开始日期离启用日期的天数 - temp
116 end 116 end
117 declare Calcu_guideboard_index_param_2 117 declare Calcu_guideboard_index_param_2
118 - ruleId : Long // 规则Id 118 + ruleId : String // 规则Id
119 s_value : Integer // 商 119 s_value : Integer // 商
120 y_value : Integer // 余 120 y_value : Integer // 余
121 end 121 end
@@ -217,18 +217,18 @@ end @@ -217,18 +217,18 @@ end
217 217
218 //----------------------- 人员范围循环计算 ------------------------// 218 //----------------------- 人员范围循环计算 ------------------------//
219 declare Calcu_employee_index_result 219 declare Calcu_employee_index_result
220 - ruleId : Long // 规则Id 220 + ruleId : String // 规则Id
221 calcu_index : Integer // 计算之后的起始索引 221 calcu_index : Integer // 计算之后的起始索引
222 end 222 end
223 declare Calcu_employee_index_param_1 223 declare Calcu_employee_index_param_1
224 - ruleId : Long // 规则Id 224 + ruleId : String // 规则Id
225 oindex : Integer // 原始起始索引 225 oindex : Integer // 原始起始索引
226 range_size : Integer // 范围大小 226 range_size : Integer // 范围大小
227 temp : Integer // 原始起始索引距离最后一个索引的大小 227 temp : Integer // 原始起始索引距离最后一个索引的大小
228 days_temp : Integer // 开始日期离启用日期的天数 - temp 228 days_temp : Integer // 开始日期离启用日期的天数 - temp
229 end 229 end
230 declare Calcu_employee_index_param_2 230 declare Calcu_employee_index_param_2
231 - ruleId : Long // 规则Id 231 + ruleId : String // 规则Id
232 s_value : Integer // 商 232 s_value : Integer // 商
233 y_value : Integer // 余 233 y_value : Integer // 余
234 end 234 end
@@ -332,7 +332,7 @@ end @@ -332,7 +332,7 @@ end
332 332
333 //----------------------- 路牌范围循环计算 ------------------------// 333 //----------------------- 路牌范围循环计算 ------------------------//
334 declare Calcu_guideboard_range_loop_result 334 declare Calcu_guideboard_range_loop_result
335 - ruleId : Long // 规则Id 335 + ruleId : String // 规则Id
336 firstLoopSize : Integer // 初始的范围循环个数 336 firstLoopSize : Integer // 初始的范围循环个数
337 middelLoopCount : Integer // 中间的范围循环次数 337 middelLoopCount : Integer // 中间的范围循环次数
338 rangeSize : Integer // 范围大小 338 rangeSize : Integer // 范围大小
@@ -340,7 +340,7 @@ declare Calcu_guideboard_range_loop_result @@ -340,7 +340,7 @@ declare Calcu_guideboard_range_loop_result
340 end 340 end
341 341
342 declare Calcu_guideboard_range_loop_param 342 declare Calcu_guideboard_range_loop_param
343 - ruleId : Long // 规则Id 343 + ruleId : String // 规则Id
344 temp : Integer // 起始索引距离最后一个索引的大小 344 temp : Integer // 起始索引距离最后一个索引的大小
345 sdays : Integer // 总共需要排班的天数 345 sdays : Integer // 总共需要排班的天数
346 end 346 end
@@ -409,7 +409,7 @@ end @@ -409,7 +409,7 @@ end
409 409
410 //----------------------- 人员范围循环计算 ------------------------// 410 //----------------------- 人员范围循环计算 ------------------------//
411 declare Calcu_employee_range_loop_result 411 declare Calcu_employee_range_loop_result
412 - ruleId : Long // 规则Id 412 + ruleId : String // 规则Id
413 firstLoopSize : Integer // 初始的范围循环个数 413 firstLoopSize : Integer // 初始的范围循环个数
414 middelLoopCount : Integer // 中间的范围循环次数 414 middelLoopCount : Integer // 中间的范围循环次数
415 rangeSize : Integer // 范围大小 415 rangeSize : Integer // 范围大小
@@ -417,7 +417,7 @@ declare Calcu_employee_range_loop_result @@ -417,7 +417,7 @@ declare Calcu_employee_range_loop_result
417 end 417 end
418 418
419 declare Calcu_employee_range_loop_param 419 declare Calcu_employee_range_loop_param
420 - ruleId : Long // 规则Id 420 + ruleId : String // 规则Id
421 temp : Integer // 起始索引距离最后一个索引的大小 421 temp : Integer // 起始索引距离最后一个索引的大小
422 sdays : Integer // 总共需要排班的天数 422 sdays : Integer // 总共需要排班的天数
423 end 423 end
@@ -489,7 +489,7 @@ end @@ -489,7 +489,7 @@ end
489 489
490 //----------------------- 路牌范围循环计算 ------------------------// 490 //----------------------- 路牌范围循环计算 ------------------------//
491 declare Calcu_loop_guideboard_result 491 declare Calcu_loop_guideboard_result
492 - ruleId : Long // 规则id 492 + ruleId : String // 规则id
493 go_list : List // 路牌循环的列表 493 go_list : List // 路牌循环的列表
494 end 494 end
495 495
@@ -553,7 +553,7 @@ end @@ -553,7 +553,7 @@ end
553 553
554 //----------------------- 人员范围循环计算 ------------------------// 554 //----------------------- 人员范围循环计算 ------------------------//
555 declare Calcu_loop_employee_result 555 declare Calcu_loop_employee_result
556 - ruleId : Long // 规则id 556 + ruleId : String // 规则id
557 eo_list : List // 人员循环的列表 557 eo_list : List // 人员循环的列表
558 end 558 end
559 559
src/main/resources/rules/ttinfo.drl 0 → 100644
  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 +
  11 +import org.slf4j.Logger;
  12 +
  13 +// 全局日志
  14 +global Logger log;
  15 +// return输出
  16 +global TTInfoResults_output results
  17 +
  18 +
  19 +/*
  20 + TODO:规则说明,以后待说明
  21 +*/
  22 +
  23 +//----------------- 第一阶段、计算规则准备数据(天数)----------------//
  24 +
  25 +declare Calcu_days_result
  26 + calcu_day : Integer // 该计算第几天
  27 + calcu_weekday : Integer // 星期几(1到7)
  28 + calcu_date : DateTime // 该计算的具体日期
  29 + calcu_days : Integer // 总共需要计算的天数
  30 + calcu_start_date : DateTime // 开始计算日期
  31 + calcu_end_date : DateTime // 结束计算日期
  32 + xlId : String // 线路Id
  33 +end
  34 +
  35 +rule "calcu_days"
  36 + when
  37 + TTInfoCalcuParam_input($fromDate : fromDate, $toDate : toDate, $fromDate.isBefore($toDate), $xlId : xlId)
  38 + then
  39 + // 构造Calcu_days_result对象,进行下一阶段计算
  40 + Calcu_days_result cdr = new Calcu_days_result();
  41 + Period p = new Period($fromDate, $toDate, PeriodType.days());
  42 +
  43 + cdr.setCalcu_day(1);
  44 + cdr.setCalcu_date($fromDate);
  45 + cdr.setCalcu_days(p.getDays() + 1);
  46 + cdr.setCalcu_weekday($fromDate.getDayOfWeek());
  47 + cdr.setCalcu_start_date($fromDate);
  48 + cdr.setCalcu_end_date(($toDate));
  49 + cdr.setXlId($xlId);
  50 +
  51 + log.info("总共需要计算的天数 calcu_days={} 之后的计算从第1天开始 ", p.getDays() + 1);
  52 +
  53 + insert(cdr); // 插入fact数据,进入下一个阶段
  54 +end
  55 +
  56 +//----------------- 第二阶段、判定时刻表是否启用 ----------------//
  57 +
  58 +declare Calcu_ttinfo_enable_result
  59 + xlId : String // 线路id
  60 + ttInfo_input_list : ArrayList // 可用时刻表列表
  61 + calcu_date : DateTime // 计算日期
  62 +end
  63 +
  64 +rule "calcu_ttinfo_enable"
  65 + salience 900
  66 + when
  67 + $calcu_days_result : Calcu_days_result($calcu_date : calcu_date, calcu_day <= calcu_days, $xlId : xlId)
  68 + $ttInfo_input_list : ArrayList(size >= 1) from collect (TTInfo_input(xlId == $xlId, isEnable == true))
  69 + then
  70 + // 构造Calcu_ttinfo_enable_result对象,进行下一步计算
  71 + Calcu_ttinfo_enable_result cter = new Calcu_ttinfo_enable_result();
  72 + cter.setXlId($xlId);
  73 + cter.setTtInfo_input_list($ttInfo_input_list);
  74 + cter.setCalcu_date($calcu_date);
  75 +
  76 + log.info("启用的时刻表:xlId={} 时刻表个数={}", $xlId, $ttInfo_input_list.size());
  77 +
  78 + insert (cter);
  79 +
  80 +end
  81 +
  82 +//----------------- 第三阶段、时刻表的日期匹配 -------------------//
  83 +
  84 +rule "calcu_ttinfo_special_day" // 特殊日期匹配
  85 + salience 800
  86 + when
  87 + $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list)
  88 + $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day)
  89 + $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays contains $calcu_date) from $ttInfo_input_list)
  90 + then
  91 + // 更新Calcu_days_result对象
  92 + int new_calcu_day = $calcu_day + 1;
  93 + $calcu_days_result.setCalcu_day(new_calcu_day);
  94 + DateTime new_calcu_date = $calcu_date.plusDays(1);
  95 + $calcu_days_result.setCalcu_date(new_calcu_date);
  96 + $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek());
  97 +
  98 + log.info("启用特殊日期时刻表:xlId={} 时刻表个数={} 特殊日期={}", $xlId, $ttinfolist.size(), $calcu_date);
  99 +
  100 + // $ttinfolist按时间倒排序,result输出
  101 + Collections.sort($ttinfolist);
  102 + results.addXlTTInfos($xlId, $calcu_date, $ttinfolist);
  103 +
  104 + update($calcu_days_result);
  105 +end
  106 +
  107 +rule "calcu_ttinfo_normal_day" // 平日匹配
  108 + salience 700
  109 + when
  110 + $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list)
  111 + $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday)
  112 + $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == true) from $ttInfo_input_list)
  113 + then
  114 + // 更新Calcu_days_result对象
  115 + int new_calcu_day = $calcu_day + 1;
  116 + $calcu_days_result.setCalcu_day(new_calcu_day);
  117 + DateTime new_calcu_date = $calcu_date.plusDays(1);
  118 + $calcu_days_result.setCalcu_date(new_calcu_date);
  119 + $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek());
  120 +
  121 + log.info("启用常规日期时刻表:xlId={} 时刻表个数={} 常规日期={} 星期几={}", $xlId, $ttinfolist.size(), $calcu_date, $calcu_weekday);
  122 +
  123 + // $ttinfolist按时间倒排序,result输出
  124 + Collections.sort($ttinfolist);
  125 + results.addXlTTInfos($xlId, $calcu_date, $ttinfolist);
  126 +
  127 + update($calcu_days_result);
  128 +end
  129 +
  130 +rule "calcu_ttinfo_other_day" // 都没有的情况下,匹配
  131 + salience 500
  132 + when
  133 + $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list)
  134 + $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday)
  135 + $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == false) from $ttInfo_input_list)
  136 + then
  137 + // 更新Calcu_days_result对象
  138 + int new_calcu_day = $calcu_day + 1;
  139 + $calcu_days_result.setCalcu_day(new_calcu_day);
  140 + DateTime new_calcu_date = $calcu_date.plusDays(1);
  141 + $calcu_days_result.setCalcu_date(new_calcu_date);
  142 + $calcu_days_result.setCalcu_weekday(new_calcu_date.getDayOfWeek());
  143 +
  144 + log.info("启用默认日期时刻表:xlId={} 时刻表个数={} 常规日期={} 星期几={}", $xlId, $ttinfolist.size(), $calcu_date, $calcu_weekday);
  145 +
  146 + // $ttinfolist按时间倒排序,result输出
  147 + Collections.sort($ttinfolist);
  148 + results.addXlTTInfos($xlId, $calcu_date, $ttinfolist);
  149 +
  150 + update($calcu_days_result);
  151 +
  152 +end
0 \ No newline at end of file 153 \ No newline at end of file
src/test/java/com/bsth/service/schedule/rules/DroolsRulesTest.java
@@ -4,11 +4,16 @@ import com.bsth.Application; @@ -4,11 +4,16 @@ import com.bsth.Application;
4 import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input; 4 import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
5 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; 5 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
6 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input; 6 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
  7 +import com.bsth.service.schedule.rules.ttinfo.TTInfoCalcuParam_input;
  8 +import com.bsth.service.schedule.rules.ttinfo.TTInfoResults_output;
  9 +import com.bsth.service.schedule.rules.ttinfo.TTInfo_input;
7 import org.joda.time.DateTime; 10 import org.joda.time.DateTime;
8 import org.junit.Test; 11 import org.junit.Test;
9 import org.junit.runner.RunWith; 12 import org.junit.runner.RunWith;
10 import org.kie.api.KieBase; 13 import org.kie.api.KieBase;
11 import org.kie.api.runtime.KieSession; 14 import org.kie.api.runtime.KieSession;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.boot.test.SpringApplicationConfiguration; 18 import org.springframework.boot.test.SpringApplicationConfiguration;
14 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 19 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -21,10 +26,13 @@ import java.util.List; @@ -21,10 +26,13 @@ import java.util.List;
21 @SpringApplicationConfiguration(classes = {Application.class}) 26 @SpringApplicationConfiguration(classes = {Application.class})
22 public class DroolsRulesTest { 27 public class DroolsRulesTest {
23 28
  29 + /** 日志记录器 */
  30 + private final static Logger logger = LoggerFactory.getLogger(DroolsRulesTest.class);
  31 +
24 @Autowired 32 @Autowired
25 private KieBase kieBase; 33 private KieBase kieBase;
26 34
27 - @Test 35 +// @Test
28 public void helloWorldDrlTest() throws Exception { 36 public void helloWorldDrlTest() throws Exception {
29 // 1、创建session,内部配置的是stateful 37 // 1、创建session,内部配置的是stateful
30 KieSession session = kieBase.newKieSession(); 38 KieSession session = kieBase.newKieSession();
@@ -51,6 +59,81 @@ public class DroolsRulesTest { @@ -51,6 +59,81 @@ public class DroolsRulesTest {
51 } 59 }
52 60
53 @Test 61 @Test
  62 + public void ttinfoDrlTest() throws Exception {
  63 + logger.info("------------ttinfoDrlTest 测试---------------");
  64 +
  65 + // 1、创建session,内部配置的是stateful
  66 + KieSession session = kieBase.newKieSession();
  67 +
  68 + // 1.1 设置gloable对象,在drl中通过别人使用
  69 + session.setGlobal("log", logger);
  70 + TTInfoResults_output ttInfoResults_output = new TTInfoResults_output();
  71 + session.setGlobal("results", ttInfoResults_output);
  72 +
  73 + // 1.2 可以设置一些监听器,再议
  74 +
  75 + // 2、创建fact对象
  76 + TTInfoCalcuParam_input ttInfoCalcuParam_input = new TTInfoCalcuParam_input(
  77 + new DateTime(2016, 8, 1, 0, 0),
  78 + new DateTime(2016, 8, 10, 0, 0),
  79 + "1"
  80 + );
  81 +
  82 +
  83 + TTInfo_input ttInfo_input1 = new TTInfo_input();
  84 + ttInfo_input1.setTtInfoId("1");
  85 + ttInfo_input1.setXlId("1");
  86 + ttInfo_input1.setWeekdays(Arrays.asList(true, true, true, true, true, false, false));
  87 + ttInfo_input1.getSpecialDays().add(new DateTime(2016, 8, 1, 0, 0));
  88 + ttInfo_input1.setUpdateDate(new DateTime(2016, 1, 1, 0, 0));
  89 + ttInfo_input1.setIsEnable(true);
  90 + ttInfo_input1.setQyDate(new DateTime(2016, 1, 1, 0, 0));
  91 +
  92 + TTInfo_input ttInfo_input1_2 = new TTInfo_input();
  93 + ttInfo_input1_2.setTtInfoId("2");
  94 + ttInfo_input1_2.setXlId("1");
  95 + ttInfo_input1_2.setWeekdays(Arrays.asList(true, false, false, false, false, true, false));
  96 + ttInfo_input1_2.getSpecialDays().add(new DateTime(2016, 8, 11, 0, 0));
  97 + ttInfo_input1_2.setUpdateDate(new DateTime(2015, 2, 1, 0, 0));
  98 + ttInfo_input1_2.setIsEnable(true);
  99 + ttInfo_input1_2.setQyDate(new DateTime(2016, 1, 1, 0, 0));
  100 +
  101 +
  102 + TTInfoCalcuParam_input ttInfoCalcuParam_inpu2 = new TTInfoCalcuParam_input(
  103 + new DateTime(2016, 8, 1, 0, 0),
  104 + new DateTime(2016, 8, 10, 0, 0),
  105 + "2"
  106 + );
  107 +
  108 + TTInfo_input ttInfo_input2 = new TTInfo_input();
  109 + ttInfo_input2.setTtInfoId("2");
  110 + ttInfo_input2.setXlId("2");
  111 + ttInfo_input2.setWeekdays(Arrays.asList(true, false, false, false, false, true, false));
  112 + ttInfo_input2.getSpecialDays().add(new DateTime(2016, 8, 11, 0, 0));
  113 + ttInfo_input2.setUpdateDate(new DateTime(2016, 1, 1, 0, 0));
  114 + ttInfo_input2.setIsEnable(true);
  115 + ttInfo_input2.setQyDate(new DateTime(2016, 1, 1, 0, 0));
  116 +
  117 + session.insert(ttInfoCalcuParam_input);
  118 + session.insert(ttInfo_input1);
  119 + session.insert(ttInfo_input1_2);
  120 + session.insert(ttInfoCalcuParam_inpu2);
  121 + session.insert(ttInfo_input2);
  122 +
  123 +
  124 +
  125 + // 3、执行rule
  126 + session.fireAllRules();
  127 +
  128 + // 4、执行完毕销毁,有日志的也要关闭
  129 + session.dispose();
  130 +
  131 + // 打印global结果
  132 + logger.info(ttInfoResults_output.showTTInfoDesc1());
  133 +
  134 + }
  135 +
  136 +// @Test
54 public void shiftloopDrlTest() throws Exception { 137 public void shiftloopDrlTest() throws Exception {
55 // 1、创建session,内部配置的是stateful 138 // 1、创建session,内部配置的是stateful
56 KieSession session = kieBase.newKieSession(); 139 KieSession session = kieBase.newKieSession();
@@ -66,17 +149,16 @@ public class DroolsRulesTest { @@ -66,17 +149,16 @@ public class DroolsRulesTest {
66 ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(); 149 ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input();
67 scheduleCalcuParam_input.setFromDate(new DateTime(2016, 8, 1, 0, 0)); 150 scheduleCalcuParam_input.setFromDate(new DateTime(2016, 8, 1, 0, 0));
68 scheduleCalcuParam_input.setToDate(new DateTime(2016, 8, 10, 0, 0)); 151 scheduleCalcuParam_input.setToDate(new DateTime(2016, 8, 10, 0, 0));
69 - scheduleCalcuParam_input.setTtinfoId(1L);  
70 152
71 ScheduleRule_input scheduleRule_input1 = new ScheduleRule_input(); 153 ScheduleRule_input scheduleRule_input1 = new ScheduleRule_input();
72 - scheduleRule_input1.setRuleId(1L); 154 + scheduleRule_input1.setRuleId("1");
73 scheduleRule_input1.setQyrq(new DateTime(2016, 7, 22, 0, 0)); 155 scheduleRule_input1.setQyrq(new DateTime(2016, 7, 22, 0, 0));
74 scheduleRule_input1.getGuideboardIds().addAll(Arrays.asList( 156 scheduleRule_input1.getGuideboardIds().addAll(Arrays.asList(
75 - 9L, 9L , 8L ,8L ,7L ,7L ,6L ,6L, 5L, 5L, 4L, 4L, 3L, 3L, 2L, 2L, 1L, 1L)); 157 + "9", "9" , "8" ,"8" ,"7" ,"7" ,"6" ,"6", "5", "5", "4", "4", "3", "3", "2", "2", "1", "1"));
76 scheduleRule_input1.setStartGbdIndex(3); 158 scheduleRule_input1.setStartGbdIndex(3);
77 - scheduleRule_input1.getEmployeeConfigIds().addAll(Arrays.asList(1L, 2L)); 159 + scheduleRule_input1.getEmployeeConfigIds().addAll(Arrays.asList("1", "2"));
78 scheduleRule_input1.setStartEIndex(1); 160 scheduleRule_input1.setStartEIndex(1);
79 - scheduleRule_input1.setCarConfigId(1L); 161 + scheduleRule_input1.setCarConfigId("1");
80 162
81 // ScheduleRule_input scheduleRule_input2 = new ScheduleRule_input(); 163 // ScheduleRule_input scheduleRule_input2 = new ScheduleRule_input();
82 // scheduleRule_input2.setRuleId(2L); 164 // scheduleRule_input2.setRuleId(2L);