refactor(ops): 状态转换成功不再镜像写 bus_log

问题:每次 transition() 成功 commit 后,OrderTransitionAuditListener 都会
向 bus_log 写一条"状态转换成功: X -> Y"的镜像记录。该信息已由各条线
EventListener(CleanOrderEventListener 的 ORDER_DISPATCHED 等)和
ops_order_event 表完整覆盖,bus_log 里这条镜像形成噪声且与业务日志重复,
线上一次工单流转能产出 4-5 条同义日志,运维抓异常时被淹没。

改动:onAfterCommit 在 event.isSuccess()=true 时直接 return;
失败 / 派发被拒(DISPATCH_REJECTED)/ 回滚三类异常路径继续写,
保留运维真正关心的"为什么失败"审计闭环。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
lzh
2026-04-22 18:03:51 +08:00
parent c78759fd52
commit 8c664a479d

View File

@@ -46,12 +46,20 @@ public class OrderTransitionAuditListener {
private EventLogRecorder eventLogRecorder;
/**
* 主事务已提交:照事件声明写一条审计日志
* 主事务已提交:仅在转换异常路径下写 bus_log
* <p>
* 取舍:成功路径不再写"状态转换成功"镜像记录——业务详情已由各条线 EventListener
* (如 CleanOrderEventListener 的 ORDER_DISPATCHED 等)和 ops_order_event 表覆盖,
* 此处镜像在 bus_log 形成噪声且与业务日志重复。仅保留派发被拒DISPATCH_REJECTED
* 等运维需追溯的异常类型,便于审计真正的"为什么失败"。
* <p>
* fallbackExecution=true在无事务上下文时也执行如测试、跨线程补写场景
*/
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = true)
public void onAfterCommit(OrderTransitionAttemptedEvent event) {
if (event.isSuccess()) {
return;
}
try {
eventLogRecorder.recordSync(toRecord(event, /*rolledBack=*/false));
} catch (Exception e) {