Activit工作流引擎核心數據表存儲解剖
阿新 • • 發佈:2018-02-10
歷史記錄 www update let def 流程實例 aaa delete nes 假設: 某公司的員工請假單審批流程是 發起者-->部門主管--->部門經理 共三個節點
發起者:公司所有的用戶
部門主管:aaa(審批)
部門經理:bbb(審批)
java Activiti工作流引擎共有23張數據表用來存儲審批 這裏我只是使用了核心的幾張表
第一步:發布流程定義
發布定義員工請假申請單流程 mysql> UPDATE act_ge_property SET rev_ = 2, value_ = '101' WHERE name_ = 'next.dbid' AND rev_ = 1; mysql> select * from act_ge_property; +----------------+--------------+------+ | NAME_ | VALUE_ | REV_ | +----------------+--------------+------+ | next.dbid | 101 | 2 | | schema.history | create(5.12) | 1 | | schema.version | 5.12 | 1 | +----------------+--------------+------+ 3 rows in set ========================================================================= mysql> INSERT INTO `act_re_deployment` SET id_ = '1', name_ = '員工請假申請單', category_ = NULL, deploy_time_ = '2018-02-09 20:23:36'; mysql> select * from act_re_deployment; +-----+--------------+-----------+-------------------------+ | ID_ | NAME_ | CATEGORY_ | DEPLOY_TIME_ | +-----+--------------+-----------+-------------------------+ | 1 | 員工請假申請單 | NULL | 2018-02-09 20:23:36 | +-----+--------------+-----------+-------------------------+ 1 row in set ========================================================================= mysql> INSERT INTO `act_ge_bytearray` SET id_='2', rev_= 1, name_= 'diagram/diagram.bpmn', bytes_= _binary'<?xml..?>..中間xml省去..</definitions>', deployment_id_= '1', generated_= 0; ========================================================================= mysql> INSERT INTO `act_re_procdef` SET id_ = 'myprocess:1:4', rev_ = 1, category_ = 'http://www.activiti.org/test', name_ = 'my process', key_ = 'myprocess', version_ = 1, deployment_id_ = '1', resource_name_ = 'diagram/diagram.bpmn', dgrm_resource_name_ = 'diagram/diagram.png', description_ = NULL, has_start_form_key_ = 0, suspension_state_ = 1; mysql> select * from `act_re_procdef`\g; *************************** 1. row *************************** id_: myprocess:1:4 rev_: 1 category_: http://www.activiti.org/test name_: my process key_: myprocess version_: 1 deployment_id_: 1 resource_name_: diagram/diagram.bpmn dgrm_resource_name_: diagram/diagram.png description_: null has_start_form_key_: 0 suspension_state_: 1 1 row in set (0.00 sec) =========================================================================
第二步:員工發起請假流程審批實例
通過流程定義 processDefinitionKey 來啟動一個流程流程 ========================================================================= mysql> UPDATE act_ge_property SET rev_ = 3, value_ = '201' WHERE name_ = 'next.dbid' AND rev_ = 2; mysql> select * from act_ge_property; +----------------+--------------+------+ | NAME_ | VALUE_ | REV_ | +----------------+--------------+------+ | next.dbid | 201 | 3 | | schema.history | create(5.12) | 1 | | schema.version | 5.12 | 1 | +----------------+--------------+------+ 3 rows in set ========================================================================= 向流程實例表插入一條數據 mysql> INSERT INTO `act_ru_execution` SET id_ = '101', rev_ = 1, proc_inst_id_ = '101', business_key_ = NULL, proc_def_id_ = 'myprocess:1:4', act_id_ = 'one', is_active_ = 1, is_concurrent_ = 0, is_scope_ = 1, is_event_scope_ = 0, parent_id_ = NULL, super_exec_ = NULL, suspension_state_ = 1, cached_ent_state_ = 2; mysql> select * from `act_ru_execution`\G; *************************** 1. row *************************** id_: 101 rev_: 1 proc_inst_id_: 101 business_key_: null parent_id_: null proc_def_id_: myprocess:1:4 super_exec_: null act_id_: one is_active_: 1 is_concurrent_: 0 is_scope_: 1 is_event_scope_: 0 suspension_state_: 1 cached_ent_state_: 2 1 row in set (0.00 sec) ========================================================================= 流程實例歷史記錄表 mysql> INSERT INTO `act_hi_procinst` SET id_ = '101', proc_inst_id_ = '101', business_key_ = NULL, proc_def_id_ = 'myprocess:1:4', start_time_ = '2018-02-09 21:38:20', end_time_ = NULL, duration_ = NULL, start_user_id_ = NULL, start_act_id_ = 'startevent1', end_act_id_ = NULL, super_process_instance_id_ = NULL, delete_reason_ = NULL; mysql> select * from `act_hi_procinst`\g; *************************** 1. row *************************** id_: 101 proc_inst_id_: 101 business_key_: null proc_def_id_: myprocess:1:4 start_time_: 2018-02-09 21:38:20 end_time_: null duration_: null start_user_id_: null start_act_id_: startevent1 end_act_id_: null super_process_instance_id_: null delete_reason_: null 1 row in set (0.00 sec) ========================================================================= mysql> INSERT INTO `act_hi_actinst` SET id_ = '102', proc_def_id_ = 'myprocess:1:4', proc_inst_id_ = '101', execution_id_ = '101', act_id_ = 'startevent1', task_id_ = NULL, call_proc_inst_id_ = NULL, act_name_ = 'start', act_type_ = 'startevent', assignee_ = NULL, start_time_ = '2018-02-09 21:38:20', end_time_ = '2018-02-09 21:38:20', duration_ = 6; mysql> INSERT INTO `act_hi_actinst` SET id_ = '103', proc_def_id_ = 'myprocess:1:4', proc_inst_id_ = '101', execution_id_ = '101', act_id_ = 'one', task_id_ = '104', call_proc_inst_id_ = NULL, act_name_ = '部門主管審批', act_type_ = 'usertask', assignee_ = 'aaa', start_time_ = '2018-02-09 21:38:20', end_time_ = NULL, duration_ = NULL; mysql> select * from `act_hi_actinst`\G; *************************** 1. row *************************** id_: 102 proc_def_id_: myprocess:1:4 proc_inst_id_: 101 execution_id_: 101 act_id_: startevent1 task_id_: null call_proc_inst_id_: null act_name_: start act_type_: startevent assignee_: null start_time_: 2018-02-09 21:38:20 end_time_: 2018-02-09 21:38:20 duration_: 6 *************************** 2. row *************************** id_: 103 proc_def_id_: myprocess:1:4 proc_inst_id_: 101 execution_id_: 101 act_id_: one task_id_: 104 call_proc_inst_id_: null act_name_: 部門主管審批 act_type_: usertask assignee_: aaa start_time_: 2018-02-09 21:38:20 end_time_: null duration_: null 2 rows in set (0.00 sec) ========================================================================= mysql> INSERT INTO `act_ru_task` SET id_ = '104', rev_ = 1, name_ = '部門主管審批', parent_task_id_ = NULL, description_ = NULL, priority_ = 50, create_time_ = '2018-02-09 21:38:20', owner_ = NULL, assignee_ = 'aaa', delegation_ = NULL, execution_id_ = '101', proc_inst_id_ = '101', proc_def_id_ = 'myprocess:1:4', task_def_key_ = 'one', due_date_ = NULL, suspension_state_ = 1; mysql> select * from `act_ru_task`\G; *************************** 1. row *************************** id_: 104 rev_: 1 execution_id_: 101 proc_inst_id_: 101 proc_def_id_: myprocess:1:4 name_: 部門主管審批 parent_task_id_: null description_: null task_def_key_: one owner_: null assignee_: aaa delegation_: null priority_: 50 create_time_: 2018-02-09 21:38:20 due_date_: null suspension_state_: 1 1 row in set (0.00 sec) ========================================================================= mysql> INSERT INTO `act_hi_taskinst` SET id_ = '104', proc_def_id_ = 'myprocess:1:4', proc_inst_id_ = '101', execution_id_ = '101', name_ = '部門主管審批', parent_task_id_ = NULL, description_ = NULL, owner_ = NULL, assignee_ = 'aaa', start_time_ = '2018-02-09 21:38:20', claim_time_ = NULL, end_time_ = NULL, duration_ = NULL, delete_reason_ = NULL, task_def_key_ = 'one', form_key_ = NULL, priority_ = 50, due_date_ = NULL; mysql> select * from `act_hi_taskinst`\G; *************************** 1. row *************************** id_: 104 proc_def_id_: myprocess:1:4 task_def_key_: one proc_inst_id_: 101 execution_id_: 101 name_: 部門主管審批 parent_task_id_: null description_: null owner_: null assignee_: aaa start_time_: 2018-02-09 21:38:20 claim_time_: null end_time_: null duration_: null delete_reason_: null priority_: 50 due_date_: null form_key_: null 1 row in set (0.00 sec) ========================================================================= mysql> INSERT INTO `act_ru_identitylink` SET id_ = '105', rev_ = 1, type_ = 'participant', user_id_ = 'aaa', group_id_ = NULL, task_id_ = NULL, proc_inst_id_ = '101', proc_def_id_ = NULL; mysql> select * from `act_ru_identitylink`\G; *************************** 1. row *************************** id_: 105 rev_: 1 group_id_: null type_: participant user_id_: aaa task_id_: null proc_inst_id_: 101 proc_def_id_: null 1 row in set (0.00 sec) =========================================================================
第三步:部門主管審批 用戶是(aaa) 這裏我們是寫死的 項目當中我們可以使用部門角色來動態查詢到不同部門的主管人員審批
部門主管(aaa)辦理自己的任務 任務ID:104 ========================================================================= 查詢任務表下面的所有待辦任務 mysql> SELECT DISTINCT RES.* FROM act_ru_task RES ORDER BY RES.id_ ASC LIMIT 2147483647 offset 0\G; *************************** 1. row *************************** id_: 104 rev_: 1 execution_id_: 101 proc_inst_id_: 101 proc_def_id_: myprocess:1:4 name_: 部門主管審批 parent_task_id_: null description_: null task_def_key_: one owner_: null assignee_: aaa delegation_: null priority_: 50 create_time_: 2018-02-09 21:38:20 due_date_: null suspension_state_: 1 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_ge_property SET rev_ = 4, value_ = '301' WHERE name_ = 'next.dbid' AND rev_ = 3; ========================================================================= mysql> INSERT INTO `act_hi_actinst` SET id_ = '201', proc_def_id_ = 'myprocess:1:4', proc_inst_id_ = '101', execution_id_ = '101', act_id_ = 'two', task_id_ = '202', call_proc_inst_id_ = NULL, act_name_ = '部門經理審批', act_type_ = 'usertask', assignee_ = 'bbb', start_time_ = '2018-02-09 22:03:25', end_time_ = NULL, duration_ = NULL; mysql> select * from `act_hi_actinst` where id_=201\G; *************************** 1. row *************************** id_: 201 proc_def_id_: myprocess:1:4 proc_inst_id_: 101 execution_id_: 101 act_id_: two task_id_: 202 call_proc_inst_id_: null act_name_: 部門經理審批 act_type_: usertask assignee_: bbb start_time_: 2018-02-09 22:03:25 end_time_: null duration_: null 1 row in set (0.00 sec) ========================================================================= 任務表插入一條數據 mysql> INSERT INTO `act_ru_task` SET id_ = '202', rev_ = 1, name_ = '部門經理審批', parent_task_id_ = NULL, description_ = NULL, priority_ = 50, create_time_ = '2018-02-09 22:03:25', owner_ = NULL, assignee_ = 'bbb', delegation_ = NULL, execution_id_ = '101', proc_inst_id_ = '101', proc_def_id_ = 'myprocess:1:4', task_def_key_ = 'two', due_date_ = NULL, suspension_state_ = 1; mysql> select * from `act_ru_task` where id_=202\G; *************************** 1. row *************************** id_: 202 rev_: 1 execution_id_: 101 proc_inst_id_: 101 proc_def_id_: myprocess:1:4 name_: 部門經理審批 parent_task_id_: null description_: null task_def_key_: two owner_: null assignee_: bbb delegation_: null priority_: 50 create_time_: 2018-02-09 22:03:25 due_date_: null suspension_state_: 1 1 row in set (0.00 sec) ========================================================================= mysql> INSERT INTO `act_hi_taskinst` SET id_ = '202', proc_def_id_ = 'myprocess:1:4', proc_inst_id_ = '101', execution_id_ = '101', name_ = '部門經理審批', parent_task_id_ = NULL, description_ = NULL, owner_ = NULL, assignee_ = 'bbb', start_time_ = '2018-02-09 22:03:25', claim_time_ = NULL, end_time_ = NULL, duration_ = NULL, delete_reason_ = NULL, task_def_key_ = 'two', form_key_ = NULL, priority_ = 50, due_date_ = NULL; mysql> select * from `act_hi_taskinst` where id_=202\G; *************************** 1. row *************************** id_: 202 proc_def_id_: myprocess:1:4 task_def_key_: two proc_inst_id_: 101 execution_id_: 101 name_: 部門經理審批 parent_task_id_: null description_: null owner_: null assignee_: bbb start_time_: 2018-02-09 22:03:25 claim_time_: null end_time_: null duration_: null delete_reason_: null priority_: 50 due_date_: null form_key_: null 1 row in set (0.00 sec) ========================================================================= mysql> INSERT INTO `act_ru_identitylink` SET id_ = '203', rev_ = 1, type_ = 'participant', user_id_ = 'bbb', group_id_ = NULL, task_id_ = NULL, proc_inst_id_ = '101', proc_def_id_ = NULL; mysql> select * from `act_ru_identitylink` where id_=203\G; *************************** 1. row *************************** ID_: 203 REV_: 1 GROUP_ID_: NULL TYPE_: participant USER_ID_: bbb TASK_ID_: NULL PROC_INST_ID_: 101 PROC_DEF_ID_: NULL 1 row in set (0.00 sec) ========================================================================= 更新當前節點辦理結束時間 mysql> UPDATE act_hi_actinst SET execution_id_ = '101', assignee_ = 'aaa', end_time_ = '2018-02-09 22:03:25', duration_ = 1505337 WHERE id_ = '103'; mysql> select * from act_hi_actinst where id_=103\G; *************************** 1. row *************************** id_: 103 proc_def_id_: myprocess:1:4 proc_inst_id_: 101 execution_id_: 101 act_id_: one task_id_: 104 call_proc_inst_id_: null act_name_: 部門主管審批 act_type_: usertask assignee_: aaa start_time_: 2018-02-09 21:38:20 end_time_: 2018-02-09 22:03:25 duration_: 1505337 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_ru_execution SET rev_ = 2, proc_def_id_ = 'myProcess:1:4', act_id_ = 'two', is_active_ = 1, is_concurrent_ = 0, is_scope_ = 1, is_event_scope_ = 0, parent_id_ = NULL, super_exec_ = NULL, suspension_state_ = 1, cached_ent_state_ = 2 WHERE id_ = '101' AND rev_ = 1; mysql> select * from act_ru_execution where id_=101\G; *************************** 1. row *************************** id_: 101 rev_: 2 proc_inst_id_: 101 business_key_: null parent_id_: null proc_def_id_: myprocess:1:4 super_exec_: null act_id_: two is_active_: 1 is_concurrent_: 0 is_scope_: 1 is_event_scope_: 0 suspension_state_: 1 cached_ent_state_: 2 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_hi_taskinst SET execution_id_ = '101', name_ = '部門主管審批', parent_task_id_ = NULL, description_ = NULL, owner_ = NULL, assignee_ = 'aaa', claim_time_ = NULL, end_time_ = '2018-02-09 22:03:25', duration_ = 1505300, delete_reason_ = 'completed', task_def_key_ = 'one', form_key_ = NULL, priority_ = 50, due_date_ = NULL WHERE id_ = '104'; mysql> select * from act_hi_taskinst where id_=104\G; *************************** 1. row *************************** id_: 104 proc_def_id_: myprocess:1:4 task_def_key_: one proc_inst_id_: 101 execution_id_: 101 name_: 部門主管審批 parent_task_id_: null description_: null owner_: null assignee_: aaa start_time_: 2018-02-09 21:38:20 claim_time_: null end_time_: 2018-02-09 22:03:25 duration_: 1505300 delete_reason_: completed priority_: 50 due_date_: null form_key_: null 1 row in set (0.00 sec) ========================================================================= 刪除當前待辦任務數據,表示辦理完成 mysql> DELETE FROM act_ru_task WHERE id_ = '104' AND rev_ = 1; =========================================================================
第四步:部門經理審批 用戶(bbb) 也是最後一個節點審批
部門經理(bbb)辦理自己的任務 也是最後一個審批節點 任務ID:202 ========================================================================= 查詢任務表下面的所有待辦任務 mysql> SELECT DISTINCT RES.* FROM act_ru_task RES ORDER BY RES.id_ ASC LIMIT 2147483647 offset 0\G; *************************** 1. row *************************** id_: 202 rev_: 1 execution_id_: 101 proc_inst_id_: 101 proc_def_id_: myprocess:1:4 name_: 部門經理審批 parent_task_id_: null description_: null task_def_key_: one owner_: null assignee_: bbb delegation_: null priority_: 50 create_time_: 2018-02-09 21:58:15 due_date_: null suspension_state_: 1 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_ge_property SET rev_ = 5, value_ = '401' WHERE name_ = 'next.dbid' AND rev_ = 4; mysql> select * from act_ge_property; +----------------+--------------+------+ | NAME_ | VALUE_ | REV_ | +----------------+--------------+------+ | next.dbid | 401 | 5 | | schema.history | create(5.12) | 1 | | schema.version | 5.12 | 1 | +----------------+--------------+------+ ========================================================================= mysql> INSERT INTO `act_hi_actinst` SET id_ = '301', proc_def_id_ = 'myprocess:1:4', proc_inst_id_ = '101', execution_id_ = '101', act_id_ = 'endevent1', task_id_ = NULL, call_proc_inst_id_ = NULL, act_name_ = 'end', act_type_ = 'endevent', assignee_ = NULL, start_time_ = '2018-02-09 22:25:39', end_time_ = '2018-02-09 22:25:39', duration_ = 0; mysql> select * from `act_hi_actinst` where id_=301\G; *************************** 1. row *************************** id_: 301 proc_def_id_: myprocess:1:4 proc_inst_id_: 101 execution_id_: 101 act_id_: endevent1 task_id_: null call_proc_inst_id_: null act_name_: end act_type_: endevent assignee_: null start_time_: 2018-02-09 22:25:39 end_time_: 2018-02-09 22:25:39 duration_: 0 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_hi_taskinst SET execution_id_ = '101', name_ = '部門經理審批', parent_task_id_ = NULL, description_ = NULL, owner_ = NULL, assignee_ = 'bbb', claim_time_ = NULL, end_time_ = '2018-02-09 22:25:39', duration_ = 1334701, delete_reason_ = 'completed', task_def_key_ = 'two', form_key_ = NULL, priority_ = 50, due_date_ = NULL WHERE id_ = '202'; mysql> select * from act_hi_taskinst where id_=202\G; *************************** 1. row *************************** id_: 202 proc_def_id_: myprocess:1:4 task_def_key_: two proc_inst_id_: 101 execution_id_: 101 name_: 部門經理審批 parent_task_id_: null description_: null owner_: null assignee_: bbb start_time_: 2018-02-09 22:03:25 claim_time_: null end_time_: 2018-02-09 22:25:39 duration_: 1334701 delete_reason_: completed priority_: 50 due_date_: null form_key_: null 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_hi_procinst SET proc_def_id_ = 'myProcess:1:4', start_time_ = '2018-02-09 21:38:20', end_time_ = '2018-02-09 22:25:39', duration_ = 2839765, end_act_id_ = 'endevent1', delete_reason_ = NULL WHERE id_ = '101'; mysql> select * from `act_hi_procinst` where id_=101\g; *************************** 1. row *************************** id_: 101 proc_inst_id_: 101 business_key_: null proc_def_id_: myprocess:1:4 start_time_: 2018-02-09 21:38:20 end_time_: 2018-02-09 22:25:39 duration_: 2839765 start_user_id_: null start_act_id_: startevent1 end_act_id_: endevent1 super_process_instance_id_: null delete_reason_: null 1 row in set (0.00 sec) ========================================================================= mysql> UPDATE act_hi_actinst SET execution_id_ = '101', assignee_ = 'bbb', end_time_ = '2018-02-09 22:25:39', duration_ = 1334740 WHERE id_ = '201'; mysql> select * from act_hi_actinst where id_=201\g; *************************** 1. row *************************** id_: 201 proc_def_id_: myprocess:1:4 proc_inst_id_: 101 execution_id_: 101 act_id_: two task_id_: 202 call_proc_inst_id_: null act_name_: 部門經理審批 act_type_: usertask assignee_: bbb start_time_: 2018-02-09 22:03:25 end_time_: 2018-02-09 22:25:39 duration_: 1334740 1 row in set (0.00 sec) ========================================================================= mysql> delete from act_ru_task where id_ = '202' and rev_ = 1; mysql> delete from act_ru_identitylink where id_ = '105'; mysql> delete from act_ru_identitylink where id_ = '203'; mysql> delete from act_ru_execution where id_ = '101' and rev_ = 2; =========================================================================
Activit工作流引擎核心數據表存儲解剖