chenjunkai 5 年之前
父节点
当前提交
c6b040a675
共有 2 个文件被更改,包括 49 次插入80 次删除
  1. 10 3
      Ansjer/config.py
  2. 39 77
      Controller/UserBrandController.py

+ 10 - 3
Ansjer/config.py

@@ -17,11 +17,9 @@ import datetime, os
 SERVER_TYPE = os.environ.get('DJANGO_SETTINGS_MODULE')
 print(SERVER_TYPE)
 
-
-
 # 亚马逊的数据库DynamoDB的密钥
 AWS_DynamoDB_REGION = 'us-west-1'
-AWS_DynamoDB_ACCESS_KEY =  'AKIA2E67UIMD4PZTYKYD'
+AWS_DynamoDB_ACCESS_KEY = 'AKIA2E67UIMD4PZTYKYD'
 AWS_DynamoDB_SECRET_KEY = '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'
 
 # 阿里云发邮箱
@@ -78,6 +76,9 @@ if SERVER_TYPE == 'Ansjer.local_settings':
         "client_secret": "EGkMCB3RWTcUGJGDYahJ9mCO0AQzEn2AvFfx1GAFjfyyn7-8a0NObcZks89QorlFpvNWTsDXVa2INRNM"
     }
     DETECT_PUSH_DOMAIN = 'http://test.push.dvema.com/'
+    # 数据库dyanamo品牌日志数据库
+    USER_BRAND = 'test_user_brand'
+    USER_BRAND_ALL = 'test_user_brand_all'
 
 elif SERVER_TYPE == 'Ansjer.test_settings':
     NGINX_RTMP_STAT = 'http://test.dvema.com/stat'
@@ -95,6 +96,9 @@ elif SERVER_TYPE == 'Ansjer.test_settings':
         # "client_secret": "EGkMCB3RWTcUGJGDYahJ9mCO0AQzEn2AvFfx1GAFjfyyn7-8a0NObcZks89QorlFpvNWTsDXVa2INRNM"
     }
     DETECT_PUSH_DOMAIN = 'http://test.push.dvema.com/'
+    # 数据库dyanamo品牌日志数据库
+    USER_BRAND = 'test_user_brand'
+    USER_BRAND_ALL = 'test_user_brand_all'
 
 elif SERVER_TYPE == 'Ansjer.formal_settings':
     NGINX_RTMP_STAT = 'http://www.dvema.com/stat'
@@ -108,6 +112,9 @@ elif SERVER_TYPE == 'Ansjer.formal_settings':
         "client_secret": "ENT-J08N3Fw0B0uAokg4RukljAwO9hFHPf8whE6-Dwd8oBWJO8AWMgpdTKpfB1pOy89t4bsFEzMWDowm"
     }
     DETECT_PUSH_DOMAIN = 'http://push.dvema.com/'
+    # 数据库dyanamo品牌日志数据库
+    USER_BRAND = 'user_brand'
+    USER_BRAND_ALL = 'user_brand_all'
 # type =2
 JPUSH_CONFIG = {
     'com.ansjer.accloud_ab': {

+ 39 - 77
Controller/UserBrandController.py

@@ -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: