|
@@ -1,10 +1,12 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+import time
|
|
|
+
|
|
|
import oss2
|
|
|
from django.views import View
|
|
|
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
-from Model.models import VoicePromptModel
|
|
|
+from Model.models import VoicePromptModel, UidChannelSetModel, Device_Info
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
@@ -35,46 +37,57 @@ class VoicePromptView(View):
|
|
|
return response.json(token.code)
|
|
|
|
|
|
if operation == 'getUploadUrl':
|
|
|
- return self.get_upload_url(token.userID, request_dict, response)
|
|
|
+ return self.get_upload_url(request_dict, response)
|
|
|
elif operation == 'add':
|
|
|
- return self.do_add(token.userID, request_dict, response)
|
|
|
+ return self.do_add(request_dict, response)
|
|
|
elif operation == 'delete':
|
|
|
return self.do_delete(token.userID, request_dict, response)
|
|
|
elif operation == 'query':
|
|
|
- return self.do_query(token.userID, request_dict, response)
|
|
|
+ return self.do_query(request_dict, response)
|
|
|
elif operation == 'adminAdd':
|
|
|
- return self.do_admin_add(token.userID, request_dict, response)
|
|
|
+ return self.do_admin_add(request_dict, response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
|
- def get_upload_url(self, userID, request_dict, response):
|
|
|
+ def get_upload_url(self, request_dict, response):
|
|
|
upload_type = request_dict.get('upload_type', None)
|
|
|
- if upload_type:
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
+
|
|
|
+ if upload_type and uid and channel:
|
|
|
+ count = VoicePromptModel.objects.filter(uid=uid, channel=channel).count()
|
|
|
+ if count >= 3:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
bucket = oss2.Bucket(auth, 'oss-cn-hongkong.aliyuncs.com', 'statres')
|
|
|
name = CommonService.createOrderID()
|
|
|
filename = str(name) + '.' + upload_type
|
|
|
- obj = 'voice_prompt/{userID}/'.format(userID=userID) + filename
|
|
|
+ obj = 'voice_prompt/{uid}/{channel}/'.format(uid=uid, channel=channel) + filename
|
|
|
|
|
|
url = bucket.sign_url('PUT', obj, 7200)
|
|
|
return response.json(0, {'put_url': url, 'filename': filename})
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
|
|
|
- def do_add(self, userID, request_dict, response):
|
|
|
+ def do_add(self, request_dict, response):
|
|
|
filename = request_dict.get('filename', None)
|
|
|
title = request_dict.get('title', None)
|
|
|
type = request_dict.get('type', None)
|
|
|
lang = request_dict.get('lang', '')
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
|
|
|
- if filename and title and type:
|
|
|
+ if filename and title and type and uid and channel:
|
|
|
voice_prompt = VoicePromptModel()
|
|
|
voice_prompt.filename = filename
|
|
|
voice_prompt.title = title
|
|
|
voice_prompt.type = type
|
|
|
voice_prompt.language = lang
|
|
|
- voice_prompt.user_id = userID
|
|
|
voice_prompt.classification = 1
|
|
|
+ voice_prompt.uid = uid
|
|
|
+ voice_prompt.channel = channel
|
|
|
+ voice_prompt.add_time = int(time.time())
|
|
|
voice_prompt.save()
|
|
|
return response.json(0)
|
|
|
else:
|
|
@@ -83,28 +96,42 @@ class VoicePromptView(View):
|
|
|
def do_delete(self, userID, request_dict, response):
|
|
|
id = request_dict.get('id', None)
|
|
|
if id:
|
|
|
- voice_qs = VoicePromptModel.objects.filter(id=id, user_id=userID)
|
|
|
+ voice_qs = VoicePromptModel.objects.filter(id=id)
|
|
|
if voice_qs.exists():
|
|
|
- voice_qs.delete()
|
|
|
- return response.json(0)
|
|
|
+ uid = voice_qs[0].uid
|
|
|
+ device_qs = Device_Info.objects.filter(UID=uid, userID=userID)
|
|
|
+ if device_qs.exists():
|
|
|
+ voice_qs.delete()
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
|
|
|
- def do_query(self, userID, request_dict, response):
|
|
|
- page = request_dict.get('page', None)
|
|
|
- line = request_dict.get('line', None)
|
|
|
+ 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 page and line and type and lang:
|
|
|
- page = int(page)
|
|
|
- line = int(line)
|
|
|
- if page < 0 or line < 0:
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
- voice_qs = VoicePromptModel.objects.filter(user_id=userID, type=type, classification=1)
|
|
|
+ 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)
|
|
|
- res = {}
|
|
|
+ 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
|
|
|
+ }
|
|
|
systems = []
|
|
|
customs = []
|
|
|
|
|
@@ -116,20 +143,18 @@ class VoicePromptView(View):
|
|
|
system_qs = system_qs.values('id', 'title', 'filename', 'type')
|
|
|
for system in system_qs:
|
|
|
filename = system['filename']
|
|
|
- obj = 'voice_prompt/' + userID + '/' + filename
|
|
|
+ obj = 'voice_prompt/' + uid + '/' + channel + '/' + filename
|
|
|
url = bucket.sign_url('GET', obj, 3600)
|
|
|
system['url'] = url
|
|
|
del system['filename']
|
|
|
systems.append(system)
|
|
|
|
|
|
if voice_qs.exists():
|
|
|
- start = (page - 1) * line
|
|
|
- end = start + line
|
|
|
- voice_qs = voice_qs[start: end].values('id', 'title', 'filename', 'type')
|
|
|
+ voice_qs = voice_qs.values('id', 'title', 'filename', 'type')
|
|
|
|
|
|
for voice in voice_qs:
|
|
|
filename = voice['filename']
|
|
|
- obj = 'voice_prompt/' + userID + '/' + filename
|
|
|
+ obj = 'voice_prompt/' + uid + '/' + channel + '/' + filename
|
|
|
url = bucket.sign_url('GET', obj, 3600)
|
|
|
voice['url'] = url
|
|
|
del voice['filename']
|
|
@@ -141,7 +166,8 @@ class VoicePromptView(View):
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
|
|
|
- def do_admin_add(self, userID, request_dict, response):
|
|
|
+
|
|
|
+ def do_admin_add(self, request_dict, response):
|
|
|
filename = request_dict.get('filename', None)
|
|
|
title = request_dict.get('title', None)
|
|
|
type = request_dict.get('type', None)
|
|
@@ -157,8 +183,8 @@ class VoicePromptView(View):
|
|
|
voice_prompt.title = title
|
|
|
voice_prompt.type = type
|
|
|
voice_prompt.language = lang
|
|
|
- voice_prompt.user_id = userID
|
|
|
voice_prompt.classification = 0
|
|
|
+ voice_prompt.add_time = int(time.time())
|
|
|
voice_prompt.save()
|
|
|
return response.json(0)
|
|
|
else:
|