fix(health): 穷尽审计修复 — 3 CRITICAL + 3 HIGH + 2 MEDIUM
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

CRITICAL:
- earn_points 日上限检查用 patient_id 比对 account_id 字段,上限永远不会触发
- verify_order 用 check_version(v, v) 旁路乐观锁,并发核销可能重复
- admin_checkin_event 同样的乐观锁旁路

HIGH:
- FIFO 消费循环改用数据库级 CAS 替代应用层 update_many
- 兑换流程账户余额/库存扣减全部改用 CAS 防并发超卖
- verify_order 改用 update_many + version filter 的原子操作

MEDIUM:
- points_checkin entity 补全 updated_at/updated_by/deleted_at/version 字段
- 新增迁移 m20260425_000055 添加列
- daily_checkin 打卡记录+积分获取+阶梯奖励合并为同一事务
- 删除废弃的 check_streak_bonus 独立函数(被 check_streak_bonus_in_txn 替代)
This commit is contained in:
iven
2026-04-25 19:44:46 +08:00
parent 17085a3e61
commit e8a794ff69
4 changed files with 187 additions and 34 deletions

View File

@@ -54,6 +54,7 @@ mod m20260425_000051_dialysis_and_lab_enhance;
mod m20260425_000052_create_ai_tables;
mod m20260425_000053_create_points_tables;
mod m20260425_000054_create_daily_monitoring;
mod m20260425_000055_points_checkin_standard_fields;
pub struct Migrator;
@@ -115,6 +116,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260425_000052_create_ai_tables::Migration),
Box::new(m20260425_000053_create_points_tables::Migration),
Box::new(m20260425_000054_create_daily_monitoring::Migration),
Box::new(m20260425_000055_points_checkin_standard_fields::Migration),
]
}
}

View File

@@ -0,0 +1,52 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
/// 为 points_checkin 表补全标准字段updated_at, created_by, updated_by, deleted_at, version
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Alias::new("points_checkin"))
.add_column(
ColumnDef::new(Alias::new("updated_at"))
.timestamp_with_time_zone()
.not_null()
.default(Expr::current_timestamp()),
)
.add_column(ColumnDef::new(Alias::new("created_by")).uuid())
.add_column(ColumnDef::new(Alias::new("updated_by")).uuid())
.add_column(ColumnDef::new(Alias::new("deleted_at")).timestamp_with_time_zone())
.add_column(
ColumnDef::new(Alias::new("version"))
.integer()
.not_null()
.default(1),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Alias::new("points_checkin"))
.drop_column(Alias::new("updated_at"))
.drop_column(Alias::new("created_by"))
.drop_column(Alias::new("updated_by"))
.drop_column(Alias::new("deleted_at"))
.drop_column(Alias::new("version"))
.to_owned(),
)
.await?;
Ok(())
}
}