修复冠字号矫正逻辑
This commit is contained in:
parent
a5251a2794
commit
5e8c0af131
|
|
@ -1279,7 +1279,7 @@ 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位数字,最后两位为01"""
|
"""矫正冠字号:确保是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
|
||||||
|
|
@ -1289,17 +1289,19 @@ async def batch_parse_deals(text: str = Body(..., embed=True)):
|
||||||
elif diff == -1:
|
elif diff == -1:
|
||||||
# 多1位,去掉倒数第4位
|
# 多1位,去掉倒数第4位
|
||||||
if len(num) >= 4:
|
if len(num) >= 4:
|
||||||
num = num[:-4] + num[-3:]
|
result = num[:5] + num[-4:]
|
||||||
if len(num) == 9:
|
if len(result) == 9:
|
||||||
return 'J0' + num
|
return 'J0' + result
|
||||||
|
result2 = num[:4] + num[-5:]
|
||||||
|
if len(result2) == 9:
|
||||||
|
return 'J0' + result2
|
||||||
elif diff == 1:
|
elif diff == 1:
|
||||||
# 少1位,加0
|
|
||||||
return 'J0' + '0' + num
|
return 'J0' + '0' + num
|
||||||
elif diff == -2:
|
elif diff == -2:
|
||||||
if len(num) >= 5:
|
if len(num) >= 5:
|
||||||
num = num[:-5] + num[-4:]
|
result = num[:5] + num[-4:]
|
||||||
if len(num) == 9:
|
if len(result) == 9:
|
||||||
return 'J0' + num
|
return 'J0' + result
|
||||||
elif diff == 2:
|
elif diff == 2:
|
||||||
return 'J0' + '00' + num
|
return 'J0' + '00' + num
|
||||||
return None
|
return None
|
||||||
|
|
@ -1379,33 +1381,32 @@ def parse_deals_locally(text: str, default_packaging: str = '', default_date: st
|
||||||
|
|
||||||
# 冠字号矫正函数
|
# 冠字号矫正函数
|
||||||
def normalize_serial(num_str):
|
def normalize_serial(num_str):
|
||||||
"""矫正冠字号:确保是J0+9位数字,最后两位为01"""
|
"""矫正冠字号:确保是J0+9位数字"""
|
||||||
num = num_str
|
num = num_str
|
||||||
diff = 9 - len(num)
|
diff = 9 - len(num)
|
||||||
if diff == 0:
|
if diff == 0:
|
||||||
# 正好9位,检查最后两位是否为01
|
|
||||||
if num[-2:] != '01':
|
|
||||||
# 尝试矫正:去掉倒数第4位(如果倒数第4位不是0)
|
|
||||||
if len(num) >= 4 and num[-4] != '0':
|
|
||||||
num = num[:-4] + num[-3:]
|
|
||||||
if num[-2:] == '01':
|
|
||||||
return 'J0' + num
|
|
||||||
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:
|
||||||
num = num[:-4] + num[-3:]
|
# 取前5位 + 最后4位
|
||||||
if len(num) == 9:
|
result = num[:5] + num[-4:]
|
||||||
return 'J0' + num
|
if len(result) == 9:
|
||||||
|
return 'J0' + result
|
||||||
|
# 如果还是不对,尝试去掉第5位
|
||||||
|
result2 = num[:4] + num[-5:]
|
||||||
|
if len(result2) == 9:
|
||||||
|
return 'J0' + result2
|
||||||
elif diff == 1:
|
elif diff == 1:
|
||||||
# 少1位(8位数字)→ 在J0后加0
|
# 少1位(8位数字)→ 在J0后加0
|
||||||
return 'J0' + '0' + num
|
return 'J0' + '0' + num
|
||||||
elif diff == -2:
|
elif diff == -2:
|
||||||
# 多2位(11位数字)→ 去掉倒数第4、5位
|
# 多2位(11位数字)→ 去掉倒数第4、5位
|
||||||
if len(num) >= 5:
|
if len(num) >= 5:
|
||||||
num = num[:-5] + num[-4:]
|
result = num[:5] + num[-4:]
|
||||||
if len(num) == 9:
|
if len(result) == 9:
|
||||||
return 'J0' + num
|
return 'J0' + result
|
||||||
elif diff == 2:
|
elif diff == 2:
|
||||||
# 少2位(7位数字)→ 在J0后加00
|
# 少2位(7位数字)→ 在J0后加00
|
||||||
return 'J0' + '00' + num
|
return 'J0' + '00' + num
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue