springboot —— flowable

14 篇文章 0 订阅

1、创建springboot项目

2、添加flowable版本依赖,包括数据库等等

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Flowable spring-boot 版套餐 -->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>6.4.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

3、配置yml文件

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/flowable-spring-boot
    username: root
    password: 
    driver-class-name: com.mysql.cj.jdbc.Driver
flowable:
  #关闭定时任务
  async-executor-activate: false

4、创建数据库,数据库为yml配置文件的数据库

5、启动springboot 项目,之后可以看到flowable的所需要的数据库表信息

6、 flowable+tomcat部署flowable项目,在线画流程图。

https://blog.csdn.net/qq_31319235/article/details/122056420

7、将设计好的流程图复制到resources/processes/目录下,如果提示流程未找到,可以将processes目录替换成flows目录

8、然后就可以在contoller中测试设计好的工作流

<?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:flowable="http://flowable.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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
  <process id="one" name="one" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <exclusiveGateway id="sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C"></exclusiveGateway>
    <sequenceFlow id="sid-850F6881-EC3F-4FBB-8D73-1418FAB87220" sourceRef="startEvent1" targetRef="sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C"></sequenceFlow>
    <userTask id="sid-791432D1-AACA-496C-A12F-9258EB149114"></userTask>
    <userTask id="sid-DC38F07C-8EAD-406E-A7AC-17FB77815BD5"></userTask>
    <userTask id="sid-76690B04-AEC8-4B52-AD72-1B2D03C63C9C"></userTask>
    <sequenceFlow id="sid-61034E5D-714A-450A-9A7D-F70106FB8F8E" sourceRef="sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C" targetRef="sid-DC38F07C-8EAD-406E-A7AC-17FB77815BD5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${input==2}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-CA5A023A-447E-4B7B-A65B-9AC2FF1BB977" sourceRef="sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C" targetRef="sid-76690B04-AEC8-4B52-AD72-1B2D03C63C9C">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${input ==3}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90"></exclusiveGateway>
    <sequenceFlow id="sid-C1ED5080-0D69-4E54-8172-7CFB5DAC4105" sourceRef="sid-DC38F07C-8EAD-406E-A7AC-17FB77815BD5" targetRef="sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90"></sequenceFlow>
    <sequenceFlow id="sid-4AB91AF6-0907-48EF-9026-E71DDDD4F0F8" sourceRef="sid-76690B04-AEC8-4B52-AD72-1B2D03C63C9C" targetRef="sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90"></sequenceFlow>
    <endEvent id="sid-93DB5674-D50B-47BD-9837-4BBC22680EEE"></endEvent>
    <sequenceFlow id="sid-774ED41C-33CE-4BE5-986E-6598FCF5262C" sourceRef="sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90" targetRef="sid-93DB5674-D50B-47BD-9837-4BBC22680EEE"></sequenceFlow>
    <sequenceFlow id="sid-97029FB6-AD81-40F2-899D-245679A4B61E" sourceRef="sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C" targetRef="sid-791432D1-AACA-496C-A12F-9258EB149114">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${input==1}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-B657A1B9-16A7-4FEE-A7D8-5FAE341C4EBA" sourceRef="sid-791432D1-AACA-496C-A12F-9258EB149114" targetRef="sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${input==10}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_one">
    <bpmndi:BPMNPlane bpmnElement="one" id="BPMNPlane_one">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C" id="BPMNShape_sid-E3445F3F-A4B3-49C1-99A7-F0169B0EF92C">
        <omgdc:Bounds height="40.0" width="40.0" x="197.5" y="162.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-791432D1-AACA-496C-A12F-9258EB149114" id="BPMNShape_sid-791432D1-AACA-496C-A12F-9258EB149114">
        <omgdc:Bounds height="80.0" width="100.0" x="300.25" y="31.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-DC38F07C-8EAD-406E-A7AC-17FB77815BD5" id="BPMNShape_sid-DC38F07C-8EAD-406E-A7AC-17FB77815BD5">
        <omgdc:Bounds height="80.0" width="100.0" x="300.25" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-76690B04-AEC8-4B52-AD72-1B2D03C63C9C" id="BPMNShape_sid-76690B04-AEC8-4B52-AD72-1B2D03C63C9C">
        <omgdc:Bounds height="80.0" width="100.0" x="300.25" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90" id="BPMNShape_sid-70045EB9-DD09-4DB8-923E-B2BF8AAD8E90">
        <omgdc:Bounds height="40.0" width="40.0" x="526.5" y="171.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-93DB5674-D50B-47BD-9837-4BBC22680EEE" id="BPMNShape_sid-93DB5674-D50B-47BD-9837-4BBC22680EEE">
        <omgdc:Bounds height="28.0" width="28.0" x="712.5" y="186.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-CA5A023A-447E-4B7B-A65B-9AC2FF1BB977" id="BPMNEdge_sid-CA5A023A-447E-4B7B-A65B-9AC2FF1BB977">
        <omgdi:waypoint x="227.64820088512604" y="191.8017324350337"></omgdi:waypoint>
        <omgdi:waypoint x="308.75852606820854" y="270.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-61034E5D-714A-450A-9A7D-F70106FB8F8E" id="BPMNEdge_sid-61034E5D-714A-450A-9A7D-F70106FB8F8E">
        <omgdi:waypoint x="235.92695745441546" y="183.51699463327373"></omgdi:waypoint>
        <omgdi:waypoint x="300.25" y="187.16446124763706"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-774ED41C-33CE-4BE5-986E-6598FCF5262C" id="BPMNEdge_sid-774ED41C-33CE-4BE5-986E-6598FCF5262C">
        <omgdi:waypoint x="565.0886363636363" y="192.3567819148936"></omgdi:waypoint>
        <omgdi:waypoint x="712.5134135194986" y="199.3377759371677"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-97029FB6-AD81-40F2-899D-245679A4B61E" id="BPMNEdge_sid-97029FB6-AD81-40F2-899D-245679A4B61E">
        <omgdi:waypoint x="228.82415384615382" y="173.35128205128206"></omgdi:waypoint>
        <omgdi:waypoint x="302.8060538116592" y="110.95"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-C1ED5080-0D69-4E54-8172-7CFB5DAC4105" id="BPMNEdge_sid-C1ED5080-0D69-4E54-8172-7CFB5DAC4105">
        <omgdi:waypoint x="400.1999999999966" y="190.2545222929936"></omgdi:waypoint>
        <omgdi:waypoint x="526.5569419812515" y="190.89860583016477"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-850F6881-EC3F-4FBB-8D73-1418FAB87220" id="BPMNEdge_sid-850F6881-EC3F-4FBB-8D73-1418FAB87220">
        <omgdi:waypoint x="129.93857240455148" y="178.58297943083323"></omgdi:waypoint>
        <omgdi:waypoint x="198.2136491557223" y="181.2488262910798"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-4AB91AF6-0907-48EF-9026-E71DDDD4F0F8" id="BPMNEdge_sid-4AB91AF6-0907-48EF-9026-E71DDDD4F0F8">
        <omgdi:waypoint x="400.20000000000005" y="279.6815286624204"></omgdi:waypoint>
        <omgdi:waypoint x="534.0495638382237" y="198.5306899286281"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-B657A1B9-16A7-4FEE-A7D8-5FAE341C4EBA" id="BPMNEdge_sid-B657A1B9-16A7-4FEE-A7D8-5FAE341C4EBA">
        <omgdi:waypoint x="400.20000000000005" y="101.5426751592357"></omgdi:waypoint>
        <omgdi:waypoint x="534.0776434329066" y="183.41106719367588"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
package com.example.demo.controller;

import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("flowable")
public class TestController {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;

    @Autowired
    private ProcessEngine processEngine;




    // 查询流程状态
    @GetMapping("status")
    public boolean statusExpense(String id){
       ProcessInstance processInstance =  processEngine.getRuntimeService().createProcessInstanceQuery()
                .processInstanceId(id).singleResult();
       
       return  processInstance == null; // null 表示流程执行完毕

    }
    // 发起流程
    @GetMapping("add")
    public String addExpense(int input){
        Map<String,Object> map =new  HashMap<>();
        map.put("input",input);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("one",map);
        return "success: " + processInstance.getId();

    }
    //流程处理
    @GetMapping("handle")
    public String handleExpense(String taskId){
        List<Task> tasks = taskService.createTaskQuery().list(); // 查询流程所有的任务
        Map<String,Object> map =new  HashMap<>();
        map.put("input",10);
        taskService.complete(taskId,map); // 处理流程,完结
        return "success: " ;

    }
}

service的作用:

RepositoryService 1)查询部署和流程定义。2)挂起或者激活流程部署或者流程定义。大多数是处理一些静态信息。

RuntimeService: 1)用来获取和保存流程变量。2)查询流程实例和当前执行位置。3)流程实例需要等待一个外部触发,从而继续进行。

TaskService:1)查询分配给某人或一组的任务。2)产生独立的任务,不依赖于任何流程实例的任务。3)操纵用户分配任务。4)完成任务。

HistoryService :1)查询各种历史数据

ManagementService:1)查询数据库表信息和表的元数据。2)管理各种 jobs 任务,例如定时器、延迟、挂起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想在Spring Boot项目中使用Flowable,你可以通过引入相应的依赖来实现。根据引用的内容,你可以添加以下依赖到你的项目中: ```xml <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>6.7.2</version> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter-actuator</artifactId> <version>6.7.2</version> </dependency> ``` 你也可以从引用和引用中提供的链接中下载Flowable的zip文件。这些文件包含了Flowable引擎的各个组件和执行器。下载并解压缩zip文件后,你可以将Flowable引擎部署到Tomcat服务器上,从而在Spring Boot项目中使用Flowable。 希望以上信息能帮助到你。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Spring Boot + Flowable 工作流引擎](https://blog.csdn.net/qq_39035773/article/details/125414301)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [SpringBoot + Flowable的使用](https://blog.csdn.net/fajing_feiyue/article/details/116209534)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [SpringBoot + Flowable的基础使用](https://blog.csdn.net/S0001100/article/details/120042604)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值