Flowable 工作流API应用与数据库对应展示

模型保存

请求参数分析

流程基本信息 process

{
  "id": "process_8616qrt8",
  "name": "name_d5mdibck"
}

流程图位置信息 svg

<?xml version="1.0" encoding="utf-8"?>
<!-- created with bpmn-js / http://bpmn.io -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="322" height="97"
     viewBox="-31 154 322 97" version="1.1">
    <defs>
        <marker id="sequenceflow-end-white-black-3sruubs92w8hngtoqurf3y84v" viewBox="0 0 20 20" refX="11" refY="10"
                markerWidth="10" markerHeight="10" orient="auto">
            <path d="M 1 5 L 11 10 L 1 15 Z"
                  style="fill: black; stroke-width: 1px; stroke-linecap: round; stroke-dasharray: 10000, 1; stroke: black;"/>
        </marker>
    </defs>
    <g class="djs-group">
        <g class="djs-element djs-shape" data-element-id="Event_02lbc8a" style="display: block;"
           transform="matrix(1 0 0 1 222 182)">
            <g class="djs-visual">
                <circle cx="18" cy="18" r="18"
                        style="stroke: black; stroke-width: 4px; fill: white; fill-opacity: 0.95;"/>
            </g>
            <rect class="djs-hit djs-hit-all" x="0" y="0" width="36" height="36"
                  style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="-6" y="-6" width="48" height="48" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
    <g class="djs-group">
        <g class="djs-element djs-connection" data-element-id="Flow_00van8r" style="display: block;">
            <g class="djs-visual">
                <path d="m  160,200L222,200 "
                      style="fill: none; stroke-width: 2px; stroke: black; stroke-linejoin: round; marker-end: url('#sequenceflow-end-white-black-3sruubs92w8hngtoqurf3y84v');"/>
            </g>
            <polyline points="160,200 222,200 " class="djs-hit djs-hit-stroke"
                      style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="154" y="194" width="74" height="12" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
    <g class="djs-group">
        <g class="djs-element djs-connection" data-element-id="Flow_1eyb522" style="display: block;">
            <g class="djs-visual">
                <path d="m  5,200L60,200 "
                      style="fill: none; stroke-width: 2px; stroke: black; stroke-linejoin: round; marker-end: url('#sequenceflow-end-white-black-3sruubs92w8hngtoqurf3y84v');"/>
            </g>
            <polyline points="5,200 60,200 " class="djs-hit djs-hit-stroke"
                      style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="-1" y="194" width="67" height="12" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
    <g class="djs-group">
        <g class="djs-element djs-shape" data-element-id="event_start" style="display: block;"
           transform="matrix(1 0 0 1 -25 185)">
            <g class="djs-visual">
                <circle cx="15" cy="15" r="15"
                        style="stroke: black; stroke-width: 2px; fill: white; fill-opacity: 0.95;"/>
            </g>
            <rect class="djs-hit djs-hit-all" x="0" y="0" width="30" height="30"
                  style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="-6" y="-6" width="42" height="42" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
    <g class="djs-group">
        <g class="djs-element djs-shape" data-element-id="startNode1_label" style="display: block;"
           transform="matrix(1 0 0 1 -23 222)">
            <g class="djs-visual">
                <text lineHeight="1.2" class="djs-label"
                      style="font-family: Arial, sans-serif; font-size: 11px; font-weight: normal; fill: black;">
                    <tspan x="0" y="9.899999999999999">开始</tspan>
                </text>
            </g>
            <rect class="djs-hit djs-hit-all" x="0" y="0" width="23" height="14"
                  style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="-6" y="-6" width="35" height="26" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
    <g class="djs-group">
        <g class="djs-element djs-shape" data-element-id="khjl001" style="display: block;"
           transform="matrix(1 0 0 1 60 160)">
            <g class="djs-visual">
                <rect x="0" y="0" width="100" height="80" rx="10" ry="10"
                      style="stroke: black; stroke-width: 2px; fill: white; fill-opacity: 0.95;"/>
                <text lineHeight="1.2" class="djs-label"
                      style="font-family: Arial, sans-serif; font-size: 12px; font-weight: normal; fill: black;">
                    <tspan x="50" y="43.599999999999994"/>
                </text>
                <path d="m 15,12 c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 -4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 zm -8,6 l 0,5.5 m 11,0 l 0,-5"
                      style="fill: white; stroke-width: 0.5px; stroke: black;"/>
                <path d="m 15,12 m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 -2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 "
                      style="fill: white; stroke-width: 0.5px; stroke: black;"/>
                <path d="m 15,12 m -6.9,-3.80 c 0,0 2.25099998,-2.358 4.27399998,-1.177 2.024,1.181 4.221,1.537 4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 -4.20799998,3.36699999 -4.20699998,4.34799999 z"
                      style="fill: black; stroke-width: 0.5px; stroke: black;"/>
            </g>
            <rect class="djs-hit djs-hit-all" x="0" y="0" width="100" height="80"
                  style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="-6" y="-6" width="112" height="92" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
    <g class="djs-group">
        <g class="djs-element djs-shape" data-element-id="Event_02lbc8a_label" style="display: block;"
           transform="matrix(1 0 0 1 195 225)">
            <g class="djs-visual">
                <text lineHeight="1.2" class="djs-label"
                      style="font-family: Arial, sans-serif; font-size: 11px; font-weight: normal; fill: black;">
                    <tspan x="0" y="9.899999999999999">结束</tspan>
                </text>
            </g>
            <rect class="djs-hit djs-hit-all" x="0" y="0" width="90" height="20"
                  style="fill: none; stroke-opacity: 0; stroke: white; stroke-width: 15px;"/>
            <rect x="-6" y="-6" width="102" height="32" class="djs-outline" style="fill: none;"/>
        </g>
    </g>
</svg>

流程图实例信息(关键) xml

<?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:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0"
             xmlns:flowable="http://flowable.org/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.flowable.org/processdef">
    <process id="process_8616qrt8" name="name_d5mdibck">
        <documentation>随便一个</documentation>
        <extensionElements>
            <flowable:executionListener class="com.bu.xxx" event="take"/>
        </extensionElements>
        <startEvent id="event_start" name="开始" flowable:formKey="表单11key" flowable:initiator="zhangs">
            <documentation>开始节点</documentation>
            <outgoing>Flow_1eyb522</outgoing>
        </startEvent>
        <sequenceFlow id="Flow_1eyb522" sourceRef="event_start" targetRef="khjl001"/>
        <userTask id="khjl001" name="客户经理" flowable:candidateGroups="90112111">
            <documentation>客户经理</documentation>
            <incoming>Flow_1eyb522</incoming>
            <outgoing>Flow_00van8r</outgoing>
        </userTask>
        <endEvent id="Event_02lbc8a" name="结束">
            <documentation>结束节点</documentation>
            <extensionElements>
                <flowable:executionListener class="com.bu.xxx" event="end"/>
            </extensionElements>
            <incoming>Flow_00van8r</incoming>
        </endEvent>
        <sequenceFlow id="Flow_00van8r" sourceRef="khjl001" targetRef="Event_02lbc8a"/>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_flow">
        <bpmndi:BPMNPlane id="BPMNPlane_flow" bpmnElement="process_8616qrt8">
            <bpmndi:BPMNEdge id="Flow_1eyb522_di" bpmnElement="Flow_1eyb522">
                <di:waypoint x="5" y="200"/>
                <di:waypoint x="60" y="200"/>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge id="Flow_00van8r_di" bpmnElement="Flow_00van8r">
                <di:waypoint x="160" y="200"/>
                <di:waypoint x="222" y="200"/>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNShape id="BPMNShape_startNode1" bpmnElement="event_start" bioc:stroke="">
                <omgdc:Bounds x="-25" y="185" width="30" height="30"/>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds x="-23" y="222" width="23" height="14"/>
                </bpmndi:BPMNLabel>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape id="Activity_17r1b2u_di" bpmnElement="khjl001">
                <omgdc:Bounds x="60" y="160" width="100" height="80"/>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape id="Event_02lbc8a_di" bpmnElement="Event_02lbc8a">
                <omgdc:Bounds x="222" y="182" width="36" height="36"/>
                <bpmndi:BPMNLabel>
                    <omgdc:Bounds x="195" y="225" width="90" height="20"/>
                </bpmndi:BPMNLabel>
            </bpmndi:BPMNShape>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

流程部署API

核心 API 

RepositoryService 流程图管理

deploy 负责deploy部署
String tenantId = UUID.randomUUID().toString();
        repositoryService.createDeployment()
                .name(processName)
                // 租户
                .tenantId(tenantId)
                // 种类
                .category(processName)
                .deploymentProperty("name", processName)
                .deploymentProperty("path", processPath)
                // 工作流文件位置
                .addClasspathResource("processes/" + processPath)
                // 部署
                .deploy();
ACT_RE_DEPLOYMENT 存储部署信息 与 API 映射保持一致 

ACT_GE_BYTEARRAY [deployment_id] 流程资源 XML 信息 与 ACT_RE_DEPLOYMENT [id] 关联

ACT_RE_PROCDEF [deployment_id] 流程基本信息 与 ACT_RE_DEPLOYMENT [id] 关联

suspend 中断流程
/**
     * @param id
     * @return 中断
     */
    @Override
    public boolean suspendDeployment(String id) {
        try {
            repositoryService.suspendProcessDefinitionById(id);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
ACT_RE_PROCDEF [SUSPENSION_STATE_] 字段表示流程状态 1 启用 2 中断

active 启用流程图

    /**
     * @param id
     * @return 唤醒
     */
    @Override
    public boolean activeDeployment(String id) {
        try {
            repositoryService.activateProcessDefinitionById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
ACT_RE_PROCDEF [SUSPENSION_STATE_] 字段表示流程状态 1 启用 2 中断
deleteDeployment 删除流程

    @Override
    public boolean deleteDeployment(String deployId) {
        repositoryService.deleteDeployment(deployId);
        return true;
    }
listDeployment 查询流程图列表(自定义查询sql)
select p.ID_               id,
        d.NAME_             name,
        d.CATEGORY_         category,
        d.TENANT_ID_        tenantId,
        d.DEPLOY_TIME_      deploymentTime,
        d.KEY_              'key',
        p.DEPLOYMENT_ID_    deployId,
        p.NAME_             xmlName,
        p.RESOURCE_NAME_    fileName,
        p.SUSPENSION_STATE_ state
        from ACT_RE_DEPLOYMENT d
        left join ACT_RE_PROCDEF p
        on d.ID_ = p.DEPLOYMENT_ID_
        order by d.DEPLOY_TIME_ desc

RuntimeService 流程管理

启动流程 createProcessInstanceBuilder



    @Override
    public void startProcess(String deployId, Object param01) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("variable", param01);
        ProcessInstance start = runtimeService.createProcessInstanceBuilder()
                .processDefinitionId(deployId)
                .variables(param)
                // 节点执行人
                .tenantId("bhz")
                .name("启动了")
                .start();
    }

流程查询接口 createProcessInstanceQuery


    @Override
    public List<ProcessInstanceDto> listProcess(Integer pageNum, Integer pageSize) {
        List<ProcessInstance> list = runtimeService.createProcessInstanceQuery()
                .listPage(pageNum, pageSize);
        return list.stream().map(i -> {
            // 获取流程携带参数
            Map<String, Object> variables = runtimeService.getVariables(i.getId());
            ProcessInstanceDto processInstanceDto = new ProcessInstanceDto();
            BeanUtils.copyProperties(i, processInstanceDto);
            processInstanceDto.setVars(variables);
            return processInstanceDto;
        }).collect(Collectors.toList());
    }

ACT_RU_EXECUTION 存储启动的流程实例

获取流程携带参数  getVariables

Map<String, Object> variables = runtimeService.getVariables(i.getId());

TaskService 任务管理

ACT_RU_TASK 任务数据信息(流程启动Task任务表已经存在任务数据)
查询任务数据信息 ACT_RU_TASK [ PROC_INST_ID_ ]  ACT_RU_VARIABLE [PROC_INST_ID_ ] 保持一致
select t.ID_ id,
        t.EXECUTION_ID_ executionId,
        t.PROC_INST_ID_ processInstanceId,
        t.PROC_DEF_ID_ processDefinitionId,
        t.NAME_ name,
        t.DESCRIPTION_ description,
        t.ASSIGNEE_ assignee,
        t.OWNER_ owner,
        t.TENANT_ID_ tenantId,
        t.REV_ rev,
        t1.BYTES_ bytes
        from ACT_RU_TASK t
        left join (
        select y.BYTES_,v.PROC_INST_ID_ -- 流程图 , 实例id
        from ACT_RU_VARIABLE v inner join ACT_GE_BYTEARRAY y on v.BYTEARRAY_ID_ = y.ID_
        ) t1 on t.PROC_INST_ID_ = t1.PROC_INST_ID_
        order by t.CREATE_TIME_ desc
任务审核提交 complete

    public Boolean complete(String id, String commonContext) {
        try {
            // 审批意见
            HashMap<String, Object> param = new HashMap<>();
            param.put("commonContext", commonContext);
            taskService.complete(id, param);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

提交完成的数据保存在  ACT_HI_TASKINST 表、ACT_RU_TASK 只保留待执行任务

调单 claim (任务id,操作人) 操作人解厄下来任务的执行人

    public Boolean claim(String id, String name) {
        try {
            // 取消调单
            taskService.unclaim(id);
            // 调单
            taskService.claim(id, name);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
未调单数据

调单后数据

HistoryService 历史信息查询

历史流程查询 createHistoricTaskInstanceQuery

历史任务查询 createHistoricProcessInstanceQuery

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值