flowable6.4.1任务与dmn结合

丶灬走出姿态 提交于 2019-12-05 18:51:43

<?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,见官方论坛:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!