|
@@ -16,15 +16,16 @@ from django.views.generic.base import View
|
|
from django.utils.decorators import method_decorator
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from Service.ModelService import ModelService
|
|
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
|
|
from django.utils import timezone
|
|
-import traceback,time,json,urllib.request
|
|
|
|
|
|
+import traceback, time, json, urllib.request
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
from collections import Counter
|
|
from collections import Counter
|
|
from Ansjer.config import DOMAIN_HOST
|
|
from Ansjer.config import DOMAIN_HOST
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
|
|
+
|
|
'''
|
|
'''
|
|
http://192.168.136.39:8000/userbrandinfo/queryByAdmin?token=test&page=1&line=10 记录
|
|
http://192.168.136.39:8000/userbrandinfo/queryByAdmin?token=test&page=1&line=10 记录
|
|
http://192.168.136.39:8000/userbrandinfo/queryArea?token=test 市的区域统计
|
|
http://192.168.136.39:8000/userbrandinfo/queryArea?token=test 市的区域统计
|
|
@@ -42,6 +43,7 @@ import json
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
+
|
|
class MyserviceDynamodb(object):
|
|
class MyserviceDynamodb(object):
|
|
def __init__(self, **kwargs):
|
|
def __init__(self, **kwargs):
|
|
self.region = 'us-west-1'
|
|
self.region = 'us-west-1'
|
|
@@ -51,16 +53,18 @@ class MyserviceDynamodb(object):
|
|
|
|
|
|
def __session(self):
|
|
def __session(self):
|
|
try:
|
|
try:
|
|
- session = Session(aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key,region_name=self.region)
|
|
|
|
|
|
+ session = Session(aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key,
|
|
|
|
+ region_name=self.region)
|
|
except:
|
|
except:
|
|
print("Failed to connect session in region{0}".format(self.region))
|
|
print("Failed to connect session in region{0}".format(self.region))
|
|
return session
|
|
return session
|
|
|
|
+
|
|
# 创建user_brand_all表
|
|
# 创建user_brand_all表
|
|
def user_brand_all_table_create(self, table_name):
|
|
def user_brand_all_table_create(self, table_name):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
inventory = my.tables_list(table_name)
|
|
inventory = my.tables_list(table_name)
|
|
if table_name in inventory:
|
|
if table_name in inventory:
|
|
- print ('包含')
|
|
|
|
|
|
+ print('包含')
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|
|
table = dynamodb.create_table(
|
|
table = dynamodb.create_table(
|
|
@@ -92,21 +96,20 @@ class MyserviceDynamodb(object):
|
|
}
|
|
}
|
|
)
|
|
)
|
|
except Exception:
|
|
except Exception:
|
|
- logger.error (table_name + '表已经存在')
|
|
|
|
|
|
+ logger.error(table_name + '表已经存在')
|
|
|
|
|
|
# 查询aws数据库里面有什么表
|
|
# 查询aws数据库里面有什么表
|
|
- def tables_list(self,table_name):
|
|
|
|
|
|
+ def tables_list(self, table_name):
|
|
client = self.session.client('dynamodb')
|
|
client = self.session.client('dynamodb')
|
|
response = client.list_tables()
|
|
response = client.list_tables()
|
|
return response['TableNames']
|
|
return response['TableNames']
|
|
|
|
|
|
-
|
|
|
|
# 创建user_brand表
|
|
# 创建user_brand表
|
|
- def table_create(self,table_name):
|
|
|
|
|
|
+ def table_create(self, table_name):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
inventory = my.tables_list(table_name)
|
|
inventory = my.tables_list(table_name)
|
|
if table_name in inventory:
|
|
if table_name in inventory:
|
|
- print ('包含')
|
|
|
|
|
|
+ print('包含')
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|
|
table = dynamodb.create_table(
|
|
table = dynamodb.create_table(
|
|
@@ -138,11 +141,10 @@ class MyserviceDynamodb(object):
|
|
}
|
|
}
|
|
)
|
|
)
|
|
except Exception:
|
|
except Exception:
|
|
- logger.error (table_name+'表已经存在')
|
|
|
|
-
|
|
|
|
|
|
+ logger.error(table_name + '表已经存在')
|
|
|
|
|
|
# 添加user_brand_all表数据
|
|
# 添加user_brand_all表数据
|
|
- def user_brand_all_item_put(self, table_name,data_list):
|
|
|
|
|
|
+ def user_brand_all_item_put(self, table_name, data_list):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
try:
|
|
try:
|
|
@@ -158,7 +160,7 @@ class MyserviceDynamodb(object):
|
|
'deviceModel': data['deviceModel'],
|
|
'deviceModel': data['deviceModel'],
|
|
'osType': data['osType'],
|
|
'osType': data['osType'],
|
|
'osVersion': data['osVersion'],
|
|
'osVersion': data['osVersion'],
|
|
- 'country' : data['country'],
|
|
|
|
|
|
+ 'country': data['country'],
|
|
'province': data['province'],
|
|
'province': data['province'],
|
|
'city': data['city'],
|
|
'city': data['city'],
|
|
'area': data['area'],
|
|
'area': data['area'],
|
|
@@ -167,18 +169,18 @@ class MyserviceDynamodb(object):
|
|
'latitude': data['latitude'],
|
|
'latitude': data['latitude'],
|
|
'appId': data['appId'],
|
|
'appId': data['appId'],
|
|
'status_all': data['status_all'],
|
|
'status_all': data['status_all'],
|
|
- 'ExpirationTime_TTL' : data['ExpirationTime_TTL'],
|
|
|
|
|
|
+ 'ExpirationTime_TTL': data['ExpirationTime_TTL'],
|
|
'ip': data['ip'],
|
|
'ip': data['ip'],
|
|
}
|
|
}
|
|
)
|
|
)
|
|
- print ('批量添加数据成功!')
|
|
|
|
|
|
+ print('批量添加数据成功!')
|
|
except Exception:
|
|
except Exception:
|
|
- logger.error ('批量添加表数据失败!')
|
|
|
|
|
|
+ logger.error('批量添加表数据失败!')
|
|
|
|
|
|
# 添加user_brand表数据
|
|
# 添加user_brand表数据
|
|
- def user_brand_item_put(self, table_name, user_id, username,add_time, device_supplier, device_model, os_type,
|
|
|
|
- os_version, country, province, city, area, street, longitude, latitude, app_id,
|
|
|
|
- status_all, ip):
|
|
|
|
|
|
+ def user_brand_item_put(self, table_name, user_id, username, add_time, device_supplier, device_model, os_type,
|
|
|
|
+ os_version, country, province, city, area, street, longitude, latitude, app_id,
|
|
|
|
+ status_all, ip):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
try:
|
|
try:
|
|
@@ -204,12 +206,12 @@ class MyserviceDynamodb(object):
|
|
'ip': ip,
|
|
'ip': ip,
|
|
}
|
|
}
|
|
)
|
|
)
|
|
- print ('添加表一条数据成功!')
|
|
|
|
|
|
+ print('添加表一条数据成功!')
|
|
except Exception:
|
|
except Exception:
|
|
- logger.error ('添加表一条数据失败!')
|
|
|
|
|
|
+ logger.error('添加表一条数据失败!')
|
|
|
|
|
|
# page分页数,line条数,table_name表名称,last_evaluated查询开始值,page_value记录分页开始值
|
|
# page分页数,line条数,table_name表名称,last_evaluated查询开始值,page_value记录分页开始值
|
|
- def get_page_line(self, page, line, table_name, last_evaluated,page_value):
|
|
|
|
|
|
+ def get_page_line(self, page, line, table_name, last_evaluated, page_value):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
if not dynamodb:
|
|
if not dynamodb:
|
|
raise DynamodbConnectionError("Failed to get resource for dynamodb!")
|
|
raise DynamodbConnectionError("Failed to get resource for dynamodb!")
|
|
@@ -230,14 +232,14 @@ class MyserviceDynamodb(object):
|
|
last_evaluated_key = response['LastEvaluatedKey']
|
|
last_evaluated_key = response['LastEvaluatedKey']
|
|
# 如果有知就追加在该值的后面
|
|
# 如果有知就追加在该值的后面
|
|
page_value.append(last_evaluated_key)
|
|
page_value.append(last_evaluated_key)
|
|
- my.get_page_line(page, line, table_name, last_evaluated_key,page_value)
|
|
|
|
|
|
+ my.get_page_line(page, line, table_name, last_evaluated_key, page_value)
|
|
except Exception:
|
|
except Exception:
|
|
return page_value
|
|
return page_value
|
|
except Exception as e:
|
|
except Exception as e:
|
|
logger.error("Failed to get table {0}, error".format(table_name, e))
|
|
logger.error("Failed to get table {0}, error".format(table_name, e))
|
|
return page_value
|
|
return page_value
|
|
|
|
|
|
- def item_get(self,line,table_name,last_evaluated_key):
|
|
|
|
|
|
+ def item_get(self, line, table_name, last_evaluated_key):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
if last_evaluated_key is None:
|
|
if last_evaluated_key is None:
|
|
@@ -251,14 +253,14 @@ class MyserviceDynamodb(object):
|
|
ExclusiveStartKey=last_evaluated_key)
|
|
ExclusiveStartKey=last_evaluated_key)
|
|
return response
|
|
return response
|
|
|
|
|
|
- def item_get_count(self,table_name):
|
|
|
|
|
|
+ def item_get_count(self, table_name):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
|
|
|
|
response = table.scan()
|
|
response = table.scan()
|
|
return len(response['Items'])
|
|
return len(response['Items'])
|
|
|
|
|
|
- def item_get_brand(self,table_name):
|
|
|
|
|
|
+ def item_get_brand(self, table_name):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
try:
|
|
try:
|
|
@@ -272,10 +274,10 @@ class MyserviceDynamodb(object):
|
|
try:
|
|
try:
|
|
response = table.put_item(Item=item_dict)
|
|
response = table.put_item(Item=item_dict)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- logger.error("Failed to put item in to {0}:error{1}".format(table,e))
|
|
|
|
|
|
+ logger.error("Failed to put item in to {0}:error{1}".format(table, e))
|
|
return response
|
|
return response
|
|
|
|
|
|
- def get_item(self, table_name,queryname ,username):
|
|
|
|
|
|
+ def get_item(self, table_name, queryname, username):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
if not dynamodb:
|
|
if not dynamodb:
|
|
raise DynamodbConnectionError("Failed to get resource for dynamodb!")
|
|
raise DynamodbConnectionError("Failed to get resource for dynamodb!")
|
|
@@ -289,54 +291,55 @@ class MyserviceDynamodb(object):
|
|
logger.error("Failed to get table {0}, error".format(table_name, e))
|
|
logger.error("Failed to get table {0}, error".format(table_name, e))
|
|
return items
|
|
return items
|
|
|
|
|
|
- def update_table(self, table_name, user_id,username, add_time, deviceSupplier, deviceModel, osType, osVersion, country, province, city, area, street, longitude , latitude,appId, ip,status_all
|
|
|
|
- ):
|
|
|
|
|
|
+ def update_table(self, table_name, user_id, username, add_time, deviceSupplier, deviceModel, osType, osVersion,
|
|
|
|
+ country, province, city, area, street, longitude, latitude, appId, ip, status_all
|
|
|
|
+ ):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
try:
|
|
try:
|
|
response = table.update_item(
|
|
response = table.update_item(
|
|
- Key = {
|
|
|
|
- 'userID': user_id,
|
|
|
|
- 'username':username
|
|
|
|
- },UpdateExpression = "SET addTime = :add_time, deviceSupplier= :deviceSupplier, deviceModel = :deviceModel, osType = :osType, osVersion = :osVersion, country = :country, province = :province, city = :city, area= :area, street= :street, longitude= :longitude, latitude= :latitude, appId= :appId, ip= :ip, status_all= :status_all",
|
|
|
|
-
|
|
|
|
- ExpressionAttributeValues={
|
|
|
|
- ':add_time': add_time,
|
|
|
|
- ':deviceSupplier': deviceSupplier,
|
|
|
|
- ':deviceModel': deviceModel,
|
|
|
|
- ':osType':osType,
|
|
|
|
- ':osVersion':osVersion,
|
|
|
|
- ':country':country,
|
|
|
|
- ':province':province,
|
|
|
|
- ':city': city,
|
|
|
|
- ':area': area,
|
|
|
|
- ':street': street,
|
|
|
|
- ':longitude': longitude,
|
|
|
|
- ':latitude': latitude,
|
|
|
|
- ':appId': appId,
|
|
|
|
- ':ip': ip,
|
|
|
|
- ':status_all': status_all,
|
|
|
|
- },ReturnValues="UPDATED_NEW")
|
|
|
|
|
|
+ Key={
|
|
|
|
+ 'userID': user_id,
|
|
|
|
+ 'username': username
|
|
|
|
+ },
|
|
|
|
+ UpdateExpression="SET addTime = :add_time, deviceSupplier= :deviceSupplier, deviceModel = :deviceModel, osType = :osType, osVersion = :osVersion, country = :country, province = :province, city = :city, area= :area, street= :street, longitude= :longitude, latitude= :latitude, appId= :appId, ip= :ip, status_all= :status_all",
|
|
|
|
+
|
|
|
|
+ ExpressionAttributeValues={
|
|
|
|
+ ':add_time': add_time,
|
|
|
|
+ ':deviceSupplier': deviceSupplier,
|
|
|
|
+ ':deviceModel': deviceModel,
|
|
|
|
+ ':osType': osType,
|
|
|
|
+ ':osVersion': osVersion,
|
|
|
|
+ ':country': country,
|
|
|
|
+ ':province': province,
|
|
|
|
+ ':city': city,
|
|
|
|
+ ':area': area,
|
|
|
|
+ ':street': street,
|
|
|
|
+ ':longitude': longitude,
|
|
|
|
+ ':latitude': latitude,
|
|
|
|
+ ':appId': appId,
|
|
|
|
+ ':ip': ip,
|
|
|
|
+ ':status_all': status_all,
|
|
|
|
+ }, ReturnValues="UPDATED_NEW")
|
|
except ClientError as e:
|
|
except ClientError as e:
|
|
if e.response['Error']['Code'] == "ConditionalCheckFailedException":
|
|
if e.response['Error']['Code'] == "ConditionalCheckFailedException":
|
|
logger.error(e.response['Error']['Message'])
|
|
logger.error(e.response['Error']['Message'])
|
|
else:
|
|
else:
|
|
print('Failed update the dynamodb by event_id,not Failed Conditional')
|
|
print('Failed update the dynamodb by event_id,not Failed Conditional')
|
|
else:
|
|
else:
|
|
- print ('修改成功')
|
|
|
|
-
|
|
|
|
|
|
+ print('修改成功')
|
|
|
|
|
|
def table_delete(self, table_name):
|
|
def table_delete(self, table_name):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
table.delete()
|
|
table.delete()
|
|
- print ('删除表成功')
|
|
|
|
|
|
+ print('删除表成功')
|
|
|
|
|
|
- def item_delete(self, table_name,user_id,user_name,add_time):
|
|
|
|
|
|
+ def item_delete(self, table_name, user_id, user_name, add_time):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
try:
|
|
try:
|
|
- print (str(table_name))
|
|
|
|
|
|
+ print(str(table_name))
|
|
if str(table_name) == str('user_brand'):
|
|
if str(table_name) == str('user_brand'):
|
|
table.delete_item(
|
|
table.delete_item(
|
|
Key={
|
|
Key={
|
|
@@ -357,6 +360,7 @@ class MyserviceDynamodb(object):
|
|
logger.error("Failed to put item in to {0}:error{1}".format(table))
|
|
logger.error("Failed to put item in to {0}:error{1}".format(table))
|
|
return 'no'
|
|
return 'no'
|
|
|
|
|
|
|
|
+
|
|
my = MyserviceDynamodb()
|
|
my = MyserviceDynamodb()
|
|
# print(my.table_delete('user_brand'))
|
|
# print(my.table_delete('user_brand'))
|
|
# print(my.table_delete('user_brand_all'))
|
|
# print(my.table_delete('user_brand_all'))
|
|
@@ -368,6 +372,8 @@ else:
|
|
user_brand_all = 'test_user_brand_all'
|
|
user_brand_all = 'test_user_brand_all'
|
|
my.table_create(user_brand)
|
|
my.table_create(user_brand)
|
|
my.user_brand_all_table_create(user_brand_all)
|
|
my.user_brand_all_table_create(user_brand_all)
|
|
|
|
+
|
|
|
|
+
|
|
# print(my.item_put('user_brand'))
|
|
# print(my.item_put('user_brand'))
|
|
# table_value = my.get_table('user_brand')
|
|
# table_value = my.get_table('user_brand')
|
|
|
|
|
|
@@ -406,17 +412,18 @@ class UserBrandInfo(View):
|
|
user_brand_all = 'test_user_brand_all'
|
|
user_brand_all = 'test_user_brand_all'
|
|
if userID is not None:
|
|
if userID is not None:
|
|
if operation == 'queryByAdmin':
|
|
if operation == 'queryByAdmin':
|
|
- return self.query_info(request_dict, userID,user_brand,user_brand_all,response)
|
|
|
|
|
|
+ return self.query_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
elif operation == 'add':
|
|
elif operation == 'add':
|
|
- return self.add_info(request_dict, userID,user_brand,user_brand_all,response)
|
|
|
|
|
|
+ return self.add_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
elif operation == 'queryAllByAdmin':
|
|
elif operation == 'queryAllByAdmin':
|
|
- return self.query_all_info(request_dict, userID,user_brand,user_brand_all,response)
|
|
|
|
|
|
+ return self.query_all_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
elif operation == 'deleteByAdmin':
|
|
elif operation == 'deleteByAdmin':
|
|
- return self.delete_by_admin(request_dict, userID,user_brand,user_brand_all,response)
|
|
|
|
|
|
+ return self.delete_by_admin(request_dict, userID, user_brand, user_brand_all, response)
|
|
elif operation == 'queryDeviceSupplier':
|
|
elif operation == 'queryDeviceSupplier':
|
|
- return self.query_deviceSupplier_info(request_dict, userID,user_brand,user_brand_all,response)
|
|
|
|
|
|
+ return self.query_deviceSupplier_info(request_dict, userID, user_brand, user_brand_all,
|
|
|
|
+ response)
|
|
elif operation == 'queryArea':
|
|
elif operation == 'queryArea':
|
|
- return self.query_area_info(request_dict, userID,user_brand,user_brand_all,response)
|
|
|
|
|
|
+ return self.query_area_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
|
|
|
|
else:
|
|
else:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
@@ -427,8 +434,9 @@ class UserBrandInfo(View):
|
|
else:
|
|
else:
|
|
return response.json(309)
|
|
return response.json(309)
|
|
# 获取外网IP
|
|
# 获取外网IP
|
|
|
|
+
|
|
# http://192.168.136.39:8000/userbrandinfo?operation=add&token=test&deviceSupplier=小米&deviceModel=HM NOTE 1TD&osType=WEB&osVersion=4.0.0
|
|
# 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,user_brand,user_brand_all,response):
|
|
|
|
|
|
+ def add_info(self, request_dict, userID, user_brand, user_brand_all, response):
|
|
deviceSupplier = request_dict.get('deviceSupplier', None)
|
|
deviceSupplier = request_dict.get('deviceSupplier', None)
|
|
deviceModel = request_dict.get('deviceModel', None)
|
|
deviceModel = request_dict.get('deviceModel', None)
|
|
osType = request_dict.get('osType', None)
|
|
osType = request_dict.get('osType', None)
|
|
@@ -442,24 +450,24 @@ class UserBrandInfo(View):
|
|
latitude = request_dict.get('latitude', None)
|
|
latitude = request_dict.get('latitude', None)
|
|
appId = request_dict.get('appId', None)
|
|
appId = request_dict.get('appId', None)
|
|
if city is None:
|
|
if city is None:
|
|
- city='无'
|
|
|
|
|
|
+ city = '无'
|
|
if area is None:
|
|
if area is None:
|
|
- area='无'
|
|
|
|
|
|
+ area = '无'
|
|
if street is None:
|
|
if street is None:
|
|
- street='无'
|
|
|
|
|
|
+ street = '无'
|
|
if longitude is None:
|
|
if longitude is None:
|
|
- longitude='无'
|
|
|
|
|
|
+ longitude = '无'
|
|
if latitude is None:
|
|
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:
|
|
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:
|
|
if '省' in province:
|
|
- province = province.replace('省','')
|
|
|
|
|
|
+ province = province.replace('省', '')
|
|
if '市' in city:
|
|
if '市' in city:
|
|
- city = city.replace('市','')
|
|
|
|
|
|
+ city = city.replace('市', '')
|
|
status = 1
|
|
status = 1
|
|
country = country
|
|
country = country
|
|
province = province
|
|
province = province
|
|
@@ -470,7 +478,7 @@ class UserBrandInfo(View):
|
|
latitude = latitude
|
|
latitude = latitude
|
|
else:
|
|
else:
|
|
status = 0
|
|
status = 0
|
|
- jsonData = CommonService.getIpIpInfo(ip=self.clientIP,lang='CN')
|
|
|
|
|
|
+ jsonData = CommonService.getIpIpInfo(ip=self.clientIP, lang='CN')
|
|
country = jsonData['country_name']
|
|
country = jsonData['country_name']
|
|
province = jsonData['region_name']
|
|
province = jsonData['region_name']
|
|
city = jsonData['city_name']
|
|
city = jsonData['city_name']
|
|
@@ -483,12 +491,12 @@ class UserBrandInfo(View):
|
|
longitude = '无'
|
|
longitude = '无'
|
|
latitude = '无'
|
|
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:
|
|
if param_flag is True:
|
|
try:
|
|
try:
|
|
addTime = int(time.time())
|
|
addTime = int(time.time())
|
|
- print (time.time())
|
|
|
|
- username = Device_User.objects.filter(userID = userID).values('userID','username','NickName')
|
|
|
|
|
|
+ print(time.time())
|
|
|
|
+ username = Device_User.objects.filter(userID=userID).values('userID', 'username', 'NickName')
|
|
username = username[0]['username']
|
|
username = username[0]['username']
|
|
add_data = {
|
|
add_data = {
|
|
'userID': userID,
|
|
'userID': userID,
|
|
@@ -517,7 +525,7 @@ class UserBrandInfo(View):
|
|
else:
|
|
else:
|
|
logKey = 'test_user_brand_all'
|
|
logKey = 'test_user_brand_all'
|
|
redisObj.rpush(name=logKey, val=add_user_brand_all_data)
|
|
redisObj.rpush(name=logKey, val=add_user_brand_all_data)
|
|
- print (redisObj.llen(name=logKey))
|
|
|
|
|
|
+ print(redisObj.llen(name=logKey))
|
|
# 判断redis列表长度
|
|
# 判断redis列表长度
|
|
if redisObj.llen(name=logKey) > 10:
|
|
if redisObj.llen(name=logKey) > 10:
|
|
data_list = redisObj.lrange(logKey, 0, -1)
|
|
data_list = redisObj.lrange(logKey, 0, -1)
|
|
@@ -526,75 +534,76 @@ class UserBrandInfo(View):
|
|
my.user_brand_all_item_put(user_brand_all, data_list)
|
|
my.user_brand_all_item_put(user_brand_all, data_list)
|
|
# 添加user_brand表信息
|
|
# 添加user_brand表信息
|
|
my.user_brand_item_put(user_brand, userID, username, addTime, deviceSupplier, deviceModel,
|
|
my.user_brand_item_put(user_brand, userID, username, addTime, deviceSupplier, deviceModel,
|
|
- osType, osVersion,
|
|
|
|
- country, province, city, area, street, longitude, latitude, appId, status,
|
|
|
|
- self.clientIP)
|
|
|
|
|
|
+ osType, osVersion,
|
|
|
|
+ country, province, city, area, street, longitude, latitude, appId, status,
|
|
|
|
+ self.clientIP)
|
|
except Exception:
|
|
except Exception:
|
|
errorInfo = traceback.format_exc()
|
|
errorInfo = traceback.format_exc()
|
|
return response.json(424, {'details': errorInfo})
|
|
return response.json(424, {'details': errorInfo})
|
|
else:
|
|
else:
|
|
- return response.json(0,{'OK':int(time.time())})
|
|
|
|
|
|
+ return response.json(0, {'OK': int(time.time())})
|
|
else:
|
|
else:
|
|
# 参数错误
|
|
# 参数错误
|
|
- return response.json(444)
|
|
|
|
-
|
|
|
|
|
|
+ return response.json(444)
|
|
|
|
|
|
# 查询每个用户的最新登录数据表
|
|
# 查询每个用户的最新登录数据表
|
|
- def query_info(self, request_dict, userID,user_brand,user_brand_all,response):
|
|
|
|
|
|
+ def query_info(self, request_dict, userID, user_brand, user_brand_all, response):
|
|
page = int(request_dict.get('page', None))
|
|
page = int(request_dict.get('page', None))
|
|
line = int(request_dict.get('line', 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])
|
|
param_flag = CommonService.get_param_flag(data=[page, line])
|
|
if param_flag is True:
|
|
if param_flag is True:
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
|
- page_value=[]
|
|
|
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
|
|
+ page_value = []
|
|
if check_perm is True:
|
|
if check_perm is True:
|
|
if username is None or username is '':
|
|
if username is None or username is '':
|
|
- table_Limit_value = my.get_page_line(page,line,user_brand,None,page_value)
|
|
|
|
|
|
+ table_Limit_value = my.get_page_line(page, line, user_brand, None, page_value)
|
|
# 页面减1
|
|
# 页面减1
|
|
- page = page-1
|
|
|
|
|
|
+ page = page - 1
|
|
if page < len(table_Limit_value):
|
|
if page < len(table_Limit_value):
|
|
# 分页后查询
|
|
# 分页后查询
|
|
- table_value = my.item_get(line,user_brand,table_Limit_value[page])
|
|
|
|
|
|
+ table_value = my.item_get(line, user_brand, table_Limit_value[page])
|
|
table_value = table_value['Items']
|
|
table_value = table_value['Items']
|
|
count = my.item_get_count(user_brand)
|
|
count = my.item_get_count(user_brand)
|
|
return response.json(0, {'datas': table_value, 'count': count})
|
|
return response.json(0, {'datas': table_value, 'count': count})
|
|
else:
|
|
else:
|
|
# 查询
|
|
# 查询
|
|
- table_value = my.get_item(user_brand, 'username' ,username)
|
|
|
|
|
|
+ table_value = my.get_item(user_brand, 'username', username)
|
|
return response.json(0, {'datas': table_value, 'count': len(table_value)})
|
|
return response.json(0, {'datas': table_value, 'count': len(table_value)})
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
else:
|
|
else:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
# 删除接口
|
|
# 删除接口
|
|
- def delete_by_admin(self, request_dict, userID,user_brand,user_brand_all,response):
|
|
|
|
|
|
+
|
|
|
|
+ def delete_by_admin(self, request_dict, userID, user_brand, user_brand_all, response):
|
|
id = request_dict.getlist('id', None)
|
|
id = request_dict.getlist('id', None)
|
|
username = request_dict.getlist('username', None)
|
|
username = request_dict.getlist('username', None)
|
|
add_time = request_dict.getlist('add_time', None)
|
|
add_time = request_dict.getlist('add_time', None)
|
|
- table_name = request_dict.getlist('table_name', None)
|
|
|
|
- param_flag = CommonService.get_param_flag(data=[id,username])
|
|
|
|
- print (table_name[0])
|
|
|
|
|
|
+ table_name = request_dict.getlist('table_name', None)
|
|
|
|
+ param_flag = CommonService.get_param_flag(data=[id, username])
|
|
|
|
+ print(table_name[0])
|
|
if param_flag is True:
|
|
if param_flag is True:
|
|
check_perm = ModelService.check_perm(userID=userID, permID=10)
|
|
check_perm = ModelService.check_perm(userID=userID, permID=10)
|
|
if check_perm is True:
|
|
if check_perm is True:
|
|
- if str(table_name[0])==str(user_brand):
|
|
|
|
- is_delete = my.item_delete(user_brand, id[0],username[0], add_time[0])
|
|
|
|
|
|
+ if str(table_name[0]) == str(user_brand):
|
|
|
|
+ is_delete = my.item_delete(user_brand, id[0], username[0], add_time[0])
|
|
else:
|
|
else:
|
|
- is_delete = my.item_delete(user_brand_all, id[0],add_time[0], add_time[0])
|
|
|
|
|
|
+ is_delete = my.item_delete(user_brand_all, id[0], add_time[0], add_time[0])
|
|
return response.json(0, {'delete_count': is_delete[0]})
|
|
return response.json(0, {'delete_count': is_delete[0]})
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
else:
|
|
else:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
+
|
|
# Query each user record statistics
|
|
# Query each user record statistics
|
|
- def query_all_info(self, request_dict, userID,user_brand,user_brand_all,response):
|
|
|
|
|
|
+ def query_all_info(self, request_dict, userID, user_brand, user_brand_all, response):
|
|
page = int(request_dict.get('page', None))
|
|
page = int(request_dict.get('page', None))
|
|
line = int(request_dict.get('line', 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])
|
|
param_flag = CommonService.get_param_flag(data=[page, line])
|
|
if param_flag is True:
|
|
if param_flag is True:
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
page_value = []
|
|
page_value = []
|
|
if check_perm is True:
|
|
if check_perm is True:
|
|
if username is None or username is '':
|
|
if username is None or username is '':
|
|
@@ -615,8 +624,8 @@ class UserBrandInfo(View):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
|
|
# Brand statistics interface
|
|
# Brand statistics interface
|
|
- def query_deviceSupplier_info(self, request_dict, userID,user_brand,user_brand_all,response):
|
|
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
|
|
|
+ def query_deviceSupplier_info(self, request_dict, userID, user_brand, user_brand_all, response):
|
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
if check_perm is True:
|
|
if check_perm is True:
|
|
table_value = my.item_get_brand(user_brand)
|
|
table_value = my.item_get_brand(user_brand)
|
|
send_jsons = []
|
|
send_jsons = []
|
|
@@ -626,26 +635,24 @@ class UserBrandInfo(View):
|
|
counts = counts + 1
|
|
counts = counts + 1
|
|
send_jsons = Counter(send_jsons)
|
|
send_jsons = Counter(send_jsons)
|
|
|
|
|
|
- return response.json(0, {'datas': send_jsons,'counts':counts})
|
|
|
|
|
|
+ return response.json(0, {'datas': send_jsons, 'counts': counts})
|
|
|
|
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
|
|
+
|
|
# Interface to area statistics
|
|
# Interface to area statistics
|
|
- def query_area_info(self, request_dict, userID,user_brand,user_brand_all,response):
|
|
|
|
- check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
|
|
|
+ def query_area_info(self, request_dict, userID, user_brand, user_brand_all, response):
|
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=30)
|
|
district = request_dict.get('district', None)
|
|
district = request_dict.get('district', None)
|
|
if check_perm is True:
|
|
if check_perm is True:
|
|
# 按照用户去重复查询
|
|
# 按照用户去重复查询
|
|
table_value = my.item_get_brand(user_brand)
|
|
table_value = my.item_get_brand(user_brand)
|
|
send_jsons = []
|
|
send_jsons = []
|
|
counts = 0
|
|
counts = 0
|
|
- for i in table_value:
|
|
|
|
|
|
+ for i in table_value:
|
|
send_jsons.append(table_value[counts][district])
|
|
send_jsons.append(table_value[counts][district])
|
|
counts = counts + 1
|
|
counts = counts + 1
|
|
send_jsons = Counter(send_jsons)
|
|
send_jsons = Counter(send_jsons)
|
|
return response.json(0, {'datas': send_jsons, 'counts': counts})
|
|
return response.json(0, {'datas': send_jsons, 'counts': counts})
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|