sync_publish_time_hy.js 2.4 KB

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