askOfLeave.bpmn描述文件
<?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://www.activiti.org/test">
<process id="askOfLeave" name="请假流程" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="请假提交"></userTask>
<userTask id="usertask2" name="部门经理审批">
<documentation>{
"actions": ["1"],
"auditContent": true,
"businessFields":["days"],
"findUserType": 1,
"findUserList": ["2"]
}</documentation>
<extensionElements>
<activiti:taskListener event="create" delegateExpression="${taskCreateListener}"></activiti:taskListener>
</extensionElements>
</userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" name="提交" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow3" name="通过" sourceRef="usertask2" targetRef="exclusivegateway1"></sequenceFlow>
<userTask id="usertask3" name="总经理审批">
<documentation>{
"actions": ["1"],
"auditContent": true,
"businessFields":["days"],
"findUserType": 1,
"findUserList": ["4"]
}</documentation>
<extensionElements>
<activiti:taskListener event="create" delegateExpression="${taskCreateListener}"></activiti:taskListener>
</extensionElements>
</userTask>
<userTask id="usertask4" name="人事行政审批">
<documentation>{
"actions": ["1"],
"auditContent": true,
"findUserType": 1,
"findUserList": ["5"]
}</documentation>
<extensionElements>
<activiti:taskListener event="create" delegateExpression="${taskCreateListener}"></activiti:taskListener>
</extensionElements>
</userTask>
<endEvent id="endevent1" name="End">
<extensionElements>
<activiti:executionListener event="start" delegateExpression="${processEndListener}"></activiti:executionListener>
</extensionElements>
</endEvent>
<sequenceFlow id="flow4" name="${ form.days>=2 } " sourceRef="exclusivegateway1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${form.days>=2}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow5" name="${form.days<2}" sourceRef="exclusivegateway1" targetRef="usertask4">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${form.days<2}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow6" name="通过" sourceRef="usertask4" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow7" name="通过" sourceRef="usertask3" targetRef="usertask4"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_askOfLeave">
<bpmndi:BPMNPlane bpmnElement="askOfLeave" id="BPMNPlane_askOfLeave">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="80.0" y="200.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="180.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="360.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="540.0" y="197.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="660.0" y="100.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="660.0" y="270.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="860.0" y="280.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="115.0" y="217.0"></omgdi:waypoint>
<omgdi:waypoint x="180.0" y="217.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="285.0" y="217.0"></omgdi:waypoint>
<omgdi:waypoint x="360.0" y="217.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="18.0" width="32.0" x="299.0" y="217.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="465.0" y="217.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="217.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="18.0" width="32.0" x="480.0" y="227.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="560.0" y="197.0"></omgdi:waypoint>
<omgdi:waypoint x="560.0" y="127.0"></omgdi:waypoint>
<omgdi:waypoint x="660.0" y="127.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="54.0" width="100.0" x="530.0" y="81.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="560.0" y="237.0"></omgdi:waypoint>
<omgdi:waypoint x="560.0" y="297.0"></omgdi:waypoint>
<omgdi:waypoint x="660.0" y="297.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="54.0" width="100.0" x="550.0" y="299.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="765.0" y="297.0"></omgdi:waypoint>
<omgdi:waypoint x="860.0" y="297.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="18.0" width="32.0" x="779.0" y="297.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="712.0" y="155.0"></omgdi:waypoint>
<omgdi:waypoint x="712.0" y="270.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="18.0" width="32.0" x="730.0" y="196.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
ProcessEndListener.java 执行监听器
@Component("processEndListener")
@Slf4j
public class ProcessEndListener implements ExecutionListener {
@Autowired
private RepositoryService repositoryService;
@Autowired
private WorkflowFeign workflowFeign;
@Override
public void notify(DelegateExecution execution) throws Exception {
log.info("=====ProcessEndListener执行=====");
log.info("修改业务表单的状态为已完结");
String eventName = execution.getEventName();
log.info("事件名称:"+eventName);
String businessKey = execution.getProcessBusinessKey();
String processDefId = execution.getProcessDefinitionId();
ProcessDefinition processDefinition =
repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefId).singleResult();
String processDefinitionKey = processDefinition.getKey();
Integer state=2 ;//状态 0待提交 1审核中 2完结 3驳回重新编辑 4挂起 5作废
log.info("调用workflowFeign.updateBusinessStatus()方法");
log.info("processDefinitionKey: "+processDefinitionKey);
log.info("businessKey: "+businessKey);
log.info("state: "+state);
UpdateStatusReq req=new UpdateStatusReq(processDefinitionKey,businessKey,state);
workflowFeign.updateBusinessStatus(req);
}
}
TaskCreateListener.java 任务监听器
/**
* 新任务创建
* 寻找新任务的办理人
* (每一个任务的create任务监听器)
*/
@Slf4j
@Component("taskCreateListener")
public class TaskCreateListener implements TaskListener {
@Autowired
private TaskService taskService;
@Override
public void notify(DelegateTask delegateTask) {
log.info("===========TaskCreateListener监听器执行=============");
log.info("流程实例id:"+delegateTask.getProcessInstanceId());
log.info("流程定义id:"+delegateTask.getProcessDefinitionId());
log.info("任务id:"+delegateTask.getId());
log.info("任务名称:"+delegateTask.getName());
log.info("任务定义key:"+delegateTask.getTaskDefinitionKey());
log.info("任务描述:"+delegateTask.getDescription());//任务描述
String taskId =delegateTask.getId();
String eventName =delegateTask.getEventName();
if(eventName.equals("create")){ //任务创建
String description =delegateTask.getDescription();
TaskDescJson descJson= JSON.parseObject(description, TaskDescJson.class);
System.out.println(descJson);
//根据descJson做相应业务处理,为新的任务对象分配办理人或候选人列表 ...
//寻找办理人的方式 1直接指定(见FindUserList字段) 2按部门直属领导查找 3职位查找
int type = descJson.getFindUserType();
if(type==1){
List<String> userList= descJson.getFindUserList();
if(userList.size()==1){
taskService.setAssignee(taskId, userList.get(0));
}else{
for(String userId: userList){
taskService.addCandidateUser(taskId,userId);
}
}
}else if(type==2){
}else if(type==3){
}else{
}
}
}
}