Эх сурвалжийг харах

修复ai开关存在问题

locky 3 жил өмнө
parent
commit
abd504e802

+ 9 - 6
Controller/AiController.py

@@ -140,11 +140,13 @@ class AiView(View):
             if nowTime > endTime:
                 return response.json(10054)
 
-            dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
+            # 查询设备是否属于该用户
+            device_info_qs = Device_Info.objects.filter(userID_id=userID, UID=uid)
+            if not device_info_qs.exists():
+                return response.json(14)
             status = int(status)
             nowTime = int(time.time())
-            if not dvqs.exists():
-                return response.json(14)
+
             uid_set_qs = UidSetModel.objects.filter(uid=uid)
             if uid_set_qs.exists():
                 uid_set_id = uid_set_qs[0].id
@@ -171,11 +173,12 @@ class AiView(View):
 
             qs_data['detect_status'] = status  # ai开关状态
             ai_service_qs.update(**qs_data)
-            topic_name = 'ansjer/generic/{}'.format(uid)
+            thing_name = CommonService.query_serial_with_uid(uid)   # 存在序列号则为使用序列号作为物品名
+            topic_name = 'ansjer/generic/{}'.format(thing_name)
             if status == 0:  # 关闭
                 # mqtt通知设备关闭AI识别功能
                 msg = {'commandType': 'AIDisable'}
-                req_success = CommonService.req_publish_mqtt_msg(uid, topic_name, msg)
+                req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
                 if not req_success:
                     return response.json(10044)
                 return response.json(0)
@@ -225,7 +228,7 @@ class AiView(View):
                               'aiIdentificationUrl': aiIdentificationUrl,
                           }
                       },
-                req_success = CommonService.req_publish_mqtt_msg(uid, topic_name, msg)
+                req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
                 if not req_success:
                     return response.json(10044)
                 return response.json(0, {'aiIdentificationUrl': aiIdentificationUrl, 'endTime': endTime, 'etk': etk})