904118851 4 달 전
부모
커밋
43c6f84726
2개의 변경된 파일123개의 추가작업 그리고 0개의 파일을 삭제
  1. 40 0
      src/helper.js
  2. 83 0
      task_script/sync_publish_time_hy_mf.js

+ 40 - 0
src/helper.js

@@ -430,4 +430,44 @@ helper.generateSign = function(map, appSecret) {
         .toUpperCase();
 }
 
+
+helper.getDate7DaysBefore = function(dateString, inputFormat, outputFormat) {
+    const inputDate = new Date(dateString);
+    
+    if (isNaN(inputDate.getTime())) {
+        // 如果默认解析失败,尝试手动解析
+        // 这里可以添加更多格式的解析逻辑
+        throw new Error('Unsupported date format - consider using moment.js for complex formats');
+    }
+    
+    const date7DaysBefore = new Date(inputDate);
+    date7DaysBefore.setDate(date7DaysBefore.getDate() - 7);
+    
+    // 简单格式化函数
+    function formatDate(date, format) {
+        if (!format || format.toLowerCase() === 'iso') {
+            return date.toISOString();
+        }
+        
+        const pad = num => num.toString().padStart(2, '0');
+        
+        const year = date.getFullYear();
+        const month = pad(date.getMonth() + 1);
+        const day = pad(date.getDate());
+        const hours = pad(date.getHours());
+        const minutes = pad(date.getMinutes());
+        const seconds = pad(date.getSeconds());
+        
+        return format
+            .replace('YYYY', year)
+            .replace('MM', month)
+            .replace('DD', day)
+            .replace('HH', hours)
+            .replace('mm', minutes)
+            .replace('ss', seconds);
+    }
+    
+    return formatDate(date7DaysBefore, outputFormat);
+}
+
 module.exports = helper;

+ 83 - 0
task_script/sync_publish_time_hy_mf.js

@@ -0,0 +1,83 @@
+//同步黑岩免费的发布时间
+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 hy_search_book = require('../src/api/hy/hy_search_book'); 
+const helper = require("../src/helper");
+const CMD = {}
+async function processTask(){
+    let right_status = true
+    let connection  = null
+    try{
+        connection = await mysql.createConnection({
+            ...taskdbConfig,
+            multipleStatements: true
+        });
+        //先获取100本没有发布时间的黑岩书籍
+        let sql = `SELECT * FROM video_product WHERE book_platform = ${config.platform_heiyanmf} AND  publish_time IS NULL  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 = 
+            // console.log("data:",data)
+            let data = await CMD.search_parent_id(connection,video_product_info.product_parent_id)
+            if(data!=null){
+                let publish_time = helper.getDate7DaysBefore(data.publish_time,null,'YYYY-MM-DD') 
+                await connection.execute(
+                    `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)
+            }
+        }
+
+
+    }catch(e){
+        if(e==0){
+            right_status = false
+        }
+        console.error("processTask error:",e)
+    } finally{
+        if(connection!=null){
+            connection.end()
+        }
+        global.setTimeout(processTask, 2000);
+    }
+
+}
+
+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(
+        sql
+    );
+    if(rows.length<=0){
+        return null
+    }
+    return rows[0]
+}
+
+
+CMD.init = async function(){
+    redis_help.connect((results)=>{
+        if(results){
+            processTask();
+        }
+    })
+
+}
+
+CMD.init()