版權聲明:轉載注明出處就OK的說,有些東西會轉載,都會注明的說= =如果有冒犯麻煩見諒 https://blog.csdn.net/Pan1458689676/article/details/82662203
StartEvent元件
StartEvent分為五種,第一種為普通StartEvent,第二種為帶定時器的SatrtEvent,第三種為接收消息的StartEvent,第四種為帶錯誤資訊的StartEvent這種最為特殊,下文會詳細來說。第五種為帶信号的StartEvent從這篇文章主要講工作流的StartEvent。下面開始逐一講解。
StartEvent為一個流程的起始點,我們來看看官網是如何描述的:
StartEvent(普通)對應的XML内代碼如下
<startEvent id="startevent1" name="Start"></startEvent>
activiti:initiator="initiator"
這個部分,activiti:initiator:在程序啟動時将存儲使用者辨別的變量名稱。以initiator為UserId。一般設定這個是和form聯用的【emmm我是不會去用的】。這裡就是告訴大家可以用xml打開bpmn的代碼有這個屬性設定。通過eclipse插件可以直接如下圖這樣設定。
老規矩跑起來試試
可以看到已經進了曆史資料表了【因為已經啟動了start這個執行個體被執行了就進入了曆史表】
starter:以這種方式設定就會是starter
participant:任務辦理人,建議以流程變量的方式指定
candidate:候選人,組任務那塊可以指定
打開允許異步操作
TimerStartEvent對應的XML内代碼如下【未做任何設定的TimerStartEvent】
<startEvent id="timerstartevent1" name="Timer start">
<timerEventDefinition></timerEventDefinition>
</startEvent>
計時器啟動事件用于在給定時間建立流程執行個體。它既可以用于應該隻啟動一次的程序,也可以用于應該以特定時間間隔啟動的程序。
- 子流程不能有TimerStartEvent。
- 一旦部署了程序,就會安排TimerStartEvent。不需要調用startProcessInstanceByXXX方法,雖然調用start process方法不受限制,并且會在startProcessInstanceByXXX Invocation時再啟動一個程序。
- 當部署具有TimerStartEvent的新版本的程序時,将删除與先前計時器對應的作業。原因是通常不希望自動啟動此舊版本流程的新流程執行個體。
使用的方式呢就是使用如下三個标簽控制定時器開始事件。接下來是demo了。
流程圖總覽【UserTask以及後面的完全沒有設定,for流程完整性和友善檢視運作效果】
流程圖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="TiemCycle">
<process id="TiemCycle" name="TiemCycle" isExecutable="true">
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<startEvent id="timerstartevent1" name="Timer start">
<timerEventDefinition>
<timeCycle>0/5 * * * * ?</timeCycle>
</timerEventDefinition>
</startEvent>
<sequenceFlow id="flow3" sourceRef="timerstartevent1" targetRef="usertask1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_TiemCycle">
<bpmndi:BPMNPlane bpmnElement="TiemCycle" id="BPMNPlane_TiemCycle">
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="490.0" y="170.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="290.0" y="160.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="timerstartevent1" id="BPMNShape_timerstartevent1">
<omgdc:Bounds height="35.0" width="35.0" x="160.0" y="170.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="395.0" y="187.0"></omgdi:waypoint>
<omgdi:waypoint x="490.0" y="187.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="195.0" y="187.0"></omgdi:waypoint>
<omgdi:waypoint x="290.0" y="187.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
corn 表達式
這個代表每分鐘的第0秒開始每五秒鐘調用一次。【生成Corn表達式的網站,不必刻意去記憶
http://cron.qqe2.com/】
【ISO 8601方式】重複5次,每次間隔10小時
<timeCycle activiti:endDate="2019-09-12T21:42:00+00:00">R5/PT10H</timeCycle>
<timeCycle>R5/2019-10-07T12:00/PT10H</timeCycle>//這個是開始時間
測試代碼
@Test
public void TiemCycleTest() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()/
.name("StartEventNormal")
.addClasspathResource("bpmn/TiemCycle.bpmn")
.addClasspathResource("bpmn/TiemCycle.png")
.deploy();
long dataCount = runtimeService.createProcessInstanceQuery().count();
System.out.println("sleep前流程執行個體數量:" + dataCount);
Thread.sleep(60000L);
dataCount = runtimeService.createProcessInstanceQuery().count();
System.out.println("sleep後流程執行個體數量:" + dataCount);
}
【上圖Name見諒一下不想再去截圖了。複制代碼快了】
流程圖總覽
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/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="timerstartevent1" name="Timer start">
<timerEventDefinition>
<timeDate>2018-09-12T17:20:00</timeDate>
</timerEventDefinition>
</startEvent>
<userTask id="usertask1" name="User Task"></userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="timerstartevent1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
<bpmndi:BPMNShape bpmnElement="timerstartevent1" id="BPMNShape_timerstartevent1">
<omgdc:Bounds height="35.0" width="35.0" x="210.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="360.0" y="230.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="590.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="245.0" y="257.0"></omgdi:waypoint>
<omgdi:waypoint x="360.0" y="257.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="465.0" y="257.0"></omgdi:waypoint>
<omgdi:waypoint x="590.0" y="257.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
時間的格式是有要求的
直接部署流程五點20時檢視是否已經自動生成流程執行個體
@Test
public void TimeDate() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()
.name("TimeDate")
.addClasspathResource("bpmn/TimeDate.bpmn")
.addClasspathResource("bpmn/TimeDate.png")
.deploy();
long dataCount = runtimeService.createProcessInstanceQuery().count();
System.out.println("sleep前流程執行個體數量:" + dataCount);
Thread.sleep(60000L);//
dataCount = runtimeService.createProcessInstanceQuery().count();
System.out.println("sleep後流程執行個體數量:" + dataCount);
}
【單元測試線程代碼運作完則退出,不會像主線程一樣等待子線程退出而退出, 會直接退出。Junit單元測試不支援多線程。主線程退出,子線程也會退出。】
微改一下,這裡稍微偷懶一下啦。
@Test
public void TimeDate() throws InterruptedException{
Deployment deployment = repositoryService.createDeployment()
.name("TimeDate")
.addClasspathResource("bpmn/TimeDate.bpmn")
.addClasspathResource("bpmn/TimeDate.png")
.deploy();
long dataCount = runtimeService.createProcessInstanceQuery().count();
System.out.println("sleep前流程執行個體數量:" + dataCount);
Thread.sleep(5000L);
dataCount = runtimeService.createProcessInstanceQuery().count();
System.out.println("sleep後流程執行個體數量:" + dataCount);
}