项目地址:https://gitee.com/lwj/flowable.git 分支flowable-base
视频地址:https://www.bilibili.com/video/av79774697/
*业务场景:
往往在我们实际业务中,规则异常重要,比方说输入一批数据得到某些结果数据,从而来简化我们的BPMN流程图,
*
flowableDMN规则引擎几种类型解释
单一命中
第一个(FIRST)
可以匹配多个(重叠)具有不同输出条目的规则。返回规则顺序中的第一次命中(返回后停止评估)。
唯一(UNIQUE)
没有重叠的可能,所有规则都是互斥的。只能匹配到一条规则。
如果多个会报错
可以利用设置解决这个问题
dmnEngine.getDmnEngineConfiguration().setStrictMode(false);
优先级(PRIORITY)
具有不同的输出条目的多个规则可以匹配。此策略返回具有最高输出优先级的匹配规则。输出优先级在输出值的有序列表中按优先级递减的顺序指定。当禁用strict mode且未定义输出值时,结果是最后一个有效规则。(违规将以验证消息的形式出现)
任何(ANY)
可能会有重叠,但如果所有匹配规则显示每个输出的输出条目相等,就可以使用任何匹配。如果输出条目不相等,则命中策略不正确,结果将为空并标记为failed。当禁用strict mode时,结果是最后一个有效规则。(违规将以验证消息的形式出现)
多重命中
输出顺序(OUTPUT ORDER)
按输出优先级递减的顺序返回所有命中规则。输出优先级在输出值的有序列表中按优先级递减的顺序指定。
规则顺序(RULE ORDER)
按规则顺序返回所有命中。
1、叠加变量
${output1 + 10}
2、包含 任意都在
输入:
List inputVariable1 = Arrays.asList("test1", "test2", "test3");
processVariablesInput.put("collection1", inputVariable1);
输出:
test2 or test5 in collection1
${collection:containsAny(collection1, '"test2", "test5"')}
3、传入对象
输入:
Person customerOne = new Person();
customerOne.setName("test1");
customerOne.setAge(10L);
processVariablesInput.put("customerOne", customerOne);
输出:${collection:contains("test1", customerOne.name)}
4、json传入匹配 IN 两个并且都在
输入:
ArrayNode arrayNode1 = objectMapper.createArrayNode().add("test1").add("test2").add("test3");
processVariablesInput.put("arrayNode1", arrayNode1);
输出:"test1 and test2 in arrayNode1"
${collection:contains(arrayNode1, '"test1", "test2"')}
5、不包含 任意都不在
传入:
List inputVariable1 = Arrays.asList("test1", "test2", "test3");
processVariablesInput.put("collection1", inputVariable1);
表达式:test3 and / or test6 not in collection1
${collection:notContainsAny(collection1, '"test3", "test6"')}
6、不包含 not in 两个并且都不在
输入:
List inputVariable1 = Arrays.asList("test1", "test2", "test3");
processVariablesInput.put("collection1", inputVariable1);
输出:
test3 and test5 not in collection1
${collection:notContains(collection1, '"test3", "test5"')}
1、叠加变量
${output1 + 10}
2、包含 任意都在
输入:
List inputVariable1 = Arrays.asList(“test1”, “test2”, “test3”);
processVariablesInput.put(“collection1”, inputVariable1);
输出:
test2 or test5 in collection1
c
o
l
l
e
c
t
i
o
n
:
c
o
n
t
a
i
n
s
A
n
y
(
c
o
l
l
e
c
t
i
o
n
1
,
′
"
t
e
s
t
2
"
,
"
t
e
s
t
5
"
′
)
3
、
传
入
对
象
输
入
:
P
e
r
s
o
n
c
u
s
t
o
m
e
r
O
n
e
=
n
e
w
P
e
r
s
o
n
(
)
;
c
u
s
t
o
m
e
r
O
n
e
.
s
e
t
N
a
m
e
(
"
t
e
s
t
1
"
)
;
c
u
s
t
o
m
e
r
O
n
e
.
s
e
t
A
g
e
(
10
L
)
;
p
r
o
c
e
s
s
V
a
r
i
a
b
l
e
s
I
n
p
u
t
.
p
u
t
(
"
c
u
s
t
o
m
e
r
O
n
e
"
,
c
u
s
t
o
m
e
r
O
n
e
)
;
输
出
:
{collection:containsAny(collection1, '"test2", "test5"')} 3、传入对象 输入: Person customerOne = new Person(); customerOne.setName("test1"); customerOne.setAge(10L); processVariablesInput.put("customerOne", customerOne); 输出:
collection:containsAny(collection1,′"test2","test5"′)3、传入对象输入:PersoncustomerOne=newPerson();customerOne.setName("test1");customerOne.setAge(10L);processVariablesInput.put("customerOne",customerOne);输出:{collection:contains(“test1”, customerOne.name)}
4、json传入匹配 IN 两个并且都在
输入:
ArrayNode arrayNode1 = objectMapper.createArrayNode().add(“test1”).add(“test2”).add(“test3”);
processVariablesInput.put(“arrayNode1”, arrayNode1);
输出:“test1 and test2 in arrayNode1”
${collection:contains(arrayNode1, ‘“test1”, “test2”’)}
5、不包含 任意都不在
传入:
List inputVariable1 = Arrays.asList(“test1”, “test2”, “test3”);
processVariablesInput.put(“collection1”, inputVariable1);
表达式:test3 and / or test6 not in collection1
${collection:notContainsAny(collection1, ‘“test3”, “test6”’)}
6、不包含 not in 两个并且都不在
输入:
List inputVariable1 = Arrays.asList(“test1”, “test2”, “test3”);
processVariablesInput.put(“collection1”, inputVariable1);
输出:
test3 and test5 not in collection1
${collection:notContains(collection1, ‘“test3”, “test5”’)}
1、叠加变量
${output1 + 10}
2、包含 任意都在
输入:
List inputVariable1 = Arrays.asList(“test1”, “test2”, “test3”);
processVariablesInput.put(“collection1”, inputVariable1);
输出:
test2 or test5 in collection1
c
o
l
l
e
c
t
i
o
n
:
c
o
n
t
a
i
n
s
A
n
y
(
c
o
l
l
e
c
t
i
o
n
1
,
′
"
t
e
s
t
2
"
,
"
t
e
s
t
5
"
′
)
3
、
传
入
对
象
输
入
:
P
e
r
s
o
n
c
u
s
t
o
m
e
r
O
n
e
=
n
e
w
P
e
r
s
o
n
(
)
;
c
u
s
t
o
m
e
r
O
n
e
.
s
e
t
N
a
m
e
(
"
t
e
s
t
1
"
)
;
c
u
s
t
o
m
e
r
O
n
e
.
s
e
t
A
g
e
(
10
L
)
;
p
r
o
c
e
s
s
V
a
r
i
a
b
l
e
s
I
n
p
u
t
.
p
u
t
(
"
c
u
s
t
o
m
e
r
O
n
e
"
,
c
u
s
t
o
m
e
r
O
n
e
)
;
输
出
:
{collection:containsAny(collection1, '"test2", "test5"')} 3、传入对象 输入: Person customerOne = new Person(); customerOne.setName("test1"); customerOne.setAge(10L); processVariablesInput.put("customerOne", customerOne); 输出:
collection:containsAny(collection1,′"test2","test5"′)3、传入对象输入:PersoncustomerOne=newPerson();customerOne.setName("test1");customerOne.setAge(10L);processVariablesInput.put("customerOne",customerOne);输出:{collection:contains(“test1”, customerOne.name)}
4、json传入匹配 IN 两个并且都在
输入:
ArrayNode arrayNode1 = objectMapper.createArrayNode().add(“test1”).add(“test2”).add(“test3”);
processVariablesInput.put(“arrayNode1”, arrayNode1);
输出:“test1 and test2 in arrayNode1”
${collection:contains(arrayNode1, ‘“test1”, “test2”’)}
5、不包含 任意都不在
传入:
List inputVariable1 = Arrays.asList(“test1”, “test2”, “test3”);
processVariablesInput.put(“collection1”, inputVariable1);
表达式:test3 and / or test6 not in collection1
${collection:notContainsAny(collection1, ‘“test3”, “test6”’)}
6、不包含 not in 两个并且都不在
输入:
List inputVariable1 = Arrays.asList(“test1”, “test2”, “test3”);
processVariablesInput.put(“collection1”, inputVariable1);
输出:
test3 and test5 not in collection1
${collection:notContains(collection1, ‘“test3”, “test5”’)}
采集(COLLECT)
以任意顺序返回所有命中。我们可以添加运算符(+,<,>,#)来将一个简单函数应用于输出。如果没有运算符,则结果是所有输出条目的列表。
+(总和):决策表的结果是所有不同输出的总和。
<(最小值):决策表的结果是所有输出中的最小值。
‘>(最大值):决策表的结果是所有输出中的最大值。
#(计数):决策表的结果是不同输出的数量。