浏览代码

删除无用代码

peng 1 年之前
父节点
当前提交
5fed4612f6
共有 2 个文件被更改,包括 22 次插入173 次删除
  1. 13 154
      Controller/CloudStorage.py
  2. 9 19
      Controller/TestApi.py

+ 13 - 154
Controller/CloudStorage.py

@@ -103,8 +103,6 @@ class CloudStorageView(View):
                 return self.do_create_pay_order(request_dict, user_id, ip, response)
             elif operation == 'changevodstatus':  # 修改云存状态,传送两个url,即getsignsts接口和storeplaylist接口
                 return self.do_change_vod_status(request_dict, user_id, response)
-            elif operation == 'changevodaistatus':  # 修改云存AI状态
-                return self.do_change_vod_ai_status(request_dict, user_id, response)
             elif operation == 'queryvodlist':  # 获取视频播放列表
                 return self.do_query_vod_list(request_dict, user_id, response)
             elif operation == 'commoditylist':  # 查询套餐列表
@@ -331,12 +329,11 @@ class CloudStorageView(View):
         now_time = int(time.time())
 
         split_vod_hls_obj = SplitVodHlsObject()
-        vod_hls_qs = split_vod_hls_obj.get_vod_hls_data(uid=uid, channel=channel, start_time__gte=start_time,
+        vod_hls_qs = split_vod_hls_obj.get_vod_hls_data(uid=uid, channel=channel, start_time=start_time,
                                                         end_time__gte=now_time).values("sec", "fg", "bucket_id",
-                                                                                       'start_time')[:10]
+                                                                                       'start_time')
         if not vod_hls_qs.exists():
             return response.json(173)
-        vod_hls_qs = sorted(vod_hls_qs, key=lambda item: item['start_time'])[:10]
         bucket_id = vod_hls_qs[0]['bucket_id']
         vod_bucket_qs = VodBucketModel.objects.filter(id=bucket_id).values('bucket', 'region', 'mold')
         if not vod_bucket_qs.exists():
@@ -344,6 +341,7 @@ class CloudStorageView(View):
         bucket_region = vod_bucket_qs[0]['region']
         bucket_name = vod_bucket_qs[0]['bucket']
         mold = vod_bucket_qs[0]["mold"]
+        fg = int(vod_hls_qs[0]['fg'])
         s3_obj = AmazonS3Util(
             AWS_ACCESS_KEY_ID[mold],
             AWS_SECRET_ACCESS_KEY[mold],
@@ -353,20 +351,16 @@ class CloudStorageView(View):
         playlist_entries = []
         # ts_count = fg & 0xf
         # fg 64位整型,低四位代表ts文件总数,然后进行位运算,一次移四位,每四位转为十进制即为当前ts文件的秒数
-        for item in vod_hls_qs:
-            fg = int(item['fg'])
-            temp_time = item['start_time']
-            for i in range(15):
-                shift = (i + 1) * 4
-                duration = (fg >> shift) & 0xf
-                if duration > 0:
-                    ts_file = '{uid}/vod{channel}/{time}/ts{i}.ts'.format(uid=uid, channel=channel, time=temp_time,
-                                                                          i=i)
-                    response_url = s3_obj.generate_file_obj_url(bucket_name, ts_file)
-                    playlist_entries.append({
-                        'name': response_url,
-                        'duration': duration,
-                    })
+        for i in range(15):
+            shift = (i + 1) * 4
+            duration = (fg >> shift) & 0xf
+            if duration > 0:
+                ts_file = '{uid}/vod{channel}/{time}/ts{i}.ts'.format(uid=uid, channel=channel, time=start_time, i=i)
+                response_url = s3_obj.generate_file_obj_url(bucket_name, ts_file)
+                playlist_entries.append({
+                    'name': response_url,
+                    'duration': duration,
+                })
 
         playlist = PlaylistGenerator(playlist_entries).generate()
         response = HttpResponse(playlist)
@@ -743,141 +737,6 @@ class CloudStorageView(View):
         store_hls_url = '{}cloudstorage/storeplaylist?uidToken={}'.format(urls, uid_obj.token)
         return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url})
 
-    @staticmethod
-    def do_change_vod_ai_status(request_dict, user_id, response):  # 修改云存状态
-        """
-        修改云存状态
-        @param request_dict: 请求数据
-        @param user_id: 用户id
-        @request_dict uid: uid
-        @request_dict status: 套餐状态
-        @request_dict channel: 通道
-        @param response: 响应
-        @return: response
-        """
-        uid = request_dict.get('uid', None)
-        vod_status = request_dict.get('vod_status', None)
-        channel = request_dict.get('channel', None)
-        domain_name = request_dict.get('domain_name', 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)
-        ai_status = request_dict.get('ai_status', None)
-        m_code = request_dict.get('m_code', None)
-        lang = request_dict.get('lang', 'en')
-        tz = request_dict.get('tz', '0')
-        detect_group = request_dict.get('detect_group', None)
-        interval = request_dict.get('interval', None)
-        if not all([uid, vod_status, channel]):
-            return response.json(444, 'uid,vod_status,channel')
-        vod_status = int(vod_status)
-        ai_status = int(ai_status)
-        device_info_qs = Device_Info.objects.filter(userID_id=user_id, UID=uid, isShare=False, isExist=1).values(
-            'vodPrimaryUserID', 'Type')
-        if not device_info_qs.exists() or device_info_qs[0]['vodPrimaryUserID'] != user_id:
-            return response.json(12)
-        device_type = device_info_qs[0]['Type']
-        uid_set_qs = UidSetModel.objects.filter(uid=uid)
-        if not uid_set_qs.exists():
-            return response.json(12)
-        if device_type in BINOCULAR_DEVICE_TYPE:  # 枪球设备开通云存不区分通道
-            uid_bucket_qs = UID_Bucket.objects.filter(uid=uid)
-        else:
-            uid_bucket_qs = UID_Bucket.objects.filter(channel=channel, uid=uid)
-        if not uid_bucket_qs.exists():
-            return response.json(10030)
-        now_time = int(time.time())
-        end_time = uid_bucket_qs[0].endTime
-        if now_time > end_time:
-            return response.json(10031)
-        try:
-            with transaction.atomic():
-                if vod_status == 0:  # 关闭云存开关
-                    uid_bucket_qs.update(status=vod_status)
-                    return response.json(0)
-                uid_obj = UidTokenObject()
-                uid_obj.generate(data={'uid': uid, 'channel': channel})
-
-                # 欧洲域名固定返回欧洲域名
-                urls = SERVER_DOMAIN_SSL
-                if domain_name in ['api.zositeche.com', 'api.loocam3.com', 'common.neutral3.com']:
-                    urls = 'https://api.zositeche.com/'
-                uid_tk_url = '{}cloudstorage/getsignsts?uidToken={}'.format(urls, uid_obj.token)
-                store_hls_url = '{}cloudstorage/storeplaylist?uidToken={}'.format(urls, uid_obj.token)
-
-                thing_name = CommonService.query_serial_with_uid(uid)  # 存在序列号则为使用序列号作为物品名
-                topic_name = 'ansjer/generic/{}'.format(thing_name)
-                ai_service_qs = AiService.objects.filter(uid=uid, use_status=1)
-                if ai_status == 0:  # 关闭
-                    # mqtt通知设备关闭AI识别功能
-                    msg = {'commandType': 'AIDisable'}
-                    req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
-                    if not req_success:
-                        return response.json(10044)
-                    ai_service_qs.update(detect_status=ai_status, endTime=end_time)
-                    return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url})
-                elif ai_status == 1:  # 开启
-                    if not all([appBundleId, app_type, token_val, uid, m_code, ai_status]):
-                        return response.json(444, 'appBundleId, app_type, token_val, uid,m_code, ai_status')
-                    # 如果传空上来,就默认为0
-                    tz = '0' if tz == '' else tz.replace('GMT', '')
-                    uid_set_id = uid_set_qs[0].id
-                    qs_data = {
-                        'updTime': now_time,
-                        'detect_interval': uid_set_qs[0].new_detect_interval if not interval else interval,
-                        'detect_group': detect_group if detect_group else ''
-                    }
-                    # 更新或创建uid_push数据
-                    uid_push_qs = UidPushModel.objects.filter(userID_id=user_id, m_code=m_code, uid_set__uid=uid)
-                    uid_push_data = {
-                        'appBundleId': appBundleId,
-                        'app_type': app_type,
-                        'push_type': push_type,
-                        'token_val': token_val,
-                        'updTime': now_time,
-                        'lang': lang,
-                        'tz': tz
-                    }
-
-                    if uid_push_qs.exists():
-                        uid_push_qs.update(**uid_push_data)
-                    else:
-                        uid_push_data['uid_set_id'] = uid_set_id
-                        uid_push_data['userID_id'] = user_id
-                        uid_push_data['m_code'] = m_code
-                        uid_push_data['addTime'] = now_time
-                        UidPushModel.objects.create(**uid_push_data)
-                    etkObj = ETkObject(etk='')
-                    etk = etkObj.encrypt(uid)
-                    # mqtt通知设备开启AI识别功能
-                    push_url = DETECT_PUSH_DOMAINS
-                    # 欧洲域名固定返回欧洲域名
-                    if domain_name in ['api.zositeche.com', 'api.loocam3.com', 'common.neutral3.com']:
-                        push_url = 'https://push.zositeche.com/'
-                    aiIdentificationUrl = '{}AiService/identification'.format(push_url)
-                    msg = {
-                        'commandType': 'AIEnable',
-                        'payload': {
-                            'etk': etk,
-                            'endTime': end_time,
-                            'aiIdentificationUrl': aiIdentificationUrl,
-                        }
-                    }
-                    req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
-                    if not req_success:
-                        return response.json(10044)
-                    uid_set_qs.update(**qs_data)
-                    qs_data['detect_status'] = ai_status  # ai开关状态
-                    qs_data['endTime'] = end_time
-                    ai_service_qs.update(**qs_data)
-                    return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url,
-                                             'aiIdentificationUrl': aiIdentificationUrl, 'endTime': end_time,
-                                             'etk': etk})
-                uid_bucket_qs.update(status=vod_status, channel=channel)
-        except Exception as e:
-            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
-
     @staticmethod
     def do_pay_error():
         response = HttpResponse()

+ 9 - 19
Controller/TestApi.py

@@ -178,8 +178,6 @@ class testView(View):
             return self.uploadAVSS(request, response)
         elif operation == 'oci_oss':  # 生成oci oss预签名链接
             return self.oci_oss(request, response)
-        elif operation == 'genericReportPush':  # 设备上传日志
-            return self.generic_report_push(request_dict, response)
         elif operation == 'celery':  # celery
             return self.celery(request_dict, response)
         elif operation == 'tz':
@@ -1107,7 +1105,7 @@ class testView(View):
         minute = request_dict.get('minute', None)
         day_of_week = request_dict.get('day_of_week', None)
         apscheduler_obj = ApschedulerObject(timezone_offset)
-        apscheduler_obj.create_cron_job(apscheduler_obj.auto_hello, task_id, day_of_week, hour, minute, ('date', ))
+        apscheduler_obj.create_cron_job(apscheduler_obj.auto_hello, task_id, day_of_week, hour, minute, ('date',))
         return response.json(0)
 
     @staticmethod
@@ -1116,7 +1114,7 @@ class testView(View):
         time_stamp = request_dict.get('time_stamp', None)
         time_stamp = int(time_stamp)
         apscheduler_obj = ApschedulerObject()
-        apscheduler_obj.create_date_job(apscheduler_obj.auto_hello, task_id, time_stamp, ('date', ))
+        apscheduler_obj.create_date_job(apscheduler_obj.auto_hello, task_id, time_stamp, ('date',))
         return response.json(0)
 
     @staticmethod
@@ -1246,20 +1244,6 @@ class testView(View):
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    @staticmethod
-    def generic_report_push(request_dict, response):
-        data = request_dict.get('data', None)
-        if not data:
-            return response.json(444)
-        try:
-            data = json.loads(data)
-            file = '{}/static/generic_report_push.txt'.format(BASE_DIR)
-            with open(file, 'w', encoding='utf-8') as f:
-                json.dump(data, f, indent='\t', ensure_ascii=False)
-            return response.json(0)
-        except Exception as e:
-            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
-
     @staticmethod
     def celery(request_dict, response):
         from celery import Celery
@@ -1327,7 +1311,13 @@ class testView(View):
     @staticmethod
     def tz(request_dict, response):
         try:
-            zone_info_list = ['Pacific/Midway','Pacific/Honolulu','America/Anchorage','America/Los_Angeles','America/Denver','America/Chicago','America/New_York','America/Halifax','Canada/Newfoundland','America/Buenos_Aires','Atlantic/South_Georgia','Atlantic/Cape_Verde','Europe/London','Europe/Paris','Europe/Athens','Europe/Moscow','Asia/Tehran','Asia/Dubai','Asia/Kabul','Asia/Karachi','Asia/Almaty','Asia/Rangoon','Asia/Bangkok','Asia/Shanghai','Asia/Tokyo','Australia/Darwin','Australia/Sydney','Asia/Magadan','Pacific/Auckland']
+            zone_info_list = ['Pacific/Midway', 'Pacific/Honolulu', 'America/Anchorage', 'America/Los_Angeles',
+                              'America/Denver', 'America/Chicago', 'America/New_York', 'America/Halifax',
+                              'Canada/Newfoundland', 'America/Buenos_Aires', 'Atlantic/South_Georgia',
+                              'Atlantic/Cape_Verde', 'Europe/London', 'Europe/Paris', 'Europe/Athens', 'Europe/Moscow',
+                              'Asia/Tehran', 'Asia/Dubai', 'Asia/Kabul', 'Asia/Karachi', 'Asia/Almaty', 'Asia/Rangoon',
+                              'Asia/Bangkok', 'Asia/Shanghai', 'Asia/Tokyo', 'Australia/Darwin', 'Australia/Sydney',
+                              'Asia/Magadan', 'Pacific/Auckland']
             for zone_info in zone_info_list:
                 timezone = zoneinfo.ZoneInfo(zone_info)
                 print(timezone)