From bfd412e726f701e576713590e41da508dee829b1 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:40:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D9=E4=BD=8D=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E8=A2=AB=E9=94=99=E8=AF=AF=E7=9F=AB=E6=AD=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/information.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index 82db926..1484998 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -1279,15 +1279,15 @@ async def batch_parse_deals(text: str = Body(..., embed=True)): data = json.loads(content.strip()) # 对AI返回的数据进行冠字号矫正 def normalize_serial_ai(num_str): - """矫正冠字号:确保是J0+9位数字""" + """矫正冠字号:确保是J0+9位数字,只对位数不对的进行矫正""" if not num_str.startswith('J0'): return None num = num_str[2:] # 去掉J0 diff = 9 - len(num) + # 位数正好9位,不需要矫正 if diff == 0: return num_str elif diff == -1: - # 多1位,去掉倒数第4位 if len(num) >= 4: result = num[:5] + num[-4:] if len(result) == 9: @@ -1379,22 +1379,22 @@ def parse_deals_locally(text: str, default_packaging: str = '', default_date: st if not serial_match: continue - # 冠字号矫正函数 + # 冠字号矫正函数 - 只对位数不对的进行矫正 def normalize_serial(num_str): """矫正冠字号:确保是J0+9位数字""" num = num_str diff = 9 - len(num) + + # 位数正好9位,不需要矫正 if diff == 0: return 'J0' + num + # 位数不对才需要矫正 elif diff == -1: # 多1位(10位数字)→ 去掉倒数第4位 - # 例如: 298810101 → 去掉第4位(0) → 2988101 + 01 = 298810101 (9位) if len(num) >= 4: - # 取前5位 + 最后4位 result = num[:5] + num[-4:] if len(result) == 9: return 'J0' + result - # 如果还是不对,尝试去掉第5位 result2 = num[:4] + num[-5:] if len(result2) == 9: return 'J0' + result2