task.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // 任务管理
  9. func delay(c *bm.Context) {
  10. v := new(struct {
  11. Taskid int64 `form:"task_id" validate:"required"`
  12. Reason string `form:"reason"`
  13. })
  14. if err := c.Bind(v); err != nil {
  15. c.JSON(nil, ecode.RequestErr)
  16. return
  17. }
  18. uid, _ := getUIDName(c)
  19. c.JSON(nil, srv.Delay(c, v.Taskid, uid, v.Reason))
  20. }
  21. func taskfree(c *bm.Context) {
  22. var uid, rows int64
  23. uid, _ = getUIDName(c)
  24. rows = srv.Free(c, uid)
  25. log.Info("释放任务(uid=%d,rows=%d)", uid, rows)
  26. c.JSON(nil, nil)
  27. }
  28. func next(c *bm.Context) {
  29. uidS := c.Request.Form.Get("uid")
  30. uid, err := strconv.Atoi(uidS)
  31. if err != nil {
  32. c.JSON(nil, ecode.RequestErr)
  33. return
  34. }
  35. task, err := srv.Next(c, int64(uid))
  36. if err != nil {
  37. log.Error("srv.Next(uid=%d) error(%v)", uid, err)
  38. c.JSON(nil, err)
  39. return
  40. }
  41. c.JSON(task, nil)
  42. }
  43. func listTask(c *bm.Context) {
  44. v := new(struct {
  45. UID int64 `form:"uid" default:"0"`
  46. IsLeader int8 `form:"isleader" default:"0"`
  47. Lt int8 `form:"listtype" default:"0"`
  48. Pn int `form:"page" default:"1"`
  49. Ps int `form:"pagesize" default:"20"`
  50. })
  51. err := c.Bind(v)
  52. if err != nil {
  53. c.JSON(nil, ecode.RequestErr)
  54. return
  55. }
  56. tasks, err := srv.List(c, v.UID, v.Pn, v.Ps, v.Lt, v.IsLeader)
  57. if err != nil {
  58. log.Error("srv.List(uid=%d,page=%d, pagesize=%d, listtype=%d, isleader=%d) error(%v)",
  59. v.UID, v.Pn, v.Ps, v.Lt, v.IsLeader, err)
  60. c.JSON(nil, err)
  61. return
  62. }
  63. c.JSON(tasks, nil)
  64. }
  65. // info 返回任务信息,复审信息
  66. func info(c *bm.Context) {
  67. var tid int
  68. if tid, _ = strconv.Atoi(c.Request.Form.Get("taskid")); tid == 0 {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. task, err := srv.Info(c, int64(tid))
  73. if err != nil {
  74. c.JSON(nil, err)
  75. return
  76. }
  77. form, err := srv.ReviewForm(c, int64(tid))
  78. if err != nil {
  79. c.JSON(nil, err)
  80. return
  81. }
  82. c.JSONMap(map[string]interface{}{
  83. "task": task,
  84. "review": form,
  85. }, nil)
  86. }