Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions docs/Integration/operator-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ def run(request) {

| 表 | 新增列 |
|----|--------|
| `t_flow_record` | `create_operator_identity`、`submit_operator_identity`、`current_operator_identity`、`forward_operator_identity`、`interfered_operator_identity` |
| `t_flow_record` | `create_operator_identity`、`submit_operator_identity`、`current_operator_identity`、`forward_operator_identity`、`interfered_operator_identity`、`handle_operator_identity` |
| `t_flow_todo_record` | `create_operator_identity`、`submit_operator_identity`、`current_operator_identity` |

「办理人」另有两列非身份字段(issue #306):`handle_operator_id`、`handle_operator_name`,与 `handle_operator_identity` 一起记录**谁以什么身份办理了这条记录**。待办表不加这三列——待办尚未办理,没有办理人语义。

只存身份标识本身,**不落库任何附加属性**(避免为 5 组操作者各加一个 JSON 快照列,也避免身份名称被冻结在历史数据里)。展示名称仍取操作者姓名;需要展示身份名称时由宿主按 `identity` 自行映射。

升级脚本见 [sql/0.3.0-operator-identity.sql](./sql/0.3.0-operator-identity.sql)。
Expand Down Expand Up @@ -311,7 +313,23 @@ def run(request) {

`OperatorManager`、操作者线程缓存、网关缓存的 `(userId, identity)` 键仍保持严格匹配——它们解决的是「取到哪一个带身份的操作者实例」,不是权限问题。

留痕口径:被办理记录保留其归属身份(`currentOperatorIdentity`,由取人脚本决定),本次操作携带的身份写入下游新生成记录的 `submitOperatorIdentity`;`USER_ONLY` 下同人换身份不算「被干预」,因此不会写 `interferedOperator*`。
留痕口径(`USER_ONLY` 下同人换身份不算「被干预」,因此不会写 `interferedOperator*`):

| 字段 | 语义 | 写入时机 |
|------|------|----------|
| `currentOperatorId/Name/Identity` | 这条待办的**归属**人(由取人脚本决定) | 记录生成时;办结后**不变** |
| `submitOperatorId/Name/Identity` | **创建这条记录时**的上游提交人 | 记录生成时 |
| `handleOperatorId/Name/Identity` | **本次办理人**——谁、以什么身份办的 | 办结动作(通过 / 拒绝 / 退回 / 转办 / 委派);暂存与抄送刷新不写 |

因此「办结」不会改写归属身份,只额外留下办理人三元组。

> **issue #306 之前的行为**:办理动作不写任何身份字段,最后一步办理人身份**无处落地**——没有下游记录可以承载
> `submitOperator*`,于是「张三以 `department2` 审批通过」在库里只能看到 `department1`(待办归属)或默认身份。
> 中间节点只能跳一条到下游记录的 `submitOperatorIdentity` 间接推断,且要求下游是同一个人。
> 升级后请以 `handleOperator*` 作为「已办是谁办的」的唯一口径。

`FlowRecord#markHandleOperator(IFlowOperator)` 由办结动作显式调用,**不在 `update()` 内隐式写入**:`update()` 同时服务于
暂存(`SaveAction`,`pass=false`)与抄送刷新(`notifyRecord`),隐式写入会把暂存人、抄送接收人误记成办理人。

### 4.5 身份写入约束

Expand Down Expand Up @@ -353,6 +371,7 @@ codingapi.flow.identity.match-mode=USER_ONLY
| 身份长度 | ≤ 64 字符(复合 key 用 `:` 拼接),入口与落库双处校验 |
| 待办索引 | 实体未声明 `@Index`,大表请按 DDL 脚本手工加索引 |
| 默认取人脚本 | issue #303 起新建节点的默认脚本返回 `OperatorKey`(创建者以发起身份参与);存量流程定义中的旧脚本不受影响,不迁移 |
| 办理人留痕 | issue #306 起 `handle_operator_*` 记录办理人与办理身份;存量记录为空,前端回退到 `current_operator_identity` 展示,行为与升级前一致;如需回填,按 `finish_time` 与下游 `submit_operator_*` 推断,引擎不做自动迁移 |
| 不做的事 | 引擎不建组织模型、不做身份授权校验(「user1 能否以 department1 身份操作」由业务侧保证)、不冻结身份名称 |

> 身份是一个**不透明字符串**,不要尝试在引擎里比较它的业务含义;需要「部门名称」等展示信息,由宿主维护 `identity → 名称` 的映射自行渲染(框架不提供附加属性字段)。
Expand Down
12 changes: 12 additions & 0 deletions docs/Integration/sql/0.3.0-operator-identity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ ALTER TABLE t_flow_record ADD COLUMN forward_operator_identity VARCHAR(64) NU
ALTER TABLE t_flow_record ADD COLUMN interfered_operator_identity VARCHAR(64) NULL;


-- -----------------------------------------------------------------------------
-- 1.1 流程记录表:办理人三列(issue #306)
-- -----------------------------------------------------------------------------
-- 背景:此前记录被办结时不写任何身份字段,current_operator_identity 保留的是「待办归属身份」,
-- submit_operator_identity 只表示「创建该记录时的上游提交人」,最后一步办理人身份因此无处可落。
-- 语义:handle_operator_* = 本次实际办理人的 (id, 名称, 身份),暂存与抄送刷新不写入。
-- 兼容:与 current_operator_identity 并存、互不覆盖;历史数据为 NULL,前端可回退到 current_operator_identity。
ALTER TABLE t_flow_record ADD COLUMN handle_operator_id BIGINT NULL;
ALTER TABLE t_flow_record ADD COLUMN handle_operator_name VARCHAR(255) NULL;
ALTER TABLE t_flow_record ADD COLUMN handle_operator_identity VARCHAR(64) NULL;


-- -----------------------------------------------------------------------------
-- 2. 待办表:发起 / 提交 / 当前 三组操作者的身份
-- -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void run(FlowSession flowSession) {

FlowRecord currentRecord = flowSession.getCurrentRecord();
currentRecord.update(flowSession, true);
currentRecord.markHandleOperator(flowSession.getCurrentOperator());

recordList.add(currentRecord);
flowEvents.add(new FlowRecordDoneEvent(currentRecord, flowSession.isMock()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void run(FlowSession flowSession) {

boolean isFinish = currentNode.isFinish(flowSession);
currentRecord.update(flowSession, true);
currentRecord.markHandleOperator(flowSession.getCurrentOperator());
// 添加流程结束事件
flowEvents.add(new FlowRecordDoneEvent(currentRecord, flowSession.isMock()));
recordList.add(currentRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void run(FlowSession flowSession) {

FlowRecord flowRecord = flowSession.getCurrentRecord();
flowRecord.update(flowSession, true);
flowRecord.markHandleOperator(flowSession.getCurrentOperator());
recordList.add(flowRecord);

// 当前审批为已办状态
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void run(FlowSession flowSession) {

FlowRecord currentRecord = flowSession.getCurrentRecord();
currentRecord.update(flowSession, true);
currentRecord.markHandleOperator(flowSession.getCurrentOperator());
recordList.add(currentRecord);

flowEvents.add(new FlowRecordDoneEvent(currentRecord,flowSession.isMock()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void run(FlowSession flowSession) {
FlowRecord currentRecord = flowSession.getCurrentRecord();

currentRecord.update(flowSession, true);
currentRecord.markHandleOperator(flowSession.getCurrentOperator());
recordList.add(currentRecord);
flowEvents.add(new FlowRecordDoneEvent(currentRecord,flowSession.isMock()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public class FlowRecordContent {
*/
private String createOperatorIdentity;

/**
* 办理人Id(issue #306),记录办结时的实际办理人
*/
private Long handleOperatorId;

/**
* 办理人名称(issue #306)
*/
private String handleOperatorName;

/**
* 办理人身份标识(issue #306),空串表示默认身份
*/
private String handleOperatorIdentity;

/**
* 合并记录id,当存在合并记录数据时待办记录数量不会增加,内容会更新至最新的待办数据信息。
* {@link FlowRecord#getTodoKey()}
Expand Down Expand Up @@ -161,6 +176,9 @@ public static FlowRecordContent convert(FlowRecord record){
content.setCreateOperatorId(record.getCreateOperatorId());
content.setCreateOperatorName(record.getCreateOperatorName());
content.setCreateOperatorIdentity(OperatorIdentity.normalize(record.getCreateOperatorIdentity()));
content.setHandleOperatorId(record.getHandleOperatorId());
content.setHandleOperatorName(record.getHandleOperatorName());
content.setHandleOperatorIdentity(OperatorIdentity.normalize(record.getHandleOperatorIdentity()));
content.setMergeable(record.isMergeable());
content.setRecordId(record.getId());
content.setTimeoutTime(record.getTimeoutTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,25 @@ public class FlowRecord {
*/
private String interferedOperatorIdentity;

/**
* 办理人Id(issue #306)
* <p>记录被办结时,本次实际办理人的用户 id;暂存与抄送刷新不写入。
*/
private long handleOperatorId;

/**
* 办理人名称(issue #306)
*/
private String handleOperatorName;

/**
* 办理人身份标识(issue #306)
* <p>本次办理时使用的身份,空串表示默认身份。与「待办归属身份」
* {@link FlowRecord#currentOperatorIdentity} 互不覆盖:办结不改变待办归属,
* 只额外留下「谁以什么身份办的」。
*/
private String handleOperatorIdentity;

/**
* 数据合并的依据,当开启时值为固定值,否则为随机数据
* <p>合并依据由 {@link RecordMergeStrategy.MergeType} 决定:
Expand Down Expand Up @@ -401,6 +420,7 @@ public FlowRecord(FlowSession flowSession, int nodeOrder) {
// 身份字段统一以空串兜底,避免出现 null 与空串两种「默认身份」表达
this.forwardOperatorIdentity = OperatorIdentity.DEFAULT;
this.interferedOperatorIdentity = OperatorIdentity.DEFAULT;
this.handleOperatorIdentity = OperatorIdentity.DEFAULT;
// 是否转交之后的人来审批的判断
if (currentOperator.equals(sourceOperator)) {
this.forwardOperatorId = 0;
Expand Down Expand Up @@ -648,6 +668,28 @@ public void update(FlowSession flowSession, boolean pass) {
}
}

/**
* 记录本次办理人(issue #306)。
*
* <p>必须由「真正办结」的动作显式调用(通过 / 拒绝 / 退回 / 转办 / 委派)。
* 暂存({@link com.codingapi.flow.action.actions.SaveAction})与抄送刷新
* ({@link #notifyRecord(com.codingapi.flow.session.FlowSession)})只是刷新记录内容、
* 并未产生办理结果,因此不能写入,否则会把暂存人、抄送接收人误记为办理人。
*
* <p>不修改 {@link #currentOperatorId} / {@link #currentOperatorIdentity}:
* 待办归属身份在办结后仍需保留(见 docs/Integration/operator-identity.md §4.4)。
*
* @param operator 本次实际办理人
*/
public void markHandleOperator(IFlowOperator operator) {
if (operator == null) {
return;
}
this.handleOperatorId = operator.getUserId();
this.handleOperatorName = operator.getName();
this.handleOperatorIdentity = OperatorIdentity.of(operator);
}

public void clearNotify(){
this.readable = false;
this.readTime = 0;
Expand Down Expand Up @@ -818,6 +860,18 @@ public void newRecord() {
this.setAdvice(null);
this.setSignKey(null);
this.setActionId(null);
// 新记录尚未被办理,不能继承上游记录的办理人信息(issue #306)
this.clearHandleOperator();
}

/**
* 清空办理人信息(issue #306)。
* <p>记录回到「未办理」状态时调用,避免复用记录对象时把上一位办理人带到新的待办上。
*/
public void clearHandleOperator() {
this.handleOperatorId = 0;
this.handleOperatorName = null;
this.handleOperatorIdentity = OperatorIdentity.DEFAULT;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ private static FlowRecord copy(FlowRecord record) {
record.getSubmitOperatorIdentity(),
record.getCurrentOperatorIdentity(),
record.getForwardOperatorIdentity(),
record.getInterferedOperatorIdentity());
record.getInterferedOperatorIdentity(),
record.getHandleOperatorId(),
record.getHandleOperatorName(),
record.getHandleOperatorIdentity());
}
}
Loading