|
@@ -0,0 +1,78 @@
|
|
|
+--来源小说原始数据
|
|
|
+local M = {}
|
|
|
+local mysqldbx = require "mysqldbx"
|
|
|
+local tools = require "tools"
|
|
|
+local skynet = require "skynet"
|
|
|
+local cjson = require "cjson"
|
|
|
+
|
|
|
+
|
|
|
+function M.reset_status(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 res,sql,id;
|
|
|
+ id = msg_body.id_list[i]
|
|
|
+ sql = string.format("UPDATE xs_origin_data SET sync_info_status = 0 WHERE id = %d ",id)
|
|
|
+ res = mysqldbx.query(sql)
|
|
|
+ end
|
|
|
+ return true,{}
|
|
|
+end
|
|
|
+
|
|
|
+function M.search(msg_body)
|
|
|
+ local isok ,key = tools.checkData({"is_wx_guajian","page_size","page_number","start_create_time","end_create_time","guajian_info","start_publish_time","end_publish_time","materialId"},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 is_wx_guajian_param = ""
|
|
|
+ if msg_body.is_wx_guajian~="" then
|
|
|
+ is_wx_guajian_param = string.format(" AND is_wx_guajian = %d ",msg_body.is_wx_guajian)
|
|
|
+ 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 create_date_param = ""
|
|
|
+ if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
|
|
|
+ create_date_param = " AND create_day >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND create_day <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. ")) "
|
|
|
+ end
|
|
|
+
|
|
|
+ local guajian_info_param = ""
|
|
|
+ -- 挂件信息条件
|
|
|
+ if msg_body.guajian_info ~= "" then
|
|
|
+ local searchTerm = string.gsub(msg_body.guajian_info, "%%", "\\%%")
|
|
|
+ guajian_info_param = string.format(" AND guajian_link LIKE CONCAT('%%', '%s', '%%') ",searchTerm)
|
|
|
+ end
|
|
|
+
|
|
|
+ local materialId_param = ""
|
|
|
+ -- 材料ID条件
|
|
|
+ if msg_body.materialId ~= "" then
|
|
|
+ materialId_param = string.format(" AND materialId = '%s' ",msg_body.materialId)
|
|
|
+ end
|
|
|
+
|
|
|
+ local param = date_param..create_date_param..guajian_info_param..materialId_param..is_wx_guajian_param
|
|
|
+
|
|
|
+ local sql = "SELECT * FROM xs_origin_data WHERE 1=1 "..param.."ORDER BY id DESC"..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
|
|
|
+
|
|
|
+ skynet.error("sql:",sql)
|
|
|
+ -- 执行查询
|
|
|
+ local res = mysqldbx.query(sql)
|
|
|
+ -- 使用 COUNT(*) 优化总数查询
|
|
|
+ sql = "SELECT COUNT(*) AS total FROM xs_origin_data WHERE 1=1 "..param
|
|
|
+
|
|
|
+ local total = mysqldbx.query(sql)
|
|
|
+
|
|
|
+ return true, res, total[1].total
|
|
|
+end
|
|
|
+
|
|
|
+return M
|