diff --git a/backend/app/routers/collections.py b/backend/app/routers/collections.py index cfad289..7fbf85a 100644 --- a/backend/app/routers/collections.py +++ b/backend/app/routers/collections.py @@ -67,11 +67,11 @@ def generate_code(version: str, user_id: str, db: Session) -> str: """自动生成藏品编号 - 按用户独立编码""" import re - # 查询当前用户的非空编码(不与其他用户混算) + # 查询当前用户的非空编码(不与其他用户混算)- 使用行锁防止并发 user_codes = db.query(Collection.f01_02_code).filter( Collection.f01_02_code.isnot(None), Collection.f99_91_user_id == user_id - ).all() + ).with_for_update().all() max_num = 0 for (code,) in user_codes: