From 07c996964d540b3aad8ebae13a7b19897ee6b003 Mon Sep 17 00:00:00 2001 From: zty Date: Thu, 9 Jan 2025 13:36:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20wpm/sflog=20=E5=A2=9E=E5=8A=A0=20enstat?= =?UTF-8?q?=20=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/views.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 2b897d69..66a555d3 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -31,6 +31,7 @@ from apps.wpm.services import mlog_submit_validate, generate_new_batch from apps.wf.models import State from apps.wpmw.models import Wpr from apps.qm.models import QctMat, Ftest +from apps.enm.models import EnStat # Create your views here. @@ -58,7 +59,7 @@ class StLogViewSet(CustomModelViewSet): return super().destroy(request, *args, **kwargs) -class SfLogViewSet(UpdateModelMixin, ListModelMixin, DestroyModelMixin, CustomGenericViewSet): +class SfLogViewSet(UpdateModelMixin, CustomListModelMixin, DestroyModelMixin, CustomGenericViewSet): """ list:值班记录 @@ -72,6 +73,16 @@ class SfLogViewSet(UpdateModelMixin, ListModelMixin, DestroyModelMixin, CustomGe search_fields = ['note'] ordering = ['-start_time'] + def add_info_for_list(self, data): + sflogs = [i['id'] for i in data] + sflogs_dict = EnStat.objects.filter(sflog_id__in=sflogs).values('sflog_id', 'total_production','qua_data','production_hour','elec_consume_unit','run_rate','production_cost_unit') + # 创建索引 + sflogs_dict = {x['sflog_id']: x for x in sflogs_dict} + for item in data: + if item['id'] in sflogs_dict: + item.update({"enstat_info": sflogs_dict[item['id']]}) + return data + @action(methods=['get'], detail=True, perms_map={'get': '*'}) def init_test(self, request, pk=None): """ @@ -96,8 +107,8 @@ class SfLogViewSet(UpdateModelMixin, ListModelMixin, DestroyModelMixin, CustomGe 'material__sort', 'material__create_time', 'testitem__sort', 'testitem__create_time') sr = QuaStatSerializer(instance=qs, many=True) return Response(sr.data) - - + + class SfLogExpViewSet(ListModelMixin, UpdateModelMixin, CustomGenericViewSet): """ list:异常值班处理