From 1841d86b1852c2bd3b6ed9198aa52d61440cc2fe Mon Sep 17 00:00:00 2001 From: wangli <274027703@qq.com> Date: Thu, 25 Dec 2025 14:23:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(REQ-5965)=20-=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=A8=E4=BA=8E=E6=9B=BF=E6=8D=A2=20wps=20?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E4=B9=8B=E5=89=8D=E7=9A=84=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=85=8D=E5=90=88=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E4=B8=AD=E7=9A=84=E6=9B=BF=E6=8D=A2=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E9=85=8D=E7=BD=AE=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...etProcessInstanceVariablesToObjectCmd.java | 29 +++++++++++++---- .../CustomOverrideProcessVariablesCmd.java | 31 +++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomGetProcessInstanceVariablesToObjectCmd.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomGetProcessInstanceVariablesToObjectCmd.java index bae1f6d06..a651b4bc0 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomGetProcessInstanceVariablesToObjectCmd.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomGetProcessInstanceVariablesToObjectCmd.java @@ -119,7 +119,7 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman Map processVariables = historicProcessInstance.getProcessVariables(); // 添加流程业务 ID 和业务下分组变量信息 - addProcessDefinitionKeyAndVariables(returnVariables, (Map) processVariables.getOrDefault(SIGN_VARIABLE, new HashMap()), historicProcessInstance); + addProcessDefinitionKeyAndVariables(returnVariables, historicProcessInstance); // 发起人流程引擎内部模型,需要外部调用该命令时,再解析; 当前命令所在 module 不支持调用二方接口 returnVariables.add(VariableObjectDTO.builder() @@ -227,6 +227,14 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman .type(convert(field.getType())) .build()); } + } else { + // 为了在审批最终结束时,配合审批业务的替换为空串的配置使用 + variables.add(VariableObjectDTO.builder() + .key(field.getId()) + .desc(field.getName()) + .value(null) + .type(convert(field.getType())) + .build()); } } }); @@ -250,9 +258,8 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman }); } - private void addProcessDefinitionKeyAndVariables(List variables, Map bizVariables, HistoricProcessInstance historicProcessInstance) { + private void addProcessDefinitionKeyAndVariables(List variables, HistoricProcessInstance historicProcessInstance) { CategoryService categoryService = SpringContextUtils.getBean(CategoryService.class); - Map processVariables = historicProcessInstance.getProcessVariables(); categoryService.get(BPM_MODEL_CATEGORY, historicProcessInstance.getProcessDefinitionKey()).ifPresent(category -> { variables.add(VariableObjectDTO.builder() .key(PRINT_VAR_PROCESS_DEFINITION_KEY) @@ -260,11 +267,13 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman .value(category.getLabel() + "(" + category.getValue() + ")") .build()); // 添加业务下的变量 - addVariables(variables, category, bizVariables, processVariables); + addVariables(variables, category, historicProcessInstance); }); } - private void addVariables(List variables, CategoryItemVO category, Map bizVariables, Map processVariables) { + private void addVariables(List variables, CategoryItemVO category, HistoricProcessInstance historicProcessInstance) { + Map bizVariables = (Map) historicProcessInstance.getProcessVariables().getOrDefault(SIGN_VARIABLE, new HashMap()); + CategoryGroupService categoryServiceGroup = SpringContextUtils.getBean(CategoryGroupService.class); List groupVariables = categoryServiceGroup.searchGroupAndVarList(CategoryGroupVarSearchDto.builder() .dictId(category.getId()) @@ -277,12 +286,20 @@ public class CustomGetProcessInstanceVariablesToObjectCmd extends AbstractComman variables.add(VariableObjectDTO.builder() .key(variable.getCode()) .desc(group.getGroupName() + variable.getName()) - .value(processVariables.getOrDefault(variable.getCode(), bizVariables.getOrDefault(variable.getCode(), null))) + .value(bizVariables.getOrDefault(variable.getCode(), null)) .type(convert(variable.getType())) .build()); }); } }); + } + + private void addVariables(List variables, CategoryItemVO category, Map bizVariables, Map processVariables) { + CategoryGroupService categoryServiceGroup = SpringContextUtils.getBean(CategoryGroupService.class); + List groupVariables = categoryServiceGroup.searchGroupAndVarList(CategoryGroupVarSearchDto.builder() + .dictId(category.getId()) + .category(category.getValue()) + .build()); } diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomOverrideProcessVariablesCmd.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomOverrideProcessVariablesCmd.java index 3a49e6ee1..0519ad756 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomOverrideProcessVariablesCmd.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomOverrideProcessVariablesCmd.java @@ -1,6 +1,11 @@ package cn.axzo.workflow.core.engine.cmd; import cn.axzo.workflow.common.exception.WorkflowEngineException; +import cn.axzo.workflow.common.model.request.category.CategoryGroupVarSearchDto; +import cn.axzo.workflow.common.model.response.category.CategoryGroupVarItemVo; +import cn.axzo.workflow.core.common.utils.SpringContextUtils; +import cn.axzo.workflow.core.service.CategoryGroupService; +import cn.axzo.workflow.core.service.CategoryService; import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; import org.flowable.common.engine.impl.interceptor.CommandContext; @@ -12,10 +17,13 @@ import org.springframework.util.CollectionUtils; import java.io.Serializable; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import static cn.axzo.workflow.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_NOT_EXISTS; +import static cn.axzo.workflow.common.constant.BpmnConstants.BPM_MODEL_CATEGORY; +import static cn.axzo.workflow.common.constant.BpmnConstants.SIGN_VARIABLE; /** * 覆写指定流程中的变量 @@ -55,6 +63,29 @@ public class CustomOverrideProcessVariablesCmd extends AbstractCommand imp throw new WorkflowEngineException(PROCESS_INSTANCE_NOT_EXISTS); } + Map signVariables = new HashMap<>(); + CategoryService categoryService = SpringContextUtils.getBean(CategoryService.class); + CategoryGroupService categoryServiceGroup = SpringContextUtils.getBean(CategoryGroupService.class); + categoryService.get(BPM_MODEL_CATEGORY, processInstance.getProcessDefinitionKey()).ifPresent(category -> { + List groupVariables = categoryServiceGroup.searchGroupAndVarList(CategoryGroupVarSearchDto.builder() + .dictId(category.getId()) + .category(category.getValue()) + .build()); + + groupVariables.forEach(group -> { + if (!CollectionUtils.isEmpty(group.getVars())) { + group.getVars().forEach(variable -> { + if (variables.containsKey(variable.getCode())) { + signVariables.put(variable.getCode(), variables.get(variable.getCode())); + } + }); + } + }); + }); + if (!CollectionUtils.isEmpty(signVariables)) { + variables.put(SIGN_VARIABLE, signVariables); + } + runtimeService.setVariables(processInstanceId, variables); return null; }