From f45758b8fdac813c0e7b26ab798ab610be2d9374 Mon Sep 17 00:00:00 2001 From: smallNorthLee <18210040298@163.com> Date: Sun, 23 Feb 2025 20:12:05 +0800 Subject: [PATCH 01/15] =?UTF-8?q?feat:=20=E5=AE=A1=E6=89=B9=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E8=87=AA=E9=80=89=E5=AE=A1=E6=89=B9=E4=BA=BA=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/service/task/BpmProcessInstanceServiceImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java index e284e42706..1976e13a8b 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java @@ -173,7 +173,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService } startUserId = Long.valueOf(historicProcessInstance.getStartUserId()); processInstanceStatus = FlowableUtils.getProcessInstanceStatus(historicProcessInstance); - processVariables = historicProcessInstance.getProcessVariables(); + // 如果流程变量为空,则使用历史流程变量 + if (null == processVariables) { + processVariables = historicProcessInstance.getProcessVariables(); + } } // 1.3 读取其它相关数据 ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition( From 5d163550424d40d0025293a9d8bc78f11b675a7c Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Mon, 24 Feb 2025 16:31:03 +0800 Subject: [PATCH 02/15] =?UTF-8?q?fix=EF=BC=9A=201=E3=80=81=E9=A2=84?= =?UTF-8?q?=E6=B5=8B=E8=8A=82=E7=82=B9=E5=AE=A1=E6=89=B9=E4=BA=BA=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E5=A6=82=E6=9E=9C=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=EF=BC=8C=E5=88=99=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=A9=BA?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=202=E3=80=81=E5=A6=82=E6=9E=9CprocessVariabl?= =?UTF-8?q?es=E4=B8=8D=E4=B8=BA=E7=A9=BA=EF=BC=8C=E5=88=99=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=89=8D=E7=AB=AF=E4=BC=A0=E9=80=92=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BpmTaskCandidateStartUserSelectStrategy.java | 10 ++++++++-- .../task/BpmProcessInstanceServiceImpl.java | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java index 9fd14d6ded..d547643609 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java @@ -53,8 +53,11 @@ public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCand Map> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance); Assert.notNull(startUserSelectAssignees, "流程实例({}) 的发起人自选审批人不能为空", execution.getProcessInstanceId()); - // 获得审批人 + // 获得审批人,如果不存在,则直接返回空,避免类型转换异常 List assignees = startUserSelectAssignees.get(execution.getCurrentActivityId()); + if (CollUtil.isEmpty(assignees)){ + return null; + } return new LinkedHashSet<>(assignees); } @@ -68,8 +71,11 @@ public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCand if (startUserSelectAssignees == null) { return Sets.newLinkedHashSet(); } - // 获得审批人 + // 获得审批人,如果不存在,则直接返回空,避免类型转换异常 List assignees = startUserSelectAssignees.get(activityId); + if (CollUtil.isEmpty(assignees)){ + return null; + } return new LinkedHashSet<>(assignees); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java index 1976e13a8b..27884ae51e 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java @@ -173,10 +173,19 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService } startUserId = Long.valueOf(historicProcessInstance.getStartUserId()); processInstanceStatus = FlowableUtils.getProcessInstanceStatus(historicProcessInstance); - // 如果流程变量为空,则使用历史流程变量 - if (null == processVariables) { - processVariables = historicProcessInstance.getProcessVariables(); + // 如果流程变量不为空,则用前端传递的新变量值覆盖历史的流程变量 + Map historicVariables = historicProcessInstance.getProcessVariables(); + if (null != processVariables) { + // 遍历新变量值,仅更新历史变量中存在的键 + for (Map.Entry entry : processVariables.entrySet()) { + String key = entry.getKey(); + if (historicVariables.containsKey(key)) { + // 如果历史变量中存在该键,则用新值覆盖 + historicVariables.put(key, entry.getValue()); + } + } } + processVariables = historicVariables; } // 1.3 读取其它相关数据 ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition( From 45a72f4cd857397c05da7a3136bb291e564a46b8 Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Mon, 24 Feb 2025 17:15:17 +0800 Subject: [PATCH 03/15] =?UTF-8?q?fix=EF=BC=9A=E5=AE=A1=E6=89=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0=E5=AE=A1=E6=89=B9=E4=BA=BA=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/task/vo/task/BpmTaskApproveReqVO.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java index 40df86efc8..07078b8db3 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotEmpty; import lombok.Data; +import java.util.List; import java.util.Map; @Schema(description = "管理后台 - 通过流程任务的 Request VO") @@ -23,4 +24,7 @@ public class BpmTaskApproveReqVO { @Schema(description = "变量实例(动态表单)", requiredMode = Schema.RequiredMode.REQUIRED) private Map variables; + @Schema(description = "节点审批人", example = "[1,2]") + private List assignees; + } From e11529375ef1e52c548597d12271c7ddb9fb9437 Mon Sep 17 00:00:00 2001 From: smallNorthLee <18210040298@163.com> Date: Mon, 24 Feb 2025 22:56:18 +0800 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=E5=AE=A1=E6=89=B9=E6=97=B6?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=B8=8B=E4=B8=80=E4=B8=AA=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=98=AF=E5=90=A6=E4=B8=BA=E8=87=AA?= =?UTF-8?q?=E9=80=89=E5=AE=A1=E6=89=B9=E4=BA=BA=E6=98=AF=E5=90=A6=E5=B7=B2?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E4=BA=86=E5=AE=A1=E6=89=B9=E4=BA=BA=EF=BC=8C?= =?UTF-8?q?=E5=90=A6=E5=88=99=E7=94=B1=E5=89=8D=E7=AB=AF=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/task/vo/task/BpmTaskApproveReqVO.java | 4 ++-- .../dept/BpmTaskCandidateStartUserSelectStrategy.java | 4 ++-- .../yudao/module/bpm/service/task/BpmTaskServiceImpl.java | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java index 07078b8db3..b84cb44ca6 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java @@ -24,7 +24,7 @@ public class BpmTaskApproveReqVO { @Schema(description = "变量实例(动态表单)", requiredMode = Schema.RequiredMode.REQUIRED) private Map variables; - @Schema(description = "节点审批人", example = "[1,2]") - private List assignees; + @Schema(description = "发起人自选审批人 Map", example = "{taskKey1: [1, 2]}") + private Map> startUserSelectAssignees; } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java index d547643609..07b051cadd 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java @@ -56,7 +56,7 @@ public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCand // 获得审批人,如果不存在,则直接返回空,避免类型转换异常 List assignees = startUserSelectAssignees.get(execution.getCurrentActivityId()); if (CollUtil.isEmpty(assignees)){ - return null; + return Sets.newLinkedHashSet(); } return new LinkedHashSet<>(assignees); } @@ -74,7 +74,7 @@ public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCand // 获得审批人,如果不存在,则直接返回空,避免类型转换异常 List assignees = startUserSelectAssignees.get(activityId); if (CollUtil.isEmpty(assignees)){ - return null; + return Sets.newLinkedHashSet(); } return new LinkedHashSet<>(assignees); } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 76c7771035..f4d08b59d9 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -520,6 +520,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); // 修改表单的值需要存储到 ProcessInstance 变量 + if (CollUtil.isNotEmpty(reqVO.getStartUserSelectAssignees())) { + variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, + reqVO.getStartUserSelectAssignees()); + } runtimeService.setVariables(task.getProcessInstanceId(), variables); taskService.complete(task.getId(), variables, true); } else { From f2909d6bb6bb1928bcc3d20f6e75a14844b61ef2 Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Tue, 25 Feb 2025 16:27:05 +0800 Subject: [PATCH 05/15] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E9=80=89=E8=8A=82=E7=82=B9=E5=AE=A1=E6=89=B9=E4=BA=BA=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E7=94=B1=E5=89=8D=E7=AB=AF=E4=BC=A0=E9=80=92?= =?UTF-8?q?=E4=B8=8B=E4=B8=AA=E8=8A=82=E7=82=B9=E9=80=89=E6=8B=A9=E7=9A=84?= =?UTF-8?q?=E5=AE=A1=E6=89=B9=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/bpm/service/task/BpmTaskServiceImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index f4d08b59d9..f2bd3ff993 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -519,10 +519,12 @@ public class BpmTaskServiceImpl implements BpmTaskService { // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); - // 修改表单的值需要存储到 ProcessInstance 变量 + // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getStartUserSelectAssignees())) { - variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, - reqVO.getStartUserSelectAssignees()); + // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 + Map> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(instance.getProcessVariables()); + startUserSelectAssignees.putAll(reqVO.getStartUserSelectAssignees()); + variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); } runtimeService.setVariables(task.getProcessInstanceId(), variables); taskService.complete(task.getId(), variables, true); From b2ca263067661919b0eeec181058b228bfd45593 Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Tue, 25 Feb 2025 16:29:35 +0800 Subject: [PATCH 06/15] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dept/BpmTaskCandidateStartUserSelectStrategy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java index 07b051cadd..f4efa549e5 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/dept/BpmTaskCandidateStartUserSelectStrategy.java @@ -53,7 +53,7 @@ public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCand Map> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance); Assert.notNull(startUserSelectAssignees, "流程实例({}) 的发起人自选审批人不能为空", execution.getProcessInstanceId()); - // 获得审批人,如果不存在,则直接返回空,避免类型转换异常 + // 获得审批人,如果不存在,则直接返回空,fix: 用于节点预测时,如果该节点不存在发起人自选审批人,类型转换异常 List assignees = startUserSelectAssignees.get(execution.getCurrentActivityId()); if (CollUtil.isEmpty(assignees)){ return Sets.newLinkedHashSet(); @@ -71,7 +71,7 @@ public class BpmTaskCandidateStartUserSelectStrategy extends AbstractBpmTaskCand if (startUserSelectAssignees == null) { return Sets.newLinkedHashSet(); } - // 获得审批人,如果不存在,则直接返回空,避免类型转换异常 + // 获得审批人,如果不存在,则直接返回空,fix: 用于节点预测时,如果该节点不存在发起人自选审批人,类型转换异常 List assignees = startUserSelectAssignees.get(activityId); if (CollUtil.isEmpty(assignees)){ return Sets.newLinkedHashSet(); From 37b2fd4789e50c646a3839fd31231d39d131eec4 Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Wed, 26 Feb 2025 15:59:42 +0800 Subject: [PATCH 07/15] =?UTF-8?q?feat=EF=BC=9A=E8=B0=83=E6=95=B4=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/task/vo/task/BpmTaskApproveReqVO.java | 4 ++-- .../yudao/module/bpm/service/task/BpmTaskServiceImpl.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java index b84cb44ca6..a0751c12e6 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskApproveReqVO.java @@ -24,7 +24,7 @@ public class BpmTaskApproveReqVO { @Schema(description = "变量实例(动态表单)", requiredMode = Schema.RequiredMode.REQUIRED) private Map variables; - @Schema(description = "发起人自选审批人 Map", example = "{taskKey1: [1, 2]}") - private Map> startUserSelectAssignees; + @Schema(description = "下一个节点审批人", example = "{nodeId:[1, 2]}") + private Map> nextAssignees; } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index f2bd3ff993..1866ed006f 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -520,11 +520,11 @@ public class BpmTaskServiceImpl implements BpmTaskService { if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); // 下个节点审批人如果不存在,则由前端传递 - if (CollUtil.isNotEmpty(reqVO.getStartUserSelectAssignees())) { + if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 - Map> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(instance.getProcessVariables()); - startUserSelectAssignees.putAll(reqVO.getStartUserSelectAssignees()); - variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); + Map> hisProcessVariables = FlowableUtils.getStartUserSelectAssignees(instance.getProcessVariables()); + hisProcessVariables.putAll(reqVO.getNextAssignees()); + variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, hisProcessVariables); } runtimeService.setVariables(task.getProcessInstanceId(), variables); taskService.complete(task.getId(), variables, true); From 13c2d36eeea6455d65c4b1262fccfdf816e0558c Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Wed, 26 Feb 2025 17:45:35 +0800 Subject: [PATCH 08/15] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=AE=A1=E6=89=B9=E6=97=B6=E6=A0=A1=E9=AA=8C=EF=BC=8C?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E4=B8=8B=E4=B8=80=E4=B8=AA=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=AE=A1=E6=89=B9=E7=9A=84=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/bpm/enums/ErrorCodeConstants.java | 1 + .../task/BpmProcessInstanceServiceImpl.java | 9 +---- .../bpm/service/task/BpmTaskServiceImpl.java | 36 +++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java index 7fbc7ba223..e089f33751 100644 --- a/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java +++ b/yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/ErrorCodeConstants.java @@ -57,6 +57,7 @@ public interface ErrorCodeConstants { ErrorCode TASK_CREATE_FAIL_NO_CANDIDATE_USER = new ErrorCode(1_009_006_003, "操作失败,原因:找不到任务的审批人!"); ErrorCode TASK_SIGNATURE_NOT_EXISTS = new ErrorCode(1_009_005_015, "签名不能为空!"); ErrorCode TASK_REASON_REQUIRE = new ErrorCode(1_009_005_016, "审批意见不能为空!"); + ErrorCode TASK_START_USER_SELECT_NODE_NOT_EXISTS = new ErrorCode(1_009_004_007, "({})不是下一个执行的流程节点!"); // ========== 动态表单模块 1-009-010-000 ========== ErrorCode FORM_NOT_EXISTS = new ErrorCode(1_009_010_000, "动态表单不存在"); diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java index 27884ae51e..3bd5c1098f 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java @@ -176,14 +176,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService // 如果流程变量不为空,则用前端传递的新变量值覆盖历史的流程变量 Map historicVariables = historicProcessInstance.getProcessVariables(); if (null != processVariables) { - // 遍历新变量值,仅更新历史变量中存在的键 - for (Map.Entry entry : processVariables.entrySet()) { - String key = entry.getKey(); - if (historicVariables.containsKey(key)) { - // 如果历史变量中存在该键,则用新值覆盖 - historicVariables.put(key, entry.getValue()); - } - } + historicVariables.putAll(processVariables); } processVariables = historicVariables; } diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 1866ed006f..44c04fb030 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -10,15 +10,19 @@ import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.PageUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailReqVO; +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO; import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*; import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; +import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.bpm.enums.definition.*; import cn.iocoder.yudao.module.bpm.enums.task.BpmCommentTypeEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskSignTypeEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; +import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; @@ -56,6 +60,7 @@ import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import java.util.*; +import java.util.stream.Collectors; import java.util.stream.Stream; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -519,6 +524,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); + // 校验传递的参数中是否存在不是下一个执行的节点 + checkNextActivityNodes(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 @@ -536,6 +543,35 @@ public class BpmTaskServiceImpl implements BpmTaskService { handleParentTaskIfSign(task.getParentTaskId()); } + /** + * 校验传递的参数中是否存在不是下一个执行的节点 + * + * @param loginUserId 流程发起人 + * @param processInstanceId 流程实例id + * @param nextActivityNodes 下一个执行节点信息 {节点id : [审批人id,审批人id]} + */ + private void checkNextActivityNodes(Long loginUserId, Map variables,String processInstanceId, + Map> nextActivityNodes){ + // 1、查询流程【预测】的全部信息 + BpmApprovalDetailRespVO approvalDetail = processInstanceService.getApprovalDetail(loginUserId, + new BpmApprovalDetailReqVO().setProcessVariables(variables).setProcessInstanceId(processInstanceId)); + // 2、获取预测节点的信息 + List activityNodes = approvalDetail.getActivityNodes(); + if (CollUtil.isNotEmpty(activityNodes)) { + // 2.1、获取节点中的审批人策略为【发起人自选】且状态为【未执行】的节点 + List notStartActivityNodes = activityNodes.stream().filter(node -> + BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy().equals(node.getCandidateStrategy()) + && BpmTaskStatusEnum.NOT_START.getStatus().equals(node.getStatus())).toList(); + // 3、校验传递的参数中是否存在不是下一节点的信息 + for (Map.Entry> nextActivityNode : nextActivityNodes.entrySet()) { + if (notStartActivityNodes.stream().noneMatch(taskNode -> taskNode.getId().equals(nextActivityNode.getKey()))) { + log.error("[checkNextActivityNodes][ ({}) 不是下一个执行的流程节点!]", nextActivityNode.getKey()); + throw exception(TASK_START_USER_SELECT_NODE_NOT_EXISTS, nextActivityNode.getKey()); + } + } + } + } + /** * 审批通过存在“后加签”的任务。 *

From 357f4966d30418128ad6aa501bc96bdf45555e42 Mon Sep 17 00:00:00 2001 From: smallNorthLee <18210040298@163.com> Date: Wed, 26 Feb 2025 22:38:31 +0800 Subject: [PATCH 09/15] =?UTF-8?q?review:=20=E4=BB=A3=E7=A0=81=E5=AE=A1?= =?UTF-8?q?=E6=9F=A5=20=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95=E5=90=8D?= =?UTF-8?q?=E7=A7=B0validateNextAssignees?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/bpm/service/task/BpmTaskServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 44c04fb030..df682c09f9 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -525,7 +525,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); // 校验传递的参数中是否存在不是下一个执行的节点 - checkNextActivityNodes(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); + validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 @@ -550,7 +550,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { * @param processInstanceId 流程实例id * @param nextActivityNodes 下一个执行节点信息 {节点id : [审批人id,审批人id]} */ - private void checkNextActivityNodes(Long loginUserId, Map variables,String processInstanceId, + private void validateNextAssignees(Long loginUserId, Map variables,String processInstanceId, Map> nextActivityNodes){ // 1、查询流程【预测】的全部信息 BpmApprovalDetailRespVO approvalDetail = processInstanceService.getApprovalDetail(loginUserId, @@ -562,7 +562,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { List notStartActivityNodes = activityNodes.stream().filter(node -> BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy().equals(node.getCandidateStrategy()) && BpmTaskStatusEnum.NOT_START.getStatus().equals(node.getStatus())).toList(); - // 3、校验传递的参数中是否存在不是下一节点的信息 + // 3、校验传递的参数中是否存在不是下一个节点的信息 for (Map.Entry> nextActivityNode : nextActivityNodes.entrySet()) { if (notStartActivityNodes.stream().noneMatch(taskNode -> taskNode.getId().equals(nextActivityNode.getKey()))) { log.error("[checkNextActivityNodes][ ({}) 不是下一个执行的流程节点!]", nextActivityNode.getKey()); From b03025746661e637454ed2a70c94e79e4641b9ae Mon Sep 17 00:00:00 2001 From: smallNorthLee <18210040298@163.com> Date: Wed, 26 Feb 2025 23:24:21 +0800 Subject: [PATCH 10/15] =?UTF-8?q?review:=20=E4=BB=A3=E7=A0=81=E5=AE=A1?= =?UTF-8?q?=E6=9F=A5=20=E4=BF=AE=E6=94=B9=E6=96=B9=E6=B3=95=E5=90=8D?= =?UTF-8?q?=E7=A7=B0validateNextAssignees?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/bpm/service/task/BpmTaskServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index df682c09f9..236efb4f48 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -561,7 +561,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { // 2.1、获取节点中的审批人策略为【发起人自选】且状态为【未执行】的节点 List notStartActivityNodes = activityNodes.stream().filter(node -> BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy().equals(node.getCandidateStrategy()) - && BpmTaskStatusEnum.NOT_START.getStatus().equals(node.getStatus())).toList(); + && BpmTaskStatusEnum.NOT_START.getStatus().equals(node.getStatus()) + && CollUtil.isEmpty(node.getCandidateUsers())).toList(); // 3、校验传递的参数中是否存在不是下一个节点的信息 for (Map.Entry> nextActivityNode : nextActivityNodes.entrySet()) { if (notStartActivityNodes.stream().noneMatch(taskNode -> taskNode.getId().equals(nextActivityNode.getKey()))) { From db6d7a74300da30b721b1e2cdaa7de78f2e810af Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Thu, 27 Feb 2025 15:17:30 +0800 Subject: [PATCH 11/15] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0TODO?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/bpm/framework/flowable/core/util/BpmnModelUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java index 49ab5bb35b..b73e0cc98d 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java @@ -778,6 +778,8 @@ public class BpmnModelUtils { if (currentElement instanceof ExclusiveGateway) { // 查找满足条件的 SequenceFlow 路径 Gateway gateway = (Gateway) currentElement; + // TODO @小北:当一个网关节点下存在多个满足的并行节点时,只查询一个节点流程流转会存在问题,需要优化, + // TODO 具体见issue:https://github.com/YunaiV/ruoyi-vue-pro/issues/761 SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) && (evalConditionExpress(variables, flow.getConditionExpression()))); From 6c6992c86a9f64b78e23c622a6f6204cd424e6ef Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Thu, 27 Feb 2025 17:28:22 +0800 Subject: [PATCH 12/15] =?UTF-8?q?feat=EF=BC=9ATODO=20List?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/service/task/BpmTaskServiceImpl.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 236efb4f48..d64a822545 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -525,6 +525,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); // 校验传递的参数中是否存在不是下一个执行的节点 + // 当前执行的流程节点,需根据该节点寻找下一个节点 + String taskDefinitionKey = task.getTaskDefinitionKey(); + List nextFlowNodes = getNextFlowNodes(taskDefinitionKey, bpmnModel, variables); + System.out.println(nextFlowNodes); validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { @@ -543,6 +547,41 @@ public class BpmTaskServiceImpl implements BpmTaskService { handleParentTaskIfSign(task.getParentTaskId()); } + /** + * + * @param taskDefinitionKey 当前节点id + * @param bpmnModel bpmnModel + */ + private List getNextFlowNodes(String taskDefinitionKey, BpmnModel bpmnModel, Map variables){ + FlowNode flowElement = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); + // 存储下一个执行的节点 + List nextFlowNodes = new ArrayList<>(); + resolveNextNodes(flowElement, bpmnModel, variables, nextFlowNodes); + return nextFlowNodes; + } + + private void resolveNextNodes(FlowNode currentNode, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { + List outgoingFlows = currentNode.getOutgoingFlows(); + for (SequenceFlow sequenceFlow : outgoingFlows) { + // 如果是排他网关,需要根据条件表达式判断 + if (currentNode instanceof ExclusiveGateway) { + String conditionExpression = sequenceFlow.getConditionExpression(); + if (conditionExpression != null && !BpmnModelUtils.evalConditionExpress(variables,conditionExpression)) { + continue; + } + } + FlowElement targetElement = bpmnModel.getFlowElement(sequenceFlow.getTargetRef()); + if (targetElement instanceof FlowNode targetNode) { + if (targetNode instanceof Gateway) { + // 如果目标节点还是网关,递归处理 + resolveNextNodes(targetNode, bpmnModel, variables, nextFlowNodes); + } else { + nextFlowNodes.add(targetNode); + } + } + } + } + /** * 校验传递的参数中是否存在不是下一个执行的节点 * @@ -559,6 +598,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { List activityNodes = approvalDetail.getActivityNodes(); if (CollUtil.isNotEmpty(activityNodes)) { // 2.1、获取节点中的审批人策略为【发起人自选】且状态为【未执行】的节点 + // TODO 获取下一个执行节点 List notStartActivityNodes = activityNodes.stream().filter(node -> BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy().equals(node.getCandidateStrategy()) && BpmTaskStatusEnum.NOT_START.getStatus().equals(node.getStatus()) From 093e563b80ef8c34ccc6fb88e1d3e54502bd8a70 Mon Sep 17 00:00:00 2001 From: smallNorthLee <18210040298@163.com> Date: Thu, 27 Feb 2025 23:33:16 +0800 Subject: [PATCH 13/15] feat: add TODO --- .../bpm/service/task/BpmTaskServiceImpl.java | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index d64a822545..04842ea51d 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -529,7 +529,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { String taskDefinitionKey = task.getTaskDefinitionKey(); List nextFlowNodes = getNextFlowNodes(taskDefinitionKey, bpmnModel, variables); System.out.println(nextFlowNodes); - validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); +// validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 @@ -548,40 +548,66 @@ public class BpmTaskServiceImpl implements BpmTaskService { } /** - * - * @param taskDefinitionKey 当前节点id - * @param bpmnModel bpmnModel + * 根据当前节点 ID 获取下一个执行的 FlowNode 列表 + * @param taskDefinitionKey 当前节点 ID + * @param bpmnModel BPMN 模型 + * @param variables 流程变量,用于条件判断 + * @return 下一个执行的 FlowNode 列表 */ - private List getNextFlowNodes(String taskDefinitionKey, BpmnModel bpmnModel, Map variables){ - FlowNode flowElement = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); - // 存储下一个执行的节点 + public List getNextFlowNodes(String taskDefinitionKey, BpmnModel bpmnModel, Map variables) { + if (taskDefinitionKey == null || bpmnModel == null) { + throw new IllegalArgumentException("taskDefinitionKey and bpmnModel cannot be null"); + } + FlowNode currentNode = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); + if (currentNode == null) { + throw new IllegalArgumentException("FlowElement with given taskDefinitionKey not found in BpmnModel"); + } List nextFlowNodes = new ArrayList<>(); - resolveNextNodes(flowElement, bpmnModel, variables, nextFlowNodes); + resolveNextNodes(currentNode, bpmnModel, variables, nextFlowNodes); return nextFlowNodes; } + /** + * 递归解析下一个执行节点 + * @param currentNode 当前节点 + * @param bpmnModel BPMN 模型 + * @param variables 流程变量,用于条件判断 + * @param nextFlowNodes 存储下一个执行节点的列表 + */ private void resolveNextNodes(FlowNode currentNode, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { List outgoingFlows = currentNode.getOutgoingFlows(); for (SequenceFlow sequenceFlow : outgoingFlows) { - // 如果是排他网关,需要根据条件表达式判断 - if (currentNode instanceof ExclusiveGateway) { - String conditionExpression = sequenceFlow.getConditionExpression(); - if (conditionExpression != null && !BpmnModelUtils.evalConditionExpress(variables,conditionExpression)) { - continue; - } + if (!shouldFollowSequenceFlow(currentNode, sequenceFlow, variables)) { + continue; } FlowElement targetElement = bpmnModel.getFlowElement(sequenceFlow.getTargetRef()); if (targetElement instanceof FlowNode targetNode) { if (targetNode instanceof Gateway) { - // 如果目标节点还是网关,递归处理 + // 如果目标节点是网关,递归处理 resolveNextNodes(targetNode, bpmnModel, variables, nextFlowNodes); - } else { + }else { nextFlowNodes.add(targetNode); } } } } + /** + * 判断是否应该遵循当前序列流 + * @param currentNode 当前节点 + * @param sequenceFlow 序列流 + * @param variables 流程变量,用于条件判断 + * @return 是否应该遵循该序列流 + */ + private boolean shouldFollowSequenceFlow(FlowNode currentNode, SequenceFlow sequenceFlow, Map variables) { + if (currentNode instanceof ExclusiveGateway) { + String conditionExpression = sequenceFlow.getConditionExpression(); + return conditionExpression == null || BpmnModelUtils.evalConditionExpress(variables, conditionExpression); + } + return true; + } + + /** * 校验传递的参数中是否存在不是下一个执行的节点 * From deef88f56fc4dd1235f24a10c11e1991be73a034 Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Fri, 28 Feb 2025 17:10:59 +0800 Subject: [PATCH 14/15] =?UTF-8?q?feat=EF=BC=9A=E5=AE=A1=E6=89=B9=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=97=B6=EF=BC=8C=E6=A0=A1=E9=AA=8C=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E4=B8=8B=E4=B8=80=E4=B8=AA=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/core/util/BpmnModelUtils.java | 119 ++++++++++++++++ .../bpm/service/task/BpmTaskServiceImpl.java | 133 ++++++------------ 2 files changed, 161 insertions(+), 91 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java index b73e0cc98d..7873681318 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java @@ -828,6 +828,125 @@ public class BpmnModelUtils { } } + /** + * 根据当前节点,获取下一个节点 + * + * @param currentElement 当前节点 + * @param bpmnModel BPMN模型 + * @param variables 流程变量 + */ + public static List getNextFlowNodes(FlowElement currentElement, BpmnModel bpmnModel, + Map variables){ + // 下一个执行的流程节点集合 + List nextFlowNodes = new ArrayList<>(); + // 当前执行节点的基本属性 + FlowNode currentNode = (FlowNode) currentElement; + // 获取当前节点的关联节点 + List outgoingFlows = currentNode.getOutgoingFlows(); + if (CollUtil.isEmpty(outgoingFlows)){ + log.warn("[getNextFlowNodes][当前节点({}) 的 outgoingFlows 为空]", currentNode.getId()); + return nextFlowNodes; + } + // 遍历每个出口流 + for (SequenceFlow outgoingFlow : outgoingFlows) { + // 获取目标节点的基本属性 + FlowElement targetElement = bpmnModel.getFlowElement(outgoingFlow.getTargetRef()); + if (targetElement == null){ + continue; + } + if (targetElement instanceof Gateway gateway) { + // 处理不同类型的网关 + if (gateway instanceof ExclusiveGateway) { + handleExclusiveGateway(gateway, bpmnModel, variables, nextFlowNodes); + } else if (gateway instanceof InclusiveGateway) { + handleInclusiveGateway(gateway, bpmnModel, variables, nextFlowNodes); + } else if (gateway instanceof ParallelGateway) { + handleParallelGateway(gateway, bpmnModel, variables, nextFlowNodes); + } + } else { + // 如果不是网关,直接添加到下一个节点列表 + nextFlowNodes.add((FlowNode) targetElement); + } + } + return nextFlowNodes; + } + + /** + * 处理排他网关 + * + * @param gateway 排他网关 + * @param bpmnModel BPMN模型 + * @param variables 流程变量 + * @param nextFlowNodes 下一个执行的流程节点集合 + */ + private static void handleExclusiveGateway(Gateway gateway, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { + // TODO @小北: 这里findOne和simulateNextFlowElements中有重复代码,需要优化,@芋道:是否重构?? + SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), + flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) + && (evalConditionExpress(variables, flow.getConditionExpression()))); + if (matchSequenceFlow == null) { + matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), + flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); + // 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的 + if (matchSequenceFlow == null && gateway.getOutgoingFlows().size() == 1) { + matchSequenceFlow = gateway.getOutgoingFlows().get(0); + } + } + // 遍历满足条件的 SequenceFlow 路径 + if (matchSequenceFlow != null) { + FlowElement targetElement = bpmnModel.getFlowElement(matchSequenceFlow.getTargetRef()); + if (targetElement instanceof FlowNode) { + nextFlowNodes.add((FlowNode) targetElement); + } + } + } + + /** + * 处理包容网关 + * + * @param gateway 排他网关 + * @param bpmnModel BPMN模型 + * @param variables 流程变量 + * @param nextFlowNodes 下一个执行的流程节点集合 + */ + private static void handleInclusiveGateway(Gateway gateway, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { + Collection matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(), + flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) + && evalConditionExpress(variables, flow.getConditionExpression())); + if (CollUtil.isEmpty(matchSequenceFlows)) { + matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(), + flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); + // 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的 + if (CollUtil.isEmpty(matchSequenceFlows) && gateway.getOutgoingFlows().size() == 1) { + matchSequenceFlows = gateway.getOutgoingFlows(); + } + } + // 遍历满足条件的 SequenceFlow 路径,获取目标节点 + matchSequenceFlows.forEach(flow -> { + FlowElement targetElement = bpmnModel.getFlowElement(flow.getTargetRef()); + if (targetElement instanceof FlowNode) { + nextFlowNodes.add((FlowNode) targetElement); + } + }); + } + /** + * 处理并行网关 + * + * @param gateway 排他网关 + * @param bpmnModel BPMN模型 + * @param variables 流程变量 + * @param nextFlowNodes 下一个执行的流程节点集合 + */ + private static void handleParallelGateway(Gateway gateway, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { + // 并行网关,遍历所有出口路径,获取目标节点 + gateway.getOutgoingFlows().forEach(flow -> { + FlowElement targetElement = bpmnModel.getFlowElement(flow.getTargetRef()); + if (targetElement instanceof FlowNode) { + nextFlowNodes.add((FlowNode) targetElement); + } + }); + } + /** * 计算条件表达式是否为 true 满足条件 * diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 04842ea51d..1a00f38617 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -23,6 +23,7 @@ import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskSignTypeEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum; +import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils; @@ -522,14 +523,10 @@ public class BpmTaskServiceImpl implements BpmTaskService { BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason())); // 2.3 调用 BPM complete 去完成任务 // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 - if (CollUtil.isNotEmpty(reqVO.getVariables())) { +// if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); // 校验传递的参数中是否存在不是下一个执行的节点 - // 当前执行的流程节点,需根据该节点寻找下一个节点 - String taskDefinitionKey = task.getTaskDefinitionKey(); - List nextFlowNodes = getNextFlowNodes(taskDefinitionKey, bpmnModel, variables); - System.out.println(nextFlowNodes); -// validateNextAssignees(userId, reqVO.getVariables(), task.getProcessInstanceId(), reqVO.getNextAssignees()); + validateNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(), bpmnModel, reqVO.getNextAssignees(), instance); // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { // 获取实例中的全部节点数据,避免后续节点的审批人被覆盖 @@ -539,104 +536,58 @@ public class BpmTaskServiceImpl implements BpmTaskService { } runtimeService.setVariables(task.getProcessInstanceId(), variables); taskService.complete(task.getId(), variables, true); - } else { - taskService.complete(task.getId()); - } +// } else { +// taskService.complete(task.getId()); +// } // 【加签专属】处理加签任务 handleParentTaskIfSign(task.getParentTaskId()); } - /** - * 根据当前节点 ID 获取下一个执行的 FlowNode 列表 - * @param taskDefinitionKey 当前节点 ID - * @param bpmnModel BPMN 模型 - * @param variables 流程变量,用于条件判断 - * @return 下一个执行的 FlowNode 列表 - */ - public List getNextFlowNodes(String taskDefinitionKey, BpmnModel bpmnModel, Map variables) { - if (taskDefinitionKey == null || bpmnModel == null) { - throw new IllegalArgumentException("taskDefinitionKey and bpmnModel cannot be null"); - } - FlowNode currentNode = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); - if (currentNode == null) { - throw new IllegalArgumentException("FlowElement with given taskDefinitionKey not found in BpmnModel"); - } - List nextFlowNodes = new ArrayList<>(); - resolveNextNodes(currentNode, bpmnModel, variables, nextFlowNodes); - return nextFlowNodes; - } - - /** - * 递归解析下一个执行节点 - * @param currentNode 当前节点 - * @param bpmnModel BPMN 模型 - * @param variables 流程变量,用于条件判断 - * @param nextFlowNodes 存储下一个执行节点的列表 - */ - private void resolveNextNodes(FlowNode currentNode, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { - List outgoingFlows = currentNode.getOutgoingFlows(); - for (SequenceFlow sequenceFlow : outgoingFlows) { - if (!shouldFollowSequenceFlow(currentNode, sequenceFlow, variables)) { - continue; - } - FlowElement targetElement = bpmnModel.getFlowElement(sequenceFlow.getTargetRef()); - if (targetElement instanceof FlowNode targetNode) { - if (targetNode instanceof Gateway) { - // 如果目标节点是网关,递归处理 - resolveNextNodes(targetNode, bpmnModel, variables, nextFlowNodes); - }else { - nextFlowNodes.add(targetNode); - } - } - } - } - - /** - * 判断是否应该遵循当前序列流 - * @param currentNode 当前节点 - * @param sequenceFlow 序列流 - * @param variables 流程变量,用于条件判断 - * @return 是否应该遵循该序列流 - */ - private boolean shouldFollowSequenceFlow(FlowNode currentNode, SequenceFlow sequenceFlow, Map variables) { - if (currentNode instanceof ExclusiveGateway) { - String conditionExpression = sequenceFlow.getConditionExpression(); - return conditionExpression == null || BpmnModelUtils.evalConditionExpress(variables, conditionExpression); - } - return true; - } - /** * 校验传递的参数中是否存在不是下一个执行的节点 * - * @param loginUserId 流程发起人 - * @param processInstanceId 流程实例id - * @param nextActivityNodes 下一个执行节点信息 {节点id : [审批人id,审批人id]} + * @param taskDefinitionKey 当前任务节点id + * @param variables 流程变量 + * @param bpmnModel 流程模型 + * @param nextActivityNodes 下一个节点审批人集合(参数) */ - private void validateNextAssignees(Long loginUserId, Map variables,String processInstanceId, - Map> nextActivityNodes){ - // 1、查询流程【预测】的全部信息 - BpmApprovalDetailRespVO approvalDetail = processInstanceService.getApprovalDetail(loginUserId, - new BpmApprovalDetailReqVO().setProcessVariables(variables).setProcessInstanceId(processInstanceId)); - // 2、获取预测节点的信息 - List activityNodes = approvalDetail.getActivityNodes(); - if (CollUtil.isNotEmpty(activityNodes)) { - // 2.1、获取节点中的审批人策略为【发起人自选】且状态为【未执行】的节点 - // TODO 获取下一个执行节点 - List notStartActivityNodes = activityNodes.stream().filter(node -> - BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy().equals(node.getCandidateStrategy()) - && BpmTaskStatusEnum.NOT_START.getStatus().equals(node.getStatus()) - && CollUtil.isEmpty(node.getCandidateUsers())).toList(); - // 3、校验传递的参数中是否存在不是下一个节点的信息 - for (Map.Entry> nextActivityNode : nextActivityNodes.entrySet()) { - if (notStartActivityNodes.stream().noneMatch(taskNode -> taskNode.getId().equals(nextActivityNode.getKey()))) { - log.error("[checkNextActivityNodes][ ({}) 不是下一个执行的流程节点!]", nextActivityNode.getKey()); - throw exception(TASK_START_USER_SELECT_NODE_NOT_EXISTS, nextActivityNode.getKey()); + private void validateNextAssignees(String taskDefinitionKey, Map variables, BpmnModel bpmnModel, + Map> nextActivityNodes,ProcessInstance processInstance){ + + // 1、获取当前任务节点的信息 + FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey); + // 2、获取下一个应该执行的节点集合 + List nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables); + // 3、比较前端传递的节点和预测的下一个节点是否匹配,匹配则将该节点设置上审批人 + for (FlowNode nextFlowNode : nextFlowNodes) { + // 获取下一个执行节点的属性 是否为 发起人自选 + Map> extensionElements = nextFlowNode.getExtensionElements(); + List elements = extensionElements.get(BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY); + if (CollUtil.isEmpty(elements)){ + continue; + } + // 获取节点中的审批人策略 + Integer candidateStrategy = Integer.valueOf(elements.get(0).getElementText()); + // 获取流程实例中的发起人自选审批人 + Map> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); + List startUserSelectAssignee = startUserSelectAssignees.get(nextFlowNode.getId()); + if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy()) && CollUtil.isEmpty(startUserSelectAssignee)) { + // 先判断节点是否存在 + if (!nextActivityNodes.containsKey(nextFlowNode.getId())){ + throw exception(TASK_TARGET_NODE_NOT_EXISTS, nextFlowNode.getName()); + } + // 如果节点存在,则判断节点中的审批人策略是否为 发起人自选 + List nextAssignees = nextActivityNodes.get(nextFlowNode.getId()); + // 3.1、如果前端传递的节点为空,则抛出异常 + if (CollUtil.isEmpty(nextAssignees)) { + throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName()); } } + } + } /** From ff555b51366c1e0df4a571f59a3cef4f812546fb Mon Sep 17 00:00:00 2001 From: smallNorthLee <18210040298@163.com> Date: Fri, 28 Feb 2025 22:37:57 +0800 Subject: [PATCH 15/15] =?UTF-8?q?feat:=20=E5=AE=A1=E6=89=B9=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=97=B6=EF=BC=8C=E6=A0=A1=E9=AA=8C=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E4=B8=8B=E4=B8=80=E4=B8=AA=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/core/util/BpmnModelUtils.java | 2 +- .../bpm/service/task/BpmTaskServiceImpl.java | 32 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java index 7873681318..fff0ac5317 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java @@ -880,7 +880,7 @@ public class BpmnModelUtils { * @param nextFlowNodes 下一个执行的流程节点集合 */ private static void handleExclusiveGateway(Gateway gateway, BpmnModel bpmnModel, Map variables, List nextFlowNodes) { - // TODO @小北: 这里findOne和simulateNextFlowElements中有重复代码,需要优化,@芋道:是否重构?? + // TODO @小北: 这里和simulateNextFlowElements中有重复代码,是否重构??每个网关节点拆分出方法应该比较合理化,@芋道 SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) && (evalConditionExpress(variables, flow.getConditionExpression()))); diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 1a00f38617..bcc70da867 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -523,9 +523,9 @@ public class BpmTaskServiceImpl implements BpmTaskService { BpmCommentTypeEnum.APPROVE.formatComment(reqVO.getReason())); // 2.3 调用 BPM complete 去完成任务 // 其中,variables 是存储动态表单到 local 任务级别。过滤一下,避免 ProcessInstance 系统级的变量被占用 -// if (CollUtil.isNotEmpty(reqVO.getVariables())) { + if (CollUtil.isNotEmpty(reqVO.getVariables())) { Map variables = FlowableUtils.filterTaskFormVariable(reqVO.getVariables()); - // 校验传递的参数中是否存在不是下一个执行的节点 + // 校验传递的参数中是否为下一个将要执行的任务节点 validateNextAssignees(task.getTaskDefinitionKey(), reqVO.getVariables(), bpmnModel, reqVO.getNextAssignees(), instance); // 下个节点审批人如果不存在,则由前端传递 if (CollUtil.isNotEmpty(reqVO.getNextAssignees())) { @@ -536,9 +536,9 @@ public class BpmTaskServiceImpl implements BpmTaskService { } runtimeService.setVariables(task.getProcessInstanceId(), variables); taskService.complete(task.getId(), variables, true); -// } else { -// taskService.complete(task.getId()); -// } + } else { + taskService.complete(task.getId()); + } // 【加签专属】处理加签任务 handleParentTaskIfSign(task.getParentTaskId()); @@ -546,7 +546,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { /** - * 校验传递的参数中是否存在不是下一个执行的节点 + * 校验传递的参数中是否为下一个将要执行的任务节点 * * @param taskDefinitionKey 当前任务节点id * @param variables 流程变量 @@ -555,39 +555,37 @@ public class BpmTaskServiceImpl implements BpmTaskService { */ private void validateNextAssignees(String taskDefinitionKey, Map variables, BpmnModel bpmnModel, Map> nextActivityNodes,ProcessInstance processInstance){ - // 1、获取当前任务节点的信息 FlowElement flowElement = bpmnModel.getFlowElement(taskDefinitionKey); - // 2、获取下一个应该执行的节点集合 + // 2、获取下一个将要执行的节点集合 List nextFlowNodes = getNextFlowNodes(flowElement, bpmnModel, variables); - // 3、比较前端传递的节点和预测的下一个节点是否匹配,匹配则将该节点设置上审批人 + // 3、循环下一个将要执行的节点集合 for (FlowNode nextFlowNode : nextFlowNodes) { - // 获取下一个执行节点的属性 是否为 发起人自选 + // 3.1、获取下一个将要执行节点的属性(是否为自选审批人等) Map> extensionElements = nextFlowNode.getExtensionElements(); List elements = extensionElements.get(BpmnModelConstants.USER_TASK_CANDIDATE_STRATEGY); if (CollUtil.isEmpty(elements)){ continue; } - // 获取节点中的审批人策略 + // 3.2、获取节点中的审批人策略 Integer candidateStrategy = Integer.valueOf(elements.get(0).getElementText()); - // 获取流程实例中的发起人自选审批人 + // 3.3、获取流程实例中的发起人自选审批人 Map> startUserSelectAssignees = FlowableUtils.getStartUserSelectAssignees(processInstance.getProcessVariables()); List startUserSelectAssignee = startUserSelectAssignees.get(nextFlowNode.getId()); + // 3.4、如果节点中的审批人策略为 发起人自选,并且该节点的审批人为空 if (ObjUtil.equals(candidateStrategy, BpmTaskCandidateStrategyEnum.START_USER_SELECT.getStrategy()) && CollUtil.isEmpty(startUserSelectAssignee)) { - // 先判断节点是否存在 + // 先判断前端传递的参数节点节点是否为将要执行的节点 if (!nextActivityNodes.containsKey(nextFlowNode.getId())){ throw exception(TASK_TARGET_NODE_NOT_EXISTS, nextFlowNode.getName()); } - // 如果节点存在,则判断节点中的审批人策略是否为 发起人自选 + // 如果节点存在,则获取节点中的审批人 List nextAssignees = nextActivityNodes.get(nextFlowNode.getId()); - // 3.1、如果前端传递的节点为空,则抛出异常 + // 如果前端传递的节点为空,则抛出异常 if (CollUtil.isEmpty(nextAssignees)) { throw exception(PROCESS_INSTANCE_START_USER_SELECT_ASSIGNEES_NOT_CONFIG, nextFlowNode.getName()); } } - } - } /**