sync_publish_time_hy.js 2.5 KB

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