chenjunkai 5 years ago
parent
commit
1ad9cb38f1
1 changed files with 117 additions and 115 deletions
  1. 117 115
      Controller/DetectController.py

+ 117 - 115
Controller/DetectController.py

@@ -88,6 +88,9 @@ class DetectControllerView(View):
             qs = qs.filter(addTime__range=(startTime, endTime))
         uids = request_dict.get('uids', None)
         if uids:
+            print('---------------------')
+            print(uids)
+            print('=====================')
             uid_list = uids.split(',')
             qs = qs.filter(devUid__in=uid_list)
             dvqs = Device_Info.objects.filter(UID__in=uid_list).values('UID', 'Type', 'NickName')
@@ -99,7 +102,7 @@ class DetectControllerView(View):
             uid_type_dict = {}
             for dv in dvqs:
                 uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
-        print(uid_type_dict)
+        # print(uid_type_dict)
         if not qs.exists():
             return response.json(0, {'datas': [], 'count': 0})
         qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
@@ -134,125 +137,124 @@ class DetectControllerView(View):
                     thumb2 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_2000,w_700'})
                     # thumb3 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_3000,w_700'})
                     p['img_list'] = [thumb0, thumb1, thumb2]
-            try:
+            if devUid in uid_type_dict.keys():
                 p['uid_type'] = uid_type_dict[devUid]['type']
                 p['devNickName'] = uid_type_dict[devUid]['NickName']
-            except Exception as e:
+            else:
                 p['uid_type'] = ''
-                p['devNickName'] = devUid
             res.append(p)
         return response.json(0, {'datas': res, 'count': count})
-    #
-    # def do_change_status1(self, userID, request_dict, response):
-    #     uid = request_dict.get('uid', None)
-    #     token_val = request_dict.get('token_val', None)
-    #     appBundleId = request_dict.get('appBundleId', None)
-    #     app_type = request_dict.get('app_type', None)
-    #     push_type = request_dict.get('push_type', None)
-    #     status = request_dict.get('status', None)
-    #     m_code = request_dict.get('m_code', None)
-    #     # 设备语言
-    #     lang = request_dict.get('lang', 'en')
-    #     tz = request_dict.get('tz', '0')
-    #     # interval = request_dict.get('interval', None)
-    #     if not status:
-    #         return response.json(444, 'status')
-    #     # 关闭推送
-    #     if not all([appBundleId, app_type, token_val, uid, m_code]):
-    #         return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
-    #     # 判断推送类型对应key是否存在
-    #     if push_type == '0':
-    #         if appBundleId not in APNS_CONFIG.keys():
-    #             return response.json(904)
-    #     elif push_type == '1':
-    #         if appBundleId not in FCM_CONFIG.keys():
-    #             return response.json(904)
-    #     elif push_type == '2':
-    #         if appBundleId not in JPUSH_CONFIG.keys():
-    #             return response.json(904)
-    #     else:
-    #         return response.json(173)
-    #     dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
-    #     status = int(status)
-    #     if dvqs.exists():
-    #         # 获取用户区域
-    #         # ip = self.ip
-    #         # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
-    #         # area = ipInfo['country_name']
-    #         # if area == 'China':
-    #         #     DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
-    #         # else:
-    #         #     DETECT_PUSH_DOMAIN = 'en.push.dvema.com'
-    #         nowTime = int(time.time())
-    #         uid_set_qs = UidSetModel.objects. \
-    #             filter(uid=uid, uidpushmodel__userID_id=userID, uidpushmodel__m_code=m_code)
-    #         # 判断是否有曾经开启过
-    #         if uid_set_qs.exists():
-    #             uid_push_update_dict = {
-    #                 'appBundleId': appBundleId,
-    #                 'app_type': app_type,
-    #                 'push_type': push_type,
-    #                 'token_val': token_val,
-    #                 'updTime': nowTime,
-    #                 'lang': lang,
-    #                 'tz': tz
-    #             }
-    #             uid_set_qs.update(detect_status=status, updTime=nowTime)
-    #             UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
-    #                 update(**uid_push_update_dict)
-    #             if status == 0:
-    #                 # 关闭成功
-    #                 return response.json(0)
-    #             utko = UidTokenObject()
-    #             # right
-    #             utko.generate(data={'uid': uid})
-    #             detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
-    #                 format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
-    #             return response.json(0, {'detectUrl': detectUrl})
-    #         else:
-    #             uid_set_qs = UidSetModel.objects.filter(uid=uid)
-    #             # 判断uid push是否绑定
-    #             if not uid_set_qs.exists():
-    #                 uid_set_create_dict = {
-    #                     'uid': uid,
-    #                     'addTime': nowTime,
-    #                     'updTime': nowTime,
-    #                     'detect_status': status,
-    #                 }
-    #                 # 添加设备配置
-    #                 uid_set_qs = UidSetModel.objects.create(**uid_set_create_dict)
-    #                 uid_set_id = uid_set_qs.id
-    #             else:
-    #                 update_dict = {
-    #                     'updTime': nowTime,
-    #                     'detect_status': status,
-    #                 }
-    #                 uid_set_qs.update(**update_dict)
-    #                 uid_set_id = uid_set_qs[0].id
-    #             uid_push_create_dict = {
-    #                 'uid_set_id': uid_set_id,
-    #                 'userID_id': userID,
-    #                 'appBundleId': appBundleId,
-    #                 'app_type': app_type,
-    #                 'push_type': push_type,
-    #                 'token_val': token_val,
-    #                 'm_code': m_code,
-    #                 'addTime': nowTime,
-    #                 'updTime': nowTime,
-    #                 'lang': lang,
-    #                 'tz': tz
-    #             }
-    #             # 绑定设备推送
-    #             UidPushModel.objects.create(**uid_push_create_dict)
-    #             if status == 0:
-    #                 return response.json(0)
-    #             utko = UidTokenObject()
-    #             utko.generate(data={'uid': uid})
-    #             detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
-    #                 format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
-    #             return response.json(0, {'detectUrl': detectUrl})
-    #     else:
-    #         return response.json(14)
+
+    def do_change_status1(self, userID, request_dict, response):
+        uid = request_dict.get('uid', None)
+        token_val = request_dict.get('token_val', None)
+        appBundleId = request_dict.get('appBundleId', None)
+        app_type = request_dict.get('app_type', None)
+        push_type = request_dict.get('push_type', None)
+        status = request_dict.get('status', None)
+        m_code = request_dict.get('m_code', None)
+        # 设备语言
+        lang = request_dict.get('lang', 'en')
+        tz = request_dict.get('tz', '0')
+        # interval = request_dict.get('interval', None)
+        if not status:
+            return response.json(444, 'status')
+        # 关闭推送
+        if not all([appBundleId, app_type, token_val, uid, m_code]):
+            return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
+        # 判断推送类型对应key是否存在
+        if push_type == '0':
+            if appBundleId not in APNS_CONFIG.keys():
+                return response.json(904)
+        elif push_type == '1':
+            if appBundleId not in FCM_CONFIG.keys():
+                return response.json(904)
+        elif push_type == '2':
+            if appBundleId not in JPUSH_CONFIG.keys():
+                return response.json(904)
+        else:
+            return response.json(173)
+        dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
+        status = int(status)
+        if dvqs.exists():
+            # 获取用户区域
+            # ip = self.ip
+            # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
+            # area = ipInfo['country_name']
+            # if area == 'China':
+            #     DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
+            # else:
+            #     DETECT_PUSH_DOMAIN = 'en.push.dvema.com'
+            nowTime = int(time.time())
+            uid_set_qs = UidSetModel.objects. \
+                filter(uid=uid, uidpushmodel__userID_id=userID, uidpushmodel__m_code=m_code)
+            # 判断是否有曾经开启过
+            if uid_set_qs.exists():
+                uid_push_update_dict = {
+                    'appBundleId': appBundleId,
+                    'app_type': app_type,
+                    'push_type': push_type,
+                    'token_val': token_val,
+                    'updTime': nowTime,
+                    'lang': lang,
+                    'tz': tz
+                }
+                uid_set_qs.update(detect_status=status, updTime=nowTime)
+                UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
+                    update(**uid_push_update_dict)
+                if status == 0:
+                    # 关闭成功
+                    return response.json(0)
+                utko = UidTokenObject()
+                # right
+                utko.generate(data={'uid': uid})
+                detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
+                    format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
+                return response.json(0, {'detectUrl': detectUrl})
+            else:
+                uid_set_qs = UidSetModel.objects.filter(uid=uid)
+                # 判断uid push是否绑定
+                if not uid_set_qs.exists():
+                    uid_set_create_dict = {
+                        'uid': uid,
+                        'addTime': nowTime,
+                        'updTime': nowTime,
+                        'detect_status': status,
+                    }
+                    # 添加设备配置
+                    uid_set_qs = UidSetModel.objects.create(**uid_set_create_dict)
+                    uid_set_id = uid_set_qs.id
+                else:
+                    update_dict = {
+                        'updTime': nowTime,
+                        'detect_status': status,
+                    }
+                    uid_set_qs.update(**update_dict)
+                    uid_set_id = uid_set_qs[0].id
+                uid_push_create_dict = {
+                    'uid_set_id': uid_set_id,
+                    'userID_id': userID,
+                    'appBundleId': appBundleId,
+                    'app_type': app_type,
+                    'push_type': push_type,
+                    'token_val': token_val,
+                    'm_code': m_code,
+                    'addTime': nowTime,
+                    'updTime': nowTime,
+                    'lang': lang,
+                    'tz': tz
+                }
+                # 绑定设备推送
+                UidPushModel.objects.create(**uid_push_create_dict)
+                if status == 0:
+                    return response.json(0)
+                utko = UidTokenObject()
+                utko.generate(data={'uid': uid})
+                detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
+                    format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
+                return response.json(0, {'detectUrl': detectUrl})
+        else:
+            return response.json(14)
 
     def do_change_status(self, userID, request_dict, response):
         uid = request_dict.get('uid', None)