diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 4574fddd..70f143f4 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -705,4 +705,22 @@ class BatchLog(BaseModel): cls.objects.filter(mlog=mlog).delete() BatchSt.objects.filter(mlog=mlog).delete() if mio: - BatchSt.objects.filter(mio=mio).delete() \ No newline at end of file + BatchSt.objects.filter(mio=mio).delete() + + @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) + last_batch_num = None + if batches: + last_batch = batches[-1] + last_batch_list = last_batch.split("-") + if last_batch_list: + try: + last_batch_num = int(last_batch_list[-1]) + except Exception: + pass + return {"batches": batches, "last_batch_num": last_batch_num, "last_batch": last_batch} + return {"batches": [], "last_batch_num": None, "last_batch": None} + + \ No newline at end of file diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 11f1a23b..d3544383 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -883,4 +883,16 @@ class BatchLogViewSet(ListModelMixin, CustomGenericViewSet): version = request.data.get("version", 1) if not batch: raise ParseError("缺少batch参数") - return Response(get_batch_dag(batch, version)) \ No newline at end of file + return Response(get_batch_dag(batch, version)) + + @action(methods=['post'], detail=False, perms_map={'post': '*'}, serializer_class=Serializer) + def batches_to(self, request, *args, **kwargs): + """获取已指向的批次号 + + 获取已指向的批次号 + """ + data = request.data + batch = data.get("batch", None) + if not batch: + raise ParseError("请指定批次号") + return Response(BatchLog.batches_to(batch=batch)) \ No newline at end of file