提交 0bf67d0e 编写于 作者: zhouweidong's avatar zhouweidong

恢复工作流回退

上级 215063f9
......@@ -34,6 +34,7 @@ import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.ProcessInstanceHistoryLog;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.task.Comment;
import org.flowable.identitylink.api.IdentityLink;
......@@ -1902,4 +1903,53 @@ public class WFCoreService
});
return true;
}
/**
* @param taskId 当前需要回退的节点
* @return 回退上一个节点
*/
public boolean wfback(String system,String appname,String entity,String taskId) {
try {
Boolean flag = true;
String sourceRef = null;
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
String taskDefinitionKey = task.getTaskDefinitionKey();
if (taskDefinitionKey == null) {
log.debug("taskDefinitionKey不存在");
return false;
}
String processInstanceId = task.getProcessInstanceId();
if (processInstanceId == null) {
log.debug("processInstanceId不存在");
return false;
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
// 获取历史路径
WFProcessInstance instance = getWFHistory(system, appname, entity, taskDefinitionKey, task.getProcessInstanceId());
if (!ObjectUtils.isEmpty(flowNode) && !ObjectUtils.isEmpty(instance)) {
List<WFProcessNode> usertasks = new ArrayList((Collection<? extends WFProcessNode>) instance.getExtensionparams().get("usertasks"));
for (WFProcessNode node : usertasks) {
for (SequenceFlow flow : flowNode.getIncomingFlows()) {
if (node.getUsertaskid().equals(flow.getSourceRef())&&flow.getSourceRef().startsWith("tid")) {
sourceRef = flow.getSourceRef();
flag = false;
break;
}
}
if (!flag) {
break;
}
}
} else {
return false;
}
// 执行回退
runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveActivityIdTo(taskDefinitionKey, sourceRef).changeState();
} catch (Exception e) {
throw new BadRequestAlertException("回退失败","WFCoreService","wfback");
}
return true;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册