|
@@ -9,7 +9,7 @@
|
|
|
import logging
|
|
|
import time
|
|
|
|
|
|
-from django.db.models import F
|
|
|
+from django.db.models import F, Value, CharField
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Model.models import DeviceAlgorithmExplain, DeviceAlgorithmBanner, DeviceUidAlgorithmType, \
|
|
@@ -119,8 +119,32 @@ class AlgorithmShopView(View):
|
|
|
.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return {}
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def get_algorithm_list(cls, lang):
|
|
|
+ """
|
|
|
+ 获取所有算法数据列表
|
|
|
+ @return: 算法数据列表
|
|
|
+ """
|
|
|
+ algorithm_qs = DeviceAlgorithmExplain.objects.filter(lang=lang).order_by('algorithm_type__sort') \
|
|
|
+ .annotate(iconUrl=F('algorithm_type__icon_url'),
|
|
|
+ imageUrl=F('algorithm_type__image_url'),
|
|
|
+ basicFunction=F('algorithm_type__basic_function'),
|
|
|
+ tag=F('algorithm_type__tag'), status=F('algorithm_type__status'),
|
|
|
+ setting=Value('', output_field=CharField())) \
|
|
|
+ .values('iconUrl', 'imageUrl', 'title', 'subtitle', 'concerning', 'basicFunction', 'price', 'tag', 'status',
|
|
|
+ 'setting')
|
|
|
+ if not algorithm_qs.exists():
|
|
|
+ return []
|
|
|
+ return list(algorithm_qs)
|
|
|
+
|
|
|
@classmethod
|
|
|
def get_scenario_list(cls, request_dist, response):
|
|
|
+ """
|
|
|
+ 获取应用场景列表
|
|
|
+ @param request_dist: lang
|
|
|
+ @param response: 响应结果
|
|
|
+ @return: 应用场景列表
|
|
|
+ """
|
|
|
try:
|
|
|
lang = request_dist.get('lang', 'en')
|
|
|
if not lang:
|
|
@@ -145,18 +169,35 @@ class AlgorithmShopView(View):
|
|
|
# 根据应用场景id查询关联算法类型数据
|
|
|
# scenario_vo['algorithmList'] = cls.get_algorithm_list_by_scenario_id(item['id'], lang)
|
|
|
scenario_list.append(scenario_vo)
|
|
|
- return response.json(0, scenario_list)
|
|
|
+ # 获取所有算法图标地址以及算法名称
|
|
|
+ algorithm_qs = DeviceAlgorithmExplain.objects.filter(lang=lang).order_by('algorithm_type__sort') \
|
|
|
+ .annotate(algorithmId=F('algorithm_type__id'), algorithmType=F('algorithm_type__type'),
|
|
|
+ iconUrl=F('algorithm_type__icon_url'),
|
|
|
+ algorithmName=F('title')).values('algorithmId', 'algorithmType', 'iconUrl', 'algorithmName')
|
|
|
+ result_dto = {'scenarioList': scenario_list, 'scenarioUrl': ''}
|
|
|
+ if algorithm_qs.exists():
|
|
|
+ result_dto['iconList'] = list(algorithm_qs)
|
|
|
+ return response.json(0, result_dto)
|
|
|
except Exception as e:
|
|
|
LOGGER.info('接口异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- return response.json(177, repr(e))
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
@classmethod
|
|
|
def get_scenario_algorithm_list(cls, request_dist, response):
|
|
|
+ """
|
|
|
+ 获取应用场景关联算法列表
|
|
|
+ @param request_dist: scenarioId、lang
|
|
|
+ @param response: 响应结果
|
|
|
+ @return: 算法列表
|
|
|
+ """
|
|
|
scenario_id = request_dist.get('scenarioId', None)
|
|
|
lang = request_dist.get('lang', 'en')
|
|
|
+ result_dto = {'scenarioBannerUrl': ''}
|
|
|
if not scenario_id:
|
|
|
- return response.json(444)
|
|
|
- return response.json(0, cls.get_algorithm_list_by_scenario_id(scenario_id, lang))
|
|
|
+ result_dto['algorithmList'] = cls.get_algorithm_list(lang)
|
|
|
+ return response.json(0, result_dto)
|
|
|
+ result_dto['algorithmList'] = cls.get_algorithm_list_by_scenario_id(scenario_id, lang)
|
|
|
+ return response.json(0, result_dto)
|
|
|
|
|
|
@classmethod
|
|
|
def get_algorithm_banner(cls, response):
|
|
@@ -212,7 +253,7 @@ class AlgorithmShopView(View):
|
|
|
return response.json(0, algorithm_list)
|
|
|
except Exception as e:
|
|
|
print('查询算法小店列表异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- return response.json(177, repr(e))
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
@classmethod
|
|
|
def get_algorithm_details(cls, request_dict, response):
|