工作流Activiti的學習總結(八)Activiti自動執行的應用
阿新 • • 發佈:2019-02-18
工作流activiti自動執行任務的開發應用
工作流模擬某公司請假流程情景如下:
1.開發人員請假流程,如果開發人員請假,如果請假天數小於3天,組長批准,人事批准即可請假。
2.如果請假大約三天,需要專案經理或者產品經理批准,並且專案總監批准
模擬自動審批:
只需要啟動一個流程例項,它會自動執行到結束。這種情況下,你不需要關注流
程的執行進度,而只需要把精力集中在每個結點的處理邏輯(通常是簡單或者複雜的商業邏輯)上。
流程設計圖如下:
流程配置檔案AutoExecuteTask.bpmn20.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: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"
- <process id="AutoExecuteTask" name="AutoExecuteTask">
-
<startEvent id="startevent1" name="Start">
- <parallelGateway id="parallelgateway1" name="多種請假方式"></parallelGateway>
- <serviceTask id="servicetask1" name="專案經理同意" activiti:class="com.easyway.workflow.activiti.gateway.DeveloperManagerServiceTask"></serviceTask>
- <serviceTask id="servicetask2" name="產品經理同意" activiti:class="com.easyway.workflow.activiti.gateway.ProductManagerServiceTask"></serviceTask>
- <serviceTask id="servicetask3" name="專案組長同意" activiti:class="com.easyway.workflow.activiti.gateway.TeamLeaderServiceTask"></serviceTask>
- <parallelGateway id="parallelgateway2" name="First Join"></parallelGateway>
- <serviceTask id="servicetask4" name="專案總監同意" activiti:class="com.easyway.workflow.activiti.gateway.ProductBossServiceTask"></serviceTask>
- <parallelGateway id="parallelgateway3" name="人事判斷"></parallelGateway>
- <serviceTask id="servicetask5" name="人事部門同意" activiti:class="com.easyway.workflow.activiti.gateway.HumanResouceServiceTask"></serviceTask>
- <endEvent id="endevent1" name="End"></endEvent>
- <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow>
- <sequenceFlow id="flow2" name="" sourceRef="parallelgateway1" targetRef="servicetask1"></sequenceFlow>
- <sequenceFlow id="flow3" name="" sourceRef="parallelgateway1" targetRef="servicetask2"></sequenceFlow>
- <sequenceFlow id="flow4" name="" sourceRef="parallelgateway1" targetRef="servicetask3"></sequenceFlow>
- <sequenceFlow id="flow5" name="" sourceRef="servicetask1" targetRef="parallelgateway2"></sequenceFlow>
- <sequenceFlow id="flow6" name="" sourceRef="servicetask2" targetRef="parallelgateway2"></sequenceFlow>
- <sequenceFlow id="flow7" name="" sourceRef="servicetask3" targetRef="parallelgateway3"></sequenceFlow>
- <sequenceFlow id="flow8" name="" sourceRef="parallelgateway2" targetRef="servicetask4"></sequenceFlow>
- <sequenceFlow id="flow9" name="" sourceRef="servicetask4" targetRef="parallelgateway3"></sequenceFlow>
- <sequenceFlow id="flow10" name="" sourceRef="parallelgateway3" targetRef="servicetask5"></sequenceFlow>
- <sequenceFlow id="flow11" name="" sourceRef="servicetask5" targetRef="endevent1"></sequenceFlow>
- </process>
- </definitions>
- package com.easyway.workflow.activiti.gateway;
- import java.util.logging.Logger;
- /**
- * execute方法的引數DelegateExecution execution可以在流程中各個結點之間傳遞流程變數。
- *通過基於Activiti 5.6的<parallelGateway>、<serviceTask>、<receiveTask>、<userTask>元素。
- *
- *自動執行
- <serviceTask>元素,可以實現自動活動,語法如下所示:
- <serviceTask id="serviceTaskId" name="serviceTaskName"
- activiti:class="org.shirdrn.workflow.activiti.gateway.ServiceTaskClass"/>
- 其中,activiti:class屬性為該結點對應的處理類,該類要求實現org.activiti.engine.delegate.JavaDelegate介面
- *
- * <serviceTask id="servicetask1" name="專案經理同意" activiti:class="com.easyway.workflow.activiti.gateway.DeveloperManagerServiceTask"></serviceTask>
- * 專案經理審批過程
- * @author longgangbai
- *
- *
- * 2011-12-17 下午07:45:47
- */
- public class DeveloperManagerServiceTask implements JavaDelegate {
- private final Logger log = Logger.getLogger(DeveloperManagerServiceTask.class.getName());
- @Override
- public void execute(DelegateExecution execution) throws Exception {
- Thread.sleep(10000);
- log.info("variavles=" + execution.getVariables());
- execution.setVariable("專案經理", "請假天數大約3天,同意請假。");
- log.info("專案經理,請假天數大約3天,同意請假。.");
- }
- }
- package com.easyway.workflow.activiti.gateway;
- import java.util.logging.Logger;
- /**
- * execute方法的引數DelegateExecution execution可以在流程中各個結點之間傳遞流程變數。
- *
- *
- * <serviceTask id="servicetask2" name="產品經理同意" activiti:class="com.easyway.workflow.activiti.gateway.ProductManagerServiceTask"></serviceTask>
- * 產品經理審批過程
- * @author longgangbai
- *
- * 2011-12-17 下午07:45:47
- */
- public class ProductManagerServiceTask implements JavaDelegate {
- private final Logger log = Logger.getLogger(ProductManagerServiceTask.class.getName());
- @Override
- public void execute(DelegateExecution execution) throws Exception {
- Thread.sleep(10000);
- log.info("variavles=" + execution.getVariables());
- execution.setVariable("產品經理", "請假天數大約3天,同意請假。");
- log.info("產品經理,請假天數大約3天,同意請假。");
- }
- }
- package com.easyway.workflow.activiti.gateway;
- import java.util.logging.Logger;
- /**
- * 專案組長批准請假
- * 模擬當開發人員請假小於3天,組長比準
- *
- *
- * <serviceTask id="servicetask3" name="專案組長同意" activiti:class="com.easyway.workflow.activiti.gateway.TeamLeaderServiceTask"></serviceTask>
- * @author longgangbai
- *
- * 2011-12-17 上午09:07:37
- */
- public class TeamLeaderServiceTask implements JavaDelegate {
- private final Logger log = Logger.getLogger(TeamLeaderServiceTask.class.getName());
- @Override
- public void execute(DelegateExecution execution) throws Exception {
- Thread.sleep(10000);
- log.info("variavles=" + execution.getVariables());
- execution.setVariable("專案組長", "請假天數小於3天,同意請假。");
- log.info("專案組長,請假天數小於3天,同意請假。");
- }
- }
- package