浏览代码

修改推送报警开关、手动报警开关

peng 2 年之前
父节点
当前提交
383c935526
共有 2 个文件被更改,包括 24 次插入0 次删除
  1. 23 0
      Controller/DetectControllerV2.py
  2. 1 0
      Controller/UserController.py

+ 23 - 0
Controller/DetectControllerV2.py

@@ -58,6 +58,9 @@ class DetectControllerViewV2(View):
             # 更新推送延迟
             elif operation == 'updateInterval':
                 return self.do_update_interval(userID, request_dict, response)
+            # 修改推送报警开关、手动报警开关
+            elif operation == 'updateAlarmpushOrManualalarm':
+                return self.do_update_alarmpush_or_manualalarm(userID, request_dict, response)
             else:
                 return response.json(414)
         else:
@@ -424,6 +427,26 @@ class DetectControllerViewV2(View):
         else:
             return response.json(0)
 
+    def do_update_alarmpush_or_manualalarm(self, user_id, request_dict, response):
+        uid = request_dict.get('uid', None)
+        status = request_dict.get('status', None)
+        alarm_type = request_dict.get('alarm_type', None)
+        if not all([uid, status, alarm_type]):
+            return response.json(444, 'uid or status or alarm_type')
+        # 查询设备是否属于该用户
+        device_info_qs = Device_Info.objects.filter(userID_id=user_id, UID=uid)
+        if not device_info_qs.exists():
+            return response.json(14)
+        thing_name = CommonService.query_serial_with_uid(uid)  # 存在序列号则为使用序列号作为物品名
+        topic_name = 'ansjer/generic/{}'.format(thing_name)
+        msg = {
+            'commandType': alarm_type,
+            'enable': status
+        }
+        req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
+        if not req_success:
+            return response.json(10044)
+        return response.json(0)
 
 # 这个接口没有调用过,不敢动
 # http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0

+ 1 - 0
Controller/UserController.py

@@ -2147,6 +2147,7 @@ class v3LoginView(TemplateView):
             else:
                 GatewayPush.objects.create(user_id=userID, app_bundle_id=app_bundle_id, app_type=app_type,
                                            push_type=push_type, token_val=token_val, m_code=m_code, lang=lang, tz=tz)
+            UidPushModel.objects.filter(userID=userID, m_code=m_code).update(token_val=token_val, push_type=push_type)
 
         now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
         region_country = users['region_country']