修正冠字号规则:J0+8位或其他J+9位
This commit is contained in:
parent
bc1485663e
commit
29c2d6f3a9
|
|
@ -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':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue