From 53e907411d8c345ce92c264f6b9dc97472187789 Mon Sep 17 00:00:00 2001 From: houhuan Date: Fri, 30 May 2025 12:14:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9D=A1=E7=A0=81=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=97=AE=E9=A2=98=EF=BC=9A=E4=BF=AE=E6=94=B9format=5F?= =?UTF-8?q?barcode=E5=87=BD=E6=95=B0=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=9C=AB?= =?UTF-8?q?=E5=B0=BE=E5=A4=9A=E4=BD=99=E7=9A=840=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E6=9D=A1=E7=A0=81=E4=B8=8D=E4=BC=9A=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E6=A0=87=E5=87=86=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/utils/string_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) 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