Implementing an OA Workflow Approval System with Activiti
This article explains how to design and implement a multi‑level approval workflow for an office automation system using the Activiti BPMN engine, covering process diagram creation, Spring Boot configuration, Java code for deployment and task handling, database tables, API overview, and comparisons with similar frameworks.
The author introduces the concept of a workflow approval feature as a core capability of an OA system and emphasizes that a robust workflow engine like Activiti simplifies complex task routing and branch decisions.
Creating the Process Diagram – The first step is to draw a BPMN diagram (e.g., a leave request with primary and secondary supervisor approvals) using the Idea actiBPM plugin, then export it as apply.bpmn .
Deploying and Starting the Process – Using Activiti’s ProcessEngine , the diagram is deployed via RepositoryService . A process instance is started with runtimeService.startProcessInstanceByKey("apply_processor_1", variableMap) , where variables such as applyUser , supervisor , and upperSupervisor are supplied.
Task Execution – Tasks are queried and completed through TaskService . The example shows the applicant completing the leave request task, the primary supervisor setting result1 , and the secondary supervisor setting result2 . Variables are stored in the process context and evaluated by exclusive gateways to determine the next path.
Gateway Logic – The workflow uses exclusive gateways to branch based on approval results ( ${result1==true} ) and leave duration ( ${day>3} ). The engine automatically evaluates these expressions and routes the flow without additional code.
Viewing Execution History – By obtaining HistoryService and querying HistoricActivityInstance , developers can retrieve a complete audit trail of each activity, assignee, and task ID.
Project Configuration – The article provides Maven dependencies for activiti-spring-boot-starter-basic and a sample Spring XML configuration that sets up an H2 in‑memory datasource and the process engine.
Full BPMN XML – A complete XML definition of the leave‑approval process is shown, illustrating start events, user tasks, exclusive gateways, end events, and sequence flows with condition expressions.
Comparisons and Best Practices – Activiti is compared with Camunda and Flowable, noting similar usage steps: define BPMN, deploy, start instance, execute tasks, listen to events, and monitor. The author also lists a five‑step workflow development checklist and further learning directions such as event listeners, task types, form management, and performance tuning.
In conclusion, Activiti enables rapid development of multi‑user approval processes with minimal custom code, requiring only front‑end adjustments and simple back‑end interfaces for new business scenarios.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.