sync_publish_time_fq_mf.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //同步番茄免费的发布时间
  2. const config = require("../etc/config.json");
  3. const mysql = require('mysql2/promise');
  4. const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
  5. const redis_help = require('../src/use_redis');
  6. const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
  7. const helper = require("../src/helper");
  8. const CMD = {}
  9. async function processTask(){
  10. let right_status = true
  11. let connection = null
  12. try{
  13. connection = await mysql.createConnection({
  14. ...taskdbConfig,
  15. multipleStatements: true
  16. });
  17. //先获取100本没有发布时间的番茄免费书籍
  18. let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_fanqiemf} AND product_parent_id !="" AND publish_time IS NULL LIMIT 500`
  19. console.log("sql:",sql)
  20. const [rows] = await connection.execute(
  21. sql
  22. );
  23. if(rows.length<=0){
  24. throw 0
  25. }
  26. for (let index = 0; index < rows.length; index++) {
  27. let video_product_info = rows[index]
  28. let book_info = await video_product_controllers.getProductData({book_id:video_product_info.product_parent_id})
  29. if(book_info.success){
  30. if(book_info.data.publish_time!=null){
  31. let publish_time = helper.getDate7DaysBefore(book_info.data.publish_time,null,'YYYY-MM-DD')
  32. await connection.execute(
  33. `UPDATE video_product SET publish_time = ${publish_time} WHERE id = ${video_product_info.id} `
  34. );
  35. }
  36. }
  37. }
  38. }catch(e){
  39. if(e==0){
  40. right_status = false
  41. }
  42. console.error("processTask error:",e)
  43. } finally{
  44. if(connection!=null){
  45. connection.end()
  46. }
  47. global.setTimeout(processTask, 2000);
  48. }
  49. }
  50. CMD.init = async function(){
  51. redis_help.connect((results)=>{
  52. if(results){
  53. processTask();
  54. }
  55. })
  56. }
  57. CMD.init()