video_product_material.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. local mysql = require "skynet.db.mysql"
  8. local config = require "run_config"
  9. local db
  10. local mysqldtaskbx = {}
  11. function M.set_status(msg_body)
  12. local isok ,key = tools.checkData({"id_list","is_download"},msg_body)
  13. if not isok then
  14. return false,string.format("缺少字段: %s.", key)
  15. end
  16. local idString = table.concat(msg_body.id_list, ",")
  17. local sql = string.format("SELECT * FROM video_product_material WHERE id IN (%s)",idString)
  18. local isok,res;
  19. res = mysqldtaskbx.Singleton().query(sql)
  20. for i = 1, #res, 1 do
  21. local id = res[i].id
  22. sql = string.format("UPDATE video_product_material SET is_download = %d WHERE id =%d ",msg_body.is_download,id)
  23. mysqldtaskbx.Singleton().query(sql)
  24. end
  25. return true,{}
  26. end
  27. function M.set_d_z_number(msg_body)
  28. local isok ,key = tools.checkData({"id_list","d_z_number"},msg_body)
  29. if not isok then
  30. return false,string.format("缺少字段: %s.", key)
  31. end
  32. local idString = table.concat(msg_body.id_list, ",")
  33. local sql = string.format("SELECT * FROM video_product_material WHERE id IN (%s)",idString)
  34. local isok,res;
  35. res = mysqldtaskbx.Singleton().query(sql)
  36. for i = 1, #res, 1 do
  37. local id = res[i].id
  38. sql = string.format("UPDATE video_product_material SET d_z_number = %d WHERE id =%d ",msg_body.d_z_number,id)
  39. mysqldtaskbx.Singleton().query(sql)
  40. end
  41. return true,{}
  42. end
  43. function M.search_video_product_material(msg_body)
  44. local isok ,key = tools.checkData({
  45. "start_publish_time",
  46. "end_publish_time",
  47. "up_or_down_publish_time",
  48. "page_size",
  49. "page_number",
  50. "start_create_time",
  51. "end_create_time",
  52. "dy_id",
  53. "product_id",
  54. "product_name",
  55. "book_platform",
  56. "title",
  57. "is_download",
  58. "signature",
  59. "cleaning_status"},msg_body)
  60. if not isok then
  61. return false,string.format("缺少字段: %s.", key)
  62. end
  63. local page_size = msg_body.page_size
  64. local page_number = msg_body.page_number
  65. local offset = (page_number - 1) * page_size
  66. local date_param = ""
  67. if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
  68. 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) .. ")) "
  69. end
  70. local up_or_down_publish_time_param = ""
  71. if msg_body.up_or_down_publish_time~="" then
  72. if(msg_body.up_or_down_publish_time == 0) then
  73. up_or_down_publish_time_param = " publish_time ASC"
  74. else
  75. up_or_down_publish_time_param = " publish_time DESC"
  76. end
  77. end
  78. local dy_id_param = ""
  79. if msg_body.dy_id~="" then
  80. dy_id_param = " AND dy_id = "..msg_body.dy_id
  81. end
  82. local product_id_param = ""
  83. if msg_body.product_id~="" then
  84. product_id_param = " AND product_id = "..msg_body.product_id
  85. end
  86. local product_name_param = ""
  87. if msg_body.product_name~="" then
  88. product_name_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.product_name)
  89. end
  90. local book_platform_param = ""
  91. if msg_body.book_platform~="" then
  92. book_platform_param = " AND book_platform = "..msg_body.book_platform
  93. end
  94. local title_param = ""
  95. if msg_body.title~="" then
  96. title_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.title)
  97. end
  98. local is_download_param = ""
  99. if msg_body.is_download~="" then
  100. is_download_param = " AND is_download = "..msg_body.is_download
  101. end
  102. local status_param = ""
  103. -- if msg_body.status~="" then
  104. -- status_param = " AND status = "..msg_body.status
  105. -- end
  106. local signature_param = ""
  107. if msg_body.signature~="" then
  108. signature_param = string.format(" AND signature = '%s' ",msg_body.signature)
  109. end
  110. local cleaning_status_param = ""
  111. if msg_body.cleaning_status~="" then
  112. cleaning_status_param = " AND cleaning_status = "..msg_body.cleaning_status
  113. end
  114. local create_date_param = ""
  115. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  116. create_date_param = " AND DATE(create_at) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(create_at) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))"
  117. end
  118. local param = date_param..dy_id_param..product_id_param..product_name_param..book_platform_param..title_param..is_download_param..status_param..create_date_param..cleaning_status_param
  119. local up_down_param = up_or_down_publish_time_param
  120. if up_down_param~="" then
  121. up_down_param = " ORDER BY "..up_down_param
  122. else
  123. up_down_param = " ORDER BY update_time DESC "
  124. end
  125. local sql = "SELECT * FROM video_product_material WHERE dy_id!=0 "..param.. up_down_param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  126. skynet.error("sql:",sql)
  127. local list = mysqldtaskbx.Singleton().query(sql)
  128. sql = "SELECT COUNT(*) AS total FROM video_product_material WHERE dy_id!=0 "..param
  129. local total = mysqldtaskbx.Singleton().query(sql)
  130. return true,list,total[1].total
  131. end
  132. function M.delete_video_product_material(msg_body)
  133. local isok ,key = tools.checkData({"id_list"},msg_body)
  134. if not isok then
  135. return false,string.format("缺少字段: %s.", key)
  136. end
  137. for i = 1, #msg_body.id_list, 1 do
  138. local id = msg_body.id_list[i]
  139. local sql = string.format("DELETE FROM video_product_material WHERE id = %d ",id)
  140. mysqldtaskbx.Singleton().query(sql)
  141. end
  142. return true, {}
  143. end
  144. function mysqldtaskbx.start()
  145. local function on_connect(db)
  146. db:query("set charset utf8mb4");
  147. end
  148. local conf = config.db_cnf.book_server.mysqldb_task_cnf
  149. db = mysql.connect{
  150. host=conf.ip,
  151. port=conf.port,
  152. database=conf.db,
  153. user=conf.user,
  154. password=conf.password,
  155. charset="utf8mb4",
  156. max_packet_size = 1024 * 1024,
  157. on_connect = on_connect
  158. }
  159. if not db then
  160. skynet.error("mysql connect fail")
  161. end
  162. end
  163. function mysqldtaskbx.Singleton()
  164. if db == nil then
  165. mysqldtaskbx.start()
  166. end
  167. return mysqldtaskbx
  168. end
  169. function mysqldtaskbx.query(sql)
  170. return db:query(sql)
  171. end
  172. return M