介紹一個真正符合中國國情的工作流設計參考(包括PHP實現(xiàn))
Mar 24, 2017 am 10:27 AM?開源的工作流很少有讓人滿意的,即便是國內(nèi)用的比較多的jbpm,用起來也會覺得很便扭。再加上PHP中沒有什么好用的工作流,于是干脆自己設計一個,設計的原則如下:
1 根據(jù)80/20原則,只使用wfmc模型中最符合自身應用的20%功能
2 充分吸收國內(nèi)使用jbpm開發(fā)BOSS中遇到的問題,工作流引擎只負責參數(shù)的收集和流程的流轉(zhuǎn),具體和業(yè)務的控制,交給每個流程定制的控制類去實現(xiàn)。
3 表單采用簡單的html+控制標簽的方法實現(xiàn)
4 權限和模板引擎,以及其它輔助函數(shù)直接使用辦公系統(tǒng)自帶的框架
5 充分利用PHP語言的特點,流程設計是基于數(shù)據(jù)庫的,程序上使用OO設計,但采用重對象的方法
6 不把可視化設計流程的工作交給最終客戶,而且由設計時完成,因此不考慮流程版本更新的問題
一、工作流數(shù)據(jù)表設計
tbl_workflow_defination:工作流定義表
defination_id |
流程id |
? |
defination_name |
流程名稱 |
? |
defination_handler |
流程處理輔助文件,每個工作流一個文件 |
自定義處理文件,及其對象。例如workflow-proporsal-handler.php,其中定義對象proposal |
tbl_workflow_node:流程結(jié)點步驟表
node_id |
結(jié)點id |
? |
defination_id |
流程id |
? |
node_index |
結(jié)點序號 |
結(jié)點的step |
node_name |
結(jié)點名稱 |
? |
node_type |
結(jié)點類型 |
1人為決策,2自動處理(直接執(zhí)行execute_function),3等待外部響應(例如外部WS觸發(fā)),4分支,5匯總 6結(jié)束結(jié)點(此結(jié)點執(zhí)行時候自動終止進程) |
init_function |
流程初始函數(shù) |
? |
run_function |
流程運行函數(shù) |
? |
save_function |
流程保存函數(shù) |
? |
transit_function |
流程流轉(zhuǎn)函數(shù) |
? |
prev_node_index |
前結(jié)點序號 |
例如1。開始結(jié)點沒有 執(zhí)行前,通過此來校驗一下流程 |
next_node_index |
后結(jié)點序號 |
例如[同意]3,[不同意]4。尾結(jié)點或要結(jié)束的結(jié)點沒有,若沒有,直接調(diào)用end |
executor |
執(zhí)行角色,組,人 |
role[1,2] group[1,2] user[1,2],為空由運行時決定 |
execute_type |
執(zhí)行類型 |
0需所有人執(zhí)行 1只需一人執(zhí)行 |
remind |
提醒 |
0不提醒 1郵件 2短信 3郵件和短信 |
field |
可編輯的字段 |
name,content |
max_day |
最長時間(天) |
? |
tbl_workflow_process:流程執(zhí)行進程表
process_id |
進程id |
? |
defination_id |
流程id |
? |
process_desc |
進程描述 |
顯示在我的工作臺中 |
context |
上下文 |
存放上下文變量,例如業(yè)務表的id |
current_node_index |
當前結(jié)點序號 |
? |
start_time |
流程啟動時間 |
如遇分支、匯合顯示為: 1=》3,4=》3,5=》6 |
finish_time |
流程完成時間 |
? |
state |
狀態(tài) |
1運行 2結(jié)束 |
start_user |
發(fā)起人 |
發(fā)起人,用于顯示自己的流程 |
tbl_workflow_thread :流程執(zhí)行線程表
thread_id |
線程id |
? |
process_id |
進程id |
? |
process_desc |
進程描述 |
? |
node_id |
結(jié)點id |
? |
node_name |
結(jié)點名稱 |
? |
executor |
執(zhí)行人 |
? |
start_time |
線程生成時間 |
? |
receive_time |
線程接收時間 |
? |
finish_time |
線程完成時間 |
? |
max_time |
結(jié)點規(guī)定的最長時間 |
? |
state |
狀態(tài) |
0未接收 1已接收 2已處理 |
二、常見流程
人工決策
領導傳閱 |
部門領導審批 |
填寫表單 |
結(jié)束 |
放棄 |
提交 |
同意 |
重填(退回) |
不同意 |
完成 |
外部響應
發(fā)送支付信息 |
接收支付成功響應(外部WS觸發(fā)該流程) |
三、PHP設計
運行的函數(shù)由結(jié)點在設計時候決定,如果沒有設定,就使用默認的函數(shù)。利用了PHP語言的以下特性
<?php class Foo { function Variable() { $name = 'Bar'; $this->$name();?//?This?calls?the?Bar()?method ????} ???? ????function?Bar() ????{ ????????echo?"This?is?Bar"; ????} } $foo?=?new?Foo(); $funcname?=?"Variable"; $foo->$funcname();??//?This?calls?$foo->Variable() ?>
使用前可以用method_exists來檢查
WorkflowService.php
? WorkflowService
??? $defination
$process
$node
$thread
$input 用戶輸入的和流程有關的變量
list_defination()
{
}
init_process(defination_id)
{? global user;
取得$defination,得到業(yè)務的handler,例如WorkflowProposalHandler
?? 建立$process行記錄
}
start_process()
{? 調(diào)用WorkflowProposalHandler->start($process)//新建業(yè)務對象,并把業(yè)務類的參數(shù)例如proposal_id放到$process[‘context’]里面
?? init_thread(1); ?//默認調(diào)用第一個結(jié)點
}
?
list_ my_thread ()
{? global user;
}
?
init_thread(node_index)
{
? 取得$node
? 取得$process
? 修改$process為運行到當前結(jié)點
? Switch($node[‘node_type’])
?? Case 1: 人工決策
?????? 建立$thread
?????? WorkflowProposalHandler-> init_function ($process,$node,$thread)
?????? 發(fā)送提醒
Case 2: 自動處理
??? 建立$thread
??? WorkflowProposalHandler-> init_function ($process,$node,$thread)
?????? 調(diào)用run_thread(thread_id)
Case 3: 等待外部響應
??? 建立$thread
??? WorkflowProposalHandler-> init_function ($process,$node,$thread)
Case 4: 分支
??? 取得所有分支的子結(jié)點
??? init_thread(子結(jié)點)
Case 5: 匯總:
?? ?取得所有前結(jié)點,如果所有前結(jié)點的Thread都結(jié)束了,調(diào)出下一結(jié)點
?????? 調(diào)用init_thread(子結(jié)點)
Case 6: 結(jié)束:直接結(jié)束進程process
??? end_process()
}
run_thread(thread_id)
{???
取得$node
取得$process
取得$thread
? Switch($node[‘node_type’])
?? Case 1: 人工決策
?????? 修改$thread為已接收
????????? WorkflowProposalHandler-> run_function ($process,$node,$thread)顯示表單
Case 2: 自動處理
??? 修改$thread為已接收
??? $next_node_id=WorkflowProposalHandler-> run_function ($process,$node,$thread)
?????? 調(diào)用transit_thread(thread_id, $next_node_id)
Case 3: 等待外部響應
??? 修改$thread為已接收
??? $next_node_id=WorkflowProposalHandler-> run_function ($process,$node,$thread)
??? transit_thread(thread_id, $next_node_id)
Case 4: 分支
Case 5: 匯總:
Case 6: 結(jié)束:
}
save_thread(thread_id)
{? //保存結(jié)點數(shù)據(jù)
取得$node
取得$process
取得$thread
? Switch($node[‘node_type’])
?? Case 1: 人工決策
????????? WorkflowProposalHandler-> save_function ($process,$node,$thread)保存表單
WorkflowProposalHandler-> run_function ($process,$node,$thread)顯示表單
Case 2: 自動處理
Case 3: 等待外部響應
Case 4: 分支
Case 5: 匯總:
Case 6: 結(jié)束:
}
transit_thread(thread_id, $next_node_id)
{ 取得$node
??取得$process
取得$thread
? Switch($node[‘node_type’])
?? Case 1: 人工決策
???? ?WorkflowProposalHandler->transit_function($process,$node,$thread,$next_node_id) ?
????????? 修改$thread為已完成
????????? If($next_node_id < $ cur_node_id) { //回退
刪除所有大于$next_node_id的Thread
}
init_thread($next_node_id)
Case 2: 自動處理
修改$thread為已完成
If($next_node_id < $ cur_node_id) { //回退
刪除所有大于$next_node_id的Thread
}
init _thread($next_node_id)
Case 3: 等待外部響應
修改$thread為已完成
If($next_node_id < $ cur_node_id) { //回退
刪除所有大于$next_node_id的Thread
}
init _thread($next_node_id)
Case 4: 分支
Case 5: 匯總:
Case 6: 結(jié)束:
}
end_process()
list_my_process
view_process
workflow_proposal_handler.php
WorkflowProposalHandler
start()
prepare_input() 準備用戶輸入變量,從$_POST收集
init_function () 線程建立后調(diào)用的默認函數(shù),當流程的執(zhí)行者由程序生成時,在此函數(shù)內(nèi)更改$thread的executor,例如直接賦值user[2]
run_function () 線程運行化時候調(diào)用的默認函數(shù)
save_function () 保存運行信息
transit_function ()執(zhí)行流轉(zhuǎn)
sendmail 其它結(jié)點調(diào)用函數(shù)
workflow.php
switch(op)
case list_defination
參數(shù):無
WorkflowService->list_defination()
case start_process :啟動
?????? 參數(shù):defination_id
?????? WorkflowService->init_process(defination_id)
WorkflowService->start_process()
?? case list_ my_thread :待處理的列表
?????? WorkflowService->list_ my_thread()
?? case run_thread :
?????? 參數(shù):thread_id
?????? WorkflowService->run_thread(thread_id)
case save_thread :
??? 參數(shù):thread_id
?? ?把input收集起來(所有的變量以 f_開頭),賦給WorkflowService的Input,另外還要獲得thread_id
??? WorkflowService->save_thread(thread_id)
?? case transit_thread :
?? 參數(shù):thread_id
把input收集起來,賦給WorkflowService的Input,另外還要獲得thread_id
$next_node_id = 得到用戶選擇的下一結(jié)點id
WorkflowService-> transit _thread(thread_id,$next_node_id)
?? case list_my_process:所有我發(fā)起的流程
case list_all_process:所有我發(fā)起的流程
case view_process :
在其它程序中初始化流程
??? 1先自行建立好業(yè)務表單
2WorkflowService->init_process(defination_id)
3把建好的業(yè)務表單的ID放在process的context里面
4WorkflowService->init_thread(1)
WorkflowService->transit_thread(1,2)通過手動調(diào)用把前面的流程過掉
外部服務繼續(xù)流轉(zhuǎn)流程(只用于自動流程)
1 把input收集起來,賦給WorkflowService的Input,另外還要獲得thread_id
2 WorkflowService->run_thread(thread_id)
相關文章:

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the popularity of Internet applications, website response speed has become more and more of a focus for users. In order to quickly respond to user requests, websites often use caching technology to cache data, thereby reducing the number of database queries. However, cache expiration time has an important impact on response speed. This article will discuss methods of controlling cache expiration time to help PHP developers better apply caching technology. 1. What is cache expiration time? Cache expiration time refers to the time when the data in the cache is considered expired. It determines when the data in the cache is needed

How to use PHP to implement mobile adaptation and responsive design Mobile adaptation and responsive design are important practices in modern website development. They can ensure good display effects of the website on different devices. In this article, we will introduce how to use PHP to implement mobile adaptation and responsive design, with code examples. 1. Understand the concepts of mobile adaptation and responsive design Mobile adaptation refers to providing different styles and layouts for different devices based on the different characteristics and sizes of the device. Responsive design refers to the use of

How to use PHP to implement user registration function In modern network applications, user registration function is a very common requirement. Through the registration function, users can create their own accounts and use corresponding functions. This article will implement the user registration function through the PHP programming language and provide detailed code examples. First, we need to create an HTML form to receive the user's registration information. In the form, we need to include some input fields, such as username, password, email, etc. Form fields can be customized according to actual needs.

User privacy protection of online voting system implemented in PHP With the development and popularization of the Internet, more and more voting activities have begun to be moved to online platforms. The convenience of online voting systems brings many benefits to users, but it also raises concerns about user privacy leaks. Privacy protection has become an important aspect in the design of online voting systems. This article will introduce how to use PHP to write an online voting system, and focus on the issue of user privacy protection. When designing and developing an online voting system, the following principles need to be followed to ensure

Implementation Principle of Consistent Hash Algorithm for PHP Data Cache Consistent Hashing algorithm (ConsistentHashing) is an algorithm commonly used for data caching in distributed systems, which can minimize the number of data migrations when the system expands and shrinks. In PHP, implementing consistent hashing algorithms can improve the efficiency and reliability of data caching. This article will introduce the principles of consistent hashing algorithms and provide code examples. The basic principle of consistent hashing algorithm. Traditional hashing algorithm disperses data to different nodes, but when the node

How to use PHP to implement file conversion and format conversion functions 1. Introduction In the process of developing web applications, we often need to implement file conversion and format conversion functions. Whether you are converting image files to other formats or converting text files from one encoding to another, these operations are common needs. This article will describe how to implement these functions using PHP, with code examples. 2. File conversion 2.1 Convert image files to other formats In PHP, we can use

With the continuous development of WeChat mini programs, more and more users are beginning to choose WeChat mini programs to log in. In order to improve users’ login experience, WeChat mini programs began to support fingerprint login. In this article, we will introduce how to use PHP to implement fingerprint login for WeChat mini programs. 1. Understand the fingerprint login of WeChat mini programs On the basis of WeChat mini programs, developers can use WeChat's fingerprint recognition function to allow users to log in to WeChat mini programs through fingerprints, thereby improving the security and convenience of the login experience. 2. Preparation work is implemented using PHP

Introduction to how to use PHP to implement data analysis and report generation: In today's information age, data analysis and report generation are an essential part of corporate decision-making. Fortunately, this functionality can be easily achieved using the PHP programming language. This article will introduce the basic methods and techniques of using PHP to implement data analysis and report generation, and provide some code examples. 1. Data Analysis Data Collection First, we need to collect and prepare the data to be analyzed. Data can come from various sources such as databases, log files,
