소스 검색

数据系统数据表添加时间字段、网关最多只能绑定3个智能按钮

peng 2 년 전
부모
커밋
2218fe4c21
6개의 변경된 파일28개의 추가작업 그리고 14개의 파일을 삭제
  1. 3 1
      Controller/CloudStorage.py
  2. 2 1
      Controller/CloudVod.py
  3. 15 9
      Controller/Cron/CronTaskController.py
  4. 1 1
      Controller/SensorGateway/SubDeviceController.py
  5. 5 0
      Model/models.py
  6. 2 2
      Object/ResponseObject.py

+ 3 - 1
Controller/CloudStorage.py

@@ -598,9 +598,11 @@ class CloudStorageView(View):
                     vod_hls = vod_hls_qs.first()
                     vod_hls.upload_frequency += 1
                     vod_hls.upload_duration += sec
+                    vod_hls.updated_time = now_time
                     vod_hls.save()
                 else:
-                    VodHlsSummary.objects.create(uid=UID, time=end_time_stamp,
+                    VodHlsSummary.objects.create(uid=UID, time=end_time_stamp, created_time=now_time,
+                                                 updated_time=now_time,
                                                  upload_duration=sec, upload_frequency=1)
 
                 res = {'code': 0, 'msg': '存储成功'}

+ 2 - 1
Controller/CloudVod.py

@@ -648,9 +648,10 @@ class CloudVodView(View):
             vod_hls = vod_hls_qs.first()
             vod_hls.upload_frequency += 1
             vod_hls.upload_duration += sec
+            vod_hls.updated_time = nowTime
             vod_hls.save()
         else:
-            VodHlsSummary.objects.create(uid=UID, time=end_time_stamp,
+            VodHlsSummary.objects.create(uid=UID, time=end_time_stamp, created_time=nowTime, updated_time=nowTime,
                                          upload_duration=sec, upload_frequency=1)
 
         return response.json(0)

+ 15 - 9
Controller/Cron/CronTaskController.py

@@ -366,6 +366,7 @@ class CronCollectDataView(View):
     @staticmethod
     def collect_play_back(response):
         try:
+            now_time = int(time.time())
             today = datetime.datetime.today()
             start_time = datetime.datetime(today.year, today.month, today.day)
             end_time = start_time + datetime.timedelta(days=1)
@@ -384,10 +385,12 @@ class CronCollectDataView(View):
                         vod_hls_summary = vod_hls_summary_qs.first()
                         vod_hls_summary.play_duration += item['play_duration']
                         vod_hls_summary.play_frequency += 1
+                        vod_hls_summary.updated_time = now_time
                         vod_hls_summary.save()
                     else:
-                        VodHlsSummary.objects.create(uid=item['uid'], time=this_month_stamp,
-                                                     play_duration=item['play_duration'], play_frequency=1)
+                        VodHlsSummary.objects.create(uid=item['uid'], time=this_month_stamp, created_time=now_time,
+                                                     play_duration=item['play_duration'], play_frequency=1,
+                                                     updated_time=now_time)
 
             return response.json(0)
         except Exception as e:
@@ -396,8 +399,9 @@ class CronCollectDataView(View):
     @staticmethod
     def collect_device_user(response):
         try:
+            created_time = int(time.time())
             today = datetime.datetime.today()
-            start_time = datetime.datetime(today.year, today.month, today.day)
+            start_time = datetime.datetime(today.year, today.month, 23)
             end_time = start_time + datetime.timedelta(days=1)
             increase_user_qs = Device_User.objects.filter(data_joined__gte=start_time, data_joined__lt=end_time).values(
                 'data_joined',
@@ -427,7 +431,7 @@ class CronCollectDataView(View):
                             increase_user_continent_dict[continent_name] = 0
                         increase_user_continent_dict[continent_name] += item['count']
                     DeviceUserSummary.objects.create(time=start_time, count=increase_user_count,
-                                                     country=increase_user_country_dict,
+                                                     country=increase_user_country_dict, created_time=created_time,
                                                      continent=increase_user_continent_dict)
                 if active_user_qs.exists():
                     active_user_count = active_user_qs.count()
@@ -444,7 +448,7 @@ class CronCollectDataView(View):
                             active_user_continent_dict[continent_name] = 0
                         active_user_continent_dict[continent_name] += item['count']
                     DeviceUserSummary.objects.create(time=start_time, query_type=1, count=active_user_count,
-                                                     country=active_user_country_dict,
+                                                     country=active_user_country_dict, created_time=created_time,
                                                      continent=active_user_continent_dict)
 
             return response.json(0)
@@ -454,6 +458,7 @@ class CronCollectDataView(View):
     @staticmethod
     def collect_order(response):
         try:
+            created_time = int(time.time())
             today = datetime.datetime.today()
             start_time = datetime.datetime(today.year, today.month, today.day)
             end_time = start_time + datetime.timedelta(days=1)
@@ -577,7 +582,7 @@ class CronCollectDataView(View):
                             }
                             OrdersSummary.objects.create(time=add_time_stamp, count=1, query_type=query_type,
                                                          service_type=order_type, total=final_total,
-                                                         country=country_temp_dict,
+                                                         country=country_temp_dict, created_time=created_time,
                                                          device_type=device_type_temp_dict,
                                                          store_meal=store_meal_temp_dict)
                     if order_summary_qs.exists():
@@ -675,7 +680,7 @@ class CronCollectDataView(View):
                             }
                         OrdersSummary.objects.create(time=add_time_stamp, count=1, query_type=is_pay,
                                                      service_type=order_type, total=final_total,
-                                                     country=country_temp_dict,
+                                                     country=country_temp_dict, created_time=created_time,
                                                      device_type=device_type_temp_dict, store_meal=store_meal_temp_dict)
             return response.json(0)
         except Exception as e:
@@ -684,6 +689,7 @@ class CronCollectDataView(View):
     @staticmethod
     def collect_device_info(response):
         try:
+            created_time = int(time.time())
             today = datetime.datetime.today()
             start_time = datetime.datetime(today.year, today.month, today.day)
             end_time = start_time + datetime.timedelta(days=1)
@@ -765,7 +771,7 @@ class CronCollectDataView(View):
                         type_name = device_type_dict.get(item['device_type'], '未知设备类型')
                         increase_device_unicom_dict[type_name] = item['count']
                     DeviceInfoSummary.objects.create(time=start_time, count=increase_device_count,
-                                                     query_type=0,
+                                                     query_type=0, created_time=created_time,
                                                      country=increase_device_country_dict,
                                                      continent=increase_device_continent_dict,
                                                      vod_service=increase_device_vod_dict,
@@ -814,7 +820,7 @@ class CronCollectDataView(View):
                         type_name = device_type_dict.get(item['device_type'], '未知设备类型')
                         active_device_unicom_dict[type_name] = item['count']
                     DeviceInfoSummary.objects.create(time=start_time, count=active_device_count,
-                                                     query_type=1,
+                                                     query_type=1, created_time=created_time,
                                                      country=active_device_country_dict,
                                                      continent=active_device_continent_dict,
                                                      vod_service=active_device_vod_dict,

+ 1 - 1
Controller/SensorGateway/SubDeviceController.py

@@ -110,7 +110,7 @@ class GatewaySubDeviceView(View):
                 return response.json(174)
             if device_type == SENSOR_TYPE['smart_button']:
                 sub_device_qs = GatewaySubDevice.objects.filter(device_id=device_id, device_type=device_type)
-                if sub_device_qs.exists():
+                if sub_device_qs.count() > 3:
                     return response.json(181)
 
             with transaction.atomic():

+ 5 - 0
Model/models.py

@@ -2937,6 +2937,8 @@ class VodHlsSummary(models.Model):
     upload_frequency = models.IntegerField(verbose_name='上传次数', default=0)
     play_duration = models.IntegerField(verbose_name='播放秒数', default=0)
     play_frequency = models.IntegerField(verbose_name='播放次数', default=0)
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
+    updated_time = models.IntegerField(default=0, verbose_name='更新时间')
 
     def __str__(self):
         return self.id
@@ -2954,6 +2956,7 @@ class DeviceUserSummary(models.Model):
     count = models.IntegerField(verbose_name='总人数', default=0)
     country = models.TextField(verbose_name='所属国家', default='')
     continent = models.TextField(verbose_name='四大洲信息', default='')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
 
     def __str__(self):
         return self.id
@@ -2974,6 +2977,7 @@ class OrdersSummary(models.Model):
     country = models.TextField(verbose_name='所属国家', default='')
     device_type = models.TextField(verbose_name='设备类型信息', default='')
     store_meal = models.TextField(verbose_name='套餐信息', default='')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
 
     def __str__(self):
         return self.id
@@ -2995,6 +2999,7 @@ class DeviceInfoSummary(models.Model):
     vod_service = models.TextField(verbose_name='云存服务信息', default='')
     ai_service = models.TextField(verbose_name='ai服务信息', default='')
     unicom_service = models.TextField(verbose_name='联通服务信息', default='')
+    created_time = models.IntegerField(default=0, verbose_name='创建时间')
 
     def __str__(self):
         return self.id

+ 2 - 2
Object/ResponseObject.py

@@ -44,7 +44,7 @@ class ResponseObject(object):
             178: 'ADD error',
             179: 'Nickname repeated',
             180: 'Smart button scene trigger conditions cannot be repeated',
-            181: 'The gateway have bound smart button',
+            181: 'The gateway only bind 3 smart button at most',
             201: 'You can only add 3 custom voice at most',
             306: 'The link has expired!',
             309: 'Please ReLogin! errmsg token',
@@ -154,7 +154,7 @@ class ResponseObject(object):
             178: '增加错误',
             179: '名称不能重复',
             180: '智能按钮场景触发条件不能重复',
-            181: '该网关已绑定智能按钮',
+            181: '该网关最多只能绑定3个智能按钮',
             201: '最多只能添加3条自定义语音',
             306: '链接已超过有效期!',
             309: '请重新登录!',