Activiti工作流驳回操作

 使用activiti6.0工作流,驳回到某个节点。

当前思想:获得流程图,找到当前节点和想要驳回到节点,清理掉线,加上新的线,执行完成操作,然后还原线,图也就还原了。相当于临时修改了一下图,执行了complete操作。

问题:高并发下,其他实例提交,驳回操作取到这个还没还原的图了怎么办?加锁又太耗费资源了。。。有没有什么方法是只取到当前实例的这张图,而不是公用的图?

代码如下:跟图中一样

Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
String currActivityId = task.getTaskDefinitionKey();
String processDefinitionId = task.getProcessDefinitionId();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);//获得流程图
//获得当前待办节点信息
FlowNode currFlow = (FlowNode) bpmnModel.getMainProcess().getFlowElement(currActivityId);
//获得驳回目标节点信息
FlowNode targetFlow = (FlowNode) bpmnModel.getFlowElement(pti.getTaskId());
//如果不是同一个流程(子流程)不能驳回
if (!(currFlow.getParentContainer().equals(targetFlow.getParentContainer()))) {
    logger.info("此处无法进行驳回操作,抛出异常");
}
//记录原活动方向
List<SequenceFlow> oriSequenceFlows = new ArrayList<>(currFlow.getOutgoingFlows());
//清理活动方向
currFlow.getOutgoingFlows().clear();
//建立新的方向
List<SequenceFlow> newSequenceFlows = new ArrayList<>();
SequenceFlow newSequenceFlow = new SequenceFlow();
String uuid = UUID.randomUUID().toString().replace("-", "");
newSequenceFlow.setId(uuid);
newSequenceFlow.setSourceFlowElement(currFlow);  //原节点
newSequenceFlow.setTargetFlowElement(targetFlow);  //目标节点
newSequenceFlows.add(newSequenceFlow);
currFlow.setOutgoingFlows(newSequenceFlows);
//完成节点任务
//taskService.complete(task.getId(), map条件);动态每次完成的时候设置进去条件,不用一次性开始就设置
taskService.complete(task.getId());//驳回不需要条件
//恢复原方向
currFlow.setOutgoingFlows(oriSequenceFlows);
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
您好,Activiti 7 中的驳回操作可以通过以下代码实现: ```java public void rejectTask(String taskId) { // 获取当前任务 Task task = taskService.createTaskQuery() .taskId(taskId) .singleResult(); if (task == null) { throw new RuntimeException("任务不存在"); } // 获取当前任务的程实例 String processInstanceId = task.getProcessInstanceId(); // 获取当前任务的历史任务实例列表 List<HistoricTaskInstance> historicTaskList = historyService.createHistoricTaskInstanceQuery() .processInstanceId(processInstanceId) .orderByHistoricTaskInstanceEndTime() .asc() .list(); // 获取需要驳回到的任务 HistoricTaskInstance targetTask = null; for (int i = 0; i < historicTaskList.size(); i++) { HistoricTaskInstance historicTask = historicTaskList.get(i); if (historicTask.getId().equals(taskId)) { if (i == 0) { throw new RuntimeException("该任务已经是第一个任务,无法驳回"); } targetTask = historicTaskList.get(i - 1); break; } } if (targetTask == null) { throw new RuntimeException("未找到驳回目标任务"); } // 驳回操作 BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId()); Process process = bpmnModel.getProcesses().get(0); FlowNode sourceNode = (FlowNode) process.getFlowElement(task.getTaskDefinitionKey()); FlowNode targetNode = (FlowNode) process.getFlowElement(targetTask.getTaskDefinitionKey()); List<Execution> executionList = runtimeService.createExecutionQuery() .processInstanceId(processInstanceId) .list(); for (Execution execution : executionList) { if (execution instanceof ExecutionEntity) { ExecutionEntity executionEntity = (ExecutionEntity) execution; executionEntity.setCurrentFlowElement(sourceNode); runtimeService.createChangeActivityStateBuilder() .processInstanceId(processInstanceId) .moveExecutionToActivityId(executionEntity.getId(), targetNode.getId()) .changeState(); } } } ``` 该代码实现了将当前任务驳回到上一步任务的操作,具体的实现过程请参考注释。需要注意的是,该代码中使用了 Activiti 7 中的一些 API,如 `BpmnModel`、`FlowNode` 等,如果您之前使用的是 Activiti 6,可能需要进行一些调整。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值