Explorar o código

fix:detect statsu

chenjunkai %!s(int64=6) %!d(string=hai) anos
pai
achega
3c4a8d1599

+ 1 - 1
Ansjer/config.py

@@ -37,7 +37,7 @@ OAUTH_ACCESS_TOKEN_SECRET = 'a+jbgnw%@1%zy^=@dn62%'
 OAUTH_REFRESH_TOKEN_SECRET = 'r+jbgnw%@1%zy^=@dn62%'
 # access_token超时
 # OAUTH_ACCESS_TOKEN_TIME = datetime.timedelta(hours=1)
-OAUTH_ACCESS_TOKEN_TIME = datetime.timedelta(days=7)
+OAUTH_ACCESS_TOKEN_TIME = datetime.timedelta(days=30)
 # refresh_token超时
 OAUTH_REFRESH_TOKEN_TIME = datetime.timedelta(days=30)
 # 腾讯验证,短信发送

+ 36 - 52
Controller/DetectController.py

@@ -323,50 +323,46 @@ class NotificationView(View):
                                                                                      'userID_id', 'userID__NickName',
                                                                                      'interval')
             if uid_set_qs.exists():
-                pass
+                redisObj = RedisObject(db=6)
+                pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
+                if redisObj.get_data(key=pkey):
+                    res_data = {'code': 0, 'msg': 'success,!'}
+                    return JsonResponse(status=200, data=res_data)
+                else:
+                    detect_interval = UidSetModel[0].detect_interval
+                    if detect_interval:
+                        redisObj.set_data(key=pkey, val=1, expire=detect_interval)
+
+                auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+                bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
+                for up in uid_push_qs:
+                    push_type = up['push_type']
+                    # ios apns
+                    if push_type == 0:
+                        self.do_apns(request_dict, up, response)
+                    # android gcm
+                    elif push_type == 1:
+                        self.do_gmc(request_dict, up, response)
+                    # android jpush
+                    elif push_type == 2:
+                        self.do_jpush(request_dict, up, response)
+                    # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
+                # 需求不一样,所以这么做的
+                self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st)
+                if is_st == '0' or is_st == '2':
+                    return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
+                else:
+                    # Endpoint以杭州为例,其它Region请按实际情况填写。
+                    obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
+                    # 设置此签名URL在60秒内有效。
+                    url = bucket.sign_url('PUT', obj, 7200)
+                    res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
+                    return JsonResponse(status=200, data=res_data)
             else:
                 return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
         else:
             return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
 
-        # if uaqs.exists():
-        #     redisObj = RedisObject(db=6)
-        #
-        #     auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-        #     bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-        #
-        #     for ua in uaqs:
-        #         push_type = ua['push_type']
-        #         pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
-        #         if redisObj.get_data(key=pkey):
-        #             res_data = {'code': 0, 'msg': 'success,!'}
-        #             return JsonResponse(status=200, data=res_data)
-        #         else:
-        #             if ua['interval']:
-        #                 redisObj.set_data(key=pkey, val=1, expire=ua['interval'])
-        #         # ios apns
-        #         if push_type == 0:
-        #             self.do_apns(request_dict, ua, response)
-        #         # android gcm
-        #         elif push_type == 1:
-        #             self.do_gmc(request_dict, ua, response)
-        #         # android jpush
-        #         elif push_type == 2:
-        #             self.do_jpush(request_dict, ua, response)
-        #
-        #         # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
-        #     # 需求不一样,所以这么做的
-        #     self.do_bulk_create_info(uaqs, n_time, channel, event_type, is_st)
-        #     if is_st == '0' or is_st == '2':
-        #         return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
-        #     else:
-        #         # Endpoint以杭州为例,其它Region请按实际情况填写。
-        #         obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
-        #         # 设置此签名URL在60秒内有效。
-        #         url = bucket.sign_url('PUT', obj, 7200)
-        #         res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
-        #         return JsonResponse(status=200, data=res_data)
-
     def do_jpush(self, request_dict, uaql, response):
         event_type = request_dict.get('event_type', None)
         jpush_config = {
@@ -494,18 +490,6 @@ class NotificationView(View):
         except Exception as e:
             return response.json(10, repr(e))
 
-    def do_save_equipment_info(self, uaql, n_time, channel, event_type, is_st):
-        Equipment_Info.objects.create(
-            userID_id=uaql['userID_id'],
-            eventTime=n_time,
-            eventType=event_type,
-            devUid=uaql['uid'],
-            devNickName=uaql['userID__NickName'],
-            Channel=channel,
-            alarm='0',
-            is_st=int(is_st),
-            receiveTime=n_time)
-
     def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st):
         #
         qs_list = []
@@ -516,7 +500,7 @@ class NotificationView(View):
                 'eventTime': n_time,
                 'eventType': event_type,
                 'devUid': dv['uid'],
-                'devNickName': dv['userID__NickName'],
+                'devNickName': '',
                 'Channel': channel,
                 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
                 'is_st': int(is_st),

+ 5 - 6
Controller/EquipmentManager.py

@@ -4,7 +4,7 @@ import traceback
 
 import simplejson as json
 from django.utils import timezone
-from Model.models import Device_User, Device_Info, UID_Bucket, UID_App, UID_Preview
+from Model.models import Device_User, Device_Info, UID_Bucket, UID_App, UID_Preview, UidSetModel
 from django.db.models import Q
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -581,7 +581,7 @@ def queryInterface(request):
         dvql = dvqs[(page - 1) * line:page * line].values('id', 'userID', 'NickName', 'UID', 'View_Account',
                                                           'View_Password', 'ChannelIndex', 'Type', 'isShare',
                                                           'primaryUserID', 'primaryMaster', 'data_joined', 'version',
-                                                          'isVod', 'isExist','NotificationMode')
+                                                          'isVod', 'isExist', 'NotificationMode')
         dvls = CommonService.qs_to_list(dvql)
         uid_list = []
         for dvl in dvls:
@@ -629,12 +629,11 @@ def uid_status(request):
     response.lang = tko.lang
     if tko.code != 0:
         return response.json(tko.code)
-    qs = UID_App.objects.filter(uid=uid, userID_id=tko.userID).values('uid', 'status', 'interval')
-    print(qs)
+    qs = UidSetModel.objects.filter(uid=uid).values('uid', 'detect_status', 'detect_interval')
     if qs.exists():
         data = {
-            'push_status': qs[0]['status'],
-            'push_interval': qs[0]['interval']  # 推送间隔
+            'push_status': qs[0]['detect_status'],
+            'push_interval': qs[0]['detect_interval']  # 推送间隔
         }
         ubqs = UID_Bucket.objects.filter(uid=uid). \
             values('bucket__content', 'status', 'channel', 'endTime', 'uid')

+ 2 - 2
Controller/StsOssController.py

@@ -63,8 +63,8 @@ class StsOssView(View):
         req.set_RoleArn(OSS_ROLE_ARN)
         req.set_RoleSessionName(userID)
         req.set_DurationSeconds(3600)
-        Resource_access = "acs:oss:*:*:{bucket_name}/{userID}*".format(bucket_name=bucket_name,
-                                                                       userID=userID)
+        Resource_access = "acs:oss:*:*:{bucket_name}/{userID}*".\
+            format(bucket_name=bucket_name,userID=userID)
         policys = {
             "Version": "1",
             "Statement": [

+ 6 - 5
Controller/UserController.py

@@ -1137,11 +1137,12 @@ class InitInfoView(View):
     def init_uid_app(self, request_dict, userID, response):
         token_val = request_dict.get('token_val', None)
         m_code = request_dict.get('m_code', None)
-        uid_app = UID_App.objects.filter(userID_id=userID, token_val=token_val, status=2, m_code=m_code)
-        if uid_app.exists():
-            uid_app.update(status=1)
-        else:
-            pass
+        # uid_app = UID_App.objects.filter(userID_id=userID, token_val=token_val, status=2, m_code=m_code)
+        #
+        # if uid_app.exists():
+        #     uid_app.update(status=1)
+        # else:
+        #     pass
         sm_count = SysMsgModel.objects.filter(userID_id=userID, status=0).count()
         res = {
             'usmsg': sm_count