做者:鄧家海html
都有一段沉默的時間,等待厚積薄發express
應用場景:mvc
當客戶有這麼一個需求:下一個任務我須要自動執行一些操做,而且這個節點不須要任何的人工干涉,也就是說這個節點是自動化的。那麼,這個當前面一個經辦人員把任務發送下去的時候,天然而然的下一個節點就會開始立刻執行。這個時候。咱們就須要使用Activiti工做流的ServiceTask任務。ide
ServiceTask任務的實現,其實不復雜。spa
實現步驟:設計
(1)設計流程xml
(2)編寫委託類htm
(3)把委託類設置到流程的監聽類上面blog
設計流程:get
編寫委託類:
1 package light.mvc.workflow.serviceTask; 2 3 4 5 import org.activiti.engine.delegate.DelegateExecution; 6 7 import org.activiti.engine.delegate.Expression; 8 9 import org.activiti.engine.delegate.JavaDelegate; 10 11 12 13 /** 14 15 * 16 17 * 項目名稱:lightmvc 18 19 * 類名稱:ServiceTask 20 21 * 類描述: 22 23 * 建立人:鄧家海 24 25 * 建立時間:2017年6月4日 下午6:18:11 26 27 * 修改人:deng 28 29 * 修改時間:2017年6月4日 下午6:18:11 30 31 * 修改備註: 32 33 * @version 34 35 * 36 37 */ 38 39 40 41 public class ServiceTask implements JavaDelegate{ 42 43 //流程變量 44 45 private Expression text1; 46 47 48 49 //重寫委託的提交方法 50 51 @Override 52 53 public void execute(DelegateExecution execution) throws Exception { 54 55 System.out.println("serviceTask已經執行已經執行!"); 56 57 String value1 = (String) text1.getValue(execution); 58 59 System.out.println(value1); 60 61 execution.setVariable("var1", new StringBuffer(value1).reverse().toString()); 62 63 } 64 65 66 67 }
把委託類設置到流程的監聽類上面:
流程代碼:
<?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="process" isExecutable="true"> <startEvent id="sid-F6C5FFC5-63CA-453D-8C11-2DA040793DE9"></startEvent> <serviceTask id="sid-77E58C69-38B7-4DE5-BD73-D0B6CEDD48D4" name="服務" activiti:class="light.mvc.workflow.serviceTask.ServiceTask"> <extensionElements> <activiti:field name="text1"> <activiti:string><![CDATA[test]]></activiti:string> </activiti:field> </extensionElements> </serviceTask> <endEvent id="sid-DB39A39C-1BCC-4F45-B909-9A4319632B42"></endEvent> <sequenceFlow id="sid-567FAFA0-954C-4BC1-AC05-4610A75001B2" sourceRef="sid-77E58C69-38B7-4DE5-BD73-D0B6CEDD48D4" targetRef="sid-DB39A39C-1BCC-4F45-B909-9A4319632B42"></sequenceFlow> <sequenceFlow id="sid-44C871F5-454A-4D4E-8E6F-C0FAA38C7E38" sourceRef="sid-F6C5FFC5-63CA-453D-8C11-2DA040793DE9" targetRef="sid-77E58C69-38B7-4DE5-BD73-D0B6CEDD48D4"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_process"> <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process"> <bpmndi:BPMNShape bpmnElement="sid-F6C5FFC5-63CA-453D-8C11-2DA040793DE9" id="BPMNShape_sid-F6C5FFC5-63CA-453D-8C11-2DA040793DE9"> <omgdc:Bounds height="30.0" width="30.0" x="172.75" y="99.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-77E58C69-38B7-4DE5-BD73-D0B6CEDD48D4" id="BPMNShape_sid-77E58C69-38B7-4DE5-BD73-D0B6CEDD48D4"> <omgdc:Bounds height="80.0" width="100.0" x="315.0" y="60.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-DB39A39C-1BCC-4F45-B909-9A4319632B42" id="BPMNShape_sid-DB39A39C-1BCC-4F45-B909-9A4319632B42"> <omgdc:Bounds height="28.0" width="28.0" x="480.0" y="100.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-567FAFA0-954C-4BC1-AC05-4610A75001B2" id="BPMNEdge_sid-567FAFA0-954C-4BC1-AC05-4610A75001B2"> <omgdi:waypoint x="415.0" y="100.0"></omgdi:waypoint> <omgdi:waypoint x="447.5" y="100.0"></omgdi:waypoint> <omgdi:waypoint x="447.5" y="114.0"></omgdi:waypoint> <omgdi:waypoint x="480.0" y="114.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-44C871F5-454A-4D4E-8E6F-C0FAA38C7E38" id="BPMNEdge_sid-44C871F5-454A-4D4E-8E6F-C0FAA38C7E38"> <omgdi:waypoint x="202.75" y="114.0"></omgdi:waypoint> <omgdi:waypoint x="258.875" y="114.0"></omgdi:waypoint> <omgdi:waypoint x="258.875" y="100.0"></omgdi:waypoint> <omgdi:waypoint x="315.0" y="100.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
而後執行流程(個人控制檯亂碼,沒時間處理,不影響):
升級:
假如客戶說,我並不想立刻去執行這個任務,我只是想在某一個時間以後纔去執行這個任務。那麼上面的要求顯然又不能知足需求了。咱們又要怎麼去升級改進呢?其實也很簡單。咱們前面已經實現了定時邊界任務。咱們只須要增長一個定時邊界來處理就能夠了。