Repository navigation
feat: 取人脚本支持返回 OperatorKey 与操作者对象,默认模板带创建者身份 (#303) - #304
Merged
Merged
Conversation
脚本返回值不再被强转为 Long,统一由 OperatorScriptResultResolver 解析, 支持 List<Long>(默认身份)、List<OperatorKey>(按身份回查)、 List<IFlowOperator>(直接采用)三种形态,允许同一列表混用。 - 新增 OperatorScriptResultResolver:按身份分组批量回查、按脚本顺序输出, 非正数 id(存量 -1 表示无审批人)跳过,非法元素抛 FlowValidationException - OperatorLoadScript / ErrorTriggerScript 统一走解析器 - OperatorLoadStrategy 的分配回查逻辑下沉到解析器 - 脚本 API:request.getCreatedOperatorKey / getCurrentOperatorKey / getSubmitOperatorKey / findPreviousNodeOperators,$bind.getOperatorKey - FlowSession 新增 loadPreviousNodeOperators(保留记录上的身份) - 脚本工厂的描述同步三种返回形态 Refs #303
- ScriptDefaultConstants 默认取人脚本改为 [request.getCreatedOperatorKey()] - operator-identity.md §3.4 补齐三种返回形态、默认模板、Key 构造 API 与 findPreviousNodeOperators 用法;§5 补默认脚本升级的兼容说明 Closes #303
This was referenced Dec 3, 2026
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #304 +/- ##
============================================
- Coverage 76.00% 75.87% -0.13%
- Complexity 2140 2163 +23
============================================
Files 282 283 +1
Lines 8714 8810 +96
Branches 1044 1064 +20
============================================
+ Hits 6623 6685 +62
- Misses 1574 1597 +23
- Partials 517 528 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
issue #303:多身份(#288 / #297 / #301)落地后,「脚本产出参与人」这条链路没有升级 ——
OperatorLoadScript把脚本返回值统一Long.parseLong(String.valueOf(x)),身份在这一步被丢掉,文档 §3.4 的[$bind.getOperatorByIdentity(2,'department1')]实际会抛NumberFormatException。本 PR 包含 issue 的全部后端改动:解析层 + 脚本 API + 默认模板 + 文档。按维护者要求合并为单一分支
feature/issue-303-operator-script-resolver(原feature/issue-303-default-script已快进合入并删除)。改动
1. 新增统一解析器
OperatorScriptResultResolverflow-engine-framework/.../script/operator/OperatorScriptResultResolver.java按元素逐个判定,三种形态允许混用:
IFlowOperatorgetIdentity()OperatorKeykey.identity()Number/ 纯数字字符串null/ 空串 / 非正数 id[-1]表示无审批人)FlowValidationException(带脚本类型、元素类型、元素内容)return request.getCreatedOperatorId()不写[])与null;OperatorLoadStrategy#loadAssignedOperators(flow-engine#288 衍生:人员指定(发起人/审批人设定)未携带身份 #292)的回查逻辑下沉到此,策略只保留分配逻辑,消除第三份重复实现。2. 改造调用点
OperatorLoadScript#execute:不再强转List<Object>,直接交给解析器;ErrorTriggerScript:operators同样支持三种形态(含单值);OperatorLoadStrategy:分配回查改调解析器。3. 脚本 API
request.getCreatedOperatorKey()OperatorKeyrequest.getCurrentOperatorKey()OperatorKeyrequest.getSubmitOperatorKey()OperatorKeyrequest.findPreviousNodeOperators()List<IFlowOperator>$bind.getOperatorKey(userId, identity)OperatorKeyFlowSession新增loadPreviousNodeOperators():复用loadPreviousNodeOperatorIds()的直接前驱校验与isAutoDone()排除,改为按记录的(currentOperatorId, currentOperatorIdentity)回查。原*Id/*Identity/getOperatorByIdentity/findPreviousNodeOperatorIds全部保留。FlowGroovyScriptFactory的脚本描述同步三种返回形态(脚本编辑器的提示文案)。4. 默认模板与文档
ScriptDefaultConstants.SCRIPT_DEFAULT_OPERATOR_LOAD改为return [request.getCreatedOperatorKey()],设计器新建「流程创建者」审批人时直接带上发起身份(对应前端 feat(flow-design): 默认取人脚本返回 OperatorKey,变量列表补身份标识 flow-frontend#89);docs/Integration/operator-identity.md§3.4 补齐三种返回形态、默认模板、Key 构造 API 与findPreviousNodeOperators用法;§5 补默认脚本升级的兼容说明。测试
新增 25 例,framework 全量 515 例通过(
./mvnw -o -pl flow-engine-framework test):OperatorScriptResultResolverTest(12 例):三种形态、混合列表顺序、单值/null/空列表、null元素、非正数 id 跳过、同人异身份不合并、非法元素异常上下文、按身份分组回查次数、对象形态不发生回查(代理计数断言);OperatorLoadScriptTest(7 例):getCreatedOperatorKey/$bind.getOperatorByIdentity/$bind.getOperatorKey/ 混用顺序 / 单值 / 非法元素;ErrorTriggerScriptTest(+3 例):operators返回 Key / 对象 / 单个 Key;OperatorScriptIdentityFlowTest(3 例):department1发起 → 创建者节点审批记录currentOperatorIdentity = department1;换department2发起同理;开始节点调用findPreviousNodeOperators()安全返回空列表。兼容性
return [id1, id2]行为不变(默认身份);[-1]「无审批人」语义保留(跳过 → 仍走 errorTrigger);NumberFormatException变为带上下文的FlowValidationException;getCreatedOperatorKey()后,新建节点审批人身份 = 流程发起时的身份(原为默认身份)。这是 issue 要的效果,但对「已启用多身份、一直用默认模板」的业务是可感知变化;存量流程定义里已保存的脚本文本不受影响,未做数据迁移。关联
前端同批改动:codingapi/flow-frontend#89(默认脚本 + 变量列表)
Closes #303