|
@@ -9,7 +9,7 @@ import oss2
|
|
|
import requests
|
|
|
from django.core.paginator import Paginator
|
|
|
from django.db import transaction
|
|
|
-from django.db.models import Q, F, Sum
|
|
|
+from django.db.models import Q, F, Sum, OuterRef, Min, Subquery
|
|
|
from django.forms.models import model_to_dict
|
|
|
from django.views.generic.base import View
|
|
|
|
|
@@ -128,6 +128,8 @@ class DeviceManagement(View):
|
|
|
return self.edit_device_voice(request_dict, response)
|
|
|
elif operation == 'delDeviceVoice':
|
|
|
return self.del_device_voice(request_dict, response)
|
|
|
+ elif operation == 'deviceTypeList':
|
|
|
+ return self.device_type_list(response)
|
|
|
else:
|
|
|
return response.json(444, 'operation')
|
|
|
|
|
@@ -1731,6 +1733,7 @@ class DeviceManagement(View):
|
|
|
"addTime": voice_prompt.add_time,
|
|
|
"algorithmType": voice_prompt.algorithm_type,
|
|
|
"uid": voice_prompt.uid,
|
|
|
+ "device_types": voice_prompt.device_types
|
|
|
})
|
|
|
return response.json(0, {'list': voice_prompt_list, 'total': paginator.count})
|
|
|
except Exception as e:
|
|
@@ -1746,7 +1749,9 @@ class DeviceManagement(View):
|
|
|
"""
|
|
|
try:
|
|
|
device_algorithm_explain_qs = DeviceAlgorithmExplain.objects.filter(lang='cn').values('title', 'algorithm_type_id')
|
|
|
- return response.json(0, list(device_algorithm_explain_qs))
|
|
|
+ device_algorithm_explain = list(device_algorithm_explain_qs)
|
|
|
+ device_algorithm_explain.append({"title": "无", "algorithm_type_id": 99})
|
|
|
+ return response.json(0, device_algorithm_explain)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -1768,10 +1773,13 @@ class DeviceManagement(View):
|
|
|
language = request_dict.get('language', None)
|
|
|
uid = request_dict.get('uid', None)
|
|
|
channel = request_dict.get('channel', 1)
|
|
|
+ device_types = request_dict.get('deviceTypes', "")
|
|
|
voice_file = request.FILES.get('voiceFile', None)
|
|
|
+
|
|
|
if not all([title, voice_type, classification, algorithm_type, status, language, voice_file]):
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
+ device_type_list = device_types.split(',')
|
|
|
classification = int(classification)
|
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'ansjer-static-resources')
|
|
@@ -1784,7 +1792,8 @@ class DeviceManagement(View):
|
|
|
"language": language,
|
|
|
"status": status,
|
|
|
"algorithm_type": algorithm_type,
|
|
|
- "add_time": int(time.time())
|
|
|
+ "add_time": int(time.time()),
|
|
|
+ "device_types": device_type_list
|
|
|
}
|
|
|
if uid and classification == 1:
|
|
|
voice_prompt_dict["uid"] = uid
|
|
@@ -1817,6 +1826,7 @@ class DeviceManagement(View):
|
|
|
algorithm_type = request_dict.get('algorithmType', None)
|
|
|
status = request_dict.get('status', None)
|
|
|
language = request_dict.get('language', None)
|
|
|
+ device_types = request_dict.get('deviceTypes', "")
|
|
|
try:
|
|
|
voice_prompt = VoicePromptModel.objects.get(pk=device_voice_id)
|
|
|
if title:
|
|
@@ -1831,6 +1841,9 @@ class DeviceManagement(View):
|
|
|
voice_prompt.status = status
|
|
|
if language:
|
|
|
voice_prompt.language = language
|
|
|
+ if device_types:
|
|
|
+ device_type_list = device_types.split(',')
|
|
|
+ voice_prompt.device_types = device_type_list
|
|
|
voice_prompt.save()
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
@@ -1867,4 +1880,24 @@ class DeviceManagement(View):
|
|
|
print(e)
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
-
|
|
|
+ @staticmethod
|
|
|
+ def device_type_list(response):
|
|
|
+ """
|
|
|
+ 获取设备类型
|
|
|
+ @param response:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ subquery = DeviceTypeModel.objects.filter(
|
|
|
+ type=OuterRef('type')
|
|
|
+ ).values('type').annotate(
|
|
|
+ min_id=Min('id')
|
|
|
+ ).values('min_id')
|
|
|
+ # 根据最小 id 获取对应的 name 和 type
|
|
|
+ device_type_qs = DeviceTypeModel.objects.filter(
|
|
|
+ id__in=Subquery(subquery)
|
|
|
+ ).values("name", "type")
|
|
|
+ return response.json(0, list(device_type_qs))
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|