from dspt_api.util.general.handle_redis import get_data_from_redis from django_redis import get_redis_connection import random class ApiPlayInfo: def __init__(self, **kwargs): self.member_type = kwargs.get('member_type') self.api = kwargs.get('api') self.ip = kwargs.get('ip') self.env = kwargs.get('env') self.cid = kwargs.get('cid') self.pid = kwargs.get('pid') def get_suggestion(self): # play_id request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}' result, _format, play_data, _timestamp = get_data_from_redis(redis_key_api) if result: play_id = play_data['id'] return [{'param': 'play_id', 'value': play_id, 'is_checked': True, 'result': True, 'timestamp': _timestamp}] else: # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 return [ {'param': 'play_id', 'value': play_data + request_api["name"], 'is_checked': True, 'result': True, 'timestamp': _timestamp}] def get_timestamp(self): # play_id request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}' result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api) return _timestamp if result else 0