From 556f8d8020480757c92d99073de213eb16a99535 Mon Sep 17 00:00:00 2001 From: houhuan Date: Fri, 30 May 2025 12:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9D=A1=E7=A0=81=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E9=97=AE=E9=A2=98=EF=BC=9A=E5=9C=A8=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=A4=84=E7=90=86=E8=BF=87=E9=95=BF=E6=9D=A1?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=9C=AB=E5=B0=BE=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=840=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=9D=A1?= =?UTF-8?q?=E7=A0=81=E4=B8=8D=E4=BC=9A=E8=B6=85=E8=BF=87=E6=A0=87=E5=87=86?= =?UTF-8?q?=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/excel/validators.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/core/excel/validators.py b/app/core/excel/validators.py index 0551096..beae53b 100644 --- a/app/core/excel/validators.py +++ b/app/core/excel/validators.py @@ -60,6 +60,20 @@ class ProductValidator: original_barcode = barcode_clean barcode_clean = '6' + barcode_clean[1:] logger.info(f"修正条码前缀 5->6: {original_barcode} -> {barcode_clean}") + + # 新增:处理14位条码,如果多余长度都是0,截断为13位 + if len(barcode_clean) > 13: + original_length = len(barcode_clean) + # 检查多余部分是否都是0 + if barcode_clean.endswith('0'): + # 从末尾开始移除0,直到条码长度为13位或不再以0结尾 + while len(barcode_clean) > 13 and barcode_clean.endswith('0'): + barcode_clean = barcode_clean[:-1] + logger.info(f"修正条码长度: 从{original_length}位截断到{len(barcode_clean)}位") + else: + error_message = f"条码长度异常: {barcode_clean}, 长度={len(barcode_clean)}" + logger.warning(error_message) + return False, barcode_clean, error_message # 验证条码长度 if len(barcode_clean) < 8 or len(barcode_clean) > 13: