diff --git a/apps/enp/views.py b/apps/enp/views.py index 08df06c2..dd0bd408 100644 --- a/apps/enp/views.py +++ b/apps/enp/views.py @@ -18,27 +18,28 @@ class DrainViewSet(CustomModelViewSet): 排口/污染源 """ + queryset = Drain.objects.all() serializer_class = DrainSerializer - filterset_fields = ['type', 'cate', 'mgroup', 'level'] - select_related_fields = ['mgroup'] + filterset_fields = ["type", "cate", "mgroup", "level"] + select_related_fields = ["mgroup"] def get_serializer_class(self): - has_equipdata = self.request.query_params.get('has_equipdata', 'no') - if self.request.method == 'GET' and has_equipdata == 'yes': + has_equipdata = self.request.query_params.get("has_equipdata", "no") + if self.request.method == "GET" and has_equipdata == "yes": return Drain2Serializer return super().get_serializer_class() - @swagger_auto_schema(manual_parameters=[ - openapi.Parameter(name="has_equipdata", in_=openapi.IN_QUERY, description="Include equip data in the response", - type=openapi.TYPE_STRING, enum=["yes", "no"], required=False), - openapi.Parameter(name="query", in_=openapi.IN_QUERY, description="定制返回数据", - type=openapi.TYPE_STRING, required=False), - ]) + @swagger_auto_schema( + manual_parameters=[ + openapi.Parameter(name="has_equipdata", in_=openapi.IN_QUERY, description="Include equip data in the response", type=openapi.TYPE_STRING, enum=["yes", "no"], required=False), + openapi.Parameter(name="query", in_=openapi.IN_QUERY, description="定制返回数据", type=openapi.TYPE_STRING, required=False), + ] + ) def list(self, request, *args, **kwargs): return super().list(request, *args, **kwargs) - @action(methods=['get'], detail=False, perms_map={'get': '*'}) + @action(methods=["get"], detail=False, perms_map={"get": "*"}) def count_cate(self, request, *args, **kwargs): """排口分类数量 @@ -46,20 +47,12 @@ class DrainViewSet(CustomModelViewSet): """ queryset = self.filter_queryset(self.get_queryset()) result = queryset.aggregate( - count=Count('id'), - count_product=Count( - Case(When(cate='product', then=1), output_field=IntegerField())), - count_mtrans=Count( - Case(When(cate='mtrans', then=1), output_field=IntegerField())), - count_mstore=Count( - Case(When(cate='mstore', then=1), output_field=IntegerField())), + count=Count("id"), + count_product=Count(Case(When(cate="product", then=1), output_field=IntegerField())), + count_mtrans=Count(Case(When(cate="mtrans", then=1), output_field=IntegerField())), + count_mstore=Count(Case(When(cate="mstore", then=1), output_field=IntegerField())), ) - json_result = { - 'count': result['count'], - 'count_product': result['count_product'], - 'count_mtrans': result['count_mtrans'], - 'count_mstore': result['count_mstore'] - } + json_result = {"count": result["count"], "count_product": result["count_product"], "count_mtrans": result["count_mtrans"], "count_mstore": result["count_mstore"]} return Response(json_result) @@ -70,23 +63,24 @@ class DrainEquipViewSet(ListModelMixin, BulkCreateModelMixin, BulkDestroyModelMi 排口/设备关系 """ - perms_map = {'get': '*', 'post:': 'drain.update', 'delete': 'drain.update'} + + perms_map = {"get": "*", "post:": "drain.update", "delete": "drain.update"} queryset = DrainEquip.objects.all() serializer_class = DrainEquipSerializer - select_related_fields = ['equipment', 'drain'] - filterset_fields = ['drain', 'equipment', - 'drain__mgroup', 'equipment__mgroup', 'drain__type', 'equipment__type'] + select_related_fields = ["equipment", "drain"] + filterset_fields = ["drain", "equipment", "drain__mgroup", "equipment__mgroup", "drain__type", "equipment__type"] def get_serializer_class(self): - has_envdata = self.request.query_params.get('has_envdata', 'no') - if self.request.method == 'GET' and has_envdata == 'yes': + has_envdata = self.request.query_params.get("has_envdata", "no") + if self.request.method == "GET" and has_envdata == "yes": return DrainEquipEnvSerializer return super().get_serializer_class() - @swagger_auto_schema(manual_parameters=[ - openapi.Parameter(name="has_envdata", in_=openapi.IN_QUERY, description="Include environmental data in the response", - type=openapi.TYPE_STRING, enum=["yes", "no"], required=False), - ]) + @swagger_auto_schema( + manual_parameters=[ + openapi.Parameter(name="has_envdata", in_=openapi.IN_QUERY, description="Include environmental data in the response", type=openapi.TYPE_STRING, enum=["yes", "no"], required=False), + ] + ) def list(self, request, *args, **kwargs): return super().list(request, *args, **kwargs) @@ -97,15 +91,16 @@ class VehicleAccessViewSet(ListModelMixin, CustomGenericViewSet): 车辆出入记录 """ - perms_map = {'get': '*'} + + perms_map = {"get": "*"} queryset = VehicleAccess.objects.all() serializer_class = VehicleAccessSerializer filterset_fields = { - "vehicle_number": ['icontains'], - "emission_standard": ['exact', 'in'], - "type": ['exact', 'in'], + "vehicle_number": ["icontains"], + "emission_standard": ["exact", "in"], + "type": ["exact", "in"], "is_new_energy": ["exact"], - "access_time": ['gte', 'lte', 'year', 'month', 'day', 'quarter', 'week'] + "access_time": ["gte", "lte", "year", "month", "day", "quarter", "week"], } @@ -115,18 +110,18 @@ class EnvDataViewSet(ListModelMixin, CustomGenericViewSet): 环保时序数据 """ - perms_map = {'get': '*'} + + perms_map = {"get": "*"} queryset = EnvData.objects.all() serializer_class = EnvDataSerializer filterset_fields = { - "time": ['exact', 'gte', 'lte', 'year', 'month', 'day'], - "equipment": ['exact'], + "timex": ["exact", "gte", "lte", "year", "month", "day"], + "equipment": ["exact"], } - ordering_fields = ['time'] - ordering = ['-time'] + ordering_fields = ["time"] + ordering = ["-time"] - @action(methods=['post'], detail=False, perms_map={'post': '*'}, - serializer_class=EnvDataExportSerializer) + @action(methods=["post"], detail=False, perms_map={"post": "*"}, serializer_class=EnvDataExportSerializer) def export_excel(self, request, *args, **kwargs): """导出Excel @@ -141,12 +136,13 @@ class CarWashViewSet(ListModelMixin, CustomGenericViewSet): 洗车记录 """ - perms_map = {'get': '*'} + + perms_map = {"get": "*"} queryset = CarWash.objects.all() serializer_class = CarWashSerializer - select_related_fields = ['station'] + select_related_fields = ["station"] filterset_fields = { - "station": ['exact'], - "start_time": ['exact', 'gte', 'lte', 'year', 'month', 'day'], + "station": ["exact"], + "start_time": ["exact", "gte", "lte", "year", "month", "day"], } - ordering = ['-start_time'] + ordering = ["-start_time"]