Flowable专栏-表数据变化

318 阅读1分钟

我们通过请假流程梳理下表中数据变化

部署请假流程图 image.png

对应的部署文档 holiday-request.bpmn20.xml 放到classpath下

<?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: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/processdef">

    <process id="holidayRequest" name="Holiday Request" isExecutable="true">
        <startEvent id="startEvent"/>
        <sequenceFlow sourceRef="startEvent" targetRef="approveTask"/>
        <userTask id="approveTask" name="Approve or reject request" flowable:candidateGroups="managers"/>
        <sequenceFlow sourceRef="approveTask" targetRef="decision"/>
        <exclusiveGateway id="decision"/>
        <sequenceFlow sourceRef="decision" targetRef="externalSystemCall">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[
                  ${approved}
                ]]>
            </conditionExpression>
        </sequenceFlow>
        <sequenceFlow sourceRef="decision" targetRef="sendRejectionMail">
            <conditionExpression xsi:type="tFormalExpression">
                <![CDATA[
                  ${!approved}
                ]]>
            </conditionExpression>
        </sequenceFlow>
        <serviceTask id="externalSystemCall" name="Enter holidays in external system"
         flowable:class="com.test.flowabletest.CallExternalSystemDelegate"/>
        <sequenceFlow sourceRef="externalSystemCall" targetRef="holidayApprovedTask"/>
        <userTask id="holidayApprovedTask" name="Holiday approved" flowable:assignee="${employee}"/>
        <sequenceFlow sourceRef="holidayApprovedTask" targetRef="approveEnd"/>
        <serviceTask id="sendRejectionMail" name="Send out rejection email"
                  flowable:class="com.test.flowabletest.SendRejectionMail"/>
        <sequenceFlow sourceRef="sendRejectionMail" targetRef="rejectEnd"/>
        <endEvent id="approveEnd"/>
        <endEvent id="rejectEnd"/>
    </process>

</definitions>

请假流程代码:

public class HolidayRequest {

    public static void main(String[] args) {
        //设置数据相关配置
        ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
                .setJdbcUrl("jdbc:mysql://localhost:3306/flowable-test" +
                        "?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true")
                .setJdbcUsername("flowabletest")
                .setJdbcPassword("*****")
                .setJdbcDriver("com.mysql.cj.jdbc.Driver")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        //启动并初始化流程引擎
        ProcessEngine processEngine = cfg.buildProcessEngine();
        //部署流程到流程引擎中
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource("holiday-request.bpmn20.xml")
                .deploy();

        //通过API查询验证流程定义(已经部署在引擎中)
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .deploymentId(deployment.getId())
                .singleResult();
        System.out.println("Found process definition : " + processDefinition.getName());

        //启动流程实例
        RuntimeService runtimeService = processEngine.getRuntimeService();
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("employee", "tom");
        variables.put("nrOfHolidays", 2);
        variables.put("description", "I want to go home with 2 days");
        ProcessInstance processInstance =
                runtimeService.startProcessInstanceByKey("holidayRequest", variables);

        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("managers").list();

        System.out.println("Manager , You have " + tasks.size() + " tasks:");
        for (int i = 0; i < tasks.size(); i++) {
            System.out.println((i + 1) + ") " + tasks.get(i).getName());
        }

        //任务1审批通过
        variables = new HashMap<>();
        variables.put("approved", true);
        taskService.complete(tasks.get(0).getId(), variables);

        tasks = taskService.createTaskQuery().taskAssignee("tom").list();
        System.out.println("Tom , You have " + tasks.size() + " tasks:");
        for (int i = 0; i < tasks.size(); i++) {
            System.out.println((i + 1) + ") " + tasks.get(i).getName());
        }
         //任务2审批通过
        taskService.complete(tasks.get(0).getId());
    }
}

流程部署完成后

ACT_RE_DEPLOYMENT 流程部署记录

image.png

ACT_GE_BYTEARRAY 部署到流程文档保存

image.png

ACT_RE_PROCDEF

image.png

表数据变化:执行到任务节点1前

image.png

ACT_RU_ACTINST image.png

ACT_RU_EXECUTION image.png

ACT_RU_TASK

image.png

ACT_RU_VARIABLE

image.png

ACT_RU_IDENTITYLINK

image.png

ACT_HI_ACTINST与 ACT_RU_ACTINST同 image.png

ACT_HI_PROCINST

image.png

ACT_HI_TASKINST 与 ACT_RU_TASK 同

image.png ACT_HI_VARINST 与 ACT_RU_VARIABLE 同

image.png ACT_HI_IDENTITYLINK 与 ACT_RU_IDENTITYLINK 同

image.png

表数据变化:执行到任务节点1完成,到节点2执行前

image.png

ACT_RU_ACTINST

image.png

ACT_RU_TASK: 只保留当前正在执行执行的任务,id为12的任务已删除 image.png

ACT_RU_EXECUTION: 当前Execution 对应的ActId 变为holidayApprovedTask

image.png

ACT_RU_VARIABLE

image.png

ACT_RU_IDENTITYLINK: 保留当前任务参与人的身份信息, ID为13的记录已删除 image.png

ACT_HI_ACTINST 变化同 ACT_RU_ACTINST

ACT_HI_PROCINST 数据不变

ACT_HI_TASKINST 增加任务记录 image.png

ACT_HI_VARINST 同ACT_RU_ACTINST

ACT_HI_IDENTITYLINK:

image.png

表数据变化:任务节点2执行完成后,流程结束

ACT_RU_* 相关表对应当前实例的数据清空

ACT_HI_ACTINST image.png

ACT_HI_PROCINST 更新结束时间和结束活动 ID image.png

ACT_HI_TASKINST ACT_HI_VARINST 更新结束时间 ACT_HI_IDENTITYLINK 不变