|
@@ -13,6 +13,9 @@
|
|
|
"""
|
|
|
import time
|
|
|
import traceback
|
|
|
+
|
|
|
+from django.db.models import Count
|
|
|
+
|
|
|
from Object.RedisObject import RedisObject
|
|
|
import simplejson as json
|
|
|
from django.utils.decorators import method_decorator
|
|
@@ -20,7 +23,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Model.models import UidSetModel, Device_User, Device_Info, UidPushModel, Equipment_Info, UID_Preview, UID_Bucket, \
|
|
|
- VodHlsModel, Order_Model, OssCrdModel, UidUserModel, UidChannelSetModel
|
|
|
+ VodHlsModel, Order_Model, OssCrdModel, UidUserModel, UidChannelSetModel, User_Brand
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
@@ -81,9 +84,11 @@ class UidSetView(View):
|
|
|
elif operation == 'update':
|
|
|
return self.do_update(request_dict, response)
|
|
|
elif operation == 'updateSet':
|
|
|
- return self.do_update_set(request_dict, response)
|
|
|
+ return self.do_update_set(request, request_dict, response)
|
|
|
elif operation == 'updateChannel':
|
|
|
return self.do_update_channel_set(request_dict, response)
|
|
|
+ # elif operation == 'test':
|
|
|
+ # return self.do_test(response)
|
|
|
else:
|
|
|
return response.json(444, 'error path')
|
|
|
|
|
@@ -194,16 +199,16 @@ class UidSetView(View):
|
|
|
else:
|
|
|
val = val + 1
|
|
|
print('UidUserModel表没有数据')
|
|
|
- #有后台管理 设备配置表UidSetModel ---uid --本身,
|
|
|
- #有后台管理 设备关联用户推送表Equipment_Info --devUid --独立没有儿子的,
|
|
|
- #有后台管理 设备预览图表UID_Preview ---uid---孤立,
|
|
|
- #有后台管理 设备关联套餐表UID_Bucket ---uid---孤立,
|
|
|
- #有后台管理 云存回放信息表VodHlsModel ---uid---孤立,
|
|
|
- #有后台管理 订单信息表Order_Model --UID----独立没有儿子的,
|
|
|
- #有后台管理 用户设备信息表(最多信息量的表)Device_Info ---UID---孤立,
|
|
|
+ # 有后台管理 设备配置表UidSetModel ---uid --本身,
|
|
|
+ # 有后台管理 设备关联用户推送表Equipment_Info --devUid --独立没有儿子的,
|
|
|
+ # 有后台管理 设备预览图表UID_Preview ---uid---孤立,
|
|
|
+ # 有后台管理 设备关联套餐表UID_Bucket ---uid---孤立,
|
|
|
+ # 有后台管理 云存回放信息表VodHlsModel ---uid---孤立,
|
|
|
+ # 有后台管理 订单信息表Order_Model --UID----独立没有儿子的,
|
|
|
+ # 有后台管理 用户设备信息表(最多信息量的表)Device_Info ---UID---孤立,
|
|
|
# 设备证书OssCrdModel ---uid---孤立
|
|
|
# 有后台管理 设备ap表 UidUserModel
|
|
|
- #设备绑定UidPushModel---关联表---设备配置表UidSetModel---配置表的详情有显示
|
|
|
+ # 设备绑定UidPushModel---关联表---设备配置表UidSetModel---配置表的详情有显示
|
|
|
|
|
|
# raise DatabaseError #测试用,检测是否能捕捉错误
|
|
|
if val == 9:
|
|
@@ -317,11 +322,11 @@ class UidSetView(View):
|
|
|
errorInfo = traceback.format_exc()
|
|
|
return response.json(500, {'details': errorInfo})
|
|
|
|
|
|
- def do_update_set(self, request_dict, response):
|
|
|
+ def do_update_set(self, request, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
deviceContent = request_dict.get('content', None)
|
|
|
token = request_dict.get('token', None)
|
|
|
- print(deviceContent)
|
|
|
+ # print(deviceContent)
|
|
|
if not deviceContent or not uid:
|
|
|
return response.json(444, 'content,uid')
|
|
|
tko = TokenObject(token)
|
|
@@ -336,7 +341,28 @@ class UidSetView(View):
|
|
|
redisObj.del_data(key='uid_qs_' + userID)
|
|
|
deviceData = json.loads(deviceContent)
|
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
- uid_set_qs.update(**deviceData)
|
|
|
+ if not uid_set_qs.exists():
|
|
|
+ # 由于uid_set表和device_info表设备数量不一致,所以添加以下逻辑把device_info表中的相关信息保存到uid_set表
|
|
|
+ di_qs = Device_Info.objects.filter(UID=uid, userID=userID)
|
|
|
+ if di_qs.exists():
|
|
|
+ di = di_qs[0]
|
|
|
+ nowTime = int(time.time())
|
|
|
+ uid_set_create_dict = {
|
|
|
+ 'uid': di.UID,
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ 'ip': CommonService.get_ip_address(request),
|
|
|
+ 'channel': di.ChannelIndex,
|
|
|
+ 'nickname': di.NickName,
|
|
|
+ }
|
|
|
+ for k, v in deviceData.items():
|
|
|
+ uid_set_create_dict[k] = v
|
|
|
+ UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
+ else:
|
|
|
+ return response.json(177)
|
|
|
+ else:
|
|
|
+ uid_set_qs.update(**deviceData)
|
|
|
+ print('update success')
|
|
|
except Exception as e:
|
|
|
return response.json(177, repr(e))
|
|
|
else:
|
|
@@ -383,3 +409,43 @@ class UidSetView(View):
|
|
|
return response.json(177, repr(e))
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
+
|
|
|
+ def do_test(self, response):
|
|
|
+ # di_qs = Device_Info.objects.values('Type').annotate(c=Count('UID', distinct=True)).order_by()
|
|
|
+ # for di in di_qs:
|
|
|
+ # print(di)
|
|
|
+ #
|
|
|
+ # # 设备总数量
|
|
|
+ # count = Device_Info.objects.values('UID').distinct().count()
|
|
|
+ # print('设备总数量:' + str(count))
|
|
|
+ #
|
|
|
+ # # 设备型号统计
|
|
|
+ # print('设备型号统计:')
|
|
|
+ # us_qs = UidSetModel.objects.values('deviceModel').annotate(c=Count('id')).order_by()
|
|
|
+ # for us in us_qs:
|
|
|
+ # print(us)
|
|
|
+ #
|
|
|
+ # # 手机品牌类型统计
|
|
|
+ # print('手机品牌类型统计:')
|
|
|
+ # ub_qs = User_Brand.objects.values('deviceSupplier').annotate(c=Count('id')).order_by()
|
|
|
+ # for ub in ub_qs:
|
|
|
+ # print(ub)
|
|
|
+ #
|
|
|
+ # # 手机型号统计
|
|
|
+ # print('手机型号统计:')
|
|
|
+ # ub_qs = User_Brand.objects.values('deviceSupplier', 'deviceModel').annotate(c=Count('id')).order_by()
|
|
|
+ # for ub in ub_qs:
|
|
|
+ # print(ub)
|
|
|
+ #
|
|
|
+ # # 区域统计
|
|
|
+ # print('区域统计:')
|
|
|
+ # di_qs = Device_Info.objects.values('area').annotate(c=Count('UID', distinct=True)).order_by()
|
|
|
+ # for di in di_qs:
|
|
|
+ # print(di)
|
|
|
+ #
|
|
|
+ # # 区域设备类型统计
|
|
|
+ # print('区域设备类型统计:')
|
|
|
+ # di_qs = Device_Info.objects.values('area', 'Type').annotate(c=Count('UID', distinct=True)).order_by()
|
|
|
+ # for di in di_qs:
|
|
|
+ # print(di)
|
|
|
+ return response.json(0)
|