|
@@ -29,11 +29,12 @@ from Object.RedisObject import RedisObject
|
|
from Object.UidTokenObject import UidTokenObject
|
|
from Object.UidTokenObject import UidTokenObject
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
-
|
|
|
|
'''
|
|
'''
|
|
http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
|
|
http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
|
|
http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
|
|
http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
|
|
'''
|
|
'''
|
|
|
|
+
|
|
|
|
+
|
|
# 移动侦测接口
|
|
# 移动侦测接口
|
|
class NotificationView(View):
|
|
class NotificationView(View):
|
|
|
|
|
|
@@ -82,7 +83,7 @@ class NotificationView(View):
|
|
# 从数据库查询出来
|
|
# 从数据库查询出来
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
- 'push_type', 'userID_id','lang',
|
|
|
|
|
|
+ 'push_type', 'userID_id', 'lang',
|
|
'tz', 'uid_set__nickname')
|
|
'tz', 'uid_set__nickname')
|
|
# 新建一个list接收数据
|
|
# 新建一个list接收数据
|
|
redis_list = []
|
|
redis_list = []
|
|
@@ -112,6 +113,7 @@ class NotificationView(View):
|
|
}
|
|
}
|
|
eq_list = []
|
|
eq_list = []
|
|
sys_msg_list = []
|
|
sys_msg_list = []
|
|
|
|
+ userID_ids = []
|
|
for up in redis_list:
|
|
for up in redis_list:
|
|
push_type = up['push_type']
|
|
push_type = up['push_type']
|
|
appBundleId = up['appBundleId']
|
|
appBundleId = up['appBundleId']
|
|
@@ -133,31 +135,32 @@ class NotificationView(View):
|
|
elif push_type == 2: # android jpush
|
|
elif push_type == 2: # android jpush
|
|
self.do_jpush(**kwag_args)
|
|
self.do_jpush(**kwag_args)
|
|
userID_id = up["userID_id"]
|
|
userID_id = up["userID_id"]
|
|
- eq_list.append(Equipment_Info(
|
|
|
|
- userID_id=userID_id,
|
|
|
|
- eventTime=n_time,
|
|
|
|
- eventType=event_type,
|
|
|
|
- devUid=uid,
|
|
|
|
- devNickName=nickname,
|
|
|
|
- Channel=channel,
|
|
|
|
- alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
- is_st=int(is_st),
|
|
|
|
- receiveTime=n_time,
|
|
|
|
- addTime=now_time
|
|
|
|
- ))
|
|
|
|
-
|
|
|
|
- if is_sys_msg:
|
|
|
|
- sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
|
- event_type=event_type,is_sys=1)
|
|
|
|
- sys_msg_list.append(SysMsgModel(
|
|
|
|
|
|
+ int_is_st = int(is_st)
|
|
|
|
+ if userID_id not in userID_ids:
|
|
|
|
+ eq_list.append(Equipment_Info(
|
|
userID_id=userID_id,
|
|
userID_id=userID_id,
|
|
- msg=sys_msg_text,
|
|
|
|
- # msg='{msg_title} {msg_text}'.format(msg_title=msg_title, msg_text=msg_text),
|
|
|
|
- addTime=now_time,
|
|
|
|
- updTime=now_time,
|
|
|
|
- uid=uid,
|
|
|
|
- eventType=event_type
|
|
|
|
|
|
+ eventTime=n_time,
|
|
|
|
+ eventType=event_type,
|
|
|
|
+ devUid=uid,
|
|
|
|
+ devNickName=nickname,
|
|
|
|
+ Channel=channel,
|
|
|
|
+ alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
+ is_st=int_is_st,
|
|
|
|
+ receiveTime=n_time,
|
|
|
|
+ addTime=now_time
|
|
))
|
|
))
|
|
|
|
+ if is_sys_msg:
|
|
|
|
+ sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
|
+ event_type=event_type, is_sys=1)
|
|
|
|
+ sys_msg_list.append(SysMsgModel(
|
|
|
|
+ userID_id=userID_id,
|
|
|
|
+ msg=sys_msg_text,
|
|
|
|
+ addTime=now_time,
|
|
|
|
+ updTime=now_time,
|
|
|
|
+ uid=uid,
|
|
|
|
+ eventType=event_type))
|
|
|
|
+ userID_ids.append(userID_id)
|
|
|
|
+
|
|
if is_sys_msg:
|
|
if is_sys_msg:
|
|
SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
Equipment_Info.objects.bulk_create(eq_list)
|
|
Equipment_Info.objects.bulk_create(eq_list)
|
|
@@ -210,7 +213,7 @@ class NotificationView(View):
|
|
return True
|
|
return True
|
|
return False
|
|
return False
|
|
|
|
|
|
- def get_msg_text(self, channel, n_time, lang, tz, event_type,is_sys=0):
|
|
|
|
|
|
+ def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
|
|
n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
|
|
n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
|
|
etype = int(event_type)
|
|
etype = int(event_type)
|
|
if lang == 'cn':
|
|
if lang == 'cn':
|
|
@@ -342,13 +345,12 @@ class PushNotificationView(View):
|
|
redisObj = RedisObject(db=6)
|
|
redisObj = RedisObject(db=6)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
-
|
|
|
|
|
|
+ ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
if redisObj.get_data(key=pkey):
|
|
if redisObj.get_data(key=pkey):
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
return JsonResponse(status=200, data=res_data)
|
|
return JsonResponse(status=200, data=res_data)
|
|
else:
|
|
else:
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
- ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
|
|
##############
|
|
##############
|
|
redis_data = redisObj.get_data(key=ykey)
|
|
redis_data = redisObj.get_data(key=ykey)
|
|
if redis_data:
|
|
if redis_data:
|
|
@@ -360,7 +362,7 @@ class PushNotificationView(View):
|
|
# 从数据库查询出来
|
|
# 从数据库查询出来
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
- 'push_type', 'userID_id','lang',
|
|
|
|
|
|
+ 'push_type', 'userID_id', 'lang',
|
|
'tz', 'uid_set__nickname')
|
|
'tz', 'uid_set__nickname')
|
|
# 新建一个list接收数据
|
|
# 新建一个list接收数据
|
|
redis_list = []
|
|
redis_list = []
|
|
@@ -393,41 +395,92 @@ class PushNotificationView(View):
|
|
img_url_list.append(url)
|
|
img_url_list.append(url)
|
|
res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
|
|
res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
|
|
return JsonResponse(status=200, data=res_data)
|
|
return JsonResponse(status=200, data=res_data)
|
|
-
|
|
|
|
else:
|
|
else:
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
else:
|
|
else:
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
|
|
|
|
|
|
def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
- #
|
|
|
|
- qs_list = []
|
|
|
|
- nowTime = int(time.time())
|
|
|
|
|
|
+ now_time = int(time.time())
|
|
# 设备昵称
|
|
# 设备昵称
|
|
userID_ids = []
|
|
userID_ids = []
|
|
- for dv in uaqs:
|
|
|
|
- userID_id = dv["userID_id"]
|
|
|
|
|
|
+ sys_msg_list = []
|
|
|
|
+ is_sys_msg = self.is_sys_msg(int(event_type))
|
|
|
|
+ is_st = int(is_st)
|
|
|
|
+ eq_list = []
|
|
|
|
+ nickname = uaqs[0]['uid_set__nickname']
|
|
|
|
+ if not nickname:
|
|
|
|
+ nickname = uid
|
|
|
|
+ for ua in uaqs:
|
|
|
|
+ lang = ua['lang']
|
|
|
|
+ tz = ua['tz']
|
|
|
|
+ userID_id = ua["userID_id"]
|
|
if userID_id not in userID_ids:
|
|
if userID_id not in userID_ids:
|
|
- uid_nickname = dv['uid_set__nickname']
|
|
|
|
- if not uid_nickname:
|
|
|
|
- uid_nickname = uid
|
|
|
|
- add_data = {
|
|
|
|
- 'userID_id': dv["userID_id"],
|
|
|
|
- 'eventTime': n_time,
|
|
|
|
- 'eventType': event_type,
|
|
|
|
- 'devUid': uid,
|
|
|
|
- 'devNickName': uid_nickname,
|
|
|
|
- 'Channel': channel,
|
|
|
|
- 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
- 'is_st': int(is_st),
|
|
|
|
- 'receiveTime': n_time,
|
|
|
|
- 'addTime': nowTime
|
|
|
|
- }
|
|
|
|
- qs_list.append(Equipment_Info(**add_data))
|
|
|
|
- userID_ids.append(userID_id)
|
|
|
|
- if qs_list:
|
|
|
|
- print(1)
|
|
|
|
- Equipment_Info.objects.bulk_create(qs_list)
|
|
|
|
|
|
+ eq_list.append(Equipment_Info(
|
|
|
|
+ userID_id=userID_id,
|
|
|
|
+ eventTime=n_time,
|
|
|
|
+ eventType=event_type,
|
|
|
|
+ devUid=uid,
|
|
|
|
+ devNickName=nickname,
|
|
|
|
+ Channel=channel,
|
|
|
|
+ alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
+ is_st=is_st,
|
|
|
|
+ receiveTime=n_time,
|
|
|
|
+ addTime=now_time
|
|
|
|
+ ))
|
|
|
|
+ if is_sys_msg:
|
|
|
|
+ sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
|
+ event_type=event_type, is_sys=1)
|
|
|
|
+ sys_msg_list.append(SysMsgModel(
|
|
|
|
+ userID_id=userID_id,
|
|
|
|
+ msg=sys_msg_text,
|
|
|
|
+ addTime=now_time,
|
|
|
|
+ updTime=now_time,
|
|
|
|
+ uid=uid,
|
|
|
|
+ eventType=event_type))
|
|
|
|
+ if eq_list:
|
|
|
|
+ print('eq_list')
|
|
|
|
+ Equipment_Info.objects.bulk_create(eq_list)
|
|
|
|
+ if is_sys_msg:
|
|
|
|
+ print('sys_msg')
|
|
|
|
+ SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
|
+ return True
|
|
|
|
+
|
|
|
|
+ def is_sys_msg(self, event_type):
|
|
|
|
+ event_type_list = [702, 703, 704]
|
|
|
|
+ if event_type in event_type_list:
|
|
return True
|
|
return True
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
|
|
|
|
+ n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
|
|
|
|
+ etype = int(event_type)
|
|
|
|
+ if lang == 'cn':
|
|
|
|
+ if etype == 704:
|
|
|
|
+ msg_type = '电量过低'
|
|
|
|
+ elif etype == 702:
|
|
|
|
+ msg_type = '摄像头休眠'
|
|
|
|
+ elif etype == 703:
|
|
|
|
+ msg_type = '摄像头唤醒'
|
|
|
|
+ else:
|
|
|
|
+ msg_type = ''
|
|
|
|
+ if is_sys:
|
|
|
|
+ send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
|
|
|
|
+ else:
|
|
|
|
+ send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
|
|
else:
|
|
else:
|
|
- return False
|
|
|
|
|
|
+ if etype == 704:
|
|
|
|
+ msg_type = 'Low battery'
|
|
|
|
+ elif etype == 702:
|
|
|
|
+ msg_type = 'Camera sleep'
|
|
|
|
+ elif etype == 703:
|
|
|
|
+ msg_type = 'Camera wake'
|
|
|
|
+ else:
|
|
|
|
+ msg_type = ''
|
|
|
|
+ if is_sys:
|
|
|
|
+ send_text = '{msg_type} channel:{channel}'. \
|
|
|
|
+ format(msg_type=msg_type, channel=channel)
|
|
|
|
+ else:
|
|
|
|
+ send_text = '{msg_type} channel:{channel} date:{date}'. \
|
|
|
|
+ format(msg_type=msg_type, channel=channel, date=n_date)
|
|
|
|
+ return send_text
|