manage.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/dm2/model"
  5. "go-common/app/interface/main/dm2/model/oplog"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/xstr"
  10. )
  11. // editState edit dm state.
  12. // 0:正常1:删除 2:保护 3:取消保护
  13. func editState(c *bm.Context) {
  14. var (
  15. p = c.Request.Form
  16. dmids = make([]int64, 0)
  17. )
  18. mid, _ := c.Get("mid")
  19. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  20. if err != nil {
  21. c.JSON(nil, ecode.RequestErr)
  22. return
  23. }
  24. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  25. if err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. state, err := strconv.ParseInt(p.Get("state"), 10, 64)
  30. if err != nil {
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. ids, err := xstr.SplitInts(p.Get("dmids"))
  35. if err != nil {
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. for _, dmid := range ids {
  40. if dmid == 0 {
  41. log.Warn("dmid is zero")
  42. continue
  43. }
  44. dmids = append(dmids, dmid)
  45. }
  46. if len(dmids) == 0 {
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. switch state {
  51. case 0, 1:
  52. err = dmSvc.EditDMState(c, int32(tp), mid.(int64), oid, int32(state), dmids, oplog.SourceUp, oplog.OperatorUp)
  53. if err != nil {
  54. log.Error("dmSvc.EditDMState(mid:%d, oid:%d, state:%d, dmids:%v) error(%v)", mid.(int64), oid, state, dmids, err)
  55. c.JSON(nil, err)
  56. return
  57. }
  58. err = dmSvc.UptSearchDMState(c, dmids, oid, int32(state), int32(tp))
  59. case 2, 3:
  60. var (
  61. affectIds []int64
  62. )
  63. attr := model.AttrYes
  64. if state == 3 {
  65. attr = model.AttrNo
  66. }
  67. affectIds, err = dmSvc.EditDMAttr(c, int32(tp), mid.(int64), oid, model.AttrProtect, attr, dmids, oplog.SourceUp, oplog.OperatorUp)
  68. if err != nil {
  69. log.Error("dmSvc.EditDMAttr(mid:%d, oid:%d, attr:%d, dmids:%v) error(%v)", mid.(int64), oid, attr, dmids, err)
  70. c.JSON(nil, err)
  71. return
  72. }
  73. if len(affectIds) > 0 {
  74. err = dmSvc.UptSearchDMAttr(c, affectIds, oid, attr, int32(tp))
  75. }
  76. default:
  77. err = ecode.RequestErr
  78. }
  79. c.JSON(nil, err)
  80. }
  81. func editPool(c *bm.Context) {
  82. p := c.Request.Form
  83. mid, _ := c.Get("mid")
  84. oid, err := strconv.ParseInt(p.Get("oid"), 10, 64)
  85. if err != nil {
  86. c.JSON(nil, ecode.RequestErr)
  87. return
  88. }
  89. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  90. if err != nil {
  91. c.JSON(nil, ecode.RequestErr)
  92. return
  93. }
  94. pool, err := strconv.ParseInt(p.Get("pool"), 10, 64)
  95. if err != nil {
  96. c.JSON(nil, ecode.RequestErr)
  97. return
  98. }
  99. dmids, err := xstr.SplitInts(p.Get("dmids"))
  100. if err != nil || len(dmids) == 0 {
  101. c.JSON(nil, ecode.RequestErr)
  102. return
  103. }
  104. err = dmSvc.EditDMPool(c, int32(tp), mid.(int64), oid, int32(pool), dmids, oplog.SourceUp, oplog.OperatorUp)
  105. if err != nil {
  106. log.Error("dmSvc.EditDMStat(oid:%d dmids:%v) error(%v)", oid, dmids, err)
  107. c.JSON(nil, err)
  108. return
  109. }
  110. err = dmSvc.UptSearchDMPool(c, dmids, oid, int32(pool), int32(tp))
  111. c.JSON(nil, err)
  112. }