保存时验证冠字号为9位

This commit is contained in:
甲辰生产 2026-04-12 00:42:38 +08:00
parent bfd412e726
commit bc1485663e
1 changed files with 17 additions and 0 deletions

View File

@ -452,6 +452,23 @@ def create_information(
db: Session = Depends(get_db) db: Session = Depends(get_db)
): ):
"""发布资讯""" """发布资讯"""
# 验证并矫正冠字号J0开头的9位数字
if data.title:
import re
# 提取冠字号
match = re.search(r'J0(\d+)', data.title)
if match:
num = match.group(1)
# 矫正位数
if len(num) > 9:
# 多位取前9位
num = num[:9]
elif len(num) < 9:
# 少位前面补0
num = num.zfill(9)
# 重新构建title
original_num = match.group(0)
data.title = data.title.replace(original_num, 'J0' + num, 1)
# 生成行情编号:日期 + 5位自然数从00001开始 # 生成行情编号:日期 + 5位自然数从00001开始
deal_no = None deal_no = None
if data.info_type == 'deal': if data.info_type == 'deal':