feat:batchst接口支持with_zt_big附带直通大批数据及zt_batch过滤

小批查询时?with_zt_big=yes每行附zt_big=所属大批完整BatchSt(含直通_*);
zt_batch加入过滤字段, 可按大批号反查全部子批

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
caoqianming 2026-07-13 22:43:30 +08:00
parent c4e0fdd265
commit 3be0b09cd9
3 changed files with 16 additions and 1 deletions

View File

@ -243,6 +243,7 @@ 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
@ -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"],

View File

@ -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`)。

View File

@ -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):