|
@@ -16,13 +16,14 @@ from django.views.generic.base import View
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from Service.ModelService import ModelService
|
|
|
-from Model.models import User_Brand,Device_User
|
|
|
+from Model.models import User_Brand, Device_User
|
|
|
from django.utils import timezone
|
|
|
-import traceback,time,json,urllib.request
|
|
|
+import traceback, time, json, urllib.request
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from collections import Counter
|
|
|
+
|
|
|
'''
|
|
|
http://192.168.136.39:8000/userbrandinfo/queryByAdmin?token=test&page=1&line=10 全部记录
|
|
|
http://192.168.136.39:8000/userbrandinfo/queryArea?token=test 市的区域统计
|
|
@@ -61,17 +62,17 @@ class UserBrandInfo(View):
|
|
|
userID = tko.userID
|
|
|
if userID is not None:
|
|
|
if operation == 'queryByAdmin':
|
|
|
- return self.query_info(request_dict, userID,response)
|
|
|
+ return self.query_info(request_dict, userID, response)
|
|
|
elif operation == 'add':
|
|
|
- return self.add_info(request_dict, userID,response)
|
|
|
+ return self.add_info(request_dict, userID, response)
|
|
|
elif operation == 'queryAllByAdmin':
|
|
|
- return self.query_all_info(request_dict, userID,response)
|
|
|
+ return self.query_all_info(request_dict, userID, response)
|
|
|
elif operation == 'deleteByAdmin':
|
|
|
- return self.delete_by_admin(request_dict, userID,response)
|
|
|
+ return self.delete_by_admin(request_dict, userID, response)
|
|
|
elif operation == 'queryDeviceSupplier':
|
|
|
- return self.query_deviceSupplier_info(request_dict, userID,response)
|
|
|
+ return self.query_deviceSupplier_info(request_dict, userID, response)
|
|
|
elif operation == 'queryArea':
|
|
|
- return self.query_area_info(request_dict, userID,response)
|
|
|
+ return self.query_area_info(request_dict, userID, response)
|
|
|
|
|
|
else:
|
|
|
return response.json(444)
|
|
@@ -83,11 +84,8 @@ class UserBrandInfo(View):
|
|
|
return response.json(309)
|
|
|
# 获取外网IP
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
# http://192.168.136.39:8000/userbrandinfo?operation=add&token=test&deviceSupplier=小米&deviceModel=HM NOTE 1TD&osType=WEB&osVersion=4.0.0
|
|
|
- def add_info(self, request_dict, userID,response):
|
|
|
+ def add_info(self, request_dict, userID, response):
|
|
|
deviceSupplier = request_dict.get('deviceSupplier', None)
|
|
|
deviceModel = request_dict.get('deviceModel', None)
|
|
|
osType = request_dict.get('osType', None)
|
|
@@ -101,22 +99,22 @@ class UserBrandInfo(View):
|
|
|
latitude = request_dict.get('latitude', None)
|
|
|
appId = request_dict.get('appId', None)
|
|
|
if area is None:
|
|
|
- area=''
|
|
|
+ area = ''
|
|
|
if street is None:
|
|
|
- street=''
|
|
|
+ street = ''
|
|
|
if longitude is None:
|
|
|
- longitude=''
|
|
|
+ longitude = ''
|
|
|
if latitude is None:
|
|
|
- latitude=''
|
|
|
- param_area = CommonService.get_param_flag(data=[country,province,city])
|
|
|
- must_fill_in = CommonService.get_param_flag(data=[appId,deviceSupplier,deviceModel,osType,osVersion])
|
|
|
+ latitude = ''
|
|
|
+ param_area = CommonService.get_param_flag(data=[country, province, city])
|
|
|
+ must_fill_in = CommonService.get_param_flag(data=[appId, deviceSupplier, deviceModel, osType, osVersion])
|
|
|
if must_fill_in is False:
|
|
|
- return response.json(444,'appId,deviceSupplier,deviceModel,osType,osVersion')
|
|
|
- if param_area is True:
|
|
|
+ return response.json(444, 'appId,deviceSupplier,deviceModel,osType,osVersion')
|
|
|
+ if param_area is True:
|
|
|
if '省' in province:
|
|
|
- province = province.replace('省','')
|
|
|
+ province = province.replace('省', '')
|
|
|
if '市' in city:
|
|
|
- city = city.replace('市','')
|
|
|
+ city = city.replace('市', '')
|
|
|
status = 1
|
|
|
country = country
|
|
|
province = province
|
|
@@ -127,8 +125,8 @@ class UserBrandInfo(View):
|
|
|
latitude = latitude
|
|
|
else:
|
|
|
status = 0
|
|
|
- print (self.clientIP)
|
|
|
- jsonData = CommonService.getIpIpInfo(ip=self.clientIP,lang='CN')
|
|
|
+ print(self.clientIP)
|
|
|
+ jsonData = CommonService.getIpIpInfo(ip=self.clientIP, lang='CN')
|
|
|
country = jsonData['country_name']
|
|
|
province = jsonData['region_name']
|
|
|
city = jsonData['city_name']
|
|
@@ -136,7 +134,7 @@ class UserBrandInfo(View):
|
|
|
street = ''
|
|
|
longitude = jsonData['longitude']
|
|
|
latitude = jsonData['latitude']
|
|
|
- param_flag = CommonService.get_param_flag(data=[deviceSupplier, deviceModel,osType,osVersion])
|
|
|
+ param_flag = CommonService.get_param_flag(data=[deviceSupplier, deviceModel, osType, osVersion])
|
|
|
if param_flag is True:
|
|
|
try:
|
|
|
user_brand = User_Brand(
|
|
@@ -146,16 +144,16 @@ class UserBrandInfo(View):
|
|
|
osType=osType,
|
|
|
osVersion=osVersion,
|
|
|
ip=self.clientIP,
|
|
|
- addTime = int(time.time()),
|
|
|
- status = status,
|
|
|
- country = country,
|
|
|
- province = province,
|
|
|
- city = city,
|
|
|
+ addTime=int(time.time()),
|
|
|
+ status=status,
|
|
|
+ country=country,
|
|
|
+ province=province,
|
|
|
+ city=city,
|
|
|
appId=appId,
|
|
|
- area = area,
|
|
|
- street = street,
|
|
|
- longitude = longitude,
|
|
|
- latitude = latitude
|
|
|
+ area=area,
|
|
|
+ street=street,
|
|
|
+ longitude=longitude,
|
|
|
+ latitude=latitude
|
|
|
)
|
|
|
user_brand.save()
|
|
|
except Exception:
|
|
@@ -164,25 +162,22 @@ class UserBrandInfo(View):
|
|
|
return response.json(424, {'details': errorInfo})
|
|
|
else:
|
|
|
print(type(user_brand.addTime))
|
|
|
- return response.json(0,{'id':user_brand.id})
|
|
|
+ return response.json(0, {'id': user_brand.id})
|
|
|
else:
|
|
|
# 参数错误
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ return response.json(444)
|
|
|
|
|
|
- def query_info(self, request_dict, userID,response):
|
|
|
+ def query_info(self, request_dict, userID, response):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
- username = request_dict.get('username',None)
|
|
|
+ username = request_dict.get('username', None)
|
|
|
|
|
|
param_flag = CommonService.get_param_flag(data=[page, line])
|
|
|
if param_flag is True:
|
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
|
if check_perm is True:
|
|
|
if username is None or username is '':
|
|
|
- user_brand_queryset = User_Brand.objects.all().order_by( '-id')
|
|
|
+ user_brand_queryset = User_Brand.objects.all().order_by('-id')
|
|
|
else:
|
|
|
user_brand_queryset = User_Brand.objects.filter(userID__username=username).order_by('-id')
|
|
|
if user_brand_queryset.exists():
|
|
@@ -190,8 +185,8 @@ class UserBrandInfo(View):
|
|
|
res = user_brand_queryset[(page - 1) * line:page * line]
|
|
|
send_json = CommonService.qs_to_dict(res)
|
|
|
for k, v in enumerate(send_json["datas"]):
|
|
|
- username = ModelService.get_user_name(userID=send_json["datas"][k]['fields']['userID'])
|
|
|
- send_json["datas"][k]['fields']['username']=username
|
|
|
+ username = ModelService.get_user_name(userID=send_json["datas"][k]['fields']['userID'])
|
|
|
+ send_json["datas"][k]['fields']['username'] = username
|
|
|
send_json['count'] = count
|
|
|
return response.json(0, send_json)
|
|
|
return response.json(0, {'datas': [], 'count': 0})
|
|
@@ -199,7 +194,8 @@ class UserBrandInfo(View):
|
|
|
return response.json(404)
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
- def delete_by_admin(self, request_dict, userID,response):
|
|
|
+
|
|
|
+ def delete_by_admin(self, request_dict, userID, response):
|
|
|
id_list = request_dict.getlist('id', None)
|
|
|
param_flag = CommonService.get_param_flag(data=[id_list])
|
|
|
if param_flag is True:
|
|
@@ -211,33 +207,38 @@ class UserBrandInfo(View):
|
|
|
return response.json(404)
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
+
|
|
|
# 查询每个用户最新的一条记录统计信息
|
|
|
- def query_all_info(self, request_dict, userID,response):
|
|
|
+ def query_all_info(self, request_dict, userID, response):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
|
username = request_dict.get('username', None)
|
|
|
param_flag = CommonService.get_param_flag(data=[page, line])
|
|
|
if param_flag is True:
|
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
|
if check_perm is True:
|
|
|
if username is None or username is '':
|
|
|
- # 按照用户去重复查询
|
|
|
- # 分页
|
|
|
- user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()[(page - 1) * line:page * line]
|
|
|
+ # 按照用户去重复查询
|
|
|
+ # 分页
|
|
|
+ user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID',
|
|
|
+ flat=True).distinct()[
|
|
|
+ (page - 1) * line:page * line]
|
|
|
else:
|
|
|
# 分页
|
|
|
- user_brand_queryset = User_Brand.objects.filter(userID__username=username).order_by('userID').values_list( 'userID',flat=True).distinct()[(page - 1) * line:page * line]
|
|
|
- send_jsons=[]
|
|
|
- counts=0
|
|
|
+ user_brand_queryset = User_Brand.objects.filter(userID__username=username).order_by(
|
|
|
+ 'userID').values_list('userID', flat=True).distinct()[(page - 1) * line:page * line]
|
|
|
+ send_jsons = []
|
|
|
+ counts = 0
|
|
|
for i in user_brand_queryset:
|
|
|
- counts=counts+1
|
|
|
+ counts = counts + 1
|
|
|
user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by('-addTime')[:1]
|
|
|
user_brand_querysetlast = CommonService.qs_to_dict(user_brand_querysetlast)
|
|
|
- username = ModelService.get_user_name(userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
- user_brand_querysetlast["datas"][0]['fields']['username']=username
|
|
|
+ username = ModelService.get_user_name(
|
|
|
+ userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
+ user_brand_querysetlast["datas"][0]['fields']['username'] = username
|
|
|
send_jsons.append(user_brand_querysetlast["datas"][0])
|
|
|
# 按照加入的日期排序
|
|
|
- send_jsons = sorted(send_jsons, key=lambda x:x['fields']['addTime'], reverse=True)
|
|
|
+ send_jsons = sorted(send_jsons, key=lambda x: x['fields']['addTime'], reverse=True)
|
|
|
return response.json(0, {'datas': send_jsons, 'count': counts})
|
|
|
else:
|
|
|
return response.json(404)
|
|
@@ -245,51 +246,51 @@ class UserBrandInfo(View):
|
|
|
return response.json(444)
|
|
|
|
|
|
# 品牌统计的接口
|
|
|
- def query_deviceSupplier_info(self, request_dict, userID,response):
|
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
+ def query_deviceSupplier_info(self, request_dict, userID, response):
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
|
if check_perm is True:
|
|
|
# 按照用户去重复查询
|
|
|
- user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
|
|
|
- send_jsons=[]
|
|
|
- counts=0
|
|
|
+ user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID',
|
|
|
+ flat=True).distinct()
|
|
|
+ send_jsons = []
|
|
|
+ counts = 0
|
|
|
for i in user_brand_queryset:
|
|
|
- counts=counts+1
|
|
|
+ counts = counts + 1
|
|
|
user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by('-addTime')[:1]
|
|
|
user_brand_querysetlast = CommonService.qs_to_dict(user_brand_querysetlast)
|
|
|
username = ModelService.get_user_name(userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
- user_brand_querysetlast["datas"][0]['fields']['username']=username
|
|
|
+ user_brand_querysetlast["datas"][0]['fields']['username'] = username
|
|
|
send_jsons.append(user_brand_querysetlast["datas"][0])
|
|
|
- deviceSupplier=[]
|
|
|
+ deviceSupplier = []
|
|
|
for k, v in enumerate(send_jsons):
|
|
|
deviceSupplier.append(v['fields']['deviceSupplier'])
|
|
|
deviceSupplier = Counter(deviceSupplier)
|
|
|
- return response.json(0, {'datas': deviceSupplier,'counts':counts})
|
|
|
+ return response.json(0, {'datas': deviceSupplier, 'counts': counts})
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
+
|
|
|
# 区域统计的接口
|
|
|
- def query_area_info(self, request_dict, userID,response):
|
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
+ def query_area_info(self, request_dict, userID, response):
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
|
district = request_dict.get('district', None)
|
|
|
if check_perm is True:
|
|
|
# 按照用户去重复查询
|
|
|
- user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
|
|
|
- send_jsons=[]
|
|
|
- counts=0
|
|
|
+ user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID',
|
|
|
+ flat=True).distinct()
|
|
|
+ send_jsons = []
|
|
|
+ counts = 0
|
|
|
for i in user_brand_queryset:
|
|
|
- counts=counts+1
|
|
|
+ counts = counts + 1
|
|
|
user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by('-addTime')[:1]
|
|
|
user_brand_querysetlast = CommonService.qs_to_dict(user_brand_querysetlast)
|
|
|
username = ModelService.get_user_name(userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
- user_brand_querysetlast["datas"][0]['fields']['username']=username
|
|
|
+ user_brand_querysetlast["datas"][0]['fields']['username'] = username
|
|
|
send_jsons.append(user_brand_querysetlast["datas"][0])
|
|
|
- deviceSupplier=[]
|
|
|
+ deviceSupplier = []
|
|
|
for k, v in enumerate(send_jsons):
|
|
|
deviceSupplier.append(v['fields'][district])
|
|
|
deviceSupplier = Counter(deviceSupplier)
|
|
|
- return response.json(0, {'datas': deviceSupplier,'counts':counts})
|
|
|
+ return response.json(0, {'datas': deviceSupplier, 'counts': counts})
|
|
|
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
-
|
|
|
-
|
|
|
-
|