task_material_queue_queue.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. --计划队列
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local cjson = require "cjson"
  7. function M.set_sweight(msg_body)
  8. local isok ,key = tools.checkData({"id_list","sweight"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. local idString = table.concat(msg_body.id_list, ",")
  13. local sql = string.format("SELECT * FROM task_material_queue_queue WHERE id IN (%s)",idString)
  14. local isok,res;
  15. res = mysqldbx.query(sql)
  16. for i = 1, #res, 1 do
  17. local id = res[i].id
  18. sql = string.format("UPDATE task_material_queue_queue SET sweight = %d WHERE id =%d ",msg_body.sweight,id)
  19. mysqldbx.query(sql)
  20. end
  21. return true,{}
  22. end
  23. function M.search_task_material_queue_queue(msg_body)
  24. local isok ,key = tools.checkData({ "error_msg", "is_copy", "start_publish_time",
  25. "end_publish_time","id","butler_id","tg_main_id","page_size","page_number","start_create_time","end_create_time",
  26. "tg_platform_id","advertiser_id","advertiser_name","product_id","product_name","material_id","status"},msg_body)
  27. if not isok then
  28. return false,string.format("缺少字段: %s.", key)
  29. end
  30. local page_size = msg_body.page_size
  31. local page_number = msg_body.page_number
  32. local offset = (page_number - 1) * page_size
  33. local error_msg_param = ""
  34. if msg_body.error_msg~="" then
  35. local searchTerm = string.gsub(msg_body.error_msg, "%%", "\\%%")
  36. error_msg_param = string.format(" AND error_msg LIKE CONCAT('%%', '%s', '%%') ",searchTerm)
  37. end
  38. local date_param = ""
  39. if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
  40. 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) .. ")) "
  41. end
  42. local is_copy_param = ""
  43. if msg_body.is_copy~="" then
  44. is_copy_param = " AND is_copy = "..msg_body.is_copy
  45. end
  46. local id_param = ""
  47. if msg_body.id~="" then
  48. id_param = " AND id = "..msg_body.id
  49. end
  50. local butler_id_param = ""
  51. if msg_body.butler_id~="" then
  52. butler_id_param = " AND butler_id = "..msg_body.butler_id
  53. end
  54. local tg_main_id_param = ""
  55. if msg_body.tg_main_id~="" then
  56. tg_main_id_param = " AND tg_main_id = "..msg_body.tg_main_id
  57. end
  58. local tg_platform_id_param = ""
  59. if msg_body.tg_platform_id~="" then
  60. tg_platform_id_param = " AND tg_platform_id = "..msg_body.tg_platform_id
  61. end
  62. local advertiser_id_param = ""
  63. if msg_body.advertiser_id~="" then
  64. advertiser_id_param = " AND advertiser_id = "..msg_body.advertiser_id
  65. end
  66. local advertiser_name_param = ""
  67. if msg_body.advertiser_name~="" then
  68. advertiser_name_param = string.format(" AND ( advertiser_name LIKE CONCAT( '%%%s%%')) ",msg_body.advertiser_name)
  69. end
  70. local product_id_param = ""
  71. if msg_body.product_id~="" then
  72. product_id_param = " AND product_id = "..msg_body.product_id
  73. end
  74. local product_name_param = ""
  75. if msg_body.product_name~="" then
  76. product_name_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.product_name)
  77. end
  78. local material_id_param = ""
  79. if msg_body.material_id~="" then
  80. material_id_param = " AND material_id = "..msg_body.material_id
  81. end
  82. local status_param = ""
  83. if msg_body.status~="" then
  84. status_param = " AND status = "..msg_body.status
  85. end
  86. local create_date_param = ""
  87. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  88. 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) .. "))"
  89. end
  90. 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
  91. 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)
  92. local list = mysqldbx.query(sql)
  93. sql = "SELECT COUNT(*) AS total FROM task_material_queue_queue WHERE 1=1 "..param
  94. local total = mysqldbx.query(sql)
  95. return true,list,total[1].total
  96. end
  97. function M.delete_task_material_queue_queue(msg_body)
  98. local isok ,key = tools.checkData({"id_list"},msg_body)
  99. if not isok then
  100. return false,string.format("缺少字段: %s.", key)
  101. end
  102. for i = 1, #msg_body.id_list, 1 do
  103. local id = msg_body.id_list[i]
  104. local sql = string.format("DELETE FROM task_material_queue_queue WHERE id = %d ",id)
  105. mysqldbx.query(sql)
  106. end
  107. return true, {}
  108. end
  109. return M