task_material_queue_queue.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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({ "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 date_param = ""
  34. if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
  35. 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) .. ")) "
  36. end
  37. local is_copy_param = ""
  38. if msg_body.is_copy~="" then
  39. is_copy_param = " AND is_copy = "..msg_body.is_copy
  40. end
  41. local id_param = ""
  42. if msg_body.id~="" then
  43. id_param = " AND id = "..msg_body.id
  44. end
  45. local butler_id_param = ""
  46. if msg_body.butler_id~="" then
  47. butler_id_param = " AND butler_id = "..msg_body.butler_id
  48. end
  49. local tg_main_id_param = ""
  50. if msg_body.tg_main_id~="" then
  51. tg_main_id_param = " AND tg_main_id = "..msg_body.tg_main_id
  52. end
  53. local tg_platform_id_param = ""
  54. if msg_body.tg_platform_id~="" then
  55. tg_platform_id_param = " AND tg_platform_id = "..msg_body.tg_platform_id
  56. end
  57. local advertiser_id_param = ""
  58. if msg_body.advertiser_id~="" then
  59. advertiser_id_param = " AND advertiser_id = "..msg_body.advertiser_id
  60. end
  61. local advertiser_name_param = ""
  62. if msg_body.advertiser_name~="" then
  63. advertiser_name_param = string.format(" AND ( advertiser_name LIKE CONCAT( '%%%s%%')) ",msg_body.advertiser_name)
  64. end
  65. local product_id_param = ""
  66. if msg_body.product_id~="" then
  67. product_id_param = " AND product_id = "..msg_body.product_id
  68. end
  69. local product_name_param = ""
  70. if msg_body.product_name~="" then
  71. product_name_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.product_name)
  72. end
  73. local material_id_param = ""
  74. if msg_body.material_id~="" then
  75. material_id_param = " AND material_id = "..msg_body.material_id
  76. end
  77. local status_param = ""
  78. if msg_body.status~="" then
  79. status_param = " AND status = "..msg_body.status
  80. end
  81. local create_date_param = ""
  82. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  83. 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) .. "))"
  84. end
  85. local 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
  86. 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)
  87. local list = mysqldbx.query(sql)
  88. sql = "SELECT COUNT(*) AS total FROM task_material_queue_queue WHERE 1=1 "..param
  89. local total = mysqldbx.query(sql)
  90. return true,list,total[1].total
  91. end
  92. function M.delete_task_material_queue_queue(msg_body)
  93. local isok ,key = tools.checkData({"id_list"},msg_body)
  94. if not isok then
  95. return false,string.format("缺少字段: %s.", key)
  96. end
  97. for i = 1, #msg_body.id_list, 1 do
  98. local id = msg_body.id_list[i]
  99. local sql = string.format("DELETE FROM task_material_queue_queue WHERE id = %d ",id)
  100. mysqldbx.query(sql)
  101. end
  102. return true, {}
  103. end
  104. return M