|
@@ -15,6 +15,7 @@ from Object.ResponseObject import ResponseObject
|
|
from Object.utils import LocalDateTimeUtil
|
|
from Object.utils import LocalDateTimeUtil
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
|
+from Service.GatewayService import GatewayPushService
|
|
|
|
|
|
|
|
|
|
class GatewayView(View):
|
|
class GatewayView(View):
|
|
@@ -46,15 +47,12 @@ class GatewayView(View):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
|
|
|
|
equipment_info_list = []
|
|
equipment_info_list = []
|
|
- now_time = int(time.time())
|
|
|
|
- device_user_id = '154700384179113800138000'
|
|
|
|
|
|
+ n_time = int(time.time())
|
|
try:
|
|
try:
|
|
- '''
|
|
|
|
- # 查询推送数据
|
|
|
|
|
|
+ # 查询推送配置数据
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=serial_number, uid_set__detect_status=1). \
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=serial_number, uid_set__detect_status=1). \
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
|
|
- 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
|
- 'uid_set__channel')
|
|
|
|
|
|
+ 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
|
|
if not uid_push_qs.exists():
|
|
if not uid_push_qs.exists():
|
|
return response.json(173)
|
|
return response.json(173)
|
|
uid_push_list = [uid_push for uid_push in uid_push_qs]
|
|
uid_push_list = [uid_push for uid_push in uid_push_qs]
|
|
@@ -63,29 +61,51 @@ class GatewayView(View):
|
|
detect_interval = uid_push_list[0]['uid_set__detect_interval']
|
|
detect_interval = uid_push_list[0]['uid_set__detect_interval']
|
|
detect_group = uid_push_list[0]['uid_set__detect_group']
|
|
detect_group = uid_push_list[0]['uid_set__detect_group']
|
|
|
|
|
|
|
|
+ kwargs = {'nickname': device_nick_name}
|
|
event_type = int(event_type)
|
|
event_type = int(event_type)
|
|
|
|
+ local_date_time = ''
|
|
for uid_push in uid_push_list:
|
|
for uid_push in uid_push_list:
|
|
|
|
+ device_user_id = uid_push['userID_id']
|
|
push_type = uid_push['push_type']
|
|
push_type = uid_push['push_type']
|
|
app_bundle_id = uid_push['appBundleId']
|
|
app_bundle_id = uid_push['appBundleId']
|
|
token_val = uid_push['token_val']
|
|
token_val = uid_push['token_val']
|
|
lang = uid_push['lang']
|
|
lang = uid_push['lang']
|
|
- tz = uid_push['tz']
|
|
|
|
- if tz is None or tz == '':
|
|
|
|
- tz = 0
|
|
|
|
- '''
|
|
|
|
- local_date_time = CommonService.get_now_time_str(n_time=now_time, tz=0, lang='cn')
|
|
|
|
- local_date_time = local_date_time[:10]
|
|
|
|
- equipment_info_list.append(EquipmentInfoService.get_equipment_info_obj(
|
|
|
|
- local_date_time,
|
|
|
|
- add_time=now_time,
|
|
|
|
- event_time=now_time,
|
|
|
|
- receive_time=now_time,
|
|
|
|
- device_uid=serial_number,
|
|
|
|
- event_type=event_type,
|
|
|
|
- alarm=alarm,
|
|
|
|
- device_nick_name=src_addr,
|
|
|
|
- device_user_id=device_user_id,
|
|
|
|
- ))
|
|
|
|
|
|
+ tz = uid_push['tz'] if uid_push['tz'] else 0
|
|
|
|
+
|
|
|
|
+ # 获取推送所需数据
|
|
|
|
+ msg_title = GatewayPushService.get_msg_title(app_bundle_id, device_nick_name)
|
|
|
|
+ msg_text = GatewayPushService.get_msg_text(n_time, tz, lang, alarm)
|
|
|
|
+
|
|
|
|
+ kwargs['msg_title'] = msg_title
|
|
|
|
+ kwargs['msg_text'] = msg_text
|
|
|
|
+ kwargs['app_bundle_id'] = app_bundle_id
|
|
|
|
+ kwargs['token_val'] = token_val
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ # 推送消息
|
|
|
|
+ if push_type == 0: # ios apns
|
|
|
|
+ GatewayPushService.ios_apns_push(**kwargs)
|
|
|
|
+ elif push_type == 1: # android gcm
|
|
|
|
+ GatewayPushService.android_fcm_push(**kwargs)
|
|
|
|
+ elif push_type == 2: # android 极光推送
|
|
|
|
+ GatewayPushService.android_jpush(**kwargs)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ logger.info('网关推送消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ # 组织存储数据
|
|
|
|
+ local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=0, lang='cn')[:10]
|
|
|
|
+ equipment_info_list.append(EquipmentInfoService.get_equipment_info_obj(
|
|
|
|
+ local_date_time,
|
|
|
|
+ add_time=n_time,
|
|
|
|
+ event_time=n_time,
|
|
|
|
+ receive_time=n_time,
|
|
|
|
+ device_uid=serial_number,
|
|
|
|
+ device_nick_name=device_nick_name,
|
|
|
|
+ alarm=alarm,
|
|
|
|
+ event_type=event_type,
|
|
|
|
+ device_user_id=device_user_id,
|
|
|
|
+ ))
|
|
if equipment_info_list:
|
|
if equipment_info_list:
|
|
# 根据日期获得星期几
|
|
# 根据日期获得星期几
|
|
week = LocalDateTimeUtil.date_to_week(local_date_time)
|
|
week = LocalDateTimeUtil.date_to_week(local_date_time)
|