async_start_chapter.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // const video_product_controllers = require('./src/data_manager/Controllers/video_product_controllers');
  2. const config = require("./etc/config.json")
  3. const redis_help = require('./src/use_redis');
  4. const mysql = require('mysql2/promise');
  5. const tools = require('./tools');
  6. const TaskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
  7. const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
  8. const CMD = {}
  9. async function processTask(){
  10. let connection = null
  11. let connection2 = null
  12. try{
  13. connection = await mysql.createConnection({
  14. ...TaskdbConfig,
  15. multipleStatements: true
  16. });
  17. connection2 = await mysql.createConnection({
  18. ...dbConfig,
  19. multipleStatements: true
  20. });
  21. let [rows] = await connection.execute('SELECT * FROM video_product WHERE publish_time IS NULL LIMIT 100')
  22. if(rows.length>0){
  23. for (let index = 0; index < rows.length; index++) {
  24. const element = rows[index];
  25. let [info] = await connection2.execute(`SELECT * FROM fq_dj_lib WHERE book_id = ${element.product_id} LIMIT 1`)
  26. let start_chapter = await require("./5_CREATE_LINK_FACTORY/fq_create_link").get_tui_jian_start_chapter(element.product_id)
  27. await new Promise(resolve => setTimeout(resolve,500));
  28. if(info.length>0&&start_chapter!=-1){
  29. start_chapter = start_chapter==null?10:start_chapter
  30. console.log("info[0].publish_time:",info[0].publish_time,start_chapter,element.product_id)
  31. await connection.execute(
  32. `UPDATE video_product
  33. SET publish_time = ?, start_chapter = ?
  34. WHERE id = ?`,
  35. [
  36. new Date(info[0].publish_time), // 自动转换为 MySQL 支持的日期格式
  37. start_chapter,
  38. element.id
  39. ]
  40. );
  41. }else{
  42. if(start_chapter==-1){
  43. await connection.execute(
  44. `DELETE from video_product
  45. WHERE id = ?`,
  46. [
  47. element.id
  48. ]
  49. );
  50. }
  51. if(info.length<=0){
  52. let book_info = await require("./src/api/fq/fq_search_book").new_search_id(element.product_id)
  53. if(book_info.code ==0 ){
  54. if(book_info.data.total>0){
  55. let item = book_info.data.data[0]
  56. const values = [
  57. [
  58. item.book_id,
  59. item.series_name,
  60. item.amount_limit_status,
  61. item.book_pool,
  62. item.category,
  63. item.category_text,
  64. item.creation_status,
  65. item.delivery_status,
  66. item.episode_amount,
  67. item.episode_price,
  68. item.free_episode_count,
  69. item.latest_update_time,
  70. item.need_show_publish_tag,
  71. item.on_shelf_time,
  72. item.original_thumb_url,
  73. item.permission_status,
  74. item.price_changed,
  75. item.publish_time,
  76. item.thumb_uri,
  77. item.thumb_url,
  78. item.wx_audit_status,
  79. item.wx_is_reject
  80. ]
  81. ];
  82. let table_name = "fq_dj_lib"
  83. const insertSQL = `
  84. INSERT INTO ${table_name}
  85. (book_id, series_name, amount_limit_status, book_pool, category,
  86. category_text, creation_status, delivery_status, episode_amount,
  87. episode_price, free_episode_count, latest_update_time, need_show_publish_tag,
  88. on_shelf_time, original_thumb_url, permission_status, price_changed,
  89. publish_time, thumb_uri,thumb_url,wx_audit_status,wx_is_reject)
  90. VALUES ?
  91. ON DUPLICATE KEY UPDATE
  92. book_id = VALUES(book_id)
  93. `;
  94. await connection2.query(insertSQL, [values]);
  95. console.log("info:",book_info.data.data)
  96. }
  97. }
  98. console.log("短剧库没有:",element.product_id)
  99. }
  100. }
  101. }
  102. }
  103. }catch(e){
  104. console.error("processTask error:",e)
  105. } finally{
  106. if(connection!=null){
  107. connection.end()
  108. }
  109. if(connection2!=null){
  110. connection2.end()
  111. }
  112. global.setTimeout(processTask, 1000);
  113. }
  114. }
  115. CMD.init = async function(){
  116. redis_help.connect((results)=>{
  117. if(results){
  118. processTask();
  119. }
  120. })
  121. }
  122. CMD.init()