From 3be0b09cd935373b9d1806c22784f5963472c07c Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 13 Jul 2026 22:43:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:batchst=E6=8E=A5=E5=8F=A3=E6=94=AF?= =?UTF-8?q?=E6=8C=81with=5Fzt=5Fbig=E9=99=84=E5=B8=A6=E7=9B=B4=E9=80=9A?= =?UTF-8?q?=E5=A4=A7=E6=89=B9=E6=95=B0=E6=8D=AE=E5=8F=8Azt=5Fbatch?= =?UTF-8?q?=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 小批查询时?with_zt_big=yes每行附zt_big=所属大批完整BatchSt(含直通_*); zt_batch加入过滤字段, 可按大批号反查全部子批 Co-Authored-By: Claude Fable 5 --- apps/wpm/filters.py | 4 +++- apps/wpm/scripts/batch_gxerp.md | 5 +++++ apps/wpm/views.py | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/wpm/filters.py b/apps/wpm/filters.py index 0b636512..f4423459 100644 --- a/apps/wpm/filters.py +++ b/apps/wpm/filters.py @@ -243,10 +243,11 @@ class BatchStFilter(filters.FilterSet): batch__startswith__in = filters.CharFilter(method='filter_batch') data__has_key = filters.CharFilter(method='filter_data') with_source_near = filters.CharFilter(label='来源', method='filter_source_near') + with_zt_big = filters.CharFilter(label='附带直通大批', method='filter_source_near') def filter_source_near(self, queryset, name, value): return queryset - + def filter_data(self, queryset, name, value): return queryset.filter(data__has_key=value) @@ -254,6 +255,7 @@ class BatchStFilter(filters.FilterSet): model = BatchSt fields = { "batch": ["exact", "contains", "startswith"], + "zt_batch": ["exact", "isnull"], "version": ["exact", "gte", "lte"], "first_time": ["exact", "gte", "lte", "isnull"], "last_time": ["exact", "gte", "lte", "isnull"], diff --git a/apps/wpm/scripts/batch_gxerp.md b/apps/wpm/scripts/batch_gxerp.md index 9cfc7181..bf6bd051 100644 --- a/apps/wpm/scripts/batch_gxerp.md +++ b/apps/wpm/scripts/batch_gxerp.md @@ -259,6 +259,11 @@ FtestWork where type2 = TYPE2_SOME | `直通_良率` | 百分比(不可得/异常为 null) | | `直通_口径` | 白料来源口径:`黑化领用` / `入库数量` / `谱系兜底` 及异常标注 | +### 接口(`/wpm/batchst/`) + +- 响应自带 `zt_batch`(所属大批号);`?with_zt_big=yes` 时每行附 `zt_big` = 所属大批的完整 BatchSt(含 `直通_*`),自身即大批时为 null(直通字段就在本行 data 里)。 +- 过滤:`?zt_batch=<大批号>` 查某大批全部子批;`with_source_near=yes` 仍可附 BatchLog 直接来源批。 + ### 部署 1. `python manage.py migrate wpm`(新增 `BatchSt.zt_batch`,迁移 `0133_batchst_zt_batch`)。 diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 14fb4110..d5a5d2a1 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -1103,6 +1103,14 @@ class BatchStViewSet(CustomListModelMixin, ComplexQueryMixin, CustomGenericViewS source_data_dict = {ins["id"]: ins for ins in source_data} for item in data: item["source_near"] = [source_data_dict[ins["source"]] for ins in batchlog_qs if ins["target"] == item["id"]] + if (self.request.query_params.get("with_zt_big", None) == "yes" or + self.request.data.get("with_zt_big", None) == "yes"): + # 附带所属直通统计大批的数据(zt_batch 指向自身的即大批本身, 不重复附带) + zt_batches = {ins["zt_batch"] for ins in data if ins.get("zt_batch") and ins["zt_batch"] != ins["batch"]} + big_data = BatchStSerializer(instance=BatchSt.objects.filter(batch__in=zt_batches, version=1), many=True).data + big_data_dict = {ins["batch"]: ins for ins in big_data} + for item in data: + item["zt_big"] = big_data_dict.get(item.get("zt_batch")) if item.get("zt_batch") != item["batch"] else None return data class MlogbwViewSet(CustomModelViewSet):