|
@@ -23,11 +23,12 @@ from AnsjerPush.config import AI_IDENTIFICATION_TAGS_DICT, CONFIG_US, CONFIG_EUR
|
|
|
from AnsjerPush.config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APNS_MODE, APNS_CONFIG, BASE_DIR, \
|
|
|
JPUSH_CONFIG, FCM_CONFIG
|
|
|
from AnsjerPush.config import CONFIG_INFO
|
|
|
-from Model.models import UidPushModel, AiService
|
|
|
+from Model.models import UidPushModel, AiService, VodHlsTag, VodHlsTagType
|
|
|
from Object import MergePic
|
|
|
from Object.ETkObject import ETkObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
+from Object.enums.MessageTypeEnum import MessageTypeEnum
|
|
|
from Object.utils import LocalDateTimeUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
@@ -248,12 +249,13 @@ class AiView(View):
|
|
|
logger.info(
|
|
|
"errLine={errLine}, errMsg={errMsg}".format(errLine=e.__traceback__.tb_lineno, errMsg=repr(e)))
|
|
|
continue
|
|
|
+ week = LocalDateTimeUtil.date_to_week(local_date_time)
|
|
|
# 分表批量存储
|
|
|
if eq_list and len(eq_list) > 0:
|
|
|
logger.info("AI存库中........")
|
|
|
- week = LocalDateTimeUtil.date_to_week(local_date_time)
|
|
|
result = EquipmentInfoService.equipment_info_bulk_create(week, eq_list)
|
|
|
logger.info("-.-存库结果{}".format(result))
|
|
|
+ AiView.save_cloud_ai_tag(uid, int(n_time), eventType, week)
|
|
|
return response.json(0)
|
|
|
|
|
|
except Exception as e:
|
|
@@ -428,69 +430,31 @@ class AiView(View):
|
|
|
send_text = '{msg} channel:{channel} date:{date}'.format(msg=msg, channel=channel, date=n_date)
|
|
|
return send_text
|
|
|
|
|
|
- def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
- app_key = JPUSH_CONFIG[appBundleId]['Key']
|
|
|
- master_secret = JPUSH_CONFIG[appBundleId]['Secret']
|
|
|
- # 此处换成各自的app_key和master_secre
|
|
|
- _jpush = jpush.JPush(app_key, master_secret)
|
|
|
- push = _jpush.create_push()
|
|
|
- push.audience = jpush.registration_id(token_val)
|
|
|
- push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
- "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
|
|
|
- android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
|
|
|
- big_text=msg_text, title=msg_title,
|
|
|
- extras=push_data)
|
|
|
- push.notification = jpush.notification(android=android)
|
|
|
- push.platform = jpush.all_
|
|
|
- res = push.send()
|
|
|
- print(res)
|
|
|
- return res.status_code
|
|
|
-
|
|
|
- def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
- try:
|
|
|
-
|
|
|
- serverKey = FCM_CONFIG[appBundleId]
|
|
|
- push_service = FCMNotification(api_key=serverKey)
|
|
|
- data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
- "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
|
|
|
- result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
|
|
|
- message_body=msg_text, data_message=data,
|
|
|
- extra_kwargs={
|
|
|
- 'default_vibrate_timings': True,
|
|
|
- 'default_sound': True,
|
|
|
- 'default_light_settings': True
|
|
|
- })
|
|
|
- print('fcm push ing')
|
|
|
- print(result)
|
|
|
- return result
|
|
|
- except Exception as e:
|
|
|
- return 'serverKey abnormal'
|
|
|
-
|
|
|
- def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
- logger = logging.getLogger('info')
|
|
|
- logger.info("进来do_apns函数了")
|
|
|
- logger.info(token_val)
|
|
|
- logger.info(APNS_MODE)
|
|
|
- logger.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
|
+ @classmethod
|
|
|
+ def save_cloud_ai_tag(cls, uid, event_time, types, week):
|
|
|
+ """
|
|
|
+ 保存云存AI标签
|
|
|
+ """
|
|
|
try:
|
|
|
- cli = apns2.APNSClient(mode=APNS_MODE,
|
|
|
- client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
|
- push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
- "received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
|
|
|
- alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
|
|
|
- payload = apns2.Payload(alert=alert, custom=push_data, sound="default")
|
|
|
- n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
- res = cli.push(n=n, device_token=token_val, topic=appBundleId)
|
|
|
-
|
|
|
- if res.status_code == 200:
|
|
|
- return res.status_code
|
|
|
+ types = str(types)
|
|
|
+ if not types:
|
|
|
+ return False
|
|
|
+ n_time = int(time.time())
|
|
|
+ vod_hls_tag = {"uid": uid, "ai_event_time": event_time, "created_time": n_time, 'tab_num': int(week)}
|
|
|
+ vod_tag_vo = VodHlsTag.objects.create(**vod_hls_tag)
|
|
|
+ tag_list = []
|
|
|
+ if len(types) > 1:
|
|
|
+ for i in range(1, len(types) + 1):
|
|
|
+ ai_type = MessageTypeEnum(int(types[i - 1:i]))
|
|
|
+ vod_tag_type_vo = VodHlsTagType(tag_id=vod_tag_vo.id, created_time=n_time, type=ai_type.value)
|
|
|
+ tag_list.append(vod_tag_type_vo)
|
|
|
else:
|
|
|
- logger.info('apns push fail')
|
|
|
- logger.info(res.reason)
|
|
|
- return res.status_code
|
|
|
- except (ValueError, ArithmeticError):
|
|
|
- return 'The program has a numeric format exception, one of the arithmetic exceptions'
|
|
|
+ ai_type = MessageTypeEnum(int(types))
|
|
|
+ vod_tag_type_vo = {"tag_id": vod_tag_vo.id, "created_time": n_time, "type": ai_type.value}
|
|
|
+ VodHlsTagType.objects.create(**vod_tag_type_vo)
|
|
|
+ if tag_list:
|
|
|
+ VodHlsTagType.objects.bulk_create(tag_list)
|
|
|
+ return True
|
|
|
except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- logger.info(repr(e))
|
|
|
- return repr(e)
|
|
|
+ print('AI标签存储异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return False
|