增加生成后端服务代码。

This commit is contained in:
dengqichen 2025-10-25 01:31:32 +08:00
parent e340e3106d
commit 15d3720f5f

View File

@ -186,11 +186,18 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl<WorkflowInstanc
public WorkflowInstanceDTO startWorkflow(WorkflowInstanceStartRequest request) { public WorkflowInstanceDTO startWorkflow(WorkflowInstanceStartRequest request) {
try { try {
WorkflowDefinition workflowDefinition = workflowDefinitionRepository.findByKey(request.getProcessKey()).orElseThrow(() -> new RuntimeException("Workflow definition process key not found: " + request.getProcessKey())); WorkflowDefinition workflowDefinition = workflowDefinitionRepository.findByKey(request.getProcessKey()).orElseThrow(() -> new RuntimeException("Workflow definition process key not found: " + request.getProcessKey()));
// 将前端传入的 variables 包装到 "form" 变量中
// 这样流程中的 ${form.xxx} 表达式就能正确解析
Map<String, Object> variables = new HashMap<>();
if (request.getVariables() != null && !request.getVariables().isEmpty()) {
variables.put("form", request.getVariables());
}
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder() ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey(request.getProcessKey()) .processDefinitionKey(request.getProcessKey())
.variables(request.getVariables()) .variables(variables) // 使用包装后的变量
.businessKey(request.getBusinessKey()) .businessKey(request.getBusinessKey())
.variables(request.getVariables())
.startAsync(); // 异步启动会自动执行 shell 任务 .startAsync(); // 异步启动会自动执行 shell 任务
// .start(); // .start();
return createWorkflowInstance(workflowDefinition.getId(), request.getBusinessKey(), processInstance); return createWorkflowInstance(workflowDefinition.getId(), request.getBusinessKey(), processInstance);