weight.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package http
  2. import (
  3. "net/http"
  4. "strconv"
  5. "go-common/app/admin/main/videoup-task/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/render"
  10. )
  11. // 权重管理
  12. func addwtconf(c *bm.Context) {
  13. var err error
  14. cfg := &model.WeightConf{}
  15. if err = c.Bind(cfg); err != nil {
  16. log.Error("addwtconf error(%v)", err)
  17. c.JSON(nil, ecode.RequestErr)
  18. return
  19. }
  20. uid, uname := getUIDName(c)
  21. err = srv.AddWeightConf(c, cfg, uid, uname)
  22. if err != nil {
  23. data := map[string]interface{}{
  24. "code": ecode.RequestErr,
  25. "message": err.Error(),
  26. }
  27. c.Render(http.StatusOK, render.MapJSON(data))
  28. return
  29. }
  30. c.JSON(nil, nil)
  31. }
  32. func delwtconf(c *bm.Context) {
  33. var err error
  34. ids := c.Request.Form.Get("id")
  35. id, err := strconv.Atoi(ids)
  36. if err != nil {
  37. c.JSON(nil, ecode.RequestErr)
  38. return
  39. }
  40. c.JSON(srv.DelWeightConf(c, int64(id)), nil)
  41. }
  42. func listwtconf(c *bm.Context) {
  43. v := new(model.Confs)
  44. if err := c.Bind(v); err != nil {
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. c.JSON(srv.ListWeightConf(c, v))
  49. }
  50. func maxweight(c *bm.Context) {
  51. c.JSON(srv.MaxWeight(c))
  52. }
  53. func listwtlog(c *bm.Context) {
  54. v := new(struct {
  55. Taskid int64 `form:"taskid" validate:"required"`
  56. Pn int `form:"page" default:"1"`
  57. Ps int `form:"ps" default:"20"`
  58. })
  59. if err := c.Bind(v); err != nil {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. cfg, count, err := srv.ListWeightLogs(c, v.Taskid, v.Pn)
  64. if err != nil {
  65. c.JSON(nil, err)
  66. return
  67. }
  68. data := make(map[string]interface{})
  69. data["data"] = cfg
  70. data["pager"] = map[string]int{
  71. "current_page": v.Pn,
  72. "total_items": int(count),
  73. "page_size": 20,
  74. }
  75. c.JSONMap(data, err)
  76. }
  77. func show(c *bm.Context) {
  78. c.JSON(srv.ShowWeightVC(c))
  79. }
  80. func set(c *bm.Context) {
  81. v := new(model.WeightVC)
  82. if err := c.Bind(v); err != nil {
  83. c.JSON(nil, ecode.RequestErr)
  84. return
  85. }
  86. c.JSON(nil, srv.SetWeightVC(c, v))
  87. }