subject.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/admin/main/reply/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. const (
  11. _remarkLength = 200
  12. )
  13. func adminSubject(c *bm.Context) {
  14. params := c.Request.Form
  15. oidStr := params.Get("oid")
  16. tpStr := params.Get("type")
  17. oid, err := strconv.ParseInt(oidStr, 10, 64)
  18. if err != nil {
  19. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  20. c.JSON(nil, ecode.RequestErr)
  21. return
  22. }
  23. tp, err := strconv.ParseInt(tpStr, 10, 64)
  24. if err != nil {
  25. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. sub, err := rpSvc.Subject(c, oid, int32(tp))
  30. if err != nil {
  31. log.Error("rpSvr.AdminGetSubjectState(oid%d,tp,%d)error(%v)", oid, int32(tp))
  32. c.JSON(nil, err)
  33. return
  34. }
  35. c.JSON(sub, nil)
  36. return
  37. }
  38. // adminSubjectState modify subject state
  39. func adminSubjectState(c *bm.Context) {
  40. v := new(struct {
  41. Oid []int64 `form:"oid,split" validate:"required"`
  42. Type int32 `form:"type" validate:"required"`
  43. State int32 `form:"state"`
  44. Remark string `form:"remark"`
  45. })
  46. err := c.Bind(v)
  47. if err != nil {
  48. return
  49. }
  50. var adid int64
  51. if uid, ok := c.Get("uid"); ok {
  52. adid = uid.(int64)
  53. }
  54. var adName string
  55. if uname, ok := c.Get("username"); ok {
  56. adName = uname.(string)
  57. }
  58. fails, err := rpSvc.ModifySubState(c, adid, adName, v.Oid, v.Type, v.State, v.Remark)
  59. c.JSON(fails, err)
  60. return
  61. }
  62. // SubLogSearch returns all subjects in recent 3 months by default,
  63. // accept start time, end time, page, pagesize, order, sort as parameters.
  64. func SubLogSearch(c *bm.Context) {
  65. v := new(struct {
  66. Oid int64 `form:"oid"`
  67. Type int32 `form:"type"`
  68. StartTime string `form:"start_time"`
  69. EndTime string `form:"end_time"`
  70. Page int64 `form:"pn"`
  71. PageSize int64 `form:"ps"`
  72. Order string `form:"order"`
  73. Sort string `form:"sort"`
  74. })
  75. var err error
  76. err = c.Bind(v)
  77. if err != nil {
  78. return
  79. }
  80. if v.EndTime == "" {
  81. v.EndTime = time.Now().Format(model.DateFormat)
  82. }
  83. // 默认只展示3个月内的数据
  84. if v.StartTime == "" {
  85. v.StartTime = time.Now().AddDate(0, -3, 0).Format(model.DateFormat)
  86. }
  87. sp := model.LogSearchParam{
  88. Oid: v.Oid,
  89. Type: v.Type,
  90. CtimeFrom: v.StartTime,
  91. CtimeTo: v.EndTime,
  92. Pn: v.Page,
  93. Ps: v.PageSize,
  94. Order: v.Order,
  95. Sort: v.Sort,
  96. }
  97. data, err := rpSvc.SubjectLog(c, sp)
  98. res := map[string]interface{}{}
  99. res["data"] = data
  100. c.JSONMap(res, err)
  101. return
  102. }
  103. // SubFreeze freeze or unfreeze the comments.
  104. func SubFreeze(c *bm.Context) {
  105. v := new(struct {
  106. Oid []int64 `form:"oid,split"`
  107. Type int32 `form:"type"`
  108. Freeze int32 `form:"freeze"`
  109. Remark string `form:"remark"`
  110. })
  111. err := c.Bind(v)
  112. if err != nil {
  113. return
  114. }
  115. var adid int64
  116. if uid, ok := c.Get("uid"); ok {
  117. adid = uid.(int64)
  118. }
  119. var adName string
  120. if uname, ok := c.Get("username"); ok {
  121. adName = uname.(string)
  122. }
  123. fails, err := rpSvc.FreezeSub(c, adid, adName, v.Oid, v.Type, v.Freeze, v.Remark)
  124. c.JSON(fails, err)
  125. return
  126. }