Эх сурвалжийг харах

ai推送数据分表存储

locky 3 жил өмнө
parent
commit
cb0109a82e
1 өөрчлөгдсөн 20 нэмэгдсэн , 12 устгасан
  1. 20 12
      Controller/AiController.py

+ 20 - 12
Controller/AiController.py

@@ -42,10 +42,12 @@ from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.UidTokenObject import UidTokenObject
+from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from django.db.models import Q, F, Count
 from decimal import Decimal
 from AnsjerPush.config import SERVER_TYPE
+from Service.EquipmentInfoService import EquipmentInfoService
 from Service.ModelService import ModelService
 from Object import MergePic
 import boto3
@@ -217,6 +219,7 @@ class AiView(View):
             userID_ids = []
             apns_start_time = 0
             apns_end_time = 0
+            local_date_time = ''
             for up in uid_push_list:
                 push_type = up['push_type']
                 appBundleId = up['appBundleId']
@@ -225,24 +228,26 @@ class AiView(View):
                 tz = up['tz']
                 if tz is None or tz == '':
                     tz = 0
-
+                local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang='cn')
+                local_date_time = local_date_time[0:10]
                 # 以下是存库
                 userID_id = up["userID_id"]
                 if userID_id not in userID_ids:
                     now_time = int(time.time())
-                    eq_list.append(Equipment_Info(
-                        userID_id=userID_id,
-                        eventTime=n_time,
-                        eventType=eventType,
-                        devUid=uid,
-                        devNickName=nickname,
-                        Channel=channel,
+                    eq_list.append(EquipmentInfoService.get_equipment_info_obj(
+                        local_date_time,
+                        device_user_id=userID_id,
+                        event_time=n_time,
+                        event_type=eventType,
+                        device_uid=uid,
+                        device_nick_name=nickname,
+                        channel=channel,
                         alarm='检查到{labels} \tChannel:{channel}'.format(labels=label_str,channel=channel),
                         is_st=is_st,
-                        receiveTime=receiveTime,
-                        addTime=now_time,
+                        receive_time=receiveTime,
+                        add_time=now_time,
                         storage_location=2,
-                        borderCoords=json.dumps(new_bounding_box_dict)
+                        border_coords=json.dumps(new_bounding_box_dict)
                     ))
                     userID_ids.append(userID_id)
 
@@ -280,7 +285,10 @@ class AiView(View):
             photo.close()
             self.del_path(dir_path)
             self.del_path(dir_path + '.jpg')
-            Equipment_Info.objects.bulk_create(eq_list)
+            # 分表批量存储
+            if eq_list and len(eq_list) > 0:
+                week = LocalDateTimeUtil.date_to_week(local_date_time)
+                EquipmentInfoService.equipment_info_bulk_create(week, eq_list)
             return response.json(0)
 
         except Exception as e: