TaskHandler.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from handlers.HandlerBase import BaseHandler
  2. from model import DingTalkUtils
  3. import os
  4. from model.DataBaseUtils import MysqlUtils
  5. from model.DateUtils import DateUtils
  6. class SrcBookInfo(BaseHandler):
  7. def get(self):
  8. db = MysqlUtils()
  9. du = DateUtils()
  10. sql = """SELECT date_format(a.effect_day,'%Y-%m-%d'),
  11. case a.type when 'mp' then 'MP' when 'gdt' then 'GDT' end type,
  12. b.book_name,c.platform_name,a.node_price from t_platform_book_ratio a
  13. left join t_platform_book b on a.platform_book_id=b.id
  14. left join t_platform_novel c on b.platform_id=c.id order by a.effect_day"""
  15. data = db.zx.getData(sql)
  16. di = {}
  17. for i in data:
  18. thedate = i[0]
  19. while True:
  20. if thedate > du.get_n_days(0):
  21. break
  22. else:
  23. di[thedate + ',' + i[1] + ',' + i[2] + ',' + i[3]] = i[4]
  24. thedate = du.add_days(thedate, 1)
  25. li = []
  26. for i, j in di.items():
  27. li.append(i.split(',') + [j])
  28. db.dm.execute("truncate table src_book_info")
  29. db.dm.executeMany("insert into src_book_info values (%s,%s,%s,%s,%s)", li)
  30. print('src_book_info success')
  31. self.write('ok')