v1.2.53 - 修复编号并发问题+images字段映射
This commit is contained in:
parent
2510f42b68
commit
404b966ba9
|
|
@ -57,6 +57,7 @@ def to_camel_case(data: dict) -> dict:
|
||||||
'f05_43_repair_fee': 'repairFee',
|
'f05_43_repair_fee': 'repairFee',
|
||||||
'f05_44_grading_fee': 'gradingFee',
|
'f05_44_grading_fee': 'gradingFee',
|
||||||
'f06_50_purpose': 'purpose',
|
'f06_50_purpose': 'purpose',
|
||||||
|
'images': 'images',
|
||||||
}
|
}
|
||||||
|
|
||||||
return {mapping.get(k, k): v for k, v in data.items()}
|
return {mapping.get(k, k): v for k, v in data.items()}
|
||||||
|
|
@ -64,25 +65,29 @@ def to_camel_case(data: dict) -> dict:
|
||||||
|
|
||||||
# 编码生成函数
|
# 编码生成函数
|
||||||
def generate_code(version: str, user_id: str, db: Session) -> str:
|
def generate_code(version: str, user_id: str, db: Session) -> str:
|
||||||
"""自动生成藏品编号 - 按用户独立编码"""
|
"""自动生成藏品编号 - 按用户独立编码,使用行锁防止并发冲突"""
|
||||||
import re
|
from sqlalchemy import text
|
||||||
|
|
||||||
# 查询当前用户的非空编码(不与其他用户混算)
|
# 使用 FOR UPDATE 行锁防止并发冲突
|
||||||
user_codes = db.query(Collection.f01_02_code).filter(
|
result = db.execute(
|
||||||
Collection.f01_02_code.isnot(None),
|
text("""
|
||||||
Collection.f99_91_user_id == user_id
|
SELECT f01_02_code FROM collections
|
||||||
).all()
|
WHERE f99_91_user_id = :user_id
|
||||||
|
AND f01_02_code IS NOT NULL
|
||||||
|
AND f01_02_code ~ '^\\d{4,5}$'
|
||||||
|
ORDER BY f01_02_code::int DESC
|
||||||
|
LIMIT 1
|
||||||
|
FOR UPDATE
|
||||||
|
"""),
|
||||||
|
{"user_id": user_id}
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
max_num = 0
|
max_num = 0
|
||||||
for (code,) in user_codes:
|
if result and result[0]:
|
||||||
# 处理纯数字编码(支持4位和5位)
|
try:
|
||||||
if re.match(r'^\d{4,5}$', code):
|
max_num = int(result[0])
|
||||||
try:
|
except (ValueError, TypeError):
|
||||||
num = int(code)
|
pass
|
||||||
if num > max_num:
|
|
||||||
max_num = num
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 当前用户最大号 +1
|
# 当前用户最大号 +1
|
||||||
next_num = max_num + 1
|
next_num = max_num + 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue