|
@@ -145,35 +145,32 @@ class MyserviceDynamodb(object):
|
|
|
def user_brand_all_item_put(self, table_name,data_list):
|
|
|
dynamodb = self.session.resource('dynamodb')
|
|
|
table = dynamodb.Table(table_name)
|
|
|
- try:
|
|
|
- with table.batch_writer() as batch:
|
|
|
- for i in data_list:
|
|
|
- data = json.loads(i.decode('utf-8'))
|
|
|
- batch.put_item(
|
|
|
- Item={
|
|
|
- 'userID': data['userID'],
|
|
|
- 'addTime': data['addTime'],
|
|
|
- 'username': data['username'],
|
|
|
- 'deviceSupplier': data['deviceSupplier'],
|
|
|
- 'deviceModel': data['deviceModel'],
|
|
|
- 'osType': data['osType'],
|
|
|
- 'osVersion': data['osVersion'],
|
|
|
- 'country' : data['country'],
|
|
|
- 'province': data['province'],
|
|
|
- 'city': data['city'],
|
|
|
- 'area': data['area'],
|
|
|
- 'street': data['street'],
|
|
|
- 'longitude': data['longitude'],
|
|
|
- 'latitude': data['latitude'],
|
|
|
- 'appId': data['appId'],
|
|
|
- 'status_all': data['status_all'],
|
|
|
- 'ExpirationTime_TTL' : data['ExpirationTime_TTL'],
|
|
|
- 'ip': data['ip'],
|
|
|
- }
|
|
|
- )
|
|
|
- print ('批量添加数据成功!')
|
|
|
- except Exception:
|
|
|
- logger.error ('批量添加表数据失败!')
|
|
|
+ with table.batch_writer() as batch:
|
|
|
+ for i in data_list:
|
|
|
+ data = json.loads(i.decode('utf-8'))
|
|
|
+ batch.put_item(
|
|
|
+ Item={
|
|
|
+ 'userID': data['userID'],
|
|
|
+ 'addTime': data['addTime'],
|
|
|
+ 'username': data['username'],
|
|
|
+ 'deviceSupplier': data['deviceSupplier'],
|
|
|
+ 'deviceModel': data['deviceModel'],
|
|
|
+ 'osType': data['osType'],
|
|
|
+ 'osVersion': data['osVersion'],
|
|
|
+ 'country' : data['country'],
|
|
|
+ 'province': data['province'],
|
|
|
+ 'city': data['city'],
|
|
|
+ 'area': data['area'],
|
|
|
+ 'street': data['street'],
|
|
|
+ 'longitude': data['longitude'],
|
|
|
+ 'latitude': data['latitude'],
|
|
|
+ 'appId': data['appId'],
|
|
|
+ 'status_all': data['status_all'],
|
|
|
+ 'ExpirationTime_TTL' : data['ExpirationTime_TTL'],
|
|
|
+ 'ip': data['ip'],
|
|
|
+ }
|
|
|
+ )
|
|
|
+ print ('批量添加数据成功!')
|
|
|
|
|
|
# 添加user_brand表数据
|
|
|
def user_brand_item_put(self, table_name, user_id, username,add_time, device_supplier, device_model, os_type,
|
|
@@ -181,32 +178,29 @@ class MyserviceDynamodb(object):
|
|
|
status_all, ip):
|
|
|
dynamodb = self.session.resource('dynamodb')
|
|
|
table = dynamodb.Table(table_name)
|
|
|
- try:
|
|
|
- table.put_item(
|
|
|
- Item={
|
|
|
- 'userID': user_id,
|
|
|
- 'username': username,
|
|
|
- 'addTime': add_time,
|
|
|
- 'deviceSupplier': device_supplier,
|
|
|
- 'deviceModel': device_model,
|
|
|
- 'osType': os_type,
|
|
|
- 'osVersion': os_version,
|
|
|
- 'country': country,
|
|
|
- 'province': province,
|
|
|
- 'city': city,
|
|
|
- 'area': area,
|
|
|
- 'street': street,
|
|
|
- 'longitude': longitude,
|
|
|
- 'latitude': latitude,
|
|
|
- 'appId': app_id,
|
|
|
- 'ExpirationTime_TTL': add_time + 2592000,
|
|
|
- 'status_all': status_all,
|
|
|
- 'ip': ip,
|
|
|
- }
|
|
|
- )
|
|
|
- print ('添加表一条数据成功!')
|
|
|
- except Exception:
|
|
|
- logger.error ('添加表一条数据失败!')
|
|
|
+ table.put_item(
|
|
|
+ Item={
|
|
|
+ 'userID': user_id,
|
|
|
+ 'username': username,
|
|
|
+ 'addTime': add_time,
|
|
|
+ 'deviceSupplier': device_supplier,
|
|
|
+ 'deviceModel': device_model,
|
|
|
+ 'osType': os_type,
|
|
|
+ 'osVersion': os_version,
|
|
|
+ 'country': country,
|
|
|
+ 'province': province,
|
|
|
+ 'city': city,
|
|
|
+ 'area': area,
|
|
|
+ 'street': street,
|
|
|
+ 'longitude': longitude,
|
|
|
+ 'latitude': latitude,
|
|
|
+ 'appId': app_id,
|
|
|
+ 'ExpirationTime_TTL': add_time + 2592000,
|
|
|
+ 'status_all': status_all,
|
|
|
+ 'ip': ip,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ print ('添加表一条数据成功!')
|
|
|
|
|
|
# page分页数,line条数,table_name表名称,last_evaluated查询开始值,page_value记录分页开始值
|
|
|
def get_page_line(self, page, line, table_name, last_evaluated,page_value):
|
|
@@ -455,7 +449,7 @@ class UserBrandInfo(View):
|
|
|
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:
|
|
|
+ if param_area is True:
|
|
|
if '省' in province:
|
|
|
province = province.replace('省','')
|
|
|
if '市' in city:
|
|
@@ -485,55 +479,55 @@ class UserBrandInfo(View):
|
|
|
|
|
|
param_flag = CommonService.get_param_flag(data=[deviceSupplier, deviceModel,osType,osVersion])
|
|
|
if param_flag is True:
|
|
|
+
|
|
|
+ addTime = int(time.time())
|
|
|
+ print (time.time())
|
|
|
+ username = Device_User.objects.filter(userID = userID).values('userID','username','NickName')
|
|
|
try:
|
|
|
- addTime = int(time.time())
|
|
|
- print (time.time())
|
|
|
- username = Device_User.objects.filter(userID = userID).values('userID','username','NickName')
|
|
|
username = username[0]['username']
|
|
|
- add_data = {
|
|
|
- 'userID': userID,
|
|
|
- 'addTime': addTime,
|
|
|
- 'username': username,
|
|
|
- 'deviceSupplier': deviceSupplier,
|
|
|
- 'deviceModel': deviceModel,
|
|
|
- 'osType': osType,
|
|
|
- 'osVersion': osVersion,
|
|
|
- 'country': country,
|
|
|
- 'province': province,
|
|
|
- 'city': city,
|
|
|
- 'area': area,
|
|
|
- 'street': street,
|
|
|
- 'longitude': longitude,
|
|
|
- 'latitude': latitude,
|
|
|
- 'appId': appId,
|
|
|
- 'status_all': status,
|
|
|
- 'ExpirationTime_TTL': addTime + 2592000,
|
|
|
- 'ip': self.clientIP
|
|
|
- }
|
|
|
- redisObj = RedisObject()
|
|
|
- add_user_brand_all_data = json.dumps(add_data)
|
|
|
- if DOMAIN_HOST == 'www.dvema.com':
|
|
|
- logKey = 'user_brand_all'
|
|
|
- else:
|
|
|
- logKey = 'test_user_brand_all'
|
|
|
- redisObj.rpush(name=logKey, val=add_user_brand_all_data)
|
|
|
- print (redisObj.llen(name=logKey))
|
|
|
- # 判断redis列表长度
|
|
|
- if redisObj.llen(name=logKey) > 10:
|
|
|
- data_list = redisObj.lrange(logKey, 0, -1)
|
|
|
- redisObj.del_data(key=logKey)
|
|
|
- # 添加user_brand_all表信息
|
|
|
- my.user_brand_all_item_put(user_brand_all, data_list)
|
|
|
- # 添加user_brand表信息
|
|
|
- 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)
|
|
|
except Exception:
|
|
|
- errorInfo = traceback.format_exc()
|
|
|
- return response.json(424, {'details': errorInfo})
|
|
|
+ username = '无'
|
|
|
+ add_data = {
|
|
|
+ 'userID': userID,
|
|
|
+ 'addTime': addTime,
|
|
|
+ 'username': username,
|
|
|
+ 'deviceSupplier': deviceSupplier,
|
|
|
+ 'deviceModel': deviceModel,
|
|
|
+ 'osType': osType,
|
|
|
+ 'osVersion': osVersion,
|
|
|
+ 'country': country,
|
|
|
+ 'province': province,
|
|
|
+ 'city': city,
|
|
|
+ 'area': area,
|
|
|
+ 'street': street,
|
|
|
+ 'longitude': longitude,
|
|
|
+ 'latitude': latitude,
|
|
|
+ 'appId': appId,
|
|
|
+ 'status_all': status,
|
|
|
+ 'ExpirationTime_TTL': addTime + 2592000,
|
|
|
+ 'ip': self.clientIP
|
|
|
+ }
|
|
|
+ redisObj = RedisObject()
|
|
|
+ add_user_brand_all_data = json.dumps(add_data)
|
|
|
+ if DOMAIN_HOST == 'www.dvema.com':
|
|
|
+ logKey = 'user_brand_all'
|
|
|
else:
|
|
|
- return response.json(0,{'OK':int(time.time())})
|
|
|
+ logKey = 'test_user_brand_all'
|
|
|
+ redisObj.rpush(name=logKey, val=add_user_brand_all_data)
|
|
|
+ print (redisObj.llen(name=logKey))
|
|
|
+ # 判断redis列表长度
|
|
|
+ if redisObj.llen(name=logKey) > 10:
|
|
|
+ data_list = redisObj.lrange(logKey, 0, -1)
|
|
|
+ redisObj.del_data(key=logKey)
|
|
|
+ # 添加user_brand_all表信息
|
|
|
+ my.user_brand_all_item_put(user_brand_all, data_list)
|
|
|
+ # 添加user_brand表信息
|
|
|
+ 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)
|
|
|
+
|
|
|
+ return response.json(0,{'OK':int(time.time())})
|
|
|
else:
|
|
|
# 参数错误
|
|
|
return response.json(444)
|