|
@@ -0,0 +1,128 @@
|
|
|
+const config = require("../etc/config.json");
|
|
|
+const helper = require("../src/helper");
|
|
|
+const HttpClient = require("../src/HttpClient");
|
|
|
+const redis_help = require('../src/use_redis');
|
|
|
+const mysql = require('mysql2/promise');
|
|
|
+const tools = require("../tools");
|
|
|
+const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
|
|
|
+const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
|
|
|
+const CMD = {}
|
|
|
+let page_index = 1;
|
|
|
+
|
|
|
+async function processTask(){
|
|
|
+ let right_status = true
|
|
|
+ let connection = null
|
|
|
+ try{
|
|
|
+ connection = await mysql.createConnection({
|
|
|
+ ...dbConfig,
|
|
|
+ multipleStatements: true
|
|
|
+ });
|
|
|
+ let postData = {
|
|
|
+ "cmd":"video_product",
|
|
|
+ "fun":"search_book_data",
|
|
|
+ "data":{
|
|
|
+ "product_id":"",
|
|
|
+ "product_name":"",
|
|
|
+ "tg_platform_id":config.platform_qimao,
|
|
|
+ "is_auto":"",
|
|
|
+ "page_size":500,
|
|
|
+ "page_number":page_index,
|
|
|
+ "oce_material_id":"",
|
|
|
+ "genre":"",
|
|
|
+ "is_store":"",
|
|
|
+ "alias_name":"",
|
|
|
+ "stat_cost":"",
|
|
|
+ "min_book_word":"",
|
|
|
+ "max_book_word":""
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log("发送请求数据:", postData);
|
|
|
+
|
|
|
+ let client = tools.getOneNewClinet()
|
|
|
+ let response = await client.post('http://127.0.0.1:9100/tg/back/api', postData, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'X-Request-Type': 'API', // 标记 API 请求
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ response = response.data
|
|
|
+ // 检查响应数据结构
|
|
|
+ if (!response || !response.data || !Array.isArray(response.data)) {
|
|
|
+ console.log("响应数据无效或格式错误");
|
|
|
+ throw 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有数据
|
|
|
+ if (response.data.length <= 0) {
|
|
|
+ console.log("没有更多数据");
|
|
|
+ throw 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ let info = response.data
|
|
|
+ let total = info.total;
|
|
|
+ let sync_main_task_item = info.data
|
|
|
+ let product_list = sync_main_task_item.data;
|
|
|
+ for (let index = 0; index < product_list.length; index++) {
|
|
|
+ const element = product_list[index];
|
|
|
+ const [rows] = await connection.execute(
|
|
|
+ `SELECT * FROM qm_iap_lib WHERE book_id = ${element.product_id} AND is_have_iaa = 1 LIMIT 1`
|
|
|
+ );
|
|
|
+ if(rows.length<=0){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ let qm_iap_book_info = rows[0]
|
|
|
+ let iaa_book_id = await CMD.getQMMFVideoProduct(connection,qm_iap_book_info.iaa_book_id)
|
|
|
+ if(iaa_book_id==null){
|
|
|
+ await CMD.addQMMFVideoProduct(connection,iaa_book_id,iaa_book_id.book_id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(e){
|
|
|
+ if(e==0){
|
|
|
+ right_status = false
|
|
|
+ }
|
|
|
+ console.error("processTask error:",e)
|
|
|
+ } finally{
|
|
|
+ if(right_status){
|
|
|
+ page_index++;
|
|
|
+ global.setTimeout(processTask, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//获取
|
|
|
+CMD.getQMMFVideoProduct = async function(connection,product_id){
|
|
|
+ const [rows] = await connection.execute(
|
|
|
+ `SELECT * FROM video_product WHERE product_id = ${product_id} AND book_platform = ${config.platform_qmmf} LIMIT 1`
|
|
|
+ );
|
|
|
+
|
|
|
+ if(rows.length<=0){
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+ return rows[0]
|
|
|
+}
|
|
|
+
|
|
|
+//插入
|
|
|
+CMD.addQMMFVideoProduct = async function(connection,product_id,product_parent_id){
|
|
|
+ let qm_book_data = await require('../src/api/qm_mf/qm_mf_search_book').search_id(product_id)
|
|
|
+ await connection.execute(
|
|
|
+ `INSERT INTO video_product (product_name,product_id,book_platform,genre,words,words,product_parent_id) VALUES (${qm_book_data.book_name},${product_id},${config.platform_qmmf},${qm_book_data.genre},${qm_book_data.words},${product_parent_id})`
|
|
|
+ );
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+CMD.init = async function(){
|
|
|
+ redis_help.connect((results)=>{
|
|
|
+ if(results){
|
|
|
+ processTask();
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+CMD.init()
|