diff --git a/docs/Integration/extension-points.md b/docs/Integration/extension-points.md index 7d669f2f..b859af94 100644 --- a/docs/Integration/extension-points.md +++ b/docs/Integration/extension-points.md @@ -145,7 +145,7 @@ IFlowAction#run | 类 | 用途 | |---|---| -| `NodeStrategyManager` | 节点全部策略的门面:`loadOperators(session)`、`getMaxOperatorCount()`、`getOperatorSelectType()`、`generateTitle(session)`、`errorTrigger(session)`、`getFieldPermissions()`、`isAdviceRequired()` 等 | +| `NodeStrategyManager` | 节点全部策略的门面:`loadOperators(session)`、`getMaxOperatorCount()`、`getOperatorSelectType()`、`generateTitle(session)`、`errorTrigger(session)`(返回 `ErrorThrow`,含 `NODE` / `OPERATORS` / `PROMPT` 三种处理方式)、`getFieldPermissions()`、`isAdviceRequired()` 等 | | `ActionManager` | 动作管理:`filterActions(session)`、`getActionById(id)`、`getActionByType(type)`、`verifySession(session)` | | `OperatorManager` | 操作人集合:`isEmpty()`、`match(operator)`、`getOperator(userId)` | | `WorkflowStrategyManager` | 流程策略:`isEnableInterfere()`、`verifyOperator` | @@ -157,7 +157,7 @@ IFlowAction#run | 子类 | 典型工厂方法与错误场景 | |---|---| -| `FlowValidationException` | `fieldReadOnly`(字段只读)、`operatorCountExceeded(nodeId, max)`(超出最大可选人数)、`operatorOutOfRange`(超出可选范围)、`required` 等 | +| `FlowValidationException` | `fieldReadOnly`(字段只读)、`operatorCountExceeded(nodeId, max)`(超出最大可选人数)、`operatorOutOfRange`(超出可选范围)、`nextNodeOperatorEmpty(nodeId, nodeName, message)`(下一节点无审批人且配置为异常提示,issue #296)、`required` 等 | | `FlowExecutionException` | `scriptExecutionError`、`routerNodeNotFound`、`operatorCountExceeded`、`invalidJumpTarget(nodeType)`、`errorTriggerLoop`、`subProcessLoop`、`addAuditOperatorAlreadyInTodo`、`reduceAuditSingleApprover`、`reduceAuditTargetNotFound` 等 | | `FlowStateException` | `repositoryNotRegistered`、`recordAlreadyDone`、`operatorNotMatch`、`workflowAlreadyDisable`、`recordNotSupportRevoke` 等 | | `FlowNotFoundException` | `workflow(workCode)`、`record(recordId)`、`node(nodeId)`、`operator(operatorId)`、`action(actionId)` | diff --git a/docs/Integration/rest-api.md b/docs/Integration/rest-api.md index 9990a163..f2c5bb86 100644 --- a/docs/Integration/rest-api.md +++ b/docs/Integration/rest-api.md @@ -44,6 +44,18 @@ operatorIdentity → 存在 → 校验后作为当前身份(空串 = 默认身 | POST | `/api/cmd/record/revoke` | `IdRequest` | `Response` | 撤销 | | POST | `/api/cmd/record/delete` | `IdRequest` | `Response` | 删除(仅未流转实例,开始节点) | +### 2.1 异常触发(`errorTrigger`)的三种语义 + +`ErrorThrow` 按脚本返回值分流,历史写法保持兼容: + +| 脚本返回 | 类型 | 提交时行为 | +|---|---|---| +| `'节点id'` 或 `[type:'node', node:'节点id']` | NODE | 跳转到指定节点 | +| `[1,2]` / `1` 或 `[type:'operators', operators:[1,2]]` | OPERATORS | 使用指定人员兜底 | +| `[type:'prompt', message:'...']` | PROMPT | 阻断本次操作,抛 `validation.node.operatorEmpty` 并回滚 | + +默认脚本已改为 PROMPT(`ScriptDefaultConstants.SCRIPT_DEFAULT_ERROR_TRIGGER`),文案可由业务方实现 `IScriptRegistry#getErrorTriggerScript` 并调用 `ScriptRegistryContext#setRegistry` 覆盖。 + ## 3. 流程设计(`/api/cmd/workflow`) `flow-engine-starter-api/src/main/java/com/codingapi/flow/api/controller/WorkflowController.java` diff --git a/docs/capabilities/flow-engine-framework/script.md b/docs/capabilities/flow-engine-framework/script.md index 0c896465..2526a4c3 100644 --- a/docs/capabilities/flow-engine-framework/script.md +++ b/docs/capabilities/flow-engine-framework/script.md @@ -73,6 +73,19 @@ ScriptRegistryContext.getInstance().setRegistry(new IScriptRegistry() { }); ``` +### 异常触发脚本(errorTrigger)返回格式 + +节点取人为空时执行,按返回值分流为三种处理方式(前两种为历史能力,`prompt` 为 issue #296 新增): + +| 返回值 | 处理方式 | 说明 | +|---|---|---| +| `[type:'prompt', message:'...']` | 异常提示 | 阻断本次操作并展示文案,事务回滚;默认脚本即此形式 | +| `[type:'node', node:'节点id']` | 指定节点 | 跳转到指定节点继续办理 | +| `[type:'operators', operators:[1,2]]` | 指定人员 | 使用给定人员兜底,继续生成记录 | +| `'节点id'` / `[1,2]` / `1` | 兼容写法 | 依次等价于 `node` / `operators` / 单个人员,历史脚本无需改动 | + +Map 未声明 `type` 时按 `message` → `node` → `operators` 的顺序推断。`@SCRIPT_META` 应与返回类型一致(如 `{"type":"prompt"}`),设计器据此渲染配置面板;`getErrorTriggerScript()` 的默认实现返回「异常提示」,业务方可通过 `ScriptRegistryContext#setRegistry` 整体覆盖文案或改为其他处理方式。 + ### 脚本执行上下文 `FlowScriptContext` 承载脚本的 `$bind` 上下文,内部持有 `IBeanFactory` 字段并委托其实现(具体实现由 starter 的 `FlowScriptContextRegister` 装配),供 Groovy 脚本以 `$bind.getBean(...)`、`$bind.getRecordById(...)`、`$bind.getOperatorById(...)` 等方式访问 Spring 容器中的 Bean、流程记录与操作者信息;脚本的实际执行由 `FlowScriptRuntimeContext` 结合 spring-boot 的 `GroovyScript` 完成。 diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/error/ErrorThrow.java b/flow-engine-framework/src/main/java/com/codingapi/flow/error/ErrorThrow.java index b0be709d..4bb8af11 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/error/ErrorThrow.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/error/ErrorThrow.java @@ -3,31 +3,119 @@ import com.codingapi.flow.node.IFlowNode; import com.codingapi.flow.operator.IFlowOperator; import lombok.Getter; -import lombok.Setter; import java.util.List; /** * 异常流程配置,在节点没有匹配到人员时触发 - * 异常时可以指定跳转到的节点或者指定默认的审批人员,两者二选一,优先以跳转的节点为准 + *

+ * 三种处理方式(issue #296): + *

    + *
  1. {@link Type#NODE}:跳转到指定节点;
  2. + *
  3. {@link Type#OPERATORS}:使用指定的默认审批人员;
  4. + *
  5. {@link Type#PROMPT}:不跳转也不兜底,阻断本次操作并把提示信息交给调用方展示。
  6. + *
+ * 前两种为历史能力,保持既有语义;{@link Type#PROMPT} 为新增语义,用于避免「静默回退到开始节点」 + * 造成发起人误以为流程已正常流转。 */ -@Setter @Getter public class ErrorThrow { + /** + * 异常处理类型 + */ + public enum Type { + /** + * 跳转节点 + */ + NODE, + /** + * 指定默认审批人员 + */ + OPERATORS, + /** + * 异常提示(阻断并提示) + */ + PROMPT + } + + /** + * 异常处理类型,未显式设置时由 {@link #isNode()} 等语义方法按字段推导 + */ + private Type type; + /** * 跳转的节点 */ private IFlowNode node; + /** * 默认审批人员 */ private List operators; /** - * 是否为节点 + * 异常提示信息,仅 {@link Type#PROMPT} 使用 + */ + private String message; + + public void setType(Type type) { + this.type = type; + } + + public void setNode(IFlowNode node) { + this.node = node; + if (node != null) { + this.type = Type.NODE; + } + } + + public void setOperators(List operators) { + this.operators = operators; + if (operators != null && !operators.isEmpty()) { + this.type = Type.OPERATORS; + } + } + + public void setMessage(String message) { + this.message = message; + if (this.node == null && (this.operators == null || this.operators.isEmpty())) { + this.type = Type.PROMPT; + } + } + + /** + * 创建异常提示结果 + * + * @param message 提示信息,为空时由调用方使用兜底文案 + * @return 异常提示配置 + */ + public static ErrorThrow prompt(String message) { + ErrorThrow errorThrow = new ErrorThrow(); + errorThrow.message = message; + // 即使文案为空也保持 PROMPT 语义:类型由配置决定,不由文案是否为空决定 + errorThrow.type = Type.PROMPT; + return errorThrow; + } + + /** + * 是否为节点跳转 */ public boolean isNode() { - return node!=null; + return node != null; + } + + /** + * 是否为异常提示 + */ + public boolean isPrompt() { + return type == Type.PROMPT; + } + + /** + * 是否指定了默认审批人员 + */ + public boolean hasOperators() { + return operators != null && !operators.isEmpty(); } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/exception/FlowValidationException.java b/flow-engine-framework/src/main/java/com/codingapi/flow/exception/FlowValidationException.java index 5d94d45d..f089295f 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/exception/FlowValidationException.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/exception/FlowValidationException.java @@ -169,4 +169,22 @@ public static FlowValidationException invalidParameter(String fieldName, String return new FlowValidationException("validation.parameter." + fieldName, String.format("Parameter %s has invalid value '%s', expected %s", fieldName, value, expected)); } + + /** + * 节点未匹配到审批人且异常处理配置为「异常提示」,需要阻断本次操作(issue #296)。 + *

+ * 提示信息优先使用流程配置的文案;未配置时回落为带节点名称的默认文案。 + * + * @param nodeId 节点 id + * @param nodeName 节点名称 + * @param message 流程配置的提示信息,可为空 + * @return exception + */ + public static FlowValidationException nextNodeOperatorEmpty(String nodeId, String nodeName, String message) { + String text = (message == null || message.isBlank()) + ? String.format("No operator matched for node '%s' (id: %s), the flow cannot continue", + nodeName, nodeId) + : message; + return new FlowValidationException("validation.node.operatorEmpty", text); + } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/node/BaseAuditNode.java b/flow-engine-framework/src/main/java/com/codingapi/flow/node/BaseAuditNode.java index 713a5ec4..edfccef6 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/node/BaseAuditNode.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/node/BaseAuditNode.java @@ -234,6 +234,11 @@ private List generateCurrentRecords(FlowSession session, Set if(errorThrow==null){ throw FlowValidationException.nodeRequired("errorTrigger"); } + // 异常提示(issue #296):阻断本次操作并把提示信息交给调用方,避免默认「回退至开始节点」 + // 造成发起人误以为流程已正常流转 + if(errorThrow.isPrompt()){ + throw FlowValidationException.nextNodeOperatorEmpty(this.getId(), this.getName(), errorThrow.getMessage()); + } if(errorThrow.isNode()){ IFlowNode errorNode = errorThrow.getNode(); // 抄送/子流程节点不产生有效记录,跳转会静默停滞 @@ -251,6 +256,10 @@ private List generateCurrentRecords(FlowSession session, Set } return errorNode.generateCurrentRecords(errorSession); }else { + // 指定人员兜底:结果为空视为配置无效,否则会生成空记录让流程静默停滞 + if (!errorThrow.hasOperators()) { + throw FlowValidationException.nodeRequired("errorTrigger"); + } operatorManager = new OperatorManager(errorThrow.getOperators()); } } diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/ScriptDefaultConstants.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ScriptDefaultConstants.java index 1b944ae5..c4632d3d 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/ScriptDefaultConstants.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/ScriptDefaultConstants.java @@ -48,13 +48,17 @@ def run(request){ """; /** - * 默认异常触发脚本 + * 默认异常触发脚本(issue #296) + *

+ * 默认行为为「异常提示」:不跳转、不兜底,阻断本次操作并提示用户,避免历史默认的 + * 「回退至开始节点」让发起人误以为流程已正常流转。业务方可通过 + * {@code ScriptRegistryContext#setRegistry} 覆盖文案或改为指定节点/指定人员。 */ public static final String SCRIPT_DEFAULT_ERROR_TRIGGER = """ - // @SCRIPT_TITLE 回退至开始节点 - // @SCRIPT_META {"type":"node","node":"START"} + // @SCRIPT_TITLE 异常提示 + // @SCRIPT_META {"type":"prompt"} def run(request){ - return request.getStartNode().getId(); + return [type:'prompt', message:'流程未匹配到审批人,无法继续处理,请联系流程管理员'] } """; diff --git a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java index d95b6157..7b53600d 100644 --- a/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java +++ b/flow-engine-framework/src/main/java/com/codingapi/flow/script/node/ErrorTriggerScript.java @@ -19,6 +19,16 @@ /** * 异常触发脚本 + *

+ * 返回值支持四种写法(issue #296): + *

+ * 历史写法全部保持兼容。 */ @AllArgsConstructor public class ErrorTriggerScript { @@ -32,21 +42,16 @@ public ErrorThrow execute(FlowSession session) { Object value = FlowScriptRuntimeContext.getInstance() .getGroovyScript(script) .invoke(Map.of("$bind", new GroovyScriptBind(FlowScriptContext.getInstance())), request); - if(value instanceof String){ - String nodeId = (String) value; + if (value instanceof Map map) { + return parseMap(session, map); + } + if (value instanceof String nodeId) { ErrorThrow errorThrow = new ErrorThrow(); errorThrow.setNode(session.getNode(nodeId)); return errorThrow; } - if(value instanceof List){ - List userIds =(List) value; - List operatorIds = new ArrayList<>(); - for(Object userId:userIds){ - operatorIds.add(Long.parseLong(String.valueOf(userId))); - } - ErrorThrow errorThrow = new ErrorThrow(); - errorThrow.setOperators(session.getRepositoryHolder().findOperatorByIds(operatorIds)); - return errorThrow; + if (value instanceof List userIds) { + return parseOperators(session, userIds); } long userId = Long.parseLong(String.valueOf(value)); @@ -58,6 +63,57 @@ public ErrorThrow execute(FlowSession session) { } + /** + * 解析 Map 形式的返回值 + * + * @param session 当前会话 + * @param map 脚本返回值 + * @return 异常处理配置 + */ + private ErrorThrow parseMap(FlowSession session, Map map) { + String type = map.get("type") == null ? null : String.valueOf(map.get("type")); + if (ErrorThrow.Type.PROMPT.name().equalsIgnoreCase(type) || "prompt".equalsIgnoreCase(type)) { + Object message = map.get("message"); + return ErrorThrow.prompt(message == null ? null : String.valueOf(message)); + } + if (ErrorThrow.Type.NODE.name().equalsIgnoreCase(type)) { + Object nodeId = map.get("node"); + ErrorThrow errorThrow = new ErrorThrow(); + errorThrow.setNode(nodeId == null ? null : session.getNode(String.valueOf(nodeId))); + return errorThrow; + } + if (ErrorThrow.Type.OPERATORS.name().equalsIgnoreCase(type)) { + Object operators = map.get("operators"); + if (operators instanceof List userIds) { + return parseOperators(session, userIds); + } + return new ErrorThrow(); + } + // 未声明 type 时按字段存在性推断:message 优先(提示),其次 node,最后 operators + if (map.get("message") != null) { + return ErrorThrow.prompt(String.valueOf(map.get("message"))); + } + if (map.get("node") != null) { + ErrorThrow errorThrow = new ErrorThrow(); + errorThrow.setNode(session.getNode(String.valueOf(map.get("node")))); + return errorThrow; + } + if (map.get("operators") instanceof List userIds) { + return parseOperators(session, userIds); + } + return new ErrorThrow(); + } + + private ErrorThrow parseOperators(FlowSession session, List userIds) { + List operatorIds = new ArrayList<>(); + for (Object userId : userIds) { + operatorIds.add(Long.parseLong(String.valueOf(userId))); + } + ErrorThrow errorThrow = new ErrorThrow(); + errorThrow.setOperators(session.getRepositoryHolder().findOperatorByIds(operatorIds)); + return errorThrow; + } + /** * 默认节点脚本 */ diff --git a/flow-engine-framework/src/test/java/com/codingapi/flow/script/ErrorTriggerScriptTest.java b/flow-engine-framework/src/test/java/com/codingapi/flow/script/ErrorTriggerScriptTest.java index fbe455da..5089edee 100644 --- a/flow-engine-framework/src/test/java/com/codingapi/flow/script/ErrorTriggerScriptTest.java +++ b/flow-engine-framework/src/test/java/com/codingapi/flow/script/ErrorTriggerScriptTest.java @@ -3,37 +3,51 @@ import com.codingapi.flow.builder.FormFieldPermissionsBuilder; import com.codingapi.flow.builder.NodeStrategyBuilder; import com.codingapi.flow.error.ErrorThrow; +import com.codingapi.flow.factory.MyFlowServiceFactory; import com.codingapi.flow.form.DataType; import com.codingapi.flow.form.FlowForm; -import com.codingapi.flow.form.FormData; import com.codingapi.flow.form.FlowFormBuilder; +import com.codingapi.flow.form.FormData; import com.codingapi.flow.form.permission.PermissionType; import com.codingapi.flow.node.nodes.ApprovalNode; import com.codingapi.flow.node.nodes.EndNode; import com.codingapi.flow.node.nodes.StartNode; import com.codingapi.flow.script.factory.FlowGroovyScriptFactory; import com.codingapi.flow.script.node.ErrorTriggerScript; -import com.codingapi.flow.factory.MyFlowServiceFactory; +import com.codingapi.flow.script.registry.DefaultScriptRegistry; +import com.codingapi.flow.script.registry.IScriptRegistry; +import com.codingapi.flow.script.registry.ScriptRegistryContext; import com.codingapi.flow.session.FlowSession; import com.codingapi.flow.strategy.node.FormFieldPermissionStrategy; import com.codingapi.flow.strategy.node.OperatorLoadStrategy; import com.codingapi.flow.user.User; import com.codingapi.flow.workflow.Workflow; import com.codingapi.flow.workflow.WorkflowBuilder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; +/** + * 异常触发脚本测试(issue #296) + *

+ * 覆盖四种返回值解析、默认脚本的「异常提示」语义,以及业务方通过脚本注册中心覆盖默认文案。 + */ class ErrorTriggerScriptTest { private final MyFlowServiceFactory factory = new MyFlowServiceFactory(); + private IScriptRegistry originRegistry; + private FlowSession flowSession; + private User user; - @Test - void execute() { - User user = new User(1, "lorne"); + @BeforeEach + void setUp() { + originRegistry = ScriptRegistryContext.getInstance().getRegistry(); + user = new User(1, "lorne"); factory.userGateway.save(user); FlowForm form = FlowFormBuilder.builder() @@ -85,22 +99,129 @@ void execute() { FormData data = new FormData(form); data.getDataBody().set("name", "张三").set("days", 10).set("reason", "事由"); - FlowSession flowSession = FlowSession.startSession(factory.repositoryHolder,user, workflow, startNode, startNode.getActions().get(0), data, 0); + flowSession = FlowSession.startSession(factory.repositoryHolder, user, workflow, startNode, + startNode.getActions().get(0), data, 0); + } + + @AfterEach + void tearDown() { + if (originRegistry != null) { + ScriptRegistryContext.getInstance().setRegistry(originRegistry); + } + } + + /** + * 默认脚本返回异常提示,不再静默回退到开始节点 + */ + @Test + void should_return_prompt_when_default_script_executed() { + ErrorThrow errorThrow = ErrorTriggerScript.defaultScript().execute(flowSession); + + assertTrue(errorThrow.isPrompt()); + assertFalse(errorThrow.isNode()); + assertFalse(errorThrow.hasOperators()); + assertNotNull(errorThrow.getMessage()); + assertTrue(errorThrow.getMessage().contains("审批人")); + } + + /** + * 历史写法:返回节点 id 时仍按节点跳转解析 + */ + @Test + void should_parse_node_when_script_returns_string() { + String script = """ + def run(request){ + return request.getStartNode().getId(); + } + """; + ErrorTriggerScript errorTriggerScript = new ErrorTriggerScript( + FlowGroovyScriptFactory.createErrorTriggerScript(script).getKey()); + + ErrorThrow errorThrow = errorTriggerScript.execute(flowSession); - ErrorTriggerScript errorNodeTriggerScript = ErrorTriggerScript.defaultScript(); - ErrorThrow errorThrow = errorNodeTriggerScript.execute(flowSession); assertTrue(errorThrow.isNode()); - assertEquals(startNode.getId(), errorThrow.getNode().getId()); + assertEquals(flowSession.getWorkflow().getStartNode().getId(), errorThrow.getNode().getId()); + } + /** + * 历史写法:返回人员 id 列表时按默认审批人兜底 + */ + @Test + void should_parse_operators_when_script_returns_list() { String script = """ - def run(request){ - return request.getCreatedOperatorId(); - } - """; + def run(request){ + return [request.getCreatedOperatorId()]; + } + """; + ErrorTriggerScript errorTriggerScript = new ErrorTriggerScript( + FlowGroovyScriptFactory.createErrorTriggerScript(script).getKey()); + + ErrorThrow errorThrow = errorTriggerScript.execute(flowSession); - ErrorTriggerScript errorOperatorTriggerScript = new ErrorTriggerScript(FlowGroovyScriptFactory.createErrorTriggerScript(script).getKey()); - errorThrow = errorOperatorTriggerScript.execute(flowSession); assertFalse(errorThrow.isNode()); + assertFalse(errorThrow.isPrompt()); assertEquals(user, errorThrow.getOperators().get(0)); } -} \ No newline at end of file + + /** + * 历史写法:返回单个人员 id 时按默认审批人兜底 + */ + @Test + void should_parse_operator_when_script_returns_number() { + String script = """ + def run(request){ + return request.getCreatedOperatorId(); + } + """; + ErrorTriggerScript errorTriggerScript = new ErrorTriggerScript( + FlowGroovyScriptFactory.createErrorTriggerScript(script).getKey()); + + ErrorThrow errorThrow = errorTriggerScript.execute(flowSession); + + assertFalse(errorThrow.isNode()); + assertFalse(errorThrow.isPrompt()); + assertEquals(user, errorThrow.getOperators().get(0)); + } + + /** + * 新写法:Map 形式声明异常提示与文案 + */ + @Test + void should_parse_prompt_when_script_returns_map() { + String script = """ + def run(request){ + return [type:'prompt', message:'下一节点没有可用审批人']; + } + """; + ErrorTriggerScript errorTriggerScript = new ErrorTriggerScript( + FlowGroovyScriptFactory.createErrorTriggerScript(script).getKey()); + + ErrorThrow errorThrow = errorTriggerScript.execute(flowSession); + + assertTrue(errorThrow.isPrompt()); + assertEquals("下一节点没有可用审批人", errorThrow.getMessage()); + } + + /** + * 业务方可以整体替换默认提示文案,而不只是改配置项 + */ + @Test + void should_use_custom_default_message_when_registry_overridden() { + ScriptRegistryContext.getInstance().setRegistry(new DefaultScriptRegistry() { + @Override + public String getErrorTriggerScript() { + String script = """ + def run(request){ + return [type:'prompt', message:'业务方自定义提示:请联系流程管理员']; + } + """; + return FlowGroovyScriptFactory.createErrorTriggerScript(script).getKey(); + } + }); + + ErrorThrow errorThrow = ErrorTriggerScript.defaultScript().execute(flowSession); + + assertTrue(errorThrow.isPrompt()); + assertEquals("业务方自定义提示:请联系流程管理员", errorThrow.getMessage()); + } +}