Переглянути джерело

Merge remote-tracking branch 'remotes/origin/dev' into test

tanghongbin 5 роки тому
батько
коміт
ae8799fd97
4 змінених файлів з 163 додано та 166 видалено
  1. 3 4
      Ansjer/urls.py
  2. 81 82
      Controller/AdminManage.py
  3. 2 2
      Controller/EquipmentManagerV3.py
  4. 77 78
      Controller/UserController.py

+ 3 - 4
Ansjer/urls.py

@@ -210,11 +210,10 @@ urlpatterns = [
     url(r'^date/(?P<operation>.*)$', DateController.DateConView.as_view()),
 
     url(r'^equipment/flow_test$', EquipmentManager.uid_status_test),
-    url(r'^account/appFrequency/(?P<operation>.*)$', UserController.UserAppFrequencyView.as_view()),
+    # url(r'^account/appFrequency/(?P<operation>.*)$', UserController.UserAppFrequencyView.as_view()),
     url(r'^v2/userbrand/(?P<operation>.*)$', UserBrandControllerV2.UserBrandV2.as_view()),
-    # url(r'^test/add$', GenerateDataController.GenerateDataView.as_view()),
-    url(r'^statistcs/appFrequencyMonth$', StatisticsController.statistcsAppFrequency),
-    url(r'^statistcs/appFrequencyYear$', StatisticsController.statistcsAppFrequencyYear),
+    # url(r'^statistcs/appFrequencyMonth$', StatisticsController.statistcsAppFrequency),
+    # url(r'^statistcs/appFrequencyYear$', StatisticsController.statistcsAppFrequencyYear),
     # app 设备消息模板
     # 路由加参数参考
     # url(r'^(?P<path>.*)/(?P<UID>.*)/lls$', Test.Test.as_view(), name=u'gg'),

+ 81 - 82
Controller/AdminManage.py

@@ -6,8 +6,7 @@ from django.views.decorators.csrf import csrf_exempt
 from django.views.generic import TemplateView
 from django.utils.decorators import method_decorator
 from django.contrib.auth.hashers import make_password  # 对密码加密模块
-from Model.models import Device_Info, Role, UserExModel, User_Brand, UidSetModel, UserAppFrequencyModel, \
-    AppFrequencyStatisticsModel, AppFrequencyYearStatisticsModel
+from Model.models import Device_Info, Role, UserExModel, User_Brand, UidSetModel
 from Service.ModelService import ModelService
 from django.utils import timezone
 from Model.models import Access_Log, Device_User
@@ -344,86 +343,86 @@ class AdminManage(TemplateView):
         model_data['quantity'] = quantity
         return response.json(0, res)
 
-    def getAppFrequency(self, userID, request_dict, response):
-        own_permission = ModelService.check_perm(userID=userID, permID=30)
-        if own_permission is not True:
-            return response.json(404)
-
-        # 当前的年份
-        current_time = int(time.time())
-        localtime = time.localtime(current_time)
-        current_year = localtime.tm_year
-        current_month = localtime.tm_mon
-
-        start_year = end_year = current_year
-        end_month = current_month
-        start_month = 1
-
-        result = []
-        if end_month != 12:
-            start_month = end_month + 1
-            start_year = current_year - 1
-
-        time_struct = [start_year, start_month, 0, 0, 0, 0, 0, 0, 0]
-        key_formal = '{year}{month}'
-        for i in range(12):
-            result.append({
-                'date_time': key_formal.format(year=time_struct[0], month=str(time_struct[1]).zfill(2)),
-                'data': None
-            })
-
-            month = time_struct[1] + 1
-            if month > 12:
-                time_struct[0] = time_struct[0] + 1
-                time_struct[1] = 1
-            else:
-                time_struct[1] = month
-        #
-        afs_qs = {}
-        if start_year == end_year:
-            afs_qs = list(AppFrequencyStatisticsModel.objects.filter(year=start_year, month__gte=start_month, month__lte=end_month).values().order_by('-year', 'month'))
-        else:
-            afs_qs = list(AppFrequencyStatisticsModel.objects.filter(year=start_year, month__gte=start_month).values().order_by('-year', 'month'))
-            tmps_qs = list(AppFrequencyStatisticsModel.objects.filter(year=end_year, month__lte=end_month).values().order_by('-year', 'month'))
-            for tmp in tmps_qs:
-                afs_qs.append(tmp)
-
-        tmp_dict = {}
-
-        for afs in afs_qs:
-            key = key_formal.format(year=afs['year'], month=str(afs['month']).zfill(2))
-            tmp_dict[key] = json.loads(afs['data'])
-
-        for res in result:
-            if tmp_dict.__contains__(res['date_time']):
-                res['data'] = tmp_dict[res['date_time']]
-        print(result)
-
-        return response.json(0, result)
-
-    def getAllAppFrequency(self, userID, response):
-        own_permission = ModelService.check_perm(userID=userID, permID=30)
-        if own_permission is not True:
-            return response.json(404)
-
-        # 取出请求年份的统计好的数据
-        print('start')
-        time_struct = time.localtime()
-        current_year = time_struct.tm_year
-        start_year = current_year - 5 + 1
-        afs_qs = AppFrequencyYearStatisticsModel.objects.filter(year__gte=start_year, year__lt=current_year).order_by(
-            '-year')
-        if afs_qs.exists():
-            afs_qs = afs_qs.values('id', 'data', 'num', 'year')
-            res = []
-            for afs in afs_qs:
-                res.append({
-                    'year': afs['year'],
-                    'data': json.loads(afs['data'])
-                })
-            return response.json(0, res)
-        else:
-            return response.json(0, [])
+    # def getAppFrequency(self, userID, request_dict, response):
+    #     own_permission = ModelService.check_perm(userID=userID, permID=30)
+    #     if own_permission is not True:
+    #         return response.json(404)
+    #
+    #     # 当前的年份
+    #     current_time = int(time.time())
+    #     localtime = time.localtime(current_time)
+    #     current_year = localtime.tm_year
+    #     current_month = localtime.tm_mon
+    #
+    #     start_year = end_year = current_year
+    #     end_month = current_month
+    #     start_month = 1
+    #
+    #     result = []
+    #     if end_month != 12:
+    #         start_month = end_month + 1
+    #         start_year = current_year - 1
+    #
+    #     time_struct = [start_year, start_month, 0, 0, 0, 0, 0, 0, 0]
+    #     key_formal = '{year}{month}'
+    #     for i in range(12):
+    #         result.append({
+    #             'date_time': key_formal.format(year=time_struct[0], month=str(time_struct[1]).zfill(2)),
+    #             'data': None
+    #         })
+    #
+    #         month = time_struct[1] + 1
+    #         if month > 12:
+    #             time_struct[0] = time_struct[0] + 1
+    #             time_struct[1] = 1
+    #         else:
+    #             time_struct[1] = month
+    #     #
+    #     afs_qs = {}
+    #     if start_year == end_year:
+    #         afs_qs = list(AppFrequencyStatisticsModel.objects.filter(year=start_year, month__gte=start_month, month__lte=end_month).values().order_by('-year', 'month'))
+    #     else:
+    #         afs_qs = list(AppFrequencyStatisticsModel.objects.filter(year=start_year, month__gte=start_month).values().order_by('-year', 'month'))
+    #         tmps_qs = list(AppFrequencyStatisticsModel.objects.filter(year=end_year, month__lte=end_month).values().order_by('-year', 'month'))
+    #         for tmp in tmps_qs:
+    #             afs_qs.append(tmp)
+    #
+    #     tmp_dict = {}
+    #
+    #     for afs in afs_qs:
+    #         key = key_formal.format(year=afs['year'], month=str(afs['month']).zfill(2))
+    #         tmp_dict[key] = json.loads(afs['data'])
+    #
+    #     for res in result:
+    #         if tmp_dict.__contains__(res['date_time']):
+    #             res['data'] = tmp_dict[res['date_time']]
+    #     print(result)
+    #
+    #     return response.json(0, result)
+    #
+    # def getAllAppFrequency(self, userID, response):
+    #     own_permission = ModelService.check_perm(userID=userID, permID=30)
+    #     if own_permission is not True:
+    #         return response.json(404)
+    #
+    #     # 取出请求年份的统计好的数据
+    #     print('start')
+    #     time_struct = time.localtime()
+    #     current_year = time_struct.tm_year
+    #     start_year = current_year - 5 + 1
+    #     afs_qs = AppFrequencyYearStatisticsModel.objects.filter(year__gte=start_year, year__lt=current_year).order_by(
+    #         '-year')
+    #     if afs_qs.exists():
+    #         afs_qs = afs_qs.values('id', 'data', 'num', 'year')
+    #         res = []
+    #         for afs in afs_qs:
+    #             res.append({
+    #                 'year': afs['year'],
+    #                 'data': json.loads(afs['data'])
+    #             })
+    #         return response.json(0, res)
+    #     else:
+    #         return response.json(0, [])
 
 
 @require_http_methods(["GET"])

+ 2 - 2
Controller/EquipmentManagerV3.py

@@ -304,7 +304,7 @@ class EquipmentManagerV3(View):
                         p['ucode'] = ''
                     data.append(p)
                 # 缓存时间为一个钟
-                redisObj.set_data(key='uid_qs_'+userID, val=data, expire=3600)
+                redisObj.set_data(key='uid_qs_'+userID, val=json.dumps(data), expire=3600)
                 result = data
                 print('分页')
                 # items=[]
@@ -326,7 +326,7 @@ class EquipmentManagerV3(View):
                     redis_value = json.loads(redis_value)
                 except Exception as e:
                     print(repr(e))
-                    return response.json(0, {'data': redis_value})
+                    return response.json(0, redis_value)
                 result = redis_value
 
             if NickName:

+ 77 - 78
Controller/UserController.py

@@ -27,8 +27,7 @@ from ratelimit.decorators import ratelimit
 
 from Ansjer.config import AuthCode_Expire, SERVER_DOMAIN, APNS_CONFIG, JPUSH_CONFIG, FCM_CONFIG, TUTK_PUSH_DOMAIN
 from Controller.CheckUserData import DataValid, date_handler, RandomStr
-from Model.models import Device_User, Role, UidPushModel, UserOauth2Model, UserExModel, Device_Info, UidSetModel, \
-    UserAppFrequencyModel
+from Model.models import Device_User, Role, UidPushModel, UserOauth2Model, UserExModel, Device_Info, UidSetModel
 from Object.AWS.SesClassObject import SesClassObject
 from Object.AliSmsObject import AliSmsObject
 from Object.RedisObject import RedisObject
@@ -2627,7 +2626,7 @@ class alexaUidView(TemplateView):
                 uid_list.append(uid_q['UID'])
                 # 给uid_q['UID']赋值
                 uid_dict[uid_q['UID']] = {'nick': uid_q['NickName'], 'password': uid_q['View_Password']}
-            us_qs = UidSetModel.objects.filter(uid__in=uid_list, is_alexa=2).values('uid', 'region_alexa')
+            us_qs = UidSetModel.objects.filter(uid__in=uid_list, is_alexa=1).values('uid', 'region_alexa')
             # uid,password,region的列表
             uid_arr = []
             for us in us_qs:
@@ -2928,81 +2927,81 @@ class Image_Code_RegisterView(TemplateView):
         return response.json(0, res)
 
 
-class UserAppFrequencyView(TemplateView):
-    @method_decorator(csrf_exempt)
-    def dispatch(self, *args, **kwargs):
-        return super(UserAppFrequencyView, self).dispatch(*args, **kwargs)
-
-    def post(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        request_dict = request.POST
-        operation = kwargs.get('operation')
-        return self.validates(request_dict, operation)
-
-    def get(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        request_dict = request.GET
-        operation = kwargs.get('operation')
-        return self.validates(request_dict, operation)
-
-    def validates(self, request_dict, operation):
-        token = request_dict.get('token', None)
-        response = ResponseObject()
-
-        token = TokenObject(token)
-        if token.code != 0:
-            return response.json(token.code)
-
-        if operation == 'refresh':
-            return self.do_refresh(request_dict, token.userID, response)
-        else:
-            return response.json(404)
-
-    def do_refresh(self, request_dict, userID, response):
-        # return response.json(0)
-        type = request_dict.get('type', None)
-        month = request_dict.get('month', None)
-        if not type or not month:
-            return response.json(444, 'type')
-        else:
-            type = int(type)
-            now_time = int(time.time())
-            month = int(month)
-            uaf_qs = UserAppFrequencyModel.objects.filter(user__userID=userID)
-
-            if not uaf_qs.exists():
-                user = Device_User.objects.filter(userID=userID)[0]
-                data = {
-                    'user': user,
-                    'type': type,
-                    'data_time': month,
-                    'add_time': now_time,
-                    'update_time': now_time,
-                }
-                UserAppFrequencyModel.objects.create(**data)
-                return response.json(0)
-            else:
-                updateMonth = time.strftime('%m', time.localtime(month))
-                uaf = uaf_qs.values('id', 'type', 'data_time')[0]
-                dbMonth = time.strftime('%m', time.localtime(int(uaf['data_time'])))
-                print('update month is ' + updateMonth)
-                print('db month is ' + dbMonth)
-                if updateMonth == dbMonth:
-                    UserAppFrequencyModel.objects.filter(id=uaf['id']).update(type=type)
-                    return response.json(0)
-                elif updateMonth > dbMonth:
-                    user = Device_User.objects.filter(userID=userID)[0]
-                    data = {
-                        'user': user,
-                        'type': type,
-                        'data_time': month,
-                        'add_time': now_time,
-                        'update_time': now_time,
-                    }
-                    UserAppFrequencyModel.objects.create(**data)
-                    return response.json(0)
-                else:
-                    return response.json(444, 'month')
+# class UserAppFrequencyView(TemplateView):
+#     @method_decorator(csrf_exempt)
+#     def dispatch(self, *args, **kwargs):
+#         return super(UserAppFrequencyView, self).dispatch(*args, **kwargs)
+#
+#     def post(self, request, *args, **kwargs):
+#         request.encoding = 'utf-8'
+#         request_dict = request.POST
+#         operation = kwargs.get('operation')
+#         return self.validates(request_dict, operation)
+#
+#     def get(self, request, *args, **kwargs):
+#         request.encoding = 'utf-8'
+#         request_dict = request.GET
+#         operation = kwargs.get('operation')
+#         return self.validates(request_dict, operation)
+#
+#     def validates(self, request_dict, operation):
+#         token = request_dict.get('token', None)
+#         response = ResponseObject()
+#
+#         token = TokenObject(token)
+#         if token.code != 0:
+#             return response.json(token.code)
+#
+#         if operation == 'refresh':
+#             return self.do_refresh(request_dict, token.userID, response)
+#         else:
+#             return response.json(404)
+#
+#     def do_refresh(self, request_dict, userID, response):
+#         # return response.json(0)
+#         type = request_dict.get('type', None)
+#         month = request_dict.get('month', None)
+#         if not type or not month:
+#             return response.json(444, 'type')
+#         else:
+#             type = int(type)
+#             now_time = int(time.time())
+#             month = int(month)
+#             uaf_qs = UserAppFrequencyModel.objects.filter(user__userID=userID)
+#
+#             if not uaf_qs.exists():
+#                 user = Device_User.objects.filter(userID=userID)[0]
+#                 data = {
+#                     'user': user,
+#                     'type': type,
+#                     'data_time': month,
+#                     'add_time': now_time,
+#                     'update_time': now_time,
+#                 }
+#                 UserAppFrequencyModel.objects.create(**data)
+#                 return response.json(0)
+#             else:
+#                 updateMonth = time.strftime('%m', time.localtime(month))
+#                 uaf = uaf_qs.values('id', 'type', 'data_time')[0]
+#                 dbMonth = time.strftime('%m', time.localtime(int(uaf['data_time'])))
+#                 print('update month is ' + updateMonth)
+#                 print('db month is ' + dbMonth)
+#                 if updateMonth == dbMonth:
+#                     UserAppFrequencyModel.objects.filter(id=uaf['id']).update(type=type)
+#                     return response.json(0)
+#                 elif updateMonth > dbMonth:
+#                     user = Device_User.objects.filter(userID=userID)[0]
+#                     data = {
+#                         'user': user,
+#                         'type': type,
+#                         'data_time': month,
+#                         'add_time': now_time,
+#                         'update_time': now_time,
+#                     }
+#                     UserAppFrequencyModel.objects.create(**data)
+#                     return response.json(0)
+#                 else:
+#                     return response.json(444, 'month')
 
 
 class loginCodeView(View):