Browse Source

修改语音提示的查询接口

tanghongbin 4 years ago
parent
commit
4c92d7f281
1 changed files with 51 additions and 24 deletions
  1. 51 24
      Controller/VoicePromptController.py

+ 51 - 24
Controller/VoicePromptController.py

@@ -102,6 +102,10 @@ class VoicePromptView(View):
                 device_qs = Device_Info.objects.filter(UID=uid, userID=userID)
                 if device_qs.exists():
                     voice_qs.delete()
+                    auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+                    bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
+                    obj = 'voice_prompt/{uid}/{channel}/'.format(uid=uid, channel=voice_qs[0].channel) + voice_qs[0].filename
+                    bucket.delete_object(obj)
                     return response.json(0)
                 else:
                     return response.json(404)
@@ -109,34 +113,36 @@ class VoicePromptView(View):
             return response.json(444)
 
     def do_query(self, request_dict, response):
-        type = request_dict.get('type', None)
         lang = request_dict.get('lang', None)
         uid = request_dict.get('uid', None)
         channel = request_dict.get('channel', None)
 
-        if uid and channel and type and lang:
-            type = int(type)
-            voice_qs = VoicePromptModel.objects.filter(uid=uid, channel=channel, type=type, classification=1)
-            system_qs = VoicePromptModel.objects.filter(type=type, classification=0, language=lang)
+        if uid and channel and lang:
+            voice_qs = VoicePromptModel.objects.filter(uid=uid, channel=channel, classification=1)
+            system_qs = VoicePromptModel.objects.filter(classification=0, language=lang)
             channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid, channel=channel)
-            if channel_qs.exists():
-                channel_qs = channel_qs.values('voice_prompt_enter', 'voice_prompt_leave')
-                print(channel_qs)
-                if type == 1:  # 进入
-                    voice_id = channel_qs[0]['voice_prompt_enter']
-                else:
-                    voice_id = channel_qs[0]['voice_prompt_leave']
-            else:
-                voice_id = 0
 
             res = {
-                'selected_voice_id': voice_id
+                'enter_voice': {},
+                'leave_voice': {},
+                'voice_status': 0,
+                'voice_mute': 0
             }
-            systems = []
-            customs = []
-
-            res['systems'] = systems
-            res['customs'] = customs
+            if channel_qs.exists():
+                channel_qs = channel_qs.values('voice_prompt_enter', 'voice_prompt_leave', 'voice_prompt_status', 'voice_prompt_intelligent_mute')
+                print(channel_qs)
+                res['enter_voice'] = channel_qs[0]['voice_prompt_enter']
+                res['leave_voice'] = channel_qs[0]['voice_prompt_leave']
+                res['voice_status'] = channel_qs[0]['voice_prompt_status']
+                res['voice_mute'] = channel_qs[0]['voice_prompt_intelligent_mute']
+
+            enter_systems = []
+            leave_systems = []
+            enter_customs = []
+            leave_customs = []
+
+            res['system'] = {}
+            res['custom'] = {}
             auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
             bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
             if system_qs.exists():
@@ -147,7 +153,18 @@ class VoicePromptView(View):
                     url = bucket.sign_url('GET', obj, 3600)
                     system['url'] = url
                     del system['filename']
-                    systems.append(system)
+                    if system['type'] == 1:
+                        enter_systems.append(system)
+                        if res['enter_voice'] == system['id']:
+                            res['enter_voice'] = system
+
+                    elif system['type'] == 2:
+                        leave_systems.append(system)
+                        if res['leave_voice'] == system['id']:
+                            res['leave_voice'] = system
+
+
+
 
             if voice_qs.exists():
                 voice_qs = voice_qs.values('id', 'title', 'filename', 'type')
@@ -158,15 +175,25 @@ class VoicePromptView(View):
                     url = bucket.sign_url('GET', obj, 3600)
                     voice['url'] = url
                     del voice['filename']
-
-                res['customs'] = list(voice_qs)
+                    if voice['type'] == 1:
+                        enter_customs.append(voice)
+                        if res['enter_voice'] == voice['id']:
+                            res['enter_voice'] = voice
+                    elif voice['type'] == 2:
+                        leave_customs.append(voice)
+                        if res['leave_voice'] == voice['id']:
+                            res['leave_voice'] = voice
+
+            res['system']['enter'] = enter_systems
+            res['system']['leave'] = leave_systems
+            res['custom']['enter'] = enter_customs
+            res['custom']['leave'] = leave_customs
 
             return response.json(0, res)
 
         else:
             return response.json(444)
 
-
     def do_admin_add(self, request_dict, response):
         filename = request_dict.get('filename', None)
         title = request_dict.get('title', None)