--计划队列 local M = {} local mysqldbx = require "mysqldbx" local tools = require "tools" local skynet = require "skynet" local cjson = require "cjson" function M.set_sweight(msg_body) local isok ,key = tools.checkData({"id_list","sweight"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local idString = table.concat(msg_body.id_list, ",") local sql = string.format("SELECT * FROM task_material_queue_queue WHERE id IN (%s)",idString) local isok,res; res = mysqldbx.query(sql) for i = 1, #res, 1 do local id = res[i].id sql = string.format("UPDATE task_material_queue_queue SET sweight = %d WHERE id =%d ",msg_body.sweight,id) mysqldbx.query(sql) end return true,{} end function M.search_task_material_queue_queue(msg_body) local isok ,key = tools.checkData({ "error_msg", "is_copy", "start_publish_time", "end_publish_time","id","butler_id","tg_main_id","page_size","page_number","start_create_time","end_create_time", "tg_platform_id","advertiser_id","advertiser_name","product_id","product_name","material_id","status"},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 error_msg_param = "" if msg_body.error_msg~="" then local searchTerm = string.gsub(msg_body.error_msg, "%%", "\\%%") error_msg_param = string.format(" AND error_msg LIKE CONCAT('%%', '%s', '%%') ",searchTerm) end 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 local is_copy_param = "" if msg_body.is_copy~="" then is_copy_param = " AND is_copy = "..msg_body.is_copy end local id_param = "" if msg_body.id~="" then id_param = " AND id = "..msg_body.id end local butler_id_param = "" if msg_body.butler_id~="" then butler_id_param = " AND butler_id = "..msg_body.butler_id end local tg_main_id_param = "" if msg_body.tg_main_id~="" then tg_main_id_param = " AND tg_main_id = "..msg_body.tg_main_id end local tg_platform_id_param = "" if msg_body.tg_platform_id~="" then tg_platform_id_param = " AND tg_platform_id = "..msg_body.tg_platform_id end local advertiser_id_param = "" if msg_body.advertiser_id~="" then advertiser_id_param = " AND advertiser_id = "..msg_body.advertiser_id end local advertiser_name_param = "" if msg_body.advertiser_name~="" then advertiser_name_param = string.format(" AND ( advertiser_name LIKE CONCAT( '%%%s%%')) ",msg_body.advertiser_name) end local product_id_param = "" if msg_body.product_id~="" then product_id_param = " AND product_id = "..msg_body.product_id end local product_name_param = "" if msg_body.product_name~="" then product_name_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.product_name) end local material_id_param = "" if msg_body.material_id~="" then material_id_param = " AND material_id = "..msg_body.material_id end local status_param = "" if msg_body.status~="" then status_param = " AND status = "..msg_body.status end local create_date_param = "" if msg_body.start_create_time~="" and msg_body.end_create_time~="" then create_date_param = " AND DATE(created_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(created_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))" end local param = error_msg_param..date_param..is_copy_param..id_param..tg_main_id_param..butler_id_param..tg_platform_id_param..advertiser_id_param..advertiser_name_param..product_id_param..product_name_param..material_id_param..status_param..create_date_param local sql = "SELECT * FROM task_material_queue_queue WHERE 1=1 "..param.." ORDER BY id DESC "..string.format(" LIMIT %d OFFSET %d ",page_size, offset) local list = mysqldbx.query(sql) sql = "SELECT COUNT(*) AS total FROM task_material_queue_queue WHERE 1=1 "..param local total = mysqldbx.query(sql) return true,list,total[1].total end function M.delete_task_material_queue_queue(msg_body) local isok ,key = tools.checkData({"id_list"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end for i = 1, #msg_body.id_list, 1 do local id = msg_body.id_list[i] local sql = string.format("DELETE FROM task_material_queue_queue WHERE id = %d ",id) mysqldbx.query(sql) end return true, {} end return M