904118851 4 miesięcy temu
rodzic
commit
c6d8c1cef2
1 zmienionych plików z 60 dodań i 4 usunięć
  1. 60 4
      task_script/sync_publish_time_hy_mf.js

+ 60 - 4
task_script/sync_publish_time_hy_mf.js

@@ -5,6 +5,7 @@ const taskdbConfig = config.isDebug?config.debug_task_mysql:config.release_task_
 const redis_help = require('../src/use_redis');
 const hy_search_book = require('../src/api/hy/hy_search_book'); 
 const helper = require("../src/helper");
+const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
 const CMD = {}
 async function processTask(){
     let right_status = true
@@ -37,10 +38,32 @@ async function processTask(){
                     `UPDATE video_product SET publish_time = "${publish_time}"  WHERE id = ${video_product_info.id} `
                 );
             }else{
-                await connection.execute(
-                    ` UPDATE video_product SET status = 0 , publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id}  `
-                );
-                console.error("查无此书:",video_product_info)
+
+                let hy_book_data = CMD.add_parent_book(video_product_info.product_parent_id)
+                let publish_time = hy_book_data.createTime
+                let words = hy_book_data.words
+                let book_name = hy_book_data.name;
+                let genre = 1
+                if(words>100000){
+                    genre = 1;
+                }else{
+                    genre = 3;
+                }
+                if(hy_book_data!=null){
+                    await CMD.insert_product({
+                        tg_platform_id:config.platform_heiyan,
+                        book_name:book_name,
+                        genre:genre,
+                        book_id:video_product_info.product_parent_id,
+                        words:words,
+                        publish_time:publish_time
+                    })
+                }else{
+                    await connection.execute(
+                         ` UPDATE video_product SET  publish_time = '2000-01-01 01:01:01' WHERE id = ${video_product_info.id}  `
+                    );
+                    console.error("查无此书:",video_product_info)
+                }
             }
         }
 
@@ -59,6 +82,28 @@ async function processTask(){
 
 }
 
+CMD.add_parent_book = async function(product_id){
+    let data = await hy_search_book.search_id(product_id)
+    if(data==undefined||data==null){
+        data = null
+    }
+
+    if(data!=null){
+        if(data.rows==null||data.rows==undefined){
+            data = null
+        }
+    }
+    if(data!=null){
+        if(data.rows.length<=0){
+            data = null
+        }
+    }
+    if(data!=null){
+        return data.rows[0]
+    }
+    return data
+}
+
 CMD.search_parent_id = async function(connection,product_parent_id) {
     let sql = `SELECT * FROM video_product WHERE product_id = '${product_parent_id}' LIMIT 1`
     const [rows] = await connection.execute(
@@ -69,6 +114,17 @@ CMD.search_parent_id = async function(connection,product_parent_id) {
     }
     return rows[0]
 }
+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(){