904118851 2 settimane fa
parent
commit
829d370406

BIN
dump.rdb


+ 1 - 1
etc/config.json

@@ -1,5 +1,5 @@
 {
-    "isDebug":false,
+    "isDebug":true,
     "redis_config": {
         "host": "127.0.0.1",
         "port": 6379

+ 24 - 1
src/api/zy/zy_search_book.js

@@ -3,6 +3,7 @@ const tools = require('../../../tools');
 const config  = require('../../../etc/config.json');
 const redis_help = require('../../use_redis');
 const helper = require('../../helper');
+const mldbConfig = config.isDebug?config.debug_mysql:config.release_mysql
 const CMD = {}
 CMD.search_id = async function(bookId) {
     try{
@@ -93,9 +94,31 @@ CMD.new_search_id = async function(bookId) {
 }
 
 
-CMD.new_search_name = async function(bookName) {
+CMD.search_name_by_lib = async function(bookName) {
     try{
+        //先搜索库里是否存在
+        const connection = await mysql.createConnection({
+            ...mldbConfig,
+            multipleStatements: true
+        });
+        let sql  =  `SELECT * FROM zy_lib WHERE product_name ="${bookName}" LIMIT 1`
+        let [info] =  await connection.execute(sql)
+
+        if(info.length<=0){
+            throw 0
+        }
+        return info[0]
+       
+    }catch(e){
         return null
+    }
+}
+CMD.new_search_name = async function(bookName) {
+    try{
+        let lib_book_info = await CMD.search_name_by_lib(bookName)
+        if(bookName!=null){
+            return {book_name:lib_book_info.product_name,book_id:lib_book_info.product_id}
+        }
         let authorization = await redis_help.getKeyValue("zy_token")
         console.log("authorization:",authorization)
         let clinet = tools.getOneNewClinet({

+ 23 - 2
src/api/zy_mf/zy_mf_search_book.js

@@ -94,10 +94,31 @@ CMD.new_search_id = async function(bookId) {
 }
 
 
-
-CMD.new_search_name = async function(bookName) {
+CMD.search_name_by_lib = async function(bookName) {
     try{
+        //先搜索库里是否存在
+        const connection = await mysql.createConnection({
+            ...mldbConfig,
+            multipleStatements: true
+        });
+        let sql  =  `SELECT * FROM zy_mf_lib WHERE product_name ="${bookName}" LIMIT 1`
+        let [info] =  await connection.execute(sql)
+
+        if(info.length<=0){
+            throw 0
+        }
+        return info[0]
+       
+    }catch(e){
         return null
+    }
+}
+CMD.new_search_name = async function(bookName) {
+    try{
+        let lib_book_info = await CMD.search_name_by_lib(bookName)
+        if(bookName!=null){
+            return {book_name:lib_book_info.product_name,book_id:lib_book_info.product_id}
+        }
         let authorization = await redis_help.getKeyValue("zy_mf_token")
         console.log("authorization:",authorization)
         let clinet = tools.getOneNewClinet({

+ 127 - 0
task_script/pull_all_zy_book_list.js

@@ -0,0 +1,127 @@
+//同步番茄免费的匹配书籍
+const config = require("../etc/config.json");
+const mysql = require('mysql2/promise');
+const mldbConfig = config.isDebug?config.debug_mysql:config.release_mysql
+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 schedule = require('node-schedule');
+const tools = require("../tools");
+const CMD = {}
+let cur_page = 1
+async function getZyDataByPage(page) {
+
+    try{
+
+        let authorization = await redis_help.getKeyValue("zy_token")
+
+        let clinet = tools.getOneNewClinet({
+                    // "cookie":"acw_tc=1a0c639417498037411406820e006fb57d572ffdc9c83cd8a46aaf8d19ca00",
+                    "authorization": authorization,
+        })
+        
+        let response =  await clinet.get(`https://gaia.zhangyue.com/gaia/v1/open_api/pay/book/getBookInfoList?reseller_id=9390&application_key=donglingstory_mini&book_ids=&book_content_type=&author=&copyright_type=&category_sex=&is_complete=&total=0&page=${page}&size=50&sort=&order=&psize=50&scheme_id=39`)
+        
+        let list = []
+
+        if(response.data.code!=0){
+            console.error("new_search_id error:",response)
+            throw response.data
+        }else{
+            list = response.data.body.list
+        }
+
+        if(list.length<=0){
+            return null
+        }
+
+        return list
+
+    }catch(e){
+        return null
+    }
+
+}
+
+async function addBookListToLib(data) {
+    try {
+        const connection = await mysql.createConnection({
+            ...mldbConfig,
+            multipleStatements: true
+        });
+        
+        // await processVideoTitles(connection, data.map(item => item.title));
+        console.log("data:",data)
+        // 转换时间戳为MySQL datetime格式
+        const values = data.map(item => [
+            item.book_id,
+            item.book_name,
+            item.create_time,
+            item.chapter_count,
+            item.default_pay_section,
+            item.default_price,
+            item.start_chapter,
+            item.fee_unit,
+            item.author,
+            item.word_count
+        ]);
+        let table_name = "zy_lib"
+        const insertSQL = `
+        INSERT INTO ${table_name}
+        (product_id, product_name, publish_time, totalChapterNum, default_pay_section, 
+            default_price, start_chapter, fee_unit, author,
+            word_count)
+        VALUES ?
+        ON DUPLICATE KEY UPDATE
+            product_id = VALUES(product_id)
+    `;
+        
+        await connection.query(insertSQL, [values]);
+        await connection.end();
+        
+        console.log(`成功插入 ${values.length} 条记录到表 ${table_name}`);
+    } catch (error) {
+        console.error('处理消息失败:', error);
+        throw error;
+    }
+}
+
+async function processTask(){
+    let connection  = null
+    let isFinish = false
+    try{
+       
+        let list = await getZyDataByPage(cur_page)
+        if( list == null ){
+            isFinish = true
+            throw 0
+        }
+        await addBookListToLib(list)
+
+    }catch(e){
+
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        if(!isFinish){
+            cur_page++;
+            global.setTimeout(processTask, 2000);
+        }
+
+    }
+
+}
+
+
+CMD.init = async function(){
+    redis_help.connect(async (results)=>{
+        if(results){
+            await  processTask();
+        }
+    })
+
+}
+
+CMD.init()

+ 122 - 0
task_script/pull_all_zy_mf_book_list.js

@@ -0,0 +1,122 @@
+//同步番茄免费的匹配书籍
+const config = require("../etc/config.json");
+const mysql = require('mysql2/promise');
+const mldbConfig = config.isDebug?config.debug_mysql:config.release_mysql
+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 schedule = require('node-schedule');
+const tools = require("../tools");
+const CMD = {}
+let cur_page = 1
+async function getZyDataByPage(page) {
+
+    try{
+        let authorization = await redis_help.getKeyValue("zy_mf_token")
+
+        let clinet = tools.getOneNewClinet({
+                    // "cookie":"acw_tc=1a0c639417498037411406820e006fb57d572ffdc9c83cd8a46aaf8d19ca00",
+                    "authorization": authorization,
+        })
+        let response =  await clinet.get(`https://gaia.zhangyue.com/gaia/v1/open_api/pay/book/getBookInfoList?reseller_id=9886&application_key=shiyuestory_mini&book_ids=&book_content_type=&author=&copyright_type=&category_sex=&is_complete=&total=0&page=${page}&size=50&sort=&order=&psize=50&scheme_id=38&business_model=free`)
+        let list = []
+        if(response.data.code!=0){
+            console.error("new_search_id error:",response)
+            throw response.data
+        }else{
+            list = response.data.body.list
+        }
+
+        if(list.length<=0){
+            return null
+        }
+
+        return list
+    }catch(e){
+        return null
+    }
+
+}
+
+async function addBookListToLib(data) {
+    try {
+        const connection = await mysql.createConnection({
+            ...mldbConfig,
+            multipleStatements: true
+        });
+        
+        // await processVideoTitles(connection, data.map(item => item.title));
+        console.log("data:",data)
+        // 转换时间戳为MySQL datetime格式
+        const values = data.map(item => [
+            item.book_id,
+            item.book_name,
+            item.create_time,
+            item.chapter_count,
+            item.default_pay_section,
+            item.default_price,
+            item.start_chapter,
+            item.fee_unit,
+            item.author,
+            item.word_count
+        ]);
+        let table_name = "zy_mf_lib"
+        const insertSQL = `
+        INSERT INTO ${table_name}
+        (product_id, product_name, publish_time, totalChapterNum, default_pay_section, 
+            default_price, start_chapter, fee_unit, author,
+            word_count)
+        VALUES ?
+        ON DUPLICATE KEY UPDATE
+            product_id = VALUES(product_id)
+    `;
+        
+        await connection.query(insertSQL, [values]);
+        await connection.end();
+        
+        console.log(`成功插入 ${values.length} 条记录到表 ${table_name}`);
+    } catch (error) {
+        console.error('处理消息失败:', error);
+        throw error;
+    }
+}
+
+async function processTask(){
+    let connection  = null
+    let isFinish = false
+    try{
+       
+        let list = await getZyDataByPage(cur_page)
+        if( list == null ){
+            isFinish = true
+            throw 0
+        }
+        await addBookListToLib(list)
+
+    }catch(e){
+
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        if(!isFinish){
+            cur_page++;
+            global.setTimeout(processTask, 2000);
+        }
+
+    }
+
+}
+
+
+CMD.init = async function(){
+    redis_help.connect(async (results)=>{
+        if(results){
+            await  processTask();
+        }
+    })
+
+}
+
+CMD.init()

+ 118 - 0
task_script/pull_zy_mf_task.js

@@ -0,0 +1,118 @@
+//同步番茄免费的匹配书籍
+const config = require("../etc/config.json");
+const mysql = require('mysql2/promise');
+const mldbConfig = config.isDebug?config.debug_mysql:config.release_mysql
+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 schedule = require('node-schedule');
+const tools = require("../tools");
+const CMD = {}
+let cur_page = 1
+async function getZyDataByPage(page) {
+
+    try{
+        let authorization = await redis_help.getKeyValue("zy_mf_token")
+
+        let clinet = tools.getOneNewClinet({
+                    // "cookie":"acw_tc=1a0c639417498037411406820e006fb57d572ffdc9c83cd8a46aaf8d19ca00",
+                    "authorization": authorization,
+        })
+        let response =  await clinet.get(`https://gaia.zhangyue.com/gaia/v1/open_api/pay/book/getBookInfoList?reseller_id=9886&application_key=shiyuestory_mini&book_ids=&book_content_type=&author=&copyright_type=&category_sex=&is_complete=&total=0&page=${page}&size=50&sort=&order=&psize=50&scheme_id=38&business_model=free`)
+        let list = []
+        if(response.data.code!=0){
+            console.error("new_search_id error:",response)
+            throw response.data
+        }else{
+            list = response.data.body.list
+        }
+
+        if(list.length<=0){
+            return null
+        }
+
+        return list
+    }catch(e){
+        return null
+    }
+
+}
+
+async function addBookListToLib(data) {
+    try {
+        const connection = await mysql.createConnection({
+            ...mldbConfig,
+            multipleStatements: true
+        });
+        
+        // await processVideoTitles(connection, data.map(item => item.title));
+        console.log("data:",data)
+        // 转换时间戳为MySQL datetime格式
+        const values = data.map(item => [
+            item.book_id,
+            item.book_name,
+            item.create_time,
+            item.chapter_count,
+            item.default_pay_section,
+            item.default_price,
+            item.start_chapter,
+            item.fee_unit,
+            item.author,
+            item.word_count
+        ]);
+        let table_name = "zy_mf_lib"
+        const insertSQL = `
+        INSERT INTO ${table_name}
+        (product_id, product_name, publish_time, totalChapterNum, default_pay_section, 
+            default_price, start_chapter, fee_unit, author,
+            word_count)
+        VALUES ?
+        ON DUPLICATE KEY UPDATE
+            product_id = VALUES(product_id)
+    `;
+        
+        await connection.query(insertSQL, [values]);
+        await connection.end();
+        
+        console.log(`成功插入 ${values.length} 条记录到表 ${table_name}`);
+    } catch (error) {
+        console.error('处理消息失败:', error);
+        throw error;
+    }
+}
+
+async function processTask(){
+    let connection  = null
+    let isFinish = false
+    try{
+       
+        let list = await getZyDataByPage(cur_page)
+        if( list == null ){
+            isFinish = true
+            throw 0
+        }
+        await addBookListToLib(list)
+
+    }catch(e){
+
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        global.setTimeout(processTask, 60000);
+    }
+
+}
+
+
+CMD.init = async function(){
+    redis_help.connect(async (results)=>{
+        if(results){
+            await  processTask();
+        }
+    })
+
+}
+
+CMD.init()

+ 122 - 0
task_script/pull_zy_task.js

@@ -0,0 +1,122 @@
+//同步番茄免费的匹配书籍
+const config = require("../etc/config.json");
+const mysql = require('mysql2/promise');
+const mldbConfig = config.isDebug?config.debug_mysql:config.release_mysql
+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 schedule = require('node-schedule');
+const tools = require("../tools");
+const CMD = {}
+let cur_page = 1
+async function getZyDataByPage(page) {
+
+    try{
+
+        let authorization = await redis_help.getKeyValue("zy_token")
+
+        let clinet = tools.getOneNewClinet({
+                    // "cookie":"acw_tc=1a0c639417498037411406820e006fb57d572ffdc9c83cd8a46aaf8d19ca00",
+                    "authorization": authorization,
+        })
+        
+        let response =  await clinet.get(`https://gaia.zhangyue.com/gaia/v1/open_api/pay/book/getBookInfoList?reseller_id=9390&application_key=donglingstory_mini&book_ids=&book_content_type=&author=&copyright_type=&category_sex=&is_complete=&total=0&page=${page}&size=50&sort=&order=&psize=50&scheme_id=39`)
+        
+        let list = []
+
+        if(response.data.code!=0){
+            console.error("new_search_id error:",response)
+            throw response.data
+        }else{
+            list = response.data.body.list
+        }
+
+        if(list.length<=0){
+            return null
+        }
+
+        return list
+
+    }catch(e){
+        return null
+    }
+
+}
+
+async function addBookListToLib(data) {
+    try {
+        const connection = await mysql.createConnection({
+            ...mldbConfig,
+            multipleStatements: true
+        });
+        // await processVideoTitles(connection, data.map(item => item.title));
+        // 转换时间戳为MySQL datetime格式
+        const values = data.map(item => [
+            item.book_id,
+            item.book_name,
+            item.create_time,
+            item.chapter_count,
+            item.default_pay_section,
+            item.default_price,
+            item.start_chapter,
+            item.fee_unit,
+            item.author,
+            item.word_count
+        ]);
+        let table_name = "zy_lib"
+        const insertSQL = `
+        INSERT INTO ${table_name}
+        (product_id, product_name, publish_time, totalChapterNum, default_pay_section, 
+            default_price, start_chapter, fee_unit, author,
+            word_count)
+        VALUES ?
+        ON DUPLICATE KEY UPDATE
+            product_id = VALUES(product_id)
+    `;
+        
+        await connection.query(insertSQL, [values]);
+        await connection.end();
+        
+        console.log(`成功插入 ${values.length} 条记录到表 ${table_name}`);
+    } catch (error) {
+        console.error('处理消息失败:', error);
+        throw error;
+    }
+}
+
+async function processTask(){
+    let connection  = null
+    let isFinish = false
+    try{
+       
+        let list = await getZyDataByPage(cur_page)
+        if( list == null ){
+            isFinish = true
+            throw 0
+        }
+        await addBookListToLib(list)
+
+    }catch(e){
+
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        global.setTimeout(processTask, 60000);
+
+    }
+
+}
+
+
+CMD.init = async function(){
+    redis_help.connect(async (results)=>{
+        if(results){
+            await  processTask();
+        }
+    })
+
+}
+
+CMD.init()