/**
* 撤销
*/
@Override
public void revoke(String processInstanceId, String businessId) {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if (processInstanceIsFinished(instance.getId())) {
throw new JeecgBootException("流程已经结束,不允许撤销");
}
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
if (!user.getUsername().equals(instance.getStartUserId())) {
throw new JeecgBootException("您不是流程的发起人,不允许撤销");
} else {
//如果系统登录人是流程的发起人,并且当前任务办理人是流程的发起人,则允许撤回
if (instance.getStartUserId().equals(task.getAssignee())) {
revokeAndUpdateForm(instance, businessId);
} else {
List<HistoricTaskInstance> historicTaskInstanceList = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId).finished().list();
if (CollectionUtils.isEmpty(historicTaskInstanceList)) {//如果任务还没有被办理过,则允许撤回
revokeAndUpdateForm(instance, businessId);
} else {
//获取办理人
List<String> assigneeList = historicTaskInstanceList.stream().map(HistoricTaskInstance::getAssignee).collect(Collectors.toList());
long count = assigneeList.stream().filter(a -> !a.equals(instance.getStartUserId())).count();
if (count == 0) {//已办的任务全部都是发起人自己办理的,则允许撤回
revokeAndUpdateForm(instance, businessId);
} else {
throw new JeecgBootException("流程已被其他人办理过,不允许撤销");
}
}
}
}
}
/**
* 撤销流程并更新表单
*
* @param instance
* @param businessId
*/
public void revokeAndUpdateForm(HistoricProcessInstance instance, String businessId) {
runtimeService.deleteProcessInstance(instance.getId(), "撤销");
//更新表单状态
formDesignService.updateFormStatus(processDefinitionService.getStartFormKey(instance.getProcessDefinitionId()),
businessId, FormStatusType.YCX.getCode());
}
文章来源地址https://www.toymoban.com/news/detail-484418.html
文章来源:https://www.toymoban.com/news/detail-484418.html
到了这里,关于camunda撤销流程的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!