sync_publish_time_fq_mf.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 CMD = {}
  7. async function processTask(){
  8. let right_status = true
  9. let connection = null
  10. try{
  11. connection = await mysql.createConnection({
  12. ...taskdbConfig,
  13. multipleStatements: true
  14. });
  15. //先获取100本没有发布时间的番茄免费书籍
  16. let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_fanqiemf} AND publish_time IS NULL LIMIT 500`
  17. console.log("sql:",sql)
  18. const [rows] = await connection.execute(
  19. sql
  20. );
  21. if(rows.length<=0){
  22. throw 0
  23. }
  24. for (let index = 0; index < rows.length; index++) {
  25. let video_product_info = rows[index]
  26. let data = await require('../src/api/fq/fq_search_book').search_mf_new_id(video_product_info.product_id)
  27. if(data==""){
  28. console.error("接口失效")
  29. }else{
  30. if(data!=null){
  31. let publish_time = data.on_shelf_time
  32. await connection.execute(
  33. `UPDATE video_product SET publish_time = "${publish_time}" WHERE id = ${video_product_info.id} `
  34. );
  35. }else{
  36. console.error("查无此书:",video_product_info)
  37. await connection.execute(
  38. ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  39. );
  40. }
  41. }
  42. }
  43. }catch(e){
  44. if(e==0){
  45. right_status = false
  46. }
  47. console.error("processTask error:",e)
  48. } finally{
  49. if(connection!=null){
  50. connection.end()
  51. }
  52. global.setTimeout(processTask, 2000);
  53. }
  54. }
  55. CMD.init = async function(){
  56. redis_help.connect((results)=>{
  57. if(results){
  58. processTask();
  59. }
  60. })
  61. }
  62. CMD.init()