springboot+activiti7整合开发根据当前任务节点获取已审批过的任务节点

springboot+activiti7整合开发根据当前任务节点获取已审批过的任务节点

应用场景

1、实现任意节点驳回功能;

代码

private static BpmnModel bpmnModel = null;

private static List<HistoricActivityInstance> activityFinishedList = null;

@GetMapping("/getHistoryNode")
@ApiOperation(value = "获取流程实例已执行节点", notes = "获取流程实例已执行节点")
public Result<List<Map<String,Object>>> getHistoryNode(@ApiParam("流程实例id") @RequestParam String procInstId,
                                                       @ApiParam("任务id") @RequestParam String taskId) {
    Result<List<Map<String,Object>>> result = new Result<>();

    tempList = new ArrayList<>();

    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

    String currActivityId = task.getTaskDefinitionKey();

    // 添加发起人任务节点
    List<Map<String,Object>> resultList = new ArrayList<>();
    Map<String, Object> tempMap = new HashMap<>();
    tempMap.put("nodeName", ActivitiConstant.PROCESS_CREATOR_NAME);
    tempMap.put("nodeId", ActivitiConstant.PROCESS_CREATOR_KEY);
    resultList.add(tempMap);

    // 添加上一步任务节点
    tempMap = new HashMap<>();
    tempMap.put("nodeName", ActivitiConstant.PROCESS_PREVIOUS_STEP_NAME);
    tempMap.put("nodeId", ActivitiConstant.PROCESS_PREVIOUS_STEP_KEY);
    resultList.add(tempMap);

    activityFinishedList = historyService.createHistoricActivityInstanceQuery()
            .processInstanceId(procInstId)
            .activityType("userTask")
            .finished()
            .orderByHistoricActivityInstanceEndTime()
            .desc()
            .list();

    bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());

    getReverseNodeList(currActivityId);

    for (HistoricActivityInstance historicActivityInstance : tempList) {
        tempMap = new HashMap<>();
        tempMap.put("nodeName", historicActivityInstance.getActivityName());
        tempMap.put("nodeId", historicActivityInstance.getActivityId());
        if (!resultList.contains(tempMap)) {
            resultList.add(tempMap);
        }
    }

    result.setResult(resultList);
    return result;
}

/**
 * 逆向获取执行过的任务节点:
 * 1、子流程只能获取到本子流程节点+主流程节点,不能获取兄弟流程任务节点;
 * 2、主流程任务节点不能获取子流程任务节点;
 * @param currActivityId
 */
private void getReverseNodeList(String currActivityId) {
    // 获取当前节点的进线,通过进线查询上个节点
    FlowNode currFlow = (FlowNode)bpmnModel.getMainProcess().getFlowElement(currActivityId);
    List<SequenceFlow> incomingFlows = currFlow.getIncomingFlows();

    // 找到上个任务节点
    for (SequenceFlow incomingFlow : incomingFlows) {
        String sourceNodeId = incomingFlow.getSourceRef();
        FlowNode sourceFlowNode = (FlowNode)bpmnModel.getMainProcess().getFlowElement(sourceNodeId);
        String gatewayType = sourceNodeId.substring(sourceNodeId
                .lastIndexOf("_") + 1);
        if (sourceFlowNode instanceof ParallelGateway && "END".equals(gatewayType.toUpperCase())) {
            sourceNodeId = sourceNodeId.substring(0, sourceNodeId
                    .lastIndexOf("_")) + "_start";
            for (HistoricActivityInstance historicActivityInstance : activityFinishedList) {
                if (historicActivityInstance.getActivityId().equals(sourceNodeId)) {
                    tempList.add(historicActivityInstance);
                }
            }
            getReverseNodeList(sourceNodeId);
        } else {
            for (HistoricActivityInstance historicActivityInstance : activityFinishedList) {
                if (historicActivityInstance.getActivityId().equals(sourceNodeId)) {
                    tempList.add(historicActivityInstance);
                }
            }
            getReverseNodeList(sourceNodeId);
        }
    }
}

后续

由于activiti7的在网上比较少,楼主后续会把springboot+activiti7的审批、驳回、作废、撤回等工作流应用场景分享出来,请大家关注楼主!支持楼主!谢谢大家!

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 19
    评论
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值