sync_author_hy.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
  7. const helper = require("../src/helper");
  8. const hy_search_book = require('../src/api/hy/hy_search_book');
  9. const CMD = {}
  10. async function processTask(){
  11. let right_status = true
  12. let connection = null
  13. try{
  14. connection = await mysql.createConnection({
  15. ...taskdbConfig,
  16. multipleStatements: true
  17. });
  18. let sql = `SELECT * FROM video_product WHERE ( book_platform = ${config.platform_heiyan} or book_platform = ${config.platform_heiyanmf} ) AND author IS NULL LIMIT 5`
  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 = await hy_search_book.search_id(video_product_info.product_id)
  29. if(data==undefined||data==null){
  30. data = null
  31. }
  32. if(data!=null){
  33. if(data.rows==null||data.rows==undefined){
  34. data = null
  35. }
  36. }
  37. if(data!=null){
  38. if(data.rows.length<=0){
  39. data = null
  40. }
  41. }
  42. if(data!=null&&data!=""){
  43. let author = data.rows[0].userName
  44. await connection.execute(
  45. ` UPDATE video_product SET author = '${author}' WHERE id = ${video_product_info.id} `
  46. );
  47. }else{
  48. await connection.execute(
  49. ` UPDATE video_product SET author = 'NONE' WHERE id = ${video_product_info.id} `
  50. );
  51. console.error("查无此书:",video_product_info)
  52. }
  53. }
  54. }catch(e){
  55. if(e==0){
  56. right_status = false
  57. }
  58. console.error("processTask error:",e)
  59. } finally{
  60. if(connection!=null){
  61. connection.end()
  62. }
  63. global.setTimeout(processTask, 1000);
  64. }
  65. }
  66. CMD.init = async function(){
  67. redis_help.connect((results)=>{
  68. if(results){
  69. processTask();
  70. }
  71. })
  72. }
  73. CMD.init()