修复9位数字被错误矫正问题
This commit is contained in:
parent
5e8c0af131
commit
bfd412e726
|
|
@ -1279,15 +1279,15 @@ async def batch_parse_deals(text: str = Body(..., embed=True)):
|
||||||
data = json.loads(content.strip())
|
data = json.loads(content.strip())
|
||||||
# 对AI返回的数据进行冠字号矫正
|
# 对AI返回的数据进行冠字号矫正
|
||||||
def normalize_serial_ai(num_str):
|
def normalize_serial_ai(num_str):
|
||||||
"""矫正冠字号:确保是J0+9位数字"""
|
"""矫正冠字号:确保是J0+9位数字,只对位数不对的进行矫正"""
|
||||||
if not num_str.startswith('J0'):
|
if not num_str.startswith('J0'):
|
||||||
return None
|
return None
|
||||||
num = num_str[2:] # 去掉J0
|
num = num_str[2:] # 去掉J0
|
||||||
diff = 9 - len(num)
|
diff = 9 - len(num)
|
||||||
|
# 位数正好9位,不需要矫正
|
||||||
if diff == 0:
|
if diff == 0:
|
||||||
return num_str
|
return num_str
|
||||||
elif diff == -1:
|
elif diff == -1:
|
||||||
# 多1位,去掉倒数第4位
|
|
||||||
if len(num) >= 4:
|
if len(num) >= 4:
|
||||||
result = num[:5] + num[-4:]
|
result = num[:5] + num[-4:]
|
||||||
if len(result) == 9:
|
if len(result) == 9:
|
||||||
|
|
@ -1379,22 +1379,22 @@ def parse_deals_locally(text: str, default_packaging: str = '', default_date: st
|
||||||
if not serial_match:
|
if not serial_match:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 冠字号矫正函数
|
# 冠字号矫正函数 - 只对位数不对的进行矫正
|
||||||
def normalize_serial(num_str):
|
def normalize_serial(num_str):
|
||||||
"""矫正冠字号:确保是J0+9位数字"""
|
"""矫正冠字号:确保是J0+9位数字"""
|
||||||
num = num_str
|
num = num_str
|
||||||
diff = 9 - len(num)
|
diff = 9 - len(num)
|
||||||
|
|
||||||
|
# 位数正好9位,不需要矫正
|
||||||
if diff == 0:
|
if diff == 0:
|
||||||
return 'J0' + num
|
return 'J0' + num
|
||||||
|
# 位数不对才需要矫正
|
||||||
elif diff == -1:
|
elif diff == -1:
|
||||||
# 多1位(10位数字)→ 去掉倒数第4位
|
# 多1位(10位数字)→ 去掉倒数第4位
|
||||||
# 例如: 298810101 → 去掉第4位(0) → 2988101 + 01 = 298810101 (9位)
|
|
||||||
if len(num) >= 4:
|
if len(num) >= 4:
|
||||||
# 取前5位 + 最后4位
|
|
||||||
result = num[:5] + num[-4:]
|
result = num[:5] + num[-4:]
|
||||||
if len(result) == 9:
|
if len(result) == 9:
|
||||||
return 'J0' + result
|
return 'J0' + result
|
||||||
# 如果还是不对,尝试去掉第5位
|
|
||||||
result2 = num[:4] + num[-5:]
|
result2 = num[:4] + num[-5:]
|
||||||
if len(result2) == 9:
|
if len(result2) == 9:
|
||||||
return 'J0' + result2
|
return 'J0' + result2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue