1, Basic knowledge
Workflow:
Workflow is the automatic management of business processes through computer technology. Implement multiple participants to automatically execute the business process according to the predetermined process.
Definition: Automate the management of business processes through computers
The main solution is to enable multiple participants to automatically transfer documents, information or tasks according to some predefined rules So as to achieve a desired business goal or promote the realization of this goal
1.1 workflow engine
ProcessEngine object: This is the core of Activiti's work Responsible for generating various instances and data during process operation, monitoring and managing process operation
1.2BPM: Business Process Management
Business process management is an end-to-end Excellence System with standardized structure
Business process as the center, systematic method for the purpose of continuously improving organizational business performance, common business management education such as EMBA and MBA
BPM is included.
1.3BPMN: business process model and symbol
It is a set of standard business process modeling symbols developed by BPMI (Business Process Management Initiative). Business processes can be created using the symbols provided by BPMN.
Flow object: a business process diagram has three core elements of flow objects
- event
- activity
- condition
2, activiti
2.1 description of activiti table
- ACT_RE process definition and process resources
- ACT_RU runtime, process instance, task, variable
- ACT_HI history table
- ACT_GE general table
https://www.cnblogs.com/telwanggs/p/7491564.html
2.2. activiti's architecture and class relationship
- Get process engine: get the interfaces of various services
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();// Default mode
- //Customization method: 1. Configuration file name; 2. bean name
ProcessEngineConfiguration processEngineConfiguration =
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource
("activiti.cfg.xml","processEngineConfiguration");
- Service interface: used for process deployment, execution, management and operation of corresponding database tables
- RepositoryService resource management class
- RuntimeService runtime management class
- TaskService task management class
- HistoryService historical data management class
- ManagementService process engine management class
2.3. bpmn plug-in actiBPM
Note: actiBPM cannot be found in idea2020 or 2021. Download the locally installed plug-in directly
2.4 flow symbols and flow charts
- Process symbols: Event, Activity, Gateway, flow direction
- Flowchart: using plug-ins
- Create a bpmn file and use process symbols in the process designer to express the process. Specify the key of the process and the task leader
- Generate a png file, change the bpmn suffix to xml, and right-click to select Diagrams – show bpmn2 0 desinger, exporting png files
- Random code problem: Baidu Bar
help – "edit custom vm options..." – add - dfile encoding=UTF-8
2.5. Deployment process: resource class operation RepositoryService
2.5. 1. Deployment operation
- Single file deployment: add bpmn files and png files directly
Deployment deploy = repositoryService.createDeployment() .name("Travel application process") .addClasspathResource("bpmn/evection.bpmn") .addClasspathResource("bpmn/evection.png") .deploy();
- Compressed package deployment: package files into
/** * Read resource package file * this.getClass().getClassLoader().getResourceAsStream("bpmn/evection.zip"); */ InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("bpmn/evection.zip"); ZipInputStream zipInputStream = new ZipInputStream(inputStream); Deployment deploy = repositoryService.createDeployment() .addZipInputStream(zipInputStream) .deploy();
2.5. 2. Deployment operation table
- act_re_deployment deployment table
- act_re_procdef process definition table
- act_ge_bytearray resource table
2.6. Start the process instance RuntimeService
2.6. 1. Start process operation
Start according to the key defined by the process
ProcessInstance session_1 = runtimeService.startProcessInstanceByKey("session_1");
2.6. 2. Operation table
- act_hi_actinst process instance execution history information
- act_ hi_ The history information of the user participating in the identitylink process
- act_ hi_ Historical information of procinst process instance
- act_hi_taskinst historical information of process tasks
- act_ru_execution process execution information
- act_ ru_ Participating user information of the identitylink process
- act_ru_task process current task information
2.7. Task query TaskService
2.7. 1. Query operation
Query according to the key and task leader defined in the process
List<Task> list = taskService.createTaskQuery() .processDefinitionKey("session_1") .taskAssignee("Task leader") .list();
2.8 task completion TaskService
//Get personal task id Task task = taskService.createTaskQuery() .processDefinitionKey("session_1") .taskAssignee("zhangsan") .singleResult(); //Complete the task according to the task id if (task == null) { System.out.println("No task"); return; } taskService.complete(task.getId());
2.9. Deleting a RepositoryService from a process definition
2.9. 1. Delete operation
/** * Delete process deployment information: according to the process deployment id */ @Test public void delDeployMent() { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.deleteDeployment("1"); }
2.9. 2. Operation table
- act_re_deployment deployment table
- act_re_procdef process definition table
- act_ge_bytearray resource table
2.9. 3. Process started but not completed cascade deletion
/** * Delete process deployment information: according to the process deployment id * act_re_deployment Deployment table * act_re_procdef Process definition table * act_ge_bytearray Resource table * The current process has not been completed. You need to use a special method to delete it: cascade deletion */ @Test public void delDeployMent() { //Get engine ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //Get RepositoryService RepositoryService repositoryService = processEngine.getRepositoryService(); //Normal deletion: by deployment id // repositoryService.deleteDeployment("2501"); // Cascade delete: repositoryService.deleteDeployment("2501", true); }
2.10 resource file download
/** * Download resource file * Method 1: use API repository service * Method 2: write your own code to query the database for download (not considered) */ @Test public void getDeployment() throws IOException { //1. Engine ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //2,api RepositoryService repositoryService = processEngine.getRepositoryService(); //3. Get the query object ProcessDefinitionQuery and query the process definition information ProcessDefinitionQuery definitionQuery = repositoryService.createProcessDefinitionQuery(); ProcessDefinition session_1 = definitionQuery.processDefinitionKey("session_1").singleResult(); //4. Obtain the deployment id \ png picture directory and name \ bpmn file directory and name through the process definition information String deploymentId = session_1.getDeploymentId(); String pngName = session_1.getDiagramResourceName(); String bpmnName = session_1.getResourceName(); //5. The deployment id and resource name parameters are passed through the repository service to obtain resource information InputStream pngInput = repositoryService.getResourceAsStream(deploymentId, pngName); InputStream bpmnInput = repositoryService.getResourceAsStream(deploymentId, bpmnName); //6. Construct outputStream File pngFile = new File("d:/zhongtong/evectionflow01.png"); File bpmnFile = new File("d:/zhongtong/evectiondlow01.bpmn"); FileOutputStream pngOutStream = new FileOutputStream(pngFile); FileOutputStream bpmnOutStream = new FileOutputStream(bpmnFile); //7. I / O stream conversion commons IO IOUtils.copy(pngInput, pngOutStream); IOUtils.copy(bpmnInput, bpmnOutStream); //8. Close flow pngOutStream.close(); bpmnOutStream.close(); pngInput.close(); bpmnInput.close(); }
2.11. Viewing historical information
/** * View historical information */ @Test public void getHistoryInfo() { //engine ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); //Get api HistoryService HistoryService historyService = processEngine.getHistoryService(); //Gets the query object of the actinst table HistoricActivityInstanceQuery instanceQuery = historyService.createHistoricActivityInstanceQuery(); //Query the actinst table, condition: InstanceId or DefinitionId List<HistoricActivityInstance> activityInstances = instanceQuery.processInstanceId("") // .processDefinitionId("") //sort .orderByHistoricActivityInstanceStartTime().asc() //Query all content .list(); for (HistoricActivityInstance hi : activityInstances) { System.out.println("hi.getActivityId() = " + hi.getActivityId()); System.out.println("hi.getActivityName() = " + hi.getActivityName()); System.out.println("hi.getProcessDefinitionId() = " + hi.getProcessDefinitionId()); System.out.println("hi.getProcessInstanceId() = " + hi.getProcessInstanceId()); } }