diff --git a/dspt_api/util/api/seat_lock.py b/dspt_api/util/api/seat_lock.py index ab66c73..27b8d4a 100644 --- a/dspt_api/util/api/seat_lock.py +++ b/dspt_api/util/api/seat_lock.py @@ -8,22 +8,48 @@ class ApiSeatLock: self.api = kwargs.get('api') self.ip = kwargs.get('ip') - # def get_suggestion(self): - # # play_id - # request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} - # redis_key_api_play = f'dspt_api_{self.ip}_{self.member_type}_{request_api_play["path"]}' - # result_play, _format_play, redis_data_play = get_data_from_redis(redis_key_api_play) - # # seat_id - # request_api_seat = {'name': '3.1.8 获取某场次座位状态', 'path': 'play/seat-status'} - # redis_key_api_seat = f'dspt_api_{self.ip}_{self.member_type}_{request_api_seat["path"]}' - # result_seat, _format_seat, redis_data_seat = get_data_from_redis(redis_key_api_seat) - # if result: - # play_data = random.choice(redis_data) - # play_id = play_data['id'] - # return [{'param': 'play_id', 'value': play_id, 'is_checked': True, 'result': True}] - # else: - # # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 - # return [ - # {'param': 'play_id', 'value': redis_data + request_api["name"], 'is_checked': True, 'result': True}] - + def get_suggestion(self): + # play_id + request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} + redis_key_api_play = f'dspt_api_{self.ip}_{self.member_type}_{request_api_play["path"]}' + result_play, _format_play, redis_data_play, _timestamp_play = get_data_from_redis(redis_key_api_play) + # seat_id + request_api_seat = {'name': '3.1.8 获取某场次座位状态', 'path': 'play/seat-status'} + redis_key_api_seat = f'dspt_api_{self.ip}_{self.member_type}_{request_api_seat["path"]}' + result_seat, _format_seat, redis_data_seat, _timestamp_seat = get_data_from_redis(redis_key_api_seat) + if result_play and result_seat: + play_data = random.choice(redis_data_play) + seat_data = random.choice(redis_data_seat) + seat_id = '' + if isinstance(seat_data, dict): + seat_id = seat_data['cineSeatId'] + if isinstance(seat_data, list): + seat_id = ','.join([seat['cineSeatId'] for seat in seat_data]) + return [{'param': 'play_id', 'value': play_data['id'], 'is_checked': True, 'result': True}, + {'param': 'play_update_time', 'value': play_data['cineUpdateTime'], 'is_checked': True, + 'result': True}, + {'param': 'seat_id', 'value': seat_id, 'is_checked': True, 'result': True}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'play_id', 'value': redis_data_play + request_api_play["name"], 'is_checked': True, + 'result': True}, + {'param': 'play_update_time', 'value': redis_data_play + request_api_play["name"], 'is_checked': True, + 'result': True}, + {'param': 'seat_id', 'value': redis_data_seat + request_api_seat["name"], 'is_checked': True, + 'result': True} + ] + def get_timestamp(self): + # play_id + request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'} + redis_key_api_play = f'dspt_api_{self.ip}_{self.member_type}_{request_api_play["path"]}' + result_play, _format_play, redis_data_play, _timestamp_play = get_data_from_redis(redis_key_api_play) + # seat_id + request_api_seat = {'name': '3.1.8 获取某场次座位状态', 'path': 'play/seat-status'} + redis_key_api_seat = f'dspt_api_{self.ip}_{self.member_type}_{request_api_seat["path"]}' + result_seat, _format_seat, redis_data_seat, _timestamp_seat = get_data_from_redis(redis_key_api_seat) + # 处理混合结果 + if result_play and result_seat: + return _timestamp_play if _timestamp_play > _timestamp_seat else _timestamp_seat + return 0 diff --git a/dspt_api/util/random_params.py b/dspt_api/util/random_params.py index da7bdf8..264d2ce 100644 --- a/dspt_api/util/random_params.py +++ b/dspt_api/util/random_params.py @@ -4,18 +4,36 @@ import time from django_redis import get_redis_connection +RANDOM_DATA_API_LIST = ['cinema/plays', 'play/seat-status'] + def random_params(_user_info, _handle_data): - print('_user_info', _user_info) - print('_handle_data', _handle_data) - redis_key_api = f'dspt_api_{_user_info["user_ip"]}_{_user_info["member_type"]}_{_user_info["api"]}_random' - redis_conn = get_redis_connection() - if redis_conn.get(redis_key_api): - redis_conn.delete(redis_key_api) - data = { - 'api': _user_info["api"], - 'member_type': _user_info["member_type"], - 'format': _user_info["format"], - 'timestamp': int(time.time()*1000), - 'user_data': [random.choice(_handle_data['res']['data'])], - } - redis_conn.set(redis_key_api, json.dumps(data)) + if _user_info["api"] in RANDOM_DATA_API_LIST: + print('_user_info', _user_info) + print('_handle_data', _handle_data) + redis_key_api = f'dspt_api_{_user_info["user_ip"]}_{_user_info["member_type"]}_{_user_info["api"]}_random' + redis_conn = get_redis_connection() + if redis_conn.get(redis_key_api): + redis_conn.delete(redis_key_api) + data = { + 'api': _user_info["api"], + 'member_type': _user_info["member_type"], + 'format': _user_info["format"], + 'timestamp': int(time.time()*1000), + } + if _user_info["api"] == 'play/seat-status': + _user_data = get_ok_status_seat_list(_handle_data['res']['data']) + else: + _user_data = _handle_data['res']['data'] + if len(_user_data) > 0: + data['user_data'] = [random.choice(_user_data)] + redis_conn.set(redis_key_api, json.dumps(data)) + else: + redis_conn.delete(redis_key_api) + + +def get_ok_status_seat_list(_data): + seat_list = [] + for s in _data: + if s['seatStatus'] == 'ok' and s['type'] in ['danren', 'zhendong', 'vip']: + seat_list.append(s) + return seat_list diff --git a/dspt_api/util/suggest_params.py b/dspt_api/util/suggest_params.py index 353c41b..25d1295 100644 --- a/dspt_api/util/suggest_params.py +++ b/dspt_api/util/suggest_params.py @@ -5,6 +5,7 @@ from dspt_api.util.api.play_seat_status import ApiPlaySeatStatus from dspt_api.util.api.play_period_changed_seats import ApiPlayPeriodChangedSeats from dspt_api.util.api.play_seat_overview import ApiPlaySeatOverview from dspt_api.util.api.cinema_goods_pic import ApiCinemaGoodsPic +from dspt_api.util.api.seat_lock import ApiSeatLock # 通过api来匹配不同的接口文件获取推荐 @@ -34,6 +35,9 @@ def suggest_params(member_type, api, ip): if api == 'cinema/goods-pic' and member_type == 'nonmember': print('cinema/goods-pic') params = ApiCinemaGoodsPic(**data).get_suggestion() + if api == 'seat/lock' and member_type == 'nonmember': + print('seat/lock') + params = ApiSeatLock(**data).get_suggestion() return params def suggest_params_timestamp(member_type, api, ip): @@ -61,4 +65,7 @@ def suggest_params_timestamp(member_type, api, ip): if api == 'cinema/goods-pic' and member_type == 'nonmember': print('cinema/goods-pic') _timestamps = ApiCinemaGoodsPic(**data).get_timestamp() + if api == 'seat/lock' and member_type == 'nonmember': + print('seat/lock') + _timestamps = ApiSeatLock(**data).get_timestamp() return _timestamps \ No newline at end of file