当前位置:   article > 正文

SpringBoot整合Activiti7——实战之出差流程(分支)

SpringBoot整合Activiti7——实战之出差流程(分支)


出差流程:开始 - 填写出差表单 - 判断(出差天数大于等于5)- 副经理审批 - 否则总经理审批 - 完成

代码实现

在这里插入图片描述

部署流程

	@Test
    public void testDeployProcess() throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("/processes/businessTrip.bpmn20.xml");

        // 部署流程 act_re_procdef
        Deployment deploy = repositoryService.createDeployment()
                .addInputStream(classPathResource.getPath(), classPathResource.getInputStream())
                .deploy();
        System.out.println("deploy = " + deploy);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

启动流程

	@Test
    public void testStartProcess() {
        //启动流程时传递的参数列表 这里根据实际情况 也可以选择不传
        Map<String, Object> variables = new HashMap<>();
        variables.put("userId", "654321");

        // 获取流程定义的Key
        String processDefinitionKey = "businessTrip";
        // 定义businessKey
        String businessKey = processDefinitionKey + ":" + "10001"; // 假设模拟出差业务id为1001

        // 设置启动流程的人
        Authentication.setAuthenticatedUserId("admin");

        // 启动流程 act_hi_procinst act_ru_variable act_ru_task
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);
        System.out.println("processInstance = " + processInstance);
        System.out.println("流程实例ID:" + processInstance.getId());
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

查询任务

将启动流程后的流程实例ID更换到下面

	@Test
    public void queryTaskList() {
        // 查询任务 act_ru_task
        TaskQuery taskQuery = taskService.createTaskQuery()
                .processInstanceId("eb12004e-35cc-11ee-86ca-18c04dcd4aee") // 流程实例ID
                .orderByTaskCreateTime().asc();

        List<Task> taskList = taskQuery.list();
        System.out.println("taskList = " + taskList);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

填写出差审批单

将任务ID更换到下面,businessTripDay天数决定是副经理还是总经理审批,这里演示副经理审批

	@Test
    public void completeBusinessTripFormTask() {
        // 根据id查询任务 act_ru_task
        Task task = taskService.createTaskQuery().taskId("eb1534a5-35cc-11ee-86ca-18c04dcd4aee").singleResult();

        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("userId", "654321");
        hashMap.put("businessTripDay", 6);
        hashMap.put("businessTripReason", "工作要求");
        hashMap.put("businessTripTime", new Date());

        // 完成任务,填写任务则更新为审核任务,任务ID改变
        taskService.complete(task.getId(), hashMap);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

经理审批

将启动流程后的流程实例ID更换到下面

	@Test
    public void managerAudit() {
        Task task = taskService.createTaskQuery().processInstanceId("eb12004e-35cc-11ee-86ca-18c04dcd4aee").singleResult();

        // 添加备注
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("remark", "好的好的");

        // 部门审批完成任务,任务列表为空
        taskService.complete(task.getId(), hashMap);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

xml文件

<?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/processdef">
  <process id="businessTrip" name="出差审批流程" isExecutable="true">
    <documentation>模拟出差审批流程</documentation>
    <startEvent id="sid-40bbaa52-1762-4d02-bc33-de0711df52b1"/>
    <userTask id="sid-705c697a-da0a-4f03-be4e-bb5e004d8e84" name="填写出差申请表" activiti:assignee="${userId}"/>
    <sequenceFlow id="sid-d2004ccc-e090-4a88-810b-ae9c242f86c1" sourceRef="sid-40bbaa52-1762-4d02-bc33-de0711df52b1" targetRef="sid-705c697a-da0a-4f03-be4e-bb5e004d8e84"/>
    <userTask id="sid-1b84b348-d685-4f5b-956b-7f9b141a033b" name="副经理审批" activiti:assignee="assistantManager"/>
    <userTask id="sid-081f1339-30af-4a73-a635-cef4c7df443f" name="总经理审批" activiti:assignee="generalManager"/>
    <sequenceFlow id="sid-bcb30913-26c8-425b-9e12-a5eb837135ea" sourceRef="sid-963c7b54-0d9e-4ad7-8196-b042da146972" targetRef="sid-081f1339-30af-4a73-a635-cef4c7df443f" name="出差天数大于5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${businessTripDay>5}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-fd792f97-88a7-4ec9-a6f9-d59dbaff36e5" sourceRef="sid-963c7b54-0d9e-4ad7-8196-b042da146972" targetRef="sid-1b84b348-d685-4f5b-956b-7f9b141a033b" name="出差天数小于等于5">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${businessTripDay<=5}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="sid-963c7b54-0d9e-4ad7-8196-b042da146972"/>
    <sequenceFlow id="sid-15d3c29e-8a8e-4e16-8f0b-c412a744a55d" sourceRef="sid-705c697a-da0a-4f03-be4e-bb5e004d8e84" targetRef="sid-963c7b54-0d9e-4ad7-8196-b042da146972"/>
    <endEvent id="sid-1edf278b-8514-4508-b021-febf84e20aa6"/>
    <sequenceFlow id="sid-eba388e8-e36e-4287-afbd-4d1cefa9b7e2" sourceRef="sid-1b84b348-d685-4f5b-956b-7f9b141a033b" targetRef="sid-1edf278b-8514-4508-b021-febf84e20aa6"/>
    <sequenceFlow id="sid-58e34e3b-9930-41e1-88fa-ff9ac2d6ae43" sourceRef="sid-081f1339-30af-4a73-a635-cef4c7df443f" targetRef="sid-1edf278b-8514-4508-b021-febf84e20aa6"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_businessTrip">
    <bpmndi:BPMNPlane bpmnElement="businessTrip" id="BPMNPlane_businessTrip">
      <bpmndi:BPMNShape id="shape-6889163e-5924-4958-9630-5aef6a1407d2" bpmnElement="sid-40bbaa52-1762-4d02-bc33-de0711df52b1">
        <omgdc:Bounds x="-359.90002" y="14.450001" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-120fece5-c27c-41dc-839d-3515b392d9c5" bpmnElement="sid-705c697a-da0a-4f03-be4e-bb5e004d8e84">
        <omgdc:Bounds x="-282.8" y="-10.550003" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-00ed7b82-f499-41ea-95b4-a6d114b81e8b" bpmnElement="sid-d2004ccc-e090-4a88-810b-ae9c242f86c1">
        <omgdi:waypoint x="-329.90002" y="29.45"/>
        <omgdi:waypoint x="-282.8" y="29.449997"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-a89b21c1-09a8-4380-b241-1552764b67f3" bpmnElement="sid-1b84b348-d685-4f5b-956b-7f9b141a033b">
        <omgdc:Bounds x="-46.51999" y="-84.67001" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-6fce5208-d3c8-4ba6-8f5b-1a9cb4531677" bpmnElement="sid-081f1339-30af-4a73-a635-cef4c7df443f">
        <omgdc:Bounds x="-46.51999" y="59.827385" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-3cd10768-0633-41fe-ae15-5ffe61dbb41e" bpmnElement="sid-bcb30913-26c8-425b-9e12-a5eb837135ea">
        <omgdi:waypoint x="-120.71713" y="49.45"/>
        <omgdi:waypoint x="-46.51999" y="79.827385"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-d2964b44-96a8-4450-82fe-b30e3b6468a9" bpmnElement="sid-fd792f97-88a7-4ec9-a6f9-d59dbaff36e5">
        <omgdi:waypoint x="-120.71713" y="9.449995"/>
        <omgdi:waypoint x="-46.51999" y="-24.670013"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-8a0a6467-da96-406e-8b05-3f5594d16616" bpmnElement="sid-963c7b54-0d9e-4ad7-8196-b042da146972">
        <omgdc:Bounds x="-140.71713" y="9.449995" width="40.0" height="40.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-c7511b2f-cfc6-4d42-95d4-fe10114b5585" bpmnElement="sid-15d3c29e-8a8e-4e16-8f0b-c412a744a55d">
        <omgdi:waypoint x="-182.79999" y="29.449997"/>
        <omgdi:waypoint x="-140.71713" y="29.449995"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-86d2ca12-5f5b-4924-ac7e-19b22661721e" bpmnElement="sid-1edf278b-8514-4508-b021-febf84e20aa6">
        <omgdc:Bounds x="132.9632" y="14.449997" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-f3516bc6-ee13-40f3-9901-5a25b58c933f" bpmnElement="sid-eba388e8-e36e-4287-afbd-4d1cefa9b7e2">
        <omgdi:waypoint x="53.48001" y="-24.670013"/>
        <omgdi:waypoint x="132.9632" y="21.949997"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-98f0c74a-cbe7-4eda-b223-d82ee7c34b89" bpmnElement="sid-58e34e3b-9930-41e1-88fa-ff9ac2d6ae43">
        <omgdi:waypoint x="53.48001" y="99.827385"/>
        <omgdi:waypoint x="132.9632" y="29.449997"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/303849
推荐阅读
相关标签
  

闽ICP备14008679号