# 出餐决策
通过DMN决策引擎,根据不同的输入(如季节、客人数量等)来决定合适的菜肴。本案例主要根据气温和日期两个参数来决策合适的菜肴。
# 流程建模
应用了出餐决策的流程模型
<?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_dish_decision" name="出餐决策" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_01aovke</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_01aovke" sourceRef="StartEvent_1" targetRef="Activity_0o5ei8e" />
<bpmn:userTask id="Activity_0o5ei8e" name="申请" camunda:assignee="${customer}">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="temperature" label="气温" type="long" defaultValue="1" />
<camunda:formField id="dayType" label="日期类型" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>Flow_01aovke</bpmn:incoming>
<bpmn:outgoing>Flow_1o7bhpj</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="Flow_1o7bhpj" sourceRef="Activity_0o5ei8e" targetRef="Activity_1nib7aw" />
<bpmn:businessRuleTask id="Activity_1nib7aw" name="出餐决策" camunda:resultVariable="desiredDish" camunda:decisionRef="dish-decision" camunda:mapDecisionResult="singleEntry">
<bpmn:incoming>Flow_1o7bhpj</bpmn:incoming>
<bpmn:outgoing>Flow_1l76q4l</bpmn:outgoing>
</bpmn:businessRuleTask>
<bpmn:sequenceFlow id="Flow_1l76q4l" sourceRef="Activity_1nib7aw" targetRef="Activity_1eux7cc" />
<bpmn:serviceTask id="Activity_1eux7cc" name="打印结果" camunda:delegateExpression="${myDecisionTask}">
<bpmn:incoming>Flow_1l76q4l</bpmn:incoming>
<bpmn:outgoing>Flow_0bw1e3o</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_1ro8uoq">
<bpmn:incoming>Flow_0bw1e3o</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0bw1e3o" sourceRef="Activity_1eux7cc" targetRef="Event_1ro8uoq" />
</bpmn:process>
</bpmn:definitions>
BPMN 建模的文件
# 决策建模
建模的可视化效果.dmn在线预览 (opens new window)
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" id="dish" name="Dish" namespace="http://camunda.org/schema/1.0/dmn" exporter="dmn-js (https://demo.bpmn.io/dmn)" exporterVersion="16.6.2">
<inputData id="dayType_id" name="Type of day">
<variable id="dayType_ii" name="Type of day" typeRef="string" />
</inputData>
<inputData id="temperature_id" name="Weather in Celsius">
<variable id="temperature_ii" name="Weather in Celsius" typeRef="integer" />
</inputData>
<knowledgeSource id="host_ks" name="Host" />
<knowledgeSource id="guest_ks" name="Guest Type">
<authorityRequirement id="AuthorityRequirement_0vkhray">
<requiredDecision href="#guestCount" />
</authorityRequirement>
</knowledgeSource>
<businessKnowledgeModel id="elMenu" name="El menú" />
<decision id="dish-decision" name="Dish Decision">
<informationRequirement id="InformationRequirement_1d56kg6">
<requiredDecision href="#guestCount" />
</informationRequirement>
<informationRequirement id="InformationRequirement_11onl5b">
<requiredDecision href="#season" />
</informationRequirement>
<authorityRequirement id="AuthorityRequirement_142y75e">
<requiredAuthority href="#host_ks" />
</authorityRequirement>
<decisionTable id="dishDecisionTable">
<input id="seasonInput" label="Season">
<inputExpression id="seasonInputExpression" typeRef="string">
<text>season</text>
</inputExpression>
</input>
<input id="guestCountInput" label="How many guests">
<inputExpression id="guestCountInputExpression" typeRef="integer">
<text>guestCount</text>
</inputExpression>
</input>
<output id="output1" label="Dish" name="desiredDish" typeRef="string" />
<rule id="row-495762709-1">
<inputEntry id="UnaryTests_1nxcsjr">
<text>"Winter"</text>
</inputEntry>
<inputEntry id="UnaryTests_1r9yorj">
<text><= 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_1mtwzqz">
<text>"Spareribs"</text>
</outputEntry>
</rule>
<rule id="row-495762709-2">
<inputEntry id="UnaryTests_1lxjbif">
<text>"Winter"</text>
</inputEntry>
<inputEntry id="UnaryTests_0nhiedb">
<text>> 8</text>
</inputEntry>
<outputEntry id="LiteralExpression_1h30r12">
<text>"Pasta"</text>
</outputEntry>
</rule>
<rule id="row-495762709-3">
<inputEntry id="UnaryTests_0ifgmfm">
<text>"Summer"</text>
</inputEntry>
<inputEntry id="UnaryTests_12cib9m">
<text>> 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_0wgaegy">
<text>"Light salad"</text>
</outputEntry>
</rule>
<rule id="row-495762709-7">
<inputEntry id="UnaryTests_0ozm9s7">
<text>"Summer"</text>
</inputEntry>
<inputEntry id="UnaryTests_0sesgov">
<text><= 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_1dvc5x3">
<text>"Beans salad"</text>
</outputEntry>
</rule>
<rule id="row-445981423-3">
<inputEntry id="UnaryTests_1er0je1">
<text>"Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_1uzqner">
<text>< 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_1pxy4g1">
<text>"Stew"</text>
</outputEntry>
</rule>
<rule id="row-445981423-4">
<inputEntry id="UnaryTests_06or48g">
<text>"Spring"</text>
</inputEntry>
<inputEntry id="UnaryTests_0wa71sy">
<text>>= 10</text>
</inputEntry>
<outputEntry id="LiteralExpression_09ggol9">
<text>"Steak"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<decision id="season" name="Season decision">
<informationRequirement id="InformationRequirement_1sdwefx">
<requiredInput href="#temperature_id" />
</informationRequirement>
<decisionTable id="seasonDecisionTable">
<input id="temperatureInput" label="Weather in Celsius">
<inputExpression id="temperatureInputExpression" typeRef="integer">
<text>temperature</text>
</inputExpression>
</input>
<output id="seasonOutput" label="season" name="season" typeRef="string" />
<rule id="row-495762709-5">
<inputEntry id="UnaryTests_1fd0eqo">
<text>>30</text>
</inputEntry>
<outputEntry id="LiteralExpression_0l98klb">
<text>"Summer"</text>
</outputEntry>
</rule>
<rule id="row-495762709-6">
<inputEntry id="UnaryTests_1nz6at2">
<text><10</text>
</inputEntry>
<outputEntry id="LiteralExpression_08moy1k">
<text>"Winter"</text>
</outputEntry>
</rule>
<rule id="row-445981423-2">
<inputEntry id="UnaryTests_1a0imxy">
<text>[10..30]</text>
</inputEntry>
<outputEntry id="LiteralExpression_1poftw4">
<text>"Spring"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<decision id="guestCount" name="Guest Count">
<informationRequirement id="InformationRequirement_0j60f3j">
<requiredInput href="#dayType_id" />
</informationRequirement>
<knowledgeRequirement id="KnowledgeRequirement_0n56cqb">
<requiredKnowledge href="#elMenu" />
</knowledgeRequirement>
<decisionTable id="guestCountDecisionTable">
<input id="typeOfDayInput" label="Type of day">
<inputExpression id="typeOfDayInputExpression" typeRef="string">
<text>dayType</text>
</inputExpression>
</input>
<output id="guestCountOutput" label="Guest count" name="guestCount" typeRef="integer" />
<rule id="row-495762709-8">
<inputEntry id="UnaryTests_0l72u8n">
<text>"Weekday"</text>
</inputEntry>
<outputEntry id="LiteralExpression_0wuwqaz">
<text>4</text>
</outputEntry>
</rule>
<rule id="row-495762709-9">
<inputEntry id="UnaryTests_03a73o9">
<text>"Holiday"</text>
</inputEntry>
<outputEntry id="LiteralExpression_1whn119">
<text>10</text>
</outputEntry>
</rule>
<rule id="row-495762709-10">
<inputEntry id="UnaryTests_12tygwt">
<text>"Weekend"</text>
</inputEntry>
<outputEntry id="LiteralExpression_1b5k9t8">
<text>15</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<textAnnotation id="TextAnnotation_1">
<text>Week day or week end</text>
</textAnnotation>
<association id="Association_18hoj4i">
<sourceRef href="#dayType_id" />
<targetRef href="#TextAnnotation_1" />
</association>
<dmndi:DMNDI>
<dmndi:DMNDiagram id="DMNDiagram_05sfxgt">
<dmndi:DMNShape id="DMNShape_1nkrqp5" dmnElementRef="dayType_id">
<dc:Bounds height="45" width="125" x="417" y="377" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_0wgwr3t" dmnElementRef="temperature_id">
<dc:Bounds height="45" width="125" x="188" y="377" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_17n98pm" dmnElementRef="host_ks">
<dc:Bounds height="63" width="100" x="646" y="48" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_1i9incu" dmnElementRef="guest_ks">
<dc:Bounds height="63" width="100" x="660" y="198" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_0tdfvdg" dmnElementRef="AuthorityRequirement_0vkhray">
<di:waypoint x="570" y="245" />
<di:waypoint x="660" y="235" />
</dmndi:DMNEdge>
<dmndi:DMNShape id="DMNShape_1uo50vq" dmnElementRef="elMenu">
<dc:Bounds height="46" width="135" x="642" y="307" />
</dmndi:DMNShape>
<dmndi:DMNShape id="DMNShape_0s7a8pk" dmnElementRef="dish-decision">
<dc:Bounds height="80" width="180" x="301" y="48" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_1cvfntf" dmnElementRef="InformationRequirement_1d56kg6">
<di:waypoint x="480" y="210" />
<di:waypoint x="421" y="148" />
<di:waypoint x="421" y="128" />
</dmndi:DMNEdge>
<dmndi:DMNEdge id="DMNEdge_0djoiii" dmnElementRef="InformationRequirement_11onl5b">
<di:waypoint x="251" y="210" />
<di:waypoint x="361" y="148" />
<di:waypoint x="361" y="128" />
</dmndi:DMNEdge>
<dmndi:DMNEdge id="DMNEdge_0qqxexx" dmnElementRef="AuthorityRequirement_142y75e">
<di:waypoint x="646" y="81" />
<di:waypoint x="481" y="86" />
</dmndi:DMNEdge>
<dmndi:DMNShape id="DMNShape_06z5z89" dmnElementRef="season">
<dc:Bounds height="80" width="180" x="161" y="210" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_1383eyj" dmnElementRef="InformationRequirement_1sdwefx">
<di:waypoint x="251" y="377" />
<di:waypoint x="251" y="310" />
<di:waypoint x="251" y="290" />
</dmndi:DMNEdge>
<dmndi:DMNShape id="DMNShape_0qbhe8q" dmnElementRef="guestCount">
<dc:Bounds height="80" width="180" x="390" y="210" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_131oa1j" dmnElementRef="KnowledgeRequirement_0n56cqb">
<di:waypoint x="691" y="307" />
<di:waypoint x="570" y="262" />
</dmndi:DMNEdge>
<dmndi:DMNEdge id="DMNEdge_1avtdb1" dmnElementRef="InformationRequirement_0j60f3j">
<di:waypoint x="480" y="377" />
<di:waypoint x="480" y="310" />
<di:waypoint x="480" y="290" />
</dmndi:DMNEdge>
<dmndi:DMNShape id="DMNShape_0bblyhb" dmnElementRef="TextAnnotation_1">
<dc:Bounds height="45" width="125" x="328" y="477" />
</dmndi:DMNShape>
<dmndi:DMNEdge id="DMNEdge_0aqnkob" dmnElementRef="Association_18hoj4i">
<di:waypoint x="480" y="422" />
<di:waypoint x="391" y="477" />
</dmndi:DMNEdge>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
以上DMN定义文件
# 演示情况
发起流程,给流程输入气温和日期数据
可以看到流程正常运行。在线体验 (opens new window)