From 45e02eae5fc822a266b1b572890fe5e455f79182 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 29 May 2025 15:30:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96batches=5Fto=E4=BB=A5?= =?UTF-8?q?=E8=BE=BE=E5=88=B0=E8=87=AA=E7=84=B6=E6=8E=92=E5=BA=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/models.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 70f143f4..6ccbec23 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -13,6 +13,7 @@ from rest_framework.exceptions import ParseError from django.db.models import Count from django.db import transaction from django.db.models import Max +import re # Create your models here. class SfLog(CommonADModel): @@ -673,7 +674,11 @@ class BatchSt(BaseModel): handover = Handover.objects.filter(mtype=20, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 拆分 handover2 = Handover.objects.filter(mtype=10, b_handover__batch=batch, submit_time__isnull=False).order_by('submit_time').first() # 合并 return ins - + +def custom_key(s): + match = re.search(r'(\d+)(?!.*\d)', s) # 匹配最后一个数字 + return int(match.group(1)) if match else float('inf') + class BatchLog(BaseModel): """ TN: 拆合批变更记录 @@ -709,8 +714,8 @@ class BatchLog(BaseModel): @classmethod def batches_to(cls, batch:str): - batches = BatchLog.objects.filter(source__batch=batch).values_list("target__batch", flat=True).order_by("target__batch").distinct() - batches = list(batches) + batches = BatchLog.objects.filter(source__batch=batch).values_list("target__batch", flat=True).distinct() + batches = sorted(list(batches), key=custom_key) last_batch_num = None if batches: last_batch = batches[-1]