diff --git a/app/core/utils/string_utils.py b/app/core/utils/string_utils.py index b8d5a3e..bd6daf6 100644 --- a/app/core/utils/string_utils.py +++ b/app/core/utils/string_utils.py @@ -225,4 +225,10 @@ def format_barcode(barcode: Any) -> str: # 只保留数字字符 barcode_str = re.sub(r'\D', '', barcode_str) + # 新增:处理末尾多余的0,标准条码通常为12-13位 + if len(barcode_str) > 13 and barcode_str.endswith('0'): + # 从末尾开始移除多余的0,直到条码长度为13位或者不再以0结尾 + while len(barcode_str) > 13 and barcode_str.endswith('0'): + barcode_str = barcode_str[:-1] + return barcode_str \ No newline at end of file