From 321564177399931273e63647f37cdddd268fa5a5 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 08 十一月 2026 21:50:35 +0800
Subject: [PATCH] fix: 修复全流程测试 P0/P1 问题

---
 yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvoker.java |   42 +++++++++++++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvoker.java b/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvoker.java
index cf9f1b3..8bea654 100644
--- a/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvoker.java
+++ b/yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/BpmTaskCandidateInvoker.java
@@ -26,11 +26,12 @@
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.MODEL_DEPLOY_FAIL_TASK_CANDIDATE_NOT_CONFIG;
+import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.START_USER_NODE_ID;
 
 /**
  * {@link BpmTaskCandidateStrategy} 鐨勮皟鐢ㄨ�咃紝鐢ㄤ簬璋冪敤瀵瑰簲鐨勭瓥鐣ワ紝瀹炵幇浠诲姟鐨勫�欓�変汉鐨勮绠�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Slf4j
 public class BpmTaskCandidateInvoker {
@@ -106,8 +107,13 @@
             Integer strategy = BpmnModelUtils.parseCandidateStrategy(flowElement);
             String param = BpmnModelUtils.parseCandidateParam(flowElement);
             Set<Long> userIds = getCandidateStrategy(strategy).calculateUsersByTask(execution, param);
-            // 1.2 绉婚櫎琚鐢ㄧ殑鐢ㄦ埛
-            removeDisableUsers(userIds);
+            ProcessInstance processInstance = SpringUtil.getBean(BpmProcessInstanceService.class)
+                    .getProcessInstance(execution.getProcessInstanceId());
+            Assert.notNull(processInstance, "娴佺▼瀹炰緥({}) 涓嶅瓨鍦�", execution.getProcessInstanceId());
+            Long startUserId = Long.valueOf(processInstance.getStartUserId());
+            // 1.2 绉婚櫎琚鐢ㄧ殑鐢ㄦ埛锛涘彂璧蜂汉鑺傜偣蹇呴』淇濈暀鍙戣捣浜猴紝
+            //     鍚﹀垯鍙戣捣浜鸿处鍙疯绂佺敤鏃惰鑺傜偣鏃犱汉鍙锛屾祦绋嬩細涓�鐩村仠鍦ㄣ�屽彂璧蜂汉銆嶈妭鐐�
+            removeDisableUsers(userIds, isStartUserNode(flowElement) ? startUserId : null);
 
             // 2. 鍊欓�変汉涓虹┖鏃讹紝鏍规嵁鈥滃鎵逛汉涓虹┖鈥濈殑閰嶇疆琛ュ厖
             if (CollUtil.isEmpty(userIds)) {
@@ -117,10 +123,7 @@
             }
 
             // 3. 绉婚櫎鍙戣捣浜虹殑鐢ㄦ埛
-            ProcessInstance processInstance = SpringUtil.getBean(BpmProcessInstanceService.class)
-                    .getProcessInstance(execution.getProcessInstanceId());
-            Assert.notNull(processInstance, "娴佺▼瀹炰緥({}) 涓嶅瓨鍦�", execution.getProcessInstanceId());
-            removeStartUserIfSkip(userIds, flowElement, Long.valueOf(processInstance.getStartUserId()));
+            removeStartUserIfSkip(userIds, flowElement, startUserId);
             return userIds;
         });
     }
@@ -146,8 +149,8 @@
         String param = BpmnModelUtils.parseCandidateParam(flowElement);
         Set<Long> userIds = getCandidateStrategy(strategy).calculateUsersByActivity(bpmnModel, activityId, param,
                 startUserId, processDefinitionId, processVariables);
-        // 1.2 绉婚櫎琚鐢ㄧ殑鐢ㄦ埛
-        removeDisableUsers(userIds);
+        // 1.2 绉婚櫎琚鐢ㄧ殑鐢ㄦ埛锛涘彂璧蜂汉鑺傜偣蹇呴』淇濈暀鍙戣捣浜猴紝閬垮厤鍙戣捣浜虹鐢ㄥ悗娴佺▼鍋滃湪銆屽彂璧蜂汉銆嶈妭鐐�
+        removeDisableUsers(userIds, START_USER_NODE_ID.equals(activityId) ? startUserId : null);
 
         // 2. 鍊欓�変汉涓虹┖鏃讹紝鏍规嵁鈥滃鎵逛汉涓虹┖鈥濈殑閰嶇疆琛ュ厖
         if (CollUtil.isEmpty(userIds)) {
@@ -163,17 +166,38 @@
 
     @VisibleForTesting
     void removeDisableUsers(Set<Long> assigneeUserIds) {
+        removeDisableUsers(assigneeUserIds, null);
+    }
+
+    /**
+     * 绉婚櫎琚鐢ㄧ殑鐢ㄦ埛
+     *
+     * @param assigneeUserIds 鍊欓�変汉
+     * @param keepUserId      闇�瑕佷繚鐣欑殑鐢ㄦ埛锛堝彂璧蜂汉鑺傜偣淇濈暀鍙戣捣浜猴級锛屽彲涓虹┖
+     */
+    @VisibleForTesting
+    void removeDisableUsers(Set<Long> assigneeUserIds, Long keepUserId) {
         if (CollUtil.isEmpty(assigneeUserIds)) {
             return;
         }
         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(assigneeUserIds);
         assigneeUserIds.removeIf(id -> {
+            if (ObjectUtil.equal(id, keepUserId)) {
+                return false;
+            }
             AdminUserRespDTO user = userMap.get(id);
             return user == null || CommonStatusEnum.isDisable(user.getStatus());
         });
     }
 
     /**
+     * 鏄惁涓恒�屽彂璧蜂汉銆嶈妭鐐�
+     */
+    private static boolean isStartUserNode(FlowElement flowElement) {
+        return flowElement != null && START_USER_NODE_ID.equals(flowElement.getId());
+    }
+
+    /**
      * 濡傛灉鈥滃鎵逛汉涓庡彂璧蜂汉鐩稿悓鏃垛�濓紝閰嶇疆浜� SKIP 璺宠繃锛屽垯绉婚櫎鍙戣捣浜�
      *
      * 娉ㄦ剰锛氬鏋滃彧鏈変竴涓�欓�変汉锛屽垯涓嶅鐞嗭紝閬垮厤鏃犳硶瀹℃壒

--
Gitblit v1.9.3