Task.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package controllers
  2. import (
  3. "bzd_server/conf"
  4. "bzd_server/lib"
  5. "bzd_server/models/System"
  6. "bzd_server/models/Task"
  7. beego "github.com/beego/beego/v2/server/web"
  8. "math"
  9. )
  10. type TaskController struct {
  11. beego.Controller
  12. }
  13. // 列表 -
  14. func (c *TaskController) List() {
  15. // 验证登录 User_is, User_r
  16. _,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  17. if !User_is {
  18. c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  19. c.ServeJSON()
  20. return
  21. }
  22. var r_jsons lib.R_JSONS
  23. page, _ := c.GetInt("page")
  24. if page < 1 {
  25. page = 1
  26. }
  27. page_z, _ := c.GetInt("page_z")
  28. if page_z < 1 {
  29. page_z = conf.Page_size
  30. }
  31. T_name := c.GetString("T_name")
  32. T_uuid := c.GetString("T_uuid")
  33. var cnt int64
  34. List, cnt := Task.Read_UserTask_List(T_uuid,T_name, page, page_z)
  35. page_size := math.Ceil(float64(cnt) / float64(page_z))
  36. r_jsons.List = List
  37. r_jsons.Page = page
  38. r_jsons.Page_size = int(page_size)
  39. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  40. r_jsons.Num = int(cnt)
  41. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  42. c.ServeJSON()
  43. return
  44. }
  45. // 列表 -
  46. func (c *TaskController) UserTaskList() {
  47. // 验证登录 User_is, User_r
  48. User_r,User_is := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  49. if !User_is {
  50. c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  51. c.ServeJSON()
  52. return
  53. }
  54. var r_jsons lib.R_JSONS
  55. page, _ := c.GetInt("page")
  56. if page < 1 {
  57. page = 1
  58. }
  59. page_z, _ := c.GetInt("page_z")
  60. if page_z < 1 {
  61. page_z = conf.Page_size
  62. }
  63. T_name := c.GetString("T_name")
  64. var cnt int64
  65. List, cnt := Task.Read_UserTask_List(User_r.T_uuid,T_name, page, page_z)
  66. page_size := math.Ceil(float64(cnt) / float64(page_z))
  67. r_jsons.List = List
  68. r_jsons.Page = page
  69. r_jsons.Page_size = int(page_size)
  70. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  71. r_jsons.Num = int(cnt)
  72. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  73. c.ServeJSON()
  74. return
  75. }
  76. // 获取-
  77. func (c *TaskController) Get() {
  78. // 验证登录 User_is, User_r
  79. _,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  80. if !User_is {
  81. c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  82. c.ServeJSON()
  83. return
  84. }
  85. T_task_id := c.GetString("T_task_id")
  86. r, is := Task.Read_Task(T_task_id);
  87. if !is {
  88. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  89. c.ServeJSON()
  90. return
  91. }
  92. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: Task.TaskToTask_R(r)}
  93. c.ServeJSON()
  94. return
  95. }
  96. // 添加-
  97. func (c *TaskController) Add() {
  98. // 验证登录 User_is, User_r
  99. User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  100. if !User_is {
  101. c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  102. c.ServeJSON()
  103. return
  104. }
  105. T_name := c.GetString("T_name")
  106. T_uuid := c.GetString("T_uuid")
  107. var_ := Task.Task{
  108. T_uuid: T_uuid,
  109. T_name: T_name,
  110. T_State: 1,
  111. }
  112. T_task_id, is := Task.Add_Task(var_)
  113. if !is {
  114. c.Data["json"] = lib.JSONS{Code: 301, Msg: "添加失败!"}
  115. c.ServeJSON()
  116. return
  117. }
  118. System.Add_UserLogs_T(User_r.T_uuid,"任务管理", "添加", var_)
  119. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!",Data: T_task_id}
  120. c.ServeJSON()
  121. return
  122. }
  123. // 修改-
  124. func (c *TaskController) Up() {
  125. // 验证登录 User_is, User_r
  126. User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  127. if !User_is {
  128. c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  129. c.ServeJSON()
  130. return
  131. }
  132. T_name := c.GetString("T_name")
  133. T_State,T_State_err := c.GetInt("T_State")
  134. T_doc1 := c.GetString("T_doc1")
  135. T_pdf1 := c.GetString("T_pdf1")
  136. T_doc2 := c.GetString("T_doc2")
  137. T_pdf2 := c.GetString("T_pdf2")
  138. T_doc3 := c.GetString("T_doc3")
  139. T_pdf3 := c.GetString("T_pdf3")
  140. T_task_id := c.GetString("T_task_id")
  141. r, is := Task.Read_Task(T_task_id);
  142. if !is {
  143. c.Data["json"] = lib.JSONS{Code: 201, Msg: "Id 错误!"}
  144. c.ServeJSON()
  145. return
  146. }
  147. // .......
  148. if len(T_name) > 0{
  149. r.T_name = T_name
  150. }
  151. if T_State_err == nil {
  152. r.T_State = T_State
  153. }
  154. if len(T_doc1) > 0{
  155. r.T_doc1 = T_doc1
  156. }
  157. if len(T_pdf1) > 0{
  158. r.T_pdf1 = T_pdf1
  159. }
  160. if len(T_doc2) > 0{
  161. r.T_doc2 = T_doc2
  162. }
  163. if len(T_pdf2) > 0{
  164. r.T_pdf2 = T_pdf2
  165. }
  166. if len(T_doc3) > 0{
  167. r.T_doc3 = T_doc3
  168. }
  169. if len(T_pdf3) > 0{
  170. r.T_pdf3 = T_pdf3
  171. }
  172. // .......
  173. if !Task.Update_Task(r,"T_name","T_State","T_doc1","T_pdf1","T_doc2","T_pdf2","T_doc3","T_pdf3") {
  174. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  175. c.ServeJSON()
  176. return
  177. }
  178. System.Add_UserLogs_T(User_r.T_uuid,"任务管理", "修改", r)
  179. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  180. c.ServeJSON()
  181. return
  182. }
  183. // 删除-
  184. func (c *TaskController) Del() {
  185. // 验证登录 User_is, User_r
  186. User_r,User_is := lib.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  187. if !User_is {
  188. c.Data["json"] = lib.JSONS{Code: 302, Msg: "请重新登录!"}
  189. c.ServeJSON()
  190. return
  191. }
  192. T_task_id := c.GetString("T_task_id")
  193. if r, is := Task.Read_Task(T_task_id); is {
  194. if !Task.Delete_Task(r) {
  195. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  196. c.ServeJSON()
  197. return
  198. }
  199. System.Add_UserLogs_T(User_r.T_uuid,"任务管理", "删除", r)
  200. }
  201. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  202. c.ServeJSON()
  203. return
  204. }