fix: batchlog batches_to 优化
This commit is contained in:
parent
31d0dc4829
commit
30f8d484d1
|
@ -16,6 +16,7 @@ from django.db.models import Max
|
|||
import re
|
||||
from django.db.models import Q
|
||||
import django.utils.timezone as timezone
|
||||
from apps.utils.sql import query_all_dict
|
||||
|
||||
# Create your models here.
|
||||
class SfLog(CommonADModel):
|
||||
|
@ -803,7 +804,30 @@ class BatchLog(BaseModel):
|
|||
|
||||
@classmethod
|
||||
def batches_to(cls, batch:str):
|
||||
batches = BatchLog.objects.filter(source__batch=batch, relation_type="split").values_list("target__batch", flat=True).distinct()
|
||||
|
||||
# query = """
|
||||
# SELECT batch FROM wpm_batchst
|
||||
# WHERE batch ~ %s
|
||||
# """
|
||||
query = """
|
||||
SELECT batch
|
||||
FROM wpm_batchst
|
||||
WHERE batch ~ %s
|
||||
ORDER BY
|
||||
-- 先按前缀部分排序(例如 'A')
|
||||
SUBSTRING(batch FROM '^(.*)-') DESC,
|
||||
-- 再按后缀的数值部分排序(将 '2', '11' 转为整数)
|
||||
CAST(SUBSTRING(batch FROM '-([0-9]+)$') AS INTEGER) DESC
|
||||
""" # 排序可在sql层处理
|
||||
query_ = """SELECT batch FROM wpm_batchst WHERE batch ~ %s"""
|
||||
pattern = f'^{batch}-[0-9]+$'
|
||||
|
||||
"""可以用如下方法直接查询
|
||||
"""
|
||||
# batches = BatchLog.objects.filter(source__batch=batch, relation_type="split").values_list("target__batch", flat=True).distinct()
|
||||
# batches = sorted(list(batches), key=custom_key)
|
||||
batches_r = query_all_dict(query_, params=(pattern,))
|
||||
batches = [b["batch"] for b in batches_r]
|
||||
batches = sorted(list(batches), key=custom_key)
|
||||
last_batch_num = None
|
||||
if batches:
|
||||
|
|
Loading…
Reference in New Issue