sync_publish_time_hy.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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!=null){
  34. if(data.rows==null||data.rows==undefined){
  35. data = null
  36. }
  37. }
  38. if(data!=null){
  39. if(data.rows.length<=0){
  40. data = null
  41. }
  42. }
  43. if(data!=null){
  44. let publish_time = data.rows[0].openTime
  45. if(publish_time==undefined){
  46. publish_time = data.rows[0].createTime
  47. }
  48. await connection.execute(
  49. `UPDATE video_product SET publish_time = "${publish_time}" WHERE id = ${video_product_info.id} `
  50. );
  51. }else{
  52. await connection.execute(
  53. ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id} `
  54. );
  55. console.error("查无此书:",video_product_info)
  56. }
  57. }
  58. }catch(e){
  59. if(e==0){
  60. right_status = false
  61. }
  62. console.error("processTask error:",e)
  63. } finally{
  64. if(connection!=null){
  65. connection.end()
  66. }
  67. global.setTimeout(processTask, 2000);
  68. }
  69. }
  70. CMD.init = async function(){
  71. redis_help.connect((results)=>{
  72. if(results){
  73. processTask();
  74. }
  75. })
  76. }
  77. CMD.init()