forked from erp-dev/erp
feat: added jobs_status_summary to printing orders api
This commit is contained in:
@@ -123,6 +123,10 @@ class PrintingOrderViewSet(LimitedModelViewSet):
|
||||
- created_date_to: 创建日期结束
|
||||
- search: 全文搜索(客户名称、面料、地区、工艺)
|
||||
- ordering: 排序字段
|
||||
|
||||
返回字段说明:
|
||||
- jobs_status_summary: 订单下所有印染任务按当前状态分组的数量汇总
|
||||
格式: [{"state_name": "进度一", "state_id": 1, "count": 3}, ...]
|
||||
"""
|
||||
queryset = models.PrintingOrder.objects.all()
|
||||
permission_classes = [DjangoModelPermissions]
|
||||
@@ -157,6 +161,21 @@ class PrintingOrderViewSet(LimitedModelViewSet):
|
||||
queryset = super().get_queryset()
|
||||
if self.action in ['list', 'retrieve']:
|
||||
queryset = queryset.select_related('customer')
|
||||
# 预取 printing_jobs 及其 business_object,用于状态汇总统计
|
||||
# 同时预取 state_logs 和 process 相关数据以减少 job.status 属性调用时的 N+1 查询
|
||||
queryset = queryset.prefetch_related(
|
||||
Prefetch(
|
||||
'printing_jobs',
|
||||
queryset=models.PrintingJob.objects.select_related(
|
||||
'business_object',
|
||||
'business_object__process',
|
||||
).prefetch_related(
|
||||
'business_object__state_logs',
|
||||
'business_object__process__process_nodes',
|
||||
'business_object__process__process_nodes__state',
|
||||
)
|
||||
)
|
||||
)
|
||||
return queryset
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user