Activiti7的使用(七)

在之前的文章已經(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í)到更多,謝謝涕烧。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末咖气,一起剝皮案震驚了整個(gè)濱河市挨措,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌崩溪,老刑警劉巖浅役,帶你破解...
    沈念sama閱讀 217,185評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異伶唯,居然都是意外死亡觉既,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,652評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門(mén)乳幸,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)瞪讼,“玉大人,你說(shuō)我怎么就攤上這事反惕〕⑺遥” “怎么了演侯?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,524評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵姿染,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我秒际,道長(zhǎng)悬赏,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,339評(píng)論 1 293
  • 正文 為了忘掉前任娄徊,我火速辦了婚禮闽颇,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘寄锐。我一直安慰自己兵多,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,387評(píng)論 6 391
  • 文/花漫 我一把揭開(kāi)白布橄仆。 她就那樣靜靜地躺著剩膘,像睡著了一般。 火紅的嫁衣襯著肌膚如雪盆顾。 梳的紋絲不亂的頭發(fā)上怠褐,一...
    開(kāi)封第一講書(shū)人閱讀 51,287評(píng)論 1 301
  • 那天,我揣著相機(jī)與錄音您宪,去河邊找鬼奈懒。 笑死奠涌,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的磷杏。 我是一名探鬼主播溜畅,決...
    沈念sama閱讀 40,130評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼极祸!你這毒婦竟也來(lái)了达皿?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,985評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤贿肩,失蹤者是張志新(化名)和其女友劉穎峦椰,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體汰规,經(jīng)...
    沈念sama閱讀 45,420評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡汤功,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,617評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了溜哮。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片滔金。...
    茶點(diǎn)故事閱讀 39,779評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖茂嗓,靈堂內(nèi)的尸體忽然破棺而出餐茵,到底是詐尸還是另有隱情,我是刑警寧澤述吸,帶...
    沈念sama閱讀 35,477評(píng)論 5 345
  • 正文 年R本政府宣布忿族,位于F島的核電站,受9級(jí)特大地震影響蝌矛,放射性物質(zhì)發(fā)生泄漏道批。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,088評(píng)論 3 328
  • 文/蒙蒙 一入撒、第九天 我趴在偏房一處隱蔽的房頂上張望隆豹。 院中可真熱鬧,春花似錦茅逮、人聲如沸璃赡。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,716評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)碉考。三九已至,卻和暖如春惩琉,著一層夾襖步出監(jiān)牢的瞬間豆励,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,857評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留良蒸,地道東北人技扼。 一個(gè)月前我還...
    沈念sama閱讀 47,876評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像嫩痰,于是被迫代替她去往敵國(guó)和親剿吻。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,700評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容