904118851 hai 1 mes
pai
achega
9644ab0591
Modificáronse 1 ficheiros con 75 adicións e 0 borrados
  1. 75 0
      task_script/reset_link.js

+ 75 - 0
task_script/reset_link.js

@@ -0,0 +1,75 @@
+//重置推广连接状态
+const config = require("../etc/config.json");
+const mysql = require('mysql2/promise');
+const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_mysql
+const redis_help = require('../src/use_redis');
+const CMD = {}
+const XLSX = require('xlsx');
+var productIds = []
+function getProductIds(filePath) {
+    try {
+        // 读取 xlsx 文件
+        const workbook = XLSX.readFile(filePath);
+        
+        // 获取第一个工作表
+        const firstSheetName = workbook.SheetNames[0];
+        const worksheet = workbook.Sheets[firstSheetName];
+        
+        // 将工作表转换为 JSON 数组
+        const data = XLSX.utils.sheet_to_json(worksheet);
+        
+        // 提取 product_id 列的所有值
+        const productIds = data.map(row => row.product_id);
+        
+        return productIds;
+    } catch (error) {
+        console.error('读取文件出错:', error);
+        return [];
+    }
+}
+
+async function processTask(){
+    // 使用示例
+    if(productIds.length<=0){
+        return console.log("完成任务")
+    }
+    let product_id = productIds.pop()
+    let connection  = null
+    try{
+        product_id = `'${product_id}'`
+        connection = await mysql.createConnection({
+            ...taskdbConfig,
+            multipleStatements: true
+        });
+        let sql = ` update video_applet_product set status = 0 , wait_status = 0 where product_id = ${product_id} `
+        console.log("sql:",sql)
+        await connection.execute(
+            sql
+        );
+
+    }catch(e){
+        console.error("processTask error:",e)
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        global.setTimeout(processTask, 1000);
+    }
+
+}
+
+
+
+CMD.init = async function(){
+    redis_help.connect((results)=>{
+        if(results){
+            const filePath = './reset_link.xlsx';
+            productIds = getProductIds(filePath);
+            console.log("productIds:",productIds)
+            // processTask();
+        }
+    })
+
+}
+
+CMD.init()