transfer.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/dm/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func addTrJob(c *bm.Context) {
  9. var (
  10. state int8
  11. p = c.Request.Form
  12. )
  13. from, err := strconv.ParseInt(p.Get("from"), 10, 64)
  14. if err != nil {
  15. c.JSON(nil, ecode.RequestErr)
  16. return
  17. }
  18. to, err := strconv.ParseInt(p.Get("to"), 10, 64)
  19. if err != nil {
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. mid, err := strconv.ParseInt(p.Get("mid"), 10, 64)
  24. if err != nil {
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. offset, err := strconv.ParseFloat(p.Get("offset"), 64)
  29. if err != nil {
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. err = dmSvc.AddTransferJob(c, from, to, mid, offset, state)
  34. c.JSON(nil, err)
  35. }
  36. func transferList(c *bm.Context) {
  37. var (
  38. p = c.Request.URL.Query()
  39. pn = int64(1)
  40. ps = int64(50)
  41. state = int64(-1)
  42. )
  43. cid, err := strconv.ParseInt(p.Get("cid"), 10, 64)
  44. if err != nil {
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. if p.Get("state") != "" {
  49. if state, err = strconv.ParseInt(p.Get("state"), 10, 64); err != nil || state < -1 || state > 3 {
  50. c.JSON(nil, ecode.RequestErr)
  51. return
  52. }
  53. }
  54. if p.Get("pn") != "" {
  55. if pn, err = strconv.ParseInt(p.Get("pn"), 10, 64); err != nil || pn <= 0 {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. }
  60. if p.Get("ps") != "" {
  61. if ps, err = strconv.ParseInt(p.Get("ps"), 10, 64); err != nil {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. }
  66. list, total, err := dmSvc.TransferList(c, cid, state, pn, ps)
  67. if err != nil {
  68. c.JSON(nil, err)
  69. return
  70. }
  71. pageInfo := &model.PageInfo{
  72. Num: pn,
  73. Size: ps,
  74. Total: total,
  75. }
  76. data := &model.TransListRes{
  77. Result: list,
  78. Page: pageInfo,
  79. }
  80. c.JSON(data, nil)
  81. }
  82. // reTransferJob retransfer job
  83. func reTransferJob(c *bm.Context) {
  84. p := c.Request.Form
  85. id, err := strconv.ParseInt(p.Get("id"), 10, 64)
  86. if err != nil {
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. mid, err := strconv.ParseInt(p.Get("mid"), 10, 64)
  91. if err != nil {
  92. c.JSON(nil, ecode.RequestErr)
  93. return
  94. }
  95. err = dmSvc.ReTransferJob(c, id, mid)
  96. if err != nil {
  97. c.JSON(nil, err)
  98. return
  99. }
  100. c.JSON(nil, nil)
  101. }