feat: enp count_cate接口
This commit is contained in:
parent
826cb8c8b1
commit
9d48575be4
|
@ -8,6 +8,7 @@ from apps.utils.sql import query_all_dict
|
|||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
from rest_framework.response import Response
|
||||
from django.db.models import Count, Case, When, IntegerField
|
||||
# Create your views here.
|
||||
|
||||
|
||||
|
@ -34,6 +35,31 @@ class DrainViewSet(CustomModelViewSet):
|
|||
def list(self, request, *args, **kwargs):
|
||||
return super().list(request, *args, **kwargs)
|
||||
|
||||
@action(methods=['get'], detail=False, perms_map={'get': '*'})
|
||||
def count_cate(self, request, *args, **kwargs):
|
||||
"""排口分类数量
|
||||
|
||||
排口分类数量
|
||||
"""
|
||||
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())),
|
||||
)
|
||||
json_result = {
|
||||
'count': result['count'],
|
||||
'count_product': result['count_product'],
|
||||
'count_mtrans': result['count_mtrans'],
|
||||
'count_mstore': result['count_mstore']
|
||||
}
|
||||
|
||||
return Response(json_result)
|
||||
|
||||
|
||||
class DrainEquipViewSet(ListModelMixin, BulkCreateModelMixin, BulkDestroyModelMixin, CustomGenericViewSet):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue