大lao们!驳回时提交后恢复原方向,要是提交中间有别的人点提交就直接到驳回的节点了,这个并发怎么弄啊?
activiti7
String processInstanceId = task.getProcessInstanceId();
// 取得所有历史任务按时间降序排序
List<HistoricTaskInstance> htiList = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByTaskCreateTime()
.desc()
.list();
if (htiList==null || htiList.size() < 2) {
return;
}
// list里的第二条代表上一个任务
HistoricTaskInstance lastTask = htiList.get(1);
// list里第二条代表当前任务
HistoricTaskInstance curTask = htiList.get(0);
// 当前节点的executionId
String curExecutionId = curTask.getExecutionId();
// 上个节点的taskId
String lastTaskId = lastTask.getId();
// 上个节点的executionId
String lastExecutionId = lastTask.getExecutionId();
if (null == lastTaskId) {
throw new Exception("LAST TASK IS NULL");
}
String processDefinitionId = lastTask.getProcessDefinitionId();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
String lastActivityId = null;
List<HistoricActivityInstance> haiFinishedList = historyService.createHistoricActivityInstanceQuery()
.executionId(lastExecutionId).finished().list();
for (HistoricActivityInstance hai : haiFinishedList) {
if (lastTaskId.equals(hai.getTaskId())) {
// 得到ActivityId,只有HistoricActivityInstance对象里才有此方法
lastActivityId = hai.getActivityId();
break;
}
}
// 得到上个节点的信息
FlowNode lastFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(lastActivityId);
// 取得当前节点的信息
Execution execution = runtimeService.createExecutionQuery().executionId(curExecutionId).singleResult();
String curActivityId = execution.getActivityId();
FlowNode curFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(curActivityId);
//记录当前节点的原活动方向
List<SequenceFlow> oriSequenceFlows = new ArrayList<>();
oriSequenceFlows.addAll(curFlowNode.getOutgoingFlows());
//清理活动方向
curFlowNode.getOutgoingFlows().clear();
//建立新方向
List<SequenceFlow> newSequenceFlowList = new ArrayList<>();
SequenceFlow newSequenceFlow = new SequenceFlow();
newSequenceFlow.setId("newSequenceFlowId");
newSequenceFlow.setSourceFlowElement(curFlowNode);
newSequenceFlow.setTargetFlowElement(lastFlowNode);
newSequenceFlowList.add(newSequenceFlow);
**curFlowNode.setOutgoingFlows(newSequenceFlowList);**
// 完成任务
taskService.complete(task.getId());
//恢复原方向
**curFlowNode.setOutgoingFlows(oriSequenceFlows);**
org.activiti.engine.task.Task nextTask = taskService
.createTaskQuery().processInstanceId(processInstanceId).singleResult();
// 设置执行人
if(nextTask!=null) {
taskService.setAssignee(nextTask.getId(), lastTask.getAssignee());
}