Overall introduction
Based on BPMN2.0 specification design, carry out the design of workflow self-development scheme, refer to the overall design of activiti framework for workflow lite version self-development scheme. The Lite version only designs a solution for simple processes and reserves some implementation slots for complex service logic to achieve simple workflow.
To achieve results
- Implement a simple linear workflow scheme.
- Implementation of user task scheme workflow self-developed version.
- Define workflow flow based on JSON/XML data format (front-end implementation is not reflected here)
Plan to introduce
Process definition Description
In a workflow, a process definition can be graphically expressed as a collection of nodes and connections. The Lite version uses JSON/XML data format to describe the process definition. A process definition description can be defined as a collection of process elements, which can be divided into two categories, node-like elements and line-of-expression elements. Decouple the actions of nodes and joins through node class and wire expression class separation, so that the subsequent implementation can be more flexible.
Node class
A node class is an abstract representation of an action and is divided into start nodes, end nodes, task nodes, and gateway nodes (reserved classes, not currently considered in lite).
Line expression class
Describes the transition relationship between different nodes, including source node, target node and flow rules. Ps: A connection can only have one source node and one destination node.
Implementation conception
The different node classes provide a unified abstract interface class that implements workflow flow through the following process.
[Process Start] - "Start node execution" - "Task node execution" - "Find the next node according to rules and connection expression class -" Next node execution - "..... -- "End node -" "process end" "Complete task" - "Complete task -" "Find the next node according to the rules and connection expression class -" Next node execute - "" create taskCopy the code
The extension points are the gateway nodes and the subprocesses. See Activiti’s Scope for a design implementation.
The process started
Get JSON parsing — execute start node process method — execute the next node process
Complete the task (approval)
Complete the current task (taskId) — execute the next node process — create the task
How do I execute the next node process
Get the targetTransition list based on the current node, and get the next node based on the node attributes and rules. Determine whether a task needs to be created based on the attribute type of the next node.
Database design
Process definition table
Store the information related to the process definition, mainly the JSON data defined by the process.
Key fields :def_context– JSON for process definition fields, describing elements, and relationships
The process defines the node table
Records the data table of the node in the process definition, describing the basic information of the node
Key fields:
Def_id — primary key ID of the process definition table. Node_type — Differentiates node types, such as start, end, Active, gateway node, etc
Node_candidate — node execution candidate, node_listener — node listener for subsequent actions.
Process task sheet
An information data sheet that records tasks in the process. The main information is related to the task, associated task instance ID, process definition ID, current task status, executor, operation information, etc.
Process, template, task/
The flow definition table stores the information related to the flow definition, mainly the JSON data defined by the flow. CREATE TABLE `process_template` ( `id` bigint NOT NULL AUTO_INCREMENT, 'biz_code' varchar(255) CHARACTER SET UTf8MB4 COLLATE UTf8MB4_general_ci NOT NULL COMMENT 'biz_code ', 'template_name' varchar(255) CHARACTER SET UTf8MB4 COLLATE UTf8MB4_general_ci NOT NULL COMMENT ', 'template_key' varchar(255) CHARACTER SET UTf8MB4 COLLATE UTf8MB4_general_ci NOT NULL COMMENT ', 'template_context' JSON NOT NULL COMMENT 'Process context data ',' template_version 'int NOT NULL COMMENT' Process definition version ', 'enable' tinyInt (1) unsigned NOT NULL DEFAULT '1' COMMENT 'Whether is available 0: is NOT available 1: Available ', 'created_at' datetime NOT NULL default current_TIMESTAMP COMMENT ', 'updated_at' datetime NOT NULL default current_TIMESTAMP COMMENT 'update time ', PRIMARY KEY (' id ')) ENGINE=InnoDB DEFAULT CHARSET= UTf8MB4 COLLATE= UTf8MB4_general_ci COMMENT=' process template '; CREATE TABLE 'process_instance' (' id 'bigint NOT NULL AUTO_INCREMENT, 'template_id' bigint NOT NULL COMMENT 'process template ID',' parent_id 'bigint NOT NULL DEFAULT 0 COMMENT' parent process ID', 'biz_code' varchar(64) NOT NULL COMMENT ' , 'biz_key' varchar(64) NOT NULL COMMENT 'biz_key ', 'current_status' tinyint(2) unsigned NOT NULL DEFAULT 0 COMMENT' status: 0- In progress, 1- Completed, ', 'start_time' datetime NOT NULL COMMENT 'start time ',' end_time 'datetime NOT NULL COMMENT' end time ', 'duration' bigint NOT NULL COMMENT 'start/end interval ',' biz_parameters' vARCHAR (512) COMMENT ' Json ', 'created_at' datetime NOT NULL default current_TIMESTAMP COMMENT 'Create time ', 'updated_at' datetime NOT NULL default current_TIMESTAMP COMMENT 'updated_at' NOT NULL default current_timestamp COMMENT ', 'creator' varchar(64) NOT NULL COMMENT 'founder ', PRIMARY KEY (' id ')) ENGINE=InnoDB DEFAULT CHARSET= UTf8MB4 COLLATE= UTf8MB4_general_ci COMMENT=' process instance '; CREATE TABLE 'process_task' (' id' bigint NOT NULL, 'process_instance_id' bigint NOT NULL COMMENT 'process instance id', 'node_code' bigint NOT NULL COMMENT 'node_code ',' task_name 'varchar(255) NOT NULL COMMENT' task_name 'varchar ', 'assign_strategy' tinyint(1) unsigned not null default 1 comment 'assign_strategy' 'assign_strategy_ext' varchar(64) comment 'extend columns by policy when type is by quantity and scale ', 'assign_user' varchar(255) CHARACTER SET utf8MB4 COLLATE UTf8MB4_general_ci NOT NULL COMMENT 'assign_user' varchar(255) CHARACTER SET utf8MB4_general_ci NOT NULL COMMENT 'assign_user' varchar(255) CHARACTER SET utf8MB4_general_ci 'assign_org_varchar (255) CHARACTER SET utf8mb4 COLLATE UTf8MB4_general_ci NOT NULL COMMENT ', 'task_status' tinyint(2) unsigned NOT NULL default 1 COMMENT' 1- In progress, ', 'source_task_id' bigint DEFAULT NULL COMMENT 'Source task id', 'start_time' datetime DEFAULT NULL COMMENT 'Start time ',' end_time 'datetime DEFAULT NULL COMMENT' end time ', 'created_at' datetime NOT NULL default current_TIMESTAMP COMMENT 'Create time ', 'updated_at' datetime NOT NULL default current_TIMESTAMP COMMENT 'updated_at' NOT NULL default current_timestamp COMMENT ', 'creator' varchar(64) NOT NULL COMMENT 'founder ', PRIMARY KEY (' id ')) ENGINE=InnoDB DEFAULT CHARSET= UTf8MB4 COLLATE= UTf8MB4_general_ci COMMENT=' process task '; Create table process_task_detail (id bigint auto_increment comment 'id', task_id bigint not null comment' id', User_id varchar(64) not null comment 'user_id ', Assign_result tinyint(1) unsigned default 0 not null comment ' Is_valid TINyInt (1) unsigned default 1 not NULL comment 'whether the comment is valid,1- valid,0- invalid. ', remark varchar(255) NULL comment ', created_at datetime default current_TIMESTAMP not null comment ', PRIMARY KEY (' id ') ENGINE=InnoDB DEFAULT CHARSET= UTf8MB4 COLLATE= UTf8MB4_general_ci COMMENT=' 表 示 表 示 '; # process_node_history: Table CREATE table 'process_node_history' (' id' BIGint (20) NOT NULL AUTO_INCREMENT COMMENT '主键 iD ', 'template_id' bigint(20) NOT NULL COMMENT 'template id',' process_instance_id 'bigint(20) NOT NULL COMMENT' process instance id', 'node_code' varchar(64) NOT NULL COMMENT 'node_code ',' task_id 'bigint(20) NULL COMMENT' taskid ', 'node_name' varchar(64) NULL COMMENT 'node name ',' node_type 'varchar(64) NULL COMMENT' node type ', 'start_time' datetime NOT NULL COMMENT 'start time ',' end_time 'datetime NULL COMMENT' end time ', PRIMARY KEY (' id ')) ENGINE = InnoDB DEFAULT CHARSET= UTf8MB4 COLLATE= UTf8MB4_general_ci COMMENT ='Copy the code
Follow-up plan
About the form
A table records the form information that needs to be set in the process definition
A table records the form data that is filled in to the process instance
A table records running process instance table data – used for changes to form data in the process
About gateways and subprocesses
When entering a subprocess or gateway, suspend the original ExecutionEntity and create a new ExecutionEntity representing a new subprocess or gateway link. Wait for the subprocess to complete the new ExecutionEntity state, and then reactivate the original ExecutionEntity.
About each business party’s own implementation
With mq messaging systems, workflows are decoupled and business parties consume messages themselves for business implementation.