|
@@ -0,0 +1,232 @@
|
|
|
+//找到带有300的数据,并且创建新书籍
|
|
|
+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_applet_product_controllers = require('../src/data_manager/Controllers/video_applet_product_controllers');
|
|
|
+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 = {}
|
|
|
+async function processTask(){
|
|
|
+ let right_status = true
|
|
|
+ let connection = null
|
|
|
+ try{
|
|
|
+ connection = await mysql.createConnection({
|
|
|
+ ...taskdbConfig,
|
|
|
+ multipleStatements: true
|
|
|
+ });
|
|
|
+ let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_qmmf} AND is_top != 2 AND is_check = 0 LIMIT 500`
|
|
|
+ console.log("sql:",sql)
|
|
|
+ const [rows] = await connection.execute(
|
|
|
+ sql
|
|
|
+ );
|
|
|
+
|
|
|
+ if(rows.length<=0){
|
|
|
+ throw 0
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let index = 0; index < rows.length; index++) {
|
|
|
+ let video_product_info = rows[index]
|
|
|
+ let data = await require('../src/api/qm_mf/qm_mf_search_book').search_350_name(video_product_info.product_name+"(350)")
|
|
|
+ if(data!=null&&data!=""){
|
|
|
+ await connection.execute(
|
|
|
+ ` UPDATE video_product SET top = 2 , is_check = 1 WHERE id = ${video_product_info.id} `
|
|
|
+ );
|
|
|
+ let book_data = {
|
|
|
+ book_name:data.book_name,
|
|
|
+ product_id:data.book_id,
|
|
|
+ genre:data.genre,
|
|
|
+ words:data.words,
|
|
|
+ product_parent_id:video_product_info.product_parent_id
|
|
|
+ }
|
|
|
+ //1创建这本书
|
|
|
+ await CMD.insert_product(book_data)
|
|
|
+ //2在创建推广链接
|
|
|
+ await CMD.update_filter_data(book_data)
|
|
|
+ }else{
|
|
|
+ await connection.execute(
|
|
|
+ ` UPDATE video_product SET is_check = 1 WHERE id = ${video_product_info.id} `
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }catch(e){
|
|
|
+ if(e==0){
|
|
|
+ right_status = false
|
|
|
+ }
|
|
|
+ console.error("processTask error:",e)
|
|
|
+ } finally{
|
|
|
+ if(connection!=null){
|
|
|
+ connection.end()
|
|
|
+ }
|
|
|
+ if(right_status==true){
|
|
|
+ global.setTimeout(processTask, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+CMD.insert_product = async function(data){
|
|
|
+ return await video_product_controllers.createProductData({
|
|
|
+ book_platform:config.platform_qmmf,
|
|
|
+ product_name:data.book_name,
|
|
|
+ genre:data.genre,
|
|
|
+ product_id:data.product_parent_id,
|
|
|
+ words:data.words
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+CMD.getAppInfoByPlatformId = function(AppConfig,tg_platform_id){
|
|
|
+ let temp = []
|
|
|
+ for (let index = 0; index < AppConfig.length; index++) {
|
|
|
+ const element = AppConfig[index];
|
|
|
+ if(element.tg_platform_id==tg_platform_id){
|
|
|
+ temp.push(element)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return temp
|
|
|
+}
|
|
|
+CMD.isBlackBook = function(all_black_books,book_id){
|
|
|
+ if(all_black_books==null){
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ for (let index = 0; index < all_black_books.length; index++) {
|
|
|
+ const black_book = all_black_books[index];
|
|
|
+ if(black_book.product_id==book_id){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+CMD.getMainInfoByAppid = function(MainConfig,app_id){
|
|
|
+ let list = []
|
|
|
+ for (let index = 0; index < MainConfig.length; index++) {
|
|
|
+ const element = MainConfig[index];
|
|
|
+ if(element.app_id==app_id){
|
|
|
+ list.push(element)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list
|
|
|
+}
|
|
|
+CMD.getSharedPlatform = function(PlatformShared,platform_shared_id){
|
|
|
+ for (let index = 0; index < PlatformShared.length; index++) {
|
|
|
+ const element = PlatformShared[index];
|
|
|
+ if(element.id==platform_shared_id){
|
|
|
+ return JSON.parse(element.info)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+CMD.getPlatformInfo = function(PlatformConfig,tg_platform_id){
|
|
|
+ for (let index = 0; index < PlatformConfig.length; index++) {
|
|
|
+ const element = PlatformConfig[index];
|
|
|
+ if(element.tg_platform_id==tg_platform_id){
|
|
|
+ return element
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+CMD.update_filter_data = async function(data) {
|
|
|
+
|
|
|
+ let MainConfig = await redis_help.getKeyValue("MainConfig")
|
|
|
+
|
|
|
+ MainConfig = JSON.parse(MainConfig)
|
|
|
+
|
|
|
+ let AppConfig = await redis_help.getKeyValue("AppConfig")
|
|
|
+
|
|
|
+ AppConfig = JSON.parse(AppConfig)
|
|
|
+
|
|
|
+ let PlatformShared = await redis_help.getKeyValue("PlatformShared")
|
|
|
+
|
|
|
+ PlatformShared = JSON.parse(PlatformShared)
|
|
|
+
|
|
|
+ let PlatformConfig = await redis_help.getKeyValue("PlatformConfig")
|
|
|
+
|
|
|
+ PlatformConfig = JSON.parse(PlatformConfig)
|
|
|
+
|
|
|
+ let PlatformInfo = CMD.getPlatformInfo(PlatformConfig,config.platform_qmmf)
|
|
|
+
|
|
|
+
|
|
|
+ let all_platform_list = CMD.getSharedPlatform(PlatformShared,PlatformInfo.platform_shared_id)
|
|
|
+
|
|
|
+
|
|
|
+ for (let i = 0; i < all_platform_list.length; i++) {
|
|
|
+ const tg_platform_id = all_platform_list[i];
|
|
|
+
|
|
|
+ let AppInfoList = CMD.getAppInfoByPlatformId(AppConfig,tg_platform_id)
|
|
|
+
|
|
|
+
|
|
|
+ for (let j = 0; j < AppInfoList.length; j++) {
|
|
|
+ const AppInfo = AppInfoList[j];
|
|
|
+ data.app_id = AppInfo.app_id
|
|
|
+
|
|
|
+ let list = CMD.getMainInfoByAppid(MainConfig,data.app_id)
|
|
|
+
|
|
|
+ if(list.length<0){
|
|
|
+ return console.error("获取主体错误:",data)
|
|
|
+ }
|
|
|
+
|
|
|
+ let black_books = await redis_help.getKeyValue("all_black_books")
|
|
|
+
|
|
|
+ if(black_books!=null){
|
|
|
+ black_books = JSON.parse(black_books)
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let index = 0; index < list.length; index++) {
|
|
|
+ const main_info = list[index];
|
|
|
+ data.main_id = main_info.id
|
|
|
+ data.main_name = main_info.main_name
|
|
|
+ let butler_id = main_info.butler_id
|
|
|
+ if(main_info.tg_link_config==undefined||main_info.tg_link_config==null){
|
|
|
+ console.error("主体配置推广链接错误:",main_info)
|
|
|
+ }else{
|
|
|
+ let min_book_word = main_info.min_book_word
|
|
|
+ let max_book_word = main_info.max_book_word
|
|
|
+ let word = data.words
|
|
|
+ let material_platform_id = main_info.material_platform_id
|
|
|
+ if(!CMD.isBlackBook(black_books,data.book_id)&&word>=min_book_word&&word<=max_book_word){
|
|
|
+ //符合标准进行创建表
|
|
|
+ let butler_video_applet_info = await tools.getAppletProductDataByButlerId(butler_id,data.book_id,data.main_id)
|
|
|
+ if(butler_video_applet_info==null){
|
|
|
+ const result = await video_applet_product_controllers.getAppletProductData({book_id:data.book_id,main_id:data.main_id})
|
|
|
+ if(!result.success){
|
|
|
+ let product_parent_id = data.product_parent_id
|
|
|
+ //没有找到 可以创建
|
|
|
+ await video_applet_product_controllers.createAppletProductData({
|
|
|
+ book_platform:config.platform_qmmf,
|
|
|
+ product_name:data.book_name,
|
|
|
+ product_id:data.book_id,
|
|
|
+ dy_small_program_start:"",
|
|
|
+ dy_small_program_start_data:"",
|
|
|
+ dy_small_applet_app_id:data.app_id,
|
|
|
+ status:0,
|
|
|
+ main_id:data.main_id,
|
|
|
+ promotion_id:"",
|
|
|
+ wait_status:0,
|
|
|
+ material_platform_id:material_platform_id,
|
|
|
+ butler_id:butler_id,
|
|
|
+ product_parent_id: product_parent_id
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+CMD.init = async function(){
|
|
|
+ redis_help.connect((results)=>{
|
|
|
+ if(results){
|
|
|
+ processTask();
|
|
|
+ // const hourlyJob = schedule.scheduleJob('0 * * * *', function() {
|
|
|
+ // console.log('整点执行的任务:', new Date().toLocaleString());
|
|
|
+ // processTask();
|
|
|
+ // });
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+CMD.init()
|