|
@@ -1,16 +1,17 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+from django.db.models import Count
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.contrib.auth.hashers import make_password # 对密码加密模块
|
|
|
-from Model.models import Device_Info, Role, UserExModel
|
|
|
+from Model.models import Device_Info, Role, UserExModel, User_Brand, UidSetModel
|
|
|
from Service.ModelService import ModelService
|
|
|
from django.utils import timezone
|
|
|
from Model.models import Access_Log, Device_User
|
|
|
from django.views.decorators.http import require_http_methods
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
-from Ansjer.config import OFF_LINE_TIME_DELTA
|
|
|
+from Ansjer.config import OFF_LINE_TIME_DELTA, DEVICE_TYPE
|
|
|
import datetime, simplejson as json
|
|
|
from Service.CommonService import CommonService
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -64,6 +65,12 @@ class AdminManage(TemplateView):
|
|
|
return self.getAllUID(userID, response)
|
|
|
if operation == 'getAllDeviceArea':
|
|
|
return self.getAllDeviceArea(userID, response)
|
|
|
+ if operation == 'getUserBrand':
|
|
|
+ return self.getUserBrand(userID, response)
|
|
|
+ if operation == 'getAreaDeviceType':
|
|
|
+ return self.getAreaDeviceType(userID, response)
|
|
|
+ if operation == 'getDeviceType':
|
|
|
+ return self.getDeviceType(userID, response)
|
|
|
|
|
|
def resetUserPwd(self, request_dict, userID, response):
|
|
|
own_permission = ModelService.check_perm(userID=userID, permID=50)
|
|
@@ -213,6 +220,124 @@ class AdminManage(TemplateView):
|
|
|
res = {'count': uid_list.count(), 'uid_list': list(uid_list)}
|
|
|
return response.json(0, res)
|
|
|
|
|
|
+ def getUserBrand(self, userID, response):
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
+ # 手机型号统计
|
|
|
+ print('手机型号统计:')
|
|
|
+ ub_qs = User_Brand.objects.values('deviceSupplier', 'deviceModel').annotate(value=Count('id')).order_by()
|
|
|
+ res = {
|
|
|
+ 'value': 0,
|
|
|
+ 'data': []
|
|
|
+ }
|
|
|
+ data = res['data']
|
|
|
+ tmpDict = {}
|
|
|
+ for ub in ub_qs:
|
|
|
+ deviceSupplier = ub['deviceSupplier']
|
|
|
+ if not tmpDict.__contains__(deviceSupplier):
|
|
|
+ tmpDict[deviceSupplier] = {
|
|
|
+ 'name': deviceSupplier,
|
|
|
+ 'value': 0,
|
|
|
+ 'children': []
|
|
|
+ }
|
|
|
+
|
|
|
+ item = tmpDict[deviceSupplier]
|
|
|
+ item['value'] = item['value'] + ub['value']
|
|
|
+ res['value'] = res['value'] + item['value']
|
|
|
+ model = {
|
|
|
+ 'name': ub['deviceModel'],
|
|
|
+ 'value': ub['value']
|
|
|
+ }
|
|
|
+ item['children'].append(model)
|
|
|
+
|
|
|
+ for k, v in tmpDict.items():
|
|
|
+ data.append(v)
|
|
|
+
|
|
|
+ print(res)
|
|
|
+ return response.json(0, res)
|
|
|
+
|
|
|
+ def getAreaDeviceType(self, userID, response):
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
+ print('区域设备类型统计:')
|
|
|
+ di_qs = Device_Info.objects.values('area', 'Type').annotate(value=Count('UID', distinct=True)).order_by()
|
|
|
+ res = {
|
|
|
+ 'quantity': 0,
|
|
|
+ 'data': []
|
|
|
+ }
|
|
|
+ data = res['data']
|
|
|
+ tmpDict = {}
|
|
|
+ tmpDict['null'] = {
|
|
|
+ 'area': '未知',
|
|
|
+ 'quantity': 0,
|
|
|
+ 'models': []
|
|
|
+ }
|
|
|
+ for di in di_qs:
|
|
|
+ area = di['area']
|
|
|
+ if area is None or area == '':
|
|
|
+ area = 'null'
|
|
|
+
|
|
|
+ if not tmpDict.__contains__(area):
|
|
|
+ tmpDict[area] = {
|
|
|
+ 'area': area,
|
|
|
+ 'quantity': 0,
|
|
|
+ 'models': []
|
|
|
+ }
|
|
|
+
|
|
|
+ item = tmpDict[area]
|
|
|
+ item['quantity'] = item['quantity'] + di['value']
|
|
|
+ res['quantity'] = res['quantity'] + item['quantity']
|
|
|
+ model = {
|
|
|
+ 'model': DEVICE_TYPE[di['Type']],
|
|
|
+ 'quantity': di['value']
|
|
|
+ }
|
|
|
+ item['models'].append(model)
|
|
|
+
|
|
|
+ for k, v in tmpDict.items():
|
|
|
+ data.append(v)
|
|
|
+ return response.json(0, res)
|
|
|
+
|
|
|
+ def getDeviceType(self, userID, response):
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
+ # 设备类型统计
|
|
|
+ di_qs = Device_Info.objects.values('Type').annotate(quantity=Count('UID', distinct=True)).order_by()
|
|
|
+
|
|
|
+ # 设备型号统计
|
|
|
+ us_qs = UidSetModel.objects.values('deviceModel').annotate(quantity=Count('id')).order_by()
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'type_data': {
|
|
|
+ 'quantity': 0,
|
|
|
+ 'data': []
|
|
|
+ },
|
|
|
+ 'model_data': {
|
|
|
+ 'quantity': 0,
|
|
|
+ 'data': []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ type_data = res['type_data']
|
|
|
+ data = type_data['data']
|
|
|
+ quantity = 0
|
|
|
+ for di in di_qs:
|
|
|
+ di['Type'] = DEVICE_TYPE[di['Type']]
|
|
|
+ quantity += di['quantity']
|
|
|
+ data.append(di)
|
|
|
+ type_data['quantity'] = quantity
|
|
|
+
|
|
|
+ model_data = res['model_data']
|
|
|
+ data = model_data['data']
|
|
|
+ quantity = 0
|
|
|
+ for us in us_qs:
|
|
|
+ data.append(us)
|
|
|
+ quantity += us['quantity']
|
|
|
+ model_data['quantity'] = quantity
|
|
|
+
|
|
|
+ return response.json(0, res)
|
|
|
+
|
|
|
|
|
|
@require_http_methods(["GET"])
|
|
|
def getUserIds(request):
|