开源的工作流很少有让人满意的,即便是国内用的比较多的jbpm,用起来也会觉得很便扭。再加上PHP中没有什么好用的工作流,于是干脆自己设计一个,设计的原则如下:
1 根据80/20原则,只使用wfmc模型中最符合自身应用的20%功能
2 充分吸收国内使用jbpm开发BOSS中遇到的问题,工作流引擎只负责参数的收集和流程的流转,具体和业务的控制,交给每个流程定制的控制类去实现。
3 表单采用简单的html+控制标签的方法实现
4 权限和模板引擎,以及其它辅助函数直接使用办公系统自带的框架
5 充分利用PHP语言的特点,流程设计是基于数据库的,程序上使用OO设计,但采用重对象的方法
6 不把可视化设计流程的工作交给最终客户,而且由设计时完成,因此不考虑流程版本更新的问题
一、工作流数据表设计
tbl_workflow_defination:工作流定义表
defination_id |
流程id |
|
defination_name |
流程名称 |
|
defination_handler |
流程处理辅助文件,每个工作流一个文件 |
自定义处理文件,及其对象。例如workflow-proporsal-handler.php,其中定义对象proposal |
tbl_workflow_node:流程结点步骤表
node_id |
结点id |
|
defination_id |
流程id |
|
node_index |
结点序号 |
结点的step |
node_name |
结点名称 |
|
node_type |
结点类型 |
1人为决策,2自动处理(直接执行execute_function),3等待外部响应(例如外部WS触发),4分支,5汇总 6结束结点(此结点执行时候自动终止进程) |
init_function |
流程初始函数 |
|
run_function |
流程运行函数 |
|
save_function |
流程保存函数 |
|
transit_function |
流程流转函数 |
|
prev_node_index |
前结点序号 |
例如1。开始结点没有 执行前,通过此来校验一下流程 |
next_node_index |
后结点序号 |
例如[同意]3,[不同意]4。尾结点或要结束的结点没有,若没有,直接调用end |
executor |
执行角色,组,人 |
role[1,2] group[1,2] user[1,2],为空由运行时决定 |
execute_type |
执行类型 |
0需所有人执行 1只需一人执行 |
remind |
提醒 |
0不提醒 1邮件 2短信 3邮件和短信 |
field |
可编辑的字段 |
name,content |
max_day |
最长时间(天) |
|
tbl_workflow_process :流程执行进程表
process_id |
进程id |
|
defination_id |
流程id |
|
process_desc |
进程描述 |
显示在我的工作台中 |
context |
上下文 |
存放上下文变量,例如业务表的id |
current_node_index |
当前结点序号 |
|
start_time |
流程启动时间 |
如遇分支、汇合显示为: 1=》3,4=》3,5=》6 |
finish_time |
流程完成时间 |
|
state |
状态 |
1运行 2结束 |
start_user |
发起人 |
发起人,用于显示自己的流程 |
tbl_workflow_thread :流程执行线程表
thread_id |
线程id |
|
process_id |
进程id |
|
process_desc |
进程描述 |
|
node_id |
结点id |
|
node_name |
结点名称 |
|
executor |
执行人 |
|
start_time |
线程生成时间 |
|
receive_time |
线程接收时间 |
|
finish_time |
线程完成时间 |
|
max_time |
结点规定的最长时间 |
|
state |
状态 |
0未接收 1已接收 2已处理 |
二、常见流程
人工决策
<group id="_x0000_s1026" style="WIDTH: 414pt; HEIGHT: 265.2pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" coordsize="8280,5304" coordorigin="1800,6715" editas="canvas"><lock aspectratio="t" v:ext="edit"></lock><shapetype id="_x0000_t75" coordsize="21600,21600" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_s1027" style="LEFT: 1800px; WIDTH: 8280px; POSITION: absolute; TOP: 6715px; HEIGHT: 5304px" o:preferrelative="f" type="#_x0000_t75"><font size="3"><fill o:detectmouseclick="t"></fill><path o:connecttype="none" o:extrusionok="t"></path><lock v:ext="edit" text="t"></lock></font></shape><shapetype id="_x0000_t109" coordsize="21600,21600" path="m,l,21600r21600,l21600,xe" o:spt="109"><stroke joinstyle="miter"></stroke><path o:connecttype="rect" gradientshapeok="t"></path></shapetype><shape id="_x0000_s1028" style="LEFT: 5220px; WIDTH: 1261px; POSITION: absolute; TOP: 10147px; HEIGHT: 466px" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1028"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">领导传阅</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shapetype id="_x0000_t110" coordsize="21600,21600" path="m10800,l,10800,10800,21600,21600,10800xe" o:spt="110"><stroke joinstyle="miter"></stroke><path o:connecttype="rect" gradientshapeok="t" textboxrect="5400,5400,16200,16200"></path></shapetype><shape id="_x0000_s1029" style="LEFT: 4320px; WIDTH: 2700px; POSITION: absolute; TOP: 7963px; HEIGHT: 1405px" type="#_x0000_t110"><textbox style="mso-next-textbox: #_x0000_s1029"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">部门领导审批</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shape id="_x0000_s1030" style="LEFT: 5220px; WIDTH: 1261px; POSITION: absolute; TOP: 7027px; HEIGHT: 468px" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1030"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">填写表单</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shapetype id="_x0000_t120" coordsize="21600,21600" path="m10800,qx,10800,10800,21600,21600,10800,10800,xe" o:spt="120"><path o:connecttype="custom" gradientshapeok="t" textboxrect="3163,3163,18437,18437" o:connectlocs="10800,0;3163,3163;0,10800;3163,18437;10800,21600;18437,18437;21600,10800;18437,3163"></path></shapetype><shape id="_x0000_s1031" style="LEFT: 5223px; WIDTH: 922px; POSITION: absolute; TOP: 11086px; HEIGHT: 682px" type="#_x0000_t120"><textbox style="mso-next-textbox: #_x0000_s1031"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">结束</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><line id="_x0000_s1032" style="POSITION: absolute" from="6481,7184" to="8100,7184"><font size="3"></font></line><line id="_x0000_s1033" style="POSITION: absolute" from="8100,7184" to="8100,11395"><font size="3"></font></line><line id="_x0000_s1034" style="POSITION: absolute; flip: x" from="6105,11395" to="8100,11396"><stroke endarrow="block"><font size="3"></font></stroke></line><line id="_x0000_s1035" style="POSITION: absolute" from="5663,7495" to="5664,7963"><stroke endarrow="block"><font size="3"></font></stroke></line><line id="_x0000_s1036" style="POSITION: absolute" from="5685,9376" to="5685,10151"><stroke endarrow="block"><font size="3"></font></stroke></line><line id="_x0000_s1037" style="POSITION: absolute" from="5685,10621" to="5685,11086"><stroke endarrow="block"><font size="3"></font></stroke></line><line id="_x0000_s1038" style="POSITION: absolute" from="7008,8668" to="7008,11396"><stroke endarrow="block"><font size="3"></font></stroke></line><line id="_x0000_s1039" style="POSITION: absolute; flip: y" from="4299,7211" to="4299,8668"><font size="3"></font></line><line id="_x0000_s1040" style="POSITION: absolute" from="4299,7211" to="5244,7211"><stroke endarrow="block"><font size="3"></font></stroke></line><shape id="_x0000_s1041" style="LEFT: 6609px; WIDTH: 903px; POSITION: absolute; TOP: 6715px; HEIGHT: 468px" stroked="f" filled="f" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1041"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">放弃</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shape id="_x0000_s1042" style="LEFT: 5748px; WIDTH: 903px; POSITION: absolute; TOP: 7521px; HEIGHT: 468px" stroked="f" filled="f" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1042"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">提交</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shape id="_x0000_s1043" style="LEFT: 4866px; WIDTH: 903px; POSITION: absolute; TOP: 9443px; HEIGHT: 468px" stroked="f" filled="f" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1043"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">同意</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shape id="_x0000_s1044" style="LEFT: 3081px; WIDTH: 1176px; POSITION: absolute; TOP: 7676px; HEIGHT: 837px" stroked="f" filled="f" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1044"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">重填(退回)</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shape id="_x0000_s1045" style="LEFT: 7029px; WIDTH: 987px; POSITION: absolute; TOP: 8730px; HEIGHT: 713px" stroked="f" filled="f" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1045"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">不同意</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><shape id="_x0000_s1046" style="LEFT: 4824px; WIDTH: 903px; POSITION: absolute; TOP: 10683px; HEIGHT: 468px" stroked="f" filled="f" type="#_x0000_t109"><textbox style="mso-next-textbox: #_x0000_s1046"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">完成</font></span></p> </div> </td> </tr></tbody></table></textbox></shape><wrap type="none"></wrap><anchorlock></anchorlock></group>
外部响应
<group id="_x0000_s1047" style="WIDTH: 414pt; HEIGHT: 124.8pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" coordsize="7200,2173" coordorigin="2362,2600" editas="canvas"><lock aspectratio="t" v:ext="edit"></lock><shape id="_x0000_s1048" style="LEFT: 2362px; WIDTH: 7200px; POSITION: absolute; TOP: 2600px; HEIGHT: 2173px" o:preferrelative="f" type="#_x0000_t75"><font size="3"><fill o:detectmouseclick="t"></fill><path o:connecttype="none" o:extrusionok="t"></path><lock v:ext="edit" text="t"></lock></font></shape><shape id="_x0000_s1049" style="LEFT: 4710px; WIDTH: 2035px; POSITION: absolute; TOP: 2736px; HEIGHT: 407px" type="#_x0000_t109"><textbox><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr> <td style="BORDER-LEFT-COLOR: #ebe9ed; BORDER-BOTTOM-COLOR: #ebe9ed; BORDER-TOP-COLOR: #ebe9ed; BACKGROUND-COLOR: transparent; BORDER-RIGHT-COLOR: #ebe9ed"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Time