Skip to content

[Bug] 办理身份未留痕:已办记录缺少本次办理人身份 #306

Done

Description

@xlorne

现象

同一个用户以不同身份办理流程时,本次办理身份在落库后无法查询。

本地实测(请假流程,codingapi.flow.identity.match-mode=USER_ONLY):

  • 发起:X-Operator-Identity: department1
  • 审批节点办理:X-Operator-Identity: department2,动作「同意」

库中该链路(processId tJqAZm9l8Q4GxDWVZH)的结果:

id 节点 current_operator_identity(归属) submit_operator_identity create_operator_identity
2152 开始节点 department1 department1 department1
2153 审批节点 department1 department1 department1

department2 在整条链路里没有任何落点。列表页「身份」列取 currentOperatorIdentity,因此展示的是待办归属身份(department1),看不出「这条是 department2 办的」。

根因

三个身份字段的语义都不覆盖「本次办理人」:

字段 写入时机 语义
createOperator* 记录构造 流程发起人
currentOperator* 记录构造(FlowRecord.java:417-419) 这条待办归属谁
submitOperator* 记录构造(FlowRecord.java:421-423) 创建这条记录时的上游提交人
interferedOperator* update() 且不满足身份匹配策略(FlowRecord.java:640-644) 他人代办

而办结时走的 FlowRecord#update(flowSession, pass)(FlowRecord.java:624-652)只更新 formData / actionId / actionType / actionName / readable / readTime / updateTime / recordState / advice / signKey,没有任何身份赋值。

FlowActionService 确实拿到了带身份的当前操作人(get(operatorId, operatorIdentity)),但它只被用作下游新记录的 submitOperator(FlowActionService.java:104 → createFlowSession)。于是:

  • 中间节点:办理身份只能跳到下游记录的 submit_operator_identity 间接看到,且前提是「下游是同一人同一身份」;
  • 最后一步:没有下游记录,department2 彻底丢失(本 issue 的实际场景)。

补充:当前 EndNode 会生成结束记录,但实测库里 38 条记录全是 START + APPROVAL,没有 END 类型记录,所以最后一步既无下游也无结束记录可承载身份。

另外 FlowActionRequest#toFlowAdvice() 没有把 advice.getOperatorIdentity() 传给 FlowAdvice(FlowAdvice 也没有该字段),身份在 advice 层就已经中断,仅被 FlowActionService 用来查一次操作人。

影响

方案

新增独立的「办理人」三元组,与已有字段并存、互不覆盖:

  1. 领域模型(flow-engine-framework)
    • FlowRecord 增加 handleOperatorId / handleOperatorName / handleOperatorIdentity;
    • 新增 markHandleOperator(IFlowOperator operator),写入三者(identity 走 OperatorIdentity.of);
    • 不在 update() 内隐式写入:update() 同时被 notifyRecord()(抄送刷新,FlowRecord.java:722)和 SaveAction(暂存,pass=false)调用,隐式写入会把抄送接收人、暂存人误记为办理人。改为在真正办结的动作里显式调用:
      • PassAction、ReturnAction、RejectAction、TransferAction、DelegateAction
      • SaveAction(暂存)不调用。
  2. 持久化(flow-engine-starter-infra)
    • FlowRecordEntity 增加 handle_operator_id / handle_operator_name / handle_operator_identity 三列(identity 用 OperatorIdentity.MAX_LENGTH);
    • FlowRecordConvertor 双向映射,identity 走 OperatorIdentity.normalize/validate;
    • 达梦 DDL 脚本同步补列。
  3. 查询(flow-engine-framework + query starter)
    • FlowRecordContent 增加三个字段并在 from(FlowRecord) 中赋值;
    • 待办记录 FlowTodoRecord 不加(待办尚未办理,无办理人语义),from(FlowTodoRecord) 不返回。
  4. 前端(flow-frontend)
    • 已办列表「身份」列改为 handleOperatorIdentity || currentOperatorIdentity(apps/app-pc/src/pages/todo.tsx);
    • 待办列表保持 currentOperatorIdentity。
  5. 文档
    • docs/Integration/operator-identity.md §4.4 补充「办理人留痕」字段说明与写入时机;§5 补兼容说明(新增列,存量数据为空,需回填时按 finish_time/下游 submit 推断,不做自动迁移)。

兼容性

测试

  • FlowRecord 单测:markHandleOperator 写入三元组、identity 为空时归一为默认身份;
  • 动作级:PassAction 办结后 handle_* 有值;SaveAction 暂存后 handle_* 仍为空;notifyRecord 不写 handle_*;
  • 流程级(参照 OperatorScriptIdentityFlowTest):department1 发起 → department2 审批走完最后一步 → 断言该记录 current_operator_identity=department1、handle_operator_identity=department2;
  • 全量 ./mvnw -pl flow-engine-framework test 不回归。

实现基线

#303(PR #304)尚未合入 dev,本次改动在其分支 feature/issue-303-operator-script-resolver 之上继续,避免与 #303 的解析器改动冲突。PR 目标分支为 feature/issue-303-operator-script-resolver,待 #304 合入 dev 后随之进入主线。

Activity

  1. added
    bug
    enhancement
    on Dec 3, 2026
  2. xlorne commented on Dec 3, 2026

    @xlorne
    ContributorAuthor

    已按方案实现并推送,基线为 #303 分支。

    交付

    仓库 分支 提交 PR
    codingapi/flow-engine feature/issue-306-handle-operator-identity 81a2bc0e #307(base feature/issue-303-operator-script-resolver)
    codingapi/flow-frontend feature/issue-306-handle-operator-identity d6f6dbd #90(base feature/issue-303-default-script)

    实现要点

    新增 handle_operator_id / handle_operator_name / handle_operator_identity 三元组,语义是「本次实际办理人及其身份」,与 current_*(待办归属)、submit_*(创建记录时的上游提交人)并存、互不覆盖。

    写入点是显式的 FlowRecord#markHandleOperator(IFlowOperator):

    动作 是否写入
    PassAction / ReturnAction / RejectAction / TransferAction / DelegateAction ✅ 办结即写
    SaveAction(暂存) ❌
    notifyRecord()(抄送刷新) ❌

    没有放进 update():暂存与抄送刷新同样调用 update(),在里面隐式写入会把暂存人、抄送接收人误记成办理人。newRecord() 里调用 clearHandleOperator(),避免记录回到未办理状态时残留上一位办理人。

    持久化与查询同步:FlowRecordEntity 三列、FlowRecordConvertor 双向映射、FlowRecordContent 暴露(from(FlowTodoRecord) 不返回,待办没有办理人语义)、DDL 脚本补列(docs/Integration/sql/0.3.0-operator-identity.sql 1.1 节)。

    你遇到的那条流程

    升级后,2153 这种场景会得到:

    字段 值
    current_operator_identity department1(待办归属,不变)
    handle_operator_identity department2(本次办理身份)
    handle_operator_name 办理人姓名

    前端已办列表的「审批人」「身份」两列按 recordState 判断:已办取 handle*,待办取 current*;历史数据没有 handle* 时自动回退,展示行为与升级前一致。

    验证

    • 新增 HandleOperatorIdentityFlowTest 3 例(USER_ONLY):最后一步办理留痕、中间节点办理留痕 + 下游 submit 一致、暂存不写;
    • ./mvnw -pl flow-engine-framework test:518 例通过(原 515 + 新增 3),0 失败 0 错误;
    • 全项目 ./mvnw compile 通过;
    • 前端 pnpm -F @flow-example/app-pc build 通过。

    兼容性与未做的事

    • 纯新增 nullable 列,ddl-auto=update 自动加列;存量记录 handle_* 为空,不做自动回填(如需回填,按 finish_time 与下游 submit_operator_* 推断);
    • 不改 currentOperatorIdentity / submitOperatorIdentity 语义,待办合并键、STRICT 回溯、verifyOperator 不受影响;
    • issue 里提到的「FlowActionRequest#toFlowAdvice() 未透传身份」本次未动 —— 目前身份只需在 FlowActionService 用一次,没有其他消费方,等出现第二个消费场景再收口。

    feature/issue-303-operator-script-resolver 未改动。

  3. added 2 commits that reference this issue on Dec 3, 2026
  4. xlorne commented on Dec 3, 2026

    @xlorne
    ContributorAuthor

    已完成并合入 dev

    实现内容

    • FlowRecord 新增 handleOperatorId / handleOperatorName / handleOperatorIdentity,以及 markHandleOperator(IFlowOperator) 与 clearHandleOperator()(后者在 newRecord() 调用,记录回到未办理状态时不残留旧的办理人)。
    • 写入点为五个办结动作:PassAction / ReturnAction / RejectAction / TransferAction / DelegateAction。刻意不放进 update():SaveAction(暂存)与 notifyRecord()(抄送刷新)也走 update(),隐式写入会把暂存人、抄送接收人误记成办理人。
    • FlowRecordEntity 新增 3 列、FlowRecordConvertor 双向映射(identity 走 normalize / validate)、FlowRecordContent 暴露三个字段(from(FlowTodoRecord) 不返回,待办没有办理人语义)。
    • docs/Integration/sql/0.3.0-operator-identity.sql 补列;operator-identity.md §4.1 / §4.4 / §5 更新留痕口径与兼容说明。

    本地全链路回归时额外修掉的一个缺陷(aae77b04)

    查询层 FlowRecordQueryServiceImpl 是用 FlowRecordContentConvertor.convert(FlowRecordEntity) 直接组装列表数据的,不走领域对象链路;本次实现只给领域对象和实体转换器加了映射,漏了这个列表转换器,导致办理人已经落库、但已办 / 全部流程接口返回的 handleOperator* 恒为 null,前端只能一直回退到待办归属人。

    已补映射并新增 FlowRecordContentConvertorTest(已办记录带办理人 / 存量记录空值 2 例),先复现红灯再修复。

    验证(本地 8090 + 3000 实跑,使用含存量数据的库)

    记录 场景 结果
    新建 张三以 department1 发起 create / submit 均为 张三 · department1
    下游待办 审批人指定 李四 · department2 current=李四·department2,submit=张三·department1
    该记录办结 李四以 department2 审批 已办 handle=李四·department2
    存量待办 2 张三默认身份待办被以 department1 办理 handle=张三·department1,current 仍为空(办理不覆盖待办归属)
    存量记录 4 306 之前办结的历史数据 handle 为空,前端回退 current*,展示与升级前一致
    • 前端页面确认:user2 的「我的已办」显示「李四 / department2」;user1 的已办显示「张三 / department1」。
    • 测试:framework 全量 518 例通过,infra 新增 2 例通过。

    仓库 / 分支 / 提交 / PR

    仓库 分支 提交 PR
    codingapi/flow-engine feature/issue-306-handle-operator-identity 81a2bc0e + aae77b04(合并提交 cb68b84a) #307(已合入 dev)
    codingapi/flow-frontend feature/issue-306-handle-operator-identity d6f6dbd(合并提交 6abade5b) #90(已合入 dev)

    关闭本 issue。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions