yxk-20260506-自定义流程表达式:

setProcessVariable可以写入主流程变量/子流程局部变量
增加了 taskId、executionId、local 字段
传 local: true 且有 taskId 时,通过 taskId 查当前 executionId
调用 runtimeService.setVariableLocal(executionId, 'subApproveUser', value)
不传 local/taskId/executionId 时,保持原来的 setVariable(processInstanceId, ...) 行为
This commit is contained in:
ye1023
2026-05-03 11:37:24 +08:00
parent 1737dffef2
commit f7b6518038
2 changed files with 28 additions and 0 deletions
@@ -11,6 +11,8 @@ import org.apache.commons.io.IOUtils;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.util.RedisUtil;
@@ -53,6 +55,8 @@ public class ActProcessController {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private ActProcessService actProcessService;
@Autowired
private IExtActProcessService extActProcessService;
@@ -87,6 +91,21 @@ public class ActProcessController {
if (oConvertUtils.isEmpty(dto.getVarField())) {
return Result.error("流程变量名不能为空");
}
if (Boolean.TRUE.equals(dto.getLocal()) || oConvertUtils.isNotEmpty(dto.getExecutionId()) || oConvertUtils.isNotEmpty(dto.getTaskId())) {
String executionId = dto.getExecutionId();
if (oConvertUtils.isEmpty(executionId) && oConvertUtils.isNotEmpty(dto.getTaskId())) {
Task task = taskService.createTaskQuery().taskId(dto.getTaskId()).singleResult();
if (task == null) {
return Result.error("任务ID不存在");
}
executionId = task.getExecutionId();
}
if (oConvertUtils.isEmpty(executionId)) {
return Result.error("执行ID不能为空");
}
runtimeService.setVariableLocal(executionId, dto.getVarField(), dto.getVarVal());
return Result.OK("保存成功");
}
runtimeService.setVariable(dto.getProcessInstanceId(), dto.getVarField(), dto.getVarVal());
return Result.OK("保存成功");
}
@@ -13,9 +13,18 @@ public class ProcessVariableDTO implements Serializable {
@Schema(description = "Process instance id")
private String processInstanceId;
@Schema(description = "Task id")
private String taskId;
@Schema(description = "Execution id")
private String executionId;
@Schema(description = "Process variable name")
private String varField;
@Schema(description = "Process variable value")
private Object varVal;
@Schema(description = "Whether to save as execution local variable")
private Boolean local;
}