refactor: 重构 流程发起接口,封装发起实例方法
This commit is contained in:
@@ -68,7 +68,7 @@ public class WfProcessController extends BaseController {
|
|||||||
@SaCheckPermission("workflow:process:start")
|
@SaCheckPermission("workflow:process:start")
|
||||||
@PostMapping("/start/{processDefId}")
|
@PostMapping("/start/{processDefId}")
|
||||||
public R<Void> start(@PathVariable(value = "processDefId") String processDefId, @RequestBody Map<String, Object> variables) {
|
public R<Void> start(@PathVariable(value = "processDefId") String processDefId, @RequestBody Map<String, Object> variables) {
|
||||||
processService.startProcess(processDefId, variables);
|
processService.startProcessByDefId(processDefId, variables);
|
||||||
return R.ok("流程启动成功");
|
return R.ok("流程启动成功");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public interface IWfProcessService {
|
|||||||
* @param procDefId 流程定义ID
|
* @param procDefId 流程定义ID
|
||||||
* @param variables 扩展参数
|
* @param variables 扩展参数
|
||||||
*/
|
*/
|
||||||
void startProcess(String procDefId, Map<String, Object> variables);
|
void startProcessByDefId(String procDefId, Map<String, Object> variables);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过DefinitionKey启动流程
|
* 通过DefinitionKey启动流程
|
||||||
|
|||||||
@@ -146,18 +146,11 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void startProcess(String procDefId, Map<String, Object> variables) {
|
public void startProcessByDefId(String procDefId, Map<String, Object> variables) {
|
||||||
try {
|
try {
|
||||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
||||||
.processDefinitionId(procDefId).singleResult();
|
.processDefinitionId(procDefId).singleResult();
|
||||||
if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) {
|
startProcess(processDefinition, variables);
|
||||||
throw new ServiceException("流程已被挂起,请先激活流程");
|
|
||||||
}
|
|
||||||
// 设置流程发起人Id到流程中
|
|
||||||
this.buildProcessVariables(variables);
|
|
||||||
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables);
|
|
||||||
// 第一个用户任务为发起人,则自动完成任务
|
|
||||||
wfTaskService.startFirstTask(processInstance, variables);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new ServiceException("流程启动错误");
|
throw new ServiceException("流程启动错误");
|
||||||
@@ -173,16 +166,9 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void startProcessByDefKey(String procDefKey, Map<String, Object> variables) {
|
public void startProcessByDefKey(String procDefKey, Map<String, Object> variables) {
|
||||||
try {
|
try {
|
||||||
if (StringUtils.isNoneBlank(procDefKey)) {
|
|
||||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
||||||
.processDefinitionKey(procDefKey).latestVersion().singleResult();
|
.processDefinitionKey(procDefKey).latestVersion().singleResult();
|
||||||
if (processDefinition != null && processDefinition.isSuspended()) {
|
startProcess(processDefinition, variables);
|
||||||
throw new ServiceException("流程已被挂起,请先激活流程");
|
|
||||||
}
|
|
||||||
this.buildProcessVariables(variables);
|
|
||||||
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(procDefKey, variables);
|
|
||||||
wfTaskService.startFirstTask(processInstance, variables);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new ServiceException("流程启动错误");
|
throw new ServiceException("流程启动错误");
|
||||||
@@ -438,13 +424,20 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扩展参数构建
|
* 启动流程实例
|
||||||
* @param variables 扩展参数
|
|
||||||
*/
|
*/
|
||||||
private void buildProcessVariables(Map<String, Object> variables) {
|
private void startProcess(ProcessDefinition procDef, Map<String, Object> variables) {
|
||||||
String userIdStr = LoginHelper.getUserId().toString();
|
if (ObjectUtil.isNotNull(procDef) && procDef.isSuspended()) {
|
||||||
|
throw new ServiceException("流程已被挂起,请先激活流程");
|
||||||
|
}
|
||||||
|
// 设置流程发起人Id到流程中
|
||||||
|
String userIdStr = TaskUtils.getUserId();
|
||||||
identityService.setAuthenticatedUserId(userIdStr);
|
identityService.setAuthenticatedUserId(userIdStr);
|
||||||
variables.put(BpmnXMLConstants.ATTRIBUTE_EVENT_START_INITIATOR, userIdStr);
|
variables.put(BpmnXMLConstants.ATTRIBUTE_EVENT_START_INITIATOR, userIdStr);
|
||||||
|
// 发起流程实例
|
||||||
|
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables);
|
||||||
|
// 第一个用户任务为发起人,则自动完成任务
|
||||||
|
wfTaskService.startFirstTask(processInstance, variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user