123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- 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 get_fq_book_tab_controllers = require("../src/data_manager/Controllers/get_fq_book_tab_controllers");
- const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
- const CMD = {}
- function getCodeFromUrl(url) {
- const codeMatch = url.match(/code=([^&]+)/);
- if (codeMatch && codeMatch[1]) {
- return codeMatch[1];
- }
- return null;
- }
- async function processTask(){
- let connection = null
- try{
- const today = helper.getLocalDate();
- let date = today.replace(/-/g, '');
- let table_name = `video_product`;
- // 创建数据库连接
- connection = await mysql.createConnection({
- ...dbConfig,
- multipleStatements: true
- });
- // 检查表是否存在
- const [tableCheck] = await connection.execute(
- `SELECT TABLE_NAME
- FROM information_schema.tables
- WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?`,
- [dbConfig.database, table_name]
- );
- if (tableCheck.length === 0) {
- // 表不存在
- console.error(`表 ${table_name} 不存在`);
- throw new Error(`表 ${table_name} 不存在`);
- } else {
- const [rows] = await connection.execute(
- `SELECT * FROM ${table_name} WHERE book_platform = 3 LIMIT 6498`
- );
-
- if(rows.length<=0){
- throw "没有数据处理!"
- }
-
- // let id_list = []
-
- // let video_id_list = []
- // let video_data_list = []
- // rows.forEach((row, index) => {
- // id_list.push(row.id)
- // video_id_list.push(row.video_id)
- // video_data_list[row.video_id] = row
- // });
-
- // const [filter_rows] = await connection.execute(
- // `SELECT * FROM filter_data WHERE video_id IN (${video_id_list.join(",")})`
- // );
- // function getFilterById(video_id){
- // for (let index = 0; index < filter_rows.length; index++) {
- // const element = filter_rows[index];
- // if(element.video_id==video_id){
- // return element
- // }
- // }
- // return null
- // }
-
- // let need_insert_list = []
- // for (let index = 0; index < video_id_list.length; index++) {
- // const video_id = video_id_list[index];
- // let d = getFilterById(video_id)
- // if(d==null){
- // need_insert_list.push(video_data_list[video_id])
- // }
- // }
- // let client = new HttpClient()
- // let values = []
- // let sid_tt_status = true
- // for (let index = 0; index < need_insert_list.length; index++) {
- // const row = need_insert_list[index];
- // if(helper.checkChannel(row.guajian_link,"pages/theatre/index")){
- // let key = getCodeFromUrl(row.guajian_link)
- // let book_name = ""
- // let book_id = ""
- // if(key!=null){
-
- // let fq_book_result = await get_fq_book_tab_controllers.getData({ book_id: key });
- // if(fq_book_result.success){
- // book_name = JSON.parse(fq_book_result.data.info.info).book_name
- // book_id = fq_book_result.data.book_id
- // }else{
- // let sid_tt = await tools.getFqSidtt()
- // let {url,params,headers} = helper.getFqRequestOpt(key,sid_tt)
- // let response = await client.fqProxyGet(url, params,headers)
-
-
- // if(response.code==0){
- // let obj = response['data']
- // book_name = obj['video_info'].book_name
- // book_id = obj['video_info'].book_id
-
- // let fq_book = {}
- // fq_book.key = key
- // let fq_book_data = {book_name:book_name,book_id:book_id,info:JSON.stringify(obj['video_info'])}
- // await CMD.add_fq_book(fq_book,fq_book_data)
- // }else{
- // if(response==""){
- // sid_tt_status = false
- // }
- // console.log("error response:",response)
- // }
- // }
-
- // }else{
- // console.log("key = null:",row.guajian_link)
- // }
-
- // if(book_name!=""){
- // values.push({video_id:row.video_id,
- // video_link:row.video_link,
- // title:row.title,
- // book_name:book_name,
- // book_id:book_id,
- // tg_platform_id:config.platform_fanqie_dx,
- // like_num:row.like_num,
- // comment_num:row.comment_num,
- // shared_num:row.shared_num,
- // kepp_num:row.kepp_num,
- // create_time:new Date(),
- // create_day:date,
- // status:0,
- // data_source:2
- // })
- // }
- // }
- // }
- // console.log("values:",values)
-
- // if(values.length>0&&sid_tt_status){
- // const formattedValues = values.map(item => [
- // item.video_id,
- // item.video_link,
- // item.title,
- // item.book_name,
- // item.book_id,
- // item.tg_platform_id,
- // item.like_num,
- // item.comment_num,
- // item.shared_num,
- // item.kepp_num,
- // item.create_time,
- // item.create_day,
- // item.status,
- // item.data_source
- // ]);
- // // 插入数据
- // const insertSQL = `
- // INSERT IGNORE INTO filter_data
- // (video_id, video_link, title, book_name,
- // book_id, tg_platform_id, like_num, comment_num, shared_num,
- // kepp_num, create_time, create_day, status,data_source)
- // VALUES ?
- // `;
-
- // await connection.query(insertSQL, [formattedValues]);
- // }
-
- // const updateSQL = `
- // UPDATE xs_origin_data
- // SET sync_info_status = 1
- // WHERE FIND_IN_SET(id, ?)
- // `;
-
- // await connection.query(updateSQL, [id_list.join(',')]);
- }
-
- }catch(e){
- console.error("processTask error:",e)
- } finally{
- global.setTimeout(processTask, 1000);
- // if(connection!=null){
- // await connection.end();
- // }
- }
- }
- CMD.add_fq_book = async function(data,response){
- let book_name = response.book_name
- let book_id = response.book_id
- data.book_name = book_name
- data.book_id = book_id
- let tab = {
- book_key:data.key,
- book_id:data.book_id,
- info:JSON.stringify(response)
- }
- return await get_fq_book_tab_controllers.createData( tab)
- }
- CMD.init = async function(){
- redis_help.connect((results)=>{
- if(results){
- processTask();
- }
- })
- }
- CMD.init()
|