feat: mlog list 支持返回mlogbw number

This commit is contained in:
caoqianming 2025-09-09 14:05:59 +08:00
parent 3906b0f744
commit bc555b7bea
1 changed files with 10 additions and 6 deletions

View File

@ -219,7 +219,7 @@ class MlogViewSet(CustomModelViewSet):
type=openapi.TYPE_STRING, required=False), type=openapi.TYPE_STRING, required=False),
openapi.Parameter(name="with_children", in_=openapi.IN_QUERY, description="带有children(yes/no/count)", openapi.Parameter(name="with_children", in_=openapi.IN_QUERY, description="带有children(yes/no/count)",
type=openapi.TYPE_STRING, required=False), type=openapi.TYPE_STRING, required=False),
openapi.Parameter(name="with_wpr", in_=openapi.IN_QUERY, description="带有wpr(yes/no)", openapi.Parameter(name="with_mlogbw", in_=openapi.IN_QUERY, description="带有个列表(out)",
type=openapi.TYPE_STRING, required=False), type=openapi.TYPE_STRING, required=False),
]) ])
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
@ -271,11 +271,15 @@ class MlogViewSet(CustomModelViewSet):
# if item.get("material_out", None): # if item.get("material_out", None):
# data_dict[item_dict["mlog"]]["mlogb"].append(item_dict) # data_dict[item_dict["mlog"]]["mlogb"].append(item_dict)
# data = list(data_dict.values()) # data = list(data_dict.values())
if self.request.query_params.get('with_wpr', False) == 'yes': if self.request.query_params.get('with_mlogbw', False) == 'out':
pass wpr_dict = {item["id"]: [] for item in data}
# wpr_dict = {item["id"]: None for item in data} wpr_out_qs = Mlogbw.objects.filter(mlogb__mlog__id__in=wpr_dict.keys(),
# wpr_out_qs = Mlogbw.objects.filter(mlogb__mlog__id__in=wpr_dict.keys(), mlogb__material_out__isnull=False).values('mlogb__mlog__id', 'number')
# mlogb__material_out__isnull=False).values_list('mlogb__mlog', 'number') for item in wpr_out_qs:
wpr_dict[item["mlogb__mlog__id"]].append(item["number"])
for item in data:
item["mlogbw_number_list"] = wpr_dict.get(item["id"], None)
return data return data
@lock_model_record_d_method(Mlog) @lock_model_record_d_method(Mlog)