ProcessDefinitionBehavior processDefinitionBehavior = Context.getCommandContext().getProcessDefinitionManager()
.findLatestProcessDefinitionByKeyAndVersion(flowId, version);
ProcessInstanceEntity subProcessInstance = new ProcessInstanceEntity(processDefinitionBehavior, bizKey,
executionContext.getProcessInstance(), executionContext.getToken());
subProcessInstance.setStartAuthor(Authentication.getAuthenticatedUserId());
DataSourceToSubProcessMapping dataSourceToSubProcessMapping=getDataSourceToSubProcessMapping();
if(dataSourceToSubProcessMapping!=null){
for (DataVariableMapping dataVariableMapping :dataSourceToSubProcessMapping.getDataVariableMapping()) {
String dataSourceId = "${" + dataVariableMapping.getDataSourceId() + "}";
subProcessInstance.getContextInstance().addDataVariable(dataVariableMapping.getSubProcesId(),
ExpressionMgmt.execute(dataSourceId, executionContext));
}
}
try {
subProcessInstance.noneStart();
ProcessInstanceManager processInstanceManager = Context.getCommandContext().getProcessInstanceManager();
processInstanceManager.saveProcessInstance(subProcessInstance);
} catch (Exception e) {
throw new FixFlowException("子流程 " + this.getName() + " 启动异常!", e);
}
createSubTask(executionContext, subProcessInstance.getId());
return subProcessInstance.getId();
}