From 29c2d6f3a9f89b05120c64fa51887cb9589bd9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Sun, 12 Apr 2026 00:46:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=86=A0=E5=AD=97=E5=8F=B7?= =?UTF-8?q?=E8=A7=84=E5=88=99=EF=BC=9AJ0+8=E4=BD=8D=E6=88=96=E5=85=B6?= =?UTF-8?q?=E4=BB=96J+9=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/information.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index 1c2628b..969be9a 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -452,23 +452,31 @@ def create_information( db: Session = Depends(get_db) ): """发布资讯""" - # 验证并矫正冠字号(J0开头的9位数字) + # 验证并矫正冠字号 if data.title: import re # 提取冠字号 - match = re.search(r'J0(\d+)', data.title) + match = re.search(r'J(\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) + # 根据前缀判断正确位数 + # 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: + num = num[:9] + elif len(num) < 9: + num = num.zfill(9) # 重新构建title - original_num = match.group(0) - data.title = data.title.replace(original_num, 'J0' + num, 1) + original = match.group(0) + data.title = data.title.replace(original, 'J' + num, 1) # 生成行情编号:日期 + 5位自然数(从00001开始) deal_no = None if data.info_type == 'deal':