美文网首页工作流
Flowable 实现节点驳回

Flowable 实现节点驳回

作者: 爱_别离 | 来源:发表于2019-05-17 01:54 被阅读0次

    在Flowable开发中可能遇到某个节点审批出问题需要驳回该节点任务 遇到此问题可以参考以下代码需要自己判断只能驳回当前节点之前的节点逻辑 直接上代码!

    /**
         * 节点驳回
         * @author: Lu Yang
         * @date: 2019-05-05 10:30
         * @param taskId 任务ID
         * @param targetNodeId 目标节点ID
         * @return: com.tlsq.framework.core.protocol.Result<java.lang.Void>
         */
        public Result<Void> flowBackBeforeNode(String taskId, String targetNodeId) {
            
            if(StringUtil.isEmpty(taskId)) {
                return Result.failure(
                        FlowResultCode.FLOW_TASK_ID_EMPTY.getErrCode(),
                        FlowResultCode.FLOW_TASK_ID_EMPTY.getErrMsg());
            }
    
            try {
                //获取流程实例
                Result<TaskEntity> taskEntityWrapper = getTaskEntity(taskId);
                if(!taskEntityWrapper.isSuccess()) {
                    return Result.failure(
                            FlowResultCode.FLOW_CALL_GET_TASK_ENTITY_METHOD_ERROR.getErrCode(),
                            FlowResultCode.FLOW_CALL_GET_TASK_ENTITY_METHOD_ERROR.getErrMsg());
                }
                TaskEntity taskEntity = taskEntityWrapper.getResult();
                @SuppressWarnings({ "static-access", "rawtypes" })
                Collection flowElements = operationHelper.getFlowElements(taskEntity);
                List<String> nodeIds = new ArrayList<>();
                String nodeId = null;
                for (Object flowElement : flowElements) {
                    if (flowElement instanceof UserTask) {
                        nodeId = ((UserTask) flowElement).getId();
                        if (nodeId.equals(taskEntity.getTaskDefinitionKey())) {
                            // 如果为空就默认回退到上一节点
                            if (StringUtil.isEmpty(targetNodeId)) {
                                targetNodeId = ((UserTask) flowElement).getIncomingFlows().get(0).getSourceRef();
                            }
                            break;
                        }
                        nodeIds.add(nodeId);
                    }
                }
    
                if (!nodeIds.contains(targetNodeId)) {
                    return Result.failure(
                            FlowResultCode.FLOW_OTHER_TARGET_NODE_ID_INEXISTENCE.getErrCode(),
                            FlowResultCode.FLOW_OTHER_TARGET_NODE_ID_INEXISTENCE.getErrMsg());
                }
    
                runtimeService.createChangeActivityStateBuilder()
                              .processInstanceId(taskEntity.getProcessInstanceId())
                              .moveActivityIdTo(taskEntity.getTaskDefinitionKey(),targetNodeId)
                              .changeState();
                
            } catch (Exception e) {
                e.printStackTrace();
                return Result.failure(
                        FlowResultCode.FLOW_CALL_FLOW_BACK_BEFORENODE_METHOD_ERROR.getErrCode(), 
                        FlowResultCode.FLOW_CALL_FLOW_BACK_BEFORENODE_METHOD_ERROR.getErrMsg());
            }
    
            return Result.success();
        }
    

    相关文章

      网友评论

        本文标题:Flowable 实现节点驳回

        本文链接:https://www.haomeiwen.com/subject/wqpgaqtx.html