flowable6.4.1+springboot使用dmn

北城余情 提交于 2019-12-04 05:40:55

resources/dmn/strings_1.dmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd"
             id="simple" name="Simple" namespace="http://activiti.org/dmn">
    <decision id="decision" name="Simple decision">
        <decisionTable id="decisionTable">
            <input>
                <inputExpression id="inputExpression1" typeRef="string">
                    <text>input1</text>
                </inputExpression>
            </input>
            <output id="output1" label="Output 1" name="output1" typeRef="string" />
            <rule>
                <inputEntry id="inputEntry1">
                    <text><![CDATA[.startsWith('test')]]></text>
                </inputEntry>
                <outputEntry id="outputEntry1">
                    <text>'shareniu1'</text>
                </outputEntry>
            </rule>
            <rule>
                <inputEntry id="inputEntry2">
                    <text><![CDATA[.endsWith('test')]]></text>
                </inputEntry>
                <outputEntry id="outputEntry2">
                    <text>'shareniu2'</text>
                </outputEntry>
            </rule>
        </decisionTable>
    </decision>
</definitions>

Service.java

import org.flowable.dmn.api.DmnRepositoryService;
import org.flowable.dmn.api.DmnRuleService;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TimerRedPacketService {

    @Autowired
    private DmnRuleService dmnRuleService;

    @Autowired
    private DmnRepositoryService dmnRepositoryService;

    public void redPacket(DelegateExecution execution) {
        dmnRepositoryService.createDeployment().name("secondDeployment").disableSchemaValidation()
                .addClasspathResource("dmn/strings_1.dmn").tenantId("testTenant")
                .deploy();

        Map<String, Object> processVariablesInput = new HashMap<>();
        processVariablesInput.put("input1", "Stringtest");
        List<Map<String, Object>> result = dmnRuleService.executeDecisionByKey("decision", processVariablesInput);
        System.out.println(result.get(0).get("output1"));
    }

}

resources/flowable.dmn.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="dmnEngineConfiguration" class="org.flowable.dmn.engine.impl.cfg.StandaloneDmnEngineConfiguration">
        <property name="jdbcUrl" value="jdbc:mysql://130.51.23.249:3306/flowable" />
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUsername" value="flowable" />
        <property name="jdbcPassword" value="flowable" />
    </bean>

</beans>

pom.xml

<!--一般已引入flowable-spring-boot-starter,因此下面也可以不需要-->
		<dependency>
			<groupId>org.flowable</groupId>
			<artifactId>flowable-spring-boot-starter-dmn</artifactId>
			<version>${flowable.version}</version>
		</dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!