1. 程式人生 > >flowable6.4.1任務與dmn結合

flowable6.4.1任務與dmn結合

今年企業對Java開發的市場需求,你看懂了嗎? >>>   

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" id="definitionsRedPacket" name="RedPacket definitions" namespace="http://activiti.org/dmn">
  <decision id="decisionRedPacket" name="RedPacket decision">
    <decisionTable id="decisionTable_1">
      <input id="input_1" label="產品套餐金額">
        <inputExpression id="inputExpression_1" typeRef="integer">
          <text>productMoney</text>
        </inputExpression>
      </input>
      <input id="InputClause_0fog0f8" label="網別">
        <inputExpression id="LiteralExpression_0b54sfq" typeRef="string">
          <text>netTypeCode</text>
        </inputExpression>
      </input>
      <input id="InputClause_1i8c3rx" label="VIP等級">
        <inputExpression id="LiteralExpression_0hxr0c0" typeRef="string">
          <text>vipLevel</text>
        </inputExpression>
      </input>
      <output id="output_1" label="是否贈送紅包" name="isRedPacket" typeRef="boolean" />
      <rule id="DecisionRule_1g3upk5">
        <inputEntry id="UnaryTests_0mjnf3d">
          <text>&gt;=96</text>
        </inputEntry>
        <inputEntry id="UnaryTests_0uor7fo">
          <text>10</text>
        </inputEntry>
        <inputEntry id="UnaryTests_1riltcl">
          <text>.matches("VIP[1-3,5]")</text>
        </inputEntry>
        <outputEntry id="LiteralExpression_0giocoa">
          <text>true</text>
        </outputEntry>
      </rule>
      <rule id="DecisionRule_0vwvbdq">
        <inputEntry id="UnaryTests_1pomr7g">
          <text>&lt;96</text>
        </inputEntry>
        <inputEntry id="UnaryTests_0tpfjhv">
          <text></text>
        </inputEntry>
        <inputEntry id="UnaryTests_1gqyfy4">
          <text></text>
        </inputEntry>
        <outputEntry id="LiteralExpression_0aczaxv">
          <text>false</text>
        </outputEntry>
      </rule>
    </decisionTable>
  </decision>
</definitions>

    public String service() {
        logger.debug("service 開始。");

        Map<String, Object> variables = new HashMap<>();
        variables.put("requestTimeout", "10000");
        String now = LocalTime.now().toString();
        String endDate = LocalTime.now().plusSeconds(10).toString();
        variables.put("now", now);
        variables.put("endDate", endDate);

        variables.put("netTypeCode", "10");
        variables.put("productMoney", 96);
        variables.put("vipLevel", "VIP2");
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("timerRedPacketProcess", variables);

        dmnRepositoryService.createDeployment()//.disableSchemaValidation()
                .addClasspathResource("dmn/RedPacketRule.dmn").deploy();
        logger.debug("service 結束。");
        return pi.getId();
    }
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:flowable="http://flowable.org/bpmn" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test">
  <process id="timerRedPacketProcess" name="定時紅包流程" isExecutable="true">
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask2"></sequenceFlow>
    <startEvent id="startevent1" name="Timer start"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="servicetask2" name="CBSS" activiti:type="http">
      <extensionElements>
        <activiti:field name="requestMethod">
          <activiti:string><![CDATA[GET]]></activiti:string>
        </activiti:field>
        <activiti:field name="requestUrl">
          <activiti:string><![CDATA[http://localhost:8830/cbss]]></activiti:string>
        </activiti:field>
        <activiti:field name="requestHeaders">
          <activiti:expression><![CDATA[Accept: application/json]]></activiti:expression>
        </activiti:field>
        <activiti:field name="requestTimeout">
          <activiti:expression><![CDATA[${requestTimeout}]]></activiti:expression>
        </activiti:field>
        <activiti:field name="resultVariablePrefix">
          <activiti:string><![CDATA[task7]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <intermediateCatchEvent id="timerintermediatecatchevent1" name="定時送紅包">
      <timerEventDefinition>
        <timeDuration>PT3S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="flow6" sourceRef="servicetask2" targetRef="timerintermediatecatchevent1"></sequenceFlow>
    <serviceTask id="servicetask3" name="送紅包" activiti:expression="#{timerRedPacketService.redPacket(execution)}"></serviceTask>
    <sequenceFlow id="flow7" sourceRef="timerintermediatecatchevent1" targetRef="servicetask5"></sequenceFlow>
    <sequenceFlow id="flow9-結束" name="結束流" sourceRef="exclusivegateway1" targetRef="endevent1"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="flow9-結束"></exclusiveGateway>
    <sequenceFlow id="flow10" sourceRef="servicetask3" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow11" sourceRef="exclusivegateway1" targetRef="timerintermediatecatchevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${endDate >= now}]]></conditionExpression>
    </sequenceFlow>
    <serviceTask id="servicetask4" name="贈送規則" activiti:type="dmn">
      <extensionElements>
        <activiti:field name="decisionTableReferenceKey">
          <activiti:string><![CDATA[decisionRedPacket]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow12" sourceRef="servicetask4" targetRef="exclusivegateway2"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway" default="flow14_no_red_packet"></exclusiveGateway>
    <sequenceFlow id="flow13" sourceRef="exclusivegateway2" targetRef="servicetask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${isRedPacket}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow14_no_red_packet" name="不贈送紅包" sourceRef="exclusivegateway2" targetRef="exclusivegateway1"></sequenceFlow>
    <serviceTask id="servicetask5" name="記錄日誌" activiti:expression="#{timerRedPacketService.log(execution)}"></serviceTask>
    <sequenceFlow id="flow14" sourceRef="servicetask5" targetRef="servicetask4"></sequenceFlow>
  </process>
</definitions>

而dmn應該用decision task,見官方論壇: