904118851 8 сар өмнө
parent
commit
1bec8694de

+ 12 - 0
common/dbproxy/tg_main.lua

@@ -196,6 +196,18 @@ function M.tgLinkConfig(msg_body)
     return true, {}
 end
 
+--设置创建链接状态
+function M.set_open_create_link_status(msg_body)
+    local isok ,key =  tools.checkData({"id","is_open_create_link"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("UPDATE `tg_main` SET  is_open_create_link = %d  WHERE id = %d ",
+    msg_body.is_open_create_link,msg_body.id)
+    mysqldbx.query(sql)
+    return true, {}
+end
+
 --获取主体下的运行总数
 function M.get_main_ad_run_number(msg_body)
     local isok ,key =  tools.checkData({"main_id"},msg_body)

+ 66 - 0
service/backmgr/checks.lua

@@ -0,0 +1,66 @@
+--检测配置
+local M = {}
+local mysqldbx = require "mysqldbx"
+local tools = require "tools"
+local skynet = require "skynet"
+local mysql = require "skynet.db.mysql"
+local config = require "run_config"
+local db
+local mysqldtaskbx = {}
+
+function M.set_products_main_id(msg_body)
+    local isok ,key =  tools.checkData({"main_id","id"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("UPDATE  products SET main_id = %d WHERE id = %d ",msg_body.main_id,msg_body.id)
+    mysqldtaskbx.Singleton().query(sql)
+    return true, {}
+end
+
+function M.search_products(msg_body)
+    local isok ,key =  tools.checkData({"page_size","page_number"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local page_size = msg_body.page_size
+    local page_number = msg_body.page_number
+    local offset = (page_number - 1) * page_size
+    local sql = "SELECT * FROM products "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
+    local list = mysqldtaskbx.Singleton().query(sql)
+    sql = "SELECT   COUNT(*) AS total  FROM products "
+    local total = mysqldtaskbx.Singleton().query(sql)
+    return true,list,total[1].total
+end
+
+function mysqldtaskbx.start()
+    local function on_connect(db)
+        db:query("set charset utf8mb4");
+    end
+    local conf = config.db_cnf.book_server.mysqldb_checks_cnf
+    db = mysql.connect{
+        host=conf.ip,
+        port=conf.port,
+        database=conf.db,
+        user=conf.user,
+        password=conf.password,
+        charset="utf8mb4",
+        max_packet_size = 1024 * 1024,
+        on_connect = on_connect
+    }
+    if not db then
+       skynet.error("mysql connect fail")
+    end
+end
+
+function mysqldtaskbx.Singleton()
+    if db == nil then
+        mysqldtaskbx.start()
+    end
+    return mysqldtaskbx
+end
+function mysqldtaskbx.query(sql)
+    return db:query(sql)
+end
+
+return M

+ 2 - 0
service/backmgr/init.lua

@@ -34,6 +34,7 @@ local video_product = require "video_product"
 local origin_data = require "origin_data"
 local video_product_material = require "video_product_material"
 local aweme_auth_list = require "aweme_auth_list"
+local checks = require "checks"
 local status_200 = 200
 local CMD = {
     
@@ -66,6 +67,7 @@ CMD["video_product"] = video_product;
 CMD["origin_data"] = origin_data;
 CMD["video_product_material"] = video_product_material;
 CMD["aweme_auth_list"] = aweme_auth_list;
+CMD["checks"] = checks;
 function run(target,fun,msg_body,fd)
     if target~=nil and fun~=nil and target[fun]~=nil then
         local isok,data,total = target[fun](msg_body)

+ 19 - 35
service/backmgr/origin_data.lua

@@ -23,56 +23,40 @@ function M.search_origin_data(msg_body)
     local page_number = msg_body.page_number
     local offset = (page_number - 1) * page_size
 
-    -- 使用数组构建查询条件,避免字符串拼接
-    local conditions = {"1=1"}
-    local params = {}
 
-    -- 创建时间条件
-    if msg_body.start_create_time ~= "" and msg_body.end_create_time ~= "" then
-        table.insert(conditions, "DATE(create_time) BETWEEN DATE(FROM_UNIXTIME(?)) AND DATE(FROM_UNIXTIME(?))")
-        table.insert(params, msg_body.start_create_time / 1000)
-        table.insert(params, msg_body.end_create_time / 1000)
+
+    local date_param = ""
+    if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
+        date_param = " AND DATE(publish_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_publish_time / 1000) .. ")) AND DATE(publish_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_publish_time / 1000) .. "))"
     end
 
-    -- 发布时间条件
-    if msg_body.start_publish_time ~= "" and msg_body.end_publish_time ~= "" then
-        table.insert(conditions, "DATE(publish_time) BETWEEN DATE(FROM_UNIXTIME(?)) AND DATE(FROM_UNIXTIME(?))")
-        table.insert(params, msg_body.start_publish_time / 1000)
-        table.insert(params, msg_body.end_publish_time / 1000)
+
+    local create_date_param = ""
+    if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
+        create_date_param = " AND DATE(create_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(create_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))"
     end
 
+    local guajian_info_param = ""
     -- 挂件信息条件
     if msg_body.guajian_info ~= "" then
-        table.insert(conditions, "guajian_link LIKE ?")
-        table.insert(params, "%" .. msg_body.guajian_info .. "%")
+        guajian_info_param = string.format(" WHERE  (guajian_info LIKE CONCAT( '%%%s%%')) ",msg_body.guajian_info)
     end
 
+    local materialId_param = ""
     -- 材料ID条件
     if msg_body.materialId ~= "" then
-        table.insert(conditions, "materialId = ?")
-        table.insert(params, msg_body.materialId)
+        materialId_param =  string.format(" AND materialId = '%s' ",msg_body.materialId)
     end
 
-    -- 构建WHERE子句
-    local where_clause = table.concat(conditions, " AND ")
-
-    -- 使用子查询优化分页
-    local sql = string.format([[
-        SELECT * FROM (
-            SELECT id FROM origin_data 
-            WHERE %s 
-            ORDER BY id DESC 
-            LIMIT %d OFFSET %d
-        ) AS tmp 
-        JOIN origin_data USING(id)
-    ]], where_clause, page_size, offset)
-
+    local param = date_param..create_date_param..guajian_info_param..materialId_param
+    
+    local sql = "SELECT * FROM origin_data WHERE 1=1 "..param.."ORDER BY id DESC"..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
+    -- 执行查询
+    local res = mysqldbx.query(sql)
     -- 使用 COUNT(*) 优化总数查询
-    local count_sql = string.format("SELECT COUNT(*) AS total FROM origin_data WHERE %s", where_clause)
+    sql =  "SELECT  COUNT(*) AS total  FROM origin_data WHERE 1=1 "..param
 
-    -- 执行查询
-    local res = mysqldbx.query(sql, table.unpack(params))
-    local total = mysqldbx.query(count_sql, table.unpack(params))
+    local total = mysqldbx.query(sql)
 
     return true, res, total[1].total
 end