actvitity查询下一环节相关信息

一、所需要注入的对象

## 注入以下工作流自带的对象
	@Autowired
    private RepositoryService repositoryService; //管理流程定义  与流程定义和部署对象相关的Service

    @Autowired
    private HistoryService historyService; 		//历史管理(执行完的数据的管理)

    @Autowired
    private RuntimeService runtimeService;        //运行中数据管理

    @Autowired
    private TaskService taskService;

整体的方法(查询下一环节信息)

/**
     * 查询下一环节是否有网关且是否有打回操作
     * @author xuao
     * @date 2022/8/5 14:53
     * @param traInstInfo
     * @return com.sitech.dto.nextTask.NextTaskInfo
     */
    public NextTaskInfo qryNextNodeIsGateWayAndIsBackOperate(TraInstInfo traInstInfo) {
        //1.获取流程实例proInstId、当前环节taskId (这一步根据业务去获取吧哈哈哈)
        String proInstId = traInstInfo.getProcInstId();
        String taskId = traInstInfo.getTaskId();
        //2.根据当前taskId查询当前任务相关信息
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task == null) {
            throw new BusiException(Constant.RESP_CODE.SQL_OUT_EMPTY,"当前任务不存在请核查taskId:{},orderId:{}",taskId,traInstInfo.getOrderId());
        }
        //3.根据当前任务id获取流程模板和历史执行的任务数据
        List<HistoricTaskInstance> hisList = historyService.createHistoricTaskInstanceQuery().processInstanceId(proInstId).list();
        //4.根据流程实例proInstId获取流程定义所有节点信息
        Collection<FlowElement> flowElements = getFlowElementsByProInstId(proInstId);
        //5.数据比对: 根据 当前任务、历史执行任务、流程定义元素 获取下一环节判断信息
        return qryNextNodeIsGateWayAndIsBackOperateInfo(task,hisList,flowElements);
    }

根据流程实例proInstId获取流程定义所有元素集合

/**
     * 根据流程实例proInstId获取流程定义所有元素集合
     * @author xuao
     * @date 2022/8/11 15:02
     * @return java.util.Collection<org.activiti.bpmn.model.FlowElement>
     */
    private Collection<FlowElement> getFlowElementsByProInstId(String proInstId) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(proInstId).singleResult();
        //获取流程定义key
        String processDefinitionId = historicProcessInstance.getProcessDefinitionId();
        //根据流程定义key获取流程model
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        //返回model定义中的所有element
        return bpmnModel.getProcesses().get(0).getFlowElements();
    }

根据 当前任务、历史执行任务、流程定义元素 获取下一环节判断信息

/**
     * 根据 当前任务、历史执行任务、流程定义元素 获取下一环节判断信息
     * @author xuao
     * @date 2022/8/11 15:19
     * @return com.sitech.dto.nextTask.NextTaskInfo
     */
    private NextTaskInfo qryNextNodeIsGateWayAndIsBackOperateInfo(Task task, List<HistoricTaskInstance> list, Collection<FlowElement> flowElements) {
        //1.根据流程定义元素进行元素分类
        FlowElementInfo flowElementInfo = getUserTaskAndGateWaySortByFlowElements(flowElements);
        List<Gateway> gateways = flowElementInfo.getGateways();
        List<UserTask> userTasks = flowElementInfo.getUserTasks();
        //2.定义出参:用户任务集合、网关判断、是否打回判断
        List<UserTask> userTaskOuts = new ArrayList<>();
        boolean isGateWayFlag = false;
        boolean isBackFlag = false;
        //3.获取出参信息
        for (UserTask userTask : userTasks) {
            //找到当前任务id
            if (userTask.getId().equals(task.getTaskDefinitionKey())) {
                //获取当前UserTask任务节点的出线
                List<SequenceFlow> outgoingFlows = userTask.getOutgoingFlows();
                for (SequenceFlow outgoingFlow : outgoingFlows) {
                    if (outgoingFlow.getTargetFlowElement() instanceof UserTask) {
                        //是任务环节,则直接返回下一个人工任务处理环节
                        UserTask userTaskNext = (UserTask)outgoingFlow.getTargetFlowElement();
                        userTaskOuts.add(userTaskNext);
                    }
                    if(outgoingFlow.getTargetFlowElement() instanceof ExclusiveGateway) {
                        isGateWayFlag = true;
                        //是单一网关,则判断是否存在之前环节且带出网关引线下一任务信息
                        for (Gateway gateway : gateways) {
                            if (gateway.getId().equals(outgoingFlow.getTargetRef())) {
                                List<SequenceFlow> gatewayOutgoingFlows = gateway.getOutgoingFlows();
                                for (SequenceFlow gatewayOutgoingFlow : gatewayOutgoingFlows) {
                                    UserTask userTaskNext = (UserTask)gatewayOutgoingFlow.getTargetFlowElement();
                                    userTaskOuts.add(userTaskNext);
                                    //任务判断是否存在打回环节
                                    for (HistoricTaskInstance taskInstance : list) {
                                        String endId = taskInstance.getTaskDefinitionKey();
                                        if (userTaskNext.getId().equals(endId)) {
                                            isBackFlag = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        NextTaskInfo outerTask = new NextTaskInfo();
        outerTask.setUserTaskOuts(userTaskOuts);
        outerTask.setGateWayFlag(isGateWayFlag);
        outerTask.setBackFlag(isBackFlag);
        return outerTask;
    }

节点分类

/**
     *
     * @author xuao
     * @date 2022/8/11 15:43
     * @return com.sitech.dto.nextTask.FlowElementInfo
     */
    private FlowElementInfo getUserTaskAndGateWaySortByFlowElements(Collection<FlowElement> flowElements) {
        List<Gateway> gateways = new ArrayList<>();
        List<UserTask> userTasks = new ArrayList<>();
        //任务分类
        flowElements.forEach(flowElement -> {
            if (flowElement instanceof Gateway) {
                gateways.add((Gateway) flowElement);
            }
            if (flowElement instanceof UserTask) {
                userTasks.add((UserTask) flowElement);
            }
        });
        //封装出参
        FlowElementInfo outInfo = new FlowElementInfo();
        outInfo.setUserTasks(userTasks);
        outInfo.setGateways(gateways);
        return outInfo;
    }

注:

NextTaskInfo 对象是封装的出参信息,可根据业务进行自定义的封装,随意即可,重点讲方法,需要的功能,请自定义封装哈哈哈

测试步骤

接口:http://ip:port/fis/flowDispatch/procdef/getNextNodeInfoByOrderId
入参:

{
  "ROOT": {
    "BODY": {
        "orderId": "W2022082517195"
    },
    "HEADER": {
      "additionalProp1": {},
      "additionalProp2": {},
      "additionalProp3": {}
    }
  }
}

出参:

{
    "ROOT": {
        "HEADER": {
            "additionalProp1": {},
            "additionalProp3": {},
            "additionalProp2": {},
            "staffInfo": {}
        },
        "BODY": {
            "RETURN_MSG": "OK",
            "RETURN_CODE": "0",
            "USER_MSG": "OK",
            "DETAIL_MSG": "OK",
            "OUT_DATA": {
                "userTaskOuts": [
                    {
                        "extensionElements": {},
                        "outgoingFlows": [
                            {
                                "targetRef": "sid-94579557-0F3E-4BFE-98D6-000E979D76D2",
                                "xmlColumnNumber": 5,
                                "executionListeners": [],
                                "extensionElements": {},
                                "attributes": {},
                                "id": "sid-09FB452F-DD30-4D53-8B2B-DB9C272F2B41",
                                "sourceRef": "customerConfirm",
                                "waypoints": [
                                    559,
                                    205,
                                    635,
                                    205,
                                    635,
                                    259
                                ],
                                "xmlRowNumber": 19
                            }
                        ],
                        "extended": false,
                        "taskListeners": [],
                        "dataOutputAssociations": [],
                        "asynchronous": false,
                        "candidateUsers": [],
                        "forCompensation": false,
                        "exclusive": true,
                        "id": "customerConfirm",
                        "xmlRowNumber": 15,
                        "formProperties": [],
                        "mapExceptions": [],
                        "incomingFlows": [
                            {
                                "targetRef": "customerConfirm",
                                "xmlColumnNumber": 5,
                                "executionListeners": [],
                                "extensionElements": {},
                                "attributes": {},
                                "id": "sid-B6599F69-7259-4DCC-8B68-97C6D5AA0CCC",
                                "sourceRef": "passengerHandle",
                                "waypoints": [
                                    509,
                                    349,
                                    509,
                                    245
                                ],
                                "xmlRowNumber": 16
                            }
                        ],
                        "boundaryEvents": [],
                        "dataInputAssociations": [],
                        "xmlColumnNumber": 5,
                        "customUserIdentityLinks": {},
                        "customGroupIdentityLinks": {},
                        "customProperties": [],
                        "executionListeners": [],
                        "notExclusive": false,
                        "candidateGroups": [],
                        "name": "客户经理确认",
                        "attributes": {}
                    }
                ],
                "backFlag": false,
                "gateWayFlag": false
            },
            "PROMPT_MSG": ""
        }
    }
}

返回响应

在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值