sync_dz_gender.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 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. let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_dianzhong} AND gender = 0 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 = await require('../src/api/dz/dz_search_book').search_id(video_product_info.product_id)
  28. if(data!=null&&data!=""){
  29. let gender = data.gender
  30. await connection.execute(
  31. ` UPDATE video_product SET gender = ${gender} WHERE id = ${video_product_info.id} `
  32. );
  33. }else{
  34. await connection.execute(
  35. ` UPDATE video_product SET gender = 3 WHERE id = ${video_product_info.id} `
  36. );
  37. console.error("查无此书:",video_product_info)
  38. }
  39. }
  40. }catch(e){
  41. if(e==0){
  42. right_status = false
  43. }
  44. console.error("processTask error:",e)
  45. } finally{
  46. if(connection!=null){
  47. connection.end()
  48. }
  49. global.setTimeout(processTask, 1000);
  50. }
  51. }
  52. CMD.init = async function(){
  53. redis_help.connect((results)=>{
  54. if(results){
  55. processTask();
  56. }
  57. })
  58. }
  59. CMD.init()