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: