本文以一个简单的请假流程为例,分析在流程在流转的过程中,Activiti相关表数据的变化,从而深入学习Activiti。
流程图如下:
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://activiti.org/bpmn20" id="review-definitions"> <process id="sysTakeLeave" name="Review And Approve Activiti Process" isExecutable="true"> <startEvent id="startevent1" name="Start"> <extensionElements> <activiti:formProperty id="staffId" name="员工" type="string"></activiti:formProperty> </extensionElements> </startEvent> <userTask id="applyLeaveTask" name="请假申请" activiti:candidateUsers="${staffId}"> <extensionElements> <activiti:formProperty id="reason" name="原因" type="string" required="true"></activiti:formProperty> </extensionElements> </userTask> <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="applyLeaveTask"></sequenceFlow> <exclusiveGateway id="exclusivegateway1" name="审批是否通过" default="approved"></exclusiveGateway> <sequenceFlow id="flow2" sourceRef="reviewLeaveTask" targetRef="exclusivegateway1"></sequenceFlow> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="approved" name="审批通过" sourceRef="exclusivegateway1" targetRef="endevent1"></sequenceFlow> <sequenceFlow id="refused" name="拒绝" sourceRef="exclusivegateway1" targetRef="startevent1"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!result}]]></conditionExpression> </sequenceFlow> <userTask id="reviewLeaveTask" name="领导审批" activiti:candidateUsers="${leaveService.getManagerIds(staffId)}"> <extensionElements> <activiti:formProperty id="managerId" name="经理" type="string" required="true"></activiti:formProperty> <activiti:formProperty id="result" name="结果" type="boolean"> <activiti:value id="true" name="同意"></activiti:value> <activiti:value id="false" name="不同意"></activiti:value> </activiti:formProperty> </extensionElements> </userTask> <sequenceFlow id="flow5" sourceRef="applyLeaveTask" targetRef="reviewLeaveTask"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_sysTakeLeave"> <bpmndi:BPMNPlane bpmnElement="sysTakeLeave" id="BPMNPlane_sysTakeLeave"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="90.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="applyLeaveTask" id="BPMNShape_applyLeaveTask"> <omgdc:Bounds height="55.0" width="105.0" x="210.0" y="141.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1"> <omgdc:Bounds height="40.0" width="40.0" x="520.0" y="148.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="605.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="reviewLeaveTask" id="BPMNShape_reviewLeaveTask"> <omgdc:Bounds height="55.0" width="105.0" x="370.0" y="141.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="125.0" y="168.0"></omgdi:waypoint> <omgdi:waypoint x="210.0" y="168.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="475.0" y="168.0"></omgdi:waypoint> <omgdi:waypoint x="520.0" y="168.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="approved" id="BPMNEdge_approved"> <omgdi:waypoint x="560.0" y="168.0"></omgdi:waypoint> <omgdi:waypoint x="605.0" y="168.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="48.0" x="560.0" y="168.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="refused" id="BPMNEdge_refused"> <omgdi:waypoint x="540.0" y="188.0"></omgdi:waypoint> <omgdi:waypoint x="540.0" y="299.0"></omgdi:waypoint> <omgdi:waypoint x="107.0" y="299.0"></omgdi:waypoint> <omgdi:waypoint x="107.0" y="186.0"></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:Bounds height="14.0" width="24.0" x="540.0" y="188.0"></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"> <omgdi:waypoint x="315.0" y="168.0"></omgdi:waypoint> <omgdi:waypoint x="370.0" y="168.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
2.流程发布
流程初次发布时,如下四张表中有数据:
act_re_deployment:每次流程发布时,会创建一条记录
act_ge_bytearray:保存流程配置文件和流程图,关联上面的流程发布记录
act_ge_property
act_re_procdef:流程定义
3.请假申请
请假申请时,员工登录系统后,创建一个申请:
“待我处理”菜单中,没有记录,因为他申请的流程需要部门领导才能处理:
“与我相关”菜单中,会出现他刚才提交的申请:
当部门领导登录系统后,“待我处理”、“与我相关”以及“所有”菜单中都会出现该记录,等待其处理:
此时总共有11张表发生了变化:
act_hi_actinst:已经发起的流程实例的ActivitiInstance数据
act_hi_comment
act_hi_detail:已经发起的流程实例的ActivitiInstance中提交的Form数据
act_hi_identitylink:已经发起的流程实例
act_hi_procinst:
act_hi_taskinst:
act_hi_varinst:
act_ru_execution:正在运行的流程实例的execution
act_ru_identitylink:正在运行的流程实例的人员关联
act_ru_task:正在运行的流程实例的当前任务
act_ru_variable:正在运行的流程实例中的变量及值
4.请假审批(拒绝)
领导拒绝了上一步的请假申请:
此时,部门领导的“待我处理”菜单中就没有记录了,“与我相关”和“所有”菜单中,还有有处理过的那条记录
而员工的“待我处理”和“与我相关”菜单中,则有这条被拒绝的记录:
数据库中有11张表发生变化,变化如下:
act_ge_property
act_hi_actinst
act_hi_comment
act_hi_detail
act_hi_identitylink
act_hi_taskinst
act_hi_varinst
act_ru_execution
act_ru_identitylink
act_ru_task
act_ru_variable
5.请假申请(重新申请)
员工重新发起请假申请:
员工的“待我处理”菜单列表中没有了记录,而“与我相关”菜单列表中有一条记录:
部门领导的“待我处理”、“与我相关”以及“所有”菜单列表中有一条记录:
数据库11张表发生变化:
act_ge_property
act_hi_actinst
act_hi_comment
act_hi_detail
act_hi_identitylink
act_hi_taskinst
act_hi_varinst
act_ru_execution
act_ru_identitylink
act_ru_task
act_ru_variable
6.请假审批(同意)
部门领导再次审批,同意了申请:
部门领导的“待我审批”菜单列表中没有记录,“与我相关”和“所有”菜单列表中有一条记录:
员工的“待我审批”菜单列表中没有记录,“与我相关”菜单列表中有一条记录:
数据库10张表变化如下:
act_hi_actinst
act_hi_comment
act_hi_detail
act_hi_procinst
act_hi_taskinst:任务实例的
act_hi_varinst:最后两个参数被修改过2次,因为“请假审批”任务被执行了2次,本次修改了result的值为1
act_ru_execution:流程已经结束,数据已经删除
act_ru_identitylink:流程已经结束,数据已经删除
act_ru_task:流程已经结束,数据已经删除
act_ru_variable:流程已经结束,数据已经删除