|
@@ -12,19 +12,21 @@
|
|
|
@Contact: pzb3076@163.com
|
|
|
"""
|
|
|
|
|
|
-from django.views.generic.base import View
|
|
|
+import time
|
|
|
+from collections import Counter
|
|
|
+
|
|
|
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 django.utils import timezone
|
|
|
-import traceback, time, json, urllib.request
|
|
|
+from django.views.generic.base import View
|
|
|
+
|
|
|
+from Ansjer.config import DOMAIN_HOST, AWS_DynamoDB_REGION, AWS_DynamoDB_ACCESS_KEY, AWS_DynamoDB_SECRET_KEY, \
|
|
|
+ USER_BRAND, USER_BRAND_ALL
|
|
|
+from Model.models import Device_User
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
-from collections import Counter
|
|
|
-from Ansjer.config import DOMAIN_HOST, AWS_DynamoDB_REGION, AWS_DynamoDB_ACCESS_KEY, AWS_DynamoDB_SECRET_KEY
|
|
|
-from Object.RedisObject import RedisObject
|
|
|
+from Service.ModelService import ModelService
|
|
|
|
|
|
'''
|
|
|
http://192.168.136.39:8000/userbrandinfo/queryByAdmin?token=test&page=1&line=10 记录
|
|
@@ -377,14 +379,9 @@ class MyserviceDynamodb(object):
|
|
|
my = MyserviceDynamodb()
|
|
|
# print(my.table_delete('user_brand'))
|
|
|
# print(my.table_delete('user_brand_all'))
|
|
|
-if DOMAIN_HOST == 'www.dvema.com':
|
|
|
- user_brand = 'user_brand'
|
|
|
- user_brand_all = 'user_brand_all'
|
|
|
-else:
|
|
|
- user_brand = 'test_user_brand'
|
|
|
- user_brand_all = 'test_user_brand_all'
|
|
|
-my.table_create(user_brand)
|
|
|
-my.user_brand_all_table_create(user_brand_all)
|
|
|
+
|
|
|
+my.table_create(USER_BRAND)
|
|
|
+my.user_brand_all_table_create(USER_BRAND_ALL)
|
|
|
|
|
|
|
|
|
# print(my.item_put('user_brand'))
|
|
@@ -407,46 +404,30 @@ class UserBrandInfo(View):
|
|
|
return self.validation(request.POST, request, operation)
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
- if operation is None:
|
|
|
- return response.json(444, 'error path')
|
|
|
self.clientIP = CommonService.get_ip_address(request)
|
|
|
response = ResponseObject()
|
|
|
token = request_dict.get('token', None)
|
|
|
- if token is not None:
|
|
|
- tko = TokenObject(token)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ if tko.code == 0:
|
|
|
response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if DOMAIN_HOST == 'www.dvema.com':
|
|
|
- user_brand = 'user_brand'
|
|
|
- user_brand_all = 'user_brand_all'
|
|
|
- else:
|
|
|
- user_brand = 'test_user_brand'
|
|
|
- user_brand_all = 'test_user_brand_all'
|
|
|
- if userID is not None:
|
|
|
- if operation == 'queryByAdmin':
|
|
|
- return self.query_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
|
- elif operation == 'add':
|
|
|
- return self.add_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
|
- elif operation == 'queryAllByAdmin':
|
|
|
- return self.query_all_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
|
- elif operation == 'deleteByAdmin':
|
|
|
- return self.delete_by_admin(request_dict, userID, user_brand, user_brand_all, response)
|
|
|
- elif operation == 'queryDeviceSupplier':
|
|
|
- return self.query_deviceSupplier_info(request_dict, userID, user_brand, user_brand_all,
|
|
|
- response)
|
|
|
- elif operation == 'queryArea':
|
|
|
- return self.query_area_info(request_dict, userID, user_brand, user_brand_all, response)
|
|
|
-
|
|
|
- else:
|
|
|
- return response.json(444)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'add':
|
|
|
+ return self.add_info(request_dict, userID, USER_BRAND, USER_BRAND_ALL, response)
|
|
|
+ elif operation == 'queryByAdmin':
|
|
|
+ return self.query_info(request_dict, userID, USER_BRAND, USER_BRAND_ALL, response)
|
|
|
+ elif operation == 'queryAllByAdmin':
|
|
|
+ return self.query_all_info(request_dict, userID, USER_BRAND, USER_BRAND_ALL, response)
|
|
|
+ elif operation == 'deleteByAdmin':
|
|
|
+ return self.delete_by_admin(request_dict, userID, USER_BRAND, USER_BRAND_ALL, response)
|
|
|
+ elif operation == 'queryDeviceSupplier':
|
|
|
+ return self.query_deviceSupplier_info(request_dict, userID, USER_BRAND, USER_BRAND_ALL, response)
|
|
|
+ elif operation == 'queryArea':
|
|
|
+ return self.query_area_info(request_dict, userID, USER_BRAND, USER_BRAND_ALL, response)
|
|
|
+
|
|
|
else:
|
|
|
- return response.json(tko.code)
|
|
|
+ return response.json(444)
|
|
|
else:
|
|
|
- return response.json(309)
|
|
|
- # 获取外网IP
|
|
|
+ return response.json(tko.code)
|
|
|
|
|
|
# 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):
|
|
@@ -456,22 +437,12 @@ class UserBrandInfo(View):
|
|
|
osVersion = request_dict.get('osVersion', None)
|
|
|
country = request_dict.get('country', None)
|
|
|
province = request_dict.get('province', None)
|
|
|
- city = request_dict.get('city', None)
|
|
|
- area = request_dict.get('area', None)
|
|
|
- street = request_dict.get('street', None)
|
|
|
- longitude = request_dict.get('longitude', None)
|
|
|
- latitude = request_dict.get('latitude', None)
|
|
|
+ city = request_dict.get('city', '')
|
|
|
+ area = request_dict.get('area', '')
|
|
|
+ street = request_dict.get('street', '')
|
|
|
+ longitude = request_dict.get('longitude', '')
|
|
|
+ latitude = request_dict.get('latitude', '')
|
|
|
appId = request_dict.get('appId', None)
|
|
|
- if city is None:
|
|
|
- city = '无'
|
|
|
- if area is None:
|
|
|
- area = '无'
|
|
|
- if street is None:
|
|
|
- street = '无'
|
|
|
- if longitude is None:
|
|
|
- longitude = '无'
|
|
|
- if latitude is None:
|
|
|
- latitude = '无'
|
|
|
if city == '':
|
|
|
city = '无'
|
|
|
if area == '':
|
|
@@ -539,10 +510,7 @@ class UserBrandInfo(View):
|
|
|
}
|
|
|
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'
|
|
|
+ logKey = USER_BRAND_ALL
|
|
|
redisObj.rpush(name=logKey, val=add_user_brand_all_data)
|
|
|
# print (redisObj.llen(name=logKey))
|
|
|
# 判断redis列表长度
|
|
@@ -559,14 +527,8 @@ class UserBrandInfo(View):
|
|
|
country, province, city, area, street, longitude, latitude, appId, status,
|
|
|
self.clientIP)
|
|
|
except Exception:
|
|
|
- if DOMAIN_HOST == 'www.dvema.com':
|
|
|
- user_brand = 'user_brand'
|
|
|
- user_brand_all = 'user_brand_all'
|
|
|
- else:
|
|
|
- user_brand = 'test_user_brand'
|
|
|
- user_brand_all = 'test_user_brand_all'
|
|
|
- my.table_create(user_brand)
|
|
|
- my.user_brand_all_table_create(user_brand_all)
|
|
|
+ my.table_create(USER_BRAND)
|
|
|
+ my.user_brand_all_table_create(USER_BRAND_ALL)
|
|
|
|
|
|
return response.json(0, {'OK': int(time.time())})
|
|
|
else:
|