最近公司有工作流審批相關(guān)業(yè)務(wù)最疆,于是學(xué)習(xí)起了Camunda澡刹。
首先是工具傳送門
IDEA安裝camunda-modeler工具
安裝了工具才能好好畫圖啊
合同審核簡易流程圖
常用操作
部署工作流
Deployment deployment=repositoryService.createDeployment()
.name(name)
.addClasspathResource("process/"+name)
.deploy();
##部署路徑根據(jù)項(xiàng)目實(shí)際路徑填寫
開啟流程實(shí)例
Map<String, Object> params=new HashMap<>();
params.put("key","contract_create");
params.put("manager","LI1,LI2");
params.put("leader","Z3");
Execution execution = runtimeService.startProcessInstanceByKey(params.get("key").toString(), params);
## 根據(jù)key啟動(dòng)流程實(shí)例 key是bpmn中定義的正蛙,Map<String, Object> params是傳入流程的參數(shù)
## demo中使用的是 camunda:candidateUsers="${manager}" 審核人通過params傳入,逗號(hào)分隔韵洋。一人審核流程即可通過
查詢我的待辦任務(wù)
List<Task> tasks = taskService.createTaskQuery()
.taskCandidateUser(assignee)
.orderByTaskCreateTime().asc()
.active().list();
查詢我的已辦任務(wù)
List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery()
.taskAssignee(assignee)
.orderByHistoricActivityInstanceStartTime().desc()
.finished().list();
審批通過
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (!ObjectUtils.isEmpty(task)) {
Map<String, Object> approveVariables = new HashMap<>(1);
approveVariables.put("passed", passed);
approveVariables.put("comment",comment);
this.taskService.claim(taskId, assignee);
taskService.createComment(taskId, task.getProcessInstanceId(), comment);
taskService.complete(taskId, approveVariables);
System.out.println("任務(wù)審核完成鸭津,審核"
+ (passed ? "通過" : "拒絕"));
return "任務(wù)審核完成眼耀,審核"
+ (passed ? "通過" : "拒絕");
}
## 審批時(shí)添加審核意見和審核結(jié)果
撤回流程
ActivityInstance activity = runtimeService.getActivityInstance(processInstanceId);
runtimeService.createProcessInstanceModification(processInstanceId)
//關(guān)閉相關(guān)任務(wù)
.cancelActivityInstance(activity.getId())
.setAnnotation("發(fā)起人撤回")
//啟動(dòng)目標(biāo)活動(dòng)節(jié)點(diǎn)
.startBeforeActivity("root")
.execute();
查詢 流程歷史
List<HistoricActivityInstance> activityInstanceList= historyService.createHistoricActivityInstanceQuery()
.processInstanceId(instanceId).orderByHistoricActivityInstanceStartTime().asc().list();
for (HistoricActivityInstance hi : activityInstanceList) {
HistoricActivityInstanceEntity entity=(HistoricActivityInstanceEntity) hi;
System.out.println("");
System.out.println("===================-===============");
System.out.println(hi.getStartTime());
System.out.println(hi.getAssignee());
System.out.println(hi.getActivityId());
System.out.println(hi.getActivityName());
System.out.println(entity.getActivityInstanceState());
List<Comment> taskComments = taskService.getTaskComments(hi.getTaskId());
taskComments.stream().forEach(e->{
System.out.println("comment:"+e.getFullMessage());
});
System.out.println(hi.getTaskId());
System.out.println(hi.getProcessDefinitionId());
System.out.println(hi.getProcessInstanceId());
System.out.println("===================-===============");
System.out.println("");
}
源碼傳送門