feat: 增加能耗统计记录表
This commit is contained in:
parent
a49fc7abe9
commit
caaeb32817
|
@ -1,5 +1,5 @@
|
|||
from django_filters import rest_framework as filters
|
||||
from apps.enm.models import MpointStat
|
||||
from apps.enm.models import MpointStat, EnStat
|
||||
|
||||
class MpointStatFilter(filters.FilterSet):
|
||||
has_create_by = filters.BooleanFilter(method='filter_has_create_by')
|
||||
|
@ -17,7 +17,9 @@ class MpointStatFilter(filters.FilterSet):
|
|||
"year": ["exact"],
|
||||
"day_s": ["exact"],
|
||||
"month_s": ["exact"],
|
||||
"year_s": ["exact"]
|
||||
"year_s": ["exact"],
|
||||
"create_by": ["exact"],
|
||||
"type": ["exact"]
|
||||
}
|
||||
|
||||
def filter_has_create_by(self, queryset, name, value):
|
||||
|
@ -25,4 +27,18 @@ class MpointStatFilter(filters.FilterSet):
|
|||
queryset = queryset.exclude(create_by=None)
|
||||
else:
|
||||
queryset = queryset.filter(create_by=None)
|
||||
return queryset
|
||||
return queryset
|
||||
|
||||
|
||||
class EnStatFilter(filters.FilterSet):
|
||||
class Meta:
|
||||
model = EnStat
|
||||
fields = {
|
||||
"mgroup": ["exact"],
|
||||
"mgroup__belong_dept": ["exact"],
|
||||
"type": ["exact"],
|
||||
"sflog": ["exact"],
|
||||
"day_s": ["exact"],
|
||||
"month_s": ["exact"],
|
||||
"year_s": ["exact"]
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.enm.models import Mpoint, MpLog, MpointStat
|
||||
from apps.enm.models import Mpoint, MpLog, MpointStat, EnStat
|
||||
from apps.utils.constants import EXCLUDE_FIELDS
|
||||
from rest_framework import serializers
|
||||
from apps.mtm.models import Mgroup
|
||||
|
@ -68,4 +68,11 @@ class MpointStatSerializer(CustomModelSerializer):
|
|||
# if not self.check_required_keys(attrs, keys[ind+1:]):
|
||||
# raise ParseError('缺少数据')
|
||||
# attrs['type'] = key
|
||||
return super().validate(attrs)
|
||||
return super().validate(attrs)
|
||||
|
||||
|
||||
class EnStatSerializer(CustomModelSerializer):
|
||||
mgroup_name = serializers.CharField(source='mgroup.name', read_only=True)
|
||||
class Meta:
|
||||
model = EnStat
|
||||
fields = '__all__'
|
|
@ -1,6 +1,6 @@
|
|||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from apps.enm.views import (MpointViewSet, MpLogViewSet, MpointStatViewSet)
|
||||
from apps.enm.views import (MpointViewSet, MpLogViewSet, MpointStatViewSet, EnStatViewSet)
|
||||
|
||||
API_BASE_URL = 'api/enm/'
|
||||
HTML_BASE_URL = 'enm/'
|
||||
|
@ -9,6 +9,7 @@ router = DefaultRouter()
|
|||
router.register('mpoint', MpointViewSet, basename='mpoint')
|
||||
router.register('mplog', MpLogViewSet, basename='mplog')
|
||||
router.register('mpointstat', MpointStatViewSet, basename='mpointstat')
|
||||
router.register('enstat', EnStatViewSet, basename='enstat')
|
||||
urlpatterns = [
|
||||
path(API_BASE_URL, include(router.urls)),
|
||||
]
|
|
@ -1,10 +1,10 @@
|
|||
from django.shortcuts import render
|
||||
from apps.enm.models import Mpoint, MpLog, MpointStat
|
||||
from apps.enm.models import Mpoint, MpLog, MpointStat, EnStat
|
||||
from apps.utils.viewsets import CustomModelViewSet, CustomGenericViewSet
|
||||
from rest_framework.mixins import ListModelMixin
|
||||
from apps.utils.mixins import BulkCreateModelMixin, BulkDestroyModelMixin
|
||||
from apps.enm.serializers import (MpointSerializer, MpLogSerializer, MpointStatSerializer)
|
||||
from apps.enm.filters import MpointStatFilter
|
||||
from apps.enm.serializers import (MpointSerializer, MpLogSerializer, MpointStatSerializer, EnStatSerializer)
|
||||
from apps.enm.filters import MpointStatFilter, EnStatFilter
|
||||
from apps.enm.tasks import cal_mpointstat_manual
|
||||
|
||||
|
||||
|
@ -54,3 +54,16 @@ class MpointStatViewSet(BulkCreateModelMixin, BulkDestroyModelMixin, ListModelMi
|
|||
mpoint, year_s, month_s, day_s = instance.mpoint, instance.year_s, instance.month_s, instance.day_s
|
||||
instance.delete()
|
||||
cal_mpointstat_manual(mpoint.id, year_s, month_s, day_s)
|
||||
|
||||
|
||||
class EnStatViewSet(ListModelMixin, CustomGenericViewSet):
|
||||
"""
|
||||
list:能耗统计记录
|
||||
|
||||
能耗统计记录
|
||||
"""
|
||||
perms_map = {'get': '*'}
|
||||
queryset = EnStat.objects.all()
|
||||
serializer_class = EnStatSerializer
|
||||
select_related_fields = ['mgroup']
|
||||
filterset_class = EnStatFilter
|
Loading…
Reference in New Issue