sync_publish_time_hy_mf.js 2.5 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 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_heiyanmf} AND publish_time IS NULL LIMIT 500`
  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 =
  29. // console.log("data:",data)
  30. let data = await CMD.search_parent_id(connection,video_product_info.product_parent_id)
  31. if(data!=null){
  32. let publish_time = helper.getDate7DaysBefore(data.publish_time,null,'YYYY-MM-DD')
  33. await connection.execute(
  34. `UPDATE video_product SET publish_time = "${publish_time}" WHERE id = ${video_product_info.id} `
  35. );
  36. }else{
  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. console.error("查无此书:",video_product_info)
  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.search_parent_id = async function(connection,product_parent_id) {
  56. let sql = `SELECT * FROM video_product WHERE product_id = '${product_parent_id}' LIMIT 1`
  57. const [rows] = await connection.execute(
  58. sql
  59. );
  60. if(rows.length<=0){
  61. return null
  62. }
  63. return rows[0]
  64. }
  65. CMD.init = async function(){
  66. redis_help.connect((results)=>{
  67. if(results){
  68. processTask();
  69. }
  70. })
  71. }
  72. CMD.init()