接上一篇:
第13篇: Flowable-BPMN操作流程之流程进展查看之流程图
https://blog.csdn.net/weixin_40816738/article/details/102902629
Flowable的TaskService提供了对任务的操作,其中完成任务complete函数提供了任务结束操作。
Flowable的任务完成实现如下:
void complete(String taskId)
Called when the task is successfully executed.
void complete(String taskId, Map variables)
Called when the task is successfully executed, and the required task parameters are given by the end-user.
/**
* 完成任务
*/
boolean completeTask(String taskId,Map paras);
/**
* 完成任务
*/
@Override
public boolean completeTask(String taskId,Map paras) {
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
if (task == null) {
return false;
}
if (null == paras){
taskService.complete(taskId);
}
else {
taskService.complete(taskId,paras);
}
return true;
}
@RequestMapping("/complete")
@ResponseBody
public Map completeTask(@RequestBody @RequestParam(required = false) Map paras){
Map res =new HashMap<>();
Map data = new HashMap<>();
if (MapUtils.isEmpty(paras)){
res.put("msg","请输入任务参数");
res.put("res","0");
res.put("data",data);
return res;
}
String taskId = paras.get("taskId");
if (StringUtils.isEmpty(taskId)){
res.put("msg","请输入任务ID");
res.put("res","0");
res.put("data",data);
return res;
}
Map flowParas=new HashMap<>();
flowParas.putAll(paras);
boolean bok = flowService.completeTask(taskId,flowParas);
if (bok){
data.put("taskId",taskId);
res.put("msg","启动流程成功");
res.put("res","1");
}
else {
data.put("taskId",taskId);
res.put("msg","启动流程失败");
res.put("res","0");
}
res.put("data",data);
return res;
}
http://localhost:8989/flow/create
http://localhost:8989/flow/start?processKey=test_bpmn
结果返回如下:
{"msg":"启动流程成功","res":"1","data":{"processId":"be53f529-0078-11ea-83cb-f8a2d6bfea5a"}}
后台打印如下: be5ccece-0078-11ea-83cb-f8a2d6bfea5a
注意:任务id就是taskid,不是processId
http://localhost:8989/flow/complete?taskId=be5ccece-0078-11ea-83cb-f8a2d6bfea5a
http://localhost:8989/flow/processDiagram?processId=be53f529-0078-11ea-83cb-f8a2d6bfea5a
从这里可以很容易的看到我们用户任务完成表示审核完成任务了,因为后面直接到结束了,所以看到红色圈已经到结束了。
gitlab链接:https://gitlab.com/gb-heima/flowablestudy/tree/master/flowablelech14
码云链接:https://gitee.com/gb_90/flowable-study/tree/master/flowablelech14
下一篇:
第15篇: Flowable-BPMN操作流程之排他网关
https://blog.csdn.net/weixin_40816738/article/details/102902674