sync_publish_time_fq_mf.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 5`
  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 data = await require('../src/api/fq/fq_search_book').search_mf_new_id(video_product_info.product_id)
  29. if(data!=null){
  30. await connection.execute(
  31. `UPDATE video_product SET publish_time = ? WHERE id = ${video_product_info.id} `,[data.publish_time]
  32. );
  33. }else{
  34. await connection.execute(
  35. ` UPDATE video_product SET publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  36. );
  37. console.error("查无此书:",video_product_info)
  38. }
  39. // if(video_product_info.product_parent_id==video_product_info.product_id){
  40. // await connection.execute(
  41. // ` UPDATE video_product SET publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  42. // );
  43. // }else{
  44. // let book_info = await video_product_controllers.getProductData({book_id:video_product_info.product_parent_id})
  45. // if(book_info.success){
  46. // if(book_info.data.publish_time!=null){
  47. // let publish_time = helper.getDate7DaysBefore(book_info.data.publish_time,null,'YYYY-MM-DD')
  48. // await connection.execute(
  49. // `UPDATE video_product SET publish_time = ? WHERE id = ${video_product_info.id} `,[publish_time]
  50. // );
  51. // }
  52. // }else{
  53. // //添加到番茄付费里
  54. // let data = await require('../src/api/fq/fq_search_book').search_new_id(video_product_info.product_parent_id)
  55. // if(data!=null){
  56. // let publish_time = data.publish_time
  57. // let words = data.words
  58. // let book_name = data.book_name;
  59. // let author = data.author
  60. // let genre = 1
  61. // if(words>100000){
  62. // genre = 1;
  63. // }else{
  64. // genre = 3;
  65. // }
  66. // await CMD.insert_product({
  67. // tg_platform_id:config.platform_fanqie,
  68. // book_name:book_name,
  69. // genre:genre,
  70. // book_id:video_product_info.product_parent_id,
  71. // words:words,
  72. // publish_time:publish_time,
  73. // author:author
  74. // })
  75. // }else{
  76. // console.error("没找父书:",video_product_info.product_parent_id)
  77. // await connection.execute(
  78. // ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  79. // );
  80. // console.error("查无此书:",video_product_info)
  81. // }
  82. // }
  83. // }
  84. }
  85. }catch(e){
  86. if(e==0){
  87. right_status = false
  88. }
  89. console.error("processTask error:",e)
  90. } finally{
  91. if(connection!=null){
  92. connection.end()
  93. }
  94. global.setTimeout(processTask, 2000);
  95. }
  96. }
  97. CMD.insert_product = async function(data){
  98. await video_product_controllers.createProductData({
  99. book_platform:data.tg_platform_id,
  100. product_name:data.book_name,
  101. genre:data.genre,
  102. product_id:data.book_id,
  103. words:data.words,
  104. publish_time:data.publish_time,
  105. author:data.author
  106. })
  107. }
  108. CMD.init = async function(){
  109. redis_help.connect((results)=>{
  110. if(results){
  111. processTask();
  112. }
  113. })
  114. }
  115. CMD.init()