Commit 4fa0d03acd1706e445bed8f44f319b2a4756ecfe

Authored by 徐烜
1 parent 0ad6ab86

Update

src/main/java/com/bsth/entity/schedule/SchedulePlan.java
1 1 package com.bsth.entity.schedule;
2 2  
3 3 import com.bsth.entity.Line;
4   -import com.bsth.entity.schedule.rule.ScheduleRule1;
5 4 import com.fasterxml.jackson.annotation.JsonIgnore;
6 5  
7 6 import javax.persistence.*;
... ... @@ -15,9 +14,8 @@ import java.util.List;
15 14 @Entity
16 15 @Table(name = "bsth_c_s_sp")
17 16 @NamedEntityGraphs({
18   - @NamedEntityGraph(name = "schedulePlan_xl_ttinfo", attributeNodes = {
  17 + @NamedEntityGraph(name = "schedulePlan_xl", attributeNodes = {
19 18 @NamedAttributeNode("xl"),
20   - @NamedAttributeNode("ttInfo")
21 19 })
22 20 })
23 21 public class SchedulePlan extends BEntity {
... ... @@ -30,22 +28,6 @@ public class SchedulePlan extends BEntity {
30 28 /** 关联的线路 */
31 29 @ManyToOne(optional = false, cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
32 30 private Line xl;
33   - /** 关联的时刻表/模版 */
34   - // TODO:这个字段之后就不用了
35   - @ManyToOne(optional = false, cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
36   - private TTInfo ttInfo;
37   - /** TODO:关联的排班规则(这里暂时改成可以不关联规则,直接生成排班) */
38   - @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
39   - private ScheduleRule1 scheduleRule1;
40   -
41   - // TODO: 新字段,测试完后删除旧的字段
42   -
43   - /** 使用的时刻表名字列表(用逗号连接) */
44   - private String ttInfoNames;
45   - /** 使用的时刻表id列表(用逗号连接) */
46   - private String ttInfoId;
47   - /** 使用的规则1列表(用逗号连接) */
48   - private String rule1Ids;
49 31  
50 32 /** 排班计划的开始时间 */
51 33 @Column(nullable = false)
... ... @@ -54,6 +36,11 @@ public class SchedulePlan extends BEntity {
54 36 @Column(nullable = false)
55 37 private Date scheduleToTime;
56 38  
  39 + /** 使用的时刻表名字列表(用逗号连接) */
  40 + private String ttInfoNames;
  41 + /** 使用的时刻表id列表(用逗号连接) */
  42 + private String ttInfoIds;
  43 +
57 44 @JsonIgnore
58 45 /** 使用中间表的一对多关联 明细信息 */
59 46 @OneToMany(mappedBy = "schedulePlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
... ... @@ -75,22 +62,6 @@ public class SchedulePlan extends BEntity {
75 62 this.xl = xl;
76 63 }
77 64  
78   - public TTInfo getTtInfo() {
79   - return ttInfo;
80   - }
81   -
82   - public void setTtInfo(TTInfo ttInfo) {
83   - this.ttInfo = ttInfo;
84   - }
85   -
86   - public ScheduleRule1 getScheduleRule1() {
87   - return scheduleRule1;
88   - }
89   -
90   - public void setScheduleRule1(ScheduleRule1 scheduleRule1) {
91   - this.scheduleRule1 = scheduleRule1;
92   - }
93   -
94 65 public Date getScheduleFromTime() {
95 66 return scheduleFromTime;
96 67 }
... ... @@ -123,19 +94,11 @@ public class SchedulePlan extends BEntity {
123 94 this.ttInfoNames = ttInfoNames;
124 95 }
125 96  
126   - public String getTtInfoId() {
127   - return ttInfoId;
128   - }
129   -
130   - public void setTtInfoId(String ttInfoId) {
131   - this.ttInfoId = ttInfoId;
132   - }
133   -
134   - public String getRule1Ids() {
135   - return rule1Ids;
  97 + public String getTtInfoIds() {
  98 + return ttInfoIds;
136 99 }
137 100  
138   - public void setRule1Ids(String rule1Ids) {
139   - this.rule1Ids = rule1Ids;
  101 + public void setTtInfoIds(String ttInfoIds) {
  102 + this.ttInfoIds = ttInfoIds;
140 103 }
141 104 }
... ...
src/main/java/com/bsth/repository/BusinessRepository.java
... ... @@ -4,6 +4,8 @@ import org.springframework.stereotype.Repository;
4 4  
5 5 import com.bsth.entity.Business;
6 6  
  7 +import java.util.List;
  8 +
7 9 /**
8 10 *
9 11 * @Interface: BusinessRepository(公司Repository数据持久层接口)
... ... @@ -23,4 +25,8 @@ import com.bsth.entity.Business;
23 25 @Repository
24 26 public interface BusinessRepository extends BaseRepository<Business, Integer> {
25 27  
  28 + List<Business> findByBusinessCode(String code);
  29 +
  30 + List<Business> findByUpCodeAndBusinessCode(String c1, String c2);
  31 +
26 32 }
... ...
src/main/java/com/bsth/repository/schedule/CarConfigInfoRepository.java
... ... @@ -45,4 +45,7 @@ public interface CarConfigInfoRepository extends BaseRepository&lt;CarConfigInfo, L
45 45  
46 46 @Query("select new map(cc.cl.id as id, cc.cl.insideCode as insideCode) from CarConfigInfo cc")
47 47 List<Map<String, Object>> findCarsFromConfig();
  48 +
  49 + @EntityGraph(value = "carConfigInfo_xl_cl", type = EntityGraph.EntityGraphType.FETCH)
  50 + List<CarConfigInfo> findByXlId(Integer xlid);
48 51 }
49 52 \ No newline at end of file
... ...
src/main/java/com/bsth/repository/schedule/EmployeeConfigInfoRepository.java
... ... @@ -25,6 +25,9 @@ public interface EmployeeConfigInfoRepository extends BaseRepository&lt;EmployeeCon
25 25 List<EmployeeConfigInfo> findBylineCode(String lineCode);
26 26  
27 27 @EntityGraph(value = "employeeConfigInfo_jsy_spy_xl", type = EntityGraph.EntityGraphType.FETCH)
  28 + List<EmployeeConfigInfo> findByXlId(Integer xlid);
  29 +
  30 + @EntityGraph(value = "employeeConfigInfo_jsy_spy_xl", type = EntityGraph.EntityGraphType.FETCH)
28 31 @Override
29 32 Page<EmployeeConfigInfo> findAll(Specification<EmployeeConfigInfo> spec, Pageable pageable);
30 33  
... ...
src/main/java/com/bsth/repository/schedule/SchedulePlanRepository.java
... ... @@ -13,7 +13,7 @@ import org.springframework.stereotype.Repository;
13 13 */
14 14 @Repository
15 15 public interface SchedulePlanRepository extends BaseRepository<SchedulePlan, Long> {
16   - @EntityGraph(value = "schedulePlan_xl_ttinfo", type = EntityGraph.EntityGraphType.FETCH)
  16 + @EntityGraph(value = "schedulePlan_xl", type = EntityGraph.EntityGraphType.FETCH)
17 17 @Override
18 18 Page<SchedulePlan> findAll(Specification<SchedulePlan> spec, Pageable pageable);
19 19  
... ...
src/main/java/com/bsth/repository/schedule/ScheduleRule1FlatRepository.java
1 1 package com.bsth.repository.schedule;
2 2  
  3 +import com.bsth.entity.Line;
3 4 import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
4 5 import com.bsth.repository.BaseRepository;
5 6 import org.springframework.data.domain.Page;
... ... @@ -9,6 +10,8 @@ import org.springframework.data.jpa.repository.EntityGraph;
9 10 import org.springframework.data.jpa.repository.Query;
10 11 import org.springframework.stereotype.Repository;
11 12  
  13 +import java.util.List;
  14 +
12 15 /**
13 16 * Created by xu on 16/7/4.
14 17 */
... ... @@ -22,4 +25,6 @@ public interface ScheduleRule1FlatRepository extends BaseRepository&lt;ScheduleRule
22 25 @EntityGraph(value = "scheduleRule1Flat_xl_carconfig", type = EntityGraph.EntityGraphType.FETCH)
23 26 @Query("select cc from ScheduleRule1Flat cc where cc.id=?1")
24 27 ScheduleRule1Flat findOneExtend(Long aLong);
  28 +
  29 + List<ScheduleRule1Flat> findByXl(Line line);
25 30 }
... ...
src/main/java/com/bsth/repository/schedule/TTInfoDetailRepository.java
... ... @@ -45,8 +45,11 @@ public interface TTInfoDetailRepository extends BaseRepository&lt;TTInfoDetail, Lon
45 45 @Query(value = "select tt from TTInfoDetail tt where tt.xl.id = ?1 and tt.ttinfo.id = ?2 and tt.lp.id = ?3 order by tt.fcno asc")
46 46 List<TTInfoDetail> findBcdetails(Integer xlId, Long ttinfoId, Long lpId);
47 47  
  48 + List<TTInfoDetail> findByTtinfoId(Long id);
  49 +
48 50 @Modifying
49 51 @Query(value = "delete from TTInfoDetail t where t.ttinfo.id = ?1")
50 52 void deleteByTtinfoIdWithModify(Long ttinfoid);
51 53  
  54 +
52 55 }
... ...
src/main/java/com/bsth/repository/schedule/TTInfoRepository.java
1 1 package com.bsth.repository.schedule;
2 2  
  3 +import com.bsth.entity.Line;
3 4 import com.bsth.entity.schedule.EmployeeConfigInfo;
4 5 import com.bsth.entity.schedule.TTInfo;
5 6 import com.bsth.repository.BaseRepository;
... ... @@ -10,6 +11,8 @@ import org.springframework.data.jpa.repository.EntityGraph;
10 11 import org.springframework.data.jpa.repository.Query;
11 12 import org.springframework.stereotype.Repository;
12 13  
  14 +import java.util.List;
  15 +
13 16 /**
14 17 * Created by xu on 16/5/12.
15 18 */
... ... @@ -23,4 +26,7 @@ public interface TTInfoRepository extends BaseRepository&lt;TTInfo, Long&gt; {
23 26 @EntityGraph(value = "ttInfo_xl", type = EntityGraph.EntityGraphType.FETCH)
24 27 @Query("select cc from TTInfo cc where cc.id=?1")
25 28 TTInfo findOneExtend(Long aLong);
  29 +
  30 + @Query("select t from TTInfo t where t.xl = ?1 and t.isCancel = false")
  31 + List<TTInfo> findInCanceledByXl(Line xl);
26 32 }
... ...
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
1 1 package com.bsth.service.schedule.impl;
2 2  
3   -import com.bsth.entity.Line;
4 3 import com.bsth.entity.schedule.SchedulePlan;
5 4 import com.bsth.entity.schedule.TTInfo;
6 5 import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
7   -import com.bsth.repository.schedule.SchedulePlanInfoRepository;
8   -import com.bsth.repository.schedule.SchedulePlanRepository;
9   -import com.bsth.service.BusinessService;
10   -import com.bsth.service.LineService;
11   -import com.bsth.service.schedule.*;
  6 +import com.bsth.repository.BusinessRepository;
  7 +import com.bsth.repository.LineRepository;
  8 +import com.bsth.repository.schedule.*;
  9 +import com.bsth.service.schedule.SchedulePlanService;
12 10 import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
13 11 import com.bsth.service.schedule.rules.plan.PlanResult;
14 12 import com.bsth.service.schedule.rules.shiftloop.ScheduleCalcuParam_input;
15 13 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
16 14 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
17   -import com.bsth.service.schedule.rules.strategy.IStrategy;
18 15 import com.bsth.service.schedule.rules.ttinfo.*;
19 16 import com.bsth.service.schedule.rules.ttinfo2.CalcuParam;
20 17 import com.bsth.service.schedule.rules.ttinfo2.Result;
... ... @@ -28,7 +25,6 @@ import org.springframework.stereotype.Service;
28 25 import org.springframework.transaction.annotation.Isolation;
29 26 import org.springframework.transaction.annotation.Propagation;
30 27 import org.springframework.transaction.annotation.Transactional;
31   -import org.springframework.util.CollectionUtils;
32 28  
33 29 import java.util.*;
34 30  
... ... @@ -40,75 +36,45 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
40 36 @Autowired
41 37 private KieBase kieBase;
42 38 @Autowired
43   - private IStrategy strategy;
44   - @Autowired
45   - private SchedulePlanRepository schedulePlanRepository;
46   - @Autowired
47 39 private SchedulePlanInfoRepository schedulePlanInfoRepository;
48 40 @Autowired
49   - private LineService lineService;
  41 + private ScheduleRule1FlatRepository scheduleRule1FlatRepository;
  42 + @Autowired
  43 + private TTInfoRepository ttInfoRepository;
50 44 @Autowired
51   - private TTInfoService ttInfoService;
  45 + private TTInfoDetailRepository ttInfoDetailRepository;
52 46 @Autowired
53   - private TTInfoDetailService ttInfoDetailService;
  47 + private LineRepository lineRepository;
54 48 @Autowired
55   - private BusinessService businessService;
  49 + private CarConfigInfoRepository carConfigInfoRepository;
56 50 @Autowired
57   - private CarConfigInfoService carConfigInfoService;
  51 + private EmployeeConfigInfoRepository employeeConfigInfoRepository;
58 52 @Autowired
59   - private EmployeeConfigInfoService employeeConfigInfoService;
  53 + private BusinessRepository businessRepository;
60 54  
61 55 /** 日志记录器 */
62 56 private Logger logger = LoggerFactory.getLogger(SchedulePlanServiceImpl.class);
63 57  
64   - // 查找线路(未撤销),TODO:到时候放入drl中
65   - private Line getLine(Integer xlId) {
66   - Map<String, Object> param = new HashMap<>();
67   - param.put("id_eq", xlId);
68   - param.put("destroy_eq", 0); // 未撤销
69   - List<Line> lines = (List<Line>) lineService.list(param);
70   - if (CollectionUtils.isEmpty(lines)) {
71   - throw new RuntimeException("线路找不到,可能已经撤销!");
72   - }
73   - return lines.get(0);
74   - }
75   - // 查找时刻表(未作废),TODO:到时候放入drl中
76   - private List<TTInfo> getTTInfos(Integer xlId) {
77   - // 查询参数
78   - Map<String, Object> param = new HashMap<>();
79   - param.put("xl.id_eq", xlId); // 线路Id
80   - param.put("isCancel_eq", false); // 作废的过滤掉
81   - Iterator<TTInfo> ttInfoIterator = ttInfoService.list(param).iterator();
82   - if (!ttInfoIterator.hasNext()) {
83   - throw new RuntimeException("线路id=" + xlId + " 没有时刻表!");
84   - }
85   - List<TTInfo> ttInfos = new ArrayList<>();
86   - while (ttInfoIterator.hasNext()) {
87   - TTInfo ttInfo = ttInfoIterator.next();
88   - ttInfos.add(ttInfo);
89   - }
90   - return ttInfos;
91   - }
92   -
93 58 /**
94 59 * 循环规则输出。
95   - * @param schedulePlan
  60 + * @param schedulePlan 排班计划对象
  61 + * @param lpInfoResults_output 时刻表每日路牌的情况
96 62 */
97   - private ScheduleResults_output loopRuleOutput(SchedulePlan schedulePlan, LpInfoResults_output lpInfoResults_output) {
98   - // 获取主线路
99   - Line xl = strategy.getLine(schedulePlan.getXl().getId());
100   -
  63 + private ScheduleResults_output loopRuleOutput(
  64 + SchedulePlan schedulePlan,
  65 + LpInfoResults_output lpInfoResults_output) {
101 66 // 1-1、构造drools规则输入数据,输出数据
102 67 // 全局计算参数
103 68 ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
104 69 // 每个规则对应的输入参数
105 70 List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>();
106   - Iterator<ScheduleRule1Flat> scheduleRule1FlatIterator = strategy.getScheduleRule(xl.getId()).iterator();
107   - while (scheduleRule1FlatIterator.hasNext()) {
108   - ScheduleRule1Flat scheduleRule1Flat_temp = scheduleRule1FlatIterator.next();
109   - ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat_temp);
  71 + List<ScheduleRule1Flat> scheduleRule1Flats = scheduleRule1FlatRepository.findByXl(schedulePlan.getXl());
  72 +
  73 + for (ScheduleRule1Flat scheduleRule1Flat: scheduleRule1Flats) {
  74 + ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat);
110 75 scheduleRule_inputs.add(scheduleRule_input);
111 76 }
  77 +
112 78 // 规则输出数据
113 79 ScheduleResults_output scheduleResults_output = new ScheduleResults_output();
114 80  
... ... @@ -124,6 +90,7 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
124 90 for (ScheduleRule_input scheduleRule_input : scheduleRule_inputs) {
125 91 session.insert(scheduleRule_input);
126 92 }
  93 + // 每日时刻表路牌数据
127 94 for (LpInfoResult_output lpInfoResult_output: lpInfoResults_output.getLpInfoResult_outputs()) {
128 95 session.insert(lpInfoResult_output);
129 96 }
... ... @@ -140,12 +107,12 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
140 107  
141 108 /**
142 109 * 时刻表选择(判定每天使用的时刻表,以及路牌数据输出)。
143   - * @param schedulePlan
  110 + * @param schedulePlan 排班计划对象
144 111 * @return TTInfoResults_output, LpInfoResults_output
145 112 */
146 113 private Object[] ttInfoOutput(SchedulePlan schedulePlan) {
147 114 // 获取线路的所有未作废的时刻表
148   - List<TTInfo> ttInfos = getTTInfos(schedulePlan.getXl().getId());
  115 + List<TTInfo> ttInfos = ttInfoRepository.findInCanceledByXl(schedulePlan.getXl());
149 116  
150 117 // 1-1、构造drools规则输入数据,输出数据
151 118 // 全局计算参数
... ... @@ -167,8 +134,7 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
167 134 session.setGlobal("results", ttInfoResults_output);
168 135 session.setGlobal("lpInfoResults_output", lpInfoResults_output);
169 136 session.setGlobal("log", logger); // 设置日志
170   -
171   - session.setGlobal("tTInfoDetailService", ttInfoDetailService);
  137 + session.setGlobal("tTInfoDetailRepository", ttInfoDetailRepository);
172 138  
173 139 // 载入数据
174 140 session.insert(ttInfoCalcuParam_input);
... ... @@ -177,12 +143,11 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
177 143 session.insert(ttInfo_input);
178 144 }
179 145  
  146 + // 载入数据2(计算规则最早启用时间)
  147 + List<ScheduleRule1Flat> scheduleRule1Flats = scheduleRule1FlatRepository.findByXl(schedulePlan.getXl());
180 148  
181   - // 载入数据2
182   - Iterator<ScheduleRule1Flat> scheduleRule1FlatIterator = strategy.getScheduleRule(schedulePlan.getXl().getId()).iterator();
183   - while (scheduleRule1FlatIterator.hasNext()) {
184   - ScheduleRule1Flat scheduleRule1Flat_temp = scheduleRule1FlatIterator.next();
185   - ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat_temp);
  149 + for (ScheduleRule1Flat scheduleRule1Flat: scheduleRule1Flats) {
  150 + ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat);
186 151 session.insert(scheduleRule_input);
187 152 }
188 153  
... ... @@ -196,6 +161,13 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
196 161  
197 162 }
198 163  
  164 + /**
  165 + * 排班生成。
  166 + * @param schedulePlan 排班计划对象
  167 + * @param scheduleResults_output loopRuleOutput方法规则输出
  168 + * @param ttInfoResults_output ttInfoOutput方法规则输出
  169 + * @return PlanResult
  170 + */
199 171 private PlanResult planResultOutput(
200 172 SchedulePlan schedulePlan,
201 173 ScheduleResults_output scheduleResults_output,
... ... @@ -216,14 +188,14 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
216 188  
217 189 // 设置gloable对象,在drl中通过别名使用
218 190 session.setGlobal("planResult", planResult);
219   - session.setGlobal("tTInfoService", ttInfoService);
220   - session.setGlobal("tTInfoDetailService", ttInfoDetailService);
221   - session.setGlobal("carConfigInfoService", carConfigInfoService);
222   - session.setGlobal("employeeConfigInfoService", employeeConfigInfoService);
223   - session.setGlobal("lineService", lineService);
224   - session.setGlobal("businessService", businessService);
225 191 session.setGlobal("log", logger); // 设置日志
226 192  
  193 + session.setGlobal("tTInfoDetailRepository", ttInfoDetailRepository);
  194 + session.setGlobal("carConfigInfoRepository", carConfigInfoRepository);
  195 + session.setGlobal("employeeConfigInfoRepository", employeeConfigInfoRepository);
  196 + session.setGlobal("lineRepository", lineRepository);
  197 + session.setGlobal("businessRepository", businessRepository);
  198 +
227 199 // 载入数据
228 200 session.insert(planCalcuParam_input);
229 201  
... ... @@ -238,207 +210,28 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
238 210 }
239 211  
240 212 @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
241   - public SchedulePlan save2(SchedulePlan schedulePlan) {
  213 + public SchedulePlan save(SchedulePlan schedulePlan) {
  214 + // pre、如果排班的数据之前已经有了,删除之前的数据
  215 + schedulePlanInfoRepository.deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(
  216 + schedulePlan.getXl().getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime()
  217 + );
  218 +
242 219 // 1、时刻表数据及每日路牌数据计算
243 220 Object[] ttInfoRets = ttInfoOutput(schedulePlan);
244 221 TTInfoResults_output ttInfoResults_output = (TTInfoResults_output) ttInfoRets[0];
245 222 LpInfoResults_output lpInfoResults_output = (LpInfoResults_output) ttInfoRets[1];
246   -
247 223 // 2、循环规则计算输出
248 224 ScheduleResults_output scheduleResults_output = loopRuleOutput(schedulePlan, lpInfoResults_output);
249   -
250 225 // 3、计划输出
251 226 PlanResult planResult = planResultOutput(schedulePlan, scheduleResults_output, ttInfoResults_output);
252 227  
253   - schedulePlan.setTtInfoId("todo"); // TODO:待修正
254   - schedulePlan.setTtInfoNames("todo"); // TODO:待修正
255   -
  228 + // 4、保存数据(TODO:之后改成批量保存)
256 229 schedulePlan.getSchedulePlanInfoList().addAll(planResult.getSchedulePlanInfos());
257   -
258 230 super.save(schedulePlan);
259 231  
260   -
261   -
262   -// // 1、循环规则计算输出
263   -// ScheduleResults_output scheduleResults_output = loopRuleOutput(schedulePlan);
264   -// // 2、时刻表选择
265   -// TTInfoResults_output ttInfoResults_output = ttInfoOutput(schedulePlan);
266   -// // 3、计划输出
267   -// PlanResult planResult = planResultOutput(schedulePlan, scheduleResults_output, ttInfoResults_output);
268   -//
269   -// schedulePlan.getSchedulePlanInfoList().addAll(planResult.getSchedulePlanInfos());
270   -// schedulePlan.setTtInfoId("todo"); // TODO:待修正
271   -// schedulePlan.setTtInfoNames("todo"); // TODO:待修正
272   -//
273   -// super.save(schedulePlan);
274   -
275 232 return new SchedulePlan();
276 233 }
277 234  
278   - @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
279   - public SchedulePlan save(SchedulePlan schedulePlan) {
280   - // 2-3、如果排班的数据之前已经有了,删除之前的数据
281   - schedulePlanInfoRepository.deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(
282   - schedulePlan.getXl().getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime()
283   - );
284   -
285   - // 测试
286   - return save2(schedulePlan);
287   -
288   -// // 1-1、查找线路具体信息
289   -// Line xl = strategy.getLine(schedulePlan.getXl().getId());
290   -// // 1-2、查出指定线路的所有规则
291   -// TTInfo ttInfo = strategy.getTTInfo(xl.getId()).get(0); // 时刻表id
292   -// schedulePlan.setTtInfo(ttInfo); // TODO:关联的时刻表,之后改掉
293   -//
294   -// // 2-1、构造drools规则输入数据,输出数据
295   -// // 全局计算参数
296   -// ScheduleCalcuParam_input scheduleCalcuParam_input = new ScheduleCalcuParam_input(schedulePlan);
297   -// // 每个规则对应的输入参数
298   -// List<ScheduleRule_input> scheduleRule_inputs = new ArrayList<>();
299   -// Iterator<ScheduleRule1Flat> scheduleRule1FlatIterator = strategy.getScheduleRule(xl.getId()).iterator();
300   -// while (scheduleRule1FlatIterator.hasNext()) {
301   -// ScheduleRule1Flat scheduleRule1Flat_temp = scheduleRule1FlatIterator.next();
302   -// ScheduleRule_input scheduleRule_input = new ScheduleRule_input(scheduleRule1Flat_temp);
303   -// scheduleRule_inputs.add(scheduleRule_input);
304   -// }
305   -// // 规则输出数据
306   -// ScheduleResults_output scheduleResults_output = new ScheduleResults_output();
307   -//
308   -// // 2-2、构造drools session->载入数据->启动规则->计算->销毁session
309   -// // 创建session,内部配置的是stateful
310   -// KieSession session = kieBase.newKieSession();
311   -// // 设置gloable对象,在drl中通过别名使用
312   -// session.setGlobal("scheduleResult", scheduleResults_output);
313   -// session.setGlobal("log", logger); // 设置日志
314   -//
315   -// // 载入数据
316   -// session.insert(scheduleCalcuParam_input);
317   -// for (ScheduleRule_input scheduleRule_input : scheduleRule_inputs) {
318   -// session.insert(scheduleRule_input);
319   -// }
320   -// // 执行rule
321   -// session.fireAllRules();
322   -//
323   -// // 执行完毕销毁,有日志的也要关闭
324   -// session.dispose();
325   -//
326   -// System.out.println(scheduleResults_output.showGuideboardDesc1());
327   -//
328   -// // 2-3、如果排班的数据之前已经有了,删除之前的数据
329   -// schedulePlanInfoRepository.deleteByXlAndScheduleDateGreaterThanEqualAndScheduleDateLessThanEqual(
330   -// xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime()
331   -// );
332   -//
333   -// // 3、根据规则返回,组合最后的输出数据
334   -// // 3-1、根据注入的策略服务,获取原始数据
335   -// Map<Date, Multimap<Long, TTInfoDetail>> gbdTTinfoMaps = strategy.getGuideboardXlTTInfoDetailMaps(
336   -// xl.getId(), schedulePlan.getScheduleFromTime(), schedulePlan.getScheduleToTime());
337   -//
338   -// Map<Long, CarConfigInfo> carConfigMaps = strategy.getCarConfigMaps(xl.getId()); // 车辆配置对应车辆信息
339   -// Map<Long, EmployeeConfigInfo> employeeConfigMaps = strategy.getEmployeeConfigMaps(xl.getId()); // 人员配置对应的人员信息
340   -//
341   -// // 3-2、循环规则输出
342   -// Map<Long, String> ttInfoMap = new HashMap<>(); // 时刻表映射,id和名字
343   -// List<SchedulePlanInfo> schedulePlanInfos = new ArrayList<>();
344   -// for (ScheduleResult_output scheduleResult_output : scheduleResults_output.getResults()) {
345   -// // 车辆配置对应的车辆
346   -// CarConfigInfo configInfo = carConfigMaps.get(Long.valueOf(scheduleResult_output.getCarConfigId()));
347   -// // 人员配置对应的人员,这里需要分班处理的
348   -// List<EmployeeConfigInfo> employeeConfigInfoList = new ArrayList<>();
349   -// String[] eids = scheduleResult_output.getEmployeeConfigId().split("-");
350   -// for (String eid : eids) {
351   -// employeeConfigInfoList.add(employeeConfigMaps.get(Long.valueOf(eid)));
352   -// }
353   -// // 排班明细(这个要迭代的)
354   -// Collection<TTInfoDetail> ttInfoDetails_ = gbdTTinfoMaps.get(scheduleResult_output.getSd().toDate()).get(
355   -// Long.parseLong(scheduleResult_output.getGuideboardId()));
356   -// List<TTInfoDetail> ttInfoDetails = new ArrayList<>(ttInfoDetails_);
357   -//
358   -// // 排序ttInfoDetails
359   -// Collections.sort(ttInfoDetails, new Comparator<TTInfoDetail>() {
360   -// @Override
361   -// public int compare(TTInfoDetail o1, TTInfoDetail o2) {
362   -// return o1.getFcno().compareTo(o2.getFcno());
363   -// }
364   -// });
365   -//
366   -// Boolean isFb = false; // 是否分班
367   -// for (int i = 0; i < ttInfoDetails.size(); i++) {
368   -// TTInfoDetail ttInfoDetail = ttInfoDetails.get(i);
369   -//
370   -// if (ttInfoDetail.getIsFB())
371   -// isFb = ttInfoDetail.getIsFB();
372   -//
373   -// SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo(
374   -// xl,
375   -// scheduleResult_output,
376   -// ttInfoDetail,
377   -// isFb,
378   -// configInfo,
379   -// employeeConfigInfoList,
380   -// schedulePlan,
381   -// i == 0,
382   -// i == ttInfoDetails.size() - 1);
383   -//
384   -// // 获取公司,分公司信息
385   -// String gsbm = xl.getCompany();
386   -// String fgsbm = xl.getBrancheCompany();
387   -// Business gs = null;
388   -// Business fgs = null;
389   -//
390   -// Map<String, Object> param = new HashMap<>();
391   -//
392   -// if (StringUtils.isNotEmpty(gsbm)) {
393   -// param.clear();
394   -// param.put("businessCode_eq", gsbm);
395   -// Iterator<Business> businessIterator = businessService.list(param).iterator();
396   -// if (businessIterator.hasNext()) {
397   -// gs = businessIterator.next();
398   -// }
399   -// }
400   -// if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) {
401   -// param.clear();;
402   -// param.put("upCode_eq", gsbm);
403   -// param.put("businessCode_eq", fgsbm);
404   -// Iterator<Business> businessIterator = businessService.list(param).iterator();
405   -// if (businessIterator.hasNext()) {
406   -// fgs = businessIterator.next();
407   -// }
408   -// }
409   -//
410   -// if (gs != null) {
411   -// schedulePlanInfo.setGsBm(gs.getBusinessCode());
412   -// schedulePlanInfo.setGsName(gs.getBusinessName());
413   -// }
414   -// if (fgs != null) {
415   -// schedulePlanInfo.setFgsBm(fgs.getBusinessCode());
416   -// schedulePlanInfo.setFgsName(fgs.getBusinessName());
417   -// }
418   -//
419   -// // 操作人,操作时间
420   -// schedulePlanInfo.setCreateBy(schedulePlan.getCreateBy());
421   -// schedulePlanInfo.setCreateDate(schedulePlan.getCreateDate());
422   -// schedulePlanInfo.setUpdateBy(schedulePlan.getUpdateBy());
423   -// schedulePlanInfo.setUpdateDate(schedulePlan.getUpdateDate());
424   -//
425   -// schedulePlanInfos.add(schedulePlanInfo);
426   -// ttInfoMap.put(ttInfoDetail.getTtinfo().getId(), ttInfoDetail.getTtinfo().getName());
427   -//
428   -// }
429   -//
430   -// }
431   -//
432   -// schedulePlan.setTtInfoId(StringUtils.join(ttInfoMap.keySet(), ","));
433   -// schedulePlan.setTtInfoNames(StringUtils.join(ttInfoMap.values(), ","));
434   -//
435   -// // 3-2、保存生成的排班和明细
436   -// schedulePlan.getSchedulePlanInfoList().addAll(schedulePlanInfos); // 关联的排班明细信息
437   -// super.save(schedulePlan);
438   -//
439   -// return new SchedulePlan();
440   - }
441   -
442 235 @Override
443 236 public SchedulePlan findSchedulePlanTommorw() {
444 237 DateTime today = new DateTime(new Date());
... ... @@ -460,8 +253,8 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
460 253 KieSession session = kieBase.newKieSession();
461 254 // 设置gloable对象,在drl中通过别名使用
462 255 session.setGlobal("log", logger);
463   - session.setGlobal("lineService", lineService);
464   - session.setGlobal("ttInfoDetailService", ttInfoDetailService);
  256 + session.setGlobal("lineRepository", lineRepository);
  257 + session.setGlobal("tTInfoDetailRepository", ttInfoDetailRepository);
465 258  
466 259 Result rs = new Result(); // 输出gloable对象
467 260 session.setGlobal("rs", rs);
... ... @@ -470,11 +263,10 @@ public class SchedulePlanServiceImpl extends BServiceImpl&lt;SchedulePlan, Long&gt; im
470 263 CalcuParam calcuParam = new CalcuParam(
471 264 new DateTime(from), new DateTime(to), xlid);
472 265 session.insert(calcuParam);
473   - List<TTInfo> ttInfos = ttInfoService.findAll();
  266 + List<TTInfo> ttInfos = (List<TTInfo>) ttInfoRepository.findAll();
474 267 for (TTInfo ttInfo: ttInfos)
475 268 session.insert(ttInfo);
476 269  
477   -
478 270 // 执行rule
479 271 session.fireAllRules();
480 272  
... ...
src/main/java/com/bsth/service/schedule/rules/Message.java deleted 100644 → 0
1   -package com.bsth.service.schedule.rules;
2   -
3   -/**
4   - * Created by xu on 16/6/15.
5   - */
6   -public class Message {
7   - public static final int HELLO = 0;
8   - public static final int GOODBYE = 1;
9   -
10   - private String message;
11   - private int status;
12   - public String getMessage() {
13   - return message;
14   - }
15   - public void setMessage(String message) {
16   - this.message = message;
17   - }
18   - public int getStatus() {
19   - return status;
20   - }
21   - public void setStatus(int status) {
22   - this.status = status;
23   - }
24   -}
src/main/java/com/bsth/service/schedule/rules/MyDroolsConfiguration.java
... ... @@ -55,9 +55,6 @@ public class MyDroolsConfiguration {
55 55 kfs.write("src/main/resources/functions.drl", kieServices.getResources()
56 56 .newInputStreamResource(this.getClass().getResourceAsStream(
57 57 "/rules/functions.drl"), "UTF-8"));
58   - kfs.write("src/main/resources/HelloWorld.drl", kieServices.getResources()
59   - .newInputStreamResource(this.getClass().getResourceAsStream(
60   - "/rules/HelloWorld.drl"), "UTF-8"));
61 58 kfs.write("src/main/resources/shiftloop_fb_2.drl", kieServices.getResources()
62 59 .newInputStreamResource(this.getClass().getResourceAsStream(
63 60 "/rules/shiftloop_fb_2.drl"), "UTF-8"));
... ...
src/main/resources/rules/HelloWorld.drl deleted 100644 → 0
1   -package com.bsth.service.schedule
2   -
3   -//list any import classes here.
4   -
5   -import com.bsth.service.schedule.rules.Message;
6   -
7   -//declare any global variables here
8   -
9   -global java.util.List list
10   -
11   -
12   -rule "Hello World"
13   - dialect "mvel"
14   - when
15   - $m : Message( status == Message.HELLO, $message : message )
16   - then
17   - System.out.println($message);
18   - $m.status = com.bsth.service.schedule.rules.Message.GOODBYE;
19   - $m.message = "Goodbye cruel world";
20   - update($m);
21   -end
22   -
23   -rule "Good bye"
24   - dialect "mvel"
25   - when
26   - $m : Message( status == Message.GOODBYE, $message : message )
27   - then
28   - System.out.println($message);
29   - list.add("you come on!");
30   -end
src/main/resources/rules/plan.drl
... ... @@ -6,12 +6,11 @@ import java.util.*;
6 6 import com.bsth.service.schedule.rules.plan.PlanCalcuParam_input;
7 7 import com.bsth.service.schedule.rules.plan.PlanResult;
8 8  
9   -import com.bsth.service.schedule.TTInfoService;
10   -import com.bsth.service.schedule.TTInfoDetailService;
11   -import com.bsth.service.schedule.CarConfigInfoService;
12   -import com.bsth.service.schedule.EmployeeConfigInfoService;
13   -import com.bsth.service.LineService;
14   -import com.bsth.service.BusinessService;
  9 +import com.bsth.repository.schedule.TTInfoDetailRepository;
  10 +import com.bsth.repository.schedule.CarConfigInfoRepository;
  11 +import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
  12 +import com.bsth.repository.LineRepository;
  13 +import com.bsth.repository.BusinessRepository;
15 14  
16 15 import com.bsth.service.schedule.rules.shiftloop.ScheduleResult_output;
17 16 import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output;
... ... @@ -33,33 +32,27 @@ import org.apache.commons.lang3.StringUtils;
33 32  
34 33 // 全局日志类(一般使用调用此规则的service类)
35 34 global Logger log;
36   -global TTInfoDetailService tTInfoDetailService;
37   -global TTInfoService tTInfoService;
38   -global CarConfigInfoService carConfigInfoService;
39   -global EmployeeConfigInfoService employeeConfigInfoService;
40   -global LineService lineService;
41   -global BusinessService businessService;
  35 +
  36 +global TTInfoDetailRepository tTInfoDetailRepository;
  37 +global CarConfigInfoRepository carConfigInfoRepository;
  38 +global EmployeeConfigInfoRepository employeeConfigInfoRepository;
  39 +global LineRepository lineRepository;
  40 +global BusinessRepository businessRepository;
42 41  
43 42 // 输出
44 43 global PlanResult planResult;
45 44  
46   -function Map ttidParams(String ttid) {
47   - Map param = new HashMap();
48   - param.put("ttinfo.id_eq", Long.parseLong(ttid));
49   - return param;
50   -}
51   -
52 45 function Map xlidParams(String xlid) {
53 46 Map param = new HashMap();
54 47 param.put("xl.id_eq", Integer.valueOf(xlid));
55 48 return param;
56 49 }
57 50  
58   -function List ecList(EmployeeConfigInfoService service, String ecids) {
  51 +function List ecList(EmployeeConfigInfoRepository repo, String ecids) {
59 52 List<String> ids = Arrays.asList(ecids.split("-"));
60 53 List rst = new ArrayList();
61 54 for (int i = 0; i < ids.size(); i++) {
62   - rst.add(service.findById(Long.parseLong(ids.get(i))));
  55 + rst.add(repo.findOne(Long.parseLong(ids.get(i))));
63 56 }
64 57 return rst;
65 58 }
... ... @@ -149,7 +142,7 @@ rule &quot;calcu_CarConfig_Wrap&quot;
149 142 salience 800
150 143 when
151 144 $lr: Loop_result($xlId: xlId)
152   - $ccf: CarConfigInfo() from carConfigInfoService.list(xlidParams($xlId))
  145 + $ccf: CarConfigInfo() from carConfigInfoRepository.findByXlId(Integer.parseInt($xlId))
153 146 then
154 147 CarConfig_Wrap carConfig_wrap = new CarConfig_Wrap();
155 148 carConfig_wrap.setId(String.valueOf($ccf.getId()));
... ... @@ -169,7 +162,7 @@ rule &quot;calcu_EmployeeConfig_Wrap&quot;
169 162 salience 800
170 163 when
171 164 $lr: Loop_result($xlId: xlId)
172   - $eci: EmployeeConfigInfo() from employeeConfigInfoService.list(xlidParams($xlId))
  165 + $eci: EmployeeConfigInfo() from employeeConfigInfoRepository.findByXlId(Integer.parseInt($xlId))
173 166 then
174 167 EmployeeConfig_Wrap employeeConfig_wrap = new EmployeeConfig_Wrap();
175 168 employeeConfig_wrap.setId(String.valueOf($eci.getId()));
... ... @@ -194,10 +187,10 @@ rule &quot;calcu_TTInfo_gid_stat&quot;
194 187 when
195 188 $lr: Loop_result($xlId: xlId)
196 189 $ttInfoId: String() from $lr.getTtInfoMap().keySet()
197   - $gids: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailService.list(ttidParams($ttInfoId)), gidscount($ttd))
  190 + $gids: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidscount($ttd))
198 191 $gid: String() from $gids
199   - $fbtime_str: String() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailService.list(ttidParams($ttInfoId)), gidfbtime($ttd))
200   - $maxfcno: Double() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailService.list(ttidParams($ttInfoId)), max($ttd.getFcno()))
  192 + $fbtime_str: String() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), gidfbtime($ttd))
  193 + $maxfcno: Double() from accumulate ($ttd: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId)), max($ttd.getFcno()))
201 194 then
202 195 TTInfo_gid_stat ttInfo_gid_stat = new TTInfo_gid_stat();
203 196 ttInfo_gid_stat.setXlId($xlId);
... ... @@ -234,7 +227,7 @@ rule &quot;calcu_TTInfoDetail_Wrap&quot;
234 227 $ttInfoStat: TTInfo_gid_stat(
235 228 ttInfoId == $ttInfoId,
236 229 $gid: gid, $maxFcno: maxFcno)
237   - $ttInfoDetail: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailService.list(ttidParams($ttInfoId))
  230 + $ttInfoDetail: TTInfoDetail(lp.id.toString() == $gid) from tTInfoDetailRepository.findByTtinfoId(Long.parseLong($ttInfoId))
238 231 then
239 232 TTInfoDetail_Wrap ttInfoDetail_wrap = new TTInfoDetail_Wrap();
240 233 ttInfoDetail_wrap.setXlId($xlId);
... ... @@ -276,7 +269,7 @@ rule &quot;Calcu_SchedulePlanInfo&quot;
276 269 )
277 270 then
278 271 // 线路
279   - Line xl = lineService.findById(Integer.valueOf($xlId));
  272 + Line xl = lineRepository.findOne(Integer.parseInt($xlId));
280 273  
281 274 SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo(
282 275 xl,
... ... @@ -284,7 +277,7 @@ rule &quot;Calcu_SchedulePlanInfo&quot;
284 277 $ttInfoDetail,
285 278 $isFb,
286 279 $cc,
287   - ecList(employeeConfigInfoService, $sro.getEmployeeConfigId()),
  280 + ecList(employeeConfigInfoRepository, $sro.getEmployeeConfigId()),
288 281 $param.getSchedulePlan(),
289 282 $isFirstBc,
290 283 $isLastBc
... ... @@ -296,23 +289,16 @@ rule &quot;Calcu_SchedulePlanInfo&quot;
296 289 Business gs = null;
297 290 Business fgs = null;
298 291  
299   - Map<String, Object> param = new HashMap<>();
300   -
301 292 if (StringUtils.isNotEmpty(gsbm)) {
302   - param.clear();
303   - param.put("businessCode_eq", gsbm);
304   - Iterator<Business> businessIterator = businessService.list(param).iterator();
305   - if (businessIterator.hasNext()) {
306   - gs = businessIterator.next();
  293 + Iterator<Business> businessIterator1 = businessRepository.findByBusinessCode(gsbm).iterator();
  294 + if (businessIterator1.hasNext()) {
  295 + gs = (Business) businessIterator1.next();
307 296 }
308 297 }
309 298 if (StringUtils.isNotEmpty(gsbm) && StringUtils.isNotEmpty(fgsbm)) {
310   - param.clear();;
311   - param.put("upCode_eq", gsbm);
312   - param.put("businessCode_eq", fgsbm);
313   - Iterator<Business> businessIterator = businessService.list(param).iterator();
314   - if (businessIterator.hasNext()) {
315   - fgs = businessIterator.next();
  299 + Iterator<Business> businessIterator2 = businessRepository.findByUpCodeAndBusinessCode(gsbm, fgsbm).iterator();
  300 + if (businessIterator2.hasNext()) {
  301 + fgs = (Business) businessIterator2.next();
316 302 }
317 303 }
318 304  
... ... @@ -331,14 +317,11 @@ rule &quot;Calcu_SchedulePlanInfo&quot;
331 317 schedulePlanInfo.setUpdateBy($param.getSchedulePlan().getUpdateBy());
332 318 schedulePlanInfo.setUpdateDate($param.getSchedulePlan().getUpdateDate());
333 319  
334   - // TODO:
335   - $param.getSchedulePlan().setTtInfo($ttInfoDetail.getTtinfo());
336   -
337 320 // result 输出
338 321 planResult.getSchedulePlanInfos().add(schedulePlanInfo);
339 322  
340 323 log.info("gid={},ecid={},ttInfoId={}",
341   - $gid, ecList(employeeConfigInfoService, $sro.getEmployeeConfigId()),
  324 + $gid, ecList(employeeConfigInfoRepository, $sro.getEmployeeConfigId()),
342 325 ttInfoId_sd($lr.getTtInfoMapLoop(), $sd));
343 326  
344 327 end
... ...
src/main/resources/rules/ttinfo.drl
... ... @@ -12,7 +12,7 @@ import com.bsth.service.schedule.rules.ttinfo.LpInfoResults_output;
12 12  
13 13 import com.bsth.service.schedule.rules.shiftloop.ScheduleRule_input;
14 14  
15   -import com.bsth.service.schedule.TTInfoDetailService;
  15 +import com.bsth.repository.schedule.TTInfoDetailRepository;
16 16  
17 17 import com.bsth.entity.schedule.TTInfo;
18 18 import com.bsth.entity.schedule.TTInfoDetail;
... ... @@ -21,21 +21,18 @@ import org.slf4j.Logger
21 21  
22 22 // 全局日志
23 23 global Logger log;
24   -// service
25   -global TTInfoDetailService tTInfoDetailService;
  24 +// repostory
  25 +global TTInfoDetailRepository tTInfoDetailRepository;
26 26 // return输出
27 27 global TTInfoResults_output results
28 28 global LpInfoResults_output lpInfoResults_output
29 29  
30   -function Map ttidParams(List ttinfolist) {
  30 +function Long ttidParams(List ttinfolist) {
31 31 // 获取第一张时刻表id
32 32 TTInfo_input ttInfo_input = (TTInfo_input) ttinfolist.get(0);
33   - Map param = new HashMap();
34   - param.put("ttinfo.id_eq", Long.parseLong(ttInfo_input.getTtInfoId()));
35   - return param;
  33 + return Long.parseLong(ttInfo_input.getTtInfoId());
36 34 }
37 35  
38   -
39 36 /*
40 37 TODO:规则说明,以后待说明
41 38 */
... ... @@ -124,7 +121,7 @@ rule &quot;calcu_ttinfo_special_day&quot; // 特殊日期匹配
124 121 $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list)
125 122 $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day)
126 123 $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays contains $calcu_date) from $ttInfo_input_list)
127   - $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailService.list(ttidParams($ttinfolist)), lpinforesult($ttd))
  124 + $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd))
128 125 then
129 126 // 更新Calcu_days_result对象
130 127 int new_calcu_day = $calcu_day + 1;
... ... @@ -155,7 +152,7 @@ rule &quot;calcu_ttinfo_normal_day&quot; // 平日匹配
155 152 $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list)
156 153 $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday)
157 154 $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == true) from $ttInfo_input_list)
158   - $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailService.list(ttidParams($ttinfolist)), lpinforesult($ttd))
  155 + $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd))
159 156 then
160 157 // 更新Calcu_days_result对象
161 158 int new_calcu_day = $calcu_day + 1;
... ... @@ -186,7 +183,7 @@ rule &quot;calcu_ttinfo_other_day&quot; // 都没有的情况下,匹配
186 183 $calcu_ttinfo_enable_result : Calcu_ttinfo_enable_result($xlId : xlId, $calcu_date : calcu_date, $ttInfo_input_list : ttInfo_input_list)
187 184 $calcu_days_result : Calcu_days_result(calcu_date == $calcu_date, xlId == $xlId, $calcu_day : calcu_day, $calcu_weekday : calcu_weekday)
188 185 $ttinfolist : ArrayList(size >= 1) from collect (TTInfo_input(specialDays not contains $calcu_date, weekdays[$calcu_weekday - 1] == false) from $ttInfo_input_list)
189   - $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailService.list(ttidParams($ttinfolist)), lpinforesult($ttd))
  186 + $lpInfoResults: List() from accumulate ($ttd: TTInfoDetail() from tTInfoDetailRepository.findByTtinfoId(ttidParams($ttinfolist)), lpinforesult($ttd))
190 187 then
191 188 // 更新Calcu_days_result对象
192 189 int new_calcu_day = $calcu_day + 1;
... ...
src/main/resources/rules/ttinfo2.drl
... ... @@ -12,8 +12,8 @@ import com.bsth.entity.schedule.TTInfo;
12 12 import com.bsth.entity.schedule.TTInfoDetail;
13 13 import com.bsth.entity.Line;
14 14  
15   -import com.bsth.service.LineService;
16   -import com.bsth.service.schedule.TTInfoDetailService;
  15 +import com.bsth.repository.LineRepository;
  16 +import com.bsth.repository.schedule.TTInfoDetailRepository;
17 17  
18 18 import org.slf4j.Logger
19 19 import org.joda.time.format.DateTimeFormat
... ... @@ -23,8 +23,8 @@ import java.lang.Object;
23 23  
24 24 // 全局日志类(一般使用调用此规则的service类)
25 25 global Logger log;
26   -global LineService lineService;
27   -global TTInfoDetailService ttInfoDetailService;
  26 +global LineRepository lineRepository;
  27 +global TTInfoDetailRepository tTInfoDetailRepository;
28 28  
29 29 // 输出
30 30 global Result rs;
... ... @@ -68,7 +68,7 @@ rule &quot;calcu_iter_days&quot;
68 68 Calcu_iter_days_result cidr = new Calcu_iter_days_result();
69 69 Period p = new Period($fromDate, $toDate, PeriodType.days());
70 70  
71   - Line line = (Line) lineService.findById($xlId);
  71 + Line line = (Line) lineRepository.findOne($xlId);
72 72  
73 73 cidr.setXlId($xlId);
74 74 cidr.setXlName(line.getName());
... ... @@ -192,9 +192,7 @@ rule &quot;Calcu_iter_days_special_day&quot; // 特殊日期匹配
192 192  
193 193 TTInfoDetails_wrap ttInfoDetails_wrap = new TTInfoDetails_wrap();
194 194 ttInfoDetails_wrap.setTtInfoId($tid);
195   - Map<String, Object> param = new HashMap<String, Object>();
196   - param.put("ttinfo.id_eq", $tid);
197   - ttInfoDetails_wrap.setBcInfoList(ttInfoDetailService.list(param));
  195 + ttInfoDetails_wrap.setBcInfoList(tTInfoDetailRepository.findByTtinfoId($tid));
198 196 insert(ttInfoDetails_wrap);
199 197 }
200 198 update($cid);
... ... @@ -239,9 +237,7 @@ rule &quot;Calcu_iter_days_normal_day&quot; // 平日匹配
239 237  
240 238 TTInfoDetails_wrap ttInfoDetails_wrap = new TTInfoDetails_wrap();
241 239 ttInfoDetails_wrap.setTtInfoId($tid);
242   - Map<String, Object> param = new HashMap<String, Object>();
243   - param.put("ttinfo.id_eq", $tid);
244   - ttInfoDetails_wrap.setBcInfoList(ttInfoDetailService.list(param));
  240 + ttInfoDetails_wrap.setBcInfoList(tTInfoDetailRepository.findByTtinfoId($tid));
245 241 insert(ttInfoDetails_wrap);
246 242 }
247 243 update($cid);
... ... @@ -286,8 +282,7 @@ rule &quot;Calcu_iter_days_other_day&quot; // 都没有的情况下,匹配
286 282 TTInfoDetails_wrap ttInfoDetails_wrap = new TTInfoDetails_wrap();
287 283 ttInfoDetails_wrap.setTtInfoId($tid);
288 284 Map<String, Object> param = new HashMap<String, Object>();
289   - param.put("ttinfo.id_eq", $tid);
290   - ttInfoDetails_wrap.setBcInfoList(ttInfoDetailService.list(param));
  285 + ttInfoDetails_wrap.setBcInfoList(tTInfoDetailRepository.findByTtinfoId($tid));
291 286 insert(ttInfoDetails_wrap);
292 287 }
293 288 update($cid);
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts2/scheduleplan/saScpdate.js
... ... @@ -21,6 +21,8 @@ angular.module(&#39;ScheduleApp&#39;).directive(
21 21 to: '=',
22 22 xlid: '=',
23 23 xlname: '=',
  24 + ttinfonames: '=',
  25 + ttinfoids: '=',
24 26 error: '='
25 27 },
26 28 controllerAs: '$saScpdateCtrl',
... ... @@ -116,6 +118,8 @@ angular.module(&#39;ScheduleApp&#39;).directive(
116 118 }
117 119  
118 120 var QClass = service.ttinfo;
  121 + var ttinfonames = [];
  122 + var ttinfoids = [];
119 123 QClass.val({xlid: xl_id, from: from_date, to: to_date},
120 124 function(result) {
121 125 scope[ctrlAs].$$ds = [];
... ... @@ -141,6 +145,9 @@ angular.module(&#39;ScheduleApp&#39;).directive(
141 145  
142 146 if (obj.errorbc > 0) {
143 147 errorTTInfos ++;
  148 + } else {
  149 + ttinfonames.push(obj.ttname);
  150 + ttinfoids.push(obj.ttid);
144 151 }
145 152 });
146 153  
... ... @@ -148,8 +155,9 @@ angular.module(&#39;ScheduleApp&#39;).directive(
148 155 scope[ctrlAs].$$internalmodel = undefined;
149 156 scope[ctrlAs].error = "时刻表有错误班次";
150 157 } else {
151   -
152 158 scope[ctrlAs].$$internalmodel = "ok";
  159 + scope[ctrlAs].ttinfonames = ttinfonames.join(",");
  160 + scope[ctrlAs].ttinfoids = ttinfoids.join(",");
153 161 }
154 162  
155 163 } else {
... ...
src/main/resources/static/pages/scheduleApp/module/common/prj-common-directive.js
... ... @@ -3688,354 +3688,362 @@ angular.module(&#39;ScheduleApp&#39;).directive(&#39;saBcgroup&#39;, [
3688 3688 }
3689 3689 }
3690 3690 ]);
3691   -/**
3692   - * saTimeTable指令,时刻表显示指令,excel表格形式,支持菜单,事件处理。
3693   - * name(必须),控件的名字
3694   - * celldbclickFn,单元格双击事件
3695   - * ds,外部数据源
3696   - *
3697   - * TODO:优化开发中
3698   - *
3699   - */
3700   -angular.module('ScheduleApp').directive('saTimetable', ['$compile', '$window',
3701   - function($compile, $window) {
3702   - return {
3703   - restrict: 'E',
3704   - templateUrl: '/pages/scheduleApp/module/common/dts2/ttinfotable/saTimeTableTemplate.html',
3705   - scope: { // 独立作用域
3706   - // 注意:数据暂时从外部ngModel里获取,以后内部自己处理
3707   - ds: "=ngModel",
3708   - celldbclickFn: "&celldbclick"
3709   -
3710   - // TODO:
3711   -
3712   - },
3713   - controllerAs: "$saTimeTableCtrl",
3714   - bindToController: true,
3715   - controller: function() {
3716   - var self = this;
3717   - this.$$headToolTip = ""; // 表头tooltip信息
3718   -
3719   - // TODO:
3720   - },
3721   -
3722   - /**,
3723   - * compile阶段,angular还没有编译模版,根据需要可以修改模版dom
3724   - * @param tElem
3725   - * @param tAttrs
3726   - * @returns {{pre: Function, post: Function}}
3727   - */
3728   - compile: function(tElem, tAttrs) {
3729   - // 获取属性
3730   - var $attr_name = tAttrs["name"]; // 控件的名字
3731   - if (!$attr_name) {
3732   - throw new Error("saTimeTable指令 name属性required");
3733   - }
3734   - var $attr_celldbclick = tAttrs["celldbclick"]; // 单元格双击事件名
3735   -
3736   - // 内部controlAs名字
3737   - var ctrlAs = '$saTimeTableCtrl';
3738   -
3739   - // 当前选中的cell
3740   - var startRowIndex = undefined;
3741   - var startColIndex = undefined;
3742   - var shiftKey = false; // shift键是否被按住
3743   - var ctrlKey = false; // ctrl是否被按住
3744   - // shift选中的cell
3745   - var shiftCells = [];
3746   -
3747   - // TODO:
3748   -
3749   - return {
3750   - pre: function(scope, element, attr) {
3751   - // TODO:
3752   - //alert(element.find("#tooltipTest").html());
3753   - //$compile(element.find("#tooltipTest"))(scope);
3754   -
3755   - },
3756   - post: function(scope, element, attr) {
3757   - // TODO:
3758   -
3759   - // ------------------- dom事件处理function -----------------//
3760   - scope[ctrlAs].$$cell_click = function(rowindex, colindex, cell) {
3761   - console.log("click " + "row=" + rowindex + ",col=" + colindex);
3762   - var internal_ds = scope[ctrlAs].ds.detailInfos;
3763   -
3764   - if (cell.ttdid) { // 是班次的单元格才能操作
3765   - cell.sel = !cell.sel;
3766   - }
3767   -
3768   - };
3769   - scope[ctrlAs].$$cell_dbclick = function(rowindex, colindex, cell) {
3770   - if (cell.ttdid) { // 是班次的单元格才能操作
3771   - if ($attr_celldbclick) {
3772   - // 注意调用方法
3773   - scope[ctrlAs].celldbclickFn()(rowindex, colindex);
3774   - }
3775   - }
3776   - };
3777   -
3778   - // ------------------- 监控function ------------------//
3779   - // 监控明细数据,生成表头的tooltip
3780   - scope.$watch(
3781   - function() {
3782   - return scope[ctrlAs].ds;
3783   - },
3784   - function(newValue, oldValue) {
3785   - if (newValue &&
3786   - newValue.detailHeads &&
3787   - newValue.detailHeads.length > 0) {
3788   - var tooltip = [];
3789   - tooltip.push("出场");
3790   - angular.forEach(newValue.detailHeads, function(value) {
3791   - if (value != "出场" &&
3792   - value != "路牌" &&
3793   - value != "进场" &&
3794   - value != "空驶班次/空驶里程" &&
3795   - value != "运营班次/运营里程" ) {
3796   - var exist = false;
3797   - angular.forEach(tooltip, function(tip) {
3798   - if (tip == value) {
3799   - exist = true;
3800   - }
3801   - });
3802   - if (!exist) {
3803   - tooltip.push(value);
3804   - }
3805   - }
3806   - });
3807   - tooltip.push("进场");
3808   - scope[ctrlAs].$$headToolTip = tooltip.join(",");
3809   - }
3810   - },
3811   - true
3812   - )
3813   - }
3814   - };
3815   - }
3816   -
3817   - };
3818   - }
3819   -]);
3820   -
3821   -/**
3822   - * saScpdate指令(非通用指令,只在排版计划form中使用)。
3823   - * 属性如下:
3824   - * name(必须):控件的名字
3825   - * xlid(必须):线路id
3826   - * xlname(必须):线路名字
3827   - * from(必须):独立作用域-绑定的开始时间属性名
3828   - * to(必须):独立作用域-绑定的结束时间属性名
3829   - * error(必须):独立作用域-绑定的错误描述属性名
3830   - */
3831   -angular.module('ScheduleApp').directive(
3832   - 'saScpdate',
3833   - [
3834   - 'SchedulePlanManageService_g',
3835   - function(service) {
3836   - return {
3837   - restrict: 'E',
3838   - templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saScpdateTemplate.html',
3839   - scope: {
3840   - from: '=',
3841   - to: '=',
3842   - xlid: '=',
3843   - xlname: '=',
3844   - error: '='
3845   - },
3846   - controllerAs: '$saScpdateCtrl',
3847   - bindToController: true,
3848   - controller: function() {
3849   - var self = this;
3850   -
3851   - // 内部ng-model值,用于和required配对
3852   - self.$$internalmodel = undefined;
3853   -
3854   - // 内部数据源(时刻表的一些信息)
3855   - self.$$ds = [];
3856   -
3857   - },
3858   - compile: function(tElem, tAttrs) {
3859   - // 获取所有属性,并验证
3860   - var $name_attr = tAttrs['name']; // 控件的名字
3861   - if (!$name_attr) {
3862   - throw "必须有名称属性";
3863   - }
3864   -
3865   - // controlAs名字
3866   - var ctrlAs = '$saScpdateCtrl';
3867   -
3868   - // 线路id
3869   - var xl_id = undefined;
3870   - // 线路名字
3871   - var xl_name = undefined;
3872   - // 开始时间
3873   - var from_date = undefined;
3874   - // 结束时间
3875   - var to_date = undefined;
3876   -
3877   - // 内部添加required验证,将所有的错误应用到required验证上去
3878   - tElem.find("div").attr("required", "");
3879   -
3880   - return {
3881   - pre: function(scope, element, attr) {
3882   -
3883   - },
3884   -
3885   - post: function(scope, element, attr) {
3886   - // 属性值
3887   - if ($name_attr) {
3888   - scope[ctrlAs]["$name_attr"] = $name_attr;
3889   - }
3890   -
3891   - // 开始日期open属性,及方法
3892   - scope[ctrlAs].$$fromDateOpen = false;
3893   - scope[ctrlAs].$$fromDate_open = function() {
3894   - scope[ctrlAs].$$fromDateOpen = true;
3895   - };
3896   -
3897   - // 结束日期open属性,及方法
3898   - scope[ctrlAs].$$toDateOpen = false;
3899   - scope[ctrlAs].$$toDate_open = function() {
3900   - scope[ctrlAs].$$toDateOpen = true;
3901   - };
3902   -
3903   -
3904   - // 内部模型刷新
3905   - scope[ctrlAs].$$internal_model_refresh = function() {
3906   - if (!xl_id) {
3907   - scope[ctrlAs].$$internalmodel = undefined;
3908   - scope[ctrlAs].error = "线路必须选择";
3909   - return;
3910   - }
3911   - if (!xl_name) {
3912   - scope[ctrlAs].$$internalmodel = undefined;
3913   - scope[ctrlAs].error = "线路必须选择";
3914   - return;
3915   - }
3916   -
3917   - if (!from_date) {
3918   - scope[ctrlAs].$$internalmodel = undefined;
3919   - scope[ctrlAs].error = "开始日期必须选择";
3920   - return;
3921   - }
3922   - if (!to_date) {
3923   - scope[ctrlAs].$$internalmodel = undefined;
3924   - scope[ctrlAs].error = "结束日期必须选择";
3925   - return;
3926   - }
3927   - if (from_date > to_date) {
3928   - scope[ctrlAs].$$internalmodel = undefined;
3929   - scope[ctrlAs].error = "开始日期必须在结束日期之前";
3930   - return;
3931   - }
3932   -
3933   - if (!scope[ctrlAs].$$ds || scope[ctrlAs].$$ds.length == 0) {
3934   - scope[ctrlAs].$$internalmodel = undefined;
3935   - scope[ctrlAs].error = "无可用时刻表";
3936   - }
3937   -
3938   - var QClass = service.ttinfo;
3939   - QClass.val({xlid: xl_id, from: from_date, to: to_date},
3940   - function(result) {
3941   - scope[ctrlAs].$$ds = [];
3942   -
3943   - var errorTTInfos = 0;
3944   -
3945   - if (result && result.data && result.data.infos && result.data.infos.length > 0) {
3946   - angular.forEach(result.data.infos, function(obj) {
3947   - scope[ctrlAs].$$ds.push({
3948   - xlid: xl_id,
3949   - ttid: obj.ttid,
3950   - xlname: xl_name,
3951   - ttname: obj.ttname,
3952   -
3953   - allbc: obj.allbc,
3954   - inbc: obj.inbc,
3955   - outbc: obj.outbc,
3956   - yybc: obj.yybc,
3957   -
3958   - errorbc: obj.errorbc
3959   -
3960   - });
3961   -
3962   - if (obj.errorbc > 0) {
3963   - errorTTInfos ++;
3964   - }
3965   - });
3966   -
3967   - if (errorTTInfos > 0) {
3968   - scope[ctrlAs].$$internalmodel = undefined;
3969   - scope[ctrlAs].error = "时刻表有错误班次";
3970   - } else {
3971   -
3972   - scope[ctrlAs].$$internalmodel = "ok";
3973   - }
3974   -
3975   - } else {
3976   - scope[ctrlAs].$$internalmodel = undefined;
3977   - scope[ctrlAs].error = "无可用时刻表";
3978   - }
3979   - },
3980   - function() {
3981   - scope[ctrlAs].$$internalmodel = undefined;
3982   - scope[ctrlAs].error = "获取时刻表数据失败!";
3983   - }
3984   - );
3985   -
3986   -
3987   - scope[ctrlAs].$$internalmodel = "ok";
3988   - };
3989   -
3990   - scope[ctrlAs].$$internal_model_refresh(); // 初始执行
3991   -
3992   - //--------------------- 监控属性方法 -------------------//
3993   - // 监控线路id模型值变化
3994   - scope.$watch(
3995   - function() {
3996   - return scope[ctrlAs].xlid;
3997   - },
3998   - function(newValue, oldValue) {
3999   - xl_id = newValue;
4000   - scope[ctrlAs].$$internal_model_refresh();
4001   - }
4002   - );
4003   - // 监控线路name模型值变化
4004   - scope.$watch(
4005   - function() {
4006   - return scope[ctrlAs].xlname;
4007   - },
4008   - function(newValue, oldValue) {
4009   - xl_name = newValue;
4010   - scope[ctrlAs].$$internal_model_refresh();
4011   - }
4012   - );
4013   -
4014   - // 监控开始时间模型值变化
4015   - scope.$watch(
4016   - function() {
4017   - return scope[ctrlAs].from;
4018   - },
4019   - function(newValue, oldValue) {
4020   - from_date = newValue;
4021   - scope[ctrlAs].$$internal_model_refresh();
4022   - }
4023   - );
4024   - // 监控结束时间模型值变化
4025   - scope.$watch(
4026   - function() {
4027   - return scope[ctrlAs].to;
4028   - },
4029   - function(newValue, oldValue) {
4030   - to_date = newValue;
4031   - scope[ctrlAs].$$internal_model_refresh();
4032   - }
4033   - );
  3691 +/**
  3692 + * saTimeTable指令,时刻表显示指令,excel表格形式,支持菜单,事件处理。
  3693 + * name(必须),控件的名字
  3694 + * celldbclickFn,单元格双击事件
  3695 + * ds,外部数据源
  3696 + *
  3697 + * TODO:优化开发中
  3698 + *
  3699 + */
  3700 +angular.module('ScheduleApp').directive('saTimetable', ['$compile', '$window',
  3701 + function($compile, $window) {
  3702 + return {
  3703 + restrict: 'E',
  3704 + templateUrl: '/pages/scheduleApp/module/common/dts2/ttinfotable/saTimeTableTemplate.html',
  3705 + scope: { // 独立作用域
  3706 + // 注意:数据暂时从外部ngModel里获取,以后内部自己处理
  3707 + ds: "=ngModel",
  3708 + celldbclickFn: "&celldbclick"
  3709 +
  3710 + // TODO:
  3711 +
  3712 + },
  3713 + controllerAs: "$saTimeTableCtrl",
  3714 + bindToController: true,
  3715 + controller: function() {
  3716 + var self = this;
  3717 + this.$$headToolTip = ""; // 表头tooltip信息
  3718 +
  3719 + // TODO:
  3720 + },
  3721 +
  3722 + /**,
  3723 + * compile阶段,angular还没有编译模版,根据需要可以修改模版dom
  3724 + * @param tElem
  3725 + * @param tAttrs
  3726 + * @returns {{pre: Function, post: Function}}
  3727 + */
  3728 + compile: function(tElem, tAttrs) {
  3729 + // 获取属性
  3730 + var $attr_name = tAttrs["name"]; // 控件的名字
  3731 + if (!$attr_name) {
  3732 + throw new Error("saTimeTable指令 name属性required");
  3733 + }
  3734 + var $attr_celldbclick = tAttrs["celldbclick"]; // 单元格双击事件名
  3735 +
  3736 + // 内部controlAs名字
  3737 + var ctrlAs = '$saTimeTableCtrl';
  3738 +
  3739 + // 当前选中的cell
  3740 + var startRowIndex = undefined;
  3741 + var startColIndex = undefined;
  3742 + var shiftKey = false; // shift键是否被按住
  3743 + var ctrlKey = false; // ctrl是否被按住
  3744 + // shift选中的cell
  3745 + var shiftCells = [];
  3746 +
  3747 + // TODO:
  3748 +
  3749 + return {
  3750 + pre: function(scope, element, attr) {
  3751 + // TODO:
  3752 + //alert(element.find("#tooltipTest").html());
  3753 + //$compile(element.find("#tooltipTest"))(scope);
  3754 +
  3755 + },
  3756 + post: function(scope, element, attr) {
  3757 + // TODO:
  3758 +
  3759 + // ------------------- dom事件处理function -----------------//
  3760 + scope[ctrlAs].$$cell_click = function(rowindex, colindex, cell) {
  3761 + console.log("click " + "row=" + rowindex + ",col=" + colindex);
  3762 + var internal_ds = scope[ctrlAs].ds.detailInfos;
  3763 +
  3764 + if (cell.ttdid) { // 是班次的单元格才能操作
  3765 + cell.sel = !cell.sel;
  3766 + }
  3767 +
  3768 + };
  3769 + scope[ctrlAs].$$cell_dbclick = function(rowindex, colindex, cell) {
  3770 + if (cell.ttdid) { // 是班次的单元格才能操作
  3771 + if ($attr_celldbclick) {
  3772 + // 注意调用方法
  3773 + scope[ctrlAs].celldbclickFn()(rowindex, colindex);
  3774 + }
  3775 + }
  3776 + };
  3777 +
  3778 + // ------------------- 监控function ------------------//
  3779 + // 监控明细数据,生成表头的tooltip
  3780 + scope.$watch(
  3781 + function() {
  3782 + return scope[ctrlAs].ds;
  3783 + },
  3784 + function(newValue, oldValue) {
  3785 + if (newValue &&
  3786 + newValue.detailHeads &&
  3787 + newValue.detailHeads.length > 0) {
  3788 + var tooltip = [];
  3789 + tooltip.push("出场");
  3790 + angular.forEach(newValue.detailHeads, function(value) {
  3791 + if (value != "出场" &&
  3792 + value != "路牌" &&
  3793 + value != "进场" &&
  3794 + value != "空驶班次/空驶里程" &&
  3795 + value != "运营班次/运营里程" ) {
  3796 + var exist = false;
  3797 + angular.forEach(tooltip, function(tip) {
  3798 + if (tip == value) {
  3799 + exist = true;
  3800 + }
  3801 + });
  3802 + if (!exist) {
  3803 + tooltip.push(value);
  3804 + }
  3805 + }
  3806 + });
  3807 + tooltip.push("进场");
  3808 + scope[ctrlAs].$$headToolTip = tooltip.join(",");
  3809 + }
  3810 + },
  3811 + true
  3812 + )
  3813 + }
  3814 + };
  3815 + }
  3816 +
  3817 + };
  3818 + }
  3819 +]);
4034 3820  
4035   - }
4036   - };
4037   - }
4038   - };
4039   - }
4040   - ]
  3821 +/**
  3822 + * saScpdate指令(非通用指令,只在排版计划form中使用)。
  3823 + * 属性如下:
  3824 + * name(必须):控件的名字
  3825 + * xlid(必须):线路id
  3826 + * xlname(必须):线路名字
  3827 + * from(必须):独立作用域-绑定的开始时间属性名
  3828 + * to(必须):独立作用域-绑定的结束时间属性名
  3829 + * error(必须):独立作用域-绑定的错误描述属性名
  3830 + */
  3831 +angular.module('ScheduleApp').directive(
  3832 + 'saScpdate',
  3833 + [
  3834 + 'SchedulePlanManageService_g',
  3835 + function(service) {
  3836 + return {
  3837 + restrict: 'E',
  3838 + templateUrl: '/pages/scheduleApp/module/common/dts2/scheduleplan/saScpdateTemplate.html',
  3839 + scope: {
  3840 + from: '=',
  3841 + to: '=',
  3842 + xlid: '=',
  3843 + xlname: '=',
  3844 + ttinfonames: '=',
  3845 + ttinfoids: '=',
  3846 + error: '='
  3847 + },
  3848 + controllerAs: '$saScpdateCtrl',
  3849 + bindToController: true,
  3850 + controller: function() {
  3851 + var self = this;
  3852 +
  3853 + // 内部ng-model值,用于和required配对
  3854 + self.$$internalmodel = undefined;
  3855 +
  3856 + // 内部数据源(时刻表的一些信息)
  3857 + self.$$ds = [];
  3858 +
  3859 + },
  3860 + compile: function(tElem, tAttrs) {
  3861 + // 获取所有属性,并验证
  3862 + var $name_attr = tAttrs['name']; // 控件的名字
  3863 + if (!$name_attr) {
  3864 + throw "必须有名称属性";
  3865 + }
  3866 +
  3867 + // controlAs名字
  3868 + var ctrlAs = '$saScpdateCtrl';
  3869 +
  3870 + // 线路id
  3871 + var xl_id = undefined;
  3872 + // 线路名字
  3873 + var xl_name = undefined;
  3874 + // 开始时间
  3875 + var from_date = undefined;
  3876 + // 结束时间
  3877 + var to_date = undefined;
  3878 +
  3879 + // 内部添加required验证,将所有的错误应用到required验证上去
  3880 + tElem.find("div").attr("required", "");
  3881 +
  3882 + return {
  3883 + pre: function(scope, element, attr) {
  3884 +
  3885 + },
  3886 +
  3887 + post: function(scope, element, attr) {
  3888 + // 属性值
  3889 + if ($name_attr) {
  3890 + scope[ctrlAs]["$name_attr"] = $name_attr;
  3891 + }
  3892 +
  3893 + // 开始日期open属性,及方法
  3894 + scope[ctrlAs].$$fromDateOpen = false;
  3895 + scope[ctrlAs].$$fromDate_open = function() {
  3896 + scope[ctrlAs].$$fromDateOpen = true;
  3897 + };
  3898 +
  3899 + // 结束日期open属性,及方法
  3900 + scope[ctrlAs].$$toDateOpen = false;
  3901 + scope[ctrlAs].$$toDate_open = function() {
  3902 + scope[ctrlAs].$$toDateOpen = true;
  3903 + };
  3904 +
  3905 +
  3906 + // 内部模型刷新
  3907 + scope[ctrlAs].$$internal_model_refresh = function() {
  3908 + if (!xl_id) {
  3909 + scope[ctrlAs].$$internalmodel = undefined;
  3910 + scope[ctrlAs].error = "线路必须选择";
  3911 + return;
  3912 + }
  3913 + if (!xl_name) {
  3914 + scope[ctrlAs].$$internalmodel = undefined;
  3915 + scope[ctrlAs].error = "线路必须选择";
  3916 + return;
  3917 + }
  3918 +
  3919 + if (!from_date) {
  3920 + scope[ctrlAs].$$internalmodel = undefined;
  3921 + scope[ctrlAs].error = "开始日期必须选择";
  3922 + return;
  3923 + }
  3924 + if (!to_date) {
  3925 + scope[ctrlAs].$$internalmodel = undefined;
  3926 + scope[ctrlAs].error = "结束日期必须选择";
  3927 + return;
  3928 + }
  3929 + if (from_date > to_date) {
  3930 + scope[ctrlAs].$$internalmodel = undefined;
  3931 + scope[ctrlAs].error = "开始日期必须在结束日期之前";
  3932 + return;
  3933 + }
  3934 +
  3935 + if (!scope[ctrlAs].$$ds || scope[ctrlAs].$$ds.length == 0) {
  3936 + scope[ctrlAs].$$internalmodel = undefined;
  3937 + scope[ctrlAs].error = "无可用时刻表";
  3938 + }
  3939 +
  3940 + var QClass = service.ttinfo;
  3941 + var ttinfonames = [];
  3942 + var ttinfoids = [];
  3943 + QClass.val({xlid: xl_id, from: from_date, to: to_date},
  3944 + function(result) {
  3945 + scope[ctrlAs].$$ds = [];
  3946 +
  3947 + var errorTTInfos = 0;
  3948 +
  3949 + if (result && result.data && result.data.infos && result.data.infos.length > 0) {
  3950 + angular.forEach(result.data.infos, function(obj) {
  3951 + scope[ctrlAs].$$ds.push({
  3952 + xlid: xl_id,
  3953 + ttid: obj.ttid,
  3954 + xlname: xl_name,
  3955 + ttname: obj.ttname,
  3956 +
  3957 + allbc: obj.allbc,
  3958 + inbc: obj.inbc,
  3959 + outbc: obj.outbc,
  3960 + yybc: obj.yybc,
  3961 +
  3962 + errorbc: obj.errorbc
  3963 +
  3964 + });
  3965 +
  3966 + if (obj.errorbc > 0) {
  3967 + errorTTInfos ++;
  3968 + } else {
  3969 + ttinfonames.push(obj.ttname);
  3970 + ttinfoids.push(obj.ttid);
  3971 + }
  3972 + });
  3973 +
  3974 + if (errorTTInfos > 0) {
  3975 + scope[ctrlAs].$$internalmodel = undefined;
  3976 + scope[ctrlAs].error = "时刻表有错误班次";
  3977 + } else {
  3978 + scope[ctrlAs].$$internalmodel = "ok";
  3979 + scope[ctrlAs].ttinfonames = ttinfonames.join(",");
  3980 + scope[ctrlAs].ttinfoids = ttinfoids.join(",");
  3981 + }
  3982 +
  3983 + } else {
  3984 + scope[ctrlAs].$$internalmodel = undefined;
  3985 + scope[ctrlAs].error = "无可用时刻表";
  3986 + }
  3987 + },
  3988 + function() {
  3989 + scope[ctrlAs].$$internalmodel = undefined;
  3990 + scope[ctrlAs].error = "获取时刻表数据失败!";
  3991 + }
  3992 + );
  3993 +
  3994 +
  3995 + scope[ctrlAs].$$internalmodel = "ok";
  3996 + };
  3997 +
  3998 + scope[ctrlAs].$$internal_model_refresh(); // 初始执行
  3999 +
  4000 + //--------------------- 监控属性方法 -------------------//
  4001 + // 监控线路id模型值变化
  4002 + scope.$watch(
  4003 + function() {
  4004 + return scope[ctrlAs].xlid;
  4005 + },
  4006 + function(newValue, oldValue) {
  4007 + xl_id = newValue;
  4008 + scope[ctrlAs].$$internal_model_refresh();
  4009 + }
  4010 + );
  4011 + // 监控线路name模型值变化
  4012 + scope.$watch(
  4013 + function() {
  4014 + return scope[ctrlAs].xlname;
  4015 + },
  4016 + function(newValue, oldValue) {
  4017 + xl_name = newValue;
  4018 + scope[ctrlAs].$$internal_model_refresh();
  4019 + }
  4020 + );
  4021 +
  4022 + // 监控开始时间模型值变化
  4023 + scope.$watch(
  4024 + function() {
  4025 + return scope[ctrlAs].from;
  4026 + },
  4027 + function(newValue, oldValue) {
  4028 + from_date = newValue;
  4029 + scope[ctrlAs].$$internal_model_refresh();
  4030 + }
  4031 + );
  4032 + // 监控结束时间模型值变化
  4033 + scope.$watch(
  4034 + function() {
  4035 + return scope[ctrlAs].to;
  4036 + },
  4037 + function(newValue, oldValue) {
  4038 + to_date = newValue;
  4039 + scope[ctrlAs].$$internal_model_refresh();
  4040 + }
  4041 + );
  4042 +
  4043 + }
  4044 + };
  4045 + }
  4046 + };
  4047 + }
  4048 + ]
4041 4049 );
4042 4050 \ No newline at end of file
... ...
src/main/resources/static/pages/scheduleApp/module/core/schedulePlanManage/form.html
... ... @@ -114,6 +114,8 @@
114 114 xlname="ctrl.schedulePlanManageForSave.xl.name"
115 115 from="ctrl.schedulePlanManageForSave.scheduleFromTime"
116 116 to="ctrl.schedulePlanManageForSave.scheduleToTime"
  117 + ttinfonames="ctrl.schedulePlanManageForSave.ttInfoNames"
  118 + ttinfoids="ctrl.schedulePlanManageForSave.ttInfoIds"
117 119 error="ctrl.scperror"
118 120 required
119 121 >
... ...
src/main/resources/static/pages/scheduleApp/module/core/schedulePlanManage/list.html
... ... @@ -81,7 +81,11 @@
81 81 <span ng-bind="info.xl.name"></span>
82 82 </td>
83 83 <td>
84   - <span ng-bind="info.ttInfoNames"></span>
  84 + <div ng-repeat="tinfo in info.rst">
  85 + <a ui-sref="ttInfoDetailManage_edit3({xlid: info.xl.id, ttid : tinfo.ttInfoId, xlname: info.xl.name, ttname : tinfo.ttInfoName, rflag : true})">
  86 + {{tinfo.ttInfoName}}
  87 + </a>
  88 + </div>
85 89 </td>
86 90 <td>
87 91 <span ng-bind="info.scheduleFromTime | date: 'yyyy-MM-dd '"></span>
... ...
src/main/resources/static/pages/scheduleApp/module/core/schedulePlanManage/module.js
... ... @@ -96,12 +96,61 @@ angular.module(&#39;ScheduleApp&#39;).controller(
96 96 self.doPage = function() {
97 97 var page = SPlan.list(self.searchCondition(), function() {
98 98 service.getPage(page);
  99 +
  100 + // 重新组装关联时刻表信息
  101 + if (page.content) {
  102 + angular.forEach(page.content, function(ttinfo) {
  103 + var rst = [];
  104 + var temp1 = [];
  105 + var temp2 = [];
  106 + if (ttinfo.ttInfoNames && ttinfo.ttInfoIds) {
  107 + temp1 = ttinfo.ttInfoNames.split(",");
  108 + temp2 = ttinfo.ttInfoIds.split(",");
  109 + }
  110 +
  111 + if (temp1.length == temp2.length) {
  112 + for (var i = 0; i < temp1.length; i++) {
  113 + rst.push({
  114 + ttInfoName: temp1[i],
  115 + ttInfoId: temp2[i]
  116 + });
  117 + }
  118 + }
  119 +
  120 + ttinfo.rst = rst;
  121 + });
  122 + }
99 123 });
100 124 };
  125 +
101 126 self.reset = function() {
102 127 service.resetStatus();
103 128 var page = SPlan.list(self.searchCondition(), function() {
104 129 service.getPage(page);
  130 +
  131 + // 重新组装关联时刻表信息
  132 + if (page.content) {
  133 + angular.forEach(page.content, function(ttinfo) {
  134 + var rst = [];
  135 + var temp1 = [];
  136 + var temp2 = [];
  137 + if (ttinfo.ttInfoNames && ttinfo.ttInfoIds) {
  138 + temp1 = ttinfo.ttInfoNames.split(",");
  139 + temp2 = ttinfo.ttInfoIds.split(",");
  140 + }
  141 +
  142 + if (temp1.length == temp2.length) {
  143 + for (var i = 0; i < temp1.length; i++) {
  144 + rst.push({
  145 + ttInfoName: temp1[i],
  146 + ttInfoId: temp2[i]
  147 + });
  148 + }
  149 + }
  150 +
  151 + ttinfo.rst = rst;
  152 + });
  153 + }
105 154 });
106 155 };
107 156  
... ...
src/test/java/com/bsth/service/schedule/rules/DroolsRulesTest.java
... ... @@ -18,9 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
18 18 import org.springframework.boot.test.SpringApplicationConfiguration;
19 19 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20 20  
21   -import java.util.ArrayList;
22 21 import java.util.Arrays;
23   -import java.util.List;
24 22  
25 23 @RunWith(SpringJUnit4ClassRunner.class)
26 24 @SpringApplicationConfiguration(classes = {Application.class})
... ... @@ -33,30 +31,30 @@ public class DroolsRulesTest {
33 31 private KieBase kieBase;
34 32  
35 33 // @Test
36   - public void helloWorldDrlTest() throws Exception {
37   - // 1、创建session,内部配置的是stateful
38   - KieSession session = kieBase.newKieSession();
39   -
40   - // 1.1 设置gloable对象,在drl中通过别名使用
41   - List<String> gloableList = new ArrayList<String>();
42   - session.setGlobal("list", gloableList);
43   -
44   - // 1.2 可以设置一些监听器,再议
45   -
46   - // 2、创建fact对象
47   - Message message = new Message();
48   - message.setMessage("Hello World");
49   - message.setStatus(Message.HELLO);
50   - session.insert(message);
51   -
52   - // 3、执行rule
53   - session.fireAllRules();
54   -
55   - System.out.println(gloableList);
56   -
57   - // 4、执行完毕销毁,有日志的也要关闭
58   - session.dispose();
59   - }
  34 +// public void helloWorldDrlTest() throws Exception {
  35 +// // 1、创建session,内部配置的是stateful
  36 +// KieSession session = kieBase.newKieSession();
  37 +//
  38 +// // 1.1 设置gloable对象,在drl中通过别名使用
  39 +// List<String> gloableList = new ArrayList<String>();
  40 +// session.setGlobal("list", gloableList);
  41 +//
  42 +// // 1.2 可以设置一些监听器,再议
  43 +//
  44 +// // 2、创建fact对象
  45 +// Message message = new Message();
  46 +// message.setMessage("Hello World");
  47 +// message.setStatus(Message.HELLO);
  48 +// session.insert(message);
  49 +//
  50 +// // 3、执行rule
  51 +// session.fireAllRules();
  52 +//
  53 +// System.out.println(gloableList);
  54 +//
  55 +// // 4、执行完毕销毁,有日志的也要关闭
  56 +// session.dispose();
  57 +// }
60 58  
61 59 // @Test
62 60 public void ttinfoDrlTest() throws Exception {
... ...