904118851 1 ماه پیش
والد
کامیت
557058f931
3فایلهای تغییر یافته به همراه224 افزوده شده و 0 حذف شده
  1. BIN
      dump.rdb
  2. 112 0
      task_script/run_all_fqmf_book_find_match_book.js
  3. 112 0
      task_script/run_all_qmmf_book_find_match_book.js

BIN
dump.rdb


+ 112 - 0
task_script/run_all_fqmf_book_find_match_book.js

@@ -0,0 +1,112 @@
+//同步番茄免费的匹配书籍
+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 video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
+const helper = require("../src/helper");
+const CMD = {}
+async function processTask(){
+    let right_status = true
+    let connection  = null
+    try{
+        connection = await mysql.createConnection({
+            ...taskdbConfig,
+            multipleStatements: true
+        });
+
+        const [rows1] =  await connection.execute(
+            `SELECT COUNT(*) AS total FROM video_product WHERE book_platform = ${config.platform_fanqiemf} AND match_book = 'NONE';`
+        );
+        let total = rows1[0].total;
+
+        const pageSize = 100;
+        const totalPages = Math.ceil(total / pageSize);
+        
+
+        // 循环分页查询
+        for (let page = 0; page < totalPages; page++) {
+            const offset = page * pageSize;
+            
+            const [records] = await connection.execute(
+                `SELECT * FROM video_product 
+                 WHERE book_platform = ${config.platform_fanqie} AND match_book = 'NONE' 
+                 LIMIT ? OFFSET ?`,
+                [pageSize, offset]
+            );
+
+
+            if(records.length<=0){
+                console.log("完成所有番茄免费的匹配")
+                throw 0
+            }
+
+            for (let index = 0; index < records.length; index++) {
+                const element = records[index];
+                let iap_book_info = await require('../src/api/fq/fq_search_book').根据番茄免费ID查询付费书籍(element.product_id)
+                if(iap_book_info!=null){
+                    let book_info = await video_product_controllers.getProductData(iap_book_info.book_id)
+                    if(!book_info.success){
+                        //创建一个付费书籍
+                        await video_product_controllers.createProductData({
+                            book_platform:config.platform_fanqie,
+                            product_name:iap_book_info.book_name,
+                            genre:iap_book_info.genre,
+                            product_id:iap_book_info.book_id,
+                            words:iap_book_info.words,
+                            match_book:element.product_id
+                        })
+                    }
+
+                    await connection.execute(
+                        `UPDATE video_product 
+                         SET match_book = ?, 
+                             product_parent_id = ? 
+                         WHERE id = ?`,
+                        [iap_book_info.book_id, iap_book_info.book_id, element.id]
+                    );
+                }
+    
+            }
+
+        }
+
+
+    }catch(e){
+        if(e==0){
+            right_status = false
+        }
+        console.error("processTask error:",e)
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        if(right_status){
+            global.setTimeout(processTask, 2000);
+        }
+    }
+
+}
+
+
+CMD.insert_product = async function(data){
+    await video_product_controllers.createProductData({
+        book_platform:data.tg_platform_id,
+        product_name:data.book_name,
+        genre:data.genre,
+        product_id:data.book_id,
+        words:data.words,
+        publish_time:data.publish_time
+
+    })
+}
+CMD.init = async function(){
+    redis_help.connect((results)=>{
+        if(results){
+            processTask();
+        }
+    })
+
+}
+
+CMD.init()

+ 112 - 0
task_script/run_all_qmmf_book_find_match_book.js

@@ -0,0 +1,112 @@
+//同步七猫免费的匹配书籍
+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 video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
+const helper = require("../src/helper");
+const CMD = {}
+async function processTask(){
+    let right_status = true
+    let connection  = null
+    try{
+        connection = await mysql.createConnection({
+            ...taskdbConfig,
+            multipleStatements: true
+        });
+
+        const [rows1] =  await connection.execute(
+            `SELECT COUNT(*) AS total FROM video_product WHERE book_platform = ${config.platform_qmmf} AND match_book = 'NONE';`
+        );
+        let total = rows1[0].total;
+
+        const pageSize = 100;
+        const totalPages = Math.ceil(total / pageSize);
+        
+
+        // 循环分页查询
+        for (let page = 0; page < totalPages; page++) {
+            const offset = page * pageSize;
+            
+            const [records] = await connection.execute(
+                `SELECT * FROM video_product 
+                 WHERE book_platform = ${config.platform_qmmf} AND match_book = 'NONE' 
+                 LIMIT ? OFFSET ?`,
+                [pageSize, offset]
+            );
+
+
+            if(records.length<=0){
+                console.log("完成所有七猫免费的匹配")
+                throw 0
+            }
+
+            for (let index = 0; index < records.length; index++) {
+                const element = records[index];
+                let iap_book_info = await require('../src/api/qm/qm_search_book').根据七猫免费D查询付费书籍(element.product_id)
+                if(iap_book_info!=null){
+                    let book_info = await video_product_controllers.getProductData(iap_book_info.book_id)
+                    if(!book_info.success){
+                        //创建一个付费书籍
+                        await video_product_controllers.createProductData({
+                            book_platform:config.platform_fanqie,
+                            product_name:iap_book_info.book_name,
+                            genre:iap_book_info.genre,
+                            product_id:iap_book_info.book_id,
+                            words:iap_book_info.words,
+                            match_book:element.product_id
+                        })
+                    }
+
+                    await connection.execute(
+                        `UPDATE video_product 
+                         SET match_book = ?, 
+                             product_parent_id = ? 
+                         WHERE id = ?`,
+                        [iap_book_info.book_id, iap_book_info.book_id, element.id]
+                    );
+                }
+    
+            }
+
+        }
+
+
+    }catch(e){
+        if(e==0){
+            right_status = false
+        }
+        console.error("processTask error:",e)
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        if(right_status){
+            global.setTimeout(processTask, 2000);
+        }
+    }
+
+}
+
+
+CMD.insert_product = async function(data){
+    await video_product_controllers.createProductData({
+        book_platform:data.tg_platform_id,
+        product_name:data.book_name,
+        genre:data.genre,
+        product_id:data.book_id,
+        words:data.words,
+        publish_time:data.publish_time
+
+    })
+}
+CMD.init = async function(){
+    redis_help.connect((results)=>{
+        if(results){
+            processTask();
+        }
+    })
+
+}
+
+CMD.init()