# 班级决策
Camunda 支持DMN1.3版本,在BPMN业务活动流程中,可通过业务规则任务调用DMN决策。DMN决策目的是想把业务代码和决策进行解耦,使决策分析人员只需关心决策即可。
# 需求描述
通过幼儿园学生年龄age和身高height分配不同的班级,决策表可随时修改。校长审核时向流程中传递决策表所需要的流程变量age、height。流程径流决策表后自动提交到相关班级老师审批。
决策规则说明
大于3岁并且身高高于70cm,可上幼儿园小班
大于等于5岁并且身高高于95cm,可上幼儿园中班
大于7岁并且身高高于120cm,可上幼儿园大班
# BPMN建模
设计校长审核并进行分班的流程模型
规则任务节点的实施设置为DMN,并按照图中进行了配置
# XML内容
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:process id="Process_choice_class" name="班级决策" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0fss2gh</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0fss2gh" sourceRef="StartEvent_1" targetRef="Activity_1nqmntb" />
<bpmn:userTask id="Activity_1nqmntb" name="校长审核" camunda:assignee="${customer}">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="age" label="年龄" type="long" defaultValue="1" />
<camunda:formField id="height" label="身高" type="long" defaultValue="0" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0fss2gh</bpmn:incoming>
<bpmn:outgoing>Flow_1w7qdzj</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_1w7qdzj" sourceRef="Activity_1nqmntb" targetRef="Activity_02itx7s" />
<bpmn:businessRuleTask id="Activity_02itx7s" name="判断哪个班级" camunda:resultVariable="dmnResult" camunda:decisionRef="class-choice" camunda:mapDecisionResult="singleEntry">
<bpmn:incoming>Flow_1w7qdzj</bpmn:incoming>
<bpmn:outgoing>Flow_1hcuyt1</bpmn:outgoing>
</bpmn:businessRuleTask>
<bpmn:exclusiveGateway id="Gateway_1c2reel">
<bpmn:incoming>Flow_1hcuyt1</bpmn:incoming>
<bpmn:outgoing>Flow_1oukih7</bpmn:outgoing>
<bpmn:outgoing>Flow_1dghuqc</bpmn:outgoing>
<bpmn:outgoing>Flow_1ry0dxl</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_1hcuyt1" sourceRef="Activity_02itx7s" targetRef="Gateway_1c2reel">
<bpmn:extensionElements>
<camunda:executionListener delegateExpression="${myClassTask}" event="take" />
</bpmn:extensionElements>
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="Flow_1oukih7" name="dmnResult==1" sourceRef="Gateway_1c2reel" targetRef="Activity_0jlob3q">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${dmnResult ==1}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:serviceTask id="Activity_0jlob3q" name="小班" camunda:delegateExpression="${myClassTask}">
<bpmn:incoming>Flow_1oukih7</bpmn:incoming>
<bpmn:outgoing>Flow_121bph1</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1dghuqc" name="dmnResult==2" sourceRef="Gateway_1c2reel" targetRef="Activity_08vymo7">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${dmnResult ==2}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:serviceTask id="Activity_08vymo7" name="中班" camunda:delegateExpression="${myClassTask}">
<bpmn:incoming>Flow_1dghuqc</bpmn:incoming>
<bpmn:outgoing>Flow_0bzrgdf</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1ry0dxl" name="dmnResult==3" sourceRef="Gateway_1c2reel" targetRef="Activity_16865do">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${dmnResult ==3}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:serviceTask id="Activity_16865do" name="大班" camunda:delegateExpression="${myClassTask}">
<bpmn:incoming>Flow_1ry0dxl</bpmn:incoming>
<bpmn:outgoing>Flow_0wftu8w</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_1tksyrl">
<bpmn:incoming>Flow_121bph1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_121bph1" sourceRef="Activity_0jlob3q" targetRef="Event_1tksyrl" />
<bpmn:endEvent id="Event_1u2u83d">
<bpmn:incoming>Flow_0bzrgdf</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0bzrgdf" sourceRef="Activity_08vymo7" targetRef="Event_1u2u83d" />
<bpmn:endEvent id="Event_0gq7hhn">
<bpmn:incoming>Flow_0wftu8w</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0wftu8w" sourceRef="Activity_16865do" targetRef="Event_0gq7hhn" />
</bpmn:process>
</bpmn:definitions>
# DMN建模
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" exporter="Camunda Modeler" exporterVersion="4.11.1" expressionLanguage="https://www.omg.org/spec/DMN/20191111/FEEL/" id="Definitions_appoaprif5r90c" name="DRD" namespace="http://camunda.org/schema/1.0/dmn" typeLanguage="https://www.omg.org/spec/DMN/20191111/FEEL/">
<decision id="class-choice" name="班级判断">
<decisionTable aggregation="MAX" hitPolicy="COLLECT" id="DecisionTable_xxe918s1gxq" preferredOrientation="Rule-as-Row">
<input camunda:inputVariable="A" id="Input_A" label="年龄">
<inputExpression id="InputExpression_A" typeRef="integer">
<text>age</text>
</inputExpression>
</input>
<input id="InputClause_1pmyqs4" label="身高">
<inputExpression id="LiteralExpression_1g9go56" typeRef="number">
<text>height</text>
</inputExpression>
</input>
<output id="Output_A" label="选择班级" name="dmnResult" typeRef="number"/>
<rule id="DecisionRule_14e302t">
<description>大于3岁并且身高高于70cm,可上幼儿园小班</description>
<inputEntry id="UnaryTests_10f17a9">
<text>>3</text>
</inputEntry>
<inputEntry id="UnaryTests_1juonnl">
<text>>70</text>
</inputEntry>
<outputEntry id="LiteralExpression_0sv3naw">
<text>1</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1dzzwnr">
<description>大于等于5岁并且身高高于95cm,可上幼儿园中班</description>
<inputEntry id="UnaryTests_0m4kz9f">
<text>>=5</text>
</inputEntry>
<inputEntry id="UnaryTests_12y1rvm">
<text>>=96</text>
</inputEntry>
<outputEntry id="LiteralExpression_0wovhui">
<text>2</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1rgvsjm">
<description>大于7岁并且身高高于120cm,可上幼儿园大班</description>
<inputEntry id="UnaryTests_0g02yle">
<text>>7</text>
</inputEntry>
<inputEntry id="UnaryTests_0xhd2bf">
<text>>120</text>
</inputEntry>
<outputEntry id="LiteralExpression_0f71spy">
<text>3</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram>
<dmndi:DMNShape dmnElementRef="Definitions_hrsxxe918s1gxq" id="DMNShape_8kn0lmvopu7" isCollapsed="false">
<dc:Bounds height="80" width="180" x="160" y="280"/>
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
# 演示情况
校长提交表单数据,发起流程。 将年龄和身高传给决策表进行班级的选择判断。
预览流程的运行情况。JeecgFlow (opens new window) 找到Camunda站点进行体验。
← 出餐决策