修正冠字号规则:J0+8位或其他J+9位

This commit is contained in:
甲辰生产 2026-04-12 00:46:28 +08:00
parent bc1485663e
commit 29c2d6f3a9
1 changed files with 19 additions and 11 deletions

View File

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