From 82d230ccfb5a13bce6113a27c0e6806c865bc213 Mon Sep 17 00:00:00 2001 From: canonical Date: Sat, 19 Oct 2024 20:31:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4IWorkflowExecutor=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/nop/wf/core/IWorkflowStep.java | 7 ++++++- .../main/java/io/nop/wf/core/NopWfCoreConstants.java | 2 +- .../nop/wf/core/engine/DefaultWorkflowExecutor.java | 7 ++++--- .../main/java/io/nop/wf/core/engine/IWfRuntime.java | 5 ++++- .../io/nop/wf/core/engine/IWorkflowExecutor.java | 2 +- .../io/nop/wf/core/engine/WorkflowEngineImpl.java | 2 +- .../wf/core/service/impl/WorkflowServiceImpl.java | 12 ++++++------ 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/IWorkflowStep.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/IWorkflowStep.java index 2676c895b..d16311688 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/IWorkflowStep.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/IWorkflowStep.java @@ -135,6 +135,11 @@ default boolean isFlowType() { void markRead(IServiceContext ctx); + /** + * 调用 + * @param args + * @param ctx + */ void kill(Map args, IServiceContext ctx); /** @@ -185,7 +190,7 @@ default boolean isFlowType() { void transitTo(String stepName, Map args, IServiceContext ctx); /** - * 如果本步骤尚未结束,则先结束本步骤。如果本步骤已结束,则直接增加目标步骤实例 + * 如果本步骤尚未结束,则结束本步骤,设置状态为指定status */ void exitStep(int status, Map args, IServiceContext ctx); diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/NopWfCoreConstants.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/NopWfCoreConstants.java index 7b06720d4..2e21da06a 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/NopWfCoreConstants.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/NopWfCoreConstants.java @@ -42,7 +42,7 @@ public interface NopWfCoreConstants extends _NopWfCoreConstants { String INTERNAL_ACTION_TRANSFER_TO_ACTOR = "_transferToActor_"; String INTERNAL_ACTION_TRANSIT = "_transit_"; - String INTERNAL_ACTION_TRANSFER_TO_STEP = "_transferToStep_"; + String INTERNAL_ACTION_TRANSIT_TO = "_transitTo_"; String VAR_ACTORS = "actors"; String VAR_REJECT_STEPS = "rejectSteps"; // reject action的参数 diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/DefaultWorkflowExecutor.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/DefaultWorkflowExecutor.java index 9712d2b28..df7dd9c96 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/DefaultWorkflowExecutor.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/DefaultWorkflowExecutor.java @@ -7,6 +7,7 @@ */ package io.nop.wf.core.engine; +import io.nop.api.core.util.FutureHelper; import io.nop.commons.util.StringHelper; import io.nop.core.context.IServiceContext; import io.nop.wf.api.WfReference; @@ -28,7 +29,7 @@ public void setWorkflowManager(IWorkflowManager workflowManager) { @Override public CompletionStage execute(WfReference wfRef, IServiceContext ctx, - Function> task) { + Function task) { IWorkflow wf; if (StringHelper.isEmpty(wfRef.getWfId())) { @@ -37,11 +38,11 @@ public CompletionStage execute(WfReference wfRef, IServiceContext ctx, wf = workflowManager.newWorkflow(wfRef.getWfName(), wfRef.getWfVersion()); } - CompletionStage ret = task.apply(wf); + T ret = task.apply(wf); // 触发步骤的自动转换 while (wf.runAutoTransitions(ctx)) ; - return ret; + return FutureHelper.toCompletionStage(ret); } } diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWfRuntime.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWfRuntime.java index a386d267e..236139eaf 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWfRuntime.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWfRuntime.java @@ -22,6 +22,9 @@ import java.util.Map; import java.util.Set; +/** + * 单次action调用所对应的上下文对象 + */ public interface IWfRuntime extends IEvalContext { void delayExecute(Runnable command); @@ -65,7 +68,7 @@ default IWfActor getStarter() { return getWf().getStarter(); } - default String getStarterId(){ + default String getStarterId() { return getWf().getRecord().getStarterId(); } diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWorkflowExecutor.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWorkflowExecutor.java index d32d5e002..6b004f01c 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWorkflowExecutor.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/IWorkflowExecutor.java @@ -19,5 +19,5 @@ */ public interface IWorkflowExecutor { CompletionStage execute(WfReference wfRef, IServiceContext ctx, - Function> task); + Function task); } \ No newline at end of file diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/WorkflowEngineImpl.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/WorkflowEngineImpl.java index 99c5c9b3f..ae8cb5a29 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/WorkflowEngineImpl.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/engine/WorkflowEngineImpl.java @@ -1627,7 +1627,7 @@ public void transitTo(IWorkflowStepImplementor step, String stepName, WfAssignmentModel assignment = stepModel.getAssignment(); List actors = getActors(assignment, stepName, wfRt); - if (!this.newSteps(step, stepModel, NopWfCoreConstants.INTERNAL_ACTION_TRANSFER_TO_STEP, actors, wfRt)) + if (!this.newSteps(step, stepModel, NopWfCoreConstants.INTERNAL_ACTION_TRANSIT_TO, actors, wfRt)) throw wfRt.newError(ERR_WF_TRANSIT_TO_NO_TARGETS) .param(ARG_TO_STEP_NAME, step.getStepName()); } diff --git a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/service/impl/WorkflowServiceImpl.java b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/service/impl/WorkflowServiceImpl.java index 9283c3a6c..1faf5ec74 100644 --- a/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/service/impl/WorkflowServiceImpl.java +++ b/nop-wf/nop-wf-core/src/main/java/io/nop/wf/core/service/impl/WorkflowServiceImpl.java @@ -61,7 +61,7 @@ public CompletionStage startWorkflowAsync(@RequestBean WfSt res.setManagerDeptId(manager.getDeptId()); res.setManagerName(manager.getActorName()); } - return FutureHelper.toCompletionStage(res); + return res; }); } @@ -77,7 +77,7 @@ public CompletionStage notifySubFlowEndAsync(@RequestBean WfSubFlowEndRequ return workflowExecutor.execute(parentWfRef, ctx, parentWf -> { IWorkflowStep parentStep = parentWf.getStepById(request.getParentWfStepId()); parentStep.notifySubFlowEnd(request.getStatus(), request.getResults(), ctx); - return FutureHelper.success(null); + return null; }); } @@ -92,7 +92,7 @@ public CompletionStage invokeActionAsync( return workflowExecutor.execute(wfRef, ctx, wf -> { IWorkflowStep step = wf.getStepById(request.getStepId()); Object result = step.invokeAction(request.getActionName(), request.getArgs(), ctx); - return FutureHelper.toCompletionStage(result); + return result; }); } @@ -104,7 +104,7 @@ public CompletionStage killWorkflowAsync(@RequestBean WfCommandRequestBean checkMandatory(wfRef, false); return workflowExecutor.execute(wfRef, ctx, wf -> { wf.kill(request.getArgs(), ctx); - return FutureHelper.success(null); + return null; }); } @@ -116,7 +116,7 @@ public CompletionStage suspendWorkflowAsync(@RequestBean WfCommandRequestB checkMandatory(wfRef, true); return workflowExecutor.execute(wfRef, ctx, wf -> { wf.suspend(request.getArgs(), ctx); - return FutureHelper.success(null); + return null; }); } @@ -128,7 +128,7 @@ public CompletionStage resumeWorkflowAsync(@RequestBean WfCommandRequestBe checkMandatory(wfRef, true); return workflowExecutor.execute(wfRef, ctx, wf -> { wf.resume(request.getArgs(), ctx); - return FutureHelper.success(null); + return null; }); }