flowable

1、安装flowable

第一步:先安装docker
 sudo wget -qO- https://get.docker.com | sh
第二步:启动docker
 systemctl start docker
第三步: 安装flowable docker镜像
docker run -p8080:8080 flowable/flowable-rest  
安装后启动报错, ctrl-c 退出后 安装如下:
 docker run -p8080:8080 flowable/all-in-one
第四步访问系统  admin 密码 test
Flowable Modeler; http://localhost:8080/flowable-modeler
Flowable Task; http://localhost:8080/flowable-task
Flowable Admin; http://localhost:8080/flowable-admin
Flowable IDM; http://localhost:8080/flowable-idm
(login/password: admin/test)

2、springboot集成

参考:https://blog.csdn.net/liuwenjun05101/article/details/86669057

把里边代码下载下来:https://gitee.com/lwj/flow-modeler-sduty.git

3、项目集成

二种方式集成:
    1)使用bpmn格式的.xml文件定义流程序
    2)使用ui页面定义流程,数据会保存到数据库中(在act_de_model表)

第一种方式网上很多,在这里采用第二张方式:

   

1)在ui页面上定义流程

重启服务流程简单实例:

 

 

 

 

 

 

 

2)Check类、Restart类

public class Check implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) {
        System.out.println("开始");
    }
}
public class Restart implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) {
        Object count = delegateExecution.getVariable("count");
        Integer count1 = (Integer) count;
        if(count1 == null) {
            count1 = 0;
        }
        // TODO 执行重启操作  如果重启失败:count+1
        delegateExecution.setVariable("count",count1+1);
        System.out.println("执行"+count1+"次");
    }
}

3)部署运行

package org.flow.web.ui.rest;

import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.ui.modeler.domain.Model;
import org.flowable.ui.modeler.serviceapi.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Description: web方式测试访问:目的开启流程
 * @Author: 
 * @Version: 1.0
 * @Create Date Time: 2019/9/3 15:29
 * @Update Date Time:
 * @see
 */
@RestController
@RequestMapping("/deployment")
public class DeployMentController {
    @Autowired
    ModelService modelService;

    @Autowired
    TaskService taskService;

    @Autowired
    RepositoryService repositoryService;

    @Autowired
    SpringProcessEngineConfiguration springProcessEngineConfiguration;

    @GetMapping("/{id}")
    public String deployment(@PathVariable String id){
        // 模型id,act_de_model表的id
        Model modelData = modelService.getModel(id);
        byte[] bytes = modelService.getBpmnXML(modelData);
        if(bytes==null){
            return "请先设计流程并保存";
        }
        BpmnModel model = modelService.getBpmnModel(modelData);
        if(model.getProcesses().size()==0){
            return "数据模型不符要求,请至少设计一条主线流程。";
        }
        byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
        String processName = modelData.getName()+".bpmn20.xml";
        // 部署,部署之后的流程图才可以用来创建流程实例
        // todo:部署之后的效果应该是一次部署多次使用,需要查看一下如何部署
        repositoryService.createDeployment()
                .name(modelData.getName())
                .addBytes(processName,bpmnBytes)
                .deploy();
        return "部署成功";
    }

    @GetMapping("/run/{key}")
    public String run(@PathVariable String key){
        // 获取流程定义
        // 获取流程引擎
        ProcessEngine processEngine = springProcessEngineConfiguration.buildProcessEngine();

        // 获取运行时service,可以在这里配置参数
        RuntimeService runtimeService = processEngine.getRuntimeService();
        // 添加全局事件监听,需实现FlowableEventListener接口
        // runtimeService.addEventListener();


        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("count",1);
        // 创建流程实例并且指定参数,该参数在全局事件监听中是可以使用的。
        runtimeService.startProcessInstanceByKey(id,variables);
        return "运行成功";
    }

}

4)访问:

http://localhost:8989/flow-study/deployment/id

id:该流程id

http://localhost:8989/flow-study/deployment/run/key

key:该流程的key值

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值