diff --git a/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/controller/ExtActProcessNodeController.java b/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/controller/ExtActProcessNodeController.java index f711f9d..a6717cf 100644 --- a/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/controller/ExtActProcessNodeController.java +++ b/jeecg-boot-platform/jeecg-boot-module-bpm-flowable/src/main/java/org/jeecg/modules/extbpm/process/controller/ExtActProcessNodeController.java @@ -347,6 +347,43 @@ public class ExtActProcessNodeController { result.setSuccess(true); return result; } + + /** + * 获取流程变量(支持局部变量),从task执行实例向上遍历,精准定位当前分支 + * @param taskId 任务ID + * @param key 变量名 + * @param isLocal 是否仅查局部变量 + * @return 变量值,未找到时value为null + */ + @GetMapping(value = "/getVariable") + public Result> getVariable( + @RequestParam(name = "taskId", required = true) String taskId, + @RequestParam(name = "key", required = true) String key, + @RequestParam(name = "isLocal", defaultValue = "false") Boolean isLocal) { + Result> result = new Result<>(); + Map map = new HashMap<>(); + Object value = null; + Task task = activitiService.getTask(taskId); + if (task != null) { + if (isLocal) { + org.flowable.engine.runtime.Execution currentExec = runtimeService.createExecutionQuery() + .executionId(task.getExecutionId()).singleResult(); + while (currentExec != null) { + value = runtimeService.getVariableLocal(currentExec.getId(), key); + if (value != null) break; + String parentId = currentExec.getParentId(); + if (parentId == null) break; + currentExec = runtimeService.createExecutionQuery().executionId(parentId).singleResult(); + } + } else { + value = runtimeService.getVariable(task.getExecutionId(), key); + } + } + map.put("value", value); + result.setResult(map); + result.setSuccess(true); + return result; + } /** * 根据流程实例id和任务id查询任务节点信息 @@ -422,7 +459,7 @@ public class ExtActProcessNodeController { //获取流程定义ID String insId = extActFlowData.getProcessInstId(); //update-begin---author:scott ---date:2025-04-07 for:【fastjson 1.2.83升级到2.0.56导致】临时方案,解决敲敲云发布后,获取流程变量报错---- - Map variablesMap = null; + Map variablesMap; try { variablesMap = runtimeService.getVariables(insId); } catch (Exception e) {