啦啦啦啦啦,富贵同学又开始开坑了,出了个免费的专栏,主要给大家从0基础开始用springBoot集成第三方的插件或者功能,如果这篇专栏能帮到你,一定不要忘了点一个赞哦!!欢迎大家收藏分享
如果没有看过富贵同学的第一篇请移步到这个地址查看SpringBoot集成Activiti(一)
第一步,取消yml的配置,因为我们需要创建一个流程
leave.bpmn
文件感谢(https://gitee.com/shenzhanwang/Spring-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://www.activiti.org/test">
<process id="leave" name="My process" isExecutable="true">
<userTask id="deptleaderaudit" name="部门领导审批" activiti:assignee="${deptleader}" activiti:candidateGroups="部门经理"></userTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<userTask id="hraudit" name="人事审批" activiti:assignee="${hr}" activiti:candidateGroups="人事"></userTask>
<sequenceFlow id="flow3" name="同意" sourceRef="exclusivegateway1" targetRef="hraudit">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptleaderapprove=='true'}]]></conditionExpression>
</sequenceFlow>
<userTask id="modifyapply" name="调整申请" activiti:assignee="${applyuserid}"></userTask>
<sequenceFlow id="flow4" name="拒绝" sourceRef="exclusivegateway1" targetRef="modifyapply">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptleaderapprove=='false'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow6" sourceRef="deptleaderaudit" targetRef="exclusivegateway1"></sequenceFlow>
<exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow7" sourceRef="modifyapply" targetRef="exclusivegateway2"></sequenceFlow>
<sequenceFlow id="flow8" name="重新申请" sourceRef="exclusivegateway2" targetRef="deptleaderaudit">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${reapply=='true'}]]></conditionExpression>
</sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow9" name="结束流程" sourceRef="exclusivegateway2" targetRef="endevent1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${reapply=='false'}]]></conditionExpression>
</sequenceFlow>
<exclusiveGateway id="exclusivegateway3" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow10" sourceRef="hraudit" targetRef="exclusivegateway3"></sequenceFlow>
<sequenceFlow id="flow11" name="拒绝" sourceRef="exclusivegateway3" targetRef="modifyapply">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrapprove=='false'}]]></conditionExpression>
</sequenceFlow>
<userTask id="reportback" name="销假" activiti:assignee="${applyuserid}"></userTask>
<sequenceFlow id="flow12" name="同意" sourceRef="exclusivegateway3" targetRef="reportback">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrapprove=='true'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow13" sourceRef="reportback" targetRef="endevent1"></sequenceFlow>
<startEvent id="startevent1" name="Start" activiti:initiator="${applyuserid}"></startEvent>
<sequenceFlow id="flow14" sourceRef="startevent1" targetRef="deptleaderaudit"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_leave">
<bpmndi:BPMNPlane bpmnElement="leave" id="BPMNPlane_leave">
<bpmndi:BPMNShape bpmnElement="deptleaderaudit" id="BPMNShape_deptleaderaudit">
<omgdc:Bounds height="55.0" width="105.0" x="250.0" y="220.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="535.0" y="227.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="hraudit" id="BPMNShape_hraudit">
<omgdc:Bounds height="55.0" width="105.0" x="620.0" y="220.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="modifyapply" id="BPMNShape_modifyapply">
<omgdc:Bounds height="55.0" width="105.0" x="503.0" y="310.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
<omgdc:Bounds height="40.0" width="40.0" x="535.0" y="410.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="890.0" y="413.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway3" id="BPMNShape_exclusivegateway3">
<omgdc:Bounds height="40.0" width="40.0" x="770.0" y="228.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="reportback" id="BPMNShape_reportback">
<omgdc:Bounds height="55.0" width="105.0" x="855.0" y="221.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="140.0" y="230.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="575.0" y="247.0"></omgdi:waypoint>
<omgdi:waypoint x="620.0" y="247.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="48.0" width="24.0" x="575.0" y="247.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="555.0" y="267.0"></omgdi:waypoint>
<omgdi:waypoint x="555.0" y="310.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="48.0" width="24.0" x="555.0" y="267.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="355.0" y="247.0"></omgdi:waypoint>
<omgdi:waypoint x="535.0" y="247.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="555.0" y="365.0"></omgdi:waypoint>
<omgdi:waypoint x="555.0" y="410.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="535.0" y="430.0"></omgdi:waypoint>
<omgdi:waypoint x="302.0" y="429.0"></omgdi:waypoint>
<omgdi:waypoint x="302.0" y="275.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="48.0" width="48.0" x="361.0" y="438.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="575.0" y="430.0"></omgdi:waypoint>
<omgdi:waypoint x="890.0" y="430.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="48.0" width="48.0" x="659.0" y="437.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="725.0" y="247.0"></omgdi:waypoint>
<omgdi:waypoint x="770.0" y="248.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
<omgdi:waypoint x="790.0" y="268.0"></omgdi:waypoint>
<omgdi:waypoint x="789.0" y="337.0"></omgdi:waypoint>
<omgdi:waypoint x="608.0" y="337.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="48.0" width="24.0" x="672.0" y="319.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
<omgdi:waypoint x="810.0" y="248.0"></omgdi:waypoint>
<omgdi:waypoint x="855.0" y="248.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="48.0" width="24.0" x="810.0" y="248.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
<omgdi:waypoint x="907.0" y="276.0"></omgdi:waypoint>
<omgdi:waypoint x="907.0" y="413.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
<omgdi:waypoint x="175.0" y="247.0"></omgdi:waypoint>
<omgdi:waypoint x="250.0" y="247.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
这是一个简单的请假申请流程
放入指定的文件夹中之后,我们重新启动启动类
第二步,查看我们的数据表
ACT_RE_PROCDEF
中可以查看到我们的流程
至此之后我们的流程就创建完成了,现在来我们的api操作
第三步,由于我们要跟我们的业务连接到一起,所以我们创建一个请假表
CREATE TABLE `leave` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`process_instance_id` varchar(45) DEFAULT NULL COMMENT '流程表id',
`user_id` varchar(20) DEFAULT NULL COMMENT '用户id',
`start_time` varchar(45) DEFAULT NULL COMMENT '开始时间',
`end_time` varchar(45) DEFAULT NULL COMMENT '结束时间',
`leave_type` varchar(45) DEFAULT NULL COMMENT '请假类型',
`reason` varchar(400) DEFAULT NULL COMMENT '请假原因',
`apply_time` datetime DEFAULT NULL COMMENT '通过时间',
`reality_start_time` varchar(45) DEFAULT NULL COMMENT '请假开始时间',
`reality_end_time` varchar(45) DEFAULT NULL COMMENT '请假结束时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='请假表';
第四步,集成底层框架
对了,我们没有数据库框架,这里我们使用mybatisPlusPro来作为底层框架
第五步,创建controller等类
import com.wangfugui.activiti.dao.LeaveDO;
import com.wangfugui.activiti.service.LeaveService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author MaSiyi
* @version 1.0.0 2021/12/2
* @since JDK 1.8.0
*/
@RestController
@RequestMapping("/leave")
public class LeaveController extends BaseController<LeaveService, LeaveDO>{
}
import com.baomidou.mybatisplus.extension.service.IService;
import com.wangfugui.activiti.dao.LeaveDO;
/**
* @author MaSiyi
* @version 1.0.0 2021/12/2
* @since JDK 1.8.0
*/
public interface LeaveService extends IService<LeaveDO> {
}
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangfugui.activiti.dao.LeaveDO;
import com.wangfugui.activiti.dao.mapper.LeaveMapper;
import com.wangfugui.activiti.service.LeaveService;
import org.springframework.stereotype.Service;
/**
* @author MaSiyi
* @version 1.0.0 2021/12/2
* @since JDK 1.8.0
*/
@Service
public class LeaveServiceImpl extends ServiceImpl<LeaveMapper, LeaveDO> implements LeaveService {
}
好了,就是这么的简单,完整代码请移至SpringBoot+Activiti 查看