from handlers.HandlerBase import BaseHandler from model import DingTalkUtils import os from model.DataBaseUtils import MysqlUtils from model.DateUtils import DateUtils class SrcBookInfo(BaseHandler): def get(self): db = MysqlUtils() du = DateUtils() sql = """SELECT date_format(a.effect_day,'%Y-%m-%d'), case a.type when 'mp' then 'MP' when 'gdt' then 'GDT' end type, b.book_name,c.platform_name,a.node_price from t_platform_book_ratio a left join t_platform_book b on a.platform_book_id=b.id left join t_platform_novel c on b.platform_id=c.id order by a.effect_day""" data = db.zx.getData(sql) di = {} for i in data: thedate = i[0] while True: if thedate > du.get_n_days(0): break else: di[thedate + ',' + i[1] + ',' + i[2] + ',' + i[3]] = i[4] thedate = du.add_days(thedate, 1) li = [] for i, j in di.items(): li.append(i.split(',') + [j]) db.dm.execute("truncate table src_book_info") db.dm.executeMany("insert into src_book_info values (%s,%s,%s,%s,%s)", li) print('src_book_info success') self.write('ok')