Forráskód Böngészése

优化云存分表

peng 2 éve
szülő
commit
74a3b880f9

+ 1 - 1
AdminController/dataSystemManagement/UserDataController.py

@@ -12,7 +12,7 @@ from django.views.generic.base import View
 import datetime
 import requests
 
-from Model.models import Device_User, CountryModel, DeviceUserSummary
+from Model.models import DeviceUserSummary
 from Service.CommonService import CommonService
 
 

+ 2 - 2
Service/CloudLogs.py

@@ -10,7 +10,7 @@ from Object.RedisObject import RedisObject
 from Object.UidTokenObject import UidTokenObject
 from Service.CommonService import CommonService
 from Service.MiscellService import MiscellService
-
+from Service.MiscellService import get_access_name
 
 def batch_add_access_log(request, status_code):
     asy = threading.Thread(target=batch_add_log_ctr, args=(request, status_code))
@@ -27,7 +27,7 @@ def batch_add_log_ctr(request, status_code):
         return
     request_path = request.path.strip().strip('/')
     if 'storeplaylist' in request_path or 'signplaym3u8' in request_path:   # 只记录上传和播放视频的操作
-        user = MiscellService.get_access_name(request_dict)
+        user = get_access_name(request_dict)
         uidToken = request_dict.get('uidToken', None)
         utko = UidTokenObject(uidToken)
         uid = utko.UID

+ 47 - 16
Service/VodHlsService.py

@@ -1,8 +1,8 @@
 # @Author    : Rocky
 # @File      : VodHlsService.py
 # @Time      : 2023/2/1 15:57
+import datetime
 from Model.models import VodHlsMon, VodHlsTues, VodHlsWed, VodHlsThur, VodHlsFri, VodHlsSat, VodHlsSun
-from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from django.db.models import Count
 
@@ -14,24 +14,21 @@ class SplitVodHlsObject:
         分表保存云存信息数据
         """
         start_time = kwargs.get('start_time')
-        str_date = CommonService.get_now_time_str(n_time=start_time, tz='0', lang='cn')[:10]
-        week = LocalDateTimeUtil.date_to_week(str_date)
-        vod_hls = None
+        week = datetime.datetime.fromtimestamp(int(start_time)).isoweekday()
         if week == 1:
-            vod_hls = VodHlsMon(**kwargs)
+            VodHlsMon.objects.create(**kwargs)
         elif week == 2:
-            vod_hls = VodHlsTues(**kwargs)
+            VodHlsTues.objects.create(**kwargs)
         elif week == 3:
-            vod_hls = VodHlsWed(**kwargs)
+            VodHlsWed.objects.create(**kwargs)
         elif week == 4:
-            vod_hls = VodHlsThur(**kwargs)
+            VodHlsThur.objects.create(**kwargs)
         elif week == 5:
-            vod_hls = VodHlsFri(**kwargs)
+            VodHlsFri.objects.create(**kwargs)
         elif week == 6:
-            vod_hls = VodHlsSat(**kwargs)
+            VodHlsSat.objects.create(**kwargs)
         elif week == 7:
-            vod_hls = VodHlsSun(**kwargs)
-        vod_hls.save()
+            VodHlsSun.objects.create(**kwargs)
 
     def del_vod_hls_data(self, **kwargs):
         """
@@ -50,11 +47,10 @@ class SplitVodHlsObject:
         分表获取云存信息数据
         @return: vod_hls
         """
+        vod_hls = VodHlsMon.objects.filter(pk=-1)
         if 'start_time' in kwargs:
             start_time = kwargs.get('start_time')
-            str_date = CommonService.get_now_time_str(n_time=start_time, tz='0', lang='cn')[:10]
-            week = LocalDateTimeUtil.date_to_week(str_date)
-            vod_hls = None
+            week = datetime.datetime.fromtimestamp(int(start_time)).isoweekday()
             if week == 1:
                 vod_hls = VodHlsMon.objects.filter(**kwargs)
             elif week == 2:
@@ -70,6 +66,41 @@ class SplitVodHlsObject:
             elif week == 7:
                 vod_hls = VodHlsSun.objects.filter(**kwargs)
             return vod_hls
+        if 'start_time__range' in kwargs:
+            start_time, end_time = kwargs.get('start_time__range')
+            vod_hls_mon = VodHlsMon.objects.filter(pk=-1)
+            vod_hls_tus = VodHlsTues.objects.filter(pk=-1)
+            vod_hls_wed = VodHlsWed.objects.filter(pk=-1)
+            vod_hls_thur = VodHlsThur.objects.filter(pk=-1)
+            vod_hls_fri = VodHlsFri.objects.filter(pk=-1)
+            vod_hls_sat = VodHlsSat.objects.filter(pk=-1)
+            vod_hls_sun = VodHlsSun.objects.filter(pk=-1)
+            start_time = datetime.datetime.fromtimestamp(int(start_time))
+            end_time = datetime.datetime.fromtimestamp(int(end_time))
+            time_list = CommonService.cutting_time(start_time, end_time, 'day')
+            day_list = []
+            for time_item in time_list:
+                week = datetime.datetime.fromtimestamp(int(time_item[0])).isoweekday()
+                if week not in day_list:
+                    day_list.append(week)
+            for week in day_list:
+                if week == 1:
+                    vod_hls_mon = VodHlsMon.objects.filter(**kwargs)
+                elif week == 2:
+                    vod_hls_tus = VodHlsTues.objects.filter(**kwargs)
+                elif week == 3:
+                    vod_hls_wed = VodHlsWed.objects.filter(**kwargs)
+                elif week == 4:
+                    vod_hls_thur = VodHlsThur.objects.filter(**kwargs)
+                elif week == 5:
+                    vod_hls_fri = VodHlsFri.objects.filter(**kwargs)
+                elif week == 6:
+                    vod_hls_sat = VodHlsSat.objects.filter(**kwargs)
+                elif week == 7:
+                    vod_hls_sun = VodHlsSun.objects.filter(**kwargs)
+            vod_hls = vod_hls.union(vod_hls_mon, vod_hls_tus, vod_hls_wed, vod_hls_thur, vod_hls_fri, vod_hls_sat,
+                                    vod_hls_sun)
+            return vod_hls
         vod_hls_mon = VodHlsMon.objects.filter(**kwargs)
         vod_hls_tus = VodHlsTues.objects.filter(**kwargs)
         vod_hls_wed = VodHlsWed.objects.filter(**kwargs)
@@ -78,7 +109,7 @@ class SplitVodHlsObject:
         vod_hls_sat = VodHlsSat.objects.filter(**kwargs)
         vod_hls_sun = VodHlsSun.objects.filter(**kwargs)
 
-        vod_hls = vod_hls_mon.union(vod_hls_tus, vod_hls_wed, vod_hls_thur, vod_hls_fri, vod_hls_sat, vod_hls_sun)
+        vod_hls = vod_hls.union(vod_hls_mon, vod_hls_tus, vod_hls_wed, vod_hls_thur, vod_hls_fri, vod_hls_sat, vod_hls_sun)
         return vod_hls
 
     def get_vod_hls_date(self, **kwargs):