From 34ee45b8b0f7a99c52c76e2731452f42e09c29d8 Mon Sep 17 00:00:00 2001 From: pengtao Date: Thu, 25 Jul 2019 15:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BD=8D=E7=BD=AE=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ad_interface_tornado.py | 14 ++++++++------ handler/ad.py | 13 ++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ad_interface_tornado.py b/ad_interface_tornado.py index 7a572ea..f0cc1bd 100644 --- a/ad_interface_tornado.py +++ b/ad_interface_tornado.py @@ -29,7 +29,7 @@ def send_cache_data(): all = [] # 添加无天数限定的记录 get_full_data = f"""select a.id,a.name,a.ad_num,a.ad_title,a.ad_body,a.ad_image,a.jump_param,a.ad_sort," \ - f"a.companyid,a.gameid,a.jump_status,b.area,b.type,b.mode from ad a,location b where \ + f"a.companyid,a.gameid,a.channelid,a.jump_status,b.area,b.type,b.mode,b.id from ad a,location b where \ a.locationid=b.id AND begin_time='{BEGIN}' or end_time='{END}'""" full_data = mydb.query(get_full_data) @@ -40,15 +40,15 @@ def send_cache_data(): item = {} try: item['id'], item['name'], item['ad_num'], item['ad_title'], item['ad_body'], item['ad_image'], item[ - 'jump_param'], item['ad_sort'], item['companyid'], item['gameid'], item['jump_status'], item[ - 'area'], item['type'], item['mode'] = line + 'jump_param'], item['ad_sort'], item['companyid'], item['gameid'], item['channelid'], item[ + 'jump_status'], item['area'], item['type'], item['mode'], item['locationid'] = line all.append(item) except Exception: log.error("split data failed", exc_info=True) # 添加有天数限定的记录 get_data_sql = f"""select a.id,a.name,a.ad_num,a.ad_title,a.ad_body,a.ad_image,a.jump_param,\ - a.ad_sort,a.companyid,a.gameid,a.jump_status,b.area,b.type,b.mode from ad a ,location b \ + a.ad_sort,a.companyid,a.gameid,a.channelid,a.jump_status,b.area,b.type,b.mode,b.id from ad a ,location b \ where'{now}'>a.begin_time and '{now}' 0: num = my_redis.get(f"ad::{line['id']}::num") diff --git a/handler/ad.py b/handler/ad.py index f34f8f6..3b56a25 100644 --- a/handler/ad.py +++ b/handler/ad.py @@ -24,6 +24,7 @@ log = logging.getLogger(__name__) parser = reqparse.RequestParser() parser.add_argument('id') parser.add_argument('gameid') +parser.add_argument('channelid') parser.add_argument('name') parser.add_argument('locationid') parser.add_argument('begin_time') @@ -55,16 +56,16 @@ class Ad(Resource): if not id: if companyid: sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,jump_param,ad_sort," \ - f"status,companyid,locationid,gameid,jump_status from ad where companyid={companyid};" + f"status,companyid,locationid,gameid,channelid,jump_status from ad where companyid={companyid};" elif status or status == 0: sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,jump_param,ad_sort," \ - f"status,companyid,locationid,gameid,jump_status from ad where status={status};" + f"status,companyid,locationid,gameid,channelid,jump_status from ad where status={status};" else: sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,jump_param,ad_sort," \ - f"status,companyid,locationid,gameid,jump_status from ad ;" + f"status,companyid,locationid,gameid,channelid,jump_status from ad ;" else: sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,jump_param,ad_sort," \ - f"status,companyid,locationid,gameid,jump_status from ad where id={id};" + f"status,companyid,locationid,gameid,channelid,jump_status from ad where id={id};" data = self.mydb.query(sel_sql) log.info(f"sql={sel_sql},data={data}") if data: @@ -75,7 +76,7 @@ class Ad(Resource): ad_info['id'], ad_info['name'], ad_info['begin_time'], ad_info['end_time'], ad_info['ad_num'], \ ad_info['ad_title'], ad_info['ad_body'], ad_info['ad_image'], ad_info['jump_param'], ad_info[ 'ad_sort'], ad_info['status'], ad_info['companyid'], ad_info['locationid'], ad_info[ - 'gameid'],ad_info['jump_status'] = line + 'gameid'],ad_info['channelid'],ad_info['jump_status'] = line all.append(ad_info) return jsonify({'code': 200, 'message': all}) except Exception: @@ -90,6 +91,7 @@ class Ad(Resource): ad['id'] = id ad['name'] = self.args['name'] ad['gameid'] = self.args['gameid'] + ad['channelid'] = self.args['channelid'] ad['locationid'] = self.args['locationid'] ad['begin_time'] = self.args['begin_time'] or '1999-01-01' ad['end_time'] = self.args['end_time'] or '3000-01-01' @@ -140,6 +142,7 @@ class Ad(Resource): ad['id'] = self.args['id'] ad['name'] = self.args['name'] ad['gameid'] = self.args['gameid'] + ad['channelid'] = self.args['channelid'] ad['locationid'] = self.args['locationid'] ad['begin_time'] = self.args['begin_time'] or '1999-01-01' ad['end_time'] = self.args['end_time'] or '3000-01-01'