项目地址:https://gitee.com/lwj/flowable.git 分支flowable-base
视频讲解地址
https://www.bilibili.com/video/av78128720/
1. 演示
2、代码
public ReturnVo<String> complete(CompleteTaskVo params) {
ReturnVo<String> returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "审批成功");
if (StringUtils.isNotBlank(params.getProcessInstanceId())
&& StringUtils.isNotBlank(params.getTaskId())) {
String type = params.getType() == null ? CommentTypeEnum.SP.toString() : params.getType();
TaskEntity taskEntity = (TaskEntity) taskService.createTaskQuery().taskId(params.getTaskId()).singleResult();
if (taskEntity != null) {
//2.委派处理
if (DelegationState.PENDING.equals(taskEntity.getDelegationState())) {
//2.1生成历史记录
TaskEntity task = this.createSubTask(taskEntity, params.getUserCode());
taskService.saveTask(task);
taskService.complete(task.getId());
//2.2生成审批意见
this.addComment(task.getId(), params.getUserCode(), params.getProcessInstanceId(),
CommentTypeEnum.SP.toString(), params.getMessage());
//2.3执行委派
taskService.resolveTask(params.getTaskId(), params.getVariables());
} else {
//3.1修改执行人 其实我这里就相当于签收了
taskService.setAssignee(params.getTaskId(), params.getUserCode());
//3.2执行任务
taskService.complete(params.getTaskId(), params.getVariables());
//3.3生成审批记录
this.addComment(params.getTaskId(), params.getUserCode(), params.getProcessInstanceId(),
CommentTypeEnum.SP.toString(), params.getMessage());
//4.处理加签父任务
String parentTaskId = taskEntity.getParentTaskId();
if (StringUtils.isNotBlank(parentTaskId)) {
String tableName = managementService.getTableName(TaskEntity.class);
String sql = "select count(1) from " + tableName + " where PARENT_TASK_ID_=#{parentTaskId}";
long subTaskCount = taskService.createNativeTaskQuery().sql(sql).parameter("parentTaskId", parentTaskId).count();
if (subTaskCount == 0) {
Task task = taskService.createTaskQuery().taskId(parentTaskId).singleResult();
//处理前后加签的任务
taskService.resolveTask(parentTaskId);
if (FlowConstant.AFTER_ADDSIGN.equals(task.getScopeType())) {
taskService.complete(parentTaskId);
}
}
}
}
} else {
returnVo = new ReturnVo<>(ReturnCode.FAIL, "没有此任务,请确认!");
}
} else {
returnVo = new ReturnVo<>(ReturnCode.FAIL, "请输入正确的参数!");
}
return returnVo;
}