|
@@ -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,AWS_DynamoDB_REGION,AWS_DynamoDB_ACCESS_KEY,AWS_DynamoDB_SECRET_KEY
|
|
|
|
|
|
+from Ansjer.config import DOMAIN_HOST, AWS_DynamoDB_REGION, AWS_DynamoDB_ACCESS_KEY, AWS_DynamoDB_SECRET_KEY
|
|
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 = AWS_DynamoDB_REGION
|
|
self.region = AWS_DynamoDB_REGION
|
|
@@ -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(
|
|
@@ -129,11 +132,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)
|
|
with table.batch_writer() as batch:
|
|
with table.batch_writer() as batch:
|
|
@@ -160,7 +162,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'],
|
|
@@ -169,16 +171,16 @@ 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('批量添加数据成功!')
|
|
|
|
|
|
# 添加user_brand表数据
|
|
# 添加user_brand表数据
|
|
- def user_brand_item_put(self, table_name, user_id,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, 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)
|
|
table.put_item(
|
|
table.put_item(
|
|
@@ -201,10 +203,10 @@ class MyserviceDynamodb(object):
|
|
'ip': ip,
|
|
'ip': ip,
|
|
}
|
|
}
|
|
)
|
|
)
|
|
- print ('添加表一条数据成功!')
|
|
|
|
|
|
+ print('添加表一条数据成功!')
|
|
|
|
|
|
# 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!")
|
|
@@ -225,14 +227,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:
|
|
@@ -246,14 +248,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:
|
|
@@ -267,10 +269,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 ,username):
|
|
|
|
|
|
+ def get_item(self, table_name, 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!")
|
|
@@ -305,50 +307,51 @@ 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, name ,user_id,add_time):
|
|
|
|
|
|
+ def item_delete(self, table_name, name, user_id, add_time):
|
|
dynamodb = self.session.resource('dynamodb')
|
|
dynamodb = self.session.resource('dynamodb')
|
|
table = dynamodb.Table(table_name)
|
|
table = dynamodb.Table(table_name)
|
|
try:
|
|
try:
|
|
@@ -370,6 +373,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'))
|
|
@@ -381,6 +385,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')
|
|
|
|
|
|
@@ -419,17 +425,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)
|
|
@@ -440,8 +447,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)
|
|
@@ -455,15 +463,15 @@ 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='无'
|
|
|
|
|
|
+ latitude = '无'
|
|
if city == '':
|
|
if city == '':
|
|
city = '无'
|
|
city = '无'
|
|
if area == '':
|
|
if area == '':
|
|
@@ -474,15 +482,15 @@ class UserBrandInfo(View):
|
|
longitude = '无'
|
|
longitude = '无'
|
|
if latitude == '':
|
|
if latitude == '':
|
|
latitude = '无'
|
|
latitude = '无'
|
|
- param_area = CommonService.get_param_flag(data=[country,province,city])
|
|
|
|
- must_fill_in = CommonService.get_param_flag(data=[appId,deviceSupplier,deviceModel,osType,osVersion])
|
|
|
|
|
|
+ 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')
|
|
|
|
|
|
+ return response.json(444, 'appId,deviceSupplier,deviceModel,osType,osVersion')
|
|
if param_area is True:
|
|
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
|
|
@@ -493,7 +501,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']
|
|
@@ -506,10 +514,10 @@ 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:
|
|
addTime = int(time.time())
|
|
addTime = int(time.time())
|
|
- print (time.time())
|
|
|
|
|
|
+ print(time.time())
|
|
add_data = {
|
|
add_data = {
|
|
'userID': userID,
|
|
'userID': userID,
|
|
'addTime': addTime,
|
|
'addTime': addTime,
|
|
@@ -539,7 +547,7 @@ class UserBrandInfo(View):
|
|
# print (redisObj.llen(name=logKey))
|
|
# print (redisObj.llen(name=logKey))
|
|
# 判断redis列表长度
|
|
# 判断redis列表长度
|
|
try:
|
|
try:
|
|
- if redisObj.llen(name=logKey) == 100 :
|
|
|
|
|
|
+ if redisObj.llen(name=logKey) > 100:
|
|
data_list = redisObj.lrange(logKey, 0, -1)
|
|
data_list = redisObj.lrange(logKey, 0, -1)
|
|
redisObj.del_data(key=logKey)
|
|
redisObj.del_data(key=logKey)
|
|
# 添加user_brand_all表信息
|
|
# 添加user_brand_all表信息
|
|
@@ -547,9 +555,9 @@ class UserBrandInfo(View):
|
|
|
|
|
|
# 添加user_brand表信息
|
|
# 添加user_brand表信息
|
|
my.user_brand_item_put(user_brand, userID, addTime, deviceSupplier, deviceModel,
|
|
my.user_brand_item_put(user_brand, userID, 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:
|
|
if DOMAIN_HOST == 'www.dvema.com':
|
|
if DOMAIN_HOST == 'www.dvema.com':
|
|
user_brand = 'user_brand'
|
|
user_brand = 'user_brand'
|
|
@@ -560,21 +568,20 @@ class UserBrandInfo(View):
|
|
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)
|
|
|
|
|
|
- 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)
|
|
@@ -595,7 +602,7 @@ class UserBrandInfo(View):
|
|
username = user_ID[0]['userID']
|
|
username = user_ID[0]['userID']
|
|
except Exception:
|
|
except Exception:
|
|
username = username
|
|
username = username
|
|
- table_value = my.get_item(user_brand ,username)
|
|
|
|
|
|
+ table_value = my.get_item(user_brand, 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:
|
|
@@ -603,32 +610,34 @@ class UserBrandInfo(View):
|
|
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])
|
|
|
|
|
|
+ table_name = request_dict.getlist('table_name', None)
|
|
|
|
+ param_flag = CommonService.get_param_flag(data=[id, username])
|
|
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])=='user_brand':
|
|
|
|
- is_delete = my.item_delete(user_brand, 'user_brand' ,id[0], add_time[0])
|
|
|
|
|
|
+ if str(table_name[0]) == 'user_brand':
|
|
|
|
+ is_delete = my.item_delete(user_brand, 'user_brand', id[0], add_time[0])
|
|
else:
|
|
else:
|
|
- is_delete = my.item_delete(user_brand_all, 'user_brand_all',id[0], add_time[0])
|
|
|
|
|
|
+ is_delete = my.item_delete(user_brand_all, 'user_brand_all', id[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 '':
|
|
@@ -651,15 +660,15 @@ class UserBrandInfo(View):
|
|
|
|
|
|
table_value = my.get_item(user_brand_all, username)
|
|
table_value = my.get_item(user_brand_all, 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)
|
|
|
|
|
|
# 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 = []
|
|
@@ -669,26 +678,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)
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|