【功能新增】工作流:API 创建流程时,设置 userId(解决 Job 下,无法设置 userId 的问题)
This commit is contained in:
parent
cdb31679da
commit
82b03d7f7d
|
@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flowable 相关的工具方法
|
* Flowable 相关的工具方法
|
||||||
|
@ -40,6 +41,17 @@ public class FlowableUtils {
|
||||||
Authentication.setAuthenticatedUserId(null);
|
Authentication.setAuthenticatedUserId(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <V> V executeAuthenticatedUserId(Long userId, Callable<V> callable) {
|
||||||
|
setAuthenticatedUserId(userId);
|
||||||
|
try {
|
||||||
|
return callable.call();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
clearAuthenticatedUserId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getTenantId() {
|
public static String getTenantId() {
|
||||||
Long tenantId = TenantContextHolder.getTenantId();
|
Long tenantId = TenantContextHolder.getTenantId();
|
||||||
return tenantId != null ? String.valueOf(tenantId) : ProcessEngineConfiguration.NO_TENANT_ID;
|
return tenantId != null ? String.valueOf(tenantId) : ProcessEngineConfiguration.NO_TENANT_ID;
|
||||||
|
|
|
@ -557,11 +557,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) {
|
public String createProcessInstance(Long userId, @Valid BpmProcessInstanceCreateReqDTO createReqDTO) {
|
||||||
|
return FlowableUtils.executeAuthenticatedUserId(userId, () -> {
|
||||||
// 获得流程定义
|
// 获得流程定义
|
||||||
ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
|
ProcessDefinition definition = processDefinitionService.getActiveProcessDefinition(createReqDTO.getProcessDefinitionKey());
|
||||||
// 发起流程
|
// 发起流程
|
||||||
return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(),
|
return createProcessInstance0(userId, definition, createReqDTO.getVariables(), createReqDTO.getBusinessKey(),
|
||||||
createReqDTO.getStartUserSelectAssignees());
|
createReqDTO.getStartUserSelectAssignees());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createProcessInstance0(Long userId, ProcessDefinition definition,
|
private String createProcessInstance0(Long userId, ProcessDefinition definition,
|
||||||
|
|
Loading…
Reference in New Issue