|
@@ -7,6 +7,7 @@ import time
|
|
|
import traceback
|
|
|
|
|
|
from django.core import serializers
|
|
|
+from django.db import models
|
|
|
from django.http import HttpResponse
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
@@ -20,7 +21,7 @@ from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from var_dump import var_dump
|
|
|
-
|
|
|
+from Ansjer.config import LOGGER
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.ModelService import ModelService, ZositechHelpModel
|
|
|
|
|
@@ -71,9 +72,9 @@ class FAQUploadView(View):
|
|
|
index = file_name.find('static/')
|
|
|
filePath = file_name[index:]
|
|
|
if SERVER_TYPE == "Ansjer.formal_settings":
|
|
|
- filePath = SERVER_DOMAIN+'faq/image/' + filePath
|
|
|
+ filePath = SERVER_DOMAIN + 'faq/image/' + filePath
|
|
|
else:
|
|
|
- filePath = SERVER_DOMAIN_SSL+'faq/image/' + filePath
|
|
|
+ filePath = SERVER_DOMAIN_SSL + 'faq/image/' + filePath
|
|
|
return response.json(0, {'filePath': filePath})
|
|
|
|
|
|
# redis中没有对应的图片信息
|
|
@@ -351,7 +352,7 @@ class FAQView(View):
|
|
|
|
|
|
def do_synZositechHelp(self, request_dict, response):
|
|
|
zhresults = request_dict.get('zhresults', None).replace("\'", "XX??????XX")
|
|
|
- #.replace("\"", "XX??????XX").replace("\'", "\"").replace("XX??????XX", "\'")
|
|
|
+ # .replace("\"", "XX??????XX").replace("\'", "\"").replace("XX??????XX", "\'")
|
|
|
zhresults = json.loads(zhresults)
|
|
|
|
|
|
enresults = request_dict.get('enresults', None).replace("\'", "XX??????XX")
|
|
@@ -391,6 +392,7 @@ class FAQView(View):
|
|
|
})
|
|
|
return response.json(0)
|
|
|
|
|
|
+
|
|
|
class HelpLinkView(View):
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
@@ -417,48 +419,56 @@ class HelpLinkView(View):
|
|
|
@staticmethod
|
|
|
def query_faq_by_device_type(request, request_dict, response):
|
|
|
"""根据设备类型和语言查询帮助链接"""
|
|
|
- device_type = request_dict.get('device_type')
|
|
|
- lang = request_dict.get('lang')
|
|
|
-
|
|
|
- if not device_type or not lang:
|
|
|
+ device_type = request_dict.get('device_type', None)
|
|
|
+ # lang = request_dict.get('lang', 'en')
|
|
|
+ # app_bundle_id = request_dict.get('app_bundle_id', None)
|
|
|
+ lang = 'en'
|
|
|
+
|
|
|
+ if not device_type:
|
|
|
return response.json(444, {'message': 'device_type和lang参数不能为空'})
|
|
|
-
|
|
|
+
|
|
|
try:
|
|
|
+ device_type = int(device_type)
|
|
|
redis = RedisObject()
|
|
|
cache_key = RedisKeyConstant.HELP_LINK_TYPE.value + f'{device_type}:{lang}'
|
|
|
-
|
|
|
+
|
|
|
# 先尝试从缓存获取
|
|
|
cached_data = redis.get_data(cache_key)
|
|
|
if cached_data:
|
|
|
cached_data = json.loads(cached_data)
|
|
|
return response.json(0, cached_data)
|
|
|
-
|
|
|
- # 查询匹配的帮助链接
|
|
|
+
|
|
|
+ # 优化数据库查询 - 单次查询获取结果
|
|
|
help_link = HelpLink.objects.filter(
|
|
|
- device_type=device_type,
|
|
|
+ models.Q(device_type=device_type) | models.Q(device_type=-1),
|
|
|
lang=lang,
|
|
|
is_active=True
|
|
|
+ ).order_by(
|
|
|
+ models.Case(
|
|
|
+ models.When(device_type=device_type, then=0),
|
|
|
+ default=1
|
|
|
+ )
|
|
|
).first()
|
|
|
-
|
|
|
+
|
|
|
if not help_link:
|
|
|
return response.json(173)
|
|
|
-
|
|
|
+
|
|
|
# 构建返回数据
|
|
|
data = {
|
|
|
'url': help_link.url,
|
|
|
'title': help_link.title,
|
|
|
'description': help_link.description
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
# 设置缓存,过期时间30天
|
|
|
try:
|
|
|
redis.set_data(cache_key, json.dumps(data), RedisKeyConstant.EXPIRE_TIME_30_DAYS.value)
|
|
|
except Exception as e:
|
|
|
- print(f"设置Redis缓存出错: {str(e)}")
|
|
|
+ LOGGER.error(f"设置Redis缓存出错: {repr(e)}")
|
|
|
# 缓存失败不影响主流程
|
|
|
-
|
|
|
+
|
|
|
return response.json(0, data)
|
|
|
-
|
|
|
+
|
|
|
except Exception as e:
|
|
|
- print(f"查询帮助链接出错: {str(e)}")
|
|
|
- return response.json(500, {'message': '服务器内部错误'})
|
|
|
+ LOGGER.error(f"查询帮助链接出错: {repr(e)}")
|
|
|
+ return response.json(500)
|