在之前的文章已經(jīng)介紹過(guò)Activiti7的基本使用眷篇,現(xiàn)在就使用springboot整合Activiti7球榆,完成一個(gè)完整的請(qǐng)假流程随抠。
Activiti7 發(fā)布正式版之后,它與 SpringBoot2.x 已經(jīng)完全支持整合開(kāi)發(fā)荸型。
Activti7 新支持ProcessRuntime 接口和TaskRuntime 接口盹靴,我沒(méi)有嘗試用這兩個(gè)接口,想用的朋友可以自己研究瑞妇。
首先創(chuàng)建一個(gè)springboot項(xiàng)目稿静,添加Activiti依賴(lài),如下:
<dependency>
? <groupId>org.activiti</groupId>
? <artifactId>activiti-spring-boot-starter</artifactId>
? <version>7.0.0.Beta2</version>
</dependency>
因?yàn)?Activiti7 與 SpringBoot 整合后辕狰,默認(rèn)情況下改备,集成了 SpringSecurity 安全框架,所以我們就要去準(zhǔn)備 SpringSecurity 整合進(jìn)來(lái)的相關(guān)用戶(hù)權(quán)限配置信息(該配置我就不貼出來(lái)了)蔓倍。
項(xiàng)目搭建好后悬钳,就要畫(huà)流程圖:
整個(gè)流程是這樣:請(qǐng)假人填寫(xiě)請(qǐng)假信息提交后润脸,就開(kāi)啟一個(gè)流程實(shí)例,并完成“填寫(xiě)請(qǐng)假信息”任務(wù)他去,然后到“部門(mén)主管審批”毙驯,審批不通過(guò)就返回“填寫(xiě)請(qǐng)假信息”,審批通過(guò)并且請(qǐng)假天數(shù)小于等于5天灾测,就轉(zhuǎn)到“人事存檔”爆价,審批通過(guò)并且請(qǐng)假天數(shù)大于5天,轉(zhuǎn)到“總經(jīng)理審批”媳搪,經(jīng)理審批不通過(guò)就跳回“填寫(xiě)請(qǐng)假信息”铭段,經(jīng)理審批通過(guò)就轉(zhuǎn)到“人事存檔”,“人事存檔”完成任務(wù)就轉(zhuǎn)到“行政考勤”和“財(cái)務(wù)統(tǒng)計(jì)”秦爆,當(dāng)“行政考勤”和“財(cái)務(wù)統(tǒng)計(jì)”都完成任務(wù)序愚,整個(gè)流程結(jié)束。
下邊是流程圖的詳細(xì)信息:
<?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:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" 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="m1574936357289" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
? <process id="qingjia_1" isClosed="false" isExecutable="true" name="請(qǐng)假申請(qǐng)流程" processType="None">
? ? <startEvent id="_2" name="請(qǐng)假申請(qǐng)開(kāi)始"/>
? ? <userTask activiti:exclusive="true" id="_3" name="填寫(xiě)請(qǐng)假信息"/>
? ? <userTask activiti:exclusive="true" id="_4" name="部門(mén)主管審批">
? ? ? <extensionElements>
? ? ? ? <activiti:taskListener class="com.lxm.sbactiviti.listener.ZhuGuanListener" event="create"/>
? ? ? </extensionElements>
? ? </userTask>
? ? <exclusiveGateway gatewayDirection="Unspecified" id="_5" name="ExclusiveGateway"/>
? ? <userTask activiti:exclusive="true" id="_6" name="總經(jīng)理審批">
? ? ? <extensionElements>
? ? ? ? <activiti:taskListener class="com.lxm.sbactiviti.listener.ZongJingLiListener" event="create"/>
? ? ? </extensionElements>
? ? </userTask>
? ? <exclusiveGateway gatewayDirection="Unspecified" id="_7" name="ExclusiveGateway"/>
? ? <userTask activiti:exclusive="true" id="_8" name="人事存檔">
? ? ? <extensionElements>
? ? ? ? <activiti:taskListener class="com.lxm.sbactiviti.listener.RenShiListener" event="create"/>
? ? ? </extensionElements>
? ? </userTask>
? ? <parallelGateway gatewayDirection="Unspecified" id="_9" name="ParallelGateway"/>
? ? <userTask activiti:exclusive="true" id="_10" name="行政考勤">
? ? ? <extensionElements>
? ? ? ? <activiti:taskListener class="com.lxm.sbactiviti.listener.XingZhengListener" event="create"/>
? ? ? </extensionElements>
? ? </userTask>
? ? <userTask activiti:exclusive="true" id="_11" name="財(cái)務(wù)統(tǒng)計(jì)">
? ? ? <extensionElements>
? ? ? ? <activiti:taskListener class="com.lxm.sbactiviti.listener.CaiWuListener" event="create"/>
? ? ? </extensionElements>
? ? </userTask>
? ? <parallelGateway gatewayDirection="Unspecified" id="_12" name="ParallelGateway"/>
? ? <endEvent id="_13" name="請(qǐng)假申請(qǐng)結(jié)束"/>
? ? <sequenceFlow id="_14" sourceRef="_2" targetRef="_3"/>
? ? <sequenceFlow id="_15" sourceRef="_3" targetRef="_4"/>
? ? <sequenceFlow id="_16" sourceRef="_4" targetRef="_5"/>
? ? <sequenceFlow id="_17" sourceRef="_5" targetRef="_8">
? ? ? <conditionExpression xsi:type="tFormalExpression"></conditionExpression>
? ? </sequenceFlow>
? ? <sequenceFlow id="_18" sourceRef="_5" targetRef="_6">
? ? ? <conditionExpression xsi:type="tFormalExpression">5}]]></conditionExpression>
? ? </sequenceFlow>
? ? <sequenceFlow id="_19" sourceRef="_6" targetRef="_7"/>
? ? <sequenceFlow id="_20" sourceRef="_7" targetRef="_8">
? ? ? <conditionExpression xsi:type="tFormalExpression"></conditionExpression>
? ? </sequenceFlow>
? ? <sequenceFlow id="_21" sourceRef="_8" targetRef="_9"/>
? ? <sequenceFlow id="_22" sourceRef="_9" targetRef="_10"/>
? ? <sequenceFlow id="_23" sourceRef="_9" targetRef="_11"/>
? ? <sequenceFlow id="_24" sourceRef="_10" targetRef="_12"/>
? ? <sequenceFlow id="_25" sourceRef="_11" targetRef="_12"/>
? ? <sequenceFlow id="_26" sourceRef="_12" targetRef="_13"/>
? ? <sequenceFlow id="_27" sourceRef="_7" targetRef="_3">
? ? ? <conditionExpression xsi:type="tFormalExpression"></conditionExpression>
? ? </sequenceFlow>
? ? <sequenceFlow id="_28" sourceRef="_5" targetRef="_3">
? ? ? <conditionExpression xsi:type="tFormalExpression"></conditionExpression>
? ? </sequenceFlow>
? </process>
? <bpmndi:BPMNDiagram documentation="background=#FFFFFF;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="qingjia_1">
? ? ? <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="175.0" y="5.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="150.0" y="95.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="150.0" y="195.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5" isMarkerVisible="false">
? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="175.0" y="305.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6">
? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="295.0" y="295.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7" isMarkerVisible="false">
? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="320.0" y="430.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_8" id="Shape-_8">
? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="150.0" y="420.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_9" id="Shape-_9">
? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="250.0" y="520.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_10" id="Shape-_10">
? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="155.0" y="585.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_11" id="Shape-_11">
? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="300.0" y="585.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_12" id="Shape-_12">
? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="255.0" y="680.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNShape bpmnElement="_13" id="Shape-_13">
? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="255.0" y="760.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNShape>
? ? ? <bpmndi:BPMNEdge bpmnElement="_15" id="BPMNEdge__15" sourceElement="_3" targetElement="_4">
? ? ? ? <omgdi:waypoint x="192.5" y="150.0"/>
? ? ? ? <omgdi:waypoint x="192.5" y="195.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_2" targetElement="_3">
? ? ? ? <omgdi:waypoint x="191.0" y="37.0"/>
? ? ? ? <omgdi:waypoint x="191.0" y="95.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_17" id="BPMNEdge__17" sourceElement="_5" targetElement="_8">
? ? ? ? <omgdi:waypoint x="191.0" y="337.0"/>
? ? ? ? <omgdi:waypoint x="191.0" y="420.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_16" id="BPMNEdge__16" sourceElement="_4" targetElement="_5">
? ? ? ? <omgdi:waypoint x="191.0" y="250.0"/>
? ? ? ? <omgdi:waypoint x="191.0" y="305.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_19" id="BPMNEdge__19" sourceElement="_6" targetElement="_7">
? ? ? ? <omgdi:waypoint x="336.0" y="350.0"/>
? ? ? ? <omgdi:waypoint x="336.0" y="430.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_18" id="BPMNEdge__18" sourceElement="_5" targetElement="_6">
? ? ? ? <omgdi:waypoint x="207.0" y="321.0"/>
? ? ? ? <omgdi:waypoint x="295.0" y="322.5"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_20" id="BPMNEdge__20" sourceElement="_7" targetElement="_8">
? ? ? ? <omgdi:waypoint x="320.0" y="446.0"/>
? ? ? ? <omgdi:waypoint x="235.0" y="447.5"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_22" id="BPMNEdge__22" sourceElement="_9" targetElement="_10">
? ? ? ? <omgdi:waypoint x="265.0" y="551.0"/>
? ? ? ? <omgdi:waypoint x="265.0" y="575.0"/>
? ? ? ? <omgdi:waypoint x="240.0" y="612.5"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_21" id="BPMNEdge__21" sourceElement="_8" targetElement="_9">
? ? ? ? <omgdi:waypoint x="190.0" y="475.0"/>
? ? ? ? <omgdi:waypoint x="190.0" y="505.0"/>
? ? ? ? <omgdi:waypoint x="250.0" y="536.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_24" id="BPMNEdge__24" sourceElement="_10" targetElement="_12">
? ? ? ? <omgdi:waypoint x="195.0" y="640.0"/>
? ? ? ? <omgdi:waypoint x="195.0" y="670.0"/>
? ? ? ? <omgdi:waypoint x="255.0" y="696.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_23" id="BPMNEdge__23" sourceElement="_9" targetElement="_11">
? ? ? ? <omgdi:waypoint x="282.0" y="536.0"/>
? ? ? ? <omgdi:waypoint x="340.0" y="575.0"/>
? ? ? ? <omgdi:waypoint x="340.0" y="585.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_26" id="BPMNEdge__26" sourceElement="_12" targetElement="_13">
? ? ? ? <omgdi:waypoint x="271.0" y="712.0"/>
? ? ? ? <omgdi:waypoint x="271.0" y="760.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_25" id="BPMNEdge__25" sourceElement="_11" targetElement="_12">
? ? ? ? <omgdi:waypoint x="340.0" y="640.0"/>
? ? ? ? <omgdi:waypoint x="340.0" y="660.0"/>
? ? ? ? <omgdi:waypoint x="287.0" y="696.0"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_28" id="BPMNEdge__28" sourceElement="_5" targetElement="_3">
? ? ? ? <omgdi:waypoint x="175.0" y="321.0"/>
? ? ? ? <omgdi:waypoint x="100.0" y="220.0"/>
? ? ? ? <omgdi:waypoint x="150.0" y="122.5"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? ? <bpmndi:BPMNEdge bpmnElement="_27" id="BPMNEdge__27" sourceElement="_7" targetElement="_3">
? ? ? ? <omgdi:waypoint x="352.0" y="446.0"/>
? ? ? ? <omgdi:waypoint x="420.0" y="300.0"/>
? ? ? ? <omgdi:waypoint x="235.0" y="122.5"/>
? ? ? ? <bpmndi:BPMNLabel>
? ? ? ? ? <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
? ? ? ? </bpmndi:BPMNLabel>
? ? ? </bpmndi:BPMNEdge>
? ? </bpmndi:BPMNPlane>
? </bpmndi:BPMNDiagram>
</definitions>
在除了“填寫(xiě)請(qǐng)假信息”外的所有任務(wù)等限,都添加了監(jiān)聽(tīng)器爸吮,作用是在這些任務(wù)創(chuàng)建時(shí),添加任務(wù)的候選人望门,然后這些候選人都可以查看到這些任務(wù)形娇,然后可以領(lǐng)取任務(wù)并完成任務(wù)。在排他網(wǎng)關(guān)的出口都添加判斷條件筹误,這些條件在上面xml中都有桐早。
然后我們啟動(dòng)springboot項(xiàng)目,發(fā)現(xiàn)數(shù)據(jù)庫(kù)表只有17張厨剪,但不影響操作哄酝;
首先部署流程:
//部署流程定義
@RequestMapping(value= "deploy/{zipName}")
@ResponseBody
public Respon deploy(@PathVariable(name="zipName")String zipName){
? ? Respon respon=new Respon();
? ? //轉(zhuǎn)化出ZipInputStream流對(duì)象
? ? InputStream is = TestController.class.getClassLoader().getResourceAsStream("diagram/"+zipName+".zip");
? ? //將 inputstream流轉(zhuǎn)化為ZipInputStream流
? ? ZipInputStream zipInputStream = new ZipInputStream(is);
? ? //進(jìn)行部署
? ? Deployment deployment = repositoryService.createDeployment()
? ? ? ? ? ? .addZipInputStream(zipInputStream).deploy();
? ? //輸出部署的一些信息
? ? System.out.println(deployment.getId());
? ? respon.setCode(Constant.CODE_SUCCESS);
? ? respon.setMsg(Constant.CODE_SUCCESS_STRING);
? ? return respon;
}
開(kāi)始請(qǐng)假
//開(kāi)始一個(gè)請(qǐng)假流程,并完成填寫(xiě)請(qǐng)假申請(qǐng)信息
@RequestMapping(value= "startTest/{userName}/{totalDay}")
@ResponseBody
public Respon startTest(@PathVariable(name="userName")String userName, @PathVariable(name="totalDay")Float totalDay){
? ? Respon respon=new Respon();
? ? String key="qingjia_1";
? ? ProcessInstance processInstance=runtimeService.startProcessInstanceByKey(key);
? ? String processInstanceId=processInstance.getProcessInstanceId();
? ? System.out.println(processInstanceId);
? ? System.out.println("開(kāi)啟了流程實(shí)例");
? ? List<Task> list=taskService.createTaskQuery()
? ? ? ? ? ? .processDefinitionKey(key)//流程實(shí)例key
? ? ? ? ? ? .processInstanceId(processInstanceId)
? ? ? ? ? ? .list();
? ? for(Task task:list){
? ? ? ? System.out.println("任務(wù)id:"+list.get(0).getId());
? ? ? ? System.out.println("任務(wù)名稱(chēng):"+list.get(0).getName());
? ? ? ? taskService.setAssignee(list.get(0).getId(),userName);
? ? ? ? Map<String,Object> map=new HashMap<String,Object>();
? ? ? ? map.put("totalDay",totalDay);
? ? ? ? map.put("applyUserName",userName);
? ? ? ? taskService.complete(task.getId(),map);
? ? ? ? //這里完成任務(wù)后祷膳,監(jiān)聽(tīng)器馬上觸發(fā)陶衅,所以是監(jiān)聽(tīng)器代碼先運(yùn)行。
? ? ? ? System.out.println(userName+"-->完成任務(wù):"+task.getId()+"."+task.getName());
? ? }
? ? respon.setData(processInstanceId);
? ? respon.setCode(Constant.CODE_SUCCESS);
? ? respon.setMsg(Constant.CODE_SUCCESS_STRING);
? ? return respon;
}
/**
* Created by Administrator on 2019/11/22.
* 主管監(jiān)聽(tīng)器
*/
@Component
public class ZhuGuanListener implements TaskListener{
? ? @Override
? ? public void notify(DelegateTask delegateTask) {
? ? ? ? System.out.println("進(jìn)入主管監(jiān)聽(tīng)器");
? ? ? ? System.out.println("新產(chǎn)生任務(wù)id:"+delegateTask.getId());
? ? ? ? System.out.println("新產(chǎn)生任務(wù)名稱(chēng):"+delegateTask.getName());
? ? ? ? List<String> list=new ArrayList<>();
? ? ? ? list.add("主管-諸葛亮");
? ? ? ? list.add("副主管-劉伯溫");
? ? ? ? list.add("副主管-李靖");
? ? ? ? delegateTask.addCandidateUsers(list);
? ? }
}
所有主管都可以查詢(xún)到相關(guān)任務(wù)
//查詢(xún)可選任務(wù)
@RequestMapping(value= "listTask/{userName}")
@ResponseBody
public Respon listTask(@PathVariable(name="userName")String userName){
? ? Respon respon=new Respon();
? ? List<Task> list=taskService.createTaskQuery().taskCandidateUser(userName).list();
? ? if(list.size()>0){
? ? ? ? String taskId=list.get(0).getId();
? ? ? ? System.out.println("任務(wù)id:"+list.get(0).getId());
? ? ? ? System.out.println("任務(wù)名稱(chēng):"+list.get(0).getName());
? ? ? ? respon.setMsg(taskId);
? ? }else{
? ? ? ? respon.setMsg("沒(méi)有可選任務(wù)");
? ? ? ? return respon;
? ? }
? ? respon.setCode(Constant.CODE_SUCCESS);
? ? return respon;
}
主管領(lǐng)取并完成任務(wù)
//主管領(lǐng)取任務(wù)并審批
@RequestMapping(value= "claimTask/{userName}/{taskId}/{flag}/{totalDay}")
@ResponseBody
public Respon claimTask(@PathVariable(name="userName")String userName,@PathVariable(name="taskId")String taskId,@PathVariable(name="flag")String flag,@PathVariable(name="totalDay")Float totalDay){
? ? Respon respon=new Respon();
? ? //flag="_3"駁回钾唬;flag="1"通過(guò)
? ? Map<String,Object> map=new HashMap<>();
? ? map.put("zhuguanFlag",flag);
? ? map.put("totalDay",totalDay);
? ? taskService.claim(taskId,userName);
? ? taskService.complete(taskId,map);
? ? System.out.println(userName+":審批任務(wù)id:"+taskId);
? ? respon.setCode(Constant.CODE_SUCCESS);
? ? respon.setMsg(Constant.CODE_SUCCESS_STRING);
? ? return respon;
}
我這里主管審批通過(guò)了万哪,所以下一步就是總經(jīng)理可以查看到任務(wù)
總經(jīng)理審批任務(wù)不通過(guò)
//經(jīng)理領(lǐng)取任務(wù)并審批
@RequestMapping(value= "claimTask2/{userName}/{taskId}/{flag}")
@ResponseBody
public Respon claimTask2(@PathVariable(name="userName")String userName,@PathVariable(name="taskId")String taskId,@PathVariable(name="flag")String flag){
? ? Respon respon=new Respon();
? ? //flag="2"駁回;flag="1"通過(guò)
? ? Map<String,Object> map=new HashMap<>();
? ? map.put("jingliFlag",flag);
? ? taskService.claim(taskId,userName);
? ? taskService.complete(taskId,map);
? ? System.out.println(userName+":審批任務(wù)id:"+taskId);
? ? respon.setCode(Constant.CODE_SUCCESS);
? ? respon.setMsg(Constant.CODE_SUCCESS_STRING);
? ? return respon;
}
審批沒(méi)通過(guò)就返回到“填寫(xiě)請(qǐng)假信息”抡秆,我不知道是什么原因奕巍,這里駁回不用寫(xiě)其他代碼,在網(wǎng)上看過(guò)很多駁回的例子都是要寫(xiě)很多東西儒士,但那都是Activiti6及更低的版本的止,可能Activiti7就不需要。
那現(xiàn)在就查看是否進(jìn)行到“填寫(xiě)請(qǐng)假信息”這個(gè)任務(wù)
//查詢(xún)?cè)摿鞒虒?shí)例有什么任務(wù)
@RequestMapping(value= "processTask/{processInstanceId}")
@ResponseBody
public Respon processTask(@PathVariable(name="processInstanceId")String processInstanceId){
? ? Respon respon=new Respon();
? ? String key="qingjia_1";
? ? List<Task> list=taskService.createTaskQuery().processDefinitionKey(key)//流程實(shí)例key
? ? ? ? ? ? .processInstanceId(processInstanceId).list();
? ? if(list.size()>0){
? ? ? ? String taskId=list.get(0).getId();
? ? ? ? System.out.println("任務(wù)id:"+list.get(0).getId());
? ? ? ? System.out.println("任務(wù)名稱(chēng):"+list.get(0).getName());
? ? ? ? respon.setMsg(taskId);
? ? }else{
? ? ? ? respon.setMsg("沒(méi)有可選任務(wù)");
? ? ? ? return respon;
? ? }
? ? respon.setCode(Constant.CODE_SUCCESS);
? ? return respon;
}
到這里差不多了着撩,剩下的步驟和上面的都類(lèi)似诅福,所有我就不一一操作匾委,如各位有什么問(wèn)題和意見(jiàn)都可以提出來(lái)苦锨,大家一起研究箩帚。
最后希望這篇文章能幫到各位學(xué)習(xí)到更多,謝謝涕烧。