Browse Source

ai推送数据分表存储

locky 3 years ago
parent
commit
cb0109a82e
1 changed files with 20 additions and 12 deletions
  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.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
 from Object.UidTokenObject import UidTokenObject
 from Object.UidTokenObject import UidTokenObject
+from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from django.db.models import Q, F, Count
 from django.db.models import Q, F, Count
 from decimal import Decimal
 from decimal import Decimal
 from AnsjerPush.config import SERVER_TYPE
 from AnsjerPush.config import SERVER_TYPE
+from Service.EquipmentInfoService import EquipmentInfoService
 from Service.ModelService import ModelService
 from Service.ModelService import ModelService
 from Object import MergePic
 from Object import MergePic
 import boto3
 import boto3
@@ -217,6 +219,7 @@ class AiView(View):
             userID_ids = []
             userID_ids = []
             apns_start_time = 0
             apns_start_time = 0
             apns_end_time = 0
             apns_end_time = 0
+            local_date_time = ''
             for up in uid_push_list:
             for up in uid_push_list:
                 push_type = up['push_type']
                 push_type = up['push_type']
                 appBundleId = up['appBundleId']
                 appBundleId = up['appBundleId']
@@ -225,24 +228,26 @@ class AiView(View):
                 tz = up['tz']
                 tz = up['tz']
                 if tz is None or tz == '':
                 if tz is None or tz == '':
                     tz = 0
                     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"]
                 userID_id = up["userID_id"]
                 if userID_id not in userID_ids:
                 if userID_id not in userID_ids:
                     now_time = int(time.time())
                     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),
                         alarm='检查到{labels} \tChannel:{channel}'.format(labels=label_str,channel=channel),
                         is_st=is_st,
                         is_st=is_st,
-                        receiveTime=receiveTime,
-                        addTime=now_time,
+                        receive_time=receiveTime,
+                        add_time=now_time,
                         storage_location=2,
                         storage_location=2,
-                        borderCoords=json.dumps(new_bounding_box_dict)
+                        border_coords=json.dumps(new_bounding_box_dict)
                     ))
                     ))
                     userID_ids.append(userID_id)
                     userID_ids.append(userID_id)
 
 
@@ -280,7 +285,10 @@ class AiView(View):
             photo.close()
             photo.close()
             self.del_path(dir_path)
             self.del_path(dir_path)
             self.del_path(dir_path + '.jpg')
             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)
             return response.json(0)
 
 
         except Exception as e:
         except Exception as e: