monitor.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. "go-common/library/xstr"
  8. )
  9. func monitorList(c *bm.Context) {
  10. var (
  11. err error
  12. tp = int64(model.SubTypeVideo)
  13. aid, cid, mid, state int64
  14. page, size int64 = 1, 50
  15. params = c.Request.Form
  16. )
  17. if params.Get("type") != "" {
  18. tp, err = strconv.ParseInt(params.Get("type"), 10, 64)
  19. if err != nil {
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. }
  24. aidStr := params.Get("aid")
  25. if len(aidStr) > 0 {
  26. aid, err = strconv.ParseInt(aidStr, 10, 64)
  27. if err != nil {
  28. c.JSON(nil, ecode.RequestErr)
  29. return
  30. }
  31. }
  32. cidStr := params.Get("cid")
  33. if len(cidStr) > 0 {
  34. cid, err = strconv.ParseInt(cidStr, 10, 64)
  35. if err != nil {
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. }
  40. midStr := params.Get("mid")
  41. if len(midStr) > 0 {
  42. mid, err = strconv.ParseInt(midStr, 10, 64)
  43. if err != nil {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. }
  48. kw := params.Get("keyword")
  49. if params.Get("state") != "" {
  50. state, err = strconv.ParseInt(params.Get("state"), 10, 64)
  51. if err != nil || (int32(state) != model.MonitorBefore && int32(state) != model.MonitorAfter) {
  52. c.JSON(nil, ecode.RequestErr)
  53. return
  54. }
  55. }
  56. pageStr := params.Get("page")
  57. if len(pageStr) > 0 {
  58. page, err = strconv.ParseInt(pageStr, 10, 64)
  59. if err != nil {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. }
  64. psStr := params.Get("page_size")
  65. if len(psStr) > 0 {
  66. size, err = strconv.ParseInt(psStr, 10, 64)
  67. if err != nil {
  68. c.JSON(nil, ecode.RequestErr)
  69. return
  70. }
  71. }
  72. sort := params.Get("sort")
  73. order := params.Get("order")
  74. data, err := dmSvc.MonitorList(c, int32(tp), aid, cid, mid, int32(state), kw, sort, order, page, size)
  75. res := map[string]interface{}{}
  76. res["data"] = data
  77. c.JSONMap(res, err)
  78. }
  79. func editMonitor(c *bm.Context) {
  80. p := c.Request.Form
  81. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  82. if err != nil {
  83. c.JSON(nil, ecode.RequestErr)
  84. return
  85. }
  86. state, err := strconv.ParseInt(p.Get("state"), 10, 64)
  87. if err != nil {
  88. c.JSON(nil, ecode.RequestErr)
  89. return
  90. }
  91. if int32(state) != model.MonitorClosed &&
  92. int32(state) != model.MonitorAfter &&
  93. int32(state) != model.MonitorBefore {
  94. c.JSON(nil, ecode.RequestErr)
  95. return
  96. }
  97. oids, err := xstr.SplitInts(p.Get("oids"))
  98. if err != nil || len(oids) == 0 {
  99. c.JSON(nil, ecode.RequestErr)
  100. return
  101. }
  102. if _, err = dmSvc.UpdateMonitor(c, int32(tp), oids, int32(state)); err != nil {
  103. c.JSON(nil, err)
  104. return
  105. }
  106. c.JSON(nil, nil)
  107. }