工作流activiti 6 学习笔记十七 实践动态回退
【摘要】 场景:已知当前节点taskid 和 目标taskid(已审批过的)。从当前节点跳转到目标节点。几经百度,发现大家写的都太复杂了,根据大家的思路进行了代码简化。实现思路:记录当前节点的流向清理当前节点流向建立新流向完成新流向审批还原原来的流向@Override public String submitRollBack(String currenttaskId,String targettask...
场景:已知当前节点taskid 和 目标taskid(已审批过的)。从当前节点跳转到目标节点。几经百度,发现大家写的都太复杂了,根据大家的思路进行了代码简化。
实现思路:记录当前节点的流向
清理当前节点流向
建立新流向
完成新流向审批
还原原来的流向
@Override
public String submitRollBack(String currenttaskId,String targettaskId) {
Task currentTask = ts.createTaskQuery().taskId(currenttaskId).singleResult();
// Task targetTask = ts.createTaskQuery().taskId(targettaskId).singleResult();
HistoricTaskInstance targetTaskH = hs.createHistoricTaskInstanceQuery().taskId(targettaskId).singleResult();
// 退回到起草人
String processDefinitionId = currentTask.getProcessDefinitionId();
// ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) rs.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
BpmnModel bpmnModel = rs.getBpmnModel(processDefinitionId);
// 目标
FlowNode myFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(targetTaskH.getTaskDefinitionKey());
Execution execution = runS.createExecutionQuery().executionId(currentTask.getExecutionId()).singleResult();
String activityId = execution.getActivityId();
FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
//记录原活动方向
List<SequenceFlow> oriSequenceFlows = new ArrayList<SequenceFlow>();
oriSequenceFlows.addAll(flowNode.getOutgoingFlows());
//清理活动方向
flowNode.getOutgoingFlows().clear();
//建立新方向
List<SequenceFlow> newSequenceFlowList = new ArrayList<SequenceFlow>();
SequenceFlow newSequenceFlow = new SequenceFlow();
newSequenceFlow.setId("tempflowId");
newSequenceFlow.setSourceFlowElement(flowNode);
newSequenceFlow.setTargetFlowElement(myFlowNode);
newSequenceFlowList.add(newSequenceFlow);
flowNode.setOutgoingFlows(newSequenceFlowList);
//完成任务
ts.complete(currentTask.getId());
//恢复原方向
flowNode.setOutgoingFlows(oriSequenceFlows);
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)