NetBPM工作流的一个示例-请假审批
在某公司中,部门员工休假需要主管(Chief)的批准。
如果休假天数大于10天,则 在部门主管同意后,还必须老板(Boss)批准。
如果是部门主管请假则直接提交老板批准。
在休假被批准之前,申请人可以撤销休假申请。
申请批准后,对休假天数进行修改(也可以是其他业务数据处理)。 每次休假申请结束之后,不管通过未通过或是否取消,都必须记录下来。
流程结束时,系统要把请假的结果信息Email给申请人。
对于大于10天的申请,如果部门主管已批准同意而上级主管还未批准,这时申请人撤销申请后,系统应发Email通知部门主管申请已撤销。
NetBPM工作流的一个示例:请假审批Made by LuBen:2007年8月12日 |
目录流程定义包源码下载(注:par包就是zip格式压缩包)。原文地址:http://www.cnblogs.com/LuBen/archive/2007/08/11/852010.html(转载请保留) 请假流程描述流程图:
假设:公司有两级领导,一级为主管(Chief),一级为老板(Boss),我们这里只是一个模拟,当然现实生活中情况比这个更加复杂;-) 描述:
流程定义之processdefinition.xml
1<?xml version="1.0"?> 2<!-- NOTE:在定义流程时,建议先画出流程图,然后再来定义,这样思维清晰,也不易于出错 3 关于processdefiniton.xml如何定义,请严格按照nPdl规定 --> 4<process-definition> 5 6 <!-- =================================== --> 7 <!-- == PROCESS DEFINITION PROPERTIES == --> 8 <!-- =================================== --> 9 <name>请假DEMO</name> 10 <description>该流程模拟公司的请假流程, Made By LuBen</description> 11 <responsible>ae</responsible> 12 13 <!-- ====================== --> 14 <!-- == START & ENDSTATE == --> 15 <!-- ====================== --> 16 <start-state name="start leave request"> 17 <description>提交请假单</description> 18 <!-- 定义了role,引擎在该start-state节点执行时,就会把执行者信息赋值给角色对应的属性“requester” --> 19 <role>requester</role> 20 <!-- 在这里定义start-state的field,它表示该filed相关联的属性,并且在该state,它对属性的访问权利。 21 如果需要定义其在web表单上的操作界面,如何进行web表单显示等,需要在webinterface.xml文件对应节点补充该field --> 22 <field attribute="start date" access="write-only-required" /> 23 <field attribute="end date" access="write-only-required" /> 24 <field attribute="leave days" access="write-only-required" /> 25 <field attribute="comment" access="write-only" /> 26 <transition to="Is Cancel Fork" /> 27 </start-state> 28 29 <!-- 结束节点除名称外不要定义其他--> 30 <end-state name="end" /> 31 32 33 <!-- ====================== --> 34 <!-- == Actions == --> 35 <!-- ====================== --> 36 <!-- 解释:这里定义process-definition节点的action,有效的事件类型为:process-instance-start, process-instance-end and process-instance-cancel --> 37 38 <!-- 此处具体为:在流程结束的时候, 发送E-Mail消息给申请者,记录请假日志 --> 39 <action event="process-instance-end" 40 handler="NetBpm.Example.LeaveOfAbsence.EmailAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 41 <!--定义action参数,供委托类实例化类调用方法时获取使用。如这里的EmailAction的run方法发送邮件,需要知道发给谁,邮件标题等等,那么 42 参数可以提供辅助--> 43 <parameter name="to">previousActor</parameter> 44 <parameter name="subject">您提交了请假申请</parameter> 45 <parameter name="message">you requested a holiday from ${start date} to ${end date} with comment ${comment}</parameter> 46 </action> 47 <!-- 此处具体为:在流程结束的时候记录请假日志, 此处Log模拟 注意:每个节点可以定义多个action --> 48 <action event="process-instance-end" 49 handler="NetBpm.Example.LeaveOfAbsence.LogLeaveInfoAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 50 <parameter name="LogInfo">记录请假日志? :) </parameter> 51 </action> 52 53 <!-- ================ --> 54 <!-- == ATTRIBUTES == --> 55 <!-- ================ --> 56 <!-- 解释:定义属性值及其序列化方式。属性值一般包括3类 --> 57 <!-- one:角色对应的属性 --> 58 <attribute name="requester" type="actor" /> 59 <attribute name="chief" type="actor" /> 60 <attribute name="boss" type="actor" /> 61 62 <!-- two:所有acitivity-state(包括start-state)处需要更新的属性,和用户表单内容对应 --> 63 <attribute name="start date" type="date" /> 64 <attribute name="end date" type="date" /> 65 <attribute name="leave days" type="integer" /> 66 <attribute name="comment" type="text" initial-value="请假理由或者备注" /> 67 <attribute name="Chief evaluation result" type="evaluation" /> 68 <attribute name="Boss evaluation result" type="evaluation" /> 69 70 <!-- three:标识属性,该属性不会在web界面上体现,主来用来存储流程标识信息,供后面的逻辑处理使用 --> 71 <!-- 该属性不会在界面上呈现, 在具体流程路径中被设置以决定Decide Which Action如何走 --> 72 <attribute name="RunTrace" type="text" /> 73 <!-- 该属性不会在界面上呈现, 该属性被用来设置流程结束将要发送给用户的邮件信息(邮件标题, 如果需要邮件内容可扩展) --> 74 <attribute name="ToUserEmailSubject" type="text" /> 75 76 <!-- =========== --> 77 <!-- == NODES == --> 78 <!-- =========== --> 79 <!-- 定义流程包含的所有节点 --> 80 81 <!-- 定义decision节点, 从decision可以流出多条边(transition),这些边可以目的地相同,也可以不同。 82 如下面,虽然decision分出了3条供选择的边,但是边的目的地都是end节点,只是边的名称不同 --> 83 <decision name="Decide Which Action" 84 handler="NetBpm.Example.LeaveOfAbsence.WhichWayDecision, NetBpm.Example.LeaveOfAbsence"> 85 <parameter name="attribute">RunTrace</parameter> 86 <transition name="approve" to="end"> 87 <action event="transition" handler="NetBpm.Example.LeaveOfAbsence.AutoSetAttributesAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 88 <parameter name="attribute">ToUserEmailSubject</parameter> 89 <parameter name="setValue">您的请假申请已经被批准 holiday from ${start date} to ${end date} with comment ${comment}</parameter> 90 </action> 91 </transition> 92 93 <transition name="disapprove" to="end" > 94 <action event="transition" handler="NetBpm.Example.LeaveOfAbsence.AutoSetAttributesAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 95 <parameter name="attribute">ToUserEmailSubject</parameter> 96 <parameter name="setValue">您的请假申请没有获得批准, holiday from ${start date} to ${end date} with comment ${comment}</parameter> 97 </action> 98 </transition> 99 100 <transition name="requestercancel" to="end"> 101 <action event="transition" handler="NetBpm.Example.LeaveOfAbsence.AutoSetAttributesAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 102 <parameter name="attribute">ToUserEmailSubject</parameter> 103 <parameter name="setValue">您取消了请假申请, holiday from ${start date} to ${end date} with comment ${comment}</parameter> 104 </action> 105 <!-- 请假人取消请假的时, 如果主管已经审批了, 则需要发邮件通知他 --> 106 <action event="transition" handler="NetBpm.Example.LeaveOfAbsence.EmailChiefAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 107 <!--- action的参数只能有3个, 切记切记, 调试的时候搞晕了--> 108 <parameter name="to">role(chief)</parameter> 109 <!--<parameter name="cancelMan">previousActor</parameter> --> 110 <parameter name="subject">请假申请被取消啦</parameter> 111 <parameter name="message"> requested a holiday from ${start date} to ${end date} with comment ${comment}</parameter> 112 </action> 113 </transition> 114 </decision> 115 116 117 <!-- ====================== --> 118 <!-- == CONCURRENT BLOCK == --> 119 <!-- ====================== --> 120 <!-- 解释:定义并发块,concurrent-block一定包括一个fork,一个join,且边不可越出其界。concurrent-block是可以嵌套的 --> 121 <concurrent-block> 122 <!-- 定义fork,若没有定义forkhandler,那么其在fork flow时将按照默认行为执行 --> 123 <fork name="Is Cancel Fork"> 124 <transition name="CancelLeaveRequest" to="Request Cancel" /> 125 <transition name="evaluation" to="IsChiefDecision" /> 126 </fork> 127 128 <!-- 定义join,此处定义了joinhandler,则当有forked flow到达join时,将根据该委托判断是否要激活父flow, 129 若没有定义joinhandler,那么将按照默认行为(AndJoin委托类,也就是所有forked flow都汇聚到达Join才激活父flow)执行 --> 130 <join name="join before decided" handler="NetBpm.Example.LeaveOfAbsence.AnyOneJoin, NetBpm.Example.LeaveOfAbsence"> 131 <transition to="Decide Which Action" /> 132 </join> 133 134 <activity-state name="Request Cancel"> 135 <description>在请假申请被最终审批前, 您可以在这里取消申请.</description> 136 <role>requester</role> 137 <!-- fields are optional. they limit the access to attributes in an activity --> 138 <field attribute="start date" access="read-only" /> 139 <field attribute="end date" access="read-only" /> 140 141 <!--eg。请假理由备注先不被看到 142 <field attribute="leave days" access="read-only" /> 143 <field attribute="comment" access="read-only" /> 144 --> 145 <action event="perform-of-activity" handler="NetBpm.Example.LeaveOfAbsence.AutoSetAttributesAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 146 <parameter name="attribute">RunTrace</parameter> 147 <parameter name="setValue">requestercancel</parameter> 148 </action> 149 <transition to="join before decided" /> 150 </activity-state> 151 152 <decision name="IsChiefDecision" handler="NetBpm.Example.LeaveOfAbsence.IsInRoleDecision, NetBpm.Example.LeaveOfAbsence"> 153 <parameter name="checkrole">chief</parameter> 154 <transition name="isChief" to="BossApprove" /> 155 <transition name="isNotChief" to="ChiefApprove" /> 156 </decision> 157 158 <activity-state name="ChiefApprove"> 159 <description>您需要在这里对该请假单进行审批</description> 160 <assignment handler="NetBpm.Example.LeaveOfAbsence.AssignmentExpressionResolver, NetBpm.Example.LeaveOfAbsence"> 161 <parameter name="expression" >role(requester)->group(hierarchy)->role(chief)</parameter> 162 </assignment> 163 <role>chief</role> 164 <field attribute="requester" access="read-only" /> 165 <field attribute="start date" access="read-only" /> 166 <field attribute="end date" access="read-only" /> 167 <field attribute="Chief evaluation result" access="write-only" /> 168 <action event="perform-of-activity" handler="NetBpm.Example.LeaveOfAbsence.EvluationResultAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 169 <parameter name="attribute">RunTrace</parameter> 170 <parameter name="setValueAttribute">Chief evaluation result</parameter> 171 </action> 172 <transition to="IsMoreTenDays" /> 173 </activity-state> 174 175 <activity-state name="BossApprove"> 176 <description>您需要在这里对该请假单进行审批</description> 177 <assignment handler="NetBpm.Example.LeaveOfAbsence.AssignmentExpressionResolver, NetBpm.Example.LeaveOfAbsence"> 178 <parameter name="expression" >role(requester)->group(hierarchy)->role(boss)</parameter> 179 </assignment> 180 <role>boss</role> 181 <field attribute="requester" access="read-only" /> 182 <field attribute="chief" access="read-only" /> 183 <field attribute="start date" access="read-only" /> 184 <field attribute="end date" access="read-only" /> 185 <!-- 理论上Boss不需要看到主管是否同意,因为不同意就不会到他这里来 186 <field attribute="leave days" access="read-only" /> 187 <field attribute="Chief evaluation result" access="read-only" /> 188 --> 189 <field attribute="Boss evaluation result" access="write-only" /> 190 <action event="perform-of-activity" handler="NetBpm.Example.LeaveOfAbsence.EvluationResultAction, NetBpm.Example.LeaveOfAbsence" on-exception="log"> 191 <parameter name="attribute">RunTrace</parameter> 192 <parameter name="setValueAttribute">Boss evaluation result</parameter> 193 </action> 194 <transition to="join before decided" /> 195 </activity-state> 196 197 <decision name="IsMoreTenDays" handler="NetBpm.Example.LeaveOfAbsence.IsMoreOrLessDecision, NetBpm.Example.LeaveOfAbsence"> 198 <parameter name="attribute">leave days</parameter> 199 <parameter name="dividingDays">10</parameter> 200 <!--考虑扩展,形成对数值比较类的通用 <parameter name="datatype">float</parameter> 201 <parameter name="compareType">More</parameter> --> 202 <transition name="IsMore" to="BossApprove" /> 203 <transition name="IsnotMore" to="join before decided" /> 204 </decision> 205 206 </concurrent-block> 207 208</process-definition> 209 |