Selaa lähdekoodia

修改ai识别消息异步推送

zhangdongming 1 vuosi sitten
vanhempi
commit
b0130c3389
1 muutettua tiedostoa jossa 25 lisäystä ja 4 poistoa
  1. 25 4
      Object/SageMakerAiObject.py

+ 25 - 4
Object/SageMakerAiObject.py

@@ -9,6 +9,7 @@
 import base64
 import json
 import logging
+import threading
 import time
 from io import BytesIO
 
@@ -98,7 +99,7 @@ class SageMakerAiObject:
         }
         """
         try:
-            LOGGER.info(f'***get_table_name***uid={uid},接收到识别信息={ai_result}')
+            LOGGER.info(f'***get_table_name***uid={uid}')
             ai_table_groups = {'person': 1, 'cat': 2, 'dog': 2, 'vehicle': 3, 'package': 4}
             event_group = []
 
@@ -158,7 +159,7 @@ class SageMakerAiObject:
                 'alarm': label_str,
                 'border_coords': coords
             }
-
+            push_msg_list = []
             equipment_info_list = []
             equipment_info_model = EquipmentInfoService.randoms_choice_equipment_info()  # 随机获取其中一张推送表
             for up in uid_push_list:
@@ -191,12 +192,19 @@ class SageMakerAiObject:
                     'msg_text': msg_text,
                     'uid': uid,
                     'channel': channel,
+                    'push_type': push_type
                 }
-                SageMakerAiObject().app_user_message_push(push_type, **kwargs)
+                push_msg_list.append(kwargs)
 
             if equipment_info_list:  # 消息存表
                 equipment_info_model.objects.bulk_create(equipment_info_list)
-            SageMakerAiObject().upload_image_to_s3(uid, channel, d_push_time, file_list)
+
+            SageMakerAiObject().upload_image_to_s3(uid, channel, d_push_time, file_list)  # 上传到云端
+
+            push_thread = threading.Thread(target=SageMakerAiObject.async_app_msg_push,
+                                           kwargs={'uid': uid, 'push_msg_list': push_msg_list})
+            push_thread.start()  # APP消息提醒异步推送
+
             AiController.AiView().save_cloud_ai_tag(uid, d_push_time, event_type, 0)  # 关联AI标签
             return True
         except Exception as e:
@@ -204,6 +212,19 @@ class SageMakerAiObject:
                         .format(uid, errLine=e.__traceback__.tb_lineno, errMsg=repr(e)))
             return False
 
+    @staticmethod
+    def async_app_msg_push(uid, push_msg_list):
+        """
+        APP消息提醒异步推送
+        """
+        if not push_msg_list:
+            LOGGER.info(f'***uid={uid}APP推送push_info为空***')
+        for item in push_msg_list:
+            push_type = item['push_type']
+            item.pop('push_type')
+            SageMakerAiObject.app_user_message_push(push_type, **item)
+        LOGGER.info(f'***uid={uid}APP推送完成')
+
     @staticmethod
     def app_user_message_push(push_type, **kwargs):
         """