Quellcode durchsuchen

Merge branch 'LocalWyp' of http://192.168.136.45:3000/SERVER/AnsjerPush into LocalWyp

WuYiPei vor 5 Jahren
Ursprung
Commit
e1c9457b3d
2 geänderte Dateien mit 115 neuen und 434 gelöschten Zeilen
  1. 113 434
      Controller/DetectController.py
  2. 2 0
      Model/models.py

+ 113 - 434
Controller/DetectController.py

@@ -50,6 +50,7 @@ class NotificationView(View):
         uidToken = request_dict.get('uidToken', None)
         etk = request_dict.get('etk', None)
         channel = request_dict.get('channel', '1')
+        channel = request_dict.get('channel', '1')
         n_time = request_dict.get('n_time', None)
         event_type = request_dict.get('event_type', None)
         is_st = request_dict.get('is_st', None)
@@ -68,451 +69,129 @@ class NotificationView(View):
         else:
             utko = UidTokenObject(uidToken)
             uid = utko.UID
-            uid = 'HLK7EJ2VYLNHHUMG111A'
-
-        redisObj = RedisObject(db=6)
         pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
         ykey = '{uid}_redis_qs'.format(uid=uid)
-        ckey = '{uid}_interval_group'.format(uid=uid)
-        dkey = '{uid}_{event_type}_redis_qs'.format(uid=uid, event_type=event_type)
-        have_push_pkey = redisObj.get_data(key=pkey)
-        have_push_dkey = redisObj.get_data(key=dkey)
-        have_push_ykey = redisObj.get_data(key=ykey)
-        have_push_ckey = redisObj.get_data(key=ckey)
-        #--------------------兼容旧代码--------------------
-        # 用缓存ckey判断兼容旧代码还是新代码的情况
-        if have_push_ckey:
-            print("从缓存ckey中获取detect_interval和detect_group")
-            check_list=eval(have_push_ckey)
-            detect_interval = check_list[0]['uid_set__detect_interval']
-            detect_group = check_list[0]['uid_set__detect_group']
+        dkey = '{uid}_{event_type}_flag'.format(uid=uid, event_type=event_type)
+        # 判断redisObj.get_data(key=pkey):不为空
+        redisObj = RedisObject(db=6)
+        have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
+        have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
+        have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
+        # 一分钟外,推送开启状态
+        detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
+        if have_pkey:
+            res_data = {'code': 0, 'msg': 'success!'}
+            return JsonResponse(status=200, data=res_data)
+        # 数据库读取数据
+        if have_ykey:
+            redis_list = eval(redisObj.get_data(key=ykey))
         else:
-            uid_push_cs = 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',
-                       'push_type', 'userID_id', 'lang',
-                       'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
-            check_list = []
+                       'push_type', 'userID_id', 'userID__NickName',
+                       'lang', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
+            # 新建一个list接收数据
+            redis_list = []
             # 把数据库数据追加进redis_list
-            for cs in uid_push_cs:
-                check_list.append(cs)
-            detect_interval = check_list[0]['uid_set__detect_interval']
-            detect_group = check_list[0]['uid_set__detect_group']
-            print(detect_group)
-            print(detect_interval)
-            redisObj.set_data(key=ckey, val=str(check_list), expire=3600)
-        # 走旧代码
-        if detect_interval and detect_group:
-            if redisObj.get_data(key=pkey):
-                res_data = {'code': 0, 'msg': 'success!'}
-                return JsonResponse(status=200, data=res_data)
-            else:
-                redis_data = redisObj.get_data(key=ykey)
-                if redis_data:
-                    redis_list = eval(redis_data)
-                else:
-                    # 设置推送时间为60秒一次
-                    redisObj.set_data(key=pkey, val=1, expire=60)
-                    print("从数据库查到数据")
-                    # 从数据库查询出来
-                    uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                        values('token_val', 'app_type', 'appBundleId',
-                               'push_type', 'userID_id', 'lang',
-                               'tz', 'uid_set__nickname')
-                    # 新建一个list接收数据
-                    redis_list = []
-                    # 把数据库数据追加进redis_list
-                    for qs in uid_push_qs:
-                        redis_list.append(qs)
-                    # 修改redis数据,并设置过期时间为10分钟
-                    redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-            if redis_list:
-                nickname = redis_list[0]['uid_set__nickname']
-                now_time = int(time.time())
-                if not nickname:
-                    nickname = uid
-                # 判断是否为系统类通知
-                is_sys_msg = self.is_sys_msg(int(event_type))
-                auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                kwag_args = {
-                    'uid': uid,
-                    'channel': channel,
-                    'event_type': event_type,
-                    'n_time': n_time,
-                    # 'appBundleId': appBundleId,
-                    # 'token_val': token_val,
-                    # 'msg_title': msg_title,
-                    # 'msg_text': msg_text
-                }
-                eq_list = []
-                sys_msg_list = []
-                userID_ids = []
-                for up in redis_list:
-                    push_type = up['push_type']
-                    appBundleId = up['appBundleId']
-                    token_val = up['token_val']
-                    lang = up['lang']
-                    tz = up['tz']
-                    # 发送标题
-                    msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
-                    # 发送内容
-                    msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                 event_type=event_type)
-                    kwag_args['appBundleId'] = appBundleId
-                    kwag_args['token_val'] = token_val
-                    kwag_args['msg_title'] = msg_title
-                    kwag_args['msg_text'] = msg_text
-                    if push_type == 0:  # ios apns
-                        self.do_apns(**kwag_args)
-                    elif push_type == 1:  # android gcm
-                        self.do_fcm(**kwag_args)
-                    elif push_type == 2:  # android jpush
-                        self.do_jpush(**kwag_args)
-                    userID_id = up["userID_id"]
-                    int_is_st = int(is_st)
-                    if userID_id not in userID_ids:
-                        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(
-                                userID_id=userID_id,
-                                msg=sys_msg_text,
-                                addTime=now_time,
-                                updTime=now_time,
-                                uid=uid,
-                                eventType=event_type))
-                        userID_ids.append(userID_id)
-                return self.save_data(uid, channel, n_time, is_sys_msg, eq_list, is_st, bucket, sys_msg_list)
+            for qs in uid_push_qs:
+                redis_list.append(qs)
+            # 修改redis数据,并设置过期时间为10分钟
+            redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
+        if not redis_list:
+            res_data = {'code': 0, 'msg': 'success!'}
+            return JsonResponse(status=200, data=res_data)
+        is_sys_msg = self.is_sys_msg(int(event_type))
+        nickname = redis_list[0]['uid_set__nickname']
+        detect_interval = redis_list[0]['uid_set__detect_interval']
+        detect_group = redis_list[0]['uid_set__detect_group']
+        now_time = int(time.time())
+        if not nickname:
+            nickname = uid
+        if detect_group:
+            if have_dkey:
+                detect_med_type = 1
             else:
-                return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
-        #--------------------/兼容旧代码--------------------
-        #新代码
-        else:
-            # 限定一分钟内不推,不存
-            if have_push_pkey:
-                res_data = {'code': 0, 'msg': 'success!'}
-                return JsonResponse(status=200, data=res_data)
-            # 没有,没有dkey,也没有ykey
-            if not have_push_dkey and not have_push_ykey:
-                    # 设置推送时间为60秒一次
-                    redisObj.set_data(key=pkey, val=1, expire=60)
-                    #------------测试
-                    # 从数据库查询出来
-                    uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                        values('token_val', 'app_type', 'appBundleId',
-                               'push_type', 'userID_id', 'lang',
-                               'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
-                    # 用来判断是否推送
-                    redis_list = []
-                    # 把数据库数据追加进redis_list
-                    for qs in uid_push_qs:
-                        redis_list.append(qs)
-                    detect_interval = redis_list[0]['uid_set__detect_interval']
-                    detect_group = redis_list[0]['uid_set__detect_group']
-
-                    if detect_group:
-                        detect_group_list = detect_group.split(',')
-                        if event_type in detect_group_list:
-                            redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                    redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-                    if redis_list:
-                        nickname = redis_list[0]['uid_set__nickname']
-                        now_time = int(time.time())
-                        if not nickname:
-                            nickname = uid
-                        # 判断是否为系统类通知
-                        is_sys_msg = self.is_sys_msg(int(event_type))
-                        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                        kwag_args = {
-                            'uid': uid,
-                            'channel': channel,
-                            'event_type': event_type,
-                            'n_time': n_time,
-                            # 'appBundleId': appBundleId,
-                            # 'token_val': token_val,
-                            # 'msg_title': msg_title,
-                            # 'msg_text': msg_text
-                        }
-                        eq_list = []
-                        sys_msg_list = []
-                        userID_ids = []
-                        for up in redis_list:
-                            push_type = up['push_type']
-                            appBundleId = up['appBundleId']
-                            token_val = up['token_val']
-                            lang = up['lang']
-                            tz = up['tz']
-                            # 发送标题
-                            msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
-                            # 发送内容
-                            msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                         event_type=event_type)
-                            kwag_args['appBundleId'] = appBundleId
-                            kwag_args['token_val'] = token_val
-                            kwag_args['msg_title'] = msg_title
-                            kwag_args['msg_text'] = msg_text
-                            #第一次进来,才推送
-                            if push_type == 0:  # ios apns
-                                self.do_apns(**kwag_args)
-                            elif push_type == 1:  # android gcm
-                                self.do_fcm(**kwag_args)
-                            elif push_type == 2:  # android jpush
-                                self.do_jpush(**kwag_args)
-                            userID_id = up["userID_id"]
-                            int_is_st = int(is_st)
-                            if userID_id not in userID_ids:
-                                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(
-                                        userID_id=userID_id,
-                                        msg=sys_msg_text,
-                                        addTime=now_time,
-                                        updTime=now_time,
-                                        uid=uid,
-                                        eventType=event_type))
-                                userID_ids.append(userID_id)
-                        return self.save_data(uid, channel, n_time, is_sys_msg, eq_list, is_st, bucket, sys_msg_list)
-            # 有dkey,也有ykey(一分钟外,10分钟内)
-            if have_push_dkey and have_push_ykey:
-                redis_data = redisObj.get_data(key=ykey)
-                if redis_data:
-                    redis_list = eval(redis_data)
-                if redis_list:
-                    nickname = redis_list[0]['uid_set__nickname']
-                    now_time = int(time.time())
-                    if not nickname:
-                        nickname = uid
-                        # 判断是否为系统类通知
-                        is_sys_msg = self.is_sys_msg(int(event_type))
-                        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                        kwag_args = {
-                            'uid': uid,
-                            'channel': channel,
-                            'event_type': event_type,
-                            'n_time': n_time
-                        }
-                        eq_list = []
-                        sys_msg_list = []
-                        userID_ids = []
-                    for up in redis_list:
-                        lang = up['lang']
-                        tz = up['tz']
-                        userID_id = up["userID_id"]
-                        int_is_st = int(is_st)
-                        if userID_id not in userID_ids:
-                            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(
-                                    userID_id=userID_id,
-                                    msg=sys_msg_text,
-                                    addTime=now_time,
-                                    updTime=now_time,
-                                    uid=uid,
-                                    eventType=event_type))
-                            userID_ids.append(userID_id)
-                    return self.save_data(uid, channel, n_time, is_sys_msg, eq_list, is_st, bucket, sys_msg_list)
-            #没有dkey,有ykey(interval分钟外,10分钟内),创建pkey,dkey,推送,存库
-            if not have_push_dkey and  have_push_ykey:
-                #-----------测试------------
-                print("aaaaaaa")
-                # -----------测试------------
-                redis_data = have_push_ykey
-
-                if redis_data:
-                    redis_list = eval(redis_data)
-                    # -----------测试------------
-                    print("输出redis_list")
-                    print(redis_list)
-                    # -----------/测试------------
-                    # 再次设置推送时间为60秒一次
-                    redisObj.set_data(key=pkey, val=1, expire=60)
-                    # -----------测试------------
-                    redisObj.del_data(pkey)
-                    # -----------/测试------------
-                    detect_interval = redis_list[0]['uid_set__detect_interval']
-                    detect_group = redis_list[0]['uid_set__detect_group']
-                    if detect_group:
-                        detect_group_list = detect_group.split(',')
-                        if event_type in detect_group_list:
-                            redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                if redis_list:
-                    nickname = redis_list[0]['uid_set__nickname']
-                    now_time = int(time.time())
-                    if not nickname:
-                        nickname = uid
-                    # 判断是否为系统类通知
-                    is_sys_msg = self.is_sys_msg(int(event_type))
-                    auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                    bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                    kwag_args = {
-                        'uid': uid,
-                        'channel': channel,
-                        'event_type': event_type,
-                        'n_time': n_time,
-                    }
-                    eq_list = []
-                    sys_msg_list = []
-                    userID_ids = []
-                    for up in redis_list:
-                        push_type = up['push_type']
-                        appBundleId = up['appBundleId']
-                        token_val = up['token_val']
-                        lang = up['lang']
-                        tz = up['tz']
-                        print(lang)
-                        # 发送标题
-                        msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
-                        # 发送内容
-                        msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                     event_type=event_type)
-                        # -----------测试------------
-                        return JsonResponse(status=200, data={'code': 0, 'msg': 'have dkey,no ykey'})
-                        # -----------/测试------------
-                        kwag_args['appBundleId'] = appBundleId
-                        kwag_args['token_val'] = token_val
-                        kwag_args['msg_title'] = msg_title
-                        kwag_args['msg_text'] = msg_text
-                        if push_type == 0:  # ios apns
-                            self.do_apns(**kwag_args)
-                        elif push_type == 1:  # android gcm
-                            self.do_fcm(**kwag_args)
-                        elif push_type == 2:  # android jpush
-                            self.do_jpush(**kwag_args)
-                        userID_id = up["userID_id"]
-                        int_is_st = int(is_st)
-                        if userID_id not in userID_ids:
-                            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(
-                                    userID_id=userID_id,
-                                    msg=sys_msg_text,
-                                    addTime=now_time,
-                                    updTime=now_time,
-                                    uid=uid,
-                                    eventType=event_type))
-                            userID_ids.append(userID_id)
-                    return self.save_data(uid, channel, n_time, is_sys_msg, eq_list, is_st, bucket, sys_msg_list)
-            #有dkey,没有ykey的情况
-            if have_push_dkey and not have_push_ykey:
-                uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                    values('token_val', 'app_type', 'appBundleId',
-                           'push_type', 'userID_id', 'lang',
-                           'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
-                redis_list = []
-                # 把数据库数据追加进redis_list
-                for qs in uid_push_qs:
-                    redis_list.append(qs)
-                redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-                if redis_list:
-                    nickname = redis_list[0]['uid_set__nickname']
-                    now_time = int(time.time())
-                    if not nickname:
-                        nickname = uid
-                    # 判断是否为系统类通知
-                    is_sys_msg = self.is_sys_msg(int(event_type))
-                    auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                    bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                    kwag_args = {
-                        'uid': uid,
-                        'channel': channel,
-                        'event_type': event_type,
-                        'n_time': n_time,
-                    }
-                    eq_list = []
-                    sys_msg_list = []
-                    userID_ids = []
-                    for up in redis_list:
-                        lang = up['lang']
-                        tz = up['tz']
-                        userID_id = up["userID_id"]
-                        int_is_st = int(is_st)
-                        if userID_id not in userID_ids:
-                            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(
-                                    userID_id=userID_id,
-                                    msg=sys_msg_text,
-                                    addTime=now_time,
-                                    updTime=now_time,
-                                    uid=uid,
-                                    eventType=event_type))
-                            userID_ids.append(userID_id)
-                    return self.save_data(uid, channel, n_time, is_sys_msg, eq_list, is_st, bucket, sys_msg_list)
-
-    # 封装存库部分代码
-    def save_data(self, uid, channel, n_time, is_sys_msg, eq_list, is_st, bucket, sys_msg_list):
+                detect_med_type = 2
+                detect_group_list = detect_group.split(',')
+                if event_type in detect_group_list:
+                    redisObj.set_data(key=dkey, val=1, expire=detect_interval)
+        # 旧模式并且没有pkey,重新创建一个
+        if not detect_group and not have_pkey:
+            # 设置推送时间为60秒一次
+            redisObj.set_data(key=pkey, val=1, expire=60)
+        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
+        kwag_args = {
+            'uid': uid,
+            'channel': channel,
+            'event_type': event_type,
+            'n_time': n_time,
+            # 'appBundleId': appBundleId,
+            # 'token_val': token_val,
+            # 'msg_title': msg_title,
+            # 'msg_text': msg_text
+        }
+        eq_list = []
+        sys_msg_list = []
+        userID_ids = []
+        for up in redis_list:
+            push_type = up['push_type']
+            appBundleId = up['appBundleId']
+            token_val = up['token_val']
+            lang = up['lang']
+            tz = up['tz']
+            # 发送标题
+            msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
+            # 发送内容
+            msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
+                                         event_type=event_type)
+            kwag_args['appBundleId'] = appBundleId
+            kwag_args['token_val'] = token_val
+            kwag_args['msg_title'] = msg_title
+            kwag_args['msg_text'] = msg_text
+            if detect_med_type == 2 or detect_med_type == 0:
+                if push_type == 0:  # ios apns
+                    self.do_apns(**kwag_args)
+                elif push_type == 1:  # android gcm
+                    self.do_fcm(**kwag_args)
+                elif push_type == 2:  # android jpush
+                    self.do_jpush(**kwag_args)
+            # 以下是存库
+            userID_id = up["userID_id"]
+            int_is_st = int(is_st)
+            if userID_id not in userID_ids:
+                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(
+                        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:
             SysMsgModel.objects.bulk_create(sys_msg_list)
         Equipment_Info.objects.bulk_create(eq_list)
         if is_st == '0' or is_st == '2':
+            print("is_st=0or2")
             return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
         elif is_st == '1':
+            print("is_st=1")
             # Endpoint以杭州为例,其它Region请按实际情况填写。
             obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
             # 设置此签名URL在60秒内有效。
@@ -520,6 +199,7 @@ class NotificationView(View):
             res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
             return JsonResponse(status=200, data=res_data)
         elif is_st == '3':
+            print("is_st=3")
             # 人形检测带动图
             # Endpoint以杭州为例,其它Region请按实际情况填写。
             img_url_list = []
@@ -532,7 +212,6 @@ class NotificationView(View):
             res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
             return JsonResponse(status=200, data=res_data)
 
-
     def get_msg_title(self, appBundleId, nickname):
         package_title_config = {
             'com.ansjer.customizedd_a': 'DVS',

+ 2 - 0
Model/models.py

@@ -333,6 +333,8 @@ class UidSetModel(models.Model):
     resetTime = models.IntegerField(default=0, verbose_name='设备重置时间')
     is_alexa = models.IntegerField(default=0, verbose_name='会否支持alexa') # 0:否,1:是
     detect_group = models.CharField(default='', max_length=32, verbose_name=u'检测类型')
+    region_alexa = models.CharField(max_length=8, verbose_name='设备alexa区域', default='ALL')  # ALL CN EU US
+
     class Meta:
         db_table = 'uid_set'
         verbose_name = u'设备配置表'