輕量方案:狀態字段流轉
CREATE TABLE application (
id BIGINT PRIMARY KEY,
status TINYINT NOT NULL DEFAULT 0, -- 0草稿 1提交 2一級通過 3一級駁回 4二級通過 5二級駁回 6結束
content JSON,
creator BIGINT,
create_time DATETIME
);
流程邏輯
- 提交:
status=0 → 1(校驗權限)。
- 一級審核:
status=1 → 2/3(記錄審核人、意見、時間)。
- 二級審核:
status=2 → 4/5。
- 結束:
status=4 → 6(自動或人工)。
代碼模板
@Transactional
public boolean audit(long id, int currentStatus, int nextStatus, String opinion, long auditor) {
int rows = jdbc.update(
"UPDATE application SET status=?, auditor=?, opinion=?, audit_time=NOW() " +
"WHERE id=? AND status=?", // 樂觀鎖防併發
nextStatus, auditor, opinion, id, currentStatus);
return rows == 1;
}
何時引入引擎
- 流程定義頻繁變更、需可視化建模。
- 複雜分支/並行/會簽/委派/超時升級。
- 需合規審計、流程實例完整追溯。