版權聲明:轉載注明出處就OK的說,有些東西會轉載,都會注明的說= =如果有冒犯麻煩見諒 https://blog.csdn.net/Pan1458689676/article/details/82625002
剩下的核心API
流程定義與流程執行個體
/**HistoryProcessInstance*/
@Test
public void HistoryProcessInstance() {
List<HistoricProcessInstance> datas = historyService.createHistoricProcessInstanceQuery()
.finished().list();
for (HistoricProcessInstance historicProcessInstance : datas) {
System.out.println("流程執行個體id: "+historicProcessInstance.getId());
System.out.println("部署id: "+historicProcessInstance.getDeploymentId());
System.out.println("結束event: "+historicProcessInstance.getEndActivityId());
System.out.println("流程名稱: "+historicProcessInstance.getName());
System.out.println("PROC_DEF_ID: "+historicProcessInstance.getProcessDefinitionId());
System.out.println("流程定義Key: "+historicProcessInstance.getProcessDefinitionKey());
System.out.println("流程定義名稱: "+historicProcessInstance.getProcessDefinitionName());
System.out.println("開始event: "+historicProcessInstance.getStartActivityId());
}
}
【其他HistoryService查詢類似】
【個人感覺在前端架構比較完善的今天幾乎不會去用這個,但是還是做一些小demo】
【流程圖】
<?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="whatFk" name="whatFk" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="User Task">
<extensionElements>
<activiti:formProperty id="userName" name="userName" type="string" variable="userName"></activiti:formProperty>
<activiti:formProperty id="age" name="age" type="string" variable="age"></activiti:formProperty>
</extensionElements>
</userTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="User Task"></userTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_whatFk">
<bpmndi:BPMNPlane bpmnElement="whatFk" id="BPMNPlane_whatFk">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="210.0" y="130.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="310.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="840.0" y="130.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="560.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="245.0" y="147.0"></omgdi:waypoint>
<omgdi:waypoint x="310.0" y="147.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="415.0" y="147.0"></omgdi:waypoint>
<omgdi:waypoint x="560.0" y="147.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="665.0" y="147.0"></omgdi:waypoint>
<omgdi:waypoint x="840.0" y="147.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
@Test
public void FormType(){
Deployment dep = repositoryService.createDeployment().addClasspathResource("bpmn/form.bpmn").deploy();
ProcessInstance pi = runtimeService.startProcessInstanceByKey("whatFk");
System.out.println(pi);
HashMap<String, String> variables = new HashMap<>();
variables.put("userName", "潘天淼");
variables.put("age", "18");
Task task = taskService.createTaskQuery().deploymentId(dep.getId()).singleResult();
formService.submitTaskFormData(task.getId(), variables);
}
資料庫内以流程變量的形式存儲了内容【注意:此方式設定的流程變量均為taskID】
@Test
public void FormTypeRead(){
//75005為偷懶直接從資料庫内複制的流程
Task task = taskService.createTaskQuery().processInstanceId("75005").singleResult();
TaskFormData taskFormData = formService.getTaskFormData(task.getId());
List<FormProperty> formProperties = taskFormData.getFormProperties();
for (FormProperty formProperty : formProperties) {
System.out.println(formProperty.getId() + ",value=" + formProperty.getValue());
}
}
上方代碼在該task未執行時能夠擷取表單所有元素
【修改代碼流程檔案與form要一同部署】
@Test
public void FormType(){
Deployment dep = repositoryService.createDeployment()
.addClasspathResource("bpmn/form.bpmn")
.addClasspathResource("bpmn/completeForm.form")
.deploy();
ProcessInstance pi = runtimeService.startProcessInstanceByKey("whatFk");
HashMap<String, String> variables = new HashMap<>();
variables.put("userName", "潘天淼");
variables.put("age", "18");
Task task = taskService.createTaskQuery().deploymentId(dep.getId()).singleResult();
formService.submitTaskFormData(task.getId(), variables);
}
【測試結果】
@Test
public void OutFormTypeRead(){
System.out.println(formService.getRenderedTaskForm("105016")==null);
HashMap<String, String> variables = new HashMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar ca = Calendar.getInstance();
String startDate = sdf.format(ca.getTime());
ca.add(Calendar.DAY_OF_MONTH, 2); // 目前日期加2天
String endDate = sdf.format(ca.getTime());
variables.put("startDate", startDate);
variables.put("endDate", endDate);
variables.put("reason", "公休");
formService.submitTaskFormData("105016", variables);
}
正常情況下呢這裡是可以擷取表單的。對于外置表單,隻是把表單内容都儲存在單獨的form檔案中,是以隻能通過讀取所有的請求參數作為流程啟動參數。
圖示部分為整塊HTML的内容【想些啥都OK我是複制了一段HTML帶表單的說】。
activiti 基礎部分到此就結束了。關于managementService據說是不怎麼用的到的,呐網上資源也比較少,就不去細說了。接下來的話。本周内會把BPMN2.0涉及到的元件全部過一遍【不常用的Task元件我就不講了。中間元件和補償邊界會全部涉及】。