kBase3_validate_rule.drl
6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.bsth.service.schedule.impl.plan.kBase3.validate.rule;
import accumulate com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ErrorInfoFunction srif;
import accumulate com.bsth.service.schedule.impl.plan.kBase3.validate.timetable.ErrorBcCountFunction ecount;
import org.joda.time.*;
import java.util.*;
import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.CalcuParam;
import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult;
import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.ValidateRuleResult.ErrorInfo;
import com.bsth.service.schedule.impl.plan.kBase3.validate.rule.WrapInput;
import com.bsth.repository.schedule.ScheduleRule1FlatRepository
import com.bsth.repository.schedule.CarConfigInfoRepository;
import com.bsth.repository.schedule.GuideboardInfoRepository;
import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.entity.schedule.CarConfigInfo;
import com.bsth.entity.schedule.GuideboardInfo;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import org.slf4j.Logger
// 全局日志
global Logger LOG;
// repository查询
global CarConfigInfoRepository ccRepo;
global GuideboardInfoRepository lpRepo;
global EmployeeConfigInfoRepository ecRepo;
global ScheduleRule1FlatRepository ruleRepo;
// return输出
global ValidateRuleResult result;
//------------------ 第一阶段、车辆信息,路牌信息,人员信息载入 -----------------//
// 1、车辆信息载入
declare CarConfig_Wraps
xlId: Integer // 线路Id
ccMap: Map // 车辆配置Map Map<车辆自编号, CarConfigInfo>
end
rule "calcu_CarConfig_Wraps"
salience 800
when
$param: CalcuParam($xlId: xlId)
then
List ccInfos = ccRepo.findByXlId($xlId);
CarConfig_Wraps carConfig_wraps = new CarConfig_Wraps();
carConfig_wraps.setXlId($xlId);
carConfig_wraps.setCcMap(new HashMap());
for (int i = 0; i < ccInfos.size(); i++) {
CarConfigInfo ccInfo = (CarConfigInfo) ccInfos.get(i);
if (!ccInfo.getIsCancel()) {
carConfig_wraps.getCcMap().put(ccInfo.getCl().getInsideCode(), ccInfo);
}
}
insert(carConfig_wraps);
LOG.info("第一阶段 --> 1、车辆信息载入 calcu_CarConfig_Wraps 有效配置车辆数={}", ccInfos.size());
end
// 2、路牌信息载入
declare Lp_Wraps
xlId: Integer // 线路Id
lpMap: Map // 路牌Map Map<id, GuideboardInfo>
end
rule "calcu_Lp_Wraps"
salience 800
when
$param: CalcuParam($xlId: xlId)
then
List lpInfos = lpRepo.findByXlId($xlId);
Lp_Wraps lp_wraps = new Lp_Wraps();
lp_wraps.setXlId($xlId);
lp_wraps.setLpMap(new HashMap());
for (int i = 0; i < lpInfos.size(); i++) {
GuideboardInfo lpInfo = (GuideboardInfo) lpInfos.get(i);
if (!lpInfo.getIsCancel()) {
lp_wraps.getLpMap().put(lpInfo.getId(), lpInfo);
}
}
insert(lp_wraps);
LOG.info("第一阶段 --> 2、路牌信息载入 calcu_Lp_Wraps 有效路牌数={}", lpInfos.size());
end
// 3、人员信息载入
declare EmployeeConfig_Wraps
xlId: Integer // 线路Id
ecMap: Map // 人员配置Map Map<id, EmployeeConfigInfo>
end
rule "calcu_EmployeeConfig_Wraps"
salience 800
when
$param: CalcuParam($xlId: xlId)
then
List ecInfos = ecRepo.findByXlId($xlId);
EmployeeConfig_Wraps employeeConfig_wraps = new EmployeeConfig_Wraps();
employeeConfig_wraps.setXlId($xlId);
employeeConfig_wraps.setEcMap(new HashMap());
for (int i = 0; i < ecInfos.size(); i++) {
EmployeeConfigInfo ecInfo = (EmployeeConfigInfo) ecInfos.get(i);
if (!ecInfo.getIsCancel()) {
employeeConfig_wraps.getEcMap().put(ecInfo.getId(), ecInfo);
}
}
insert(employeeConfig_wraps);
LOG.info("第一阶段 --> 3、人员信息载入 calcu_EmployeeConfig_Wraps 有效人员配置数={}", ecInfos.size());
end
//------------------ 第二阶段、规则载入,计算相关数量 -----------------//
declare Rule_Wraps
xlId: Integer // 线路Id
qyrq: Date // 启用日期
rule: ScheduleRule1Flat // ScheduleRule1Flat规则
end
rule "calcu_schedule_rule_wrap"
salience 700
when
$param: CalcuParam($xlId: xlId)
$rule: ScheduleRule1Flat($qyrq: qyrq) from ruleRepo.findByXlId($xlId)
then
Rule_Wraps rw = new Rule_Wraps();
rw.setXlId($xlId);
rw.setQyrq($qyrq);
rw.setRule($rule);
insert(rw);
end
rule "calcu_all_rule_count"
salience 600
when
$param: CalcuParam($xlId: xlId, $fd: fromDate, $td: toDate)
$allList: ArrayList() from collect(Rule_Wraps(xlId == $xlId))
then
result.setXlId($xlId);
result.setCount($allList.size());
LOG.info("第二阶段 --> 规则总数={}", $allList.size());
end
rule "calcu_all_qy_rule_count"
salience 500
when
$param: CalcuParam($xlId: xlId, $fd: fromDate, $td: toDate)
$qyList: ArrayList() from collect(
Rule_Wraps(xlId == $xlId, qyrq.getTime() <= $td.getMillis()))
then
result.setXlId($xlId);
result.setQyCount($qyList.size());
LOG.info("第二阶段 --> 启用规则数={}", $qyList.size());
end
//------------------ 第三阶段、规则判定 -----------------//
rule "calcu_Wrap_input"
salience 400
when
$param: CalcuParam($xlId: xlId, $fd: fromDate, $td: toDate)
$qy_rule: Rule_Wraps(xlId == $xlId, qyrq.getTime() <= $td.getMillis())
$cc: CarConfig_Wraps(xlId == $xlId)
$lp: Lp_Wraps(xlId == $xlId)
$ec: EmployeeConfig_Wraps(xlId == $xlId)
then
WrapInput wr = new WrapInput(
$qy_rule.getRule(),
$cc.getCcMap(),
$lp.getLpMap(),
$ec.getEcMap()
);
insert(wr);
end
rule "calcu_error_info"
salience 300
when
$param: CalcuParam($xlId: xlId)
$errorMap: Map() from accumulate ($wr: WrapInput(xlId == $xlId), srif($wr))
then
result.setQyErrorCount($errorMap.size());
result.getErrorInfos().addAll($errorMap.values());
LOG.info("第三阶段 --> 规则总数={}, 启用规则数={}, 错误的启用规则数={}",
result.getCount(), result.getQyCount(), result.getQyErrorCount());
end