|
@@ -5,13 +5,20 @@
|
|
|
@File :Cloudsum.py
|
|
|
@IDE :PyCharm
|
|
|
"""
|
|
|
-from Model.models import Order_Model, UID_Bucket, UserExModel
|
|
|
+import json
|
|
|
+
|
|
|
+from Ansjer.config import SERVER_TYPE
|
|
|
+from Model.models import Order_Model, UID_Bucket, UserExModel, EquipmentLogModel
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from django.views import View
|
|
|
-from Service.ModelService import Device_User,ModelService
|
|
|
+
|
|
|
+from Service.CommonService import CommonService
|
|
|
+from Service.ModelService import Device_User, ModelService
|
|
|
from django.db.models import Count, Sum
|
|
|
|
|
|
+
|
|
|
class Cloudsum(View):
|
|
|
def dispatch(self, requset, *args, **kwargs):
|
|
|
return super(Cloudsum, self).dispatch(requset, *args, **kwargs)
|
|
@@ -45,6 +52,8 @@ class Cloudsum(View):
|
|
|
return self.usercount(userID, request_dict, response)
|
|
|
if operation == 'usercloud':
|
|
|
return self.usercloud(userID, response)
|
|
|
+ if operation == 'equipment_logs':
|
|
|
+ return self.equipment_logs(userID, request_dict, response)
|
|
|
|
|
|
# 类型:用户手机
|
|
|
# 统计用户手机型号 已有
|
|
@@ -59,10 +68,10 @@ class Cloudsum(View):
|
|
|
if own_permission is not True:
|
|
|
return response.json(404)
|
|
|
res = UserExModel.objects.extra(tables=['app_info'],
|
|
|
- select={'appname':'app_info.appName',
|
|
|
- 'appversion':'app_info.newAppversion'},
|
|
|
- where=["user_ex.appBundleId=app_info.appBundleId"]).\
|
|
|
- values('appBundleId','appname','appversion').annotate(dates=Count('appBundleId')).order_by()
|
|
|
+ select={'appname': 'app_info.appName',
|
|
|
+ 'appversion': 'app_info.newAppversion'},
|
|
|
+ where=["user_ex.appBundleId=app_info.appBundleId"]). \
|
|
|
+ values('appBundleId', 'appname', 'appversion').annotate(dates=Count('appBundleId')).order_by()
|
|
|
print(res.query)
|
|
|
print(res)
|
|
|
return response.json(0, list(res))
|
|
@@ -82,7 +91,7 @@ class Cloudsum(View):
|
|
|
# where=["data_joined between '%s-01-01' and '%s-01-01' "],
|
|
|
# params=[usercountyear, usercountyear+1]).values(
|
|
|
# 'dates').annotate(用户合计=Count('data_joined')).order_by('dates')
|
|
|
- count = Device_User.objects.extra(select={'dates': "DATE_FORMAT(data_joined,'%%Y-%%m')"},).values(
|
|
|
+ count = Device_User.objects.extra(select={'dates': "DATE_FORMAT(data_joined,'%%Y-%%m')"}, ).values(
|
|
|
'dates').annotate(用户合计=Count('data_joined')).order_by('dates')
|
|
|
print(count.query)
|
|
|
return response.json(0, list(count))
|
|
@@ -118,4 +127,54 @@ class Cloudsum(View):
|
|
|
return response.json(404)
|
|
|
a = Order_Model.objects.extra(select={'dates': "FROM_UNIXTIME(addTime,'%%Y-%%m')"}).values(
|
|
|
'dates').filter(status=1).annotate(开通云存合计=Count('addTime')).order_by('dates')
|
|
|
- return response.json(0, list(a))
|
|
|
+ return response.json(0, list(a))
|
|
|
+
|
|
|
+ def equipment_logs(self, userID, request_dict, response):
|
|
|
+ page = int(request_dict.get('page', None))
|
|
|
+ line = int(request_dict.get('line', None))
|
|
|
+ # order = request_dict.get('order', '-id')
|
|
|
+ # if order == '':
|
|
|
+ # order = '-id'
|
|
|
+ if not page or not line:
|
|
|
+ return response.json(444, 'page,line')
|
|
|
+
|
|
|
+ # own_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ # if own_perm is not True:
|
|
|
+ # return response.json(404)
|
|
|
+
|
|
|
+ if SERVER_TYPE == 'Ansjer.formal_settings':
|
|
|
+ logKey = 'logger'
|
|
|
+ else:
|
|
|
+ logKey = 'test_logger'
|
|
|
+ # 判断redis列表长度
|
|
|
+ redisObj = RedisObject()
|
|
|
+ data_list = redisObj.lrange(logKey, 0, -1)
|
|
|
+ redisObj.del_data(key=logKey)
|
|
|
+ add_batch_log(data_list)
|
|
|
+
|
|
|
+ qs = EquipmentLogModel.objects.all().order_by('id')
|
|
|
+ if qs.exists():
|
|
|
+ count = qs.count()
|
|
|
+ res = qs[(page - 1) * line:page * line]
|
|
|
+ send_json = CommonService.qs_to_dict(res)
|
|
|
+ send_json['count'] = count
|
|
|
+ return response.json(0, send_json)
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+
|
|
|
+# 访问日志批量添加
|
|
|
+def add_batch_log(data_list):
|
|
|
+ try:
|
|
|
+ if data_list:
|
|
|
+ querysetlist = []
|
|
|
+ for i in data_list:
|
|
|
+ data = json.loads(i.decode('utf-8'))
|
|
|
+ querysetlist.append(EquipmentLogModel(**data))
|
|
|
+ EquipmentLogModel.objects.bulk_create(querysetlist)
|
|
|
+ else:
|
|
|
+ return
|
|
|
+ except Exception as e:
|
|
|
+ print('ggga')
|
|
|
+ print(repr(e))
|
|
|
+ return False
|
|
|
+ else:
|
|
|
+ return True
|