AppSetController.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: AnsjerFormal
  7. @software: PyCharm
  8. @DATE: 2020/2/27 9:38
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: AppSetController.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. from Model.models import versionControlModel
  15. from django.views.generic.base import View
  16. from cacheout import LFUCache
  17. import time,json
  18. from Object.ResponseObject import ResponseObject
  19. cache = LFUCache()
  20. class AppSetView(View):
  21. def get(self, request, *args, **kwargs):
  22. request.encoding = 'utf-8'
  23. operation = kwargs.get('operation', None)
  24. return self.validation(request.GET, operation)
  25. def post(self, request, *args, **kwargs):
  26. request.encoding = 'utf-8'
  27. operation = kwargs.get('operation', None)
  28. return self.validation(request.POST, operation)
  29. def validation(self, request_dict, operation):
  30. response = ResponseObject()
  31. # token = request_dict.get('token', None)
  32. # tko = TokenObject(token)
  33. # userID = tko.userID
  34. if operation == 'query':
  35. return self.do_query(request_dict, response)
  36. else:
  37. return response.json(414)
  38. # 查询
  39. def do_query(self, request_dict, response):
  40. appBundleId = request_dict.get('appBundleId', None)
  41. if not appBundleId:
  42. return response.json(444,'appBundleId')
  43. if cache.get(appBundleId)==None:
  44. print('添加到缓存')
  45. # 查数据库
  46. sm_qs = versionControlModel.objects.filter(appBundleId=appBundleId)
  47. count = sm_qs.count()
  48. if count > 0:
  49. sm_qs = sm_qs.values( 'id', 'appBundleId', 'content', 'addTime', 'updTime')
  50. # 添加到缓存,缓存时间为3600秒------指的是一个钟后再次访问,就会刷新缓存一次
  51. cache.set(appBundleId, {'content': list(sm_qs)}, ttl=3600)
  52. # return response.json(0,list(sm_qs))
  53. # 返回固定值
  54. return response.json(0, json.loads(list(sm_qs)[0]['content']))
  55. else:
  56. return response.json(0)
  57. else:
  58. # print('去缓存找')
  59. # return response.json(0, cache.get(appBundleId).get('content'))
  60. # 返回固定值
  61. return response.json(0, json.loads(cache.get(appBundleId).get('content')[0]['content']))
  62. # res = {}
  63. # res['grade'] = 1
  64. # # # 用户帮助
  65. # res['usingHelp'] = 0
  66. # # # AP添加方式
  67. # res['apAdd'] = 1
  68. # # # AP工具
  69. # res['apTool'] = 1
  70. # # # 广告模块
  71. # res['ad_module'] = {
  72. # "time": 0,
  73. # "ad_path": [
  74. # "https://test.dvema.com/web/static/image/default_ad1",
  75. # "https://test.dvema.com/web/static/image/default_ad2",
  76. # "https://test.dvema.com/web/static/image/default_ad3",
  77. # ]
  78. # }
  79. # res['init_img'] = 'https://test.dvema.com/web/static/image/default_start'
  80. # return response.json(0, res)