fix(core): 消除乐观锁 version.unwrap() 潜在 panic
20 处 ActiveValue::unwrap() + 1 乐观锁递增改为 take().unwrap_or(0) + 1, 避免数据库记录缺少 version 字段时 panic。覆盖 erp-auth/erp-config/ erp-workflow/erp-health/erp-ai/erp-server 7 个 crate。 DTO 层 Option<i32> 字段保持原有 unwrap_or(0) 不变。
This commit is contained in:
@@ -383,7 +383,7 @@ impl MenuService {
|
||||
active.deleted_at = Set(Some(now));
|
||||
active.updated_at = Set(now);
|
||||
active.updated_by = Set(operator_id);
|
||||
active.version = Set(active.version.unwrap() + 1);
|
||||
active.version = Set(active.version.take().unwrap_or(0) + 1);
|
||||
active
|
||||
.update(db)
|
||||
.await
|
||||
|
||||
@@ -392,7 +392,7 @@ impl NumberingService {
|
||||
active.seq_current = Set(next_seq);
|
||||
active.last_reset_date = Set(Some(today));
|
||||
active.updated_at = Set(Utc::now());
|
||||
active.version = Set(active.version.unwrap() + 1);
|
||||
active.version = Set(active.version.take().unwrap_or(0) + 1);
|
||||
active
|
||||
.update(txn)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user