|
@@ -22,6 +22,7 @@ from utils.permission import isLogin
|
|
|
from utils.wx.WXBizDataCrypt import WXBizDataCrypt
|
|
|
from apps.tenant.poster.serializer import PosterSerializer, Poster
|
|
|
from apps.tenant.device.models import DeviceModel
|
|
|
+from apps.tenant.repair_order.models import RepairOrder
|
|
|
|
|
|
from .serializers import *
|
|
|
|
|
@@ -97,25 +98,47 @@ class WxBindView(APIView):
|
|
|
else:
|
|
|
return response_error('参数错误')
|
|
|
|
|
|
+class HomeStatisticsView(APIView):
|
|
|
+ '''小程序首页统计数据'''
|
|
|
|
|
|
-class HomeView(generics.ListAPIView):
|
|
|
- '''小程序首页数据'''
|
|
|
-
|
|
|
- queryset = Config.objects.filter()
|
|
|
- serializer_class = ConfigSerializer
|
|
|
+ def get(self, request):
|
|
|
+ statistics = {
|
|
|
+ 'total':0, #总报修
|
|
|
+ 'wait':0, #待维修
|
|
|
+ 'working':0, #维修中
|
|
|
+ 'complete':0, #已完工
|
|
|
+ }
|
|
|
+ if request.user or request.user.is_authenticated:
|
|
|
+ tenant = request.user.employee.tenant
|
|
|
+ rows = RepairOrder.objects.filter(tenant=tenant)
|
|
|
+ statistics['total'] = rows.filter(status__gte=RepairOrder.CHECKED).count()
|
|
|
+ statistics['wait'] = rows.filter(status=RepairOrder.CHECKED).count()
|
|
|
+ statistics['working'] = rows.filter(status=RepairOrder.DISPATCH).count()
|
|
|
+ statistics['complete'] = rows.filter(status__in=[RepairOrder.FINISH,RepairOrder.APPRAISE,]).count()
|
|
|
+ return response_ok(statistics)
|
|
|
+ else:
|
|
|
+ return response_ok(statistics)
|
|
|
|
|
|
- def filter_queryset(self, queryset):
|
|
|
- appid = self.request.GET.get('appid')
|
|
|
- app = WechatApplet.getByAppid(appid)
|
|
|
- queryset = queryset.filter(tenant=app.tenant)
|
|
|
- return queryset
|
|
|
+class StatisticsView(APIView):
|
|
|
+ '''小程序统计数据'''
|
|
|
|
|
|
- def list(self, request, *args, **kwargs):
|
|
|
- try:
|
|
|
- data = super(HomeView, self).list(request)
|
|
|
- except NotFound:
|
|
|
- return response_ok([])
|
|
|
- return data
|
|
|
+ def get(self, request):
|
|
|
+ statistics = {
|
|
|
+ 'total':0, #总报修
|
|
|
+ 'wait':0, #待维修
|
|
|
+ 'working':0, #维修中
|
|
|
+ 'complete':0, #已完工
|
|
|
+ }
|
|
|
+ if request.user or request.user.is_authenticated:
|
|
|
+ tenant = request.user.employee.tenant
|
|
|
+ rows = RepairOrder.objects.filter(tenant=tenant)
|
|
|
+ statistics['total'] = rows.filter(status__gte=RepairOrder.CHECKED).count()
|
|
|
+ statistics['wait'] = rows.filter(status=RepairOrder.CHECKED).count()
|
|
|
+ statistics['working'] = rows.filter(status=RepairOrder.DISPATCH).count()
|
|
|
+ statistics['complete'] = rows.filter(status__in=[RepairOrder.FINISH,RepairOrder.APPRAISE,]).count()
|
|
|
+ return response_ok(statistics)
|
|
|
+ else:
|
|
|
+ return response_ok(statistics)
|
|
|
|
|
|
class PosterView(generics.ListAPIView):
|
|
|
'''小程序首页数据'''
|
|
@@ -175,35 +198,6 @@ class NoticesDetailView(generics.RetrieveAPIView):
|
|
|
def retrieve(self, request, *args, **kwargs):
|
|
|
return response_ok(NoticesWXSerializer(self.get_object()).data)
|
|
|
|
|
|
-
|
|
|
-class BuildingView(APIView):
|
|
|
-
|
|
|
- def get(self, request):
|
|
|
- area = request.GET.get('area')
|
|
|
- data = []
|
|
|
- rows = Building.objects.filter(area=area).values('building').order_by('building').distinct()
|
|
|
- for build in rows:
|
|
|
- build_dict = {
|
|
|
- 'name':build['building'],
|
|
|
- 'childern':[]
|
|
|
- }
|
|
|
- floors = Building.objects.filter(area=area,building=build['building']).values('floor').order_by('floor').distinct()
|
|
|
- for floor in floors:
|
|
|
- floor_dict = {
|
|
|
- 'name': floor['floor'],
|
|
|
- 'childern': []
|
|
|
- }
|
|
|
- build_dict['childern'].append(floor_dict)
|
|
|
- locations = Building.objects.filter(area=area, building=build['building'],floor=floor['floor'])
|
|
|
- for location in locations:
|
|
|
- floor_dict['childern'].append({
|
|
|
- 'id':location.id,
|
|
|
- 'name':location.location,
|
|
|
- })
|
|
|
- data.append(build_dict)
|
|
|
-
|
|
|
- return response_ok(data)
|
|
|
-
|
|
|
class DeviceView(APIView):
|
|
|
permission_classes = [isLogin, ]
|
|
|
def get(self, request):
|