瀏覽代碼

同步旧接口分表查询

zhangdongming 3 年之前
父節點
當前提交
ad71e6296f
共有 1 個文件被更改,包括 42 次插入27 次删除
  1. 42 27
      Controller/DetectController.py

+ 42 - 27
Controller/DetectController.py

@@ -11,6 +11,7 @@
 @file: DetectController.py
 @Contact: chanjunkai@163.com
 """
+import logging
 import os
 import time
 
@@ -20,10 +21,11 @@ import oss2
 from django.http import JsonResponse
 from django.views.generic.base import View
 from pyfcm import FCMNotification
-from Object.RedisObject import RedisObject
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN,\
-                            JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, \
-                            BASE_DIR, APNS_MODE,  SERVER_TYPE
+
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, \
+    JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, \
+    BASE_DIR, APNS_MODE, SERVER_TYPE
+from Ansjer.config import PUSH_REDIS_ADDRESS
 from Model.models import Device_Info, VodHlsModel, Equipment_Info, UidSetModel, UidPushModel, SysMsgModel
 from Object.ETkObject import ETkObject
 from Object.RedisObject import RedisObject
@@ -31,8 +33,7 @@ from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.UidTokenObject import UidTokenObject
 from Service.CommonService import CommonService
-from Service.ModelService import ModelService
-from Ansjer.config import PUSH_REDIS_ADDRESS
+from Service.EquipmentInfoService import EquipmentInfoService
 
 
 class DetectControllerView(View):
@@ -73,6 +74,8 @@ class DetectControllerView(View):
             return response.json(tko.code)
 
     def do_query(self, request_dict, response, userID):
+        logger = logging.getLogger('info')
+        logger.info("-----旧APP调用移动侦测查询")
         page = int(request_dict.get('page', None))
         line = int(request_dict.get('line', None))
         if not page or not line:
@@ -80,15 +83,26 @@ class DetectControllerView(View):
         startTime = request_dict.get('startTime', None)
         endTime = request_dict.get('endTime', None)
         eventType = request_dict.get('eventType', None)
-        qs = Equipment_Info.objects.filter(userID_id=userID).order_by('-eventTime')
+        # qs = Equipment_Info.objects.filter(userID_id=userID).order_by('-eventTime')
+        # if startTime and endTime:
+        #     qs = qs.filter(eventTime__range=(startTime, endTime))
+        # if eventType:
+        #     qs = qs.filter(eventType=eventType)
         if startTime and endTime:
-            qs = qs.filter(eventTime__range=(startTime, endTime))
-        if eventType:
-            qs = qs.filter(eventType=eventType)
+            qs, count = EquipmentInfoService.find_by_start_time_equipment_info(page, line, userID, startTime,
+                                                                               endTime, eventType,
+                                                                               request_dict.get('uids', None))
+
+        else:
+            # 默认查询近七天消息推送
+            qs, count = EquipmentInfoService.get_equipment_info_week_all(page, line, userID, startTime, endTime,
+                                                                         eventType,
+                                                                         request_dict.get('uids', None))
+        logger.info('<<<|||分表查询结果count:{}'.format(count))
         uids = request_dict.get('uids', None)
         if uids:
             uid_list = uids.split(',')
-            qs = qs.filter(devUid__in=uid_list)
+            # qs = qs.filter(devUid__in=uid_list)
             dvqs = Device_Info.objects.filter(UID__in=uid_list, userID_id=userID).values('UID', 'Type', 'NickName')
             uid_type_dict = {}
             for dv in dvqs:
@@ -99,13 +113,16 @@ class DetectControllerView(View):
             for dv in dvqs:
                 uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
         # print(uid_type_dict)
-        if not qs.exists():
+        if not qs or count == 0 or not qs.exists():
             return response.json(0, {'datas': [], 'count': 0})
-        qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
-                       'receiveTime', 'is_st', 'addTime')
-
-        count = qs.count()
-        qr = qs[(page - 1) * line:page * line]
+        # if not qs.exists():
+        #     return response.json(0, {'datas': [], 'count': 0})
+        # qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
+        #                'receiveTime', 'is_st', 'addTime')
+
+        # count = qs.count()
+        # qr = qs[(page - 1) * line:page * line]
+        qr = qs
         res = []
         auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
         img_bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
@@ -320,7 +337,6 @@ class DetectControllerView(View):
             return response.json(0)
 
 
-
 '''
 http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
 http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
@@ -394,8 +410,8 @@ class NotificationView(View):
             print(have_ykey)
         else:
             # 从数据库查询出来
-            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
-                values('token_val', 'app_type', 'appBundleId','m_code',
+            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
+                values('token_val', 'app_type', 'appBundleId', 'm_code',
                        'push_type', 'userID_id', 'userID__NickName',
                        'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
                        'uid_set__channel')
@@ -435,7 +451,7 @@ class NotificationView(View):
             else:
                 detect_med_type = 2  # 为2的话,既推送,又存库
                 # detect_group=0允许全部推送的时候
-                if detect_group == '0'or detect_group == '':
+                if detect_group == '0' or detect_group == '':
                     redisObj.set_data(key=dkey, val=1, expire=detect_interval)
                 else:
                     detect_group_list = detect_group.split(',')
@@ -445,7 +461,7 @@ class NotificationView(View):
                         redisObj.set_data(key=dkey, val=1, expire=detect_interval)
                 # 改为1秒
                 # 如果不是正式
-                if SERVER_TYPE!="Ansjer.formal_settings":
+                if SERVER_TYPE != "Ansjer.formal_settings":
                     redisObj.set_data(key=pkey, val=1, expire=10)
                 else:
                     redisObj.set_data(key=pkey, val=1, expire=60)
@@ -497,7 +513,7 @@ class NotificationView(View):
             kwag_args['msg_title'] = msg_title
             kwag_args['msg_text'] = msg_text
             push_server_status = 0
-            #推送
+            # 推送
             if detect_med_type == 2 or detect_med_type == 0:
                 if push_type == 0:  # ios apns
                     print('do_apns')
@@ -569,7 +585,7 @@ class NotificationView(View):
                 del up['uid_set__nickname']
                 del up['uid_set__detect_interval']
                 del up['uid_set__detect_group']
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2' ,'re_list':redis_list})
+            return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
 
         elif is_st == '1':
             print("is_st=1")
@@ -632,7 +648,6 @@ class NotificationView(View):
                 res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
             return JsonResponse(status=200, data=res_data)
 
-
     def get_msg_title(self, appBundleId, nickname):
         package_title_config = {
             'com.ansjer.customizedd_a': 'DVS',
@@ -659,7 +674,7 @@ class NotificationView(View):
         return False
 
     def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
+        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
         etype = int(event_type)
         if lang == 'cn':
             if etype == 704:
@@ -933,7 +948,7 @@ class PushNotificationView(View):
                 # 从数据库查询出来
                 uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
                     values('token_val', 'app_type', 'appBundleId',
-                           'push_type', 'userID_id', 'lang','m_code',
+                           'push_type', 'userID_id', 'lang', 'm_code',
                            'tz', 'uid_set__nickname')
                 # 新建一个list接收数据
                 redis_list = []