123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //同步掌阅付费的匹配书籍
- 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 schedule = require('node-schedule');
- const CMD = {}
- async function processTask(){
- let right_status = true
- let connection = null
- try{
- connection = await mysql.createConnection({
- ...taskdbConfig,
- multipleStatements: true
- });
- const [records] = await connection.execute(
- `SELECT * FROM video_product WHERE create_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND create_at <= CURDATE()
- AND book_platform = ${config.platform_zy} AND match_book = "NONE" LIMIT 1000 ;`
- );
- if(records.length<=0){
- console.log("完成所有七猫付费的匹配")
- throw 0
- }
- for (let index = 0; index < records.length; index++) {
- const element = records[index];
- let iaa_book_info = await require('../src/api/zy_mf/zy_mf_search_book').new_search_name(element.product_name)
- if(iaa_book_info!=null){
- iaa_book_info = await require('../src/api/zy_mf/zy_mf_search_book').new_search_id(iaa_book_info.book_id)
- if(iaa_book_info!=null){
- let book_info = await video_product_controllers.getProductData({book_id:iaa_book_info.book_id})
- if(!book_info.success){
- //创建一个免费书籍
- await video_product_controllers.createProductData({
- book_platform:config.platform_zymf,
- product_name:iaa_book_info.book_name,
- genre:iaa_book_info.genre,
- product_id:iaa_book_info.book_id,
- words:iaa_book_info.words,
- totalChapterNum:iaa_book_info.totalChapterNum,
- publish_time:iaa_book_info.publish_time,
- default_pay_section:iaa_book_info.default_pay_section,
- default_price:iaa_book_info.default_price,
- fee_unit:iaa_book_info.fee_unit,
- product_parent_id:element.product_id,
- match_book:element.product_id,
- gender:iaa_book_info.gender
- })
- }else{
- await video_product_controllers.updateData({id:book_info.data.id},{
- match_book:element.product_id
- })
- }
-
- await connection.execute(
- `UPDATE video_product
- SET match_book = ? WHERE id = ?`,
- [iaa_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.init = async function(){
- redis_help.connect((results)=>{
- if(results){
- const job = schedule.scheduleJob('0 09,21 * * *', async function() {
- await processTask();
- });
- }
- })
- }
- CMD.init()
|