reset_link.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 CMD = {}
  7. const XLSX = require('xlsx');
  8. var productIds = []
  9. function getProductIds(filePath) {
  10. try {
  11. // 读取 xlsx 文件
  12. const workbook = XLSX.readFile(filePath);
  13. // 获取第一个工作表
  14. const firstSheetName = workbook.SheetNames[0];
  15. const worksheet = workbook.Sheets[firstSheetName];
  16. // 将工作表转换为 JSON 数组
  17. const data = XLSX.utils.sheet_to_json(worksheet);
  18. // 提取 product_id 列的所有值
  19. const productIds = data.map(row => row.product_id);
  20. return productIds;
  21. } catch (error) {
  22. console.error('读取文件出错:', error);
  23. return [];
  24. }
  25. }
  26. async function processTask(){
  27. // 使用示例
  28. if(productIds.length<=0){
  29. return console.log("完成任务")
  30. }
  31. let product_id = productIds.pop()
  32. let connection = null
  33. try{
  34. product_id = `'${product_id}'`
  35. connection = await mysql.createConnection({
  36. ...taskdbConfig,
  37. multipleStatements: true
  38. });
  39. let sql = ` update video_applet_product set status = 0 , wait_status = 0 where product_id = ${product_id} `
  40. console.log("sql:",sql)
  41. await connection.execute(
  42. sql
  43. );
  44. }catch(e){
  45. console.error("processTask error:",e)
  46. } finally{
  47. if(connection!=null){
  48. connection.end()
  49. }
  50. global.setTimeout(processTask, 1000);
  51. }
  52. }
  53. CMD.init = async function(){
  54. redis_help.connect((results)=>{
  55. if(results){
  56. const filePath = './reset_link.xlsx';
  57. productIds = getProductIds(filePath);
  58. console.log("productIds:",productIds)
  59. // processTask();
  60. }
  61. })
  62. }
  63. CMD.init()