camunda撤销流程

 /**
     * 撤销
     */
    @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());
    }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值