springCloud集成activiti5.22.0流程引擎
点关注不迷路,欢迎再访!
精简博客内容,尽量已行业术语来分享。
努力做到对每一位认可自己的读者负责。
帮助别人的同时更是丰富自己的良机。
文章目录
一.Spring boot2.x与Activiti 5.22.0整合
1.POM文件中添加依赖
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>5.22.0</version>
<exclusions>
<!-- 排除activiti的mybatis,避免和外面的mybatis-plus冲突 -->
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>
二.制作bpmn流程文件
创建bpmn文件
右键该文件夹New–>BPMN File 创建名为leave_flow的流程文件
文件名"xxx.bpmn" 更改为 “xxx.bpmn.xml”
注: 因为activiti的默认流程图格式是bpmn, 但是idea必须xml格式才能生成图片, 所以改为这样, 后面部署流程的时候才可以部署上去, 否则是存不进数据库.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/testm1723732311976" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1723732311976" name="" targetNamespace="http://www.activiti.org/testm1723732311976" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="leaveProcess" isClosed="false" isExecutable="true" name="请假审批流程" processType="None">
<startEvent id="STEP1" name="开始"/>
<userTask activiti:assignee="${userId}" activiti:exclusive="true" id="STEP2" name="员工"/>
<userTask activiti:assignee="${userId}" activiti:exclusive="true" id="STEP3" name="经理"/>
<endEvent id="STEP4" name="结束"/>
<sequenceFlow id="_6" sourceRef="STEP1" targetRef="STEP2"/>
<sequenceFlow id="_7" sourceRef="STEP2" targetRef="STEP3"/>
<exclusiveGateway gatewayDirection="Unspecified" id="_8" name="ExclusiveGateway"/>
<sequenceFlow id="_2" name="同意" sourceRef="_8" targetRef="STEP4">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${accept==”同意”}]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="_3" sourceRef="STEP3" targetRef="_8"/>
<sequenceFlow id="_4" name="驳回" sourceRef="_8" targetRef="STEP2">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[${accept==”驳回”}]]>
</conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
<bpmndi:BPMNPlane bpmnElement="leaveProcess">
<bpmndi:BPMNShape bpmnElement="STEP1" id="Shape-STEP1">
<dc:Bounds height="32.0" width="32.0" x="160.0" y="40.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="STEP2" id="Shape-STEP2">
<dc:Bounds height="55.0" width="85.0" x="130.0" y="145.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="STEP3" id="Shape-STEP3">
<dc:Bounds height="55.0" width="85.0" x="135.0" y="275.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="STEP4" id="Shape-STEP4">
<dc:Bounds height="32.0" width="32.0" x="325.0" y="525.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_8" id="Shape-_8" isMarkerVisible="false">
<dc:Bounds height="32.0" width="32.0" x="325.0" y="400.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="_2" id="BPMNEdge__2" sourceElement="_8" targetElement="STEP4">
<di:waypoint x="341.0" y="432.0"/>
<di:waypoint x="341.0" y="525.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_3" id="BPMNEdge__3" sourceElement="STEP3" targetElement="_8">
<di:waypoint x="175.0" y="330.0"/>
<di:waypoint x="175.0" y="410.0"/>
<di:waypoint x="331.0" y="410.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_4" id="BPMNEdge__4" sourceElement="_8" targetElement="STEP2">
<di:waypoint x="340.0" y="401.0"/>
<di:waypoint x="340.0" y="285.0"/>
<di:waypoint x="215.0" y="172.5"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6" sourceElement="STEP1" targetElement="STEP2">
<di:waypoint x="176.0" y="72.0"/>
<di:waypoint x="176.0" y="145.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7" sourceElement="STEP2" targetElement="STEP3">
<di:waypoint x="175.0" y="200.0"/>
<di:waypoint x="175.0" y="275.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
三.流程演示
分支审批
/**
* @param processInstanceId 流程实例
* @param isAccept 0:同意 1:驳回
* @param userId 审批人
*/
@Override
public void assginLeaveWorkFlow(String processInstanceId,int isAccept,String userId) {
Map<String,Object> map = new HashMap<>();
//得到当前实例下的task
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
taskService.addComment(task.getId(), processInstanceId, "审核人是否同意该请假流程");
if(isAccept == 0){
map.put("accept","同意");
task.setAssignee(userId);
map.put("userId", userId);
}else{
map.put("accept","驳回");
//审核驳回后
task.setAssignee("发起人");
map.put("auditor","发起人");
}
task.setDescription("请假的描述信息");
//执行当前这个工作流任务
taskService.saveTask(task);
taskService.complete(task.getId(), map);
}