Introduction to several common APIs of Activiti workflow and table analysis

Activiti has several commonly used APIs

1ProcessEngineConfiguration is used to generate ProcessEngine core objects, which gives me the feeling similar to Configuration in Hibernate

//通过ProcessEngineConfiguration来生成ProcessEngine流程引擎对象    
public void generateTables(){
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        configuration.setJdbcDriver("oracle.jdbc.driver.OracleDriver");
        configuration.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:xe");
        configuration.setJdbcUsername("qsw");
        configuration.setJdbcPassword("admin");
        //设置自动建表,一共生成25张表
     configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        configuration.buildProcessEngine();
    }

2RepositoryService object

a.RepositoryService is obtained through ProcessEngine

b.RepositoryService is mainly used to operate operation process deployment and definition, and query process deployment and definition information. It mainly involves four tables: act_re_deployment (process deployment information), act_re_procdef (process definition information), and act_ge_bytearray (the flow chart is stored in it) , act_ge_property (which involves the version number of the process)

Several common functions of c.RepositoryService:

  1. Process deployment and definition
    @Test
    public void deployProcess(){
        //只部署bmpn文件(数据库保存的时候自动生成图片)
//        repositoryService.createDeployment()
//                .addClasspathResource("diagrams/leave.bpmn")
//                .name("请假流程")
//                .deploy();
        //部署bpmn文件和图片,数据库不会自动生成图片,会使用你上传的图片
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("diagrams/leave.bpmn")
                .addClasspathResource("diagrams/leave.png")
                .name("请假流程")
                .deploy();
        System.out.println(deploy.getId()+","+deploy.getName()+","+deploy.getDeploymentTime());

    }

 

 

2.RepositoryService is used to query process deployment information and process definition information

//查询流程部署的信息
 public void queryDeployment(){
        List<Deployment> deployments = repositoryService.createDeploymentQuery()
                .deploymentId("1")
                .deploymentName("请假流程").list();
        for (Deployment dep :
                deployments) {
            System.out.println(dep.getId()+","+dep.getName());
        }
    }
 //流程定义信息的查询
    @Test
    public void queryProcessDefined(){
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
        for (ProcessDefinition definition :
             list) {
            System.out.println(definition.getId()+","+definition.getDeploymentId());
        }
    }

3. Query flow chart

  @Test
    public void queryProcessPicture() throws IOException {
        InputStream is = repositoryService.getProcessDiagram("leaveProcess:2:2504");
        OutputStream os = new FileOutputStream("e:/demo.png");
        FileUtil.copyStream(is,os);
    }

4. Deletion of process definition (the code will not be demonstrated here...)

5. Modification of the process definition. Note that the process definition cannot be modified after it is deployed. You can redeploy one.

 

3.RuntimeService object

a. Mainly used for execution management (including operations such as starting, advancing and deleting process instances), mainly involving the tables act_ru_execution (execution of process instances), ACT_RU_TASK (process instance tasks), ACT_RU_IDENTITYLINK (tasks corresponding to process instances) agent), ACT_HI_ACTINST (the activity history of the process instance, the activity here refers to the collective name of each activity point in the entire process from startPoint to endPoint), ACT_HI_TASKINST (task history, the task refers to the leader in bpmn blocks)

b. It should be noted that process definition and process instance are not the same concept, just like the design drawing of a car and the car are not the same concept. One process definition can start multiple 'new' process instances.

c. Several common operations of RuntimeService

1. The start of the process instance (it can be started according to the id of the process definition, the key of the process definition, and the name of the message),

    //流程的启动(流程实例的启动)
    @Test
    public void processInstanceStart(){
        //1通过流程定义的id
//        ProcessInstance processInstance = runtimeService.startProcessInstanceById("leaveProcess:2:2504");
//        System.out.println("流程实例的id"+processInstance.getId()+",流程实例的名字"+processInstance.getName());
//        System.out.println("流程实例对应的流程定义"+processInstance.getProcessDefinitionId());
        //通过流程定义的key来启动
        ProcessInstance leaveProcess = runtimeService.startProcessInstanceByKey("leaveProcess");
        System.out.println("流程实例的id"+leaveProcess.getId()+",流程实例的name"+leaveProcess.getName());
        System.out.println("流程定义的name"+leaveProcess.getProcessDefinitionKey());

    }

2 Query of process instance (no coding, after all, RepositoryService, the following are basic routines...)

3 The coordinates of the current node of the process (view the location where the current process is running)

  //获取当前流程的节点坐标,为了让用户能够看到当前流程执行到哪个活动点,可以获取图像信息,在页面中通过div来给当前所在节点进行标红
    //单个节点
    @Test
    public void getActiveNodeZuoBiao(){
        String act_id = "doApplicate";
        GraphicInfo info = repositoryService.getBpmnModel("leaveProcess:2:2504").getGraphicInfo(act_id);
        System.out.println("宽度"+info.getWidth());
        System.out.println("高度"+info.getHeight());
        System.out.println("x轴"+info.getX());
        System.out.println("y轴"+info.getY());
    }

4 Forcible deletion of process instances (application scenarios, such as Xiao Wang applying for resignation, but regretting it, immediately canceling the resignation application...)

 //流程实例的硬性删除
    @Test
    public void deleteProcessInstance(){
        runtimeService.deleteProcessInstance("5001","操作失误,不想离职");
    }

4. TaskServcie object (mainly used for handling personal tasks, the tables involved are act_ru_task, act_hi_taskinst)

View personal to-do tasks

 //查询个人待办任务
    @Test
    public void querySelfUncompleteTask(){
        List<Task> tasks = taskService.createTaskQuery()
                .taskAssignee("张三")
                .list();
        for (Task task :
                tasks) {
            System.out.println(task.getId()+","+task.getAssignee());
        }
    }

Personal to-do tasks completed

  //完成个人代办任务
    @Test
    public void completeTask(){
        taskService.complete("7504"); //任务id去act_hi_taskinst表中获取
    }
}

 

In addition, there are HistoryService (history management), IdentityService (organization management), FormService (task form management) and ManagerService. I will not list them one by one. The above APIs are the most commonly used. I personally think that there will be one and the others will follow. Yes, but you have to be familiar with those 25 tables.

Guess you like

Origin blog.csdn.net/qsw2lw/article/details/90224919