123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
- @AUTHOR: ASJRD018
- @NAME: AnsjerFormal
- @software: PyCharm
- @DATE: 2020/2/27 9:38
- @Version: python3.6
- @MODIFY DECORD:ansjer dev
- @file: AppSetController.py
- @Contact: chanjunkai@163.com
- """
- from Model.models import versionControlModel
- from django.views.generic.base import View
- from cacheout import LFUCache
- import time,json
- from Object.ResponseObject import ResponseObject
- cache = LFUCache()
- class AppSetView(View):
- def get(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation', None)
- return self.validation(request.GET, operation)
- def post(self, request, *args, **kwargs):
- request.encoding = 'utf-8'
- operation = kwargs.get('operation', None)
- return self.validation(request.POST, operation)
- def validation(self, request_dict, operation):
- response = ResponseObject()
- # token = request_dict.get('token', None)
- # tko = TokenObject(token)
- # userID = tko.userID
- if operation == 'query':
- return self.do_query(request_dict, response)
- else:
- return response.json(414)
- # 查询
- def do_query(self, request_dict, response):
- appBundleId = request_dict.get('appBundleId', None)
- if not appBundleId:
- return response.json(444,'appBundleId')
- if cache.get(appBundleId)==None:
- print('添加到缓存')
- # 查数据库
- sm_qs = versionControlModel.objects.filter(appBundleId=appBundleId)
- count = sm_qs.count()
- if count > 0:
- sm_qs = sm_qs.values( 'id', 'appBundleId', 'content', 'addTime', 'updTime')
- # 添加到缓存,缓存时间为3600秒------指的是一个钟后再次访问,就会刷新缓存一次
- cache.set(appBundleId, {'content': list(sm_qs)}, ttl=3600)
- # return response.json(0,list(sm_qs))
- # 返回固定值
- return response.json(0, json.loads(list(sm_qs)[0]['content']))
- else:
- return response.json(0)
- else:
- # print('去缓存找')
- # return response.json(0, cache.get(appBundleId).get('content'))
- # 返回固定值
- return response.json(0, json.loads(cache.get(appBundleId).get('content')[0]['content']))
- # res = {}
- # res['grade'] = 1
- # # # 用户帮助
- # res['usingHelp'] = 0
- # # # AP添加方式
- # res['apAdd'] = 1
- # # # AP工具
- # res['apTool'] = 1
- # # # 广告模块
- # res['ad_module'] = {
- # "time": 0,
- # "ad_path": [
- # "https://test.dvema.com/web/static/image/default_ad1",
- # "https://test.dvema.com/web/static/image/default_ad2",
- # "https://test.dvema.com/web/static/image/default_ad3",
- # ]
- # }
- # res['init_img'] = 'https://test.dvema.com/web/static/image/default_start'
- # return response.json(0, res)
|